diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/Android.bp | 1 | ||||
-rw-r--r-- | java/app.go | 4 | ||||
-rw-r--r-- | java/builder.go | 8 | ||||
-rw-r--r-- | java/config/config.go | 1 | ||||
-rw-r--r-- | java/dex.go | 18 | ||||
-rw-r--r-- | java/dexpreopt_check.go | 7 | ||||
-rw-r--r-- | java/droiddoc.go | 3 | ||||
-rw-r--r-- | java/droidstubs.go | 24 | ||||
-rw-r--r-- | java/droidstubs_test.go | 6 | ||||
-rw-r--r-- | java/java.go | 1 | ||||
-rw-r--r-- | java/java_test.go | 4 | ||||
-rw-r--r-- | java/rro.go | 5 | ||||
-rw-r--r-- | java/sdk.go | 2 | ||||
-rw-r--r-- | java/testing.go | 1 | ||||
-rw-r--r-- | java/tracereferences.go | 54 |
15 files changed, 114 insertions, 25 deletions
diff --git a/java/Android.bp b/java/Android.bp index 911af8336..99d9c38a6 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -78,6 +78,7 @@ bootstrap_go_package { "system_modules.go", "systemserver_classpath_fragment.go", "testing.go", + "tracereferences.go", "tradefed.go", ], testSrcs: [ diff --git a/java/app.go b/java/app.go index fe5eec32d..65ccc686c 100644 --- a/java/app.go +++ b/java/app.go @@ -2209,3 +2209,7 @@ func setCommonAppInfo(appInfo *AppInfo, m androidApp) { appInfo.Certificate = m.Certificate() appInfo.PrivAppAllowlist = m.PrivAppAllowlist() } + +type AppInfos []AppInfo + +var AppInfosProvider = blueprint.NewProvider[AppInfos]() diff --git a/java/builder.go b/java/builder.go index ade978450..dff0032d8 100644 --- a/java/builder.go +++ b/java/builder.go @@ -310,7 +310,7 @@ var ( gatherReleasedFlaggedApisRule = pctx.AndroidStaticRule("gatherReleasedFlaggedApisRule", blueprint.RuleParams{ - Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}' ` + + Command: `${aconfig} dump-cache --dedup --format=protobuf ` + `--out ${out} ` + `${flags_path} ` + `${filter_args} `, @@ -320,8 +320,8 @@ var ( generateMetalavaRevertAnnotationsRule = pctx.AndroidStaticRule("generateMetalavaRevertAnnotationsRule", blueprint.RuleParams{ - Command: `${keep-flagged-apis} ${in} > ${out}`, - CommandDeps: []string{"${keep-flagged-apis}"}, + Command: `${aconfig-to-metalava-flags} ${in} > ${out}`, + CommandDeps: []string{"${aconfig-to-metalava-flags}"}, }) generateApiXMLRule = pctx.AndroidStaticRule("generateApiXMLRule", @@ -339,7 +339,7 @@ func init() { pctx.HostBinToolVariable("aconfig", "aconfig") pctx.HostBinToolVariable("ravenizer", "ravenizer") pctx.HostBinToolVariable("apimapper", "apimapper") - pctx.HostBinToolVariable("keep-flagged-apis", "keep-flagged-apis") + pctx.HostBinToolVariable("aconfig-to-metalava-flags", "aconfig-to-metalava-flags") } type javaBuilderFlags struct { diff --git a/java/config/config.go b/java/config/config.go index 71025de6a..fdb8d7886 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -173,6 +173,7 @@ func init() { pctx.HostBinToolVariable("R8Cmd", "r8") pctx.HostBinToolVariable("ExtractR8RulesCmd", "extract-r8-rules") pctx.HostBinToolVariable("ResourceShrinkerCmd", "resourceshrinker") + pctx.HostBinToolVariable("TraceReferencesCmd", "tracereferences") pctx.HostBinToolVariable("HiddenAPICmd", "hiddenapi") pctx.HostBinToolVariable("ExtractApksCmd", "extract_apks") pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string { diff --git a/java/dex.go b/java/dex.go index ed2df2103..b32d5aee0 100644 --- a/java/dex.go +++ b/java/dex.go @@ -103,6 +103,19 @@ type DexProperties struct { // If true, transitive reverse dependencies of this module will have this // module's proguard spec appended to their optimization action Export_proguard_flags_files *bool + + // Path to a file containing a list of class names that should not be compiled using R8. + // These classes will be compiled by D8 similar to when Optimize.Enabled is false. + // + // Example: + // + // r8.exclude: + // com.example.Foo + // com.example.Bar + // com.example.Bar$Baz + // + // By default all classes are compiled using R8 when Optimize.Enabled is set. + Exclude *string `android:"path"` } // Keep the data uncompressed. We always need uncompressed dex for execution, @@ -528,6 +541,11 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, r8Flags = append(r8Flags, "--store-store-fence-constructor-inlining") } + if opt.Exclude != nil { + r8Flags = append(r8Flags, "--exclude", *opt.Exclude) + r8Deps = append(r8Deps, android.PathForModuleSrc(ctx, *opt.Exclude)) + } + return r8Flags, r8Deps, artProfileOutput } diff --git a/java/dexpreopt_check.go b/java/dexpreopt_check.go index c97156541..9d0f539ba 100644 --- a/java/dexpreopt_check.go +++ b/java/dexpreopt_check.go @@ -100,7 +100,12 @@ func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.Mod if systemServerJar.InstallInSystemExt() && ctx.Config().InstallApexSystemServerDexpreoptSamePartition() { partition = ctx.DeviceConfig().SystemExtPath() // system_ext } - dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, systemServerJar.Name()) + var dexLocation string + if m, ok := systemServerJar.(ModuleWithStem); ok { + dexLocation = dexpreopt.GetSystemServerDexLocation(ctx, global, m.Stem()) + } else { + ctx.PropertyErrorf("dexpreopt_systemserver_check", "%v is not a ModuleWithStem", systemServerJar.Name()) + } odexLocation := dexpreopt.ToOdexPath(dexLocation, targets[0].Arch.ArchType, partition) odexPath := getInstallPath(ctx, odexLocation) vdexPath := getInstallPath(ctx, pathtools.ReplaceExtension(odexLocation, "vdex")) diff --git a/java/droiddoc.go b/java/droiddoc.go index 225f201a9..3faf294de 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -195,6 +195,9 @@ func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersio "them instead.") } return false + } else if ctx.Config().PartialCompileFlags().Disable_stub_validation && + !ctx.Config().BuildFromTextStub() { + return false } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" { return true } else if String(apiToCheck.Api_file) != "" { diff --git a/java/droidstubs.go b/java/droidstubs.go index caad6883e..c21592518 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -821,19 +821,17 @@ func generateRevertAnnotationArgs(ctx android.ModuleContext, cmd *android.RuleBu } } - if len(aconfigFlagsPaths) == 0 { - // This argument should not be added for "everything" stubs - cmd.Flag("--revert-annotation android.annotation.FlaggedApi") - return - } + // If aconfigFlagsPaths is empty then it is still important to generate the + // Metalava flags config file, albeit with an empty set of flags, so that all + // flagged APIs will be reverted. - releasedFlaggedApisFile := android.PathForModuleOut(ctx, fmt.Sprintf("released-flagged-apis-%s.txt", stubsType.String())) - revertAnnotationsFile := android.PathForModuleOut(ctx, fmt.Sprintf("revert-annotations-%s.txt", stubsType.String())) + releasedFlagsFile := android.PathForModuleOut(ctx, fmt.Sprintf("released-flags-%s.pb", stubsType.String())) + metalavaFlagsConfigFile := android.PathForModuleOut(ctx, fmt.Sprintf("flags-config-%s.xml", stubsType.String())) ctx.Build(pctx, android.BuildParams{ Rule: gatherReleasedFlaggedApisRule, Inputs: aconfigFlagsPaths, - Output: releasedFlaggedApisFile, + Output: releasedFlagsFile, Description: fmt.Sprintf("%s gather aconfig flags", stubsType), Args: map[string]string{ "flags_path": android.JoinPathsWithPrefix(aconfigFlagsPaths, "--cache "), @@ -843,12 +841,12 @@ func generateRevertAnnotationArgs(ctx android.ModuleContext, cmd *android.RuleBu ctx.Build(pctx, android.BuildParams{ Rule: generateMetalavaRevertAnnotationsRule, - Input: releasedFlaggedApisFile, - Output: revertAnnotationsFile, - Description: fmt.Sprintf("%s revert annotations", stubsType), + Input: releasedFlagsFile, + Output: metalavaFlagsConfigFile, + Description: fmt.Sprintf("%s metalava flags config", stubsType), }) - cmd.FlagWithInput("@", revertAnnotationsFile) + cmd.FlagWithInput("--config-file ", metalavaFlagsConfigFile) } func (d *Droidstubs) commonMetalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, @@ -1245,7 +1243,7 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Add options for the other optional tasks: API-lint and check-released. // We generate separate timestamp files for them. - doApiLint := BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) + doApiLint := BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().PartialCompileFlags().Disable_api_lint doCheckReleased := apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") writeSdkValues := Bool(d.properties.Write_sdk_values) diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index dfdf87703..1f9d223b5 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -410,12 +410,12 @@ func TestAconfigDeclarations(t *testing.T) { m := result.ModuleForTests(t, "foo", "android_common") android.AssertStringDoesContain(t, "foo generates revert annotations file", - strings.Join(m.AllOutputs(), ""), "revert-annotations-exportable.txt") + strings.Join(m.AllOutputs(), ""), "flags-config-exportable.xml") // revert-annotations.txt passed to exportable stubs generation metalava command manifest := m.Output("metalava_exportable.sbox.textproto") cmdline := String(android.RuleBuilderSboxProtoForTests(t, result.TestContext, manifest).Commands[0].Command) - android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "revert-annotations-exportable.txt") + android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "flags-config-exportable.xml") android.AssertStringDoesContain(t, "foo generates exportable stubs jar", strings.Join(m.AllOutputs(), ""), "exportable/foo-stubs.srcjar") @@ -460,7 +460,7 @@ func TestReleaseExportRuntimeApis(t *testing.T) { m := result.ModuleForTests(t, "foo", "android_common") - rule := m.Output("released-flagged-apis-exportable.txt") + rule := m.Output("released-flags-exportable.pb") exposeWritableApisFilter := "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'" android.AssertStringEquals(t, "Filter argument expected to contain READ_WRITE permissions", exposeWritableApisFilter, rule.Args["filter_args"]) } diff --git a/java/java.go b/java/java.go index c1e4f8ca0..215fbbda8 100644 --- a/java/java.go +++ b/java/java.go @@ -2530,6 +2530,7 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { apiContributions := al.properties.Api_contributions addValidations := !ctx.Config().IsEnvTrue("DISABLE_STUB_VALIDATION") && !ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") && + !ctx.Config().PartialCompileFlags().Disable_stub_validation && proptools.BoolDefault(al.properties.Enable_validation, true) for _, apiContributionName := range apiContributions { ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName) diff --git a/java/java_test.go b/java/java_test.go index c91d2da97..1ba78d49b 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2912,12 +2912,12 @@ func TestApiLibraryAconfigDeclarations(t *testing.T) { m := result.ModuleForTests(t, "foo", "android_common") android.AssertStringDoesContain(t, "foo generates revert annotations file", - strings.Join(m.AllOutputs(), ""), "revert-annotations-exportable.txt") + strings.Join(m.AllOutputs(), ""), "flags-config-exportable.xml") // revert-annotations.txt passed to exportable stubs generation metalava command manifest := m.Output("metalava.sbox.textproto") cmdline := String(android.RuleBuilderSboxProtoForTests(t, result.TestContext, manifest).Commands[0].Command) - android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "revert-annotations-exportable.txt") + android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "flags-config-exportable.xml") } func TestTestOnly(t *testing.T) { diff --git a/java/rro.go b/java/rro.go index b3d934867..42d42b86a 100644 --- a/java/rro.go +++ b/java/rro.go @@ -427,6 +427,11 @@ func (a *AutogenRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android. // Install the signed apk installDir := android.PathForModuleInstall(ctx, "overlay") ctx.InstallFile(installDir, signed.Base(), signed) + + android.SetProvider(ctx, RuntimeResourceOverlayInfoProvider, RuntimeResourceOverlayInfo{ + OutputFile: signed, + Certificate: a.certificate, + }) } func (a *AutogenRuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { diff --git a/java/sdk.go b/java/sdk.go index ab1c653d1..73262dab3 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -382,7 +382,7 @@ func createAPIFingerprint(ctx android.SingletonContext) { rule.Build("api_fingerprint", "generate api_fingerprint.txt") - if ctx.Config().BuildOS == android.Linux { + if ctx.Config().BuildOS.Linux() { ctx.DistForGoals([]string{"sdk", "droidcore"}, out) } } diff --git a/java/testing.go b/java/testing.go index 3abbb8453..d7878d68d 100644 --- a/java/testing.go +++ b/java/testing.go @@ -424,7 +424,6 @@ func gatherRequiredDepsForTest() string { "kotlin-stdlib-jdk8", "kotlin-annotations", "stub-annotations", - "aconfig-annotations-lib", "aconfig_storage_stub", "unsupportedappusage", diff --git a/java/tracereferences.go b/java/tracereferences.go new file mode 100644 index 000000000..342b6a630 --- /dev/null +++ b/java/tracereferences.go @@ -0,0 +1,54 @@ +// Copyright 2025 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "android/soong/android" + + "github.com/google/blueprint" +) + +var traceReferences = pctx.AndroidStaticRule("traceReferences", + blueprint.RuleParams{ + Command: `${config.TraceReferencesCmd} ` + + // Note that we suppress missing def errors, as we're only interested + // in the direct deps between the sources and target. + `--map-diagnostics:MissingDefinitionsDiagnostic error none ` + + `--keep-rules ` + + `--output ${out} ` + + `--target ${in} ` + + // `--source` and `--lib` are already prepended to each + // jar reference in the sources and libs joined string args. + `${sources} ` + + `${libs}`, + CommandDeps: []string{"${config.TraceReferencesCmd}"}, + }, "sources", "libs") + +// Generates keep rules in output corresponding to any references from sources +// (a list of jars) onto target (the referenced jar) that are not included in +// libs (a list of external jars). +func TraceReferences(ctx android.ModuleContext, sources android.Paths, target android.Path, libs android.Paths, + output android.WritablePath) { + ctx.Build(pctx, android.BuildParams{ + Rule: traceReferences, + Input: target, + Output: output, + Implicits: append(sources, libs...), + Args: map[string]string{ + "sources": android.JoinWithPrefix(sources.Strings(), "--source "), + "libs": android.JoinWithPrefix(libs.Strings(), "--lib "), + }, + }) +} |