diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/dexpreopt_bootjars.go | 11 | ||||
| -rw-r--r-- | java/java.go | 81 | ||||
| -rw-r--r-- | java/java_test.go | 132 |
3 files changed, 120 insertions, 104 deletions
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 062005b5b..80211fd7a 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -422,16 +422,19 @@ func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) { // Note that the same jar may occur in multiple modules. // This logic is tested in the apex package to avoid import cycle apex <-> java. func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) { - // Ignore any module that is not listed in the boot image configuration. name := ctx.ModuleName(module) + + // Strip a prebuilt_ prefix so that this can access the dex jar from a prebuilt module. + name = android.RemoveOptionalPrebuiltPrefix(name) + + // Ignore any module that is not listed in the boot image configuration. index := image.modules.IndexOfJar(name) if index == -1 { return -1, nil } - // It is an error if a module configured in the boot image does not support - // accessing the dex jar. This is safe because every module that has the same - // name has to have the same module type. + // It is an error if a module configured in the boot image does not support accessing the dex jar. + // This is safe because every module that has the same name has to have the same module type. jar, hasJar := module.(interface{ DexJarBuildPath() android.Path }) if !hasJar { ctx.Errorf("module %q configured in boot image %q does not support accessing dex jar", module, image.name) diff --git a/java/java.go b/java/java.go index 99bc55dd6..3c6146b76 100644 --- a/java/java.go +++ b/java/java.go @@ -2859,6 +2859,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) var flags javaBuilderFlags + var deapexerModule android.Module ctx.VisitDirectDeps(func(module android.Module) { tag := ctx.OtherModuleDependencyTag(module) @@ -2879,6 +2880,11 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } addCLCFromDep(ctx, module, j.classLoaderContexts) + + // Save away the `deapexer` module on which this depends, if any. + if tag == android.DeapexerTag { + deapexerModule = module + } }) if Bool(j.properties.Installable) { @@ -2888,39 +2894,60 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) - if ctx.Device() && Bool(j.dexProperties.Compile_dex) { - sdkDep := decodeSdkDep(ctx, sdkContext(j)) - if sdkDep.invalidVersion { - ctx.AddMissingDependencies(sdkDep.bootclasspath) - ctx.AddMissingDependencies(sdkDep.java9Classpath) - } else if sdkDep.useFiles { - // sdkDep.jar is actually equivalent to turbine header.jar. - flags.classpath = append(flags.classpath, sdkDep.jars...) - } + if ctx.Device() { + // If this is a variant created for a prebuilt_apex then use the dex implementation jar + // obtained from the associated deapexer module. + ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) + if ai.ForPrebuiltApex { + if deapexerModule == nil { + // This should never happen as a variant for a prebuilt_apex is only created if the + // deapxer module has been configured to export the dex implementation jar for this module. + ctx.ModuleErrorf("internal error: module %q does not depend on a `deapexer` module for prebuilt_apex %q", + j.Name(), ai.ApexVariationName) + } - // Dex compilation + // Get the path of the dex implementation jar from the `deapexer` module. + di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) + j.dexJarFile = di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar") + if j.dexJarFile == nil { + // This should never happen as a variant for a prebuilt_apex is only created if the + // prebuilt_apex has been configured to export the java library dex file. + ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name()) + } + } else if Bool(j.dexProperties.Compile_dex) { + sdkDep := decodeSdkDep(ctx, sdkContext(j)) + if sdkDep.invalidVersion { + ctx.AddMissingDependencies(sdkDep.bootclasspath) + ctx.AddMissingDependencies(sdkDep.java9Classpath) + } else if sdkDep.useFiles { + // sdkDep.jar is actually equivalent to turbine header.jar. + flags.classpath = append(flags.classpath, sdkDep.jars...) + } - j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", jarName) - if j.dexProperties.Uncompress_dex == nil { - // If the value was not force-set by the user, use reasonable default based on the module. - j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) - } - j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex + // Dex compilation - var dexOutputFile android.ModuleOutPath - dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName) - if ctx.Failed() { - return - } + j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", jarName) + if j.dexProperties.Uncompress_dex == nil { + // If the value was not force-set by the user, use reasonable default based on the module. + j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) + } + j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex - configurationName := j.BaseModuleName() - primary := j.Prebuilt().UsePrebuilt() + var dexOutputFile android.ModuleOutPath + dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName) + if ctx.Failed() { + return + } - // Hidden API CSV generation and dex encoding - dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, outputFile, - proptools.Bool(j.dexProperties.Uncompress_dex)) + configurationName := j.BaseModuleName() + primary := j.Prebuilt().UsePrebuilt() - j.dexJarFile = dexOutputFile + // Hidden API CSV generation and dex encoding + dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, outputFile, + proptools.Bool(j.dexProperties.Uncompress_dex)) + + j.dexJarFile = dexOutputFile + } } } diff --git a/java/java_test.go b/java/java_test.go index a2466f995..1c0738fa4 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -867,83 +867,43 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { return config } - isValidDependency := func(configInfo testConfigInfo) bool { - if configInfo.enforceVendorInterface == false { - return true - } - - if configInfo.enforceJavaSdkLibraryCheck == false { - return true - } - - if inList("bar", configInfo.allowList) { - return true - } - - if configInfo.libraryType == "java_library" { - if configInfo.fromPartition != configInfo.toPartition { - if !configInfo.enforceProductInterface && - ((configInfo.fromPartition == "system" && configInfo.toPartition == "product") || - (configInfo.fromPartition == "product" && configInfo.toPartition == "system")) { - return true - } - return false - } - } - - return true - } - errorMessage := "is not allowed across the partitions" - allPartitionCombinations := func() [][2]string { - var result [][2]string - partitions := []string{"system", "vendor", "product"} - - for _, fromPartition := range partitions { - for _, toPartition := range partitions { - result = append(result, [2]string{fromPartition, toPartition}) - } - } - - return result - } - - allFlagCombinations := func() [][3]bool { - var result [][3]bool - flagValues := [2]bool{false, true} - - for _, vendorInterface := range flagValues { - for _, productInterface := range flagValues { - for _, enableEnforce := range flagValues { - result = append(result, [3]bool{vendorInterface, productInterface, enableEnforce}) - } - } - } + testJavaWithConfig(t, createTestConfig(testConfigInfo{ + libraryType: "java_library", + fromPartition: "product", + toPartition: "system", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: false, + })) - return result - } + testJavaWithConfig(t, createTestConfig(testConfigInfo{ + libraryType: "java_library", + fromPartition: "product", + toPartition: "system", + enforceVendorInterface: true, + enforceProductInterface: false, + enforceJavaSdkLibraryCheck: true, + })) - for _, libraryType := range []string{"java_library", "java_sdk_library"} { - for _, partitionValues := range allPartitionCombinations() { - for _, flagValues := range allFlagCombinations() { - testInfo := testConfigInfo{ - libraryType: libraryType, - fromPartition: partitionValues[0], - toPartition: partitionValues[1], - enforceVendorInterface: flagValues[0], - enforceProductInterface: flagValues[1], - enforceJavaSdkLibraryCheck: flagValues[2], - } + testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ + libraryType: "java_library", + fromPartition: "product", + toPartition: "system", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: true, + })) - if isValidDependency(testInfo) { - testJavaWithConfig(t, createTestConfig(testInfo)) - } else { - testJavaErrorWithConfig(t, errorMessage, createTestConfig(testInfo)) - } - } - } - } + testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ + libraryType: "java_library", + fromPartition: "vendor", + toPartition: "system", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: true, + })) testJavaWithConfig(t, createTestConfig(testConfigInfo{ libraryType: "java_library", @@ -958,11 +918,37 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ libraryType: "java_library", fromPartition: "vendor", + toPartition: "product", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: true, + })) + + testJavaWithConfig(t, createTestConfig(testConfigInfo{ + libraryType: "java_sdk_library", + fromPartition: "product", + toPartition: "system", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: true, + })) + + testJavaWithConfig(t, createTestConfig(testConfigInfo{ + libraryType: "java_sdk_library", + fromPartition: "vendor", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - allowList: []string{"foo"}, + })) + + testJavaWithConfig(t, createTestConfig(testConfigInfo{ + libraryType: "java_sdk_library", + fromPartition: "vendor", + toPartition: "product", + enforceVendorInterface: true, + enforceProductInterface: true, + enforceJavaSdkLibraryCheck: true, })) } |