diff options
author | Zoran Jovanovic <zoran.jovanovic@sony.com> | 2018-08-21 17:10:29 +0200 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-11-14 15:02:46 +0000 |
commit | 8736ce29e8cda85924fa2f083a1421afed965bb2 (patch) | |
tree | 7755f70b63be5bce2f22b7c8c66d8ec0dd9f63eb /java/java.go | |
parent | ad9eab8b51f9e38b287d4ab42880d724970126bf (diff) |
Enable kotlinc flags in blueprint files
Add support for adding kotlinc files in the module.
Some flags are unnecessary as they are added by
default (-no-jdk and -no-stdlib), or are not needed
on an Android build (-include-runtime), or may
conflict with the build (-kotlin-home and
-Xintellij-plugin-root), so the error stops the
build if they are added.
Test: part of java/java_test.go
Change-Id: If3b2777062daaa490a20c014e9b1bb4b1cb0a8df
Signed-off-by: Zoran Jovanovic <zoran.jovanovic@sony.com>
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/java/java.go b/java/java.go index fef9a215d..5ed99f7e8 100644 --- a/java/java.go +++ b/java/java.go @@ -89,6 +89,9 @@ type CompilerProperties struct { // list of module-specific flags that will be used for javac compiles Javacflags []string `android:"arch_variant"` + // list of module-specific flags that will be used for kotlinc compiles + Kotlincflags []string `android:"arch_variant"` + // list of of java libraries that will be in the classpath Libs []string `android:"arch_variant"` @@ -1087,13 +1090,21 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path var kotlinJars android.Paths if srcFiles.HasExt(".kt") { + // user defined kotlin flags. + kotlincFlags := j.properties.Kotlincflags + CheckKotlincFlags(ctx, kotlincFlags) + // If there are kotlin files, compile them first but pass all the kotlin and java files // kotlinc will use the java files to resolve types referenced by the kotlin files, but // won't emit any classes for them. - - flags.kotlincFlags = "-no-stdlib" + kotlincFlags = append(kotlincFlags, "-no-stdlib") if ctx.Device() { - flags.kotlincFlags += " -no-jdk" + kotlincFlags = append(kotlincFlags, "-no-jdk") + } + if len(kotlincFlags) > 0 { + // optimization. + ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " ")) + flags.kotlincFlags += "$kotlincFlags" } var kotlinSrcFiles android.Paths @@ -1332,6 +1343,31 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.outputFile = outputFile.WithoutRel() } +// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user, +// since some of these flags may be used internally. +func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { + for _, flag := range flags { + flag = strings.TrimSpace(flag) + + if !strings.HasPrefix(flag, "-") { + ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag) + } 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) { + 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) + } else { + args := strings.Split(flag, " ") + if args[0] == "-kotlin-home" { + ctx.PropertyErrorf("kotlincflags", + "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag) + } + } + } +} + func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path { |