Loading bp2build/cc_library_conversion_test.go +169 −296 Original line number Diff line number Diff line Loading @@ -113,15 +113,12 @@ cc_library { srcs: ["bionic.cpp"] }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-Wall", "-I.", "-I$(BINDIR)/.", ], copts = ["-Wall"], export_includes = ["foo-dir"], implementation_deps = [":some-headers"], linkopts = ["-Wl,--exclude-libs=bar.a"] + select({ Loading Loading @@ -186,6 +183,7 @@ cc_library { ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( Loading @@ -195,8 +193,6 @@ cc_library { "-Wextra", "-Wunused", "-Werror", "-I.", "-I$(BINDIR)/.", ], implementation_deps = [":libc_headers"], linkopts = [ Loading Loading @@ -277,12 +273,12 @@ func TestCcLibrarySharedStaticProps(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/both.cpp": "", "foo/bar/sharedonly.cpp": "", "foo/bar/staticonly.cpp": "", "foo/bar/Android.bp": ` "both.cpp": "", "sharedonly.cpp": "", "staticonly.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["both.cpp"], Loading @@ -304,36 +300,57 @@ cc_library { static_libs: ["static_dep_for_shared"], whole_static_libs: ["whole_static_lib_for_shared"], }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library_static { name: "static_dep_for_shared" } cc_library_static { name: "static_dep_for_shared", bazel_module: { bp2build_available: false }, } cc_library_static { name: "static_dep_for_static" } cc_library_static { name: "static_dep_for_static", bazel_module: { bp2build_available: false }, } cc_library_static { name: "static_dep_for_both" } cc_library_static { name: "static_dep_for_both", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_shared" } cc_library_static { name: "whole_static_lib_for_shared", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_static" } cc_library_static { name: "whole_static_lib_for_static", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_both" } cc_library_static { name: "whole_static_lib_for_both", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_shared" } cc_library { name: "shared_dep_for_shared", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_static" } cc_library { name: "shared_dep_for_static", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_both" } cc_library { name: "shared_dep_for_both", bazel_module: { bp2build_available: false }, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "bothflag", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], copts = ["bothflag"], dynamic_deps = [":shared_dep_for_both"], implementation_deps = [":static_dep_for_both"], shared = { Loading Loading @@ -374,6 +391,7 @@ cc_library { whole_static_libs: ["whole_static_lib_for_shared"], }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } Loading @@ -386,10 +404,6 @@ cc_prebuilt_library_static { name: "whole_static_lib_for_both" } blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], shared = { "whole_archive_deps": [":whole_static_lib_for_shared_alwayslink"], }, Loading Loading @@ -693,16 +707,13 @@ cc_library { srcs: ["a.cpp"], version_script: "v.map", bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = "v.map", )`}, Loading Loading @@ -731,16 +742,13 @@ func TestCcLibraryConfiguredVersionScript(t *testing.T) { }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = select({ "//build/bazel/platforms/arch:arm": "arm.map", Loading @@ -757,35 +765,21 @@ func TestCcLibrarySharedLibs(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "mylib", bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: false }, } cc_library { name: "a", shared_libs: ["mylib",], bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], dynamic_deps = [":mylib"], )`, `cc_library( name = "mylib", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) } Loading @@ -796,14 +790,12 @@ func TestCcLibraryPackRelocations(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["a.cpp"], pack_relocations: false, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { Loading @@ -814,7 +806,7 @@ cc_library { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { Loading @@ -825,24 +817,14 @@ cc_library { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, }`, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = ["-Wl,--pack-dyn-relocs=none"], srcs = ["a.cpp"], )`, `cc_library( name = "b", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = select({ "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], Loading @@ -850,10 +832,6 @@ cc_library { srcs = ["b.cpp"], )`, `cc_library( name = "c", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = select({ "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], Loading @@ -869,24 +847,18 @@ func TestCcLibrarySpacesInCopts(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", cflags: ["-include header.h",], bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-include", "header.h", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) Loading @@ -898,14 +870,10 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": `cc_library { blueprint: soongCcLibraryPreamble + `cc_library { name: "a", srcs: ["a.cpp"], cflags: [ "-Wall", ], cflags: ["-Wall"], cppflags: [ "-fsigned-char", "-pedantic", Loading @@ -920,18 +888,12 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { cppflags: ["-DANDROID=1"], }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Wall", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], copts = ["-Wall"], cppflags = [ "-fsigned-char", "-pedantic", Loading @@ -953,9 +915,7 @@ func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["a.cpp"], Loading @@ -967,18 +927,11 @@ func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { version_script: "linux_bionic_arm64.map", }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = select({ "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", Loading Loading @@ -1031,6 +984,7 @@ cc_library { ], }, }, include_build_directory: false, } cc_library { Loading Loading @@ -1071,10 +1025,6 @@ cc_library { expectedBazelTargets: []string{ `cc_library( name = "foo_static", copts = [ "-I.", "-I$(BINDIR)/.", ], dynamic_deps = select({ "//build/bazel/platforms/arch:arm": [], "//conditions:default": [":arm_shared_lib_excludes"], Loading Loading @@ -1117,14 +1067,11 @@ cc_library { name: "foo-lib", srcs: ["impl.cpp"], no_libcrt: true, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = False, )`}}) Loading @@ -1144,14 +1091,11 @@ cc_library { name: "foo-lib", srcs: ["impl.cpp"], no_libcrt: false, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = True, )`}}) Loading @@ -1166,7 +1110,6 @@ func TestCCLibraryNoCrtArchVariant(t *testing.T) { "impl.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "some-headers" } cc_library { name: "foo-lib", srcs: ["impl.cpp"], Loading @@ -1178,14 +1121,11 @@ cc_library { no_libcrt: true, }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = select({ "//build/bazel/platforms/arch:arm": False, Loading @@ -1204,7 +1144,6 @@ func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { "impl.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "some-headers" } cc_library { name: "foo-lib", srcs: ["impl.cpp"], Loading @@ -1217,14 +1156,11 @@ cc_library { no_libcrt: true, }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = select({ "//build/bazel/platforms/arch:arm": False, Loading @@ -1240,102 +1176,74 @@ func TestCcLibraryStrip(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "nothing", bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { name: "keep_symbols", bazel_module: { bp2build_available: true }, strip: { keep_symbols: true, } }, include_build_directory: false, } cc_library { name: "keep_symbols_and_debug_frame", bazel_module: { bp2build_available: true }, strip: { keep_symbols_and_debug_frame: true, } }, include_build_directory: false, } cc_library { name: "none", bazel_module: { bp2build_available: true }, strip: { none: true, } }, include_build_directory: false, } cc_library { name: "keep_symbols_list", bazel_module: { bp2build_available: true }, strip: { keep_symbols_list: ["symbol"], } }, include_build_directory: false, } cc_library { name: "all", bazel_module: { bp2build_available: true }, strip: { all: true, } }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "all", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "all": True, }, )`, `cc_library( name = "keep_symbols", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols": True, }, )`, `cc_library( name = "keep_symbols_and_debug_frame", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols_and_debug_frame": True, }, )`, `cc_library( name = "keep_symbols_list", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols_list": ["symbol"], }, )`, `cc_library( name = "none", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "none": True, }, )`, `cc_library( name = "nothing", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) } Loading @@ -1346,12 +1254,9 @@ func TestCcLibraryStripWithArch(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "multi-arch", bazel_module: { bp2build_available: true }, target: { darwin: { strip: { Loading @@ -1370,17 +1275,12 @@ cc_library { keep_symbols: true, }, }, } }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "multi-arch", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols": select({ "//build/bazel/platforms/arch:arm64": True, Loading Loading @@ -1412,14 +1312,11 @@ func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { cc_library { name: "root_empty", system_shared_libs: [], include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "root_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1437,14 +1334,11 @@ cc_library { static: { system_shared_libs: [], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "static_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], static = { "system_dynamic_deps": [], }, Loading @@ -1464,14 +1358,11 @@ cc_library { shared: { system_shared_libs: [], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "shared_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [], }, Loading @@ -1495,14 +1386,11 @@ cc_library { } } }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "shared_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [], }, Loading @@ -1528,14 +1416,11 @@ cc_library { system_shared_libs: [], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "target_linux_bionic_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1555,14 +1440,11 @@ cc_library { system_shared_libs: [], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "target_bionic_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1575,8 +1457,14 @@ func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, blueprint: soongCcLibraryPreamble + ` cc_library {name: "libc"} cc_library {name: "libm"} cc_library { name: "libc", bazel_module: { bp2build_available: false }, } cc_library { name: "libm", bazel_module: { bp2build_available: false }, } cc_library { name: "foo", Loading @@ -1584,30 +1472,15 @@ cc_library { shared: { system_shared_libs: ["libm"], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [":libm"], }, system_dynamic_deps = [":libc"], )`, `cc_library( name = "libc", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library( name = "libm", copts = [ "-I.", "-I$(BINDIR)/.", ], )`}, }) } bp2build/cc_library_headers_conversion_test.go +57 −106 Original line number Diff line number Diff line Loading @@ -99,11 +99,13 @@ func TestCcLibraryHeadersSimple(t *testing.T) { cc_library_headers { name: "lib-1", export_include_dirs: ["lib-1"], bazel_module: { bp2build_available: false }, } cc_library_headers { name: "lib-2", export_include_dirs: ["lib-2"], bazel_module: { bp2build_available: false }, } cc_library_headers { Loading Loading @@ -145,25 +147,11 @@ cc_library_headers { ":lib-1", ":lib-2", ], )`, `cc_library_headers( name = "lib-1", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-1"], )`, `cc_library_headers( name = "lib-2", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-2"], )`}, }) } func TestCcLibraryHeadersOSSpecificHeader(t *testing.T) { func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { runCcLibraryHeadersTestCase(t, bp2buildTestCase{ description: "cc_library_headers test with os-specific header_libs props", moduleTypeUnderTest: "cc_library_headers", Loading @@ -171,12 +159,30 @@ func TestCcLibraryHeadersOSSpecificHeader(t *testing.T) { moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, filesystem: map[string]string{}, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib" } cc_library_headers { name: "base-lib" } cc_library_headers { name: "darwin-lib" } cc_library_headers { name: "linux-lib" } cc_library_headers { name: "linux_bionic-lib" } cc_library_headers { name: "windows-lib" } cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "base-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "darwin-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "linux-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "linux_bionic-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "windows-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "foo_headers", header_libs: ["base-lib"], Loading @@ -187,32 +193,10 @@ cc_library_headers { linux_glibc: { header_libs: ["linux-lib"] }, windows: { header_libs: ["windows-lib"] }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "android-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "base-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "darwin-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], implementation_deps = [":base-lib"] + select({ "//build/bazel/platforms/os:android": [":android-lib"], "//build/bazel/platforms/os:darwin": [":darwin-lib"], Loading @@ -221,24 +205,6 @@ cc_library_headers { "//build/bazel/platforms/os:windows": [":windows-lib"], "//conditions:default": [], }), )`, `cc_library_headers( name = "linux-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "linux_bionic-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "windows-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`}, }) } Loading @@ -251,32 +217,23 @@ func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, filesystem: map[string]string{}, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib" } cc_library_headers { name: "exported-lib" } cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "exported-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "foo_headers", target: { android: { header_libs: ["android-lib"], export_header_lib_headers: ["exported-lib"] }, }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "android-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "exported-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], deps = select({ "//build/bazel/platforms/os:android": [":exported-lib"], "//conditions:default": [], Loading Loading @@ -330,13 +287,10 @@ func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { ], }, }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], export_system_includes = ["shared_include_dir"] + select({ "//build/bazel/platforms/arch:arm": ["arm_include_dir"], "//build/bazel/platforms/arch:x86_64": ["x86_64_include_dir"], Loading Loading @@ -375,13 +329,10 @@ cc_library_headers { name: "lib-1", export_include_dirs: ["lib-1"], no_libcrt: true, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "lib-1", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-1"], )`}, }) Loading bp2build/cc_library_static_conversion_test.go +125 −269 File changed.Preview size limit exceeded, changes collapsed. Show changes bp2build/cc_object_conversion_test.go +10 −29 Original line number Diff line number Diff line Loading @@ -78,14 +78,12 @@ func TestCcObjectSimple(t *testing.T) { func TestCcObjectDefaults(t *testing.T) { runCcObjectTestCase(t, bp2buildTestCase{ description: "simple cc_object with defaults", moduleTypeUnderTest: "cc_object", moduleTypeUnderTestFactory: cc.ObjectFactory, moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, blueprint: `cc_object { name: "foo", system_shared_libs: [], local_include_dirs: ["include"], srcs: [ "a/b/*.h", "a/b/c.c" Loading Loading @@ -115,8 +113,6 @@ cc_defaults { "-Wall", "-Werror", "-fno-addrsig", "-Iinclude", "-I$(BINDIR)/include", "-I.", "-I$(BINDIR)/.", ], Loading @@ -140,29 +136,23 @@ func TestCcObjectCcObjetDepsInObjs(t *testing.T) { system_shared_libs: [], srcs: ["a/b/c.c"], objs: ["bar"], include_build_directory: false, } cc_object { name: "bar", system_shared_libs: [], srcs: ["x/y/z.c"], include_build_directory: false, } `, expectedBazelTargets: []string{`cc_object( name = "bar", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ], copts = ["-fno-addrsig"], srcs = ["x/y/z.c"], )`, `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ], copts = ["-fno-addrsig"], deps = [":bar"], srcs = ["a/b/c.c"], )`, Loading Loading @@ -245,16 +235,13 @@ func TestCcObjectCflagsOneArch(t *testing.T) { srcs: ["arch/arm/file.cpp"], // label list }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:x86": ["-fPIC"], "//conditions:default": [], }), Loading Loading @@ -295,16 +282,13 @@ func TestCcObjectCflagsFourArch(t *testing.T) { cflags: ["-Wall"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:arm": ["-Wall"], "//build/bazel/platforms/arch:arm64": ["-Wall"], "//build/bazel/platforms/arch:x86": ["-fPIC"], Loading Loading @@ -344,16 +328,13 @@ func TestCcObjectCflagsMultiOs(t *testing.T) { cflags: ["-Wall"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/os:android": ["-fPIC"], "//build/bazel/platforms/os:darwin": ["-Wall"], "//build/bazel/platforms/os:windows": ["-fPIC"], Loading Loading
bp2build/cc_library_conversion_test.go +169 −296 Original line number Diff line number Diff line Loading @@ -113,15 +113,12 @@ cc_library { srcs: ["bionic.cpp"] }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-Wall", "-I.", "-I$(BINDIR)/.", ], copts = ["-Wall"], export_includes = ["foo-dir"], implementation_deps = [":some-headers"], linkopts = ["-Wl,--exclude-libs=bar.a"] + select({ Loading Loading @@ -186,6 +183,7 @@ cc_library { ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( Loading @@ -195,8 +193,6 @@ cc_library { "-Wextra", "-Wunused", "-Werror", "-I.", "-I$(BINDIR)/.", ], implementation_deps = [":libc_headers"], linkopts = [ Loading Loading @@ -277,12 +273,12 @@ func TestCcLibrarySharedStaticProps(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/both.cpp": "", "foo/bar/sharedonly.cpp": "", "foo/bar/staticonly.cpp": "", "foo/bar/Android.bp": ` "both.cpp": "", "sharedonly.cpp": "", "staticonly.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["both.cpp"], Loading @@ -304,36 +300,57 @@ cc_library { static_libs: ["static_dep_for_shared"], whole_static_libs: ["whole_static_lib_for_shared"], }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library_static { name: "static_dep_for_shared" } cc_library_static { name: "static_dep_for_shared", bazel_module: { bp2build_available: false }, } cc_library_static { name: "static_dep_for_static" } cc_library_static { name: "static_dep_for_static", bazel_module: { bp2build_available: false }, } cc_library_static { name: "static_dep_for_both" } cc_library_static { name: "static_dep_for_both", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_shared" } cc_library_static { name: "whole_static_lib_for_shared", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_static" } cc_library_static { name: "whole_static_lib_for_static", bazel_module: { bp2build_available: false }, } cc_library_static { name: "whole_static_lib_for_both" } cc_library_static { name: "whole_static_lib_for_both", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_shared" } cc_library { name: "shared_dep_for_shared", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_static" } cc_library { name: "shared_dep_for_static", bazel_module: { bp2build_available: false }, } cc_library { name: "shared_dep_for_both" } cc_library { name: "shared_dep_for_both", bazel_module: { bp2build_available: false }, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "bothflag", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], copts = ["bothflag"], dynamic_deps = [":shared_dep_for_both"], implementation_deps = [":static_dep_for_both"], shared = { Loading Loading @@ -374,6 +391,7 @@ cc_library { whole_static_libs: ["whole_static_lib_for_shared"], }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } Loading @@ -386,10 +404,6 @@ cc_prebuilt_library_static { name: "whole_static_lib_for_both" } blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], shared = { "whole_archive_deps": [":whole_static_lib_for_shared_alwayslink"], }, Loading Loading @@ -693,16 +707,13 @@ cc_library { srcs: ["a.cpp"], version_script: "v.map", bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = "v.map", )`}, Loading Loading @@ -731,16 +742,13 @@ func TestCcLibraryConfiguredVersionScript(t *testing.T) { }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = select({ "//build/bazel/platforms/arch:arm": "arm.map", Loading @@ -757,35 +765,21 @@ func TestCcLibrarySharedLibs(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "mylib", bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: false }, } cc_library { name: "a", shared_libs: ["mylib",], bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], dynamic_deps = [":mylib"], )`, `cc_library( name = "mylib", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) } Loading @@ -796,14 +790,12 @@ func TestCcLibraryPackRelocations(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["a.cpp"], pack_relocations: false, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { Loading @@ -814,7 +806,7 @@ cc_library { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { Loading @@ -825,24 +817,14 @@ cc_library { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, }`, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = ["-Wl,--pack-dyn-relocs=none"], srcs = ["a.cpp"], )`, `cc_library( name = "b", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = select({ "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], Loading @@ -850,10 +832,6 @@ cc_library { srcs = ["b.cpp"], )`, `cc_library( name = "c", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], linkopts = select({ "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], Loading @@ -869,24 +847,18 @@ func TestCcLibrarySpacesInCopts(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", cflags: ["-include header.h",], bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-include", "header.h", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) Loading @@ -898,14 +870,10 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": `cc_library { blueprint: soongCcLibraryPreamble + `cc_library { name: "a", srcs: ["a.cpp"], cflags: [ "-Wall", ], cflags: ["-Wall"], cppflags: [ "-fsigned-char", "-pedantic", Loading @@ -920,18 +888,12 @@ func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { cppflags: ["-DANDROID=1"], }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Wall", "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], copts = ["-Wall"], cppflags = [ "-fsigned-char", "-pedantic", Loading @@ -953,9 +915,7 @@ func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "a", srcs: ["a.cpp"], Loading @@ -967,18 +927,11 @@ func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { version_script: "linux_bionic_arm64.map", }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], srcs = ["a.cpp"], version_script = select({ "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", Loading Loading @@ -1031,6 +984,7 @@ cc_library { ], }, }, include_build_directory: false, } cc_library { Loading Loading @@ -1071,10 +1025,6 @@ cc_library { expectedBazelTargets: []string{ `cc_library( name = "foo_static", copts = [ "-I.", "-I$(BINDIR)/.", ], dynamic_deps = select({ "//build/bazel/platforms/arch:arm": [], "//conditions:default": [":arm_shared_lib_excludes"], Loading Loading @@ -1117,14 +1067,11 @@ cc_library { name: "foo-lib", srcs: ["impl.cpp"], no_libcrt: true, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = False, )`}}) Loading @@ -1144,14 +1091,11 @@ cc_library { name: "foo-lib", srcs: ["impl.cpp"], no_libcrt: false, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = True, )`}}) Loading @@ -1166,7 +1110,6 @@ func TestCCLibraryNoCrtArchVariant(t *testing.T) { "impl.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "some-headers" } cc_library { name: "foo-lib", srcs: ["impl.cpp"], Loading @@ -1178,14 +1121,11 @@ cc_library { no_libcrt: true, }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = select({ "//build/bazel/platforms/arch:arm": False, Loading @@ -1204,7 +1144,6 @@ func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { "impl.cpp": "", }, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "some-headers" } cc_library { name: "foo-lib", srcs: ["impl.cpp"], Loading @@ -1217,14 +1156,11 @@ cc_library { no_libcrt: true, }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], srcs = ["impl.cpp"], use_libcrt = select({ "//build/bazel/platforms/arch:arm": False, Loading @@ -1240,102 +1176,74 @@ func TestCcLibraryStrip(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "nothing", bazel_module: { bp2build_available: true }, include_build_directory: false, } cc_library { name: "keep_symbols", bazel_module: { bp2build_available: true }, strip: { keep_symbols: true, } }, include_build_directory: false, } cc_library { name: "keep_symbols_and_debug_frame", bazel_module: { bp2build_available: true }, strip: { keep_symbols_and_debug_frame: true, } }, include_build_directory: false, } cc_library { name: "none", bazel_module: { bp2build_available: true }, strip: { none: true, } }, include_build_directory: false, } cc_library { name: "keep_symbols_list", bazel_module: { bp2build_available: true }, strip: { keep_symbols_list: ["symbol"], } }, include_build_directory: false, } cc_library { name: "all", bazel_module: { bp2build_available: true }, strip: { all: true, } }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "all", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "all": True, }, )`, `cc_library( name = "keep_symbols", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols": True, }, )`, `cc_library( name = "keep_symbols_and_debug_frame", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols_and_debug_frame": True, }, )`, `cc_library( name = "keep_symbols_list", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols_list": ["symbol"], }, )`, `cc_library( name = "none", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "none": True, }, )`, `cc_library( name = "nothing", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], )`}, }) } Loading @@ -1346,12 +1254,9 @@ func TestCcLibraryStripWithArch(t *testing.T) { moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` blueprint: soongCcLibraryPreamble + ` cc_library { name: "multi-arch", bazel_module: { bp2build_available: true }, target: { darwin: { strip: { Loading @@ -1370,17 +1275,12 @@ cc_library { keep_symbols: true, }, }, } }, include_build_directory: false, } `, }, blueprint: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "multi-arch", copts = [ "-Ifoo/bar", "-I$(BINDIR)/foo/bar", ], strip = { "keep_symbols": select({ "//build/bazel/platforms/arch:arm64": True, Loading Loading @@ -1412,14 +1312,11 @@ func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { cc_library { name: "root_empty", system_shared_libs: [], include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "root_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1437,14 +1334,11 @@ cc_library { static: { system_shared_libs: [], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "static_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], static = { "system_dynamic_deps": [], }, Loading @@ -1464,14 +1358,11 @@ cc_library { shared: { system_shared_libs: [], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "shared_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [], }, Loading @@ -1495,14 +1386,11 @@ cc_library { } } }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "shared_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [], }, Loading @@ -1528,14 +1416,11 @@ cc_library { system_shared_libs: [], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "target_linux_bionic_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1555,14 +1440,11 @@ cc_library { system_shared_libs: [], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "target_bionic_empty", copts = [ "-I.", "-I$(BINDIR)/.", ], system_dynamic_deps = [], )`}, }) Loading @@ -1575,8 +1457,14 @@ func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, blueprint: soongCcLibraryPreamble + ` cc_library {name: "libc"} cc_library {name: "libm"} cc_library { name: "libc", bazel_module: { bp2build_available: false }, } cc_library { name: "libm", bazel_module: { bp2build_available: false }, } cc_library { name: "foo", Loading @@ -1584,30 +1472,15 @@ cc_library { shared: { system_shared_libs: ["libm"], }, include_build_directory: false, } `, expectedBazelTargets: []string{`cc_library( name = "foo", copts = [ "-I.", "-I$(BINDIR)/.", ], shared = { "system_dynamic_deps": [":libm"], }, system_dynamic_deps = [":libc"], )`, `cc_library( name = "libc", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library( name = "libm", copts = [ "-I.", "-I$(BINDIR)/.", ], )`}, }) }
bp2build/cc_library_headers_conversion_test.go +57 −106 Original line number Diff line number Diff line Loading @@ -99,11 +99,13 @@ func TestCcLibraryHeadersSimple(t *testing.T) { cc_library_headers { name: "lib-1", export_include_dirs: ["lib-1"], bazel_module: { bp2build_available: false }, } cc_library_headers { name: "lib-2", export_include_dirs: ["lib-2"], bazel_module: { bp2build_available: false }, } cc_library_headers { Loading Loading @@ -145,25 +147,11 @@ cc_library_headers { ":lib-1", ":lib-2", ], )`, `cc_library_headers( name = "lib-1", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-1"], )`, `cc_library_headers( name = "lib-2", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-2"], )`}, }) } func TestCcLibraryHeadersOSSpecificHeader(t *testing.T) { func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { runCcLibraryHeadersTestCase(t, bp2buildTestCase{ description: "cc_library_headers test with os-specific header_libs props", moduleTypeUnderTest: "cc_library_headers", Loading @@ -171,12 +159,30 @@ func TestCcLibraryHeadersOSSpecificHeader(t *testing.T) { moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, filesystem: map[string]string{}, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib" } cc_library_headers { name: "base-lib" } cc_library_headers { name: "darwin-lib" } cc_library_headers { name: "linux-lib" } cc_library_headers { name: "linux_bionic-lib" } cc_library_headers { name: "windows-lib" } cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "base-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "darwin-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "linux-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "linux_bionic-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "windows-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "foo_headers", header_libs: ["base-lib"], Loading @@ -187,32 +193,10 @@ cc_library_headers { linux_glibc: { header_libs: ["linux-lib"] }, windows: { header_libs: ["windows-lib"] }, }, bazel_module: { bp2build_available: true }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "android-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "base-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "darwin-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], implementation_deps = [":base-lib"] + select({ "//build/bazel/platforms/os:android": [":android-lib"], "//build/bazel/platforms/os:darwin": [":darwin-lib"], Loading @@ -221,24 +205,6 @@ cc_library_headers { "//build/bazel/platforms/os:windows": [":windows-lib"], "//conditions:default": [], }), )`, `cc_library_headers( name = "linux-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "linux_bionic-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "windows-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`}, }) } Loading @@ -251,32 +217,23 @@ func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, filesystem: map[string]string{}, blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib" } cc_library_headers { name: "exported-lib" } cc_library_headers { name: "android-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "exported-lib", bazel_module: { bp2build_available: false }, } cc_library_headers { name: "foo_headers", target: { android: { header_libs: ["android-lib"], export_header_lib_headers: ["exported-lib"] }, }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "android-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "exported-lib", copts = [ "-I.", "-I$(BINDIR)/.", ], )`, `cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], deps = select({ "//build/bazel/platforms/os:android": [":exported-lib"], "//conditions:default": [], Loading Loading @@ -330,13 +287,10 @@ func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { ], }, }, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "foo_headers", copts = [ "-I.", "-I$(BINDIR)/.", ], export_system_includes = ["shared_include_dir"] + select({ "//build/bazel/platforms/arch:arm": ["arm_include_dir"], "//build/bazel/platforms/arch:x86_64": ["x86_64_include_dir"], Loading Loading @@ -375,13 +329,10 @@ cc_library_headers { name: "lib-1", export_include_dirs: ["lib-1"], no_libcrt: true, include_build_directory: false, }`, expectedBazelTargets: []string{`cc_library_headers( name = "lib-1", copts = [ "-I.", "-I$(BINDIR)/.", ], export_includes = ["lib-1"], )`}, }) Loading
bp2build/cc_library_static_conversion_test.go +125 −269 File changed.Preview size limit exceeded, changes collapsed. Show changes
bp2build/cc_object_conversion_test.go +10 −29 Original line number Diff line number Diff line Loading @@ -78,14 +78,12 @@ func TestCcObjectSimple(t *testing.T) { func TestCcObjectDefaults(t *testing.T) { runCcObjectTestCase(t, bp2buildTestCase{ description: "simple cc_object with defaults", moduleTypeUnderTest: "cc_object", moduleTypeUnderTestFactory: cc.ObjectFactory, moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, blueprint: `cc_object { name: "foo", system_shared_libs: [], local_include_dirs: ["include"], srcs: [ "a/b/*.h", "a/b/c.c" Loading Loading @@ -115,8 +113,6 @@ cc_defaults { "-Wall", "-Werror", "-fno-addrsig", "-Iinclude", "-I$(BINDIR)/include", "-I.", "-I$(BINDIR)/.", ], Loading @@ -140,29 +136,23 @@ func TestCcObjectCcObjetDepsInObjs(t *testing.T) { system_shared_libs: [], srcs: ["a/b/c.c"], objs: ["bar"], include_build_directory: false, } cc_object { name: "bar", system_shared_libs: [], srcs: ["x/y/z.c"], include_build_directory: false, } `, expectedBazelTargets: []string{`cc_object( name = "bar", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ], copts = ["-fno-addrsig"], srcs = ["x/y/z.c"], )`, `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ], copts = ["-fno-addrsig"], deps = [":bar"], srcs = ["a/b/c.c"], )`, Loading Loading @@ -245,16 +235,13 @@ func TestCcObjectCflagsOneArch(t *testing.T) { srcs: ["arch/arm/file.cpp"], // label list }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:x86": ["-fPIC"], "//conditions:default": [], }), Loading Loading @@ -295,16 +282,13 @@ func TestCcObjectCflagsFourArch(t *testing.T) { cflags: ["-Wall"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/arch:arm": ["-Wall"], "//build/bazel/platforms/arch:arm64": ["-Wall"], "//build/bazel/platforms/arch:x86": ["-fPIC"], Loading Loading @@ -344,16 +328,13 @@ func TestCcObjectCflagsMultiOs(t *testing.T) { cflags: ["-Wall"], }, }, include_build_directory: false, } `, expectedBazelTargets: []string{ `cc_object( name = "foo", copts = [ "-fno-addrsig", "-I.", "-I$(BINDIR)/.", ] + select({ copts = ["-fno-addrsig"] + select({ "//build/bazel/platforms/os:android": ["-fPIC"], "//build/bazel/platforms/os:darwin": ["-Wall"], "//build/bazel/platforms/os:windows": ["-fPIC"], Loading