diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/aar.go | 5 | ||||
-rwxr-xr-x | java/app.go | 9 | ||||
-rw-r--r-- | java/app_test.go | 15 | ||||
-rw-r--r-- | java/dex.go | 1 | ||||
-rw-r--r-- | java/droiddoc.go | 15 | ||||
-rw-r--r-- | java/hiddenapi_singleton.go | 43 | ||||
-rw-r--r-- | java/hiddenapi_singleton_test.go | 97 | ||||
-rw-r--r-- | java/java.go | 13 | ||||
-rw-r--r-- | java/java_test.go | 13 | ||||
-rw-r--r-- | java/robolectric.go | 10 | ||||
-rw-r--r-- | java/sdk.go | 14 | ||||
-rw-r--r-- | java/sdk_library.go | 48 | ||||
-rw-r--r-- | java/testing.go | 4 |
13 files changed, 224 insertions, 63 deletions
diff --git a/java/aar.go b/java/aar.go index 667dd9de4..9cab0bdca 100644 --- a/java/aar.go +++ b/java/aar.go @@ -189,7 +189,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, // Version code if !hasVersionCode { - linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion()) + linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) } if !hasVersionName { @@ -774,7 +774,8 @@ func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.M return a.depIsInSameApex(ctx, dep) } -func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { return nil } diff --git a/java/app.go b/java/app.go index ae7373fc7..13d08b94a 100755 --- a/java/app.go +++ b/java/app.go @@ -157,7 +157,7 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) "abis": strings.Join(SupportedAbis(ctx), ","), "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)), "screen-densities": screenDensities, - "sdk-version": ctx.Config().PlatformSdkVersion(), + "sdk-version": ctx.Config().PlatformSdkVersion().String(), "stem": as.BaseModuleName(), "apkcerts": as.apkcertsFile.String(), "partition": as.PartitionTag(ctx.DeviceConfig()), @@ -436,7 +436,7 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil { a.checkJniLibsSdkVersion(ctx, minSdkVersion) - android.CheckMinSdkVersion(a, ctx, int(minSdkVersion)) + android.CheckMinSdkVersion(a, ctx, minSdkVersion.ApiLevel(ctx)) } else { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) } @@ -678,7 +678,7 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) { seenModules[child] = true // Skip host modules. - if child.Target().Os.Class == android.Host || child.Target().Os.Class == android.HostCross { + if child.Target().Os.Class == android.Host { return false } @@ -1637,7 +1637,8 @@ func (a *AndroidAppImport) minSdkVersion() sdkSpec { return sdkSpecFrom("") } -func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // Do not check for prebuilts against the min_sdk_version of enclosing APEX return nil } diff --git a/java/app_test.go b/java/app_test.go index 536797119..4347db8b1 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -1078,6 +1078,7 @@ func TestAppSdkVersion(t *testing.T) { platformSdkFinal bool expectedMinSdkVersion string platformApis bool + activeCodenames []string }{ { name: "current final SDK", @@ -1094,6 +1095,7 @@ func TestAppSdkVersion(t *testing.T) { platformSdkCodename: "OMR1", platformSdkFinal: false, expectedMinSdkVersion: "OMR1", + activeCodenames: []string{"OMR1"}, }, { name: "default final SDK", @@ -1112,11 +1114,14 @@ func TestAppSdkVersion(t *testing.T) { platformSdkCodename: "OMR1", platformSdkFinal: false, expectedMinSdkVersion: "OMR1", + activeCodenames: []string{"OMR1"}, }, { name: "14", sdkVersion: "14", expectedMinSdkVersion: "14", + platformSdkCodename: "S", + activeCodenames: []string{"S"}, }, } @@ -1137,6 +1142,7 @@ func TestAppSdkVersion(t *testing.T) { config := testAppConfig(nil, bp, nil) config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename + config.TestProductVariables.Platform_version_active_codenames = test.activeCodenames config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal checkSdkVersion(t, config, test.expectedMinSdkVersion) @@ -1179,15 +1185,6 @@ func TestVendorAppSdkVersion(t *testing.T) { platformSdkInt: 29, platformSdkCodename: "Q", platformSdkFinal: false, - deviceCurrentApiLevelForVendorModules: "current", - expectedMinSdkVersion: "Q", - }, - { - name: "current final SDK", - sdkVersion: "current", - platformSdkInt: 29, - platformSdkCodename: "Q", - platformSdkFinal: false, deviceCurrentApiLevelForVendorModules: "28", expectedMinSdkVersion: "28", }, diff --git a/java/dex.go b/java/dex.go index 21a59266e..055d47983 100644 --- a/java/dex.go +++ b/java/dex.go @@ -135,6 +135,7 @@ var r8, r8RE = remoteexec.MultiCommandStaticRules(pctx, "r8", "$r8Template": &remoteexec.REParams{ Labels: map[string]string{"type": "compile", "compiler": "r8"}, Inputs: []string{"$implicits", "${config.R8Jar}"}, + OutputFiles: []string{"${outUsage}"}, ExecStrategy: "${config.RER8ExecStrategy}", ToolchainInputs: []string{"${config.JavaCmd}"}, Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, diff --git a/java/droiddoc.go b/java/droiddoc.go index e39a556e7..33f422d4e 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -253,6 +253,10 @@ type DroidstubsProperties struct { // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. Create_doc_stubs *bool + // if set to true, cause Metalava to output Javadoc comments in the stubs source files. Defaults to false. + // Has no effect if create_doc_stubs: true. + Output_javadoc_comments *bool + // if set to false then do not write out stubs. Defaults to true. // // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately. @@ -1150,7 +1154,9 @@ func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuil cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) } else { cmd.FlagWithArg("--stubs ", stubsDir.String()) - cmd.Flag("--exclude-documentation-from-stubs") + if !Bool(d.properties.Output_javadoc_comments) { + cmd.Flag("--exclude-documentation-from-stubs") + } } } } @@ -1228,7 +1234,7 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml) cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml) - cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion()) + cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar") @@ -1298,6 +1304,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi cmd.BuiltTool(ctx, "metalava"). Flag(config.JavacVmFlags). + Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED"). FlagWithArg("-encoding ", "UTF-8"). FlagWithArg("-source ", javaVersion.String()). FlagWithRspFileInputList("@", srcs). @@ -1411,9 +1418,7 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released. if d.Name() != "android.car-system-stubs-docs" && - d.Name() != "android.car-stubs-docs" && - d.Name() != "system-api-stubs-docs" && - d.Name() != "test-api-stubs-docs" { + d.Name() != "android.car-stubs-docs" { cmd.Flag("--lints-as-errors") cmd.Flag("--warnings-as-errors") // Most lints are actually warnings. } diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index b6af3bf28..61a9b97e4 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -92,31 +92,34 @@ func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) { // stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image // modules. func stubFlagsRule(ctx android.SingletonContext) { - // Public API stubs - publicStubModules := []string{ - "android_stubs_current", + var publicStubModules []string + var systemStubModules []string + var testStubModules []string + var corePlatformStubModules []string + + if ctx.Config().AlwaysUsePrebuiltSdks() { + // Build configuration mandates using prebuilt stub modules + publicStubModules = append(publicStubModules, "sdk_public_current_android") + systemStubModules = append(systemStubModules, "sdk_system_current_android") + testStubModules = append(testStubModules, "sdk_test_current_android") + } else { + // Use stub modules built from source + publicStubModules = append(publicStubModules, "android_stubs_current") + systemStubModules = append(systemStubModules, "android_system_stubs_current") + testStubModules = append(testStubModules, "android_test_stubs_current") } + // We do not have prebuilts of the core platform api yet + corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") // Add the android.test.base to the set of stubs only if the android.test.base module is on // the boot jars list as the runtime will only enforce hiddenapi access against modules on // that list. - if inList("android.test.base", ctx.Config().BootJars()) && !ctx.Config().AlwaysUsePrebuiltSdks() { - publicStubModules = append(publicStubModules, "android.test.base.stubs") - } - - // System API stubs - systemStubModules := []string{ - "android_system_stubs_current", - } - - // Test API stubs - testStubModules := []string{ - "android_test_stubs_current", - } - - // Core Platform API stubs - corePlatformStubModules := []string{ - "legacy.core.platform.api.stubs", + if inList("android.test.base", ctx.Config().BootJars()) { + if ctx.Config().AlwaysUsePrebuiltSdks() { + publicStubModules = append(publicStubModules, "sdk_public_current_android.test.base") + } else { + publicStubModules = append(publicStubModules, "android.test.base.stubs") + } } // Allow products to define their own stubs for custom product jars that apps can use. diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index bcca93a00..dbdab7ade 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -16,8 +16,11 @@ package java import ( "android/soong/android" + "fmt" "strings" "testing" + + "github.com/google/blueprint/proptools" ) func testConfigWithBootJars(bp string, bootJars []string) android.Config { @@ -32,19 +35,30 @@ func testContextWithHiddenAPI() *android.TestContext { return ctx } -func testHiddenAPI(t *testing.T, bp string, bootJars []string) (*android.TestContext, android.Config) { +func testHiddenAPIWithConfig(t *testing.T, config android.Config) *android.TestContext { t.Helper() - config := testConfigWithBootJars(bp, bootJars) ctx := testContextWithHiddenAPI() run(t, ctx, config) + return ctx +} + +func testHiddenAPIBootJars(t *testing.T, bp string, bootJars []string) (*android.TestContext, android.Config) { + config := testConfigWithBootJars(bp, bootJars) - return ctx, config + return testHiddenAPIWithConfig(t, config), config +} + +func testHiddenAPIUnbundled(t *testing.T, unbundled bool) (*android.TestContext, android.Config) { + config := testConfig(nil, ``, nil) + config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(unbundled) + + return testHiddenAPIWithConfig(t, config), config } func TestHiddenAPISingleton(t *testing.T) { - ctx, _ := testHiddenAPI(t, ` + ctx, _ := testHiddenAPIBootJars(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -61,7 +75,7 @@ func TestHiddenAPISingleton(t *testing.T) { } func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { - ctx, _ := testHiddenAPI(t, ` + ctx, _ := testHiddenAPIBootJars(t, ` java_import { name: "foo", jars: ["a.jar"], @@ -78,7 +92,7 @@ func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { } func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { - ctx, _ := testHiddenAPI(t, ` + ctx, _ := testHiddenAPIBootJars(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -107,7 +121,7 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { } func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { - ctx, _ := testHiddenAPI(t, ` + ctx, _ := testHiddenAPIBootJars(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -134,3 +148,72 @@ func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { t.Errorf("Did not expect %s in hiddenapi command, but it was present: %s", fromSourceJarArg, hiddenapiRule.RuleParams.Command) } } + +func TestHiddenAPISingletonSdks(t *testing.T) { + testCases := []struct { + name string + unbundledBuild bool + publicStub string + systemStub string + testStub string + corePlatformStub string + }{ + { + name: "testBundled", + unbundledBuild: false, + publicStub: "android_stubs_current", + systemStub: "android_system_stubs_current", + testStub: "android_test_stubs_current", + corePlatformStub: "legacy.core.platform.api.stubs", + }, { + name: "testUnbundled", + unbundledBuild: true, + publicStub: "sdk_public_current_android", + systemStub: "sdk_system_current_android", + testStub: "sdk_test_current_android", + corePlatformStub: "legacy.core.platform.api.stubs", + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ctx, _ := testHiddenAPIUnbundled(t, tc.unbundledBuild) + + hiddenAPI := ctx.SingletonForTests("hiddenapi") + hiddenapiRule := hiddenAPI.Rule("hiddenapi") + wantPublicStubs := "--public-stub-classpath=" + generateSdkDexPath(tc.publicStub, tc.unbundledBuild) + if !strings.Contains(hiddenapiRule.RuleParams.Command, wantPublicStubs) { + t.Errorf("Expected %s in hiddenapi command, but it was not present: %s", wantPublicStubs, hiddenapiRule.RuleParams.Command) + } + + wantSystemStubs := "--system-stub-classpath=" + generateSdkDexPath(tc.systemStub, tc.unbundledBuild) + if !strings.Contains(hiddenapiRule.RuleParams.Command, wantSystemStubs) { + t.Errorf("Expected %s in hiddenapi command, but it was not present: %s", wantSystemStubs, hiddenapiRule.RuleParams.Command) + } + + wantTestStubs := "--test-stub-classpath=" + generateSdkDexPath(tc.testStub, tc.unbundledBuild) + if !strings.Contains(hiddenapiRule.RuleParams.Command, wantTestStubs) { + t.Errorf("Expected %s in hiddenapi command, but it was not present: %s", wantTestStubs, hiddenapiRule.RuleParams.Command) + } + + wantCorePlatformStubs := "--core-platform-stub-classpath=" + generateDexPath(tc.corePlatformStub) + if !strings.Contains(hiddenapiRule.RuleParams.Command, wantCorePlatformStubs) { + t.Errorf("Expected %s in hiddenapi command, but it was not present: %s", wantCorePlatformStubs, hiddenapiRule.RuleParams.Command) + } + }) + } +} + +func generateDexedPath(subDir, dex, module string) string { + return fmt.Sprintf("%s/.intermediates/%s/android_common/%s/%s.jar", buildDir, subDir, dex, module) +} + +func generateDexPath(module string) string { + return generateDexedPath(module, "dex", module) +} + +func generateSdkDexPath(module string, unbundled bool) string { + if unbundled { + return generateDexedPath("prebuilts/sdk/"+module, "dex", module) + } + return generateDexPath(module) +} diff --git a/java/java.go b/java/java.go index d67e9e098..1d7eaa771 100644 --- a/java/java.go +++ b/java/java.go @@ -1658,7 +1658,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { if v := sdkSpec.version; v.isNumbered() { return v.String() } else { - return ctx.Config().DefaultAppTargetSdk() + return ctx.Config().DefaultAppTargetSdk(ctx).String() } } @@ -1876,7 +1876,8 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu return j.depIsInSameApex(ctx, dep) } -func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { sdkSpec := j.minSdkVersion() if !sdkSpec.specified() { return fmt.Errorf("min_sdk_version is not specified") @@ -1888,7 +1889,7 @@ func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersi if err != nil { return err } - if int(ver) > sdkVersion { + if ver.ApiLevel(ctx).GreaterThan(sdkVersion) { return fmt.Errorf("newer SDK(%v)", ver) } return nil @@ -2753,7 +2754,8 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu return j.depIsInSameApex(ctx, dep) } -func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // Do not check for prebuilts against the min_sdk_version of enclosing APEX return nil } @@ -2936,7 +2938,8 @@ func (j *DexImport) DexJarBuildPath() android.Path { return j.dexJarFile } -func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // we don't check prebuilt modules for sdk_version return nil } diff --git a/java/java_test.go b/java/java_test.go index 9e6357792..f16639aa8 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1487,6 +1487,12 @@ func TestJavaSdkLibrary(t *testing.T) { libs: ["foo"], sdk_version: "system_29", } + java_library { + name: "baz-module-30", + srcs: ["c.java"], + libs: ["foo"], + sdk_version: "module_30", + } `) // check the existence of the internal modules @@ -1533,6 +1539,13 @@ func TestJavaSdkLibrary(t *testing.T) { "prebuilts/sdk/29/system/foo.jar") } + bazModule30Javac := ctx.ModuleForTests("baz-module-30", "android_common").Rule("javac") + // tests if "baz-module-30" is actually linked to the module 30 stubs lib + if !strings.Contains(bazModule30Javac.Args["classpath"], "prebuilts/sdk/30/module-lib/foo.jar") { + t.Errorf("baz-module-30 javac classpath %v does not contain %q", bazModule30Javac.Args["classpath"], + "prebuilts/sdk/30/module-lib/foo.jar") + } + // test if baz has exported SDK lib names foo and bar to qux qux := ctx.ModuleForTests("qux", "android_common") if quxLib, ok := qux.Module().(*Library); ok { diff --git a/java/robolectric.go b/java/robolectric.go index ec112bc99..04fc11722 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -31,7 +31,6 @@ func init() { } var robolectricDefaultLibs = []string{ - "robolectric_android-all-stub", "Robolectric_all-target", "mockito-robolectric-prebuilt", "truth-prebuilt", @@ -99,7 +98,8 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, roboCoverageLibsTag, r.robolectricProperties.Coverage_libs...) - ctx.AddVariationDependencies(nil, roboRuntimesTag, "robolectric-android-all-prebuilts") + ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), + roboRuntimesTag, "robolectric-android-all-prebuilts") } func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -335,7 +335,7 @@ func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) func robolectricRuntimesFactory() android.Module { module := &robolectricRuntimes{} module.AddProperties(&module.props) - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + android.InitAndroidArchModule(module, android.HostSupportedNoCross, android.MultilibCommon) return module } @@ -365,6 +365,10 @@ func (r *robolectricRuntimes) DepsMutator(ctx android.BottomUpMutatorContext) { } func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleContext) { + if ctx.Target().Os != ctx.Config().BuildOSCommonTarget.Os { + return + } + files := android.PathsForModuleSrc(ctx, r.props.Jars) androidAllDir := android.PathForModuleInstall(ctx, "android-all") diff --git a/java/sdk.go b/java/sdk.go index 56fa12b3e..971791f4a 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -107,7 +107,7 @@ type sdkVersion int const ( // special version number for a not-yet-frozen SDK - sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevel) + sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevelInt) // special version number to be used for SDK specs where version number doesn't // make sense, e.g. "none", "", etc. sdkVersionNone sdkVersion = sdkVersion(0) @@ -133,6 +133,10 @@ func (v sdkVersion) String() string { return "(no version)" } +func (v sdkVersion) ApiLevel(ctx android.EarlyModuleContext) android.ApiLevel { + return android.ApiLevelOrPanic(ctx, v.String()) +} + // asNumberString directly converts the numeric value of this sdk version as a string. // When isNumbered() is true, this method is the same as String(). However, for sdkVersionCurrent // and sdkVersionNone, this returns 10000 and 0 while String() returns "current" and "(no version"), @@ -218,7 +222,7 @@ func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool { return ctx.Config().AlwaysUsePrebuiltSdks() } else if s.version.isNumbered() { // validation check - if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest { + if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest && s.kind != sdkModule { panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind)) return false } @@ -243,7 +247,7 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e if s.version.isNumbered() { return s.version, nil } - return sdkVersion(ctx.Config().DefaultAppTargetSdkInt()), nil + return sdkVersion(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()), nil } // effectiveVersionString converts an sdkSpec into the concrete version string that the module @@ -251,8 +255,8 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e // it returns the codename (P, Q, R, etc.) func (s sdkSpec) effectiveVersionString(ctx android.EarlyModuleContext) (string, error) { ver, err := s.effectiveVersion(ctx) - if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdkInt() { - return ctx.Config().DefaultAppTargetSdk(), nil + if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt() { + return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil } return ver.String(), err } diff --git a/java/sdk_library.go b/java/sdk_library.go index 1a5ef544c..60924a662 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -589,6 +589,9 @@ type commonToSdkLibraryAndImportProperties struct { // An Android shared library is one that can be referenced in a <uses-library> element // in an AndroidManifest.xml. Shared_library *bool + + // Files containing information about supported java doc tags. + Doctag_files []string `android:"path"` } // Common code between sdk library and sdk library import @@ -601,6 +604,9 @@ type commonToSdkLibraryAndImport struct { commonSdkLibraryProperties commonToSdkLibraryAndImportProperties + // Paths to commonSdkLibraryProperties.Doctag_files + doctagPaths android.Paths + // Functionality related to this being used as a component of a java_sdk_library. EmbeddableSdkLibraryComponent } @@ -633,6 +639,10 @@ func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android return true } +func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { + c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) +} + // Module name of the runtime implementation library func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { return c.moduleBase.BaseModuleName() + ".impl" @@ -732,6 +742,14 @@ func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Pat } } else { + switch tag { + case ".doctags": + if c.doctagPaths != nil { + return c.doctagPaths, nil + } else { + return nil, fmt.Errorf("no doctag_files specified on %s", c.moduleBase.BaseModuleName()) + } + } return nil, nil } } @@ -1014,6 +1032,8 @@ func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { } func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + module.generateCommonBuildActions(ctx) + // Only build an implementation library if required. if module.requiresRuntimeImplementationLibrary() { module.Library.GenerateAndroidBuildActions(ctx) @@ -1203,6 +1223,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC Sdk_version *string System_modules *string Libs []string + Output_javadoc_comments *bool Arg_files []string Args *string Java_version *string @@ -1278,6 +1299,11 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC } droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) + // Output Javadoc comments for public scope. + if apiScope == apiScopePublic { + props.Output_javadoc_comments = proptools.BoolPtr(true) + } + // Add in scope specific arguments. droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files @@ -1878,7 +1904,8 @@ func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, return false } -func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // we don't check prebuilt modules for sdk_version return nil } @@ -1888,6 +1915,8 @@ func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { } func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { + module.generateCommonBuildActions(ctx) + // Record the paths to the prebuilt stubs library and stubs source. ctx.VisitDirectDeps(func(to android.Module) { tag := ctx.OtherModuleDependencyTag(to) @@ -2078,7 +2107,8 @@ func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { // do nothing } -func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked return nil } @@ -2179,6 +2209,9 @@ type sdkLibrarySdkMemberProperties struct { // True if the java_sdk_library_import is for a shared library, false // otherwise. Shared_library *bool + + // The paths to the doctag files to add to the prebuilt. + Doctag_paths android.Paths } type scopeProperties struct { @@ -2218,6 +2251,7 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe s.Libs = sdk.properties.Libs s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) + s.Doctag_paths = sdk.doctagPaths } func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { @@ -2266,6 +2300,16 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo } } + if len(s.Doctag_paths) > 0 { + dests := []string{} + for _, p := range s.Doctag_paths { + dest := filepath.Join("doctags", p.Rel()) + ctx.SnapshotBuilder().CopyToSnapshot(p, dest) + dests = append(dests, dest) + } + propertySet.AddProperty("doctag_files", dests) + } + if len(s.Libs) > 0 { propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) } diff --git a/java/testing.go b/java/testing.go index 322dc9ec6..461fd3f9f 100644 --- a/java/testing.go +++ b/java/testing.go @@ -55,6 +55,8 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string "prebuilts/sdk/30/public/framework.aidl": nil, "prebuilts/sdk/30/system/android.jar": nil, "prebuilts/sdk/30/system/foo.jar": nil, + "prebuilts/sdk/30/module-lib/android.jar": nil, + "prebuilts/sdk/30/module-lib/foo.jar": nil, "prebuilts/sdk/30/public/core-for-system-modules.jar": nil, "prebuilts/sdk/current/core/android.jar": nil, "prebuilts/sdk/current/public/android.jar": nil, @@ -88,7 +90,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string "prebuilts/sdk/30/system/api/bar-removed.txt": nil, "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"],}`), + "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "30", "current"], imports_sdk_version: "none", imports_compile_dex:true,}`), "bin.py": nil, python.StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%' |