diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 186 |
1 files changed, 142 insertions, 44 deletions
diff --git a/java/java.go b/java/java.go index 725e25abe..b320732cd 100644 --- a/java/java.go +++ b/java/java.go @@ -75,7 +75,6 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() }) - ctx.RegisterParallelSingletonType("logtags", LogtagsSingleton) ctx.RegisterParallelSingletonType("kythe_java_extract", kytheExtractJavaFactory) } @@ -270,7 +269,7 @@ type JavaInfo struct { ImplementationAndResourcesJars android.Paths // ImplementationJars is a list of jars that contain the implementations of classes in the - //module. + // module. ImplementationJars android.Paths // ResourceJars is a list of jars that contain the resources included in the module. @@ -367,14 +366,14 @@ type dependencyTag struct { toolchain bool static bool + + installable bool } -// installDependencyTag is a dependency tag that is annotated to cause the installed files of the -// dependency to be installed when the parent module is installed. -type installDependencyTag struct { - blueprint.BaseDependencyTag - android.InstallAlwaysNeededDependencyTag - name string +var _ android.InstallNeededDependencyTag = (*dependencyTag)(nil) + +func (d dependencyTag) InstallDepNeeded() bool { + return d.installable } func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { @@ -406,7 +405,7 @@ func makeUsesLibraryDependencyTag(sdkVersion int, optional bool) usesLibraryDepe } func IsJniDepTag(depTag blueprint.DependencyTag) bool { - return depTag == jniLibTag + return depTag == jniLibTag || depTag == jniInstallTag } var ( @@ -435,8 +434,8 @@ var ( javaApiContributionTag = dependencyTag{name: "java-api-contribution"} depApiSrcsTag = dependencyTag{name: "dep-api-srcs"} aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"} - jniInstallTag = installDependencyTag{name: "jni install"} - binaryInstallTag = installDependencyTag{name: "binary install"} + jniInstallTag = dependencyTag{name: "jni install", runtimeLinked: true, installable: true} + binaryInstallTag = dependencyTag{name: "binary install", runtimeLinked: true, installable: true} usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false) usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true) usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true) @@ -444,6 +443,30 @@ var ( usesLibCompat30OptTag = makeUsesLibraryDependencyTag(30, true) ) +// A list of tags for deps used for compiling a module. +// Any dependency tags that modifies the following properties of `deps` in `Module.collectDeps` should be +// added to this list: +// - bootClasspath +// - classpath +// - java9Classpath +// - systemModules +// - kotlin deps... +var ( + compileDependencyTags = []blueprint.DependencyTag{ + sdkLibTag, + libTag, + staticLibTag, + bootClasspathTag, + systemModulesTag, + java9LibTag, + kotlinStdlibTag, + kotlinAnnotationsTag, + kotlinPluginTag, + syspropPublicStubDepTag, + instrumentationForTag, + } +) + func IsLibDepTag(depTag blueprint.DependencyTag) bool { return depTag == libTag || depTag == sdkLibTag } @@ -492,6 +515,7 @@ type jniLib struct { coverageFile android.OptionalPath unstrippedFile android.Path partition string + installPaths android.InstallPaths } func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) { @@ -567,6 +591,12 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an return normalizeJavaVersion(ctx, javaVersion) } else if ctx.Device() { return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) + } else if ctx.Config().TargetsJava21() { + // Temporary experimental flag to be able to try and build with + // java version 21 options. The flag, if used, just sets Java + // 21 as the default version, leaving any components that + // target an older version intact. + return JAVA_VERSION_21 } else { return JAVA_VERSION_17 } @@ -675,6 +705,10 @@ type Library struct { var _ android.ApexModule = (*Library)(nil) +func (j *Library) CheckDepsMinSdkVersion(ctx android.ModuleContext) { + CheckMinSdkVersion(ctx, j) +} + // Provides access to the list of permitted packages from apex boot jars. type PermittedPackagesForUpdatableBootJars interface { PermittedPackagesForUpdatableBootJars() []string @@ -903,6 +937,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.minSdkVersion = j.MinSdkVersion(ctx) j.maxSdkVersion = j.MaxSdkVersion(ctx) + // Check min_sdk_version of the transitive dependencies if this module is created from + // java_sdk_library. + if j.overridableProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil { + j.CheckDepsMinSdkVersion(ctx) + } + // SdkLibrary.GenerateAndroidBuildActions(ctx) sets the stubsLinkType to Unknown. // If the stubsLinkType has already been set to Unknown, the stubsLinkType should // not be overridden. @@ -933,8 +973,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkSdkVersions(ctx) j.checkHeadersOnly(ctx) if ctx.Device() { + libName := j.Name() + if j.SdkLibraryName() != nil && strings.HasSuffix(libName, ".impl") { + libName = proptools.String(j.SdkLibraryName()) + } j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, j.Name(), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + ctx, libName, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -945,8 +989,26 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.compile(ctx, nil, nil, nil) - exclusivelyForApex := !apexInfo.IsForPlatform() - if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { + // If this module is an impl library created from java_sdk_library, + // install the files under the java_sdk_library module outdir instead of this module outdir. + if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { + j.setInstallRules(ctx, proptools.String(j.SdkLibraryName())) + } else { + j.setInstallRules(ctx, ctx.ModuleName()) + } + + android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ + TestOnly: Bool(j.sourceProperties.Test_only), + TopLevelTarget: j.sourceProperties.Top_level_test_target, + }) + + setOutputFiles(ctx, j.Module) +} + +func (j *Library) setInstallRules(ctx android.ModuleContext, installModuleName string) { + apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) + + if (Bool(j.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() { var extraInstallDeps android.InstallPaths if j.InstallMixin != nil { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) @@ -963,22 +1025,27 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { if !ctx.Host() { archDir = ctx.DeviceConfig().DeviceArch() } - installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + installDir = android.PathForModuleInstall(ctx, installModuleName, archDir) } else { installDir = android.PathForModuleInstall(ctx, "framework") } j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) } - - android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ - TestOnly: Bool(j.sourceProperties.Test_only), - TopLevelTarget: j.sourceProperties.Top_level_test_target, - }) } func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { j.usesLibrary.deps(ctx, false) j.deps(ctx) + + if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { + if dexpreopt.IsDex2oatNeeded(ctx) { + dexpreopt.RegisterToolDeps(ctx) + } + prebuiltSdkLibExists := ctx.OtherModuleExists(android.PrebuiltNameFromSource(proptools.String(j.SdkLibraryName()))) + if prebuiltSdkLibExists && ctx.OtherModuleExists("all_apex_contributions") { + ctx.AddDependency(ctx.Module(), android.AcDepTag, "all_apex_contributions") + } + } } const ( @@ -1062,7 +1129,7 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo // If the min_sdk_version was set then add the canonical representation of the API level to the // snapshot. - if j.deviceProperties.Min_sdk_version != nil { + if j.overridableProperties.Min_sdk_version != nil { canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String()) if err != nil { ctx.ModuleErrorf("%s", err) @@ -1315,7 +1382,7 @@ func (j *JavaTestImport) InstallInTestcases() bool { return true } -func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { +func (j *TestHost) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { return ctx.DeviceConfig().NativeCoverageEnabled() } @@ -1460,13 +1527,16 @@ func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { InstalledFiles: j.data, OutputFile: j.outputFile, TestConfig: j.testConfig, - RequiredModuleNames: j.RequiredModuleNames(), + RequiredModuleNames: j.RequiredModuleNames(ctx), TestSuites: j.testProperties.Test_suites, IsHost: true, + LocalSdkVersion: j.sdkVersion.String(), + IsUnitTest: Bool(j.testProperties.Test_options.Unit_test), }) } func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { + checkMinSdkVersionMts(ctx, j.MinSdkVersion(ctx)) j.generateAndroidBuildActionsWithConfig(ctx, nil) android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{}) } @@ -1792,6 +1862,8 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { // libraries. This is verified by TestBinary. j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), ctx.ModuleName()+ext, j.wrapperFile) + + setOutputFiles(ctx, j.Library.Module) } } @@ -1967,12 +2039,17 @@ type JavaApiLibraryProperties struct { // List of aconfig_declarations module names that the stubs generated in this module // depend on. Aconfig_declarations []string + + // List of hard coded filegroups containing Metalava config files that are passed to every + // Metalava invocation that this module performs. See addMetalavaConfigFilesToCmd. + ConfigFiles []string `android:"path" blueprint:"mutated"` } func ApiLibraryFactory() android.Module { module := &ApiLibrary{} - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) module.AddProperties(&module.properties) + module.properties.ConfigFiles = getMetalavaConfigFilegroupReference() + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) module.initModuleAndImport(module) android.InitDefaultableModule(module) return module @@ -1988,7 +2065,7 @@ func (al *ApiLibrary) StubsJar() android.Path { func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, homeDir android.WritablePath, - classpath android.Paths) *android.RuleBuilderCommand { + classpath android.Paths, configFiles android.Paths) *android.RuleBuilderCommand { rule.Command().Text("rm -rf").Flag(homeDir.String()) rule.Command().Text("mkdir -p").Flag(homeDir.String()) @@ -2027,6 +2104,8 @@ func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, FlagWithArg("--hide ", "InvalidNullabilityOverride"). FlagWithArg("--hide ", "ChangedDefault") + addMetalavaConfigFilesToCmd(cmd, configFiles) + if len(classpath) == 0 { // The main purpose of the `--api-class-resolution api` option is to force metalava to ignore // classes on the classpath when an API file contains missing classes. However, as this command @@ -2137,7 +2216,7 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { // Map where key is the api scope name and value is the int value // representing the order of the api scope, narrowest to the widest -var scopeOrderMap = allApiScopes.MapToIndex( +var scopeOrderMap = AllApiScopes.MapToIndex( func(s *apiScope) string { return s.name }) func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) []JavaApiImportInfo { @@ -2238,14 +2317,16 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName()) } - cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths) + configFiles := android.PathsForModuleSrc(ctx, al.properties.ConfigFiles) + + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths, configFiles) al.stubsFlags(ctx, cmd, stubsDir) - migratingNullability := String(al.properties.Previous_api) != "" - if migratingNullability { - previousApi := android.PathForModuleSrc(ctx, String(al.properties.Previous_api)) - cmd.FlagWithInput("--migrate-nullness ", previousApi) + previousApi := String(al.properties.Previous_api) + if previousApi != "" { + previousApiFiles := android.PathsForModuleSrc(ctx, []string{previousApi}) + cmd.FlagForEachInput("--migrate-nullness ", previousApiFiles) } al.addValidation(ctx, cmd, al.validationPaths) @@ -2298,7 +2379,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { classesJar: al.stubsJar, jarName: ctx.ModuleName() + ".jar", } - dexOutputFile := al.dexer.compileDex(ctx, dexParams) + dexOutputFile, _ := al.dexer.compileDex(ctx, dexParams) uncompressed := true al.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), al.stubsJar, &uncompressed) dexOutputFile = al.hiddenAPIEncodeDex(ctx, dexOutputFile) @@ -2338,10 +2419,35 @@ func (al *ApiLibrary) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiL return android.FutureApiLevel } +func (al *ApiLibrary) IDEInfo(i *android.IdeInfo) { + i.Deps = append(i.Deps, al.ideDeps()...) + i.Libs = append(i.Libs, al.properties.Libs...) + i.Static_libs = append(i.Static_libs, al.properties.Static_libs...) + i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String()) +} + +// deps of java_api_library for module_bp_java_deps.json +func (al *ApiLibrary) ideDeps() []string { + ret := []string{} + ret = append(ret, al.properties.Libs...) + ret = append(ret, al.properties.Static_libs...) + if al.properties.System_modules != nil { + ret = append(ret, proptools.String(al.properties.System_modules)) + } + if al.properties.Full_api_surface_stub != nil { + ret = append(ret, proptools.String(al.properties.Full_api_surface_stub)) + } + // Other non java_library dependencies like java_api_contribution are ignored for now. + return ret +} + // implement the following interfaces for hiddenapi processing var _ hiddenAPIModule = (*ApiLibrary)(nil) var _ UsesLibraryDependency = (*ApiLibrary)(nil) +// implement the following interface for IDE completion. +var _ android.IDEInfo = (*ApiLibrary)(nil) + // // Java prebuilts // @@ -2682,7 +2788,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { jarName: jarName, } - dexOutputFile = j.dexer.compileDex(ctx, dexParams) + dexOutputFile, _ = j.dexer.compileDex(ctx, dexParams) if ctx.Failed() { return } @@ -2708,6 +2814,9 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { StubsLinkType: j.stubsLinkType, // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts }) + + ctx.SetOutputFiles(android.Paths{j.combinedImplementationFile}, "") + ctx.SetOutputFiles(android.Paths{j.combinedImplementationFile}, ".jar") } func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) { @@ -2728,17 +2837,6 @@ func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputF ctx.InstallFile(installDir, jarName, outputFile) } -func (j *Import) OutputFiles(tag string) (android.Paths, error) { - switch tag { - case "", ".jar": - return android.Paths{j.combinedImplementationFile}, nil - default: - return nil, fmt.Errorf("unsupported module reference tag %q", tag) - } -} - -var _ android.OutputFileProducer = (*Import)(nil) - func (j *Import) HeaderJars() android.Paths { return android.PathsIfNonNil(j.combinedHeaderFile) } |