Merge changes from topic "android_stubs_current_refactor"
* changes:
Cleanup android.JavaApiLibraryName references
Redefine core and core platform API surface java_library
Introduce product variable Build_from_text_stub
Introduce "Exclude_static_libs" property for Java modules
diff --git a/android/config.go b/android/config.go
index 0e119a3..d4703ff 100644
--- a/android/config.go
+++ b/android/config.go
@@ -517,6 +517,8 @@
config: config,
}
+ config.productVariables.Build_from_text_stub = boolPtr(config.buildFromTextStub)
+
// Soundness check of the build and source directories. This won't catch strange
// configurations with symlinks, but at least checks the obvious case.
absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
@@ -2017,6 +2019,7 @@
func (c *config) SetBuildFromTextStub(b bool) {
c.buildFromTextStub = b
+ c.productVariables.Build_from_text_stub = boolPtr(b)
}
func (c *config) AddForceEnabledModules(forceEnabled []string) {
diff --git a/android/neverallow.go b/android/neverallow.go
index 5b5e613..f2e8c85 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -59,6 +59,7 @@
AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
AddNeverAllowRules(createBp2BuildRule())
AddNeverAllowRules(createCcStubsRule())
+ AddNeverAllowRules(createJavaExcludeStaticLibsRule())
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -253,6 +254,14 @@
}
}
+func createJavaExcludeStaticLibsRule() Rule {
+ return NeverAllow().
+ NotIn("build/soong").
+ ModuleType("java_library").
+ WithMatcher("exclude_static_libs", isSetMatcherInstance).
+ Because("exclude_static_libs property is only allowed for java modules defined in build/soong")
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index ddd982d..1639bbf 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -344,6 +344,23 @@
`module "outside_allowed_list": violates neverallow`,
},
},
+ // Test for the rule restricting use of exclude_static_libs
+ {
+ name: `"exclude_static_libs" outside allowed directory`,
+ fs: map[string][]byte{
+ "a/b/Android.bp": []byte(`
+ java_library {
+ name: "baz",
+ exclude_static_libs: [
+ "bar",
+ ],
+ }
+ `),
+ },
+ expectedErrors: []string{
+ `exclude_static_libs property is only allowed for java modules defined in build/soong`,
+ },
+ },
}
var prepareForNeverAllowTest = GroupFixturePreparers(
@@ -430,9 +447,10 @@
}
type mockJavaLibraryProperties struct {
- Libs []string
- Sdk_version *string
- Uncompress_dex *bool
+ Libs []string
+ Sdk_version *string
+ Uncompress_dex *bool
+ Exclude_static_libs []string
}
type mockJavaLibraryModule struct {
diff --git a/android/sdk_version.go b/android/sdk_version.go
index 08762ef..80aeb2e 100644
--- a/android/sdk_version.go
+++ b/android/sdk_version.go
@@ -84,12 +84,6 @@
}
}
-// JavaLibraryName returns the soong module containing the Java APIs of that API surface.
-func (k SdkKind) JavaLibraryName(c Config) string {
- name := k.DefaultJavaLibraryName()
- return JavaApiLibraryName(c, name)
-}
-
// JavaApiLibraryName returns the name of .txt equivalent of a java_library, but does
// not check if either module exists.
// TODO: Return .txt (single-tree or multi-tree equivalents) based on config
@@ -335,11 +329,10 @@
// Export the name of the soong modules representing the various Java API surfaces.
func javaSdkMakeVars(ctx MakeVarsContext) {
- ctx.Strict("ANDROID_PUBLIC_STUBS", SdkPublic.JavaLibraryName(ctx.Config()))
- ctx.Strict("ANDROID_SYSTEM_STUBS", SdkSystem.JavaLibraryName(ctx.Config()))
- ctx.Strict("ANDROID_TEST_STUBS", SdkTest.JavaLibraryName(ctx.Config()))
- ctx.Strict("ANDROID_MODULE_LIB_STUBS", SdkModule.JavaLibraryName(ctx.Config()))
- ctx.Strict("ANDROID_SYSTEM_SERVER_STUBS", SdkSystemServer.JavaLibraryName(ctx.Config()))
- // TODO (jihoonkang): Create a .txt equivalent for core.current.stubs
- ctx.Strict("ANDROID_CORE_STUBS", SdkCore.JavaLibraryName(ctx.Config()))
+ ctx.Strict("ANDROID_PUBLIC_STUBS", SdkPublic.DefaultJavaLibraryName())
+ ctx.Strict("ANDROID_SYSTEM_STUBS", SdkSystem.DefaultJavaLibraryName())
+ ctx.Strict("ANDROID_TEST_STUBS", SdkTest.DefaultJavaLibraryName())
+ ctx.Strict("ANDROID_MODULE_LIB_STUBS", SdkModule.DefaultJavaLibraryName())
+ ctx.Strict("ANDROID_SYSTEM_SERVER_STUBS", SdkSystemServer.DefaultJavaLibraryName())
+ ctx.Strict("ANDROID_CORE_STUBS", SdkCore.DefaultJavaLibraryName())
}
diff --git a/android/variable.go b/android/variable.go
index 60a6503..6362953 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -109,6 +109,11 @@
Cflags []string
}
+ Build_from_text_stub struct {
+ Static_libs []string
+ Exclude_static_libs []string
+ }
+
// debuggable is true for eng and userdebug builds, and can be used to turn on additional
// debugging features that don't significantly impact runtime behavior. userdebug builds
// are used for dogfooding and performance testing, and should be as similar to user builds
@@ -286,6 +291,7 @@
Uml *bool `json:",omitempty"`
Arc *bool `json:",omitempty"`
MinimizeJavaDebugInfo *bool `json:",omitempty"`
+ Build_from_text_stub *bool `json:",omitempty"`
Check_elf_files *bool `json:",omitempty"`
@@ -526,6 +532,7 @@
Malloc_pattern_fill_contents: boolPtr(false),
Safestack: boolPtr(false),
TrimmedApex: boolPtr(false),
+ Build_from_text_stub: boolPtr(false),
BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
diff --git a/java/base.go b/java/base.go
index dd02ef8..ed61e12 100644
--- a/java/base.go
+++ b/java/base.go
@@ -79,6 +79,9 @@
// list of java libraries that will be compiled into the resulting jar
Static_libs []string `android:"arch_variant"`
+ // list of java libraries that should not be used to build this module
+ Exclude_static_libs []string `android:"arch_variant"`
+
// manifest file to be included in resulting jar
Manifest *string `android:"path"`
@@ -724,6 +727,8 @@
}
libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
+
+ j.properties.Static_libs = android.RemoveListFromList(j.properties.Static_libs, j.properties.Exclude_static_libs)
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
// Add dependency on libraries that provide additional hidden api annotations.
@@ -1923,22 +1928,22 @@
func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) {
switch name {
- case android.SdkCore.JavaLibraryName(ctx.Config()),
- android.JavaApiLibraryName(ctx.Config(), "legacy.core.platform.api.stubs"),
- android.JavaApiLibraryName(ctx.Config(), "stable.core.platform.api.stubs"),
+ case android.SdkCore.DefaultJavaLibraryName(),
+ "legacy.core.platform.api.stubs",
+ "stable.core.platform.api.stubs",
"stub-annotations", "private-stub-annotations-jar",
- android.JavaApiLibraryName(ctx.Config(), "core-lambda-stubs"),
+ "core-lambda-stubs",
"core-generated-annotation-stubs":
return javaCore, true
- case android.SdkPublic.JavaLibraryName(ctx.Config()):
+ case android.SdkPublic.DefaultJavaLibraryName():
return javaSdk, true
- case android.SdkSystem.JavaLibraryName(ctx.Config()):
+ case android.SdkSystem.DefaultJavaLibraryName():
return javaSystem, true
- case android.SdkModule.JavaLibraryName(ctx.Config()):
+ case android.SdkModule.DefaultJavaLibraryName():
return javaModule, true
- case android.SdkSystemServer.JavaLibraryName(ctx.Config()):
+ case android.SdkSystemServer.DefaultJavaLibraryName():
return javaSystemServer, true
- case android.SdkTest.JavaLibraryName(ctx.Config()):
+ case android.SdkTest.DefaultJavaLibraryName():
return javaSystem, true
}
diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp
index 958f4ce..eadd9c6 100644
--- a/java/core-libraries/Android.bp
+++ b/java/core-libraries/Android.bp
@@ -33,19 +33,45 @@
"win_sdk",
]
-java_library {
- name: "core.current.stubs",
+java_defaults {
+ name: "core.current.stubs.defaults",
visibility: ["//visibility:public"],
+ sdk_version: "none",
+ system_modules: "none",
+ dist: {
+ targets: dist_targets,
+ },
+}
+
+java_library {
+ name: "core.current.stubs.from-source",
+ defaults: [
+ "core.current.stubs.defaults",
+ ],
static_libs: [
"art.module.public.api.stubs",
"conscrypt.module.public.api.stubs",
"i18n.module.public.api.stubs",
],
- sdk_version: "none",
- system_modules: "none",
+}
- dist: {
- targets: dist_targets,
+java_library {
+ name: "core.current.stubs",
+ defaults: [
+ "core.current.stubs.defaults",
+ ],
+ static_libs: [
+ "core.current.stubs.from-source",
+ ],
+ product_variables: {
+ build_from_text_stub: {
+ static_libs: [
+ "core.current.stubs.from-text",
+ ],
+ exclude_static_libs: [
+ "core.current.stubs.from-source",
+ ],
+ },
},
}
@@ -199,18 +225,46 @@
// API annotations are available to the dex tools that enable enforcement of runtime
// accessibility. b/119068555
java_library {
- name: "legacy.core.platform.api.stubs",
+ name: "legacy.core.platform.api.stubs.from-source",
visibility: core_platform_visibility,
- hostdex: true,
- compile_dex: true,
-
- sdk_version: "none",
- system_modules: "none",
+ defaults: [
+ "core.platform.api.stubs.defaults",
+ ],
static_libs: [
"art.module.public.api.stubs.module_lib",
"conscrypt.module.platform.api.stubs",
"legacy.i18n.module.platform.api.stubs",
],
+}
+
+java_library {
+ name: "legacy.core.platform.api.stubs",
+ visibility: core_platform_visibility,
+ defaults: [
+ "core.platform.api.stubs.defaults",
+ ],
+ static_libs: [
+ "legacy.core.platform.api.stubs.from-source",
+ ],
+ product_variables: {
+ build_from_text_stub: {
+ static_libs: [
+ "stable.core.platform.api.stubs.from-text",
+ ],
+ exclude_static_libs: [
+ "stable.core.platform.api.stubs.from-source",
+ ],
+ },
+ },
+}
+
+java_defaults {
+ name: "core.platform.api.stubs.defaults",
+ hostdex: true,
+ compile_dex: true,
+
+ sdk_version: "none",
+ system_modules: "none",
patch_module: "java.base",
}
@@ -233,20 +287,38 @@
}
java_library {
- name: "stable.core.platform.api.stubs",
+ name: "stable.core.platform.api.stubs.from-source",
visibility: core_platform_visibility,
- hostdex: true,
- compile_dex: true,
-
- sdk_version: "none",
- system_modules: "none",
+ defaults: [
+ "core.platform.api.stubs.defaults",
+ ],
static_libs: [
"art.module.public.api.stubs.module_lib",
// conscrypt only has a stable version, so it is okay to depend on it here:
"conscrypt.module.platform.api.stubs",
"stable.i18n.module.platform.api.stubs",
],
- patch_module: "java.base",
+}
+
+java_library {
+ name: "stable.core.platform.api.stubs",
+ visibility: core_platform_visibility,
+ defaults: [
+ "core.platform.api.stubs.defaults",
+ ],
+ static_libs: [
+ "stable.core.platform.api.stubs.from-source",
+ ],
+ product_variables: {
+ build_from_text_stub: {
+ static_libs: [
+ "stable.core.platform.api.stubs.from-text",
+ ],
+ exclude_static_libs: [
+ "stable.core.platform.api.stubs.from-source",
+ ],
+ },
+ },
}
// Same as stable.core.platform.api.stubs, but android annotations are
diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go
index e54275b..da9c997 100644
--- a/java/hiddenapi_modular.go
+++ b/java/hiddenapi_modular.go
@@ -236,12 +236,12 @@
testStubModules = append(testStubModules, "sdk_test_current_android")
} else {
// Use stub modules built from source
- publicStubModules = append(publicStubModules, android.SdkPublic.JavaLibraryName(config))
- systemStubModules = append(systemStubModules, android.SdkSystem.JavaLibraryName(config))
- testStubModules = append(testStubModules, android.SdkTest.JavaLibraryName(config))
+ 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, android.JavaApiLibraryName(config, "legacy.core.platform.api.stubs"))
+ 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()...)
diff --git a/java/java_test.go b/java/java_test.go
index cd5c343..561b187 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2322,3 +2322,34 @@
t.Errorf("Expected args[\"extraTestRunnerConfigs\"] to equal %q, was %q", expected, args["extraTestRunnerConfigs"])
}
}
+
+func TestJavaExcludeStaticLib(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_library {
+ name: "bar",
+ }
+ java_library {
+ name: "foo",
+ }
+ java_library {
+ name: "baz",
+ static_libs: [
+ "foo",
+ "bar",
+ ],
+ exclude_static_libs: [
+ "bar",
+ ],
+ }
+ `)
+
+ // "bar" not included as dependency of "baz"
+ CheckModuleDependencies(t, ctx, "baz", "android_common", []string{
+ `core-lambda-stubs`,
+ `ext`,
+ `foo`,
+ `framework`,
+ `stable-core-platform-api-stubs-system-modules`,
+ `stable.core.platform.api.stubs`,
+ })
+}
diff --git a/java/sdk.go b/java/sdk.go
index 7fa604f..7699aab 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -151,7 +151,7 @@
systemModules := android.JavaApiLibraryName(ctx.Config(), fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind))
return sdkDep{
useModule: true,
- bootclasspath: []string{module, android.JavaApiLibraryName(ctx.Config(), config.DefaultLambdaStubsLibrary)},
+ bootclasspath: []string{module, config.DefaultLambdaStubsLibrary},
systemModules: systemModules,
java9Classpath: []string{module},
frameworkResModule: "framework-res",
@@ -193,20 +193,20 @@
noFrameworksLibs: true,
}
case android.SdkPublic, android.SdkSystem, android.SdkTest:
- return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), sdkFrameworkAidlPath(ctx))
+ return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
case android.SdkCore:
return sdkDep{
useModule: true,
- bootclasspath: []string{android.SdkCore.JavaLibraryName(ctx.Config()), android.JavaApiLibraryName(ctx.Config(), config.DefaultLambdaStubsLibrary)},
+ bootclasspath: []string{android.SdkCore.DefaultJavaLibraryName(), config.DefaultLambdaStubsLibrary},
systemModules: android.JavaApiLibraryName(ctx.Config(), "core-public-stubs-system-modules"),
noFrameworksLibs: true,
}
case android.SdkModule:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
- return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), nonUpdatableFrameworkAidlPath(ctx))
+ return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), nonUpdatableFrameworkAidlPath(ctx))
case android.SdkSystemServer:
// TODO(146757305): provide .apk and .aidl that have more APIs for modules
- return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), sdkFrameworkAidlPath(ctx))
+ return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx))
default:
panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw))
}
@@ -269,9 +269,9 @@
// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
func createSdkFrameworkAidl(ctx android.SingletonContext) {
stubsModules := []string{
- android.SdkPublic.JavaLibraryName(ctx.Config()),
- android.SdkTest.JavaLibraryName(ctx.Config()),
- android.SdkSystem.JavaLibraryName(ctx.Config()),
+ android.SdkPublic.DefaultJavaLibraryName(),
+ android.SdkTest.DefaultJavaLibraryName(),
+ android.SdkSystem.DefaultJavaLibraryName(),
}
combinedAidl := sdkFrameworkAidlPath(ctx)
@@ -286,7 +286,7 @@
// Creates a version of framework.aidl for the non-updatable part of the platform.
func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) {
- stubsModules := []string{android.SdkModule.JavaLibraryName(ctx.Config())}
+ stubsModules := []string{android.SdkModule.DefaultJavaLibraryName()}
combinedAidl := nonUpdatableFrameworkAidlPath(ctx)
tempPath := tempPathForRestat(ctx, combinedAidl)