Merge "Remove 6 install related fields from ModuleBase." into main
diff --git a/apex/apex.go b/apex/apex.go
index 6286be3..2feaaee 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2230,6 +2230,10 @@
addAconfigFiles(vctx, ctx, child)
return true // track transitive dependencies
} else if rm, ok := child.(*rust.Module); ok {
+ if !android.IsDepInSameApex(ctx, am, am) {
+ return false
+ }
+
af := apexFileForRustLibrary(ctx, rm)
af.transitiveDep = true
vctx.filesInfo = append(vctx.filesInfo, af)
@@ -2249,6 +2253,10 @@
}
} else if rust.IsDylibDepTag(depTag) {
if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() {
+ if !android.IsDepInSameApex(ctx, am, am) {
+ return false
+ }
+
af := apexFileForRustLibrary(ctx, rustm)
af.transitiveDep = true
vctx.filesInfo = append(vctx.filesInfo, af)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 6b9944d..8d34e9f 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -906,7 +906,7 @@
cc_library {
name: "mylib",
srcs: ["mylib.cpp"],
- shared_libs: ["mylib2", "mylib3"],
+ shared_libs: ["mylib2", "mylib3", "my_prebuilt_platform_lib", "my_prebuilt_platform_stub_only_lib"],
system_shared_libs: [],
stl: "none",
apex_available: [ "myapex" ],
@@ -919,6 +919,7 @@
system_shared_libs: [],
stl: "none",
stubs: {
+ symbol_file: "mylib2.map.txt",
versions: ["1", "2", "3"],
},
}
@@ -930,6 +931,7 @@
system_shared_libs: [],
stl: "none",
stubs: {
+ symbol_file: "mylib3.map.txt",
versions: ["10", "11", "12"],
},
apex_available: [ "myapex" ],
@@ -943,6 +945,24 @@
apex_available: [ "myapex" ],
}
+ cc_prebuilt_library_shared {
+ name: "my_prebuilt_platform_lib",
+ stubs: {
+ symbol_file: "my_prebuilt_platform_lib.map.txt",
+ versions: ["1", "2", "3"],
+ },
+ srcs: ["foo.so"],
+ }
+
+ // Similar to my_prebuilt_platform_lib, but this library only provides stubs, i.e. srcs is empty
+ cc_prebuilt_library_shared {
+ name: "my_prebuilt_platform_stub_only_lib",
+ stubs: {
+ symbol_file: "my_prebuilt_platform_stub_only_lib.map.txt",
+ versions: ["1", "2", "3"],
+ }
+ }
+
rust_binary {
name: "foo.rust",
srcs: ["foo.rs"],
@@ -1022,6 +1042,20 @@
apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.shared_from_rust.so")
+
+ // Ensure that mylib is linking with the latest version of stubs for my_prebuilt_platform_lib
+ ensureContains(t, mylibLdFlags, "my_prebuilt_platform_lib/android_arm64_armv8-a_shared_current/my_prebuilt_platform_lib.so")
+ // ... and not linking to the non-stub (impl) variant of my_prebuilt_platform_lib
+ ensureNotContains(t, mylibLdFlags, "my_prebuilt_platform_lib/android_arm64_armv8-a_shared/my_prebuilt_platform_lib.so")
+ // Ensure that genstub for platform-provided lib is invoked with --systemapi
+ ensureContains(t, ctx.ModuleForTests("my_prebuilt_platform_lib", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"], "--systemapi")
+
+ // Ensure that mylib is linking with the latest version of stubs for my_prebuilt_platform_lib
+ ensureContains(t, mylibLdFlags, "my_prebuilt_platform_stub_only_lib/android_arm64_armv8-a_shared_current/my_prebuilt_platform_stub_only_lib.so")
+ // ... and not linking to the non-stub (impl) variant of my_prebuilt_platform_lib
+ ensureNotContains(t, mylibLdFlags, "my_prebuilt_platform_stub_only_lib/android_arm64_armv8-a_shared/my_prebuilt_platform_stub_only_lib.so")
+ // Ensure that genstub for platform-provided lib is invoked with --systemapi
+ ensureContains(t, ctx.ModuleForTests("my_prebuilt_platform_stub_only_lib", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"], "--systemapi")
}
func TestApexShouldNotEmbedStubVariant(t *testing.T) {
@@ -1156,6 +1190,7 @@
system_shared_libs: [],
stl: "none",
stubs: {
+ symbol_file: "mylib2.map.txt",
versions: ["28", "29", "30", "current"],
},
min_sdk_version: "28",
@@ -1168,6 +1203,7 @@
system_shared_libs: [],
stl: "none",
stubs: {
+ symbol_file: "mylib3.map.txt",
versions: ["28", "29", "30", "current"],
},
apex_available: [ "myapex" ],
@@ -11940,7 +11976,7 @@
).RunTest(t)
ldRule := result.ModuleForTests("installedlib", "android_arm64_armv8-a_shared").Rule("ld")
- android.AssertStringDoesContain(t, "", ldRule.Args["libFlags"], "android_arm64_armv8-a_shared/libfoo.so")
+ android.AssertStringDoesContain(t, "", ldRule.Args["libFlags"], "android_arm64_armv8-a_shared_current/libfoo.so")
installRules := result.InstallMakeRulesForTesting(t)
diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go
index 920fc0c..17ade1d 100644
--- a/apex/platform_bootclasspath_test.go
+++ b/apex/platform_bootclasspath_test.go
@@ -791,6 +791,128 @@
`)
}
+// Skip bcp_fragment content validation of source apexes if prebuilts are active.
+func TestNonBootJarInPrebuilts(t *testing.T) {
+ testCases := []struct {
+ description string
+ selectedApexContributions string
+ expectedError string
+ }{
+ {
+ description: "source is active",
+ selectedApexContributions: "",
+ expectedError: "in contents must also be declared in PRODUCT_APEX_BOOT_JARS",
+ },
+ {
+ description: "prebuilts are active",
+ selectedApexContributions: "myapex.prebuilt.contributions",
+ expectedError: "", // skip content validation of source bcp fragment
+ },
+ }
+ bp := `
+// Source
+apex {
+ name: "myapex",
+ key: "myapex.key",
+ bootclasspath_fragments: ["apex-fragment"],
+ updatable: false,
+ min_sdk_version: "29",
+}
+
+override_apex {
+ name: "myapex.override", // overrides the min_sdk_version, thereby creating different variants of its transitive deps
+ base: "myapex",
+ min_sdk_version: "34",
+}
+
+apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+}
+
+java_library {
+ name: "foo",
+ srcs: ["b.java"],
+ installable: true,
+ apex_available: ["myapex"],
+ permitted_packages: ["foo"],
+ min_sdk_version: "29",
+}
+
+java_library {
+ name: "bar",
+ srcs: ["b.java"],
+ installable: true,
+ apex_available: ["myapex"],
+ permitted_packages: ["bar"],
+ min_sdk_version: "29",
+}
+
+bootclasspath_fragment {
+ name: "apex-fragment",
+ contents: ["foo", "bar"],
+ apex_available:[ "myapex" ],
+ hidden_api: {
+ split_packages: ["*"],
+ },
+}
+
+platform_bootclasspath {
+ name: "myplatform-bootclasspath",
+ fragments: [{
+ apex: "myapex",
+ module:"apex-fragment",
+ }],
+}
+
+// prebuilts
+prebuilt_apex {
+ name: "myapex",
+ apex_name: "myapex",
+ src: "myapex.apex",
+ exported_bootclasspath_fragments: ["apex-fragment"],
+ }
+
+ prebuilt_bootclasspath_fragment {
+ name: "apex-fragment",
+ contents: ["foo"],
+ hidden_api: {
+ annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv",
+ metadata: "my-bootclasspath-fragment/metadata.csv",
+ index: "my-bootclasspath-fragment/index.csv",
+ stub_flags: "my-bootclasspath-fragment/stub-flags.csv",
+ all_flags: "my-bootclasspath-fragment/all-flags.csv",
+ },
+ }
+ java_import {
+ name: "foo",
+ jars: ["foo.jar"],
+ }
+
+apex_contributions {
+ name: "myapex.prebuilt.contributions",
+ api_domain: "myapex",
+ contents: ["prebuilt_myapex"],
+}
+`
+
+ for _, tc := range testCases {
+ fixture := android.GroupFixturePreparers(
+ prepareForTestWithPlatformBootclasspath,
+ PrepareForTestWithApexBuildComponents,
+ prepareForTestWithMyapex,
+ java.FixtureConfigureApexBootJars("myapex:foo"),
+ android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", tc.selectedApexContributions),
+ )
+ if tc.expectedError != "" {
+ fixture = fixture.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(tc.expectedError))
+ }
+ fixture.RunTestWithBp(t, bp)
+ }
+
+}
+
// Source and prebuilt apex provide different set of boot jars
func TestNonBootJarMissingInPrebuiltFragment(t *testing.T) {
bp := `
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 79e386f..93630db 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -927,7 +927,7 @@
cc_prebuilt_library_shared {
name: "libllndkprebuilt",
- stubs: { versions: ["1", "2"] },
+ stubs: { versions: ["1", "2"] , symbol_file: "libllndkprebuilt.map.txt" },
llndk: {
symbol_file: "libllndkprebuilt.map.txt",
},
diff --git a/cc/library.go b/cc/library.go
index 6017848..65a923a 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -594,43 +594,7 @@
return objs
}
if library.buildStubs() {
- symbolFile := String(library.Properties.Stubs.Symbol_file)
- if symbolFile != "" && !strings.HasSuffix(symbolFile, ".map.txt") {
- ctx.PropertyErrorf("symbol_file", "%q doesn't have .map.txt suffix", symbolFile)
- return Objects{}
- }
- library.stubsSymbolFilePath = android.PathForModuleSrc(ctx, symbolFile)
- // b/239274367 --apex and --systemapi filters symbols tagged with # apex and #
- // systemapi, respectively. The former is for symbols defined in platform libraries
- // and the latter is for symbols defined in APEXes.
- // A single library can contain either # apex or # systemapi, but not both.
- // The stub generator (ndkstubgen) is additive, so passing _both_ of these to it should be a no-op.
- // However, having this distinction helps guard accidental
- // promotion or demotion of API and also helps the API review process b/191371676
- var flag string
- if ctx.Module().(android.ApexModule).NotInPlatform() {
- flag = "--apex"
- } else {
- flag = "--systemapi"
- }
- // b/184712170, unless the lib is an NDK library, exclude all public symbols from
- // the stub so that it is mandated that all symbols are explicitly marked with
- // either apex or systemapi.
- if !ctx.Module().(*Module).IsNdk(ctx.Config()) {
- flag = flag + " --no-ndk"
- }
- nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile,
- android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag)
- objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
- library.versionScriptPath = android.OptionalPathForPath(
- nativeAbiResult.versionScript)
-
- // Parse symbol file to get API list for coverage
- if library.stubsVersion() == "current" && ctx.PrimaryArch() && !ctx.inRecovery() && !ctx.inProduct() && !ctx.inVendor() {
- library.apiListCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
- }
-
- return objs
+ return library.compileModuleLibApiStubs(ctx, flags, deps)
}
srcs := library.baseCompiler.Properties.Srcs.GetOrDefault(ctx, nil)
@@ -681,6 +645,61 @@
return objs
}
+// Compile stubs for the API surface between platform and apex
+// This method will be used by source and prebuilt cc module types.
+func (library *libraryDecorator) compileModuleLibApiStubs(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
+ // TODO (b/275273834): Make this a hard error when the symbol files have been added to module sdk.
+ if library.Properties.Stubs.Symbol_file == nil {
+ return Objects{}
+ }
+ symbolFile := String(library.Properties.Stubs.Symbol_file)
+ library.stubsSymbolFilePath = android.PathForModuleSrc(ctx, symbolFile)
+ // b/239274367 --apex and --systemapi filters symbols tagged with # apex and #
+ // systemapi, respectively. The former is for symbols defined in platform libraries
+ // and the latter is for symbols defined in APEXes.
+ // A single library can contain either # apex or # systemapi, but not both.
+ // The stub generator (ndkstubgen) is additive, so passing _both_ of these to it should be a no-op.
+ // However, having this distinction helps guard accidental
+ // promotion or demotion of API and also helps the API review process b/191371676
+ var flag string
+ if ctx.Module().(android.ApexModule).NotInPlatform() {
+ flag = "--apex"
+ } else {
+ flag = "--systemapi"
+ }
+ // b/184712170, unless the lib is an NDK library, exclude all public symbols from
+ // the stub so that it is mandated that all symbols are explicitly marked with
+ // either apex or systemapi.
+ if !ctx.Module().(*Module).IsNdk(ctx.Config()) &&
+ // the symbol files of libclang libs are autogenerated and do not contain systemapi tags
+ // TODO (spandandas): Update mapfile.py to include #systemapi tag on all symbols
+ !strings.Contains(ctx.ModuleName(), "libclang_rt") {
+ flag = flag + " --no-ndk"
+ }
+ // TODO(b/361303067): Remove this special case if bionic/ projects are added to ART development branches.
+ if isBionic(ctx.baseModuleName()) {
+ // set the flags explicitly for bionic libs.
+ // this is necessary for development in minimal branches which does not contain bionic/*.
+ // In such minimal branches, e.g. on the prebuilt libc stubs
+ // 1. IsNdk will return false (since the ndk_library definition for libc does not exist)
+ // 2. NotInPlatform will return true (since the source com.android.runtime does not exist)
+ flag = "--apex"
+ }
+ nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile,
+ android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag)
+ objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
+
+ library.versionScriptPath = android.OptionalPathForPath(
+ nativeAbiResult.versionScript)
+
+ // Parse symbol file to get API list for coverage
+ if library.stubsVersion() == "current" && ctx.PrimaryArch() && !ctx.inRecovery() && !ctx.inProduct() && !ctx.inVendor() {
+ library.apiListCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
+ }
+
+ return objs
+}
+
type libraryInterface interface {
versionedInterface
@@ -1182,12 +1201,17 @@
return unstrippedOutputFile
}
-func addStubDependencyProviders(ctx ModuleContext) {
+// Visits the stub variants of the library and returns a struct containing the stub .so paths
+func addStubDependencyProviders(ctx ModuleContext) []SharedStubLibrary {
+ stubsInfo := []SharedStubLibrary{}
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
if len(stubs) > 0 {
- var stubsInfo []SharedStubLibrary
for _, stub := range stubs {
- stubInfo, _ := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
+ stubInfo, ok := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
+ // TODO (b/275273834): Make this a hard error when the symbol files have been added to module sdk.
+ if !ok {
+ continue
+ }
flagInfo, _ := android.OtherModuleProvider(ctx, stub, FlagExporterInfoProvider)
stubsInfo = append(stubsInfo, SharedStubLibrary{
Version: moduleLibraryInterface(stub).stubsVersion(),
@@ -1195,11 +1219,14 @@
FlagExporterInfo: flagInfo,
})
}
- android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{
- SharedStubLibraries: stubsInfo,
- IsLLNDK: ctx.IsLlndk(),
- })
+ if len(stubsInfo) > 0 {
+ android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{
+ SharedStubLibraries: stubsInfo,
+ IsLLNDK: ctx.IsLlndk(),
+ })
+ }
}
+ return stubsInfo
}
func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index fb151d8..299fb51 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -16,6 +16,7 @@
import (
"path/filepath"
+ "strings"
"github.com/google/blueprint/proptools"
@@ -95,10 +96,6 @@
return p.libraryDecorator.linkerDeps(ctx, deps)
}
-func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
- return flags
-}
-
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
return p.libraryDecorator.linkerProps()
}
@@ -117,6 +114,30 @@
// TODO(ccross): verify shared library dependencies
srcs := p.prebuiltSrcs(ctx)
+ stubInfo := addStubDependencyProviders(ctx)
+
+ // Stub variants will create a stub .so file from stub .c files
+ if p.buildStubs() && objs.objFiles != nil {
+ // TODO (b/275273834): Make objs.objFiles == nil a hard error when the symbol files have been added to module sdk.
+
+ // The map.txt files of libclang_rt.* contain version information, but the checked in .so files do not.
+ // e.g. libclang_rt.* libs impl
+ // $ nm -D prebuilts/../libclang_rt.hwasan-aarch64-android.so
+ // __hwasan_init
+
+ // stubs generated from .map.txt
+ // $ nm -D out/soong/.intermediates/../<stubs>/libclang_rt.hwasan-aarch64-android.so
+ // __hwasan_init@@LIBCLANG_RT_ASAN
+
+ // Special-case libclang_rt.* libs to account for this discrepancy.
+ // TODO (spandandas): Remove this special case https://r.android.com/3236596 has been submitted, and a new set of map.txt
+ // files of libclang_rt.* libs have been generated.
+ if strings.Contains(ctx.ModuleName(), "libclang_rt.") {
+ p.versionScriptPath = android.OptionalPathForPath(nil)
+ }
+ return p.linkShared(ctx, flags, deps, objs)
+ }
+
if len(srcs) > 0 {
if len(srcs) > 1 {
ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
@@ -203,6 +224,16 @@
return outputFile
}
+ } else if p.shared() && len(stubInfo) > 0 {
+ // This is a prebuilt which does not have any implementation (nil `srcs`), but provides APIs.
+ // Provide the latest (i.e. `current`) stubs to reverse dependencies.
+ latestStub := stubInfo[len(stubInfo)-1].SharedLibraryInfo.SharedLibrary
+ android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{
+ SharedLibrary: latestStub,
+ Target: ctx.Target(),
+ })
+
+ return latestStub
}
if p.header() {
@@ -257,11 +288,11 @@
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) {
module, library := NewLibrary(hod)
- module.compiler = nil
prebuilt := &prebuiltLibraryLinker{
libraryDecorator: library,
}
+ module.compiler = prebuilt
module.linker = prebuilt
module.library = prebuilt
@@ -280,6 +311,13 @@
return module, library
}
+func (p *prebuiltLibraryLinker) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
+ if p.buildStubs() && p.stubsVersion() != "" {
+ return p.compileModuleLibApiStubs(ctx, flags, deps)
+ }
+ return Objects{}
+}
+
// cc_prebuilt_library installs a precompiled shared library that are
// listed in the srcs property in the device's directory.
func PrebuiltLibraryFactory() android.Module {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index e15ebb0..f949b12 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -210,15 +210,19 @@
}
})
// Find the apex variant for this module
- _, apexVariantsWithoutTestApexes, _ := android.ListSetDifference(apexInfo.InApexVariants, apexInfo.TestApexes)
+ var apexVariantsWithoutTestApexes []string
+ if apexInfo.BaseApexName != "" {
+ // This is a transitive dependency of an override_apex
+ apexVariantsWithoutTestApexes = []string{apexInfo.BaseApexName}
+ } else {
+ _, apexVariantsWithoutTestApexes, _ = android.ListSetDifference(apexInfo.InApexVariants, apexInfo.TestApexes)
+ }
disableSource := false
// find the selected apexes
for _, apexVariant := range apexVariantsWithoutTestApexes {
- for _, selected := range psi.GetSelectedModulesForApiDomain(apexVariant) {
- // If the apex_contribution for this api domain contains a prebuilt apex, disable the source variant
- if strings.HasPrefix(selected, "prebuilt_com.google.android") {
- disableSource = true
- }
+ if len(psi.GetSelectedModulesForApiDomain(apexVariant)) > 0 {
+ // If the apex_contribution for this api domain is non-empty, disable the source variant
+ disableSource = true
}
}
return disableSource
diff --git a/rust/library.go b/rust/library.go
index 50d5a72..7db8f36 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -70,6 +70,10 @@
// Whether this library is part of the Rust toolchain sysroot.
Sysroot *bool
+
+ // Exclude this rust_ffi target from being included in APEXes.
+ // TODO(b/362509506): remove this once stubs are properly supported by rust_ffi targets.
+ Apex_exclude *bool
}
type LibraryMutatedProperties struct {
@@ -122,6 +126,7 @@
shared() bool
sysroot() bool
source() bool
+ apexExclude() bool
// Returns true if the build options for the module have selected a particular build type
buildRlib() bool
@@ -186,6 +191,10 @@
return library.MutatedProperties.VariantIsSource
}
+func (library *libraryDecorator) apexExclude() bool {
+ return Bool(library.Properties.Apex_exclude)
+}
+
func (library *libraryDecorator) buildRlib() bool {
return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true)
}
diff --git a/rust/rust.go b/rust/rust.go
index 3402adc..5a973c4 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -294,6 +294,15 @@
return mod.StaticallyLinked()
}
+func (mod *Module) ApexExclude() bool {
+ if mod.compiler != nil {
+ if library, ok := mod.compiler.(libraryInterface); ok {
+ return library.apexExclude()
+ }
+ }
+ return false
+}
+
func (mod *Module) Object() bool {
// Rust has no modules which produce only object files.
return false
@@ -1863,6 +1872,10 @@
return false
}
+ if rustDep, ok := dep.(*Module); ok && rustDep.ApexExclude() {
+ return false
+ }
+
return true
}