Enable hiddenapi check for exportable stubs
This change modifies the dependencies of the hiddenapi to always depend on the exportable stubs, instead of the currently utilized everything stubs. To support this, the full api surface exportable stubs are defined in a separate change at the `frameworks/base` project. Note that the full api surface exportable stubs are only used for the hiddenapi purpose, and `sdk_version` continues to utilize the currently existing everything stubs. Currently, this feature is hidden behind the build flag "RELEASE_HIDDEN_API_EXPORTABLE_STUBS". This feature will be fully enabled once metalava fully supports handling of the flagged apis. Test: ENABLE_HIDDENAPI_FLAGS=true m Bug: 317426356 Change-Id: I109b7cd27b20ceffcdf1766ab8106b0c276be2b3
This commit is contained in:
@@ -222,6 +222,11 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
|
||||
PrepareForTestWithJavaSdkLibraryFiles,
|
||||
FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
|
||||
FixtureConfigureApexBootJars("someapex:mysdklibrary"),
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, `
|
||||
bootclasspath_fragment {
|
||||
name: "myfragment",
|
||||
@@ -277,11 +282,11 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
|
||||
stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar"
|
||||
|
||||
// Stubs jars for mysdklibrary
|
||||
publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar"
|
||||
systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.system/android_common/dex/mysdklibrary.stubs.system.jar"
|
||||
publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar"
|
||||
systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.exportable.system/android_common/dex/mysdklibrary.stubs.exportable.system.jar"
|
||||
|
||||
// Stubs jars for myothersdklibrary
|
||||
otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar"
|
||||
otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs.exportable/android_common/dex/myothersdklibrary.stubs.exportable.jar"
|
||||
|
||||
// Check that SdkPublic uses public stubs for all sdk libraries.
|
||||
android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(PublicHiddenAPIScope))
|
||||
|
@@ -38,9 +38,6 @@ java_defaults {
|
||||
visibility: ["//visibility:public"],
|
||||
sdk_version: "none",
|
||||
system_modules: "none",
|
||||
dist: {
|
||||
targets: dist_targets,
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
@@ -89,6 +86,32 @@ java_library {
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "core.current.stubs.exportable.from-source",
|
||||
defaults: [
|
||||
"core.current.stubs.defaults",
|
||||
],
|
||||
static_libs: [
|
||||
"art.module.public.api.stubs.exportable",
|
||||
"conscrypt.module.public.api.stubs.exportable",
|
||||
"i18n.module.public.api.stubs.exportable",
|
||||
],
|
||||
dist: {
|
||||
targets: dist_targets,
|
||||
dest: "core.current.stubs.jar",
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "core.current.stubs.exportable",
|
||||
defaults: [
|
||||
"core.current.stubs.defaults",
|
||||
],
|
||||
static_libs: [
|
||||
"core.current.stubs.exportable.from-source",
|
||||
],
|
||||
}
|
||||
|
||||
// Distributed with the SDK for turning into system modules to compile apps
|
||||
// against.
|
||||
//
|
||||
@@ -298,6 +321,19 @@ java_library {
|
||||
],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "legacy.core.platform.api.stubs.exportable.from-source",
|
||||
visibility: core_platform_visibility,
|
||||
defaults: [
|
||||
"core.platform.api.stubs.defaults",
|
||||
],
|
||||
static_libs: [
|
||||
"art.module.public.api.stubs.exportable.module_lib",
|
||||
"conscrypt.module.platform.api.stubs.exportable",
|
||||
"legacy.i18n.module.platform.api.stubs.exportable",
|
||||
],
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "android_core_platform_stubs_current_contributions",
|
||||
api_surface: "core_platform",
|
||||
@@ -345,6 +381,17 @@ java_library {
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "legacy.core.platform.api.stubs.exportable",
|
||||
visibility: core_platform_visibility,
|
||||
defaults: [
|
||||
"core.platform.api.stubs.defaults",
|
||||
],
|
||||
static_libs: [
|
||||
"legacy.core.platform.api.stubs.exportable.from-source",
|
||||
],
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "core.platform.api.stubs.defaults",
|
||||
hostdex: true,
|
||||
|
@@ -245,12 +245,22 @@ func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[*Hidden
|
||||
testStubModules = append(testStubModules, "sdk_test_current_android")
|
||||
} else {
|
||||
// Use stub modules built from source
|
||||
publicStubModules = append(publicStubModules, android.SdkPublic.DefaultJavaLibraryName())
|
||||
systemStubModules = append(systemStubModules, android.SdkSystem.DefaultJavaLibraryName())
|
||||
testStubModules = append(testStubModules, android.SdkTest.DefaultJavaLibraryName())
|
||||
if config.ReleaseHiddenApiExportableStubs() {
|
||||
publicStubModules = append(publicStubModules, android.SdkPublic.DefaultExportableJavaLibraryName())
|
||||
systemStubModules = append(systemStubModules, android.SdkSystem.DefaultExportableJavaLibraryName())
|
||||
testStubModules = append(testStubModules, android.SdkTest.DefaultExportableJavaLibraryName())
|
||||
} else {
|
||||
publicStubModules = append(publicStubModules, android.SdkPublic.DefaultJavaLibraryName())
|
||||
systemStubModules = append(systemStubModules, android.SdkSystem.DefaultJavaLibraryName())
|
||||
testStubModules = append(testStubModules, android.SdkTest.DefaultJavaLibraryName())
|
||||
}
|
||||
}
|
||||
// We do not have prebuilts of the core platform api yet
|
||||
corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs")
|
||||
if config.ReleaseHiddenApiExportableStubs() {
|
||||
corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs.exportable")
|
||||
} else {
|
||||
corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs")
|
||||
}
|
||||
|
||||
// Allow products to define their own stubs for custom product jars that apps can use.
|
||||
publicStubModules = append(publicStubModules, config.ProductHiddenAPIStubs()...)
|
||||
@@ -289,7 +299,12 @@ func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, apiScop
|
||||
func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.Module, kind android.SdkKind) android.Path {
|
||||
var dexJar OptionalDexJarPath
|
||||
if sdkLibrary, ok := module.(SdkLibraryDependency); ok {
|
||||
dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind)
|
||||
if ctx.Config().ReleaseHiddenApiExportableStubs() {
|
||||
dexJar = sdkLibrary.SdkApiExportableStubDexJar(ctx, kind)
|
||||
} else {
|
||||
dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind)
|
||||
}
|
||||
|
||||
} else if j, ok := module.(UsesLibraryDependency); ok {
|
||||
dexJar = j.DexJarBuildPath(ctx)
|
||||
} else {
|
||||
|
@@ -177,10 +177,10 @@ func TestHiddenAPISingletonSdks(t *testing.T) {
|
||||
{
|
||||
name: "testBundled",
|
||||
unbundledBuild: false,
|
||||
publicStub: "android_stubs_current",
|
||||
systemStub: "android_system_stubs_current",
|
||||
testStub: "android_test_stubs_current",
|
||||
corePlatformStub: "legacy.core.platform.api.stubs",
|
||||
publicStub: "android_stubs_current_exportable",
|
||||
systemStub: "android_system_stubs_current_exportable",
|
||||
testStub: "android_test_stubs_current_exportable",
|
||||
corePlatformStub: "legacy.core.platform.api.stubs.exportable",
|
||||
preparer: android.GroupFixturePreparers(),
|
||||
}, {
|
||||
name: "testUnbundled",
|
||||
@@ -188,7 +188,7 @@ func TestHiddenAPISingletonSdks(t *testing.T) {
|
||||
publicStub: "sdk_public_current_android",
|
||||
systemStub: "sdk_system_current_android",
|
||||
testStub: "sdk_test_current_android",
|
||||
corePlatformStub: "legacy.core.platform.api.stubs",
|
||||
corePlatformStub: "legacy.core.platform.api.stubs.exportable",
|
||||
preparer: PrepareForTestWithPrebuiltsOfCurrentApi,
|
||||
},
|
||||
}
|
||||
@@ -200,6 +200,9 @@ func TestHiddenAPISingletonSdks(t *testing.T) {
|
||||
prepareForTestWithDefaultPlatformBootclasspath,
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(tc.unbundledBuild)
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTest(t)
|
||||
|
||||
|
@@ -104,9 +104,16 @@ type apiScope struct {
|
||||
// The name of the property in the java_sdk_library_import
|
||||
propertyName string
|
||||
|
||||
// The tag to use to depend on the stubs library module.
|
||||
// The tag to use to depend on the stubs library module if the parent module
|
||||
// does not differentiate everything and exportable stubs (e.g. sdk_library_import).
|
||||
stubsTag scopeDependencyTag
|
||||
|
||||
// The tag to use to depend on the everything stubs library module.
|
||||
everythingStubsTag scopeDependencyTag
|
||||
|
||||
// The tag to use to depend on the exportable stubs library module.
|
||||
exportableStubsTag scopeDependencyTag
|
||||
|
||||
// The tag to use to depend on the stubs source module (if separate from the API module).
|
||||
stubsSourceTag scopeDependencyTag
|
||||
|
||||
@@ -172,6 +179,16 @@ func initApiScope(scope *apiScope) *apiScope {
|
||||
apiScope: scope,
|
||||
depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
|
||||
}
|
||||
scope.everythingStubsTag = scopeDependencyTag{
|
||||
name: name + "-stubs-everything",
|
||||
apiScope: scope,
|
||||
depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency,
|
||||
}
|
||||
scope.exportableStubsTag = scopeDependencyTag{
|
||||
name: name + "-stubs-exportable",
|
||||
apiScope: scope,
|
||||
depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency,
|
||||
}
|
||||
scope.stubsSourceTag = scopeDependencyTag{
|
||||
name: name + "-stubs-source",
|
||||
apiScope: scope,
|
||||
@@ -669,6 +686,11 @@ type scopePaths struct {
|
||||
// This is not the implementation jar, it still only contains stubs.
|
||||
stubsDexJarPath OptionalDexJarPath
|
||||
|
||||
// The exportable dex jar for the stubs.
|
||||
// This is not the implementation jar, it still only contains stubs.
|
||||
// Includes unflagged apis and flagged apis enabled by release configurations.
|
||||
exportableStubsDexJarPath OptionalDexJarPath
|
||||
|
||||
// The API specification file, e.g. system_current.txt.
|
||||
currentApiFilePath android.OptionalPath
|
||||
|
||||
@@ -695,6 +717,30 @@ func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.Modul
|
||||
|
||||
libDep := dep.(UsesLibraryDependency)
|
||||
paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
|
||||
paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
|
||||
}
|
||||
}
|
||||
|
||||
func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
|
||||
if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
|
||||
paths.stubsHeaderPath = lib.HeaderJars
|
||||
paths.stubsImplPath = lib.ImplementationJars
|
||||
|
||||
libDep := dep.(UsesLibraryDependency)
|
||||
paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
|
||||
}
|
||||
}
|
||||
|
||||
func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
|
||||
if _, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
|
||||
libDep := dep.(UsesLibraryDependency)
|
||||
paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
|
||||
@@ -1131,6 +1177,16 @@ func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleCon
|
||||
return paths.stubsDexJarPath
|
||||
}
|
||||
|
||||
// to satisfy SdkLibraryDependency interface
|
||||
func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath {
|
||||
paths := c.selectScopePaths(ctx, kind)
|
||||
if paths == nil {
|
||||
return makeUnsetDexJarPath()
|
||||
}
|
||||
|
||||
return paths.exportableStubsDexJarPath
|
||||
}
|
||||
|
||||
// to satisfy SdkLibraryDependency interface
|
||||
func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath {
|
||||
apiScope := sdkKindToApiScope(kind)
|
||||
@@ -1249,10 +1305,16 @@ type SdkLibraryDependency interface {
|
||||
// they are identical to the corresponding header jars.
|
||||
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths
|
||||
|
||||
// SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing
|
||||
// tool which processes dex files.
|
||||
// SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt
|
||||
// java_sdk_library_import module. It is needed by the hiddenapi processing tool which
|
||||
// processes dex files.
|
||||
SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
|
||||
|
||||
// SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for
|
||||
// java_sdk_library module. It is needed by the hiddenapi processing tool which processes
|
||||
// dex files.
|
||||
SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
|
||||
|
||||
// SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind.
|
||||
SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath
|
||||
|
||||
@@ -1365,8 +1427,10 @@ func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContex
|
||||
for _, apiScope := range module.getGeneratedApiScopes(ctx) {
|
||||
// Add dependencies to the stubs library
|
||||
stubModuleName := module.stubsLibraryModuleName(apiScope)
|
||||
ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName)
|
||||
|
||||
ctx.AddVariationDependencies(nil, apiScope.stubsTag, stubModuleName)
|
||||
exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope)
|
||||
ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName)
|
||||
|
||||
// Add a dependency on the stubs source in order to access both stubs source and api information.
|
||||
ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))
|
||||
|
@@ -38,6 +38,11 @@ func TestJavaSdkLibrary(t *testing.T) {
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.SetApiLibraries([]string{"foo"})
|
||||
}),
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, `
|
||||
droiddoc_exported_dir {
|
||||
name: "droiddoc-templates-sdk",
|
||||
@@ -139,6 +144,9 @@ func TestJavaSdkLibrary(t *testing.T) {
|
||||
"foo.api.public.latest",
|
||||
"foo.api.system.latest",
|
||||
"foo.stubs",
|
||||
"foo.stubs.exportable",
|
||||
"foo.stubs.exportable.system",
|
||||
"foo.stubs.exportable.test",
|
||||
"foo.stubs.source",
|
||||
"foo.stubs.source.system",
|
||||
"foo.stubs.source.test",
|
||||
@@ -529,6 +537,11 @@ func TestJavaSdkLibrary_Deps(t *testing.T) {
|
||||
prepareForJavaTest,
|
||||
PrepareForTestWithJavaSdkLibraryFiles,
|
||||
FixtureWithLastReleaseApis("sdklib"),
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, `
|
||||
java_sdk_library {
|
||||
name: "sdklib",
|
||||
@@ -547,6 +560,7 @@ func TestJavaSdkLibrary_Deps(t *testing.T) {
|
||||
`sdklib.api.public.latest`,
|
||||
`sdklib.impl`,
|
||||
`sdklib.stubs`,
|
||||
`sdklib.stubs.exportable`,
|
||||
`sdklib.stubs.source`,
|
||||
`sdklib.xml`,
|
||||
})
|
||||
@@ -919,6 +933,11 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
||||
prepareForJavaTest,
|
||||
PrepareForTestWithJavaSdkLibraryFiles,
|
||||
FixtureWithLastReleaseApis("sdklib"),
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, `
|
||||
java_sdk_library {
|
||||
name: "sdklib",
|
||||
@@ -945,6 +964,7 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
|
||||
`sdklib.api.public.latest`,
|
||||
`sdklib.impl`,
|
||||
`sdklib.stubs`,
|
||||
`sdklib.stubs.exportable`,
|
||||
`sdklib.stubs.source`,
|
||||
`sdklib.xml`,
|
||||
})
|
||||
@@ -966,6 +986,11 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an
|
||||
PrepareForTestWithJavaSdkLibraryFiles,
|
||||
FixtureWithLastReleaseApis("sdklib"),
|
||||
preparer,
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.BuildFlags = map[string]string{
|
||||
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, `
|
||||
java_sdk_library {
|
||||
name: "sdklib",
|
||||
@@ -1018,6 +1043,7 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an
|
||||
`sdklib.api.public.latest`,
|
||||
`sdklib.impl`,
|
||||
`sdklib.stubs`,
|
||||
`sdklib.stubs.exportable`,
|
||||
`sdklib.stubs.source`,
|
||||
`sdklib.xml`,
|
||||
})
|
||||
|
@@ -407,6 +407,14 @@ func gatherRequiredDepsForTest() string {
|
||||
"legacy.core.platform.api.stubs",
|
||||
"stable.core.platform.api.stubs",
|
||||
|
||||
"android_stubs_current_exportable",
|
||||
"android_system_stubs_current_exportable",
|
||||
"android_test_stubs_current_exportable",
|
||||
"android_module_lib_stubs_current_exportable",
|
||||
"android_system_server_stubs_current_exportable",
|
||||
"core.current.stubs.exportable",
|
||||
"legacy.core.platform.api.stubs.exportable",
|
||||
|
||||
"kotlin-stdlib",
|
||||
"kotlin-stdlib-jdk7",
|
||||
"kotlin-stdlib-jdk8",
|
||||
|
Reference in New Issue
Block a user