Merge "Add support for renamed kotlin stdlib."
This commit is contained in:
@@ -66,6 +66,7 @@ var (
|
|||||||
`${config.GenKotlinBuildFileCmd} $classpath $outDir $out.rsp $srcJarDir/list > $outDir/kotlinc-build.xml &&` +
|
`${config.GenKotlinBuildFileCmd} $classpath $outDir $out.rsp $srcJarDir/list > $outDir/kotlinc-build.xml &&` +
|
||||||
`${config.KotlincCmd} $kotlincFlags ` +
|
`${config.KotlincCmd} $kotlincFlags ` +
|
||||||
`-jvm-target $kotlinJvmTarget -Xbuild-file=$outDir/kotlinc-build.xml && ` +
|
`-jvm-target $kotlinJvmTarget -Xbuild-file=$outDir/kotlinc-build.xml && ` +
|
||||||
|
`rm $outDir/kotlinc-build.xml && ` +
|
||||||
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
||||||
CommandDeps: []string{
|
CommandDeps: []string{
|
||||||
"${config.KotlincCmd}",
|
"${config.KotlincCmd}",
|
||||||
@@ -358,6 +359,11 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
|
|||||||
// for downstream tools like desugar.
|
// for downstream tools like desugar.
|
||||||
jarArgs = append(jarArgs, "-stripFile module-info.class")
|
jarArgs = append(jarArgs, "-stripFile module-info.class")
|
||||||
|
|
||||||
|
// Remove any kotlin-reflect related files
|
||||||
|
// TODO(pszczepaniak): Support kotlin-reflect
|
||||||
|
jarArgs = append(jarArgs, "-stripFile \"*.kotlin_module\"")
|
||||||
|
jarArgs = append(jarArgs, "-stripFile \"*.kotlin_builtin\"")
|
||||||
|
|
||||||
if stripDirs {
|
if stripDirs {
|
||||||
jarArgs = append(jarArgs, "-D")
|
jarArgs = append(jarArgs, "-D")
|
||||||
}
|
}
|
||||||
|
24
java/java.go
24
java/java.go
@@ -83,6 +83,10 @@ type CompilerProperties struct {
|
|||||||
// ext, and framework for device targets)
|
// ext, and framework for device targets)
|
||||||
No_framework_libs *bool
|
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
|
// list of module-specific flags that will be used for javac compiles
|
||||||
Javacflags []string `android:"arch_variant"`
|
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.
|
// won't emit any classes for them.
|
||||||
|
|
||||||
flags.kotlincFlags = "-no-stdlib"
|
flags.kotlincFlags = "-no-stdlib"
|
||||||
|
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
flags.kotlincFlags += " -no-jdk"
|
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
|
// Make javac rule depend on the kotlinc rule
|
||||||
flags.classpath = append(flags.classpath, kotlinJar)
|
flags.classpath = append(flags.classpath, kotlinJar)
|
||||||
|
|
||||||
// Jar kotlin classes into the final jar after javac
|
// Jar kotlin classes into the final jar after javac
|
||||||
jars = append(jars, kotlinJar)
|
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
|
// 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
|
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 {
|
if j.properties.Jarjar_rules != nil {
|
||||||
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
||||||
// Transform classes.jar into classes-jarjar.jar
|
// Transform classes.jar into classes-jarjar.jar
|
||||||
|
@@ -176,6 +176,8 @@ func testContext(config android.Config, bp string,
|
|||||||
"bar-doc/b.java": nil,
|
"bar-doc/b.java": nil,
|
||||||
"bar-doc/known_oj_tags.txt": nil,
|
"bar-doc/known_oj_tags.txt": nil,
|
||||||
"external/doclava/templates-sdk": nil,
|
"external/doclava/templates-sdk": nil,
|
||||||
|
|
||||||
|
"external/kotlinc/jarjar-rules.txt": nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range fs {
|
for k, v := range fs {
|
||||||
@@ -755,6 +757,12 @@ func TestKotlin(t *testing.T) {
|
|||||||
name: "baz",
|
name: "baz",
|
||||||
srcs: ["c.java"],
|
srcs: ["c.java"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "blorg",
|
||||||
|
renamed_kotlin_stdlib: true,
|
||||||
|
srcs: ["b.kt"],
|
||||||
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
||||||
@@ -797,6 +805,12 @@ func TestKotlin(t *testing.T) {
|
|||||||
t.Errorf(`expected %q in bar implicits %v`,
|
t.Errorf(`expected %q in bar implicits %v`,
|
||||||
bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
|
bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blorgRenamedJar := ctx.ModuleForTests("blorg", "android_common").Output("kotlin-renamed/blorg.jar")
|
||||||
|
if blorgRenamedJar.Implicit.String() != "external/kotlinc/jarjar-rules.txt" {
|
||||||
|
t.Errorf(`expected external/kotlinc/jarjar-rules.txt in blorg implicit %q`,
|
||||||
|
blorgRenamedJar.Implicit.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTurbine(t *testing.T) {
|
func TestTurbine(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user