diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/java.go | 21 | ||||
| -rw-r--r-- | java/java_test.go | 32 | ||||
| -rw-r--r-- | java/sdk_library.go | 37 | ||||
| -rw-r--r-- | java/testing.go | 7 |
4 files changed, 89 insertions, 8 deletions
diff --git a/java/java.go b/java/java.go index 8b5aeaaf6..ab8f859b6 100644 --- a/java/java.go +++ b/java/java.go @@ -612,6 +612,21 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { ctx.Config().UnbundledBuild()) } +func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool { + // Force enable the instrumentation for java code that is built for APEXes ... + // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent + // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true. + isJacocoAgent := ctx.ModuleName() == "jacocoagent" + if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() { + if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { + return true + } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { + return true + } + } + return false +} + func (j *Module) sdkVersion() sdkSpec { return sdkSpecFrom(String(j.deviceProperties.Sdk_version)) } @@ -1545,11 +1560,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.headerJarFile = j.implementationJarFile } - // Force enable the instrumentation for java code that is built for APEXes ... - // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent - // doesn't make sense) - isJacocoAgent := ctx.ModuleName() == "jacocoagent" - if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() { + if j.shouldInstrumentInApex(ctx) { j.properties.Instrument = true } diff --git a/java/java_test.go b/java/java_test.go index 215070e6f..b74111ba7 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1448,6 +1448,38 @@ func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { `) } +func TestJavaSdkLibrary_ModuleLib(t *testing.T) { + testJava(t, ` + java_sdk_library { + name: "foo", + srcs: ["a.java", "b.java"], + api_packages: ["foo"], + system: { + enabled: true, + }, + module_lib: { + enabled: true, + }, + } + `) +} + +func TestJavaSdkLibrary_SystemServer(t *testing.T) { + testJava(t, ` + java_sdk_library { + name: "foo", + srcs: ["a.java", "b.java"], + api_packages: ["foo"], + system: { + enabled: true, + }, + system_server: { + enabled: true, + }, + } + `) +} + func TestJavaSdkLibrary_MissingScope(t *testing.T) { testJavaError(t, `requires api scope module-lib from foo but it only has \[\] available`, ` java_sdk_library { diff --git a/java/sdk_library.go b/java/sdk_library.go index de5ee03c4..63ebe6352 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -264,7 +264,7 @@ var ( apiScopeModuleLib = initApiScope(&apiScope{ name: "module-lib", extends: apiScopeSystem, - // Module_lib scope is disabled by default in legacy mode. + // The module-lib scope is disabled by default in legacy mode. // // Enabling this would break existing usages. legacyEnabledStatus: func(module *SdkLibrary) bool { @@ -280,11 +280,34 @@ var ( "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)", }, }) + apiScopeSystemServer = initApiScope(&apiScope{ + name: "system-server", + extends: apiScopePublic, + // The system-server scope is disabled by default in legacy mode. + // + // Enabling this would break existing usages. + legacyEnabledStatus: func(module *SdkLibrary) bool { + return false + }, + scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { + return &module.sdkLibraryProperties.System_server + }, + apiFilePrefix: "system-server-", + moduleSuffix: ".system_server", + sdkVersion: "system_server_current", + droidstubsArgs: []string{ + "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ", + "--hide-annotation android.annotation.Hide", + // com.android.* classes are okay in this interface" + "--hide InternalClasses", + }, + }) allApiScopes = apiScopes{ apiScopePublic, apiScopeSystem, apiScopeTest, apiScopeModuleLib, + apiScopeSystemServer, } ) @@ -429,12 +452,18 @@ type sdkLibraryProperties struct { // In non-legacy mode the test api scope is disabled by default. Test ApiScopeProperties - // The properties specific to the module_lib api scope + // The properties specific to the module-lib api scope // - // Unless explicitly specified by using test.enabled the module_lib api scope is + // Unless explicitly specified by using test.enabled the module-lib api scope is // disabled by default. Module_lib ApiScopeProperties + // The properties specific to the system-server api scope + // + // Unless explicitly specified by using test.enabled the module-lib api scope is + // disabled by default. + System_server ApiScopeProperties + // Determines if the stubs are preferred over the implementation library // for linking, even when the client doesn't specify sdk_version. When this // is set to true, such clients are provided with the widest API surface that @@ -743,6 +772,8 @@ func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android. apiScope = apiScopeModuleLib case sdkTest: apiScope = apiScopeTest + case sdkSystemServer: + apiScope = apiScopeSystemServer default: apiScope = apiScopePublic } diff --git a/java/testing.go b/java/testing.go index f34c64af6..6fc10dae3 100644 --- a/java/testing.go +++ b/java/testing.go @@ -80,6 +80,13 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string "prebuilts/sdk/30/test/api/bar-removed.txt": nil, "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"],}`), + + // For java_sdk_library + "api/module-lib-current.txt": nil, + "api/module-lib-removed.txt": nil, + "api/system-server-current.txt": nil, + "api/system-server-removed.txt": nil, + "build/soong/scripts/gen-java-current-api-files.sh": nil, } cc.GatherRequiredFilesForTest(mockFS) |