diff options
author | 2023-01-19 15:36:52 -0500 | |
---|---|---|
committer | 2023-01-25 15:14:03 -0500 | |
commit | 4e115cc90de936fd68ce162c847370df5fb5021c (patch) | |
tree | 6cad36e0b5f4640ba68a941dbc1e3c17055771e6 /cc | |
parent | ba46e7662221801867534444e64928f438511a5b (diff) |
add androidmk cc-related variables to androidmk
The adbd_test androidmk definition is missing some cc-related variables
for cc_test in mixed builds. These variables should be populated from
information from Bazel.
Bug: 265758350
Change-Id: I59d017e2eb2f139188ba3383c457cc0055372b61
Diffstat (limited to 'cc')
-rw-r--r-- | cc/cc.go | 11 | ||||
-rw-r--r-- | cc/cc_test.go | 177 |
2 files changed, 187 insertions, 1 deletions
@@ -1870,7 +1870,8 @@ var ( // in any of the --bazel-mode(s). This filters at the module level and takes // precedence over the allowlists in allowlists/allowlists.go. func (c *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { - if c.testBinary() && !android.InList(c.Name(), mixedBuildSupportedCcTest) { + _, isForTesting := ctx.Config().BazelContext.(android.MockBazelContext) + if c.testBinary() && !android.InList(c.Name(), mixedBuildSupportedCcTest) && !isForTesting { // Per-module rollout of mixed-builds for cc_test modules. return false } @@ -1888,6 +1889,14 @@ func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) { bazelCtx := ctx.Config().BazelContext if ccInfo, err := bazelCtx.GetCcInfo(bazelModuleLabel, android.GetConfigKey(ctx)); err == nil { c.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles) + c.Properties.AndroidMkSharedLibs = ccInfo.LocalSharedLibs + c.Properties.AndroidMkStaticLibs = ccInfo.LocalStaticLibs + c.Properties.AndroidMkWholeStaticLibs = ccInfo.LocalWholeStaticLibs + } + if unstrippedInfo, err := bazelCtx.GetCcUnstrippedInfo(bazelModuleLabel, android.GetConfigKey(ctx)); err == nil { + c.Properties.AndroidMkSharedLibs = unstrippedInfo.LocalSharedLibs + c.Properties.AndroidMkStaticLibs = unstrippedInfo.LocalStaticLibs + c.Properties.AndroidMkWholeStaticLibs = unstrippedInfo.LocalWholeStaticLibs } c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel) diff --git a/cc/cc_test.go b/cc/cc_test.go index 8293f2db7..39cc0730c 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -25,6 +25,7 @@ import ( "testing" "android/soong/android" + "android/soong/bazel/cquery" ) func TestMain(m *testing.M) { @@ -3028,6 +3029,32 @@ func checkStaticLibs(t *testing.T, expected []string, module *Module) { } } +func checkWholeStaticLibs(t *testing.T, expected []string, module *Module) { + t.Helper() + actual := module.Properties.AndroidMkWholeStaticLibs + if !reflect.DeepEqual(actual, expected) { + t.Errorf("incorrect whole_static_libs"+ + "\nactual: %v"+ + "\nexpected: %v", + actual, + expected, + ) + } +} + +func checkSharedLibs(t *testing.T, expected []string, module *Module) { + t.Helper() + actual := module.Properties.AndroidMkSharedLibs + if !reflect.DeepEqual(actual, expected) { + t.Errorf("incorrect shared_libs"+ + "\nactual: %v"+ + "\nexpected: %v", + actual, + expected, + ) + } +} + const staticLibAndroidBp = ` cc_library { name: "lib1", @@ -3054,6 +3081,156 @@ func TestStaticLibDepExport(t *testing.T) { checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module) } +func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) { + bp := ` + cc_library { + name: "static_dep", + } + cc_library { + name: "whole_static_dep", + } + cc_library { + name: "shared_dep", + } + cc_library { + name: "lib", + bazel_module: { label: "//:lib" }, + static_libs: ["static_dep"], + whole_static_libs: ["whole_static_dep"], + shared_libs: ["shared_dep"], + } + cc_test { + name: "test", + bazel_module: { label: "//:test" }, + static_libs: ["static_dep"], + whole_static_libs: ["whole_static_dep"], + shared_libs: ["shared_dep"], + gtest: false, + } + cc_binary { + name: "binary", + bazel_module: { label: "//:binary" }, + static_libs: ["static_dep"], + whole_static_libs: ["whole_static_dep"], + shared_libs: ["shared_dep"], + } + ` + + testCases := []struct { + name string + moduleName string + variant string + androidMkInfo cquery.CcAndroidMkInfo + }{ + { + name: "shared lib", + moduleName: "lib", + variant: "android_arm64_armv8-a_shared", + androidMkInfo: cquery.CcAndroidMkInfo{ + LocalStaticLibs: []string{"static_dep"}, + LocalWholeStaticLibs: []string{"whole_static_dep"}, + LocalSharedLibs: []string{"shared_dep"}, + }, + }, + { + name: "static lib", + moduleName: "lib", + variant: "android_arm64_armv8-a_static", + androidMkInfo: cquery.CcAndroidMkInfo{ + LocalStaticLibs: []string{"static_dep"}, + LocalWholeStaticLibs: []string{"whole_static_dep"}, + LocalSharedLibs: []string{"shared_dep"}, + }, + }, + { + name: "cc_test arm64", + moduleName: "test", + variant: "android_arm64_armv8-a", + androidMkInfo: cquery.CcAndroidMkInfo{ + LocalStaticLibs: []string{"static_dep"}, + LocalWholeStaticLibs: []string{"whole_static_dep"}, + LocalSharedLibs: []string{"shared_dep"}, + }, + }, + { + name: "cc_test arm", + moduleName: "test", + variant: "android_arm_armv7-a-neon", + androidMkInfo: cquery.CcAndroidMkInfo{ + LocalStaticLibs: []string{"static_dep"}, + LocalWholeStaticLibs: []string{"whole_static_dep"}, + LocalSharedLibs: []string{"shared_dep"}, + }, + }, + { + name: "cc_binary", + moduleName: "binary", + variant: "android_arm64_armv8-a", + androidMkInfo: cquery.CcAndroidMkInfo{ + LocalStaticLibs: []string{"static_dep"}, + LocalWholeStaticLibs: []string{"whole_static_dep"}, + LocalSharedLibs: []string{"shared_dep"}, + }, + }, + } + + outputBaseDir := "out/bazel" + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForCcTest, + android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: outputBaseDir, + LabelToCcInfo: map[string]cquery.CcInfo{ + "//:lib": cquery.CcInfo{ + CcAndroidMkInfo: tc.androidMkInfo, + RootDynamicLibraries: []string{""}, + }, + "//:lib_bp2build_cc_library_static": cquery.CcInfo{ + CcAndroidMkInfo: tc.androidMkInfo, + RootStaticArchives: []string{""}, + }, + }, + LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{ + "//:test": cquery.CcUnstrippedInfo{ + CcAndroidMkInfo: tc.androidMkInfo, + }, + "//:binary": cquery.CcUnstrippedInfo{ + CcAndroidMkInfo: tc.androidMkInfo, + }, + }, + } + }), + ).RunTestWithBp(t, bp) + ctx := result.TestContext + + module := ctx.ModuleForTests(tc.moduleName, tc.variant).Module().(*Module) + entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] + checkStaticLibs(t, tc.androidMkInfo.LocalStaticLibs, module) + missingStaticDeps := android.ListDifference(entries.EntryMap["LOCAL_STATIC_LIBRARIES"], tc.androidMkInfo.LocalStaticLibs) + if len(missingStaticDeps) > 0 { + t.Errorf("expected LOCAL_STATIC_LIBRARIES to be %q"+ + " but was %q; difference: %q", tc.androidMkInfo.LocalStaticLibs, entries.EntryMap["LOCAL_STATIC_LIBRARIES"], missingStaticDeps) + } + + checkWholeStaticLibs(t, tc.androidMkInfo.LocalWholeStaticLibs, module) + missingWholeStaticDeps := android.ListDifference(entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], tc.androidMkInfo.LocalWholeStaticLibs) + if len(missingWholeStaticDeps) > 0 { + t.Errorf("expected LOCAL_WHOLE_STATIC_LIBRARIES to be %q"+ + " but was %q; difference: %q", tc.androidMkInfo.LocalWholeStaticLibs, entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], missingWholeStaticDeps) + } + + checkSharedLibs(t, tc.androidMkInfo.LocalSharedLibs, module) + missingSharedDeps := android.ListDifference(entries.EntryMap["LOCAL_SHARED_LIBRARIES"], tc.androidMkInfo.LocalSharedLibs) + if len(missingSharedDeps) > 0 { + t.Errorf("expected LOCAL_SHARED_LIBRARIES to be %q"+ + " but was %q; difference: %q", tc.androidMkInfo.LocalSharedLibs, entries.EntryMap["LOCAL_SHARED_LIBRARIES"], missingSharedDeps) + } + }) + } +} + var compilerFlagsTestCases = []struct { in string out bool |