diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 122 |
1 files changed, 93 insertions, 29 deletions
diff --git a/java/java.go b/java/java.go index c568ec43d..a973bab39 100644 --- a/java/java.go +++ b/java/java.go @@ -324,6 +324,10 @@ type CompilerDeviceProperties struct { Stem *string IsSDKLibrary bool `blueprint:"mutated"` + + // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file. + // Defaults to false. + V4_signature *bool } // Functionality common to Module and Import @@ -447,6 +451,8 @@ type Module struct { // Collect the module directory for IDE info in java/jdeps.go. modulePaths []string + + hideApexVariantFromMake bool } func (j *Module) addHostProperties() { @@ -541,13 +547,8 @@ type dependencyTag struct { name string } -type jniDependencyTag struct { - blueprint.BaseDependencyTag -} - func IsJniDepTag(depTag blueprint.DependencyTag) bool { - _, ok := depTag.(*jniDependencyTag) - return ok + return depTag == jniLibTag } var ( @@ -566,8 +567,8 @@ var ( certificateTag = dependencyTag{name: "certificate"} instrumentationForTag = dependencyTag{name: "instrumentation_for"} usesLibTag = dependencyTag{name: "uses-library"} - usesLibCompatTag = dependencyTag{name: "uses-library-compat"} extraLintCheckTag = dependencyTag{name: "extra-lint-check"} + jniLibTag = dependencyTag{name: "jnilib"} ) func IsLibDepTag(depTag blueprint.DependencyTag) bool { @@ -635,8 +636,9 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool { // Force enable the instrumentation for java code that is built for APEXes ... // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true. + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) isJacocoAgent := ctx.ModuleName() == "jacocoagent" - if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() { + if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() { if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { return true } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { @@ -732,9 +734,21 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { return ret } - ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...) + libDeps := ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...) ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...) + // 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 { + if dep != nil { + if component, ok := dep.(SdkLibraryComponentDependency); ok { + if lib := component.OptionalSdkLibraryImplementation(); lib != nil { + ctx.AddVariationDependencies(nil, usesLibTag, *lib) + } + } + } + } + ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) @@ -983,7 +997,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) - if _, ok := tag.(*jniDependencyTag); ok { + if IsJniDepTag(tag) { // Handled by AndroidApp.collectAppDeps return } @@ -1490,7 +1504,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { args := map[string]string{ "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "), } - if ctx.Config().IsEnvTrue("RBE_ZIP") { + if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") { rule = zipRE args["implicits"] = strings.Join(services.Strings(), ",") } @@ -1587,7 +1601,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.implementationAndResourcesJar = implementationAndResourcesJar // Enable dex compilation for the APEX variants, unless it is disabled explicitly - if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() { + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) + if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() { if j.dexProperties.Compile_dex == nil { j.dexProperties.Compile_dex = proptools.BoolPtr(true) } @@ -1611,6 +1626,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { configurationName := j.ConfigurationName() primary := configurationName == ctx.ModuleName() + // If the prebuilt is being used rather than the from source, skip this + // module to prevent duplicated classes + primary = primary && !j.IsReplacedByPrebuilt() // Hidden API CSV generation and dex encoding dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile, @@ -1652,7 +1670,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { if v := sdkSpec.version; v.isNumbered() { return v.String() } else { - return ctx.Config().DefaultAppTargetSdk() + return ctx.Config().DefaultAppTargetSdk(ctx).String() } } @@ -1666,7 +1684,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion()) j.linter.javaLanguageLevel = flags.javaVersion.String() j.linter.kotlinLanguageLevel = "1.3" - if j.ApexVariationName() != "" && ctx.Config().UnbundledBuildApps() { + if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() { j.linter.buildModuleReportZip = true } j.linter.lint(ctx) @@ -1870,7 +1888,8 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu return j.depIsInSameApex(ctx, dep) } -func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { sdkSpec := j.minSdkVersion() if !sdkSpec.specified() { return fmt.Errorf("min_sdk_version is not specified") @@ -1882,7 +1901,7 @@ func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersi if err != nil { return err } - if int(ver) > sdkVersion { + if ver.ApiLevel(ctx).GreaterThan(sdkVersion) { return fmt.Errorf("newer SDK(%v)", ver) } return nil @@ -1927,7 +1946,7 @@ func (j *Library) PermittedPackagesForUpdatableBootJars() []string { func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { // Store uncompressed (and aligned) any dex files from jars in APEXes. - if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() { + if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() { return true } @@ -1949,6 +1968,11 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) + if !apexInfo.IsForPlatform() { + j.hideApexVariantFromMake = true + } + j.checkSdkVersions(ctx) j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary @@ -1963,7 +1987,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Collect the module directory for IDE info in java/jdeps.go. j.modulePaths = append(j.modulePaths, ctx.ModuleDir()) - exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform() + exclusivelyForApex := !apexInfo.IsForPlatform() if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { var extraInstallDeps android.Paths if j.InstallMixin != nil { @@ -1979,9 +2003,9 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { // added to the Android manifest. j.exportedSdkLibs.MaybeAddLibraryPath(ctx, j.OptionalImplicitSdkLibrary(), j.DexJarBuildPath(), j.DexJarInstallPath()) - // If this is a non-SDK uses-library, export itself. - if proptools.Bool(j.usesLibraryProperties.Is_uses_lib) { - j.exportedSdkLibs.AddLibraryPath(ctx, ctx.ModuleName(), 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.distFiles = j.GenerateTaggedDistFiles(ctx) @@ -2408,6 +2432,10 @@ type binaryProperties struct { // Name of the class containing main to be inserted into the manifest as Main-Class. Main_class *string + + // Names of modules containing JNI libraries that should be installed alongside the host + // variant of the binary. + Jni_libs []string } type Binary struct { @@ -2448,18 +2476,21 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") } - // Depend on the installed jar so that the wrapper doesn't get executed by - // another build rule before the jar has been installed. - jarFile := ctx.PrimaryModule().(*Binary).installFile - + // The host installation rules make the installed wrapper depend on all the dependencies + // of the wrapper variant, which will include the common variant's jar file and any JNI + // libraries. This is verified by TestBinary. j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), - ctx.ModuleName(), j.wrapperFile, jarFile) + ctx.ModuleName(), j.wrapperFile) } } func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { if ctx.Arch().ArchType == android.Common { j.deps(ctx) + } else { + // This dependency ensures the host installation rules will install the jni libraries + // when the wrapper is installed. + ctx.AddVariationDependencies(nil, jniLibTag, j.binaryProperties.Jni_libs...) } } @@ -2555,6 +2586,8 @@ type Import struct { combinedClasspathFile android.Path exportedSdkLibs dexpreopt.LibraryPaths exportAidlIncludeDirs android.Paths + + hideApexVariantFromMake bool } func (j *Import) sdkVersion() sdkSpec { @@ -2610,6 +2643,10 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { + if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { + j.hideApexVariantFromMake = true + } + jars := android.PathsForModuleSrc(ctx, j.properties.Jars) jarName := j.Stem() + ".jar" @@ -2681,10 +2718,28 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { return } + configurationName := j.BaseModuleName() + primary := j.Prebuilt().UsePrebuilt() + + // 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 } } +func (j *Import) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case "", ".jar": + return android.Paths{j.combinedClasspathFile}, nil + default: + return nil, fmt.Errorf("unsupported module reference tag %q", tag) + } +} + +var _ android.OutputFileProducer = (*Import)(nil) + var _ Dependency = (*Import)(nil) func (j *Import) HeaderJars() android.Paths { @@ -2740,7 +2795,8 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu return j.depIsInSameApex(ctx, dep) } -func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // Do not check for prebuilts against the min_sdk_version of enclosing APEX return nil } @@ -2834,6 +2890,8 @@ type DexImport struct { maybeStrippedDexJarFile android.Path dexpreopter + + hideApexVariantFromMake bool } func (j *DexImport) Prebuilt() *android.Prebuilt { @@ -2869,6 +2927,11 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.PropertyErrorf("jars", "exactly one jar must be provided") } + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) + if !apexInfo.IsForPlatform() { + j.hideApexVariantFromMake = true + } + j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) @@ -2913,7 +2976,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.maybeStrippedDexJarFile = dexOutputFile - if j.IsForPlatform() { + if apexInfo.IsForPlatform() { ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), j.Stem()+".jar", dexOutputFile) } @@ -2923,7 +2986,8 @@ func (j *DexImport) DexJarBuildPath() android.Path { return j.dexJarFile } -func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error { +func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, + sdkVersion android.ApiLevel) error { // we don't check prebuilt modules for sdk_version return nil } |