Add bp2build converter for cc library stubs and use the stub library target of a library while linking it in APEXs.
Bug: 231322789
Test: with this CL on internal master,
1) b build --verbose_failures //vendor/google/modules/AdbdGoogle:com.google.android.adbd --config=android_x86_64
2) adb install bazel-bin/vendor/google/modules/AdbdGoogle/com.google.android.adbd.apex, and adbd is activated successfully on cuttlefish device.
3) m mts && mts-tradefed run mts-adbd, and there is no failure with cuttlefish device
4) packages/modules/adb/test_device.py, and there is no failure with cuttlefish device.
Change-Id: I81b6f5336cacf35c68957ae2dac65f985b6eafb9
diff --git a/cc/library.go b/cc/library.go
index 41dca01..709dfef 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -392,9 +392,11 @@
None: linkerAttrs.stripNone,
},
Features: linkerAttrs.features,
+ }
- Stubs_symbol_file: compilerAttrs.stubsSymbolFile,
- Stubs_versions: compilerAttrs.stubsVersions,
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ hasStubs := true
+ sharedTargetAttrs.Has_stubs.SetValue(&hasStubs)
}
for axis, configToProps := range m.GetArchVariantProperties(ctx, &LibraryProperties{}) {
@@ -427,6 +429,25 @@
ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
android.CommonAttributes{Name: m.Name()},
sharedTargetAttrs, sharedAttrs.Enabled)
+
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ stubSuitesProps := bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_stub_suite",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
+ }
+ soname := m.Name() + ".so"
+ stubSuitesAttrs := &bazelCcStubSuiteAttributes{
+ Symbol_file: compilerAttrs.stubsSymbolFile,
+ Versions: compilerAttrs.stubsVersions,
+ Export_includes: exportedIncludes.Includes,
+ Soname: &soname,
+ Source_library: *bazel.MakeLabelAttribute(":" + m.Name()),
+ Deps: baseAttributes.deps,
+ }
+ ctx.CreateBazelTargetModule(stubSuitesProps,
+ android.CommonAttributes{Name: m.Name() + "_stub_libs"},
+ stubSuitesAttrs)
+ }
}
// cc_library creates both static and/or shared libraries for a device and/or
@@ -2584,7 +2605,7 @@
} else {
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
- attrs = &bazelCcLibrarySharedAttributes{
+ sharedLibAttrs := &bazelCcLibrarySharedAttributes{
staticOrSharedAttributes: commonAttrs,
Cppflags: compilerAttrs.cppFlags,
@@ -2617,10 +2638,12 @@
},
Features: linkerAttrs.features,
-
- Stubs_symbol_file: compilerAttrs.stubsSymbolFile,
- Stubs_versions: compilerAttrs.stubsVersions,
}
+ if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
+ hasStubs := true
+ sharedLibAttrs.Has_stubs.SetValue(&hasStubs)
+ }
+ attrs = sharedLibAttrs
}
var modType string
@@ -2694,7 +2717,16 @@
Features bazel.StringListAttribute
- Stubs_symbol_file *string
- Stubs_versions bazel.StringListAttribute
- Inject_bssl_hash bazel.BoolAttribute
+ Has_stubs bazel.BoolAttribute
+
+ Inject_bssl_hash bazel.BoolAttribute
+}
+
+type bazelCcStubSuiteAttributes struct {
+ Symbol_file *string
+ Versions bazel.StringListAttribute
+ Export_includes bazel.StringListAttribute
+ Source_library bazel.LabelAttribute
+ Soname *string
+ Deps bazel.LabelListAttribute
}