Merge "Add experimental option to target Java 17" am: 78ce8c23de

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2104326

Change-Id: I2657bd024f5d0eabd609ff4df5d1a088b8dbd1f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sorin Basca 2022-05-24 15:36:26 +00:00 committed by Automerger Merge Worker
commit a571b7d389
3 changed files with 23 additions and 2 deletions

View file

@ -698,6 +698,10 @@ func (c *config) IsEnvFalse(key string) bool {
return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
}
func (c *config) TargetsJava17() bool {
return c.IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_17")
}
// EnvDeps returns the environment variables this build depends on. The first
// call to this function blocks future reads from the environment.
func (c *config) EnvDeps() map[string]string {

View file

@ -468,6 +468,12 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an
return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() {
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
} else if ctx.Config().TargetsJava17() {
// Temporary experimental flag to be able to try and build with
// java version 17 options. The flag, if used, just sets Java
// 17 as the default version, leaving any components that
// target an older version intact.
return JAVA_VERSION_17
} else {
return JAVA_VERSION_11
}
@ -482,6 +488,7 @@ const (
JAVA_VERSION_8 = 8
JAVA_VERSION_9 = 9
JAVA_VERSION_11 = 11
JAVA_VERSION_17 = 17
)
func (v javaVersion) String() string {
@ -496,6 +503,8 @@ func (v javaVersion) String() string {
return "1.9"
case JAVA_VERSION_11:
return "11"
case JAVA_VERSION_17:
return "17"
default:
return "unsupported"
}
@ -518,8 +527,10 @@ func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) jav
return JAVA_VERSION_9
case "11":
return JAVA_VERSION_11
case "10":
ctx.PropertyErrorf("java_version", "Java language levels 10 is not supported")
case "17":
return JAVA_VERSION_11
case "10", "12", "13", "14", "15", "16":
ctx.PropertyErrorf("java_version", "Java language level %s is not supported", javaVersion)
return JAVA_VERSION_UNSUPPORTED
default:
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")

View file

@ -57,6 +57,12 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe
return JAVA_VERSION_8
} else if sdk.FinalOrFutureInt() <= 31 {
return JAVA_VERSION_9
} else if ctx.Config().TargetsJava17() {
// Temporary experimental flag to be able to try and build with
// java version 17 options. The flag, if used, just sets Java
// 17 as the default version, leaving any components that
// target an older version intact.
return JAVA_VERSION_17
} else {
return JAVA_VERSION_11
}