Normalize and validate the java_version property.
There are two parts to this change. Normalization: If a module specifies 'java_version: "9"', this is now normalized into 'java_version: "1.9"'. Users might reasonably assume that "9" should be valid, since javac treats them as synonyms (and, in fact, the javac documentation lists "9" as a valid value but doesn't mention "1.9"). However, the soong code that triggers JPMS support (i.e. setting -system rather than --boot-class-path) looks for the string "1.9", so prior to this change modules specifying "9" would fail with a confusing error ('javac: option --boot-class-path not allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The change normalizes the other supported values, too, for consistency.) Validation: This change also makes the build fail-fast with a clear error message for invalid values. In particular, modules specifying "10" or "11" fail with an explicit message that this is not supported, in anticipation of the switch to OpenJDK 11. Prior to this change, modules setting those values would get the confusing '--boot-class-path not allowed' error described about since JPMS support would not be triggered. (That could be fixed by changing the JPMS logic to trigger on "10" and "11", but that would be dangerous since support in the rest of the system for v54 and v55 class files is unproven: it is better to fail explicitly.) (This change also makes it fail-fast for any unrecognized values.) Test: make java Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change) Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message Bug: 131683177 Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
This commit is contained in:
21
java/java.go
21
java/java.go
@@ -907,7 +907,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
|
||||
ctx.PropertyErrorf("sdk_version", "%s", err)
|
||||
}
|
||||
if javaVersion != "" {
|
||||
ret = javaVersion
|
||||
ret = normalizeJavaVersion(ctx, javaVersion)
|
||||
} else if ctx.Device() && sdk <= 23 {
|
||||
ret = "1.7"
|
||||
} else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() {
|
||||
@@ -926,6 +926,25 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
|
||||
return ret
|
||||
}
|
||||
|
||||
func normalizeJavaVersion(ctx android.ModuleContext, javaVersion string) string {
|
||||
switch javaVersion {
|
||||
case "1.6", "6":
|
||||
return "1.6"
|
||||
case "1.7", "7":
|
||||
return "1.7"
|
||||
case "1.8", "8":
|
||||
return "1.8"
|
||||
case "1.9", "9":
|
||||
return "1.9"
|
||||
case "10", "11":
|
||||
ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
|
||||
return "unsupported"
|
||||
default:
|
||||
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
|
||||
return "unrecognized"
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
|
||||
|
||||
var flags javaBuilderFlags
|
||||
|
Reference in New Issue
Block a user