diff options
author | 2023-10-06 21:35:21 +0000 | |
---|---|---|
committer | 2023-10-09 18:07:39 +0000 | |
commit | 17a27f0c143bd3482ecbb0f516d7f117290b464d (patch) | |
tree | e41ba67b1294adf23f5c6d5fa696764fc5374534 | |
parent | 69cf8a3221e8ced4f86d915bb4800a775a36c8ab (diff) |
Replace ndk_libs.bzl with an attr in cc_stub_suite
(This CL is a cleanup, and should be a no-op)
Currently we support three variations of cc api stubs.
1. publicapi stubs, i.e. ndk stubs (empty additional args to ndkstubgen)
2. module-libapi stubs that are also an ndk library (--systemapi --apex)
3. module-libapi stubs that are not an ndk library (--systemapi --apex
--no-ndk)
ndk_libs.bzl was used to differentiate between (2) and (3). This creates
an additional layer of indirection - users will need to modify this
external .bzl file if they would like to add a library to an ndk.
Replace this with an explicit atttibute in cc_stub_suite macro for better UX.
Test: go test ./bp2build
Test: b test //build/bazel/rules/cc:cc_stub_library_tests (added in
sibling CL)
Bug: 299501496
Change-Id: Idd3579e8013bae7a1740534f90d2767df5bac1a5
-rw-r--r-- | bp2build/cc_library_conversion_test.go | 59 | ||||
-rw-r--r-- | bp2build/conversion.go | 11 | ||||
-rw-r--r-- | bp2build/conversion_test.go | 4 | ||||
-rw-r--r-- | cc/library.go | 11 | ||||
-rw-r--r-- | cc/ndk_library.go | 7 |
5 files changed, 74 insertions, 18 deletions
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 5c9cbf24c..d19859645 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -5178,6 +5178,7 @@ ndk_library { ExpectedBazelTargets: []string{ MakeBazelTarget("cc_stub_suite", "libfoo.ndk_stub_libs", AttrNameToString{ "api_surface": `"publicapi"`, + "included_in_ndk": `True`, "soname": `"libfoo.so"`, "source_library_label": `"//:libfoo"`, "symbol_file": `"libfoo.map.txt"`, @@ -5305,3 +5306,61 @@ cc_library_static { }, }) } + +func TestPropertiesIfStubLibraryIsInNdk(t *testing.T) { + tc := Bp2buildTestCase{ + Description: "If an equivalent ndk_library exists, set included_in_ndk=true for module-libapi stubs", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: ` +// libfoo is an ndk library and contributes to module-libapi +cc_library { + name: "libfoo", + stubs: {symbol_file: "libfoo.map.txt"}, +} +ndk_library { + name: "libfoo", + first_version: "29", + symbol_file: "libfoo.map.txt", +} +// libbar is not an ndk library, but contributes to module-libapi +cc_library { + name: "libbar", + stubs: {symbol_file: "libbar.map.txt"}, +} +`, + StubbedBuildDefinitions: []string{"libfoo.ndk"}, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "libfoo_bp2build_cc_library_static", AttrNameToString{ + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_shared", "libfoo", AttrNameToString{ + "local_includes": `["."]`, + "stubs_symbol_file": `"libfoo.map.txt"`, + }), + MakeBazelTarget("cc_stub_suite", "libfoo_stub_libs", AttrNameToString{ + "api_surface": `"module-libapi"`, + "soname": `"libfoo.so"`, + "source_library_label": `"//:libfoo"`, + "symbol_file": `"libfoo.map.txt"`, + "versions": `["current"]`, + "included_in_ndk": `True`, + }), + MakeBazelTarget("cc_library_static", "libbar_bp2build_cc_library_static", AttrNameToString{ + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_shared", "libbar", AttrNameToString{ + "local_includes": `["."]`, + "stubs_symbol_file": `"libbar.map.txt"`, + }), + MakeBazelTarget("cc_stub_suite", "libbar_stub_libs", AttrNameToString{ + "api_surface": `"module-libapi"`, + "soname": `"libbar.so"`, + "source_library_label": `"//:libbar"`, + "symbol_file": `"libbar.map.txt"`, + "versions": `["current"]`, + }), + }, + } + runCcLibraryTestCase(t, tc) +} diff --git a/bp2build/conversion.go b/bp2build/conversion.go index c69723587..b2792e6cf 100644 --- a/bp2build/conversion.go +++ b/bp2build/conversion.go @@ -15,7 +15,6 @@ import ( rust_config "android/soong/rust/config" "android/soong/starlark_fmt" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -34,19 +33,9 @@ func createSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) ( files = append(files, newFile("android", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package. files = append(files, newFile("android", "constants.bzl", android.BazelCcToolchainVars(cfg))) - // Visit all modules to determine the list of ndk libraries - // This list will be used to add additional flags for cc stub generation - ndkLibsStringFormatted := []string{} - ctx.Context().VisitAllModules(func(m blueprint.Module) { - if ctx.Context().ModuleType(m) == "ndk_library" { - ndkLibsStringFormatted = append(ndkLibsStringFormatted, fmt.Sprintf(`"%s"`, m.Name())) // name will be `"libc.ndk"` - } - }) - files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package. files = append(files, newFile("cc_toolchain", "config_constants.bzl", cc_config.BazelCcToolchainVars(cfg))) files = append(files, newFile("cc_toolchain", "sanitizer_constants.bzl", cc.BazelCcSanitizerToolchainVars(cfg))) - files = append(files, newFile("cc_toolchain", "ndk_libs.bzl", fmt.Sprintf("ndk_libs = [%v]", strings.Join(ndkLibsStringFormatted, ", ")))) files = append(files, newFile("java_toolchain", GeneratedBuildFileName, "")) // Creates a //java_toolchain package. files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg))) diff --git a/bp2build/conversion_test.go b/bp2build/conversion_test.go index 6b100772c..51675ce5e 100644 --- a/bp2build/conversion_test.go +++ b/bp2build/conversion_test.go @@ -107,10 +107,6 @@ func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) { }, { dir: "cc_toolchain", - basename: "ndk_libs.bzl", - }, - { - dir: "cc_toolchain", basename: "sanitizer_constants.bzl", }, { diff --git a/cc/library.go b/cc/library.go index 6acd7ae56..21615121d 100644 --- a/cc/library.go +++ b/cc/library.go @@ -500,6 +500,10 @@ func createStubsBazelTargetIfNeeded(ctx android.Bp2buildMutatorContext, m *Modul Deps: baseAttributes.deps, Api_surface: proptools.StringPtr("module-libapi"), } + if _, isNdk := ctx.ModuleFromName(m.Name() + ".ndk"); isNdk { + stubSuitesAttrs.Included_in_ndk = proptools.BoolPtr(true) + } + ctx.CreateBazelTargetModule(stubSuitesProps, android.CommonAttributes{ Name: m.Name() + "_stub_libs", // TODO: b/303307456 - Remove this when data is properly supported in cc rules. @@ -3023,6 +3027,13 @@ type bazelCcStubSuiteAttributes struct { Soname *string Deps bazel.LabelListAttribute Api_surface *string + + // Unless the library is in the NDK, module-libapi stubs should *not* include the public symbols + // Soong uses a global variable to determine if the library is in the NDK + // Since Bazel does not have global analysis, create an explicit property + // This property is only relevant if `api_surface = module-libapi` + // https://cs.android.com/android/_/android/platform/build/soong/+/main:cc/library.go;l=1214-1219;drc=7123cc5370a38983ee6325b5f5f6df19f4e4f10b;bpv=1;bpt=0 + Included_in_ndk *bool } type bazelCcHeaderAbiCheckerAttributes struct { diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 49365598f..df775de3e 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -594,9 +594,10 @@ func ndkLibraryBp2build(ctx android.Bp2buildMutatorContext, c *Module) { symbolFileLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(ndk.properties.Symbol_file)) attrs := &bazelCcStubSuiteAttributes{ // TODO - b/300504837 Add ndk headers - Symbol_file: proptools.StringPtr(symbolFileLabel.Label), - Soname: proptools.StringPtr(sourceLibraryName + ".so"), - Api_surface: proptools.StringPtr(android.PublicApi.String()), + Symbol_file: proptools.StringPtr(symbolFileLabel.Label), + Soname: proptools.StringPtr(sourceLibraryName + ".so"), + Api_surface: proptools.StringPtr(android.PublicApi.String()), + Included_in_ndk: proptools.BoolPtr(true), } if sourceLibrary, exists := ctx.ModuleFromName(sourceLibraryName); exists { // the source library might not exist in minimal/unbuildable branches like kernel-build-tools. |