Refactor bp2build tests
Moves to specifying attributes as a map, such at it is possible to add additional attributes conditionally. This is in particular useful once supporting the `enabled` property which will add `target_compatible_with` Test: go test soong tests Change-Id: Iade8eed1ce3acb1d1712a9ee3119d9ae59675624
This commit is contained in:
@@ -37,15 +37,15 @@ func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
|
||||
|
||||
func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).moduleTypeUnderTest = "cc_library_shared"
|
||||
(&tc).moduleTypeUnderTestFactory = cc.LibrarySharedFactory
|
||||
(&tc).moduleTypeUnderTestBp2BuildMutator = cc.CcLibrarySharedBp2Build
|
||||
runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedSimple(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared simple overall test",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared simple overall test",
|
||||
filesystem: map[string]string{
|
||||
// NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
|
||||
"include_dir_1/include_dir_1_a.h": "",
|
||||
@@ -140,52 +140,50 @@ cc_library_shared {
|
||||
|
||||
// TODO: Also support export_header_lib_headers
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
absolute_includes = [
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"absolute_includes": `[
|
||||
"include_dir_1",
|
||||
"include_dir_2",
|
||||
],
|
||||
copts = [
|
||||
]`,
|
||||
"copts": `[
|
||||
"-Dflag1",
|
||||
"-Dflag2",
|
||||
],
|
||||
export_includes = [
|
||||
]`,
|
||||
"export_includes": `[
|
||||
"export_include_dir_1",
|
||||
"export_include_dir_2",
|
||||
],
|
||||
implementation_deps = [
|
||||
]`,
|
||||
"implementation_deps": `[
|
||||
":header_lib_1",
|
||||
":header_lib_2",
|
||||
],
|
||||
implementation_dynamic_deps = [
|
||||
]`,
|
||||
"implementation_dynamic_deps": `[
|
||||
":shared_lib_1",
|
||||
":shared_lib_2",
|
||||
],
|
||||
local_includes = [
|
||||
]`,
|
||||
"local_includes": `[
|
||||
"local_include_dir_1",
|
||||
"local_include_dir_2",
|
||||
".",
|
||||
],
|
||||
srcs = [
|
||||
]`,
|
||||
"srcs": `[
|
||||
"foo_shared1.cc",
|
||||
"foo_shared2.cc",
|
||||
],
|
||||
whole_archive_deps = [
|
||||
]`,
|
||||
"whole_archive_deps": `[
|
||||
":whole_static_lib_1",
|
||||
":whole_static_lib_2",
|
||||
],
|
||||
)`},
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
filesystem: map[string]string{},
|
||||
description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
|
||||
filesystem: map[string]string{},
|
||||
blueprint: soongCcLibrarySharedPreamble + `
|
||||
cc_library_static {
|
||||
name: "static_dep",
|
||||
@@ -200,27 +198,25 @@ cc_library_shared {
|
||||
arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
implementation_dynamic_deps = select({
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"implementation_dynamic_deps": `select({
|
||||
"//build/bazel/platforms/arch:arm64": [":shared_dep"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
whole_archive_deps = select({
|
||||
})`,
|
||||
"whole_archive_deps": `select({
|
||||
"//build/bazel/platforms/arch:arm64": [":static_dep"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)`},
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared os-specific shared_libs",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
filesystem: map[string]string{},
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared os-specific shared_libs",
|
||||
filesystem: map[string]string{},
|
||||
blueprint: soongCcLibrarySharedPreamble + `
|
||||
cc_library_shared {
|
||||
name: "shared_dep",
|
||||
@@ -231,23 +227,21 @@ cc_library_shared {
|
||||
target: { android: { shared_libs: ["shared_dep"], } },
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
implementation_dynamic_deps = select({
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"implementation_dynamic_deps": `select({
|
||||
"//build/bazel/platforms/os:android": [":shared_dep"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)`},
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared base, arch, and os-specific shared_libs",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
filesystem: map[string]string{},
|
||||
description: "cc_library_shared base, arch, and os-specific shared_libs",
|
||||
filesystem: map[string]string{},
|
||||
blueprint: soongCcLibrarySharedPreamble + `
|
||||
cc_library_shared {
|
||||
name: "shared_dep",
|
||||
@@ -268,25 +262,23 @@ cc_library_shared {
|
||||
arch: { arm64: { shared_libs: ["shared_dep3"] } },
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
implementation_dynamic_deps = [":shared_dep"] + select({
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"implementation_dynamic_deps": `[":shared_dep"] + select({
|
||||
"//build/bazel/platforms/arch:arm64": [":shared_dep3"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//build/bazel/platforms/os:android": [":shared_dep2"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)`},
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared simple exclude_srcs",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared simple exclude_srcs",
|
||||
filesystem: map[string]string{
|
||||
"common.c": "",
|
||||
"foo-a.c": "",
|
||||
@@ -299,23 +291,21 @@ cc_library_shared {
|
||||
exclude_srcs: ["foo-excluded.c"],
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
srcs_c = [
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"srcs_c": `[
|
||||
"common.c",
|
||||
"foo-a.c",
|
||||
],
|
||||
)`},
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedStrip(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared stripping",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
filesystem: map[string]string{},
|
||||
description: "cc_library_shared stripping",
|
||||
filesystem: map[string]string{},
|
||||
blueprint: soongCcLibrarySharedPreamble + `
|
||||
cc_library_shared {
|
||||
name: "foo_shared",
|
||||
@@ -328,9 +318,9 @@ cc_library_shared {
|
||||
},
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
strip = {
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"strip": `{
|
||||
"all": True,
|
||||
"keep_symbols": False,
|
||||
"keep_symbols_and_debug_frame": True,
|
||||
@@ -339,17 +329,15 @@ cc_library_shared {
|
||||
"sym2",
|
||||
],
|
||||
"none": False,
|
||||
},
|
||||
)`},
|
||||
}`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedVersionScript(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared version script",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared version script",
|
||||
filesystem: map[string]string{
|
||||
"version_script": "",
|
||||
},
|
||||
@@ -359,20 +347,18 @@ cc_library_shared {
|
||||
version_script: "version_script",
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
additional_linker_inputs = ["version_script"],
|
||||
linkopts = ["-Wl,--version-script,$(location version_script)"],
|
||||
)`},
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"additional_linker_inputs": `["version_script"]`,
|
||||
"linkopts": `["-Wl,--version-script,$(location version_script)"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared - nocrt: true emits attribute",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared - nocrt: true emits attribute",
|
||||
filesystem: map[string]string{
|
||||
"impl.cpp": "",
|
||||
},
|
||||
@@ -384,19 +370,18 @@ cc_library_shared {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
link_crt = False,
|
||||
srcs = ["impl.cpp"],
|
||||
)`}})
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"link_crt": `False`,
|
||||
"srcs": `["impl.cpp"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared - nocrt: false doesn't emit attribute",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared - nocrt: false doesn't emit attribute",
|
||||
filesystem: map[string]string{
|
||||
"impl.cpp": "",
|
||||
},
|
||||
@@ -408,18 +393,17 @@ cc_library_shared {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{`cc_library_shared(
|
||||
name = "foo_shared",
|
||||
srcs = ["impl.cpp"],
|
||||
)`}})
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{
|
||||
"srcs": `["impl.cpp"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, bp2buildTestCase{
|
||||
description: "cc_library_shared - nocrt in select",
|
||||
moduleTypeUnderTest: "cc_library_shared",
|
||||
moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
|
||||
moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build,
|
||||
description: "cc_library_shared - nocrt in select",
|
||||
filesystem: map[string]string{
|
||||
"impl.cpp": "",
|
||||
},
|
||||
|
Reference in New Issue
Block a user