diff options
author | 2025-01-08 03:06:21 +0000 | |
---|---|---|
committer | 2025-01-09 21:18:41 +0000 | |
commit | 1a7705d96ddaee5fc829c11bca0c43543b9b4155 (patch) | |
tree | 7b8c9ed9736dad3f9c44725f060c298b726b3ec6 | |
parent | f8ac19663f24e83d9d4a037f9bbccc93d3ed99bf (diff) |
Add kotlin-lang flag.
This allows targets to choose whether they compile with kotlin 1.9
or kotlin 2
Bug: 383569207
Flag: EXEMPT this is a flag itself
Test: built system image
Change-Id: I1228ed1d8a5f9d6029261e4a867a2301069e315f
-rw-r--r-- | java/base.go | 18 | ||||
-rw-r--r-- | java/config/kotlin.go | 5 |
2 files changed, 20 insertions, 3 deletions
diff --git a/java/base.go b/java/base.go index 1aef37ca4..a2fc29de7 100644 --- a/java/base.go +++ b/java/base.go @@ -90,6 +90,10 @@ type CommonProperties struct { // list of module-specific flags that will be used for kotlinc compiles Kotlincflags []string `android:"arch_variant"` + // Kotlin language version to target. Currently only 1.9 and 2 are supported. + // See kotlinc's `-language-version` flag. + Kotlin_lang_version *string + // list of java libraries that will be in the classpath Libs []string `android:"arch_variant"` @@ -1331,6 +1335,16 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath kotlincFlags := j.properties.Kotlincflags CheckKotlincFlags(ctx, kotlincFlags) + kotlin_lang_version := proptools.StringDefault(j.properties.Kotlin_lang_version, "1.9") + if kotlin_lang_version == "1.9" { + kotlincFlags = append(kotlincFlags, "-language-version 1.9") + } else if kotlin_lang_version == "2" { + kotlincFlags = append(kotlincFlags, "-Xsuppress-version-warnings", "-Xconsistent-data-class-copy-visibility") + } else { + ctx.PropertyErrorf("kotlin_lang_version", "Must be one of `1.9` or `2`") + + } + // Workaround for KT-46512 kotlincFlags = append(kotlincFlags, "-Xsam-conversions=class") @@ -2059,7 +2073,9 @@ func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") { ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, only use internal compiler for consistency.", flag) - } else if inList(flag, config.KotlincIllegalFlags) { + } else if slices.ContainsFunc(config.KotlincIllegalFlags, func(f string) bool { + return strings.HasPrefix(flag, f) + }) { ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag) } else if flag == "-include-runtime" { ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag) diff --git a/java/config/kotlin.go b/java/config/kotlin.go index bf4c886d1..ffb025d9c 100644 --- a/java/config/kotlin.go +++ b/java/config/kotlin.go @@ -21,6 +21,7 @@ var ( KotlincIllegalFlags = []string{ "-no-jdk", "-no-stdlib", + "-language-version", } ) @@ -49,12 +50,12 @@ func init() { "-J--add-opens=java.base/java.util=ALL-UNNAMED", // https://youtrack.jetbrains.com/issue/KT-43704 }, " ")) - pctx.StaticVariable("KotlincGlobalFlags", strings.Join([]string{"-language-version 1.9"}, " ")) + pctx.StaticVariable("KotlincGlobalFlags", strings.Join([]string{}, " ")) // Use KotlincKytheGlobalFlags to prevent kotlinc version skew issues between android and // g3 kythe indexers. // This is necessary because there might be instances of kotlin code in android // platform that are not fully compatible with the kotlinc used in g3 kythe indexers. // e.g. uninitialized variables are a warning in 1.*, but an error in 2.* // https://github.com/JetBrains/kotlin/blob/master/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt#L748 - pctx.StaticVariable("KotlincKytheGlobalFlags", strings.Join([]string{"-language-version 1.9"}, " ")) + pctx.StaticVariable("KotlincKytheGlobalFlags", strings.Join([]string{}, " ")) } |