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
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 8293f2d..39cc073 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -25,6 +25,7 @@
"testing"
"android/soong/android"
+ "android/soong/bazel/cquery"
)
func TestMain(m *testing.M) {
@@ -3028,6 +3029,32 @@
}
}
+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 @@
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