summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go185
1 files changed, 113 insertions, 72 deletions
diff --git a/java/java.go b/java/java.go
index 263d0f333..1d4fa44f2 100644
--- a/java/java.go
+++ b/java/java.go
@@ -269,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.
@@ -432,7 +432,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}
@@ -443,6 +442,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
}
@@ -1981,12 +2004,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"`
@@ -2015,12 +2032,26 @@ 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"`
+
+ // 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 {
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
@@ -2036,7 +2067,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())
@@ -2075,6 +2106,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
@@ -2110,40 +2143,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") &&
@@ -2170,14 +2169,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)
}
@@ -2233,8 +2236,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)
@@ -2248,12 +2251,12 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
case libTag:
provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
classPaths = append(classPaths, provider.HeaderJars...)
+ case bootClasspathTag:
+ provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
+ 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]
case systemModulesTag:
module := dep.(SystemModulesProvider)
systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...)
@@ -2286,7 +2289,12 @@ 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)
+
+ 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)
@@ -2304,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").
@@ -2317,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().
@@ -2340,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,
@@ -2376,19 +2380,56 @@ 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) {
+ 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))
+ }
+ // 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)
+var _ android.SdkContext = (*ApiLibrary)(nil)
+
+// implement the following interface for IDE completion.
+var _ android.IDEInfo = (*ApiLibrary)(nil)
//
// Java prebuilts