diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 226 |
1 files changed, 118 insertions, 108 deletions
diff --git a/java/java.go b/java/java.go index b320732cd..46344c842 100644 --- a/java/java.go +++ b/java/java.go @@ -315,14 +315,14 @@ type JavaInfo struct { AconfigIntermediateCacheOutputPaths android.Paths } -var JavaInfoProvider = blueprint.NewProvider[JavaInfo]() +var JavaInfoProvider = blueprint.NewProvider[*JavaInfo]() // SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to // the sysprop implementation library. type SyspropPublicStubInfo struct { // JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to // the sysprop implementation library. - JavaInfo JavaInfo + JavaInfo *JavaInfo } var SyspropPublicStubInfoProvider = blueprint.NewProvider[SyspropPublicStubInfo]() @@ -421,8 +421,6 @@ var ( bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true} systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true} frameworkResTag = dependencyTag{name: "framework-res"} - kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true} - kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true} kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true} proguardRaiseTag = dependencyTag{name: "proguard-raise"} certificateTag = dependencyTag{name: "certificate"} @@ -432,7 +430,6 @@ var ( r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true} syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} javaApiContributionTag = dependencyTag{name: "java-api-contribution"} - depApiSrcsTag = dependencyTag{name: "dep-api-srcs"} aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"} jniInstallTag = dependencyTag{name: "jni install", runtimeLinked: true, installable: true} binaryInstallTag = dependencyTag{name: "binary install", runtimeLinked: true, installable: true} @@ -459,8 +456,6 @@ var ( bootClasspathTag, systemModulesTag, java9LibTag, - kotlinStdlibTag, - kotlinAnnotationsTag, kotlinPluginTag, syspropPublicStubDepTag, instrumentationForTag, @@ -569,8 +564,6 @@ type deps struct { srcJars android.Paths systemModules *systemModules aidlPreprocess android.OptionalPath - kotlinStdlib android.Paths - kotlinAnnotations android.Paths kotlinPlugins android.Paths aconfigProtoFiles android.Paths @@ -1871,10 +1864,12 @@ func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { if ctx.Arch().ArchType == android.Common { j.deps(ctx) } - if ctx.Arch().ArchType != android.Common { - // These dependencies ensure the host installation rules will install the jar file and - // the jni libraries when the wrapper is installed. + // These dependencies ensure the installation rules will install the jar file when the + // wrapper is installed, and the jni libraries on host when the wrapper is installed. + if ctx.Arch().ArchType != android.Common && ctx.Os().Class == android.Host { ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...) + } + if ctx.Arch().ArchType != android.Common { ctx.AddVariationDependencies( []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}}, binaryInstallTag, ctx.ModuleName()) @@ -2005,12 +2000,6 @@ type JavaApiLibraryProperties struct { // merge zipped after metalava invocation Static_libs []string - // Java Api library to provide the full API surface stub jar file. - // If this property is set, the stub jar of this module is created by - // extracting the compiled class files provided by the - // full_api_surface_stub module. - Full_api_surface_stub *string - // Version of previously released API file for compatibility check. Previous_api *string `android:"path"` @@ -2043,6 +2032,15 @@ type JavaApiLibraryProperties struct { // 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"` + + // If not blank, set to the version of the sdk to compile against. + // Defaults to an empty string, which compiles the module against the private platform APIs. + // Values are of one of the following forms: + // 1) numerical API level, "current", "none", or "core_platform" + // 2) An SDK kind with an API level: "<sdk kind>_<API level>" + // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds. + // If the SDK kind is empty, it will be set to public. + Sdk_version *string } func ApiLibraryFactory() android.Module { @@ -2141,40 +2139,6 @@ func (al *ApiLibrary) addValidation(ctx android.ModuleContext, cmd *android.Rule } } -// This method extracts the stub class files from the stub jar file provided -// from full_api_surface_stub module instead of compiling the srcjar generated from invoking metalava. -// This method is used because metalava can generate compilable from-text stubs only when -// the codebase encompasses all classes listed in the input API text file, and a class can extend -// a class that is not within the same API domain. -func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.RuleBuilder, stubsDir android.OptionalPath, fullApiSurfaceStubJar android.Path) { - classFilesList := android.PathForModuleOut(ctx, "metalava", "classes.txt") - unzippedSrcJarDir := android.PathForModuleOut(ctx, "metalava", "unzipDir") - - rule.Command(). - BuiltTool("list_files"). - Text(stubsDir.String()). - FlagWithOutput("--out ", classFilesList). - FlagWithArg("--extensions ", ".java"). - FlagWithArg("--root ", unzippedSrcJarDir.String()). - Flag("--classes") - - rule.Command(). - Text("unzip"). - Flag("-q"). - Input(fullApiSurfaceStubJar). - FlagWithArg("-d ", unzippedSrcJarDir.String()) - - rule.Command(). - BuiltTool("soong_zip"). - Flag("-jar"). - Flag("-write_if_changed"). - Flag("-ignore_missing_files"). - Flag("-quiet"). - FlagWithArg("-C ", unzippedSrcJarDir.String()). - FlagWithInput("-l ", classFilesList). - FlagWithOutput("-o ", al.stubsJarWithoutStaticLibs) -} - func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { apiContributions := al.properties.Api_contributions addValidations := !ctx.Config().IsEnvTrue("DISABLE_STUB_VALIDATION") && @@ -2201,14 +2165,18 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { } } } + if ctx.Device() { + sdkDep := decodeSdkDep(ctx, android.SdkContext(al)) + if sdkDep.useModule { + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) + ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...) + ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) + + } + } ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...) - if al.properties.Full_api_surface_stub != nil { - ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Full_api_surface_stub)) - } - if al.properties.System_modules != nil { - ctx.AddVariationDependencies(nil, systemModulesTag, String(al.properties.System_modules)) - } + for _, aconfigDeclarationsName := range al.properties.Aconfig_declarations { ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfigDeclarationsName) } @@ -2264,8 +2232,8 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { var srcFilesInfo []JavaApiImportInfo var classPaths android.Paths + var bootclassPaths android.Paths var staticLibs android.Paths - var depApiSrcsStubsJar android.Path var systemModulesPaths android.Paths ctx.VisitDirectDeps(func(dep android.Module) { tag := ctx.OtherModuleDependencyTag(dep) @@ -2277,17 +2245,21 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { } srcFilesInfo = append(srcFilesInfo, provider) case libTag: - provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider) - classPaths = append(classPaths, provider.HeaderJars...) + if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { + classPaths = append(classPaths, provider.HeaderJars...) + } + case bootClasspathTag: + if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { + bootclassPaths = append(bootclassPaths, provider.HeaderJars...) + } case staticLibTag: - provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider) - staticLibs = append(staticLibs, provider.HeaderJars...) - case depApiSrcsTag: - provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider) - depApiSrcsStubsJar = provider.HeaderJars[0] + if provider, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { + staticLibs = append(staticLibs, provider.HeaderJars...) + } case systemModulesTag: - module := dep.(SystemModulesProvider) - systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...) + if sm, ok := android.OtherModuleProvider(ctx, dep, SystemModulesProvider); ok { + systemModulesPaths = append(systemModulesPaths, sm.HeaderJars...) + } case metalavaCurrentApiTimestampTag: if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok { al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp()) @@ -2319,7 +2291,10 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { configFiles := android.PathsForModuleSrc(ctx, al.properties.ConfigFiles) - cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths, configFiles) + combinedPaths := append(([]android.Path)(nil), systemModulesPaths...) + combinedPaths = append(combinedPaths, classPaths...) + combinedPaths = append(combinedPaths, bootclassPaths...) + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, combinedPaths, configFiles) al.stubsFlags(ctx, cmd, stubsDir) @@ -2337,9 +2312,6 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar") al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName())) - if depApiSrcsStubsJar != nil { - al.extractApiSrcs(ctx, rule, stubsDir, depApiSrcsStubsJar) - } rule.Command(). BuiltTool("soong_zip"). Flag("-write_if_changed"). @@ -2350,18 +2322,17 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { rule.Build("metalava", "metalava merged text") - if depApiSrcsStubsJar == nil { - var flags javaBuilderFlags - flags.javaVersion = getStubsJavaVersion() - flags.javacFlags = strings.Join(al.properties.Javacflags, " ") - flags.classpath = classpath(classPaths) - flags.bootClasspath = classpath(systemModulesPaths) + javacFlags := javaBuilderFlags{ + javaVersion: getStubsJavaVersion(), + javacFlags: strings.Join(al.properties.Javacflags, " "), + classpath: classpath(classPaths), + bootClasspath: classpath(append(systemModulesPaths, bootclassPaths...)), + } - annoSrcJar := android.PathForModuleOut(ctx, ctx.ModuleName(), "anno.srcjar") + annoSrcJar := android.PathForModuleOut(ctx, ctx.ModuleName(), "anno.srcjar") - TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 0, android.Paths{}, - android.Paths{al.stubsSrcJar}, annoSrcJar, flags, android.Paths{}) - } + TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 0, android.Paths{}, + android.Paths{al.stubsSrcJar}, annoSrcJar, javacFlags, android.Paths{}) builder := android.NewRuleBuilder(pctx, ctx) builder.Command(). @@ -2373,7 +2344,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { // compile stubs to .dex for hiddenapi processing dexParams := &compileDexParams{ - flags: javaBuilderFlags{}, + flags: javacFlags, sdkVersion: al.SdkVersion(ctx), minSdkVersion: al.MinSdkVersion(ctx), classesJar: al.stubsJar, @@ -2387,7 +2358,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.Phony(ctx.ModuleName(), al.stubsJar) - android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ + android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{ HeaderJars: android.PathsIfNonNil(al.stubsJar), ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar), ImplementationJars: android.PathsIfNonNil(al.stubsJar), @@ -2409,14 +2380,28 @@ func (al *ApiLibrary) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { return nil } -// java_api_library constitutes the sdk, and does not build against one +// Most java_api_library constitues the sdk, but there are some java_api_library that +// does not contribute to the api surface. Such modules are allowed to set sdk_version +// other than "none" func (al *ApiLibrary) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return android.SdkSpecNone + return android.SdkSpecFrom(ctx, proptools.String(al.properties.Sdk_version)) } // java_api_library is always at "current". Return FutureApiLevel func (al *ApiLibrary) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { - return android.FutureApiLevel + return al.SdkVersion(ctx).ApiLevel +} + +func (al *ApiLibrary) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { + return al.SdkVersion(ctx).ApiLevel +} + +func (al *ApiLibrary) SystemModules() string { + return proptools.String(al.properties.System_modules) +} + +func (al *ApiLibrary) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return al.SdkVersion(ctx).ApiLevel } func (al *ApiLibrary) IDEInfo(i *android.IdeInfo) { @@ -2434,9 +2419,6 @@ func (al *ApiLibrary) ideDeps() []string { 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 } @@ -2444,6 +2426,7 @@ func (al *ApiLibrary) ideDeps() []string { // implement the following interfaces for hiddenapi processing var _ hiddenAPIModule = (*ApiLibrary)(nil) var _ UsesLibraryDependency = (*ApiLibrary)(nil) +var _ android.SdkContext = (*ApiLibrary)(nil) // implement the following interface for IDE completion. var _ android.IDEInfo = (*ApiLibrary)(nil) @@ -2653,6 +2636,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.collectTransitiveHeaderJars(ctx) var staticJars android.Paths + var staticResourceJars android.Paths var staticHeaderJars android.Paths ctx.VisitDirectDeps(func(module android.Module) { tag := ctx.OtherModuleDependencyTag(module) @@ -2663,7 +2647,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...) case staticLibTag: flags.classpath = append(flags.classpath, dep.HeaderJars...) - staticJars = append(staticJars, dep.ImplementationAndResourcesJars...) + staticJars = append(staticJars, dep.ImplementationJars...) + staticResourceJars = append(staticResourceJars, dep.ResourceJars...) staticHeaderJars = append(staticHeaderJars, dep.HeaderJars...) case bootClasspathTag: flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...) @@ -2683,43 +2668,67 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Always pass the input jars to TransformJarsToJar, even if there is only a single jar, we need the output // file of the module to be named jarName. - outputFile := android.PathForModuleOut(ctx, "combined", jarName) + var outputFile android.Path + combinedImplementationJar := android.PathForModuleOut(ctx, "combined", jarName) implementationJars := append(slices.Clone(jars), staticJars...) - TransformJarsToJar(ctx, outputFile, "combine prebuilt implementation jars", implementationJars, android.OptionalPath{}, + TransformJarsToJar(ctx, combinedImplementationJar, "combine prebuilt implementation jars", implementationJars, android.OptionalPath{}, false, j.properties.Exclude_files, j.properties.Exclude_dirs) + outputFile = combinedImplementationJar // If no dependencies have separate header jars then there is no need to create a separate // header jar for this module. reuseImplementationJarAsHeaderJar := slices.Equal(staticJars, staticHeaderJars) - var headerOutputFile android.ModuleOutPath + var resourceJarFile android.Path + if len(staticResourceJars) > 1 { + combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) + TransformJarsToJar(ctx, combinedJar, "for resources", staticResourceJars, android.OptionalPath{}, + false, nil, nil) + resourceJarFile = combinedJar + } else if len(staticResourceJars) == 1 { + resourceJarFile = staticResourceJars[0] + } + + var headerJar android.Path if reuseImplementationJarAsHeaderJar { - headerOutputFile = outputFile + headerJar = outputFile } else { headerJars := append(slices.Clone(jars), staticHeaderJars...) - headerOutputFile = android.PathForModuleOut(ctx, "turbine-combined", jarName) + headerOutputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) TransformJarsToJar(ctx, headerOutputFile, "combine prebuilt header jars", headerJars, android.OptionalPath{}, false, j.properties.Exclude_files, j.properties.Exclude_dirs) + headerJar = headerOutputFile } if Bool(j.properties.Jetifier) { - inputFile := outputFile - outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) - TransformJetifier(ctx, outputFile, inputFile) + jetifierOutputFile := android.PathForModuleOut(ctx, "jetifier", jarName) + TransformJetifier(ctx, jetifierOutputFile, outputFile) + outputFile = jetifierOutputFile if !reuseImplementationJarAsHeaderJar { - headerInputFile := headerOutputFile - headerOutputFile = android.PathForModuleOut(ctx, "jetifier-headers", jarName) - TransformJetifier(ctx, headerOutputFile, headerInputFile) + jetifierHeaderJar := android.PathForModuleOut(ctx, "jetifier-headers", jarName) + TransformJetifier(ctx, jetifierHeaderJar, headerJar) + headerJar = jetifierHeaderJar } else { - headerOutputFile = outputFile + headerJar = outputFile } } + implementationJarFile := outputFile + + // merge implementation jar with resources if necessary + if resourceJarFile != nil { + jars := android.Paths{resourceJarFile, outputFile} + combinedJar := android.PathForModuleOut(ctx, "withres", jarName) + TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, + false, nil, nil) + outputFile = combinedJar + } + // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource. // Also strip the relative path from the header output file so that the reuseImplementationJarAsHeaderJar check // in a module that depends on this module considers them equal. - j.combinedHeaderFile = headerOutputFile.WithoutRel() + j.combinedHeaderFile = headerJar.WithoutRel() j.combinedImplementationFile = outputFile.WithoutRel() j.maybeInstall(ctx, jarName, outputFile) @@ -2779,7 +2788,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex - var dexOutputFile android.OutputPath + var dexOutputFile android.Path dexParams := &compileDexParams{ flags: flags, sdkVersion: j.SdkVersion(ctx), @@ -2804,12 +2813,13 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } - android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ + android.SetProvider(ctx, JavaInfoProvider, &JavaInfo{ HeaderJars: android.PathsIfNonNil(j.combinedHeaderFile), TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedImplementationFile), - ImplementationJars: android.PathsIfNonNil(j.combinedImplementationFile), + ImplementationJars: android.PathsIfNonNil(implementationJarFile.WithoutRel()), + ResourceJars: android.PathsIfNonNil(resourceJarFile), AidlIncludeDirs: j.exportAidlIncludeDirs, StubsLinkType: j.stubsLinkType, // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts @@ -2924,7 +2934,7 @@ var _ android.IDECustomizedModuleName = (*Import)(nil) // Collect information for opening IDE project files in java/jdeps.go. func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { - dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) + dpInfo.Jars = append(dpInfo.Jars, j.combinedHeaderFile.String()) } func (j *Import) IDECustomizedModuleName() string { |