Make javaVersion an enum
Remove the hardcoded checks against "1.9" by making javaVersion an enum and implementing javaVersion.usesJavaModules(). Test: TestClasspath Change-Id: I559eeb1f45880bb8177269c6d977ee4dfbadce57
This commit is contained in:
parent
74362a4d5e
commit
1e7438524b
5 changed files with 63 additions and 33 deletions
|
@ -535,6 +535,10 @@ func (a *AARImport) targetSdkVersion() string {
|
|||
return a.sdkVersion()
|
||||
}
|
||||
|
||||
func (a *AARImport) javaVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
||||
|
||||
func (a *AARImport) ExportPackage() android.Path {
|
||||
|
|
|
@ -190,7 +190,7 @@ type javaBuilderFlags struct {
|
|||
systemModules *systemModules
|
||||
aidlFlags string
|
||||
aidlDeps android.Paths
|
||||
javaVersion string
|
||||
javaVersion javaVersion
|
||||
|
||||
errorProneExtraJavacFlags string
|
||||
errorProneProcessorPath classpath
|
||||
|
@ -239,7 +239,7 @@ func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx
|
|||
deps = append(deps, srcJars...)
|
||||
|
||||
var bootClasspath string
|
||||
if flags.javaVersion == "1.9" {
|
||||
if flags.javaVersion.usesJavaModules() {
|
||||
var systemModuleDeps android.Paths
|
||||
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
|
||||
deps = append(deps, systemModuleDeps...)
|
||||
|
@ -279,7 +279,7 @@ func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx
|
|||
"bootClasspath": bootClasspath,
|
||||
"classpath": flags.classpath.FormJavaClassPath("-classpath"),
|
||||
"javacFlags": flags.javacFlags,
|
||||
"javaVersion": flags.javaVersion,
|
||||
"javaVersion": flags.javaVersion.String(),
|
||||
"outDir": android.PathForModuleOut(ctx, "javac", "classes.xref").String(),
|
||||
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
|
||||
"processor": processor,
|
||||
|
@ -318,7 +318,7 @@ func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.
|
|||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||
"classpath": strings.Join(flags.classpath.FormTurbineClasspath("--classpath "), " "),
|
||||
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
"javaVersion": flags.javaVersion.String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
|
|||
deps = append(deps, srcJars...)
|
||||
|
||||
var bootClasspath string
|
||||
if flags.javaVersion == "1.9" {
|
||||
if flags.javaVersion.usesJavaModules() {
|
||||
var systemModuleDeps android.Paths
|
||||
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
|
||||
deps = append(deps, systemModuleDeps...)
|
||||
|
@ -388,7 +388,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
|
|||
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(),
|
||||
"outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
"javaVersion": flags.javaVersion.String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -665,7 +665,7 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
|
||||
deps.systemModules, deps.classpath, j.sourcepaths)
|
||||
|
||||
cmd.FlagWithArg("-source ", javaVersion).
|
||||
cmd.FlagWithArg("-source ", javaVersion.String()).
|
||||
Flag("-J-Xmx1024m").
|
||||
Flag("-XDignore.symbol.file").
|
||||
Flag("-Xdoclint:none")
|
||||
|
@ -1432,12 +1432,12 @@ func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleB
|
|||
}
|
||||
}
|
||||
|
||||
func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion string, srcs android.Paths,
|
||||
func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
|
||||
srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
|
||||
cmd := rule.Command().BuiltTool(ctx, "metalava").
|
||||
Flag(config.JavacVmFlags).
|
||||
FlagWithArg("-encoding ", "UTF-8").
|
||||
FlagWithArg("-source ", javaVersion).
|
||||
FlagWithArg("-source ", javaVersion.String()).
|
||||
FlagWithRspFileInputList("@", srcs).
|
||||
FlagWithInput("@", srcJarList)
|
||||
|
||||
|
|
70
java/java.go
70
java/java.go
|
@ -865,8 +865,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||
return deps
|
||||
}
|
||||
|
||||
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
|
||||
var ret string
|
||||
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
|
||||
v := sdkContext.sdkVersion()
|
||||
// For PDK builds, use the latest SDK version instead of "current"
|
||||
if ctx.Config().IsPdkBuild() &&
|
||||
|
@ -884,41 +883,69 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
|
|||
ctx.PropertyErrorf("sdk_version", "%s", err)
|
||||
}
|
||||
if javaVersion != "" {
|
||||
ret = normalizeJavaVersion(ctx, javaVersion)
|
||||
return normalizeJavaVersion(ctx, javaVersion)
|
||||
} else if ctx.Device() && sdk <= 23 {
|
||||
ret = "1.7"
|
||||
return JAVA_VERSION_7
|
||||
} else if ctx.Device() && sdk <= 29 {
|
||||
ret = "1.8"
|
||||
return JAVA_VERSION_8
|
||||
} else if ctx.Device() &&
|
||||
sdkContext.sdkVersion() != "" &&
|
||||
sdkContext.sdkVersion() != "none" &&
|
||||
sdkContext.sdkVersion() != "core_platform" &&
|
||||
sdk == android.FutureApiLevel {
|
||||
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
|
||||
ret = "1.8"
|
||||
return JAVA_VERSION_8
|
||||
} else {
|
||||
ret = "1.9"
|
||||
return JAVA_VERSION_9
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func normalizeJavaVersion(ctx android.ModuleContext, javaVersion string) string {
|
||||
type javaVersion int
|
||||
|
||||
const (
|
||||
JAVA_VERSION_UNSUPPORTED = 0
|
||||
JAVA_VERSION_6 = 6
|
||||
JAVA_VERSION_7 = 7
|
||||
JAVA_VERSION_8 = 8
|
||||
JAVA_VERSION_9 = 9
|
||||
)
|
||||
|
||||
func (v javaVersion) String() string {
|
||||
switch v {
|
||||
case JAVA_VERSION_6:
|
||||
return "1.6"
|
||||
case JAVA_VERSION_7:
|
||||
return "1.7"
|
||||
case JAVA_VERSION_8:
|
||||
return "1.8"
|
||||
case JAVA_VERSION_9:
|
||||
return "1.9"
|
||||
default:
|
||||
return "unsupported"
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
|
||||
func (v javaVersion) usesJavaModules() bool {
|
||||
return v >= 9
|
||||
}
|
||||
|
||||
func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
|
||||
switch javaVersion {
|
||||
case "1.6", "6":
|
||||
return "1.6"
|
||||
return JAVA_VERSION_6
|
||||
case "1.7", "7":
|
||||
return "1.7"
|
||||
return JAVA_VERSION_7
|
||||
case "1.8", "8":
|
||||
return "1.8"
|
||||
return JAVA_VERSION_8
|
||||
case "1.9", "9":
|
||||
return "1.9"
|
||||
return JAVA_VERSION_9
|
||||
case "10", "11":
|
||||
ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
|
||||
return "unsupported"
|
||||
return JAVA_VERSION_UNSUPPORTED
|
||||
default:
|
||||
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
|
||||
return "unrecognized"
|
||||
return JAVA_VERSION_UNSUPPORTED
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -931,7 +958,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
|
|||
|
||||
// javac flags.
|
||||
javacFlags := j.properties.Javacflags
|
||||
if flags.javaVersion == "1.9" {
|
||||
if flags.javaVersion.usesJavaModules() {
|
||||
javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
|
||||
}
|
||||
if ctx.Config().MinimizeJavaDebugInfo() {
|
||||
|
@ -963,9 +990,8 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
|
|||
|
||||
flags.processor = strings.Join(deps.processorClasses, ",")
|
||||
|
||||
if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
|
||||
decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() &&
|
||||
inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
|
||||
if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
|
||||
decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
|
||||
// Give host-side tools a version of OpenJDK's standard libraries
|
||||
// close to what they're targeting. As of Dec 2017, AOSP is only
|
||||
// bundling OpenJDK 8 and 9, so nothing < 8 is available.
|
||||
|
@ -989,7 +1015,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
|
|||
}
|
||||
}
|
||||
|
||||
if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
|
||||
if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
|
||||
// Manually specify build directory in case it is not under the repo root.
|
||||
// (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
|
||||
// just adding a symlink under the root doesn't help.)
|
||||
|
@ -1022,7 +1048,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||
deps := j.collectDeps(ctx)
|
||||
flags := j.collectBuilderFlags(ctx, deps)
|
||||
|
||||
if flags.javaVersion == "1.9" {
|
||||
if flags.javaVersion.usesJavaModules() {
|
||||
j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
|
||||
}
|
||||
srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
|
||||
|
|
|
@ -141,8 +141,8 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
|
|||
}
|
||||
|
||||
encodedJavacFlags := kaptEncodeFlags([][2]string{
|
||||
{"-source", flags.javaVersion},
|
||||
{"-target", flags.javaVersion},
|
||||
{"-source", flags.javaVersion.String()},
|
||||
{"-target", flags.javaVersion.String()},
|
||||
})
|
||||
|
||||
kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
|
||||
|
|
Loading…
Reference in a new issue