diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/aar.go | 4 | ||||
| -rw-r--r-- | java/androidmk.go | 14 | ||||
| -rw-r--r-- | java/config/config.go | 8 | ||||
| -rw-r--r-- | java/config/makevars.go | 1 | ||||
| -rw-r--r-- | java/droiddoc.go | 82 | ||||
| -rw-r--r-- | java/java.go | 34 | ||||
| -rw-r--r-- | java/java_test.go | 12 | ||||
| -rw-r--r-- | java/sdk.go | 12 | ||||
| -rw-r--r-- | java/sdk_test.go | 11 | ||||
| -rw-r--r-- | java/system_modules.go | 23 |
10 files changed, 164 insertions, 37 deletions
diff --git a/java/aar.go b/java/aar.go index 6a883d3ad..6426ac365 100644 --- a/java/aar.go +++ b/java/aar.go @@ -520,6 +520,10 @@ func (a *AARImport) sdkVersion() string { return proptools.StringDefault(a.properties.Sdk_version, defaultSdkVersion(a)) } +func (a *AARImport) systemModules() string { + return "" +} + func (a *AARImport) minSdkVersion() string { if a.properties.Min_sdk_version != nil { return *a.properties.Min_sdk_version diff --git a/java/androidmk.go b/java/androidmk.go index bc61297d1..955f22b36 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -145,7 +145,7 @@ func (j *TestHelperLibrary) AndroidMkEntries() android.AndroidMkEntries { } func (prebuilt *Import) AndroidMkEntries() android.AndroidMkEntries { - if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().IsCurrentVersion() { + if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().Unversioned() { return android.AndroidMkEntries{ Disabled: true, } @@ -598,6 +598,18 @@ func (dstubs *Droidstubs) AndroidMkEntries() android.AndroidMkEntries { fmt.Fprintln(w, "droidcore: checkapi") } } + if dstubs.apiLintTimestamp != nil { + fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-api-lint") + fmt.Fprintln(w, dstubs.Name()+"-api-lint:", + dstubs.apiLintTimestamp.String()) + + fmt.Fprintln(w, ".PHONY: checkapi") + fmt.Fprintln(w, "checkapi:", + dstubs.apiLintTimestamp.String()) + + fmt.Fprintln(w, ".PHONY: droidcore") + fmt.Fprintln(w, "droidcore: checkapi") + } if dstubs.checkNullabilityWarningsTimestamp != nil { fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings") fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:", diff --git a/java/config/config.go b/java/config/config.go index ce62b932a..f418ee7f9 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -86,6 +86,14 @@ func init() { // This is set up and guaranteed by soong_ui return ctx.Config().Getenv("ANDROID_JAVA_HOME") }) + pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string { + switch ctx.Config().Getenv("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN") { + case "true": + return "11" + default: + return "9" + } + }) pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin") pctx.SourcePathVariableWithEnvOverride("JavacCmd", diff --git a/java/config/makevars.go b/java/config/makevars.go index c40f4fcc5..2fa6f8969 100644 --- a/java/config/makevars.go +++ b/java/config/makevars.go @@ -38,6 +38,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("ANDROID_JAVA_HOME", "${JavaHome}") ctx.Strict("ANDROID_JAVA8_HOME", "prebuilts/jdk/jdk8/${hostPrebuiltTag}") ctx.Strict("ANDROID_JAVA9_HOME", "prebuilts/jdk/jdk9/${hostPrebuiltTag}") + ctx.Strict("ANDROID_JAVA11_HOME", "prebuilts/jdk/jdk11/${hostPrebuiltTag}") ctx.Strict("ANDROID_JAVA_TOOLCHAIN", "${JavaToolchain}") ctx.Strict("JAVA", "${JavaCmd} ${JavaVmFlags}") ctx.Strict("JAVAC", "${JavacCmd} ${JavacVmFlags}") diff --git a/java/droiddoc.go b/java/droiddoc.go index aab61c5a7..3b581cb44 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -67,9 +67,15 @@ type JavadocProperties struct { // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. Installable *bool - // if not blank, set to the version of the sdk to compile against + // if not blank, set to the version of the sdk to compile against. + // Defaults to compiling against the current platform. Sdk_version *string `android:"arch_variant"` + // When targeting 1.9 and above, override the modules to use with --system, + // otherwise provides defaults libraries to add to the bootclasspath. + // Defaults to "none" + System_modules *string + Aidl struct { // Top level directories to pass to aidl tool Include_dirs []string @@ -238,6 +244,16 @@ type DroidstubsProperties struct { // do not perform API check against Last_released, in the case that both two specified API // files by Last_released are modules which don't exist. Ignore_missing_latest_api *bool `blueprint:"mutated"` + + Api_lint struct { + Enabled *bool + + // If set, performs api_lint on any new APIs not found in the given signature file + New_since *string `android:"path"` + + // If not blank, path to the baseline txt file for approved API lint violations. + Baseline_file *string `android:"path"` + } } // user can specify the version of previous released API file in order to do compatibility check. @@ -391,6 +407,10 @@ func (j *Javadoc) sdkVersion() string { return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j)) } +func (j *Javadoc) systemModules() string { + return proptools.String(j.properties.System_modules) +} + func (j *Javadoc) minSdkVersion() string { return j.sdkVersion() } @@ -417,6 +437,10 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { } ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) } + } else if sdkDep.systemModules != "" { + // Add the system modules to both the system modules and bootclasspath. + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) + ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules) } } @@ -504,6 +528,10 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: if dep, ok := module.(Dependency); ok { deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) + } else if sm, ok := module.(*SystemModules); ok { + // A system modules dependency has been added to the bootclasspath + // so add its libs to the bootclasspath. + deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...) } else { panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) } @@ -1154,6 +1182,7 @@ type Droidstubs struct { checkCurrentApiTimestamp android.WritablePath updateCurrentApiTimestamp android.WritablePath checkLastReleasedApiTimestamp android.WritablePath + apiLintTimestamp android.WritablePath checkNullabilityWarningsTimestamp android.WritablePath @@ -1490,6 +1519,57 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Create rule for apicheck + if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() { + rule := android.NewRuleBuilder() + rule.Command().Text("( true") + + srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars") + srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) + + cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList, + deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths) + + cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles) + + newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since) + if newSince.Valid() { + cmd.FlagWithInput("--api-lint ", newSince.Path()) + } else { + cmd.Flag("--api-lint") + } + + d.inclusionAnnotationsFlags(ctx, cmd) + d.mergeAnnoDirFlags(ctx, cmd) + + baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file) + updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt") + d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp") + + if baselineFile.Valid() { + cmd.FlagWithInput("--baseline ", baselineFile.Path()) + cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput) + } + + zipSyncCleanupCmd(rule, srcJarDir) + + msg := fmt.Sprintf(`\n******************************\n`+ + `Your API changes are triggering API Lint warnings or errors.\n\n`+ + `To make these errors go away, you have two choices:\n`+ + ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+ + ` 2. You can update the baseline by executing the following command:\n`+ + ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+ + `******************************\n`, updatedBaselineOutput, baselineFile.Path()) + rule.Command(). + Text("touch").Output(d.apiLintTimestamp). + Text(") || ("). + Text("echo").Flag("-e").Flag(`"` + msg + `"`). + Text("; exit 38"). + Text(")") + + rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint") + + } + if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") && !ctx.Config().IsPdkBuild() { diff --git a/java/java.go b/java/java.go index 47fb1a7be..3b95f1e47 100644 --- a/java/java.go +++ b/java/java.go @@ -270,7 +270,8 @@ type CompilerDeviceProperties struct { Proguard_flags_files []string `android:"path"` } - // When targeting 1.9, override the modules to use with --system + // When targeting 1.9 and above, override the modules to use with --system, + // otherwise provides defaults libraries to add to the bootclasspath. System_modules *string UncompressDex bool `blueprint:"mutated"` @@ -347,8 +348,8 @@ type Module struct { // list of SDK lib names that this java moudule is exporting exportedSdkLibs []string - // list of source files, collected from compiledJavaSrcs and compiledSrcJars - // filter out Exclude_srcs, will be used by android.IDEInfo struct + // list of source files, collected from srcFiles with uniqie java and all kt files, + // will be used by android.IDEInfo struct expandIDEInfoCompiledSrcs []string // expanded Jarjar_rules @@ -457,7 +458,10 @@ type checkVendorModuleContext interface { type sdkDep struct { useModule, useFiles, useDefaultLibs, invalidVersion bool - modules []string + modules []string + + // The default system modules to use. Will be an empty string if no system + // modules are to be used. systemModules string frameworkResModule string @@ -496,6 +500,10 @@ func (j *Module) sdkVersion() string { return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j)) } +func (j *Module) systemModules() string { + return proptools.String(j.deviceProperties.System_modules) +} + func (j *Module) minSdkVersion() string { if j.deviceProperties.Min_sdk_version != nil { return *j.deviceProperties.Min_sdk_version @@ -528,13 +536,10 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...) } } - } else if j.deviceProperties.System_modules == nil { - ctx.PropertyErrorf("sdk_version", - `system_modules is required to be set when sdk_version is "none", did you mean "core_platform"`) - } else if *j.deviceProperties.System_modules != "none" { + } else if sdkDep.systemModules != "" { // Add the system modules to both the system modules and bootclasspath. - ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules) - ctx.AddVariationDependencies(nil, bootClasspathTag, *j.deviceProperties.System_modules) + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) + ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules) } if ctx.ModuleName() == "android_stubs_current" || ctx.ModuleName() == "android_system_stubs_current" || @@ -1030,9 +1035,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { srcJars = append(srcJars, aaptSrcJar) } - // Collect source files and filter out Exclude_srcs that IDEInfo struct will use - j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...) - if j.properties.Jarjar_rules != nil { j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) } @@ -1049,6 +1051,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { } } + // Collect .java files for AIDEGen + j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...) + var kotlinJars android.Paths if srcFiles.HasExt(".kt") { @@ -1073,6 +1078,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...) kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...) + // Collect .kt files for AIDEGen + j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...) + flags.classpath = append(flags.classpath, deps.kotlinStdlib...) flags.classpath = append(flags.classpath, deps.kotlinAnnotations...) diff --git a/java/java_test.go b/java/java_test.go index f0cb6f8bd..a3499ccd8 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1095,8 +1095,10 @@ func TestPatchModule(t *testing.T) { ` t.Run("Java language level 8", func(t *testing.T) { - // Test default javac -source 1.8 -target 1.8 - ctx, _ := testJava(t, bp) + // Test with legacy javac -source 1.8 -target 1.8 + config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"}) + ctx := testContext(bp, nil) + run(t, ctx, config) checkPatchModuleFlag(t, ctx, "foo", "") checkPatchModuleFlag(t, ctx, "bar", "") @@ -1104,10 +1106,8 @@ func TestPatchModule(t *testing.T) { }) t.Run("Java language level 9", func(t *testing.T) { - // Test again with javac -source 9 -target 9 - config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "true"}) - ctx := testContext(bp, nil) - run(t, ctx, config) + // Test with default javac -source 9 -target 9 + ctx, _ := testJava(t, bp) checkPatchModuleFlag(t, ctx, "foo", "") expected := "java.base=.:" + buildDir diff --git a/java/sdk.go b/java/sdk.go index 3451774c0..c6a9a73c8 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -39,6 +39,8 @@ var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey") type sdkContext interface { // sdkVersion returns the sdk_version property of the current module, or an empty string if it is not set. sdkVersion() string + // systemModules returns the system_modules property of the current module, or an empty string if it is not set. + systemModules() string // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set. minSdkVersion() string // targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set. @@ -185,8 +187,18 @@ func decodeSdkDep(ctx android.BaseModuleContext, sdkContext sdkContext) sdkDep { frameworkResModule: "framework-res", } case "none": + systemModules := sdkContext.systemModules() + if systemModules == "" { + ctx.PropertyErrorf("sdk_version", + `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`) + } else if systemModules == "none" { + // Normalize no system modules to an empty string. + systemModules = "" + } + return sdkDep{ noStandardLibs: true, + systemModules: systemModules, } case "core_platform": return sdkDep{ diff --git a/java/sdk_test.go b/java/sdk_test.go index 5001b477b..5e0e592f6 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -279,9 +279,9 @@ func TestClasspath(t *testing.T) { } } + // Test with legacy javac -source 1.8 -target 1.8 t.Run("Java language level 8", func(t *testing.T) { - // Test default javac -source 1.8 -target 1.8 - config := testConfig(nil) + config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"}) if testcase.unbundled { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } @@ -302,9 +302,9 @@ func TestClasspath(t *testing.T) { } }) - // Test again with javac -source 9 -target 9 + // Test with default javac -source 9 -target 9 t.Run("Java language level 9", func(t *testing.T) { - config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "true"}) + config := testConfig(nil) if testcase.unbundled { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } @@ -327,7 +327,8 @@ func TestClasspath(t *testing.T) { // Test again with PLATFORM_VERSION_CODENAME=REL t.Run("REL", func(t *testing.T) { - config := testConfig(nil) + // TODO(b/115604102): This test should be rewritten with language level 9 + config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"}) config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) diff --git a/java/system_modules.go b/java/system_modules.go index 43e4e118b..b56a401d3 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -36,13 +36,15 @@ func init() { var ( jarsTosystemModules = pctx.AndroidStaticRule("jarsTosystemModules", blueprint.RuleParams{ Command: `rm -rf ${outDir} ${workDir} && mkdir -p ${workDir}/jmod && ` + - `${moduleInfoJavaPath} ${moduleName} $in > ${workDir}/module-info.java && ` + + `${moduleInfoJavaPath} java.base $in > ${workDir}/module-info.java && ` + `${config.JavacCmd} --system=none --patch-module=java.base=${classpath} ${workDir}/module-info.java && ` + `${config.SoongZipCmd} -jar -o ${workDir}/classes.jar -C ${workDir} -f ${workDir}/module-info.class && ` + `${config.MergeZipsCmd} -j ${workDir}/module.jar ${workDir}/classes.jar $in && ` + - `${config.JmodCmd} create --module-version 9 --target-platform android ` + - ` --class-path ${workDir}/module.jar ${workDir}/jmod/${moduleName}.jmod && ` + - `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules ${moduleName} --output ${outDir} ` + + // Note: The version of the java.base module created must match the version + // of the jlink tool which consumes it. + `${config.JmodCmd} create --module-version ${config.JlinkVersion} --target-platform android ` + + ` --class-path ${workDir}/module.jar ${workDir}/jmod/java.base.jmod && ` + + `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules java.base --output ${outDir} ` + // Note: The system-modules jlink plugin is disabled because (a) it is not // useful on Android, and (b) it causes errors with later versions of jlink // when the jdk.internal.module is absent from java.base (as it is here). @@ -58,10 +60,10 @@ var ( "${config.JrtFsJar}", }, }, - "moduleName", "classpath", "outDir", "workDir") + "classpath", "outDir", "workDir") ) -func TransformJarsToSystemModules(ctx android.ModuleContext, moduleName string, jars android.Paths) (android.Path, android.Paths) { +func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) { outDir := android.PathForModuleOut(ctx, "system") workDir := android.PathForModuleOut(ctx, "modules") outputFile := android.PathForModuleOut(ctx, "system/lib/modules") @@ -77,10 +79,9 @@ func TransformJarsToSystemModules(ctx android.ModuleContext, moduleName string, Outputs: outputs, Inputs: jars, Args: map[string]string{ - "moduleName": moduleName, - "classpath": strings.Join(jars.Strings(), ":"), - "workDir": workDir.String(), - "outDir": outDir.String(), + "classpath": strings.Join(jars.Strings(), ":"), + "workDir": workDir.String(), + "outDir": outDir.String(), }, }) @@ -123,7 +124,7 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte system.headerJars = jars - system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, "java.base", jars) + system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, jars) } func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) { |