diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/Android.bp | 1 | ||||
-rw-r--r-- | java/app.go | 30 | ||||
-rw-r--r-- | java/app_import.go | 10 | ||||
-rw-r--r-- | java/base.go | 30 | ||||
-rw-r--r-- | java/builder.go | 8 | ||||
-rw-r--r-- | java/config/config.go | 1 | ||||
-rw-r--r-- | java/dex.go | 47 | ||||
-rw-r--r-- | java/dex_test.go | 43 | ||||
-rw-r--r-- | java/dexpreopt.go | 3 | ||||
-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 | 13 | ||||
-rw-r--r-- | java/java_test.go | 73 | ||||
-rw-r--r-- | java/jdeps.go | 2 | ||||
-rw-r--r-- | java/kotlin.go | 16 | ||||
-rw-r--r-- | java/lint.go | 2 | ||||
-rw-r--r-- | java/platform_compat_config.go | 2 | ||||
-rw-r--r-- | java/ravenwood.go | 2 | ||||
-rw-r--r-- | java/ravenwood_test.go | 11 | ||||
-rw-r--r-- | java/robolectric.go | 8 | ||||
-rw-r--r-- | java/robolectric_test.go | 11 | ||||
-rw-r--r-- | java/rro.go | 22 | ||||
-rw-r--r-- | java/rro_test.go | 18 | ||||
-rw-r--r-- | java/sdk.go | 2 | ||||
-rw-r--r-- | java/sdk_library.go | 6 | ||||
-rw-r--r-- | java/testing.go | 1 | ||||
-rw-r--r-- | java/tracereferences.go | 54 |
29 files changed, 372 insertions, 84 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..553c65894 100644 --- a/java/app.go +++ b/java/app.go @@ -425,6 +425,10 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon } else { moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite") } + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: a.appTestHelperAppProperties.Test_suites, + }) } func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -531,7 +535,7 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer if _, ok := android.OtherModuleProvider(ctx, m, cc.CcInfoProvider); !ok { panic(fmt.Errorf("jni dependency is not a cc module: %v", m)) } - commonInfo, ok := android.OtherModuleProvider(ctx, m, android.CommonModuleInfoKey) + commonInfo, ok := android.OtherModuleProvider(ctx, m, android.CommonModuleInfoProvider) if !ok { panic(fmt.Errorf("jni dependency doesn't have CommonModuleInfo provider: %v", m)) } @@ -1229,7 +1233,7 @@ func collectJniDeps(ctx android.ModuleContext, seenModulePaths := make(map[string]bool) ctx.WalkDepsProxy(func(module, parent android.ModuleProxy) bool { - if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { + if !android.OtherModulePointerProviderOrDefault(ctx, module, android.CommonModuleInfoProvider).Enabled { return false } otherName := ctx.OtherModuleName(module) @@ -1249,7 +1253,7 @@ func collectJniDeps(ctx android.ModuleContext, } seenModulePaths[path.String()] = true - commonInfo := android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey) + commonInfo := android.OtherModulePointerProviderOrDefault(ctx, module, android.CommonModuleInfoProvider) if checkNativeSdkVersion && commonInfo.SdkVersion == "" { ctx.PropertyErrorf("jni_libs", "JNI dependency %q uses platform APIs, but this module does not", otherName) @@ -1287,13 +1291,13 @@ func collectJniDeps(ctx android.ModuleContext, } func (a *AndroidApp) WalkPayloadDeps(ctx android.BaseModuleContext, do android.PayloadDepsCallback) { - ctx.WalkDeps(func(child, parent android.Module) bool { + ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { // TODO(ccross): Should this use android.DepIsInSameApex? Right now it is applying the android app // heuristics to every transitive dependency, when it should probably be using the heuristics of the // immediate parent. isExternal := !a.GetDepInSameApexChecker().OutgoingDepIsInSameApex(ctx.OtherModuleDependencyTag(child)) - if am, ok := child.(android.ApexModule); ok { - if !do(ctx, parent, am, isExternal) { + if am, ok := android.OtherModuleProvider(ctx, child, android.CommonModuleInfoProvider); ok && am.IsApexModule { + if !do(ctx, parent, child, isExternal) { return false } } @@ -1307,12 +1311,12 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { } depsInfo := android.DepNameToDepInfoMap{} - a.WalkPayloadDeps(ctx, func(ctx android.BaseModuleContext, from android.Module, to android.ApexModule, externalDep bool) bool { + a.WalkPayloadDeps(ctx, func(ctx android.BaseModuleContext, from, to android.ModuleProxy, externalDep bool) bool { depName := to.Name() // Skip dependencies that are only available to APEXes; they are developed with updatability // in mind and don't need manual approval. - if android.OtherModuleProviderOrDefault(ctx, to, android.CommonModuleInfoKey).NotAvailableForPlatform { + if android.OtherModulePointerProviderOrDefault(ctx, to, android.CommonModuleInfoProvider).NotAvailableForPlatform { return true } @@ -1322,7 +1326,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { depsInfo[depName] = info } else { toMinSdkVersion := "(no version)" - if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoKey); ok && + if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoProvider); ok && !info.MinSdkVersion.IsPlatform && info.MinSdkVersion.ApiLevel != nil { toMinSdkVersion = info.MinSdkVersion.ApiLevel.String() } @@ -1703,6 +1707,10 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { moduleInfoJSON.AutoTestConfig = []string{"true"} } moduleInfoJSON.TestMainlineModules = append(moduleInfoJSON.TestMainlineModules, a.testProperties.Test_mainline_modules...) + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: a.testProperties.Test_suites, + }) } func testcaseRel(paths android.Paths) []string { @@ -2209,3 +2217,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/app_import.go b/java/app_import.go index 37c673ca0..c0e8171d5 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -177,7 +177,7 @@ type AndroidAppImportProperties struct { Prebuilt_info *string `android:"path"` // Path of extracted apk which is extracted from prebuilt apk. Use this extracted to import. - Extract_apk *string + Extract_apk proptools.Configurable[string] // Compress the output APK using gzip. Defaults to false. Compress_apk proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"` @@ -307,7 +307,7 @@ func (a *AndroidAppImport) uncompressEmbeddedJniLibs( func (a *AndroidAppImport) extractSubApk( ctx android.ModuleContext, inputPath android.Path, outputPath android.WritablePath) { - extractApkPath := *a.properties.Extract_apk + extractApkPath := a.properties.Extract_apk.GetOrDefault(ctx, "") ctx.Build(pctx, android.BuildParams{ Rule: extractApkRule, Input: inputPath, @@ -405,7 +405,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext // TODO: LOCAL_PACKAGE_SPLITS srcApk := a.prebuilt.SingleSourcePath(ctx) - if a.properties.Extract_apk != nil { + if a.properties.Extract_apk.GetOrDefault(ctx, "") != "" { extract_apk := android.PathForModuleOut(ctx, "extract-apk", ctx.ModuleName()+".apk") a.extractSubApk(ctx, srcApk, extract_apk) srcApk = extract_apk @@ -787,6 +787,10 @@ func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContex a.updateModuleInfoJSON(ctx) a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: a.testProperties.Test_suites, + }) } func (a *AndroidTestImport) updateModuleInfoJSON(ctx android.ModuleContext) { diff --git a/java/base.go b/java/base.go index 1fb44e779..1a12075bc 100644 --- a/java/base.go +++ b/java/base.go @@ -629,7 +629,7 @@ func CheckStableSdkVersion(ctx android.BaseModuleContext, module android.ModuleP return nil } if info.SdkVersion.Kind == android.SdkCorePlatform { - if useLegacyCorePlatformApi(ctx, android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).BaseModuleName) { + if useLegacyCorePlatformApi(ctx, android.OtherModulePointerProviderOrDefault(ctx, module, android.CommonModuleInfoProvider).BaseModuleName) { return fmt.Errorf("non stable SDK %v - uses legacy core platform", info.SdkVersion) } else { // Treat stable core platform as stable. @@ -888,6 +888,10 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { // Add dependency on libraries that provide additional hidden api annotations. ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...) + // Add dependency on (soft) downstream libs from which to trace references during optimization. + traceRefs := j.dexProperties.Optimize.Trace_references_from.GetOrDefault(ctx, []string{}) + ctx.AddVariationDependencies(nil, traceReferencesTag, traceRefs...) + // For library dependencies that are component libraries (like stubs), add the implementation // as a dependency (dexpreopt needs to be against the implementation library, not stubs). for _, dep := range libDeps { @@ -1160,14 +1164,7 @@ func (j *Module) addGeneratedSrcJars(path android.Path) { j.properties.Generated_srcjars = append(j.properties.Generated_srcjars, path) } -func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspathJars, extraCombinedJars, - extraDepCombinedJars android.Paths) *JavaInfo { - - manifest := j.overrideManifest - if !manifest.Valid() && j.properties.Manifest != nil { - manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) - } - +func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspathJars, extraCombinedJars, extraDepCombinedJars android.Paths) *JavaInfo { // Auto-propagating jarjar rules jarjarProviderData := j.collectJarJarRules(ctx) if jarjarProviderData != nil { @@ -1288,7 +1285,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath transitiveStaticLibsHeaderJars := deps.transitiveStaticLibsHeaderJars localHeaderJars, combinedHeaderJarFile := j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, - extraCombinedJars, manifest) + extraCombinedJars) combinedHeaderJarFile, jarjared := j.jarjarIfNecessary(ctx, combinedHeaderJarFile, jarName, "turbine", false) if jarjared { @@ -1401,7 +1398,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) kotlinHeaderJar := android.PathForModuleOut(ctx, "kotlin_headers", jarName) - j.kotlinCompile(ctx, kotlinJar, kotlinHeaderJar, uniqueSrcFiles, kotlinCommonSrcFiles, srcJars, flags, manifest) + j.kotlinCompile(ctx, kotlinJar, kotlinHeaderJar, uniqueSrcFiles, kotlinCommonSrcFiles, srcJars, flags) if ctx.Failed() { return nil } @@ -1436,7 +1433,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath extraJars := slices.Clone(kotlinHeaderJars) extraJars = append(extraJars, extraCombinedJars...) var combinedHeaderJarFile android.Path - localHeaderJars, combinedHeaderJarFile = j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars, manifest) + localHeaderJars, combinedHeaderJarFile = j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars) shardingHeaderJars = localHeaderJars var jarjared bool @@ -1617,6 +1614,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath combinedResourceJar = combinedJar } + manifest := j.overrideManifest + if !manifest.Valid() && j.properties.Manifest != nil { + manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) + } + // Combine the classes built from sources, any manifests, and any static libraries into // classes.jar. If there is only one input jar this step will be skipped. var outputFile android.Path @@ -2071,7 +2073,7 @@ func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, deps deps, flags javaBuilderFlags, jarName string, - extraJars android.Paths, manifest android.OptionalPath) (localHeaderJars android.Paths, combinedHeaderJar android.Path) { + extraJars android.Paths) (localHeaderJars android.Paths, combinedHeaderJar android.Path) { if len(srcFiles) > 0 || len(srcJars) > 0 { // Compile java sources into turbine.jar. @@ -2090,7 +2092,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars // we cannot skip the combine step for now if there is only one jar // since we have to strip META-INF/TRANSITIVE dir from turbine.jar combinedHeaderJarOutputPath := android.PathForModuleOut(ctx, "turbine-combined", jarName) - TransformJarsToJar(ctx, combinedHeaderJarOutputPath, "for turbine", jars, manifest, + TransformJarsToJar(ctx, combinedHeaderJarOutputPath, "for turbine", jars, android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"}) return localHeaderJars, combinedHeaderJarOutputPath 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..ed9c82ba2 100644 --- a/java/dex.go +++ b/java/dex.go @@ -103,6 +103,34 @@ 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"` + + // Optional list of downstream (Java) libraries from which to trace and preserve references + // when optimizing. Note that this requires that the source reference does *not* have + // a strict lib dependency on this target; dependencies should be on intermediate targets + // statically linked into this target, e.g., if A references B, and we want to trace and + // keep references from A when optimizing B, you would create an intermediate B.impl ( + // containing all static code), have A depend on `B.impl` via libs, and set + // `trace_references_from: ["A"]` on B. + // + // Also note that these are *not* inherited across targets, they must be specified at the + // top-level target that is optimized. + // + // TODO(b/212737576): Handle this implicitly using bottom-up deps mutation and implicit + // creation of a proxy `.impl` library. + Trace_references_from proptools.Configurable[[]string] `android:"arch_variant"` } // Keep the data uncompressed. We always need uncompressed dex for execution, @@ -445,6 +473,20 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...) + traceReferencesSources := android.Paths{} + ctx.VisitDirectDepsProxyWithTag(traceReferencesTag, func(m android.ModuleProxy) { + if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok { + traceReferencesSources = append(traceReferencesSources, dep.ImplementationJars...) + } + }) + if len(traceReferencesSources) > 0 { + traceTarget := dexParams.classesJar + traceLibs := android.FirstUniquePaths(append(flags.bootClasspath.Paths(), flags.dexClasspath.Paths()...)) + traceReferencesFlags := android.PathForModuleOut(ctx, "proguard", "trace_references.flags") + TraceReferences(ctx, traceReferencesSources, traceTarget, traceLibs, traceReferencesFlags) + flagFiles = append(flagFiles, traceReferencesFlags) + } + flagFiles = android.FirstUniquePaths(flagFiles) r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include ")) @@ -528,6 +570,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/dex_test.go b/java/dex_test.go index 66d801dcc..e94864bbc 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -866,3 +866,46 @@ func TestDebugReleaseFlags(t *testing.T) { }) } } + +func TestTraceReferences(t *testing.T) { + t.Parallel() + bp := ` + android_app { + name: "app", + libs: ["lib.impl"], + srcs: ["foo.java"], + platform_apis: true, + } + + java_library { + name: "lib", + optimize: { + enabled: true, + trace_references_from: ["app"], + }, + srcs: ["bar.java"], + static_libs: ["lib.impl"], + installable: true, + } + + java_library { + name: "lib.impl", + srcs: ["baz.java"], + } + ` + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, bp) + + appJar := result.ModuleForTests(t, "app", "android_common").Output("combined/app.jar").Output + libJar := result.ModuleForTests(t, "lib", "android_common").Output("combined/lib.jar").Output + libTraceRefs := result.ModuleForTests(t, "lib", "android_common").Rule("traceReferences") + libR8 := result.ModuleForTests(t, "lib", "android_common").Rule("r8") + + android.AssertStringDoesContain(t, "expected trace reference source from app jar", + libTraceRefs.Args["sources"], "--source "+appJar.String()) + android.AssertStringEquals(t, "expected trace reference target into lib jar", + libJar.String(), libTraceRefs.Input.String()) + android.AssertStringDoesContain(t, "expected trace reference proguard flags in lib r8 flags", + libR8.Args["r8Flags"], "trace_references.flags") +} diff --git a/java/dexpreopt.go b/java/dexpreopt.go index b21cfc968..e8e1cd405 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -650,6 +650,9 @@ func checkSystemServerOrder(ctx android.ModuleContext, libName string) { // for now just exclude any known irrelevant dependencies that would lead to incorrect errors. if _, ok := tag.(bootclasspathDependencyTag); ok { return false + } else if tag == traceReferencesTag { + // Allow ordering inversion if the dependency is purely for tracing references. + return false } depIndex := jars.IndexOfJar(dep.Name()) if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars { 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..dd9f852f0 100644 --- a/java/java.go +++ b/java/java.go @@ -578,6 +578,7 @@ var ( extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true} jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true} r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true} + traceReferencesTag = dependencyTag{name: "trace-references"} syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} javaApiContributionTag = dependencyTag{name: "java-api-contribution"} aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"} @@ -608,6 +609,7 @@ var ( kotlinPluginTag, syspropPublicStubDepTag, instrumentationForTag, + traceReferencesTag, } ) @@ -1954,6 +1956,10 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, ctx.InstallFile(pathInTestCases, ctx.ModuleName()+".jar", j.outputFile) } } + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: j.testProperties.Test_suites, + }) } func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -1970,6 +1976,10 @@ func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContex if optionalConfig.Valid() { moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, optionalConfig.String()) } + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: j.testHelperLibraryProperties.Test_suites, + }) } func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -2225,7 +2235,7 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { // install these alongside the java binary. ctx.VisitDirectDepsProxyWithTag(jniInstallTag, func(jni android.ModuleProxy) { // Use the BaseModuleName of the dependency (without any prebuilt_ prefix) - commonInfo, _ := android.OtherModuleProvider(ctx, jni, android.CommonModuleInfoKey) + commonInfo := android.OtherModulePointerProviderOrDefault(ctx, jni, android.CommonModuleInfoProvider) j.androidMkNamesOfJniLibs = append(j.androidMkNamesOfJniLibs, commonInfo.BaseModuleName+":"+commonInfo.Target.Arch.ArchType.Bitness()) }) // Check that native libraries are not listed in `required`. Prompt users to use `jni_libs` instead. @@ -2530,6 +2540,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 a6290a628..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) { @@ -3193,3 +3193,72 @@ cc_library_shared { deps := findDepsOfModule(res, res.ModuleForTests(t, "myjavabin", "android_common").Module(), "mynativelib") android.AssertIntEquals(t, "Create a dep on the first variant", 1, len(deps)) } + +func TestBootJarNotInUsesLibs(t *testing.T) { + t.Parallel() + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary"), + FixtureConfigureApexBootJars("myapex:mysdklibrary"), + ).RunTestWithBp(t, ` + bootclasspath_fragment { + name: "myfragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: ["*"], + }, + } + + java_sdk_library { + name: "mysdklibrary", + srcs: ["Test.java"], + compile_dex: true, + public: {enabled: true}, + min_sdk_version: "2", + permitted_packages: ["mysdklibrary"], + sdk_version: "current", + } + + java_sdk_library { + name: "myothersdklibrary", + srcs: ["Test.java"], + compile_dex: true, + public: {enabled: true}, + min_sdk_version: "2", + permitted_packages: ["myothersdklibrary"], + sdk_version: "current", + } + + java_library { + name: "foo", + libs: [ + "bar", + "mysdklibrary.stubs", + ], + srcs: ["A.java"], + } + + java_library { + name: "bar", + libs: [ + "myothersdklibrary.stubs" + ], + } + `) + ctx := result.TestContext + fooModule := ctx.ModuleForTests(t, "foo", "android_common") + + androidMkEntries := android.AndroidMkEntriesForTest(t, ctx, fooModule.Module())[0] + localExportSdkLibraries := androidMkEntries.EntryMap["LOCAL_EXPORT_SDK_LIBRARIES"] + android.AssertStringListDoesNotContain(t, + "boot jar should not be included in uses libs entries", + localExportSdkLibraries, + "mysdklibrary", + ) + android.AssertStringListContains(t, + "non boot jar is included in uses libs entries", + localExportSdkLibraries, + "myothersdklibrary", + ) +} diff --git a/java/jdeps.go b/java/jdeps.go index 4711dc1a4..56142c89b 100644 --- a/java/jdeps.go +++ b/java/jdeps.go @@ -46,7 +46,7 @@ func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCont moduleInfos := make(map[string]android.IdeInfo) ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { - if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { + if !android.OtherModulePointerProviderOrDefault(ctx, module, android.CommonModuleInfoProvider).Enabled { return } diff --git a/java/kotlin.go b/java/kotlin.go index 57d0802e4..308bb0305 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -40,8 +40,8 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports ` -kotlin-home $emptyDir ` + ` -Xplugin=${config.KotlinAbiGenPluginJar} ` + ` -P plugin:org.jetbrains.kotlin.jvm.abi:outputDir=$headerClassesDir && ` + - `${config.SoongZipCmd} -jar $jarArgs -o $out -C $classesDir -D $classesDir -write_if_changed && ` + - `${config.SoongZipCmd} -jar $jarArgs -o $headerJar -C $headerClassesDir -D $headerClassesDir -write_if_changed && ` + + `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir -write_if_changed && ` + + `${config.SoongZipCmd} -jar -o $headerJar -C $headerClassesDir -D $headerClassesDir -write_if_changed && ` + `rm -rf "$srcJarDir" "$classesDir" "$headerClassesDir"`, CommandDeps: []string{ "${config.KotlincCmd}", @@ -62,7 +62,7 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports Restat: true, }, "kotlincFlags", "classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "classesDir", - "headerClassesDir", "headerJar", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name", "jarArgs") + "headerClassesDir", "headerJar", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir", "name") var kotlinKytheExtract = pctx.AndroidStaticRule("kotlinKythe", blueprint.RuleParams{ @@ -104,7 +104,8 @@ func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Path // kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile. func (j *Module) kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile android.WritablePath, - srcFiles, commonSrcFiles, srcJars android.Paths, flags javaBuilderFlags, manifest android.OptionalPath) { + srcFiles, commonSrcFiles, srcJars android.Paths, + flags javaBuilderFlags) { var deps android.Paths deps = append(deps, flags.kotlincClasspath...) @@ -126,12 +127,6 @@ func (j *Module) kotlinCompile(ctx android.ModuleContext, outputFile, headerOutp android.WriteFileRule(ctx, classpathRspFile, strings.Join(flags.kotlincClasspath.Strings(), " ")) deps = append(deps, classpathRspFile) - var jarArgs string - if manifest.Valid() { - jarArgs = "-m " + manifest.Path().String() - deps = append(deps, manifest.Path()) - } - ctx.Build(pctx, android.BuildParams{ Rule: kotlinc, Description: "kotlinc", @@ -152,7 +147,6 @@ func (j *Module) kotlinCompile(ctx android.ModuleContext, outputFile, headerOutp "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), "kotlinJvmTarget": flags.javaVersion.StringForKotlinc(), "name": kotlinName, - "jarArgs": jarArgs, }, }) diff --git a/java/lint.go b/java/lint.go index c31dfd005..dc1e51ffb 100644 --- a/java/lint.go +++ b/java/lint.go @@ -659,7 +659,7 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) { var outputs []*LintInfo var dirs []string ctx.VisitAllModuleProxies(func(m android.ModuleProxy) { - commonInfo, _ := android.OtherModuleProvider(ctx, m, android.CommonModuleInfoKey) + commonInfo := android.OtherModulePointerProviderOrDefault(ctx, m, android.CommonModuleInfoProvider) if ctx.Config().KatiEnabled() && !commonInfo.ExportedToMake { return } diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index ab4f8f81f..d2ec8bd4f 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -277,7 +277,7 @@ func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.Singlet var compatConfigMetadata android.Paths ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { - if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { + if !android.OtherModulePointerProviderOrDefault(ctx, module, android.CommonModuleInfoProvider).Enabled { return } if c, ok := android.OtherModuleProvider(ctx, module, PlatformCompatConfigMetadataInfoProvider); ok { diff --git a/java/ravenwood.go b/java/ravenwood.go index c4078c587..a942dc653 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -117,6 +117,8 @@ func ravenwoodTestFactory() android.Module { "ravenwood-tests", } module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false) + module.Module.sourceProperties.Test_only = proptools.BoolPtr(true) + module.Module.sourceProperties.Top_level_test_target = true InitJavaModule(module, android.DeviceSupported) android.InitDefaultableModule(module) diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go index 24a02bbdc..d6493bcfa 100644 --- a/java/ravenwood_test.go +++ b/java/ravenwood_test.go @@ -230,4 +230,15 @@ func TestRavenwoodTest(t *testing.T) { android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/libred.so") android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so") android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar") + + // Ensure they are listed as "test" modules for code coverage + expectedTestOnlyModules := []string{ + "ravenwood-test", + "ravenwood-test-empty", + } + expectedTopLevelTests := []string{ + "ravenwood-test", + "ravenwood-test-empty", + } + assertTestOnlyAndTopLevel(t, ctx, expectedTestOnlyModules, expectedTopLevelTests) } diff --git a/java/robolectric.go b/java/robolectric.go index be369f780..1d204a4e0 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -284,6 +284,11 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ TestSuites: r.TestSuites(), }) + + android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ + TestOnly: Bool(r.sourceProperties.Test_only), + TopLevelTarget: r.sourceProperties.Top_level_test_target, + }) } func generateSameDirRoboTestConfigJar(ctx android.ModuleContext, outputFile android.ModuleOutPath) { @@ -335,7 +340,8 @@ func RobolectricTestFactory() android.Module { module.Module.dexpreopter.isTest = true module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) - + module.Module.sourceProperties.Test_only = proptools.BoolPtr(true) + module.Module.sourceProperties.Top_level_test_target = true module.testProperties.Test_suites = []string{"robolectric-tests"} InitJavaModule(module, android.DeviceSupported) diff --git a/java/robolectric_test.go b/java/robolectric_test.go index 4bf224b4f..cc16c6a26 100644 --- a/java/robolectric_test.go +++ b/java/robolectric_test.go @@ -107,4 +107,15 @@ func TestRobolectricJniTest(t *testing.T) { // Check that the .so files make it into the output. module := ctx.ModuleForTests(t, "robo-test", "android_common") module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so") + + // Ensure they are listed as "test" modules for code coverage + expectedTestOnlyModules := []string{ + "robo-test", + } + + expectedTopLevelTests := []string{ + "robo-test", + } + assertTestOnlyAndTopLevel(t, ctx, expectedTestOnlyModules, expectedTopLevelTests) + } diff --git a/java/rro.go b/java/rro.go index b3d934867..4ae8d7fc7 100644 --- a/java/rro.go +++ b/java/rro.go @@ -99,15 +99,6 @@ type RuntimeResourceOverlayProperties struct { Overrides []string } -// RuntimeResourceOverlayModule interface is used by the apex package to gather information from -// a RuntimeResourceOverlay module. -type RuntimeResourceOverlayModule interface { - android.Module - OutputFile() android.Path - Certificate() Certificate - Theme() string -} - // RRO's partition logic is different from the partition logic of other modules defined in soong/android/paths.go // The default partition for RRO is "/product" and not "/system" func rroPartition(ctx android.ModuleContext) string { @@ -217,11 +208,13 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC }) android.SetProvider(ctx, RuntimeResourceOverlayInfoProvider, RuntimeResourceOverlayInfo{ - OutputFile: r.OutputFile(), + OutputFile: r.outputFile, Certificate: r.Certificate(), Theme: r.Theme(), }) + ctx.SetOutputFiles([]android.Path{r.outputFile}, "") + buildComplianceMetadata(ctx) } @@ -252,10 +245,6 @@ func (r *RuntimeResourceOverlay) Certificate() Certificate { return r.certificate } -func (r *RuntimeResourceOverlay) OutputFile() android.Path { - return r.outputFile -} - func (r *RuntimeResourceOverlay) Theme() string { return String(r.properties.Theme) } @@ -427,6 +416,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/rro_test.go b/java/rro_test.go index 0ccc8e707..3e4fed51e 100644 --- a/java/rro_test.go +++ b/java/rro_test.go @@ -358,3 +358,21 @@ func TestRuntimeResourceOverlayFlagsPackages(t *testing.T) { "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt", ) } + +func TestCanBeDataOfTest(t *testing.T) { + android.GroupFixturePreparers( + prepareForJavaTest, + ).RunTestWithBp(t, ` + runtime_resource_overlay { + name: "foo", + sdk_version: "current", + } + android_test { + name: "bar", + data: [ + ":foo", + ], + } + `) + // Just test that this doesn't get errors +} 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/sdk_library.go b/java/sdk_library.go index 0fee529e9..00ba8b2fb 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1337,10 +1337,10 @@ func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { func CheckMinSdkVersion(ctx android.ModuleContext, module *Library) { android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.BaseModuleContext, do android.PayloadDepsCallback) { - ctx.WalkDeps(func(child android.Module, parent android.Module) bool { + ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { isExternal := !android.IsDepInSameApex(ctx, module, child) - if am, ok := child.(android.ApexModule); ok { - if !do(ctx, parent, am, isExternal) { + if am, ok := android.OtherModuleProvider(ctx, child, android.CommonModuleInfoProvider); ok && am.IsApexModule { + if !do(ctx, parent, child, isExternal) { return false } } 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 "), + }, + }) +} |