diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/aar.go | 51 | ||||
-rw-r--r-- | java/android_manifest.go | 7 | ||||
-rw-r--r-- | java/android_resources.go | 1 | ||||
-rw-r--r-- | java/androidmk.go | 2 | ||||
-rwxr-xr-x | java/app.go | 36 | ||||
-rw-r--r-- | java/app_test.go | 36 | ||||
-rw-r--r-- | java/device_host_converter.go | 2 | ||||
-rw-r--r-- | java/dexpreopt.go | 14 | ||||
-rw-r--r-- | java/dexpreopt_bootjars_test.go | 2 | ||||
-rw-r--r-- | java/hiddenapi_singleton_test.go | 6 | ||||
-rw-r--r-- | java/java.go | 36 | ||||
-rw-r--r-- | java/java_test.go | 20 | ||||
-rw-r--r-- | java/sdk_test.go | 8 |
13 files changed, 112 insertions, 109 deletions
diff --git a/java/aar.go b/java/aar.go index 157d677d3..7c3840bb1 100644 --- a/java/aar.go +++ b/java/aar.go @@ -109,7 +109,6 @@ type aapt struct { useEmbeddedNativeLibs bool useEmbeddedDex bool usesNonSdkApis bool - sdkLibraries dexpreopt.LibraryPaths hasNoCode bool LoggingParent string resourceFiles android.Paths @@ -259,12 +258,11 @@ var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", CommandDeps: []string{"${config.Zip2ZipCmd}"}, }) -func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) { +func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, + sdkLibraries dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) { - transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries := - aaptLibs(ctx, sdkContext) - - a.sdkLibraries = sdkLibraries + transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags := + aaptLibs(ctx, sdkContext, sdkLibraries) // App manifest file manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") @@ -391,29 +389,31 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex } // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths -func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths, - staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries dexpreopt.LibraryPaths) { +func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dexpreopt.ClassLoaderContextMap) ( + transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) { var sharedLibs android.Paths + if sdkLibraries == nil { + // Not all callers need to compute class loader context, those who don't just pass nil. + // Create a temporary class loader context here (it will be computed, but not used). + sdkLibraries = make(dexpreopt.ClassLoaderContextMap) + } + sdkDep := decodeSdkDep(ctx, sdkContext) if sdkDep.useFiles { sharedLibs = append(sharedLibs, sdkDep.jars...) } - sdkLibraries = make(dexpreopt.LibraryPaths) - ctx.VisitDirectDeps(func(module android.Module) { + depName := ctx.OtherModuleName(module) + var exportPackage android.Path aarDep, _ := module.(AndroidLibraryDependency) if aarDep != nil { exportPackage = aarDep.ExportPackage() } - if dep, ok := module.(Dependency); ok { - sdkLibraries.AddLibraryPaths(dep.ExportedSdkLibs()) - } - switch ctx.OtherModuleDependencyTag(module) { case instrumentationForTag: // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. @@ -426,7 +426,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati // (including the java_sdk_library) itself then append any implicit sdk library // names to the list of sdk libraries to be added to the manifest. if component, ok := module.(SdkLibraryComponentDependency); ok { - sdkLibraries.MaybeAddLibraryPath(ctx, component.OptionalImplicitSdkLibrary(), + sdkLibraries.MaybeAddContext(ctx, component.OptionalImplicitSdkLibrary(), component.DexJarBuildPath(), component.DexJarInstallPath()) } @@ -439,7 +439,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...) - sdkLibraries.AddLibraryPaths(aarDep.ExportedSdkLibs()) + sdkLibraries.AddContextMap(aarDep.ExportedSdkLibs(), depName) if aarDep.ExportedAssets().Valid() { assets = append(assets, aarDep.ExportedAssets().Path()) } @@ -457,6 +457,12 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati } } } + + // Add nested dependencies after processing the direct dependency: if it is a <uses-library>, + // nested context is added as its subcontext, and should not be re-added at the top-level. + if dep, ok := module.(Dependency); ok { + sdkLibraries.AddContextMap(dep.ExportedSdkLibs(), depName) + } }) deps = append(deps, sharedLibs...) @@ -473,7 +479,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs) transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests) - return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries + return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags } type AndroidLibrary struct { @@ -508,8 +514,8 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.aapt.isLibrary = true - a.aapt.buildActions(ctx, sdkContext(a)) - a.exportedSdkLibs = a.aapt.sdkLibraries + a.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) + a.aapt.buildActions(ctx, sdkContext(a), a.exportedSdkLibs) a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() @@ -781,12 +787,11 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) linkDeps = append(linkDeps, a.manifest) - transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags, sdkLibraries := - aaptLibs(ctx, sdkContext(a)) + transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags := + aaptLibs(ctx, sdkContext(a), nil) _ = staticLibManifests _ = staticRRODirs - _ = sdkLibraries linkDeps = append(linkDeps, libDeps...) linkFlags = append(linkFlags, libFlags...) @@ -827,7 +832,7 @@ func (a *AARImport) AidlIncludeDirs() android.Paths { return nil } -func (a *AARImport) ExportedSdkLibs() dexpreopt.LibraryPaths { +func (a *AARImport) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { return nil } diff --git a/java/android_manifest.go b/java/android_manifest.go index 62cd11203..6b39c3584 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -43,8 +43,9 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", "args", "libs") // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml -func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries dexpreopt.LibraryPaths, - isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path { +func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, + sdkLibraries dexpreopt.ClassLoaderContextMap, isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, + useEmbeddedDex, hasNoCode bool, loggingParent string) android.Path { var args []string if isLibrary { @@ -70,7 +71,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext args = append(args, "--use-embedded-dex") } - for _, usesLib := range android.SortedStringKeys(sdkLibraries) { + for _, usesLib := range sdkLibraries.UsesLibs() { if inList(usesLib, dexpreopt.OptionalCompatUsesLibs) { args = append(args, "--optional-uses-library", usesLib) } else { diff --git a/java/android_resources.go b/java/android_resources.go index 97f76793c..720d3a5ae 100644 --- a/java/android_resources.go +++ b/java/android_resources.go @@ -23,6 +23,7 @@ import ( func init() { android.RegisterPreSingletonType("overlay", OverlaySingletonFactory) + } var androidResourceIgnoreFilenames = []string{ diff --git a/java/androidmk.go b/java/androidmk.go index e1a661fc1..c6062457f 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -115,7 +115,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile) } - entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", android.SortedStringKeys(library.exportedSdkLibs)...) + entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs.UsesLibs()...) if len(library.additionalCheckedModules) != 0 { entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...) diff --git a/java/app.go b/java/app.go index c24e0c56b..9ff413cc1 100755 --- a/java/app.go +++ b/java/app.go @@ -565,9 +565,8 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...) a.aapt.splitNames = a.appProperties.Package_splits - a.aapt.sdkLibraries = a.exportedSdkLibs a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent) - a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...) + a.aapt.buildActions(ctx, sdkContext(a), a.exportedSdkLibs, aaptLinkFlags...) // apps manifests are handled by aapt, don't let Module see them a.properties.Manifest = nil @@ -601,7 +600,7 @@ func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") } -func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext, sdkLibs dexpreopt.LibraryPaths) android.Path { +func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { a.dexpreopter.installPath = a.installPath(ctx) if a.dexProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. @@ -609,12 +608,8 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext, sdkLibs dexpreop } a.dexpreopter.uncompressedDex = *a.dexProperties.Uncompress_dex a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() - a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs - a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx) - a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx) - a.dexpreopter.libraryPaths.AddLibraryPaths(sdkLibs) + a.dexpreopter.classLoaderContexts = a.exportedSdkLibs a.dexpreopter.manifestFile = a.mergedManifestFile - a.exportedSdkLibs = make(dexpreopt.LibraryPaths) if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) @@ -784,6 +779,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput } + a.exportedSdkLibs = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) + // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) @@ -791,7 +788,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.usesLibrary.freezeEnforceUsesLibraries() // Add implicit SDK libraries to <uses-library> list. - for _, usesLib := range android.SortedStringKeys(a.aapt.sdkLibraries) { + for _, usesLib := range a.exportedSdkLibs.UsesLibs() { a.usesLibrary.addLib(usesLib, inList(usesLib, dexpreopt.OptionalCompatUsesLibs)) } @@ -808,7 +805,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.linter.resources = a.aapt.resourceFiles a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps() - dexJarFile := a.dexBuildActions(ctx, a.aapt.sdkLibraries) + dexJarFile := a.dexBuildActions(ctx) jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) jniJarFile := a.jniBuildActions(jniLibs, ctx) @@ -1540,9 +1537,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() - a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs - a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx) - a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx) + a.dexpreopter.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed) if a.dexpreopter.uncompressedDex { @@ -1852,7 +1847,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC aaptLinkFlags = append(aaptLinkFlags, "--rename-overlay-target-package "+*r.overridableProperties.Target_package_name) } - r.aapt.buildActions(ctx, r, aaptLinkFlags...) + r.aapt.buildActions(ctx, r, nil, aaptLinkFlags...) // Sign the built package _, certificates := collectAppDeps(ctx, r, false, false) @@ -1976,17 +1971,18 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s return optionalUsesLibs } -// usesLibraryPaths returns a map of module names of shared library dependencies to the paths +// Returns a map of module names of shared library dependencies to the paths // to their dex jars on host and on device. -func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths { - usesLibPaths := make(dexpreopt.LibraryPaths) +func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext) dexpreopt.ClassLoaderContextMap { + clcMap := make(dexpreopt.ClassLoaderContextMap) if !ctx.Config().UnbundledBuild() { ctx.VisitDirectDeps(func(m android.Module) { - if _, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { + if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { dep := ctx.OtherModuleName(m) if lib, ok := m.(Dependency); ok { - usesLibPaths.AddLibraryPath(ctx, dep, lib.DexJarBuildPath(), lib.DexJarInstallPath()) + clcMap.AddContextForSdk(ctx, tag.sdkVersion, dep, + lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ExportedSdkLibs()) } else if ctx.Config().AllowMissingDependencies() { ctx.AddMissingDependencies([]string{dep}) } else { @@ -1996,7 +1992,7 @@ func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.Libr }) } - return usesLibPaths + return clcMap } // enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs diff --git a/java/app_test.go b/java/app_test.go index 82577e32e..6429ab836 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -59,7 +59,7 @@ func testAppConfig(env map[string]string, bp string, fs map[string][]byte) andro func testApp(t *testing.T, bp string) *android.TestContext { config := testAppConfig(nil, bp, nil) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -220,7 +220,7 @@ func TestAndroidAppSet_Variants(t *testing.T) { config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI config.TestProductVariables.Platform_sdk_version = &test.sdkVersion config.Targets[android.Android] = test.targets - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) module := ctx.ModuleForTests("foo", "android_common") const packedSplitApks = "foo.zip" @@ -657,7 +657,7 @@ func TestResourceDirs(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) module := ctx.ModuleForTests("foo", "android_common") @@ -973,7 +973,7 @@ func TestAndroidResources(t *testing.T) { config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { @@ -1039,7 +1039,7 @@ func TestAndroidResources(t *testing.T) { } func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) { - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -1633,7 +1633,7 @@ func TestCertificates(t *testing.T) { if test.certificateOverride != "" { config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride} } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -1698,7 +1698,7 @@ func TestRequestV4SigningFlag(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { config := testAppConfig(nil, test.bp, nil) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -1758,7 +1758,7 @@ func TestPackageNameOverride(t *testing.T) { if test.packageNameOverride != "" { config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride} } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -1793,7 +1793,7 @@ func TestInstrumentationTargetOverridden(t *testing.T) { ` config := testAppConfig(nil, bp, nil) config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -2416,7 +2416,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { config := testAppConfig(nil, bp, nil) config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -2777,7 +2777,7 @@ func TestUsesLibraries(t *testing.T) { config := testAppConfig(nil, bp, nil) config.TestProductVariables.MissingUsesLibraries = []string{"baz"} - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -2815,11 +2815,11 @@ func TestUsesLibraries(t *testing.T) { // Test that all present libraries are preopted, including implicit SDK dependencies, possibly stubs cmd = app.Rule("dexpreopt").RuleParams.Command w := `--target-context-for-sdk any ` + - `PCL[/system/framework/foo.jar]#` + - `PCL[/system/framework/quuz.jar]#` + `PCL[/system/framework/qux.jar]#` + - `PCL[/system/framework/runtime-library.jar]#` + - `PCL[/system/framework/bar.jar]` + `PCL[/system/framework/quuz.jar]#` + + `PCL[/system/framework/foo.jar]#` + + `PCL[/system/framework/bar.jar]#` + + `PCL[/system/framework/runtime-library.jar]` if !strings.Contains(cmd, w) { t.Errorf("wanted %q in %q", w, cmd) } @@ -3129,7 +3129,7 @@ func TestUncompressDex(t *testing.T) { config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) @@ -3209,7 +3209,7 @@ func TestRuntimeResourceOverlay(t *testing.T) { } ` config := testAppConfig(nil, bp, fs) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) m := ctx.ModuleForTests("foo", "android_common") @@ -3506,7 +3506,7 @@ func TestEnforceRRO_propagatesToDependencies(t *testing.T) { config.TestProductVariables.EnforceRROExemptedTargets = testCase.enforceRROExemptTargets } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) modules := []string{"foo", "bar"} diff --git a/java/device_host_converter.go b/java/device_host_converter.go index 40a2280d9..d8b617e7d 100644 --- a/java/device_host_converter.go +++ b/java/device_host_converter.go @@ -163,7 +163,7 @@ func (d *DeviceHostConverter) AidlIncludeDirs() android.Paths { return nil } -func (d *DeviceHostConverter) ExportedSdkLibs() dexpreopt.LibraryPaths { +func (d *DeviceHostConverter) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { return nil } diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 20dbc666b..a21fb7640 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -33,11 +33,9 @@ type dexpreopter struct { isTest bool isPresignedPrebuilt bool - manifestFile android.Path - usesLibs []string - optionalUsesLibs []string - enforceUsesLibs bool - libraryPaths dexpreopt.LibraryPaths + manifestFile android.Path + enforceUsesLibs bool + classLoaderContexts dexpreopt.ClassLoaderContextMap builtInstalled string } @@ -193,10 +191,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo ProfileIsTextListing: profileIsTextListing, ProfileBootListing: profileBootListing, - EnforceUsesLibraries: d.enforceUsesLibs, - OptionalUsesLibraries: d.optionalUsesLibs, - UsesLibraries: d.usesLibs, - LibraryPaths: d.libraryPaths, + EnforceUsesLibraries: d.enforceUsesLibs, + ClassLoaderContexts: d.classLoaderContexts, Archs: archs, DexPreoptImages: images, diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index ab31958cf..95fe5e10e 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -51,7 +51,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList([]string{"platform:foo", "platform:bar", "platform:baz"}) dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) - ctx := testContext() + ctx := testContext(config) RegisterDexpreoptBootJarsComponents(ctx) run(t, ctx, config) diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 7acaae750..34a485618 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -29,8 +29,8 @@ func testConfigWithBootJars(bp string, bootJars []string) android.Config { return config } -func testContextWithHiddenAPI() *android.TestContext { - ctx := testContext() +func testContextWithHiddenAPI(config android.Config) *android.TestContext { + ctx := testContext(config) ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory) return ctx } @@ -38,7 +38,7 @@ func testContextWithHiddenAPI() *android.TestContext { func testHiddenAPIWithConfig(t *testing.T, config android.Config) *android.TestContext { t.Helper() - ctx := testContextWithHiddenAPI() + ctx := testContextWithHiddenAPI(config) run(t, ctx, config) return ctx diff --git a/java/java.go b/java/java.go index 9f0905126..d6dc148a6 100644 --- a/java/java.go +++ b/java/java.go @@ -416,8 +416,8 @@ type Module struct { // manifest file to use instead of properties.Manifest overrideManifest android.OptionalPath - // map of SDK libs exported by this java module to their build and install paths - exportedSdkLibs dexpreopt.LibraryPaths + // map of SDK version to class loader context + exportedSdkLibs dexpreopt.ClassLoaderContextMap // list of plugins that this java module is exporting exportedPluginJars android.Paths @@ -509,7 +509,7 @@ type Dependency interface { ImplementationJars() android.Paths ResourceJars() android.Paths AidlIncludeDirs() android.Paths - ExportedSdkLibs() dexpreopt.LibraryPaths + ExportedSdkLibs() dexpreopt.ClassLoaderContextMap ExportedPlugins() (android.Paths, []string) SrcJarArgs() ([]string, android.Paths) BaseModuleName() string @@ -1027,7 +1027,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case libTag: deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) // names of sdk libs that are directly depended are exported - j.exportedSdkLibs.MaybeAddLibraryPath(ctx, dep.OptionalImplicitSdkLibrary(), dep.DexJarBuildPath(), dep.DexJarInstallPath()) + j.exportedSdkLibs.MaybeAddContext(ctx, dep.OptionalImplicitSdkLibrary(), + dep.DexJarBuildPath(), dep.DexJarInstallPath()) case staticLibTag: ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) } @@ -1038,7 +1039,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case libTag, instrumentationForTag: deps.classpath = append(deps.classpath, dep.HeaderJars()...) // sdk lib names from dependencies are re-exported - j.exportedSdkLibs.AddLibraryPaths(dep.ExportedSdkLibs()) + j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) pluginJars, pluginClasses := dep.ExportedPlugins() addPlugins(&deps, pluginJars, pluginClasses...) @@ -1050,7 +1051,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...) // sdk lib names from dependencies are re-exported - j.exportedSdkLibs.AddLibraryPaths(dep.ExportedSdkLibs()) + j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) pluginJars, pluginClasses := dep.ExportedPlugins() addPlugins(&deps, pluginJars, pluginClasses...) @@ -1902,7 +1903,7 @@ func (j *Module) AidlIncludeDirs() android.Paths { return j.exportAidlIncludeDirs } -func (j *Module) ExportedSdkLibs() dexpreopt.LibraryPaths { +func (j *Module) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { return j.exportedSdkLibs } @@ -2041,7 +2042,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) } j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex - j.exportedSdkLibs = make(dexpreopt.LibraryPaths) + j.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) j.compile(ctx, nil) // Collect the module directory for IDE info in java/jdeps.go. @@ -2061,11 +2062,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { // add the name of that java_sdk_library to the exported sdk libs to make sure // that, if necessary, a <uses-library> element for that java_sdk_library is // added to the Android manifest. - j.exportedSdkLibs.MaybeAddLibraryPath(ctx, j.OptionalImplicitSdkLibrary(), j.DexJarBuildPath(), j.DexJarInstallPath()) + j.exportedSdkLibs.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), + j.DexJarBuildPath(), j.DexJarInstallPath()) // A non-SDK library may provide a <uses-library> (the name may be different from the module name). if lib := proptools.String(j.usesLibraryProperties.Provides_uses_lib); lib != "" { - j.exportedSdkLibs.AddLibraryPath(ctx, lib, j.DexJarBuildPath(), j.DexJarInstallPath()) + j.exportedSdkLibs.AddContext(ctx, lib, j.DexJarBuildPath(), j.DexJarInstallPath()) } j.distFiles = j.GenerateTaggedDistFiles(ctx) @@ -2644,7 +2646,7 @@ type Import struct { dexJarFile android.Path combinedClasspathFile android.Path - exportedSdkLibs dexpreopt.LibraryPaths + exportedSdkLibs dexpreopt.ClassLoaderContextMap exportAidlIncludeDirs android.Paths hideApexVariantFromMake bool @@ -2719,7 +2721,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { TransformJetifier(ctx, outputFile, inputFile) } j.combinedClasspathFile = outputFile - j.exportedSdkLibs = make(dexpreopt.LibraryPaths) + j.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap) var flags javaBuilderFlags @@ -2733,7 +2735,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { case libTag, staticLibTag: flags.classpath = append(flags.classpath, dep.HeaderJars()...) // sdk lib names from dependencies are re-exported - j.exportedSdkLibs.AddLibraryPaths(dep.ExportedSdkLibs()) + j.exportedSdkLibs.AddContextMap(dep.ExportedSdkLibs(), otherName) case bootClasspathTag: flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars()...) } @@ -2742,7 +2744,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { case libTag: flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) // names of sdk libs that are directly depended are exported - j.exportedSdkLibs.AddLibraryPath(ctx, otherName, dep.DexJarBuildPath(), dep.DexJarInstallPath()) + j.exportedSdkLibs.AddContext(ctx, otherName, + dep.DexJarBuildPath(), dep.DexJarInstallPath()) } } }) @@ -2757,7 +2760,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // add the name of that java_sdk_library to the exported sdk libs to make sure // that, if necessary, a <uses-library> element for that java_sdk_library is // added to the Android manifest. - j.exportedSdkLibs.MaybeAddLibraryPath(ctx, j.OptionalImplicitSdkLibrary(), outputFile, installFile) + j.exportedSdkLibs.MaybeAddContext(ctx, j.OptionalImplicitSdkLibrary(), + outputFile, installFile) j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) @@ -2839,7 +2843,7 @@ func (j *Import) AidlIncludeDirs() android.Paths { return j.exportAidlIncludeDirs } -func (j *Import) ExportedSdkLibs() dexpreopt.LibraryPaths { +func (j *Import) ExportedSdkLibs() dexpreopt.ClassLoaderContextMap { return j.exportedSdkLibs } diff --git a/java/java_test.go b/java/java_test.go index 6c0a90856..4594b8111 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -70,9 +70,9 @@ func testConfig(env map[string]string, bp string, fs map[string][]byte) android. return config } -func testContext() *android.TestContext { +func testContext(config android.Config) *android.TestContext { - ctx := android.NewTestArchContext() + ctx := android.NewTestArchContext(config) RegisterJavaBuildComponents(ctx) RegisterAppBuildComponents(ctx) RegisterAARBuildComponents(ctx) @@ -115,7 +115,7 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) { pathCtx := android.PathContextForTesting(config) dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) - ctx.Register(config) + ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) @@ -129,12 +129,12 @@ func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContex func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) { t.Helper() - ctx := testContext() + ctx := testContext(config) pathCtx := android.PathContextForTesting(config) dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) - ctx.Register(config) + ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Android.bp") if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) @@ -163,7 +163,7 @@ func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) { t.Helper() - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) return ctx, config @@ -1440,7 +1440,7 @@ func TestJavaLibrary(t *testing.T) { } `), }) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) } @@ -1458,7 +1458,7 @@ func TestJavaImport(t *testing.T) { } `), }) - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) } @@ -1593,8 +1593,8 @@ func TestJavaSdkLibrary(t *testing.T) { // 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 { - sdkLibs := android.SortedStringKeys(quxLib.ExportedSdkLibs()) - if w := []string{"bar", "foo", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) { + sdkLibs := quxLib.ExportedSdkLibs().UsesLibs() + if w := []string{"foo", "bar", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) { t.Errorf("qux should export %q but exports %q", w, sdkLibs) } } diff --git a/java/sdk_test.go b/java/sdk_test.go index 776069dc9..dc90ea304 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -356,7 +356,7 @@ func TestClasspath(t *testing.T) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) checkClasspath(t, ctx, true /* isJava8 */) @@ -377,7 +377,7 @@ func TestClasspath(t *testing.T) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) checkClasspath(t, ctx, false /* isJava8 */) @@ -401,7 +401,7 @@ func TestClasspath(t *testing.T) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) checkClasspath(t, ctx, true /* isJava8 */) @@ -417,7 +417,7 @@ func TestClasspath(t *testing.T) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) } - ctx := testContext() + ctx := testContext(config) run(t, ctx, config) checkClasspath(t, ctx, false /* isJava8 */) |