Enable from-text stub generation in non-sdk java_sdk_library
This change allows from-text stubs to be generated for all
java_sdk_library modules, unlike how it is currently limited to the
modules that contribute to the api surfaces (i.e. the SDK).
This change accomplish this by modifying the dependency of the
from-text stubs generation, so that the sdk_library generated from-text
stubs generating java_api_library modules no longer depend on the full
api surface stubs, but generate the stubs in the module level, and
combined later to generate the full api surface stubs.
This change also removes the java_api_library modules defined in
core-libraries/Android.bp, which are passed to generate the system
modules. Given that the from-text vs from-source toggle is done within
the java_sdk_library stubs level, these modules no longer need to exist.
Implementation details:
- Allow sdk_version to be specified in java_api_library modules. For
java_sdk_library-generated java_api_library modules, they inherit that
of the sdk_library module. Some java_sdk_library modules that do not
contribute to the api surface are allowed to set sdk_version to
something other than "none" or "core".
- Implement java_api_library to implement `SdkContext`. This allows
java_api_library to collect required deps from sdk_version (classpath,
bootclasspath, system modules), and pass the collected jars when
generating the stubs srcjar in metalava and compiling the stubs srcjar
in javac.
- Remove hardcoded list of sdk_library modules that are allowed to
genereate stubs from the api signature files, and allow from-text
stubs generation by default. Modules that are not able to generate
stubs from the api signature files are specified by setting the newly
introduced `Build_from_text_stubs` property to `false`.
Test: ENABLE_HIDDENAPI_FLAGS=true m
Bug: 327507877
Change-Id: Ia35d2f3cf9fae48fc8c4bd99a84ae18d7c0e7bee
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index a8a1494..f9c3dd5 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -35,9 +35,6 @@
"29": {"foo"},
"30": {"bar", "barney", "baz", "betty", "foo", "fred", "quuz", "wilma"},
}),
- 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",
@@ -1588,9 +1585,6 @@
prepareForJavaTest,
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("foo"),
- android.FixtureModifyConfig(func(config android.Config) {
- config.SetApiLibraries([]string{"foo"})
- }),
).RunTestWithBp(t, `
java_sdk_library {
name: "foo",
@@ -1609,36 +1603,30 @@
`)
testCases := []struct {
- scope *apiScope
- apiContributions []string
- fullApiSurfaceStub string
+ scope *apiScope
+ apiContributions []string
}{
{
- scope: apiScopePublic,
- apiContributions: []string{"foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_stubs_current",
+ scope: apiScopePublic,
+ apiContributions: []string{"foo.stubs.source.api.contribution"},
},
{
- scope: apiScopeSystem,
- apiContributions: []string{"foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_system_stubs_current",
+ scope: apiScopeSystem,
+ apiContributions: []string{"foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
},
{
- scope: apiScopeTest,
- apiContributions: []string{"foo.stubs.source.test.api.contribution", "foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_test_stubs_current",
+ scope: apiScopeTest,
+ apiContributions: []string{"foo.stubs.source.test.api.contribution", "foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
},
{
- scope: apiScopeModuleLib,
- apiContributions: []string{"foo.stubs.source.module_lib.api.contribution", "foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
- fullApiSurfaceStub: "android_module_lib_stubs_current_full.from-text",
+ scope: apiScopeModuleLib,
+ apiContributions: []string{"foo.stubs.source.module_lib.api.contribution", "foo.stubs.source.system.api.contribution", "foo.stubs.source.api.contribution"},
},
}
for _, c := range testCases {
m := result.ModuleForTests(c.scope.apiLibraryModuleName("foo"), "android_common").Module().(*ApiLibrary)
android.AssertArrayString(t, "Module expected to contain api contributions", c.apiContributions, m.properties.Api_contributions)
- android.AssertStringEquals(t, "Module expected to contain full api surface api library", c.fullApiSurfaceStub, *m.properties.Full_api_surface_stub)
}
}
@@ -1708,9 +1696,6 @@
prepareForJavaTest,
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("foo"),
- android.FixtureModifyConfig(func(config android.Config) {
- config.SetApiLibraries([]string{"foo"})
- }),
).RunTestWithBp(t, `
aconfig_declarations {
name: "bar",