33b2fb7333
Allow a cc_prebuilt_library_shared to share the same name as a cc_library by always creating static and shared variants of prebuilts so that the variants of the source module are always a superset of the variants of the target module. Bug: 131709055 Test: TestPrebuilts Change-Id: I4afd6d37e6a986d08ad25aee69eca6d994febc6b
126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
// Copyright 2019 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package cc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"android/soong/android"
|
|
|
|
"github.com/google/blueprint"
|
|
)
|
|
|
|
func TestPrebuilt(t *testing.T) {
|
|
bp := `
|
|
cc_library {
|
|
name: "liba",
|
|
}
|
|
|
|
cc_prebuilt_library_shared {
|
|
name: "liba",
|
|
srcs: ["liba.so"],
|
|
}
|
|
|
|
cc_library {
|
|
name: "libb",
|
|
}
|
|
|
|
cc_prebuilt_library_static {
|
|
name: "libb",
|
|
srcs: ["libb.a"],
|
|
}
|
|
|
|
cc_library_shared {
|
|
name: "libd",
|
|
}
|
|
|
|
cc_prebuilt_library_shared {
|
|
name: "libd",
|
|
srcs: ["libd.so"],
|
|
}
|
|
|
|
cc_library_static {
|
|
name: "libe",
|
|
}
|
|
|
|
cc_prebuilt_library_static {
|
|
name: "libe",
|
|
srcs: ["libe.a"],
|
|
}
|
|
`
|
|
|
|
fs := map[string][]byte{
|
|
"liba.so": nil,
|
|
"libb.a": nil,
|
|
"libd.so": nil,
|
|
"libe.a": nil,
|
|
}
|
|
|
|
config := android.TestArchConfig(buildDir, nil)
|
|
|
|
ctx := createTestContext(t, config, bp, fs, android.Android)
|
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory))
|
|
ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory))
|
|
ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory))
|
|
|
|
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
|
|
ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators)
|
|
|
|
ctx.Register()
|
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
android.FailIfErrored(t, errs)
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
android.FailIfErrored(t, errs)
|
|
|
|
// Verify that all the modules exist and that their dependencies were connected correctly
|
|
liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_core_shared").Module()
|
|
libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_core_static").Module()
|
|
libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_core_shared").Module()
|
|
libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_core_static").Module()
|
|
|
|
prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_core_shared").Module()
|
|
prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_core_static").Module()
|
|
prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_core_shared").Module()
|
|
prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_core_static").Module()
|
|
|
|
hasDep := func(m android.Module, wantDep android.Module) bool {
|
|
t.Helper()
|
|
var found bool
|
|
ctx.VisitDirectDeps(m, func(dep blueprint.Module) {
|
|
if dep == wantDep {
|
|
found = true
|
|
}
|
|
})
|
|
return found
|
|
}
|
|
|
|
if !hasDep(liba, prebuiltLiba) {
|
|
t.Errorf("liba missing dependency on prebuilt_liba")
|
|
}
|
|
|
|
if !hasDep(libb, prebuiltLibb) {
|
|
t.Errorf("libb missing dependency on prebuilt_libb")
|
|
}
|
|
|
|
if !hasDep(libd, prebuiltLibd) {
|
|
t.Errorf("libd missing dependency on prebuilt_libd")
|
|
}
|
|
|
|
if !hasDep(libe, prebuiltLibe) {
|
|
t.Errorf("libe missing dependency on prebuilt_libe")
|
|
}
|
|
}
|