diff options
| author | 2018-03-08 13:21:55 +0000 | |
|---|---|---|
| committer | 2018-03-20 12:55:19 +0000 | |
| commit | 66c0c4067f8a70847eaa37273671aa8fe4203f1d (patch) | |
| tree | c6b7e79ab4cd9804740ce634b6a896ec452e155c /java/java.go | |
| parent | bfe65a32bb3a85a835b2b6aafb803e465e52e092 (diff) | |
Add support for renamed kotlin stdlib.
Added new CompilerProperty flag, rename_kotlin_stdlib, which
allow to build kotlin libraries/binaries that use platform internal
version of kotlin stdlib (com.android.kotlin.*). This way, app-provided
kotlin standard library won't collide with version used internaly.
+ remove kotlinc-build.xml after compilation so it won't end up in the
result jar file
+ remove *.kotlin_module and *.kotlin_bultin filesfrom result jar file.
These files are needed only by kotlin-reflect library and
need more work to support kotlin-stdlib renaming.
Bug: 73281388
Test: java_test.go
Change-Id: Iae7ccb919e2ae9853b3f30f3dd447ebd01a1bed0
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/java/java.go b/java/java.go index 5f5225c4d..125fde1ec 100644 --- a/java/java.go +++ b/java/java.go @@ -83,6 +83,10 @@ type CompilerProperties struct { // ext, and framework for device targets) No_framework_libs *bool + // Use renamed kotlin stdlib (com.android.kotlin.*). This allows kotlin usage without colliding + // with app-provided kotlin stdlib. + Renamed_kotlin_stdlib *bool + // list of module-specific flags that will be used for javac compiles Javacflags []string `android:"arch_variant"` @@ -810,6 +814,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path // won't emit any classes for them. flags.kotlincFlags = "-no-stdlib" + if ctx.Device() { flags.kotlincFlags += " -no-jdk" } @@ -830,9 +835,15 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path // Make javac rule depend on the kotlinc rule flags.classpath = append(flags.classpath, kotlinJar) + // Jar kotlin classes into the final jar after javac jars = append(jars, kotlinJar) - jars = append(jars, deps.kotlinStdlib...) + + // Don't add kotlin-stdlib if using (on-device) renamed stdlib + // (it's expected to be on device bootclasspath) + if !proptools.Bool(j.properties.Renamed_kotlin_stdlib) { + jars = append(jars, deps.kotlinStdlib...) + } } // Store the list of .java files that was passed to javac @@ -952,6 +963,17 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path outputFile = combinedJar } + // Use renamed kotlin standard library? + if srcFiles.HasExt(".kt") && proptools.Bool(j.properties.Renamed_kotlin_stdlib) { + jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName) + TransformJarJar(ctx, jarjarFile, outputFile, + android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt")) + outputFile = jarjarFile + if ctx.Failed() { + return + } + } + if j.properties.Jarjar_rules != nil { jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) // Transform classes.jar into classes-jarjar.jar |