Don't hide *.kotlin_module in turbine dependencies

The jars containing the merged header classes from transitive
static dependencies were stripping all of META-INF/.  Kotlin
puts metadata in META-INF that is used to map the package to
the static class that contains the package-level functions.

This also exposed that the metadata in META-INF is always
called "name.kotlin_module", so a library that contains
kotlin files with a dependency that also contains kotlin files
would shade the metadata file.  Use a unique name instead.

Fixes: 131709692
Test: m checkbuild
Change-Id: I5cd276e563206e37c4c0d90fe9f346e9396f88c0
This commit is contained in:
Colin Cross
2019-05-08 14:30:12 -07:00
parent 082640d6ee
commit 6c6e6cd64d
4 changed files with 21 additions and 10 deletions

View File

@@ -126,7 +126,7 @@ func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleCont
if len(d.headerJars) > 1 { if len(d.headerJars) > 1 {
outputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) outputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName)
TransformJarsToJar(ctx, outputFile, "turbine combine", d.headerJars, TransformJarsToJar(ctx, outputFile, "turbine combine", d.headerJars,
android.OptionalPath{}, false, nil, nil) android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"})
d.combinedHeaderJar = outputFile d.combinedHeaderJar = outputFile
} else { } else {
d.combinedHeaderJar = d.headerJars[0] d.combinedHeaderJar = d.headerJars[0]

View File

@@ -1380,7 +1380,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
// since we have to strip META-INF/TRANSITIVE dir from turbine.jar // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
false, nil, []string{"META-INF"}) false, nil, []string{"META-INF/TRANSITIVE"})
headerJar = combinedJar headerJar = combinedJar
if j.expandJarjarRules != nil { if j.expandJarjarRules != nil {

View File

@@ -18,6 +18,7 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"encoding/binary" "encoding/binary"
"path/filepath"
"strings" "strings"
"android/soong/android" "android/soong/android"
@@ -30,7 +31,7 @@ var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` + Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` +
`mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` + `mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.GenKotlinBuildFileCmd} $classpath $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` + `${config.GenKotlinBuildFileCmd} $classpath "$name" $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
`${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` + `${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
`-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` + `-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` + `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
@@ -50,7 +51,8 @@ var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
Rspfile: "$out.rsp", Rspfile: "$out.rsp",
RspfileContent: `$in`, RspfileContent: `$in`,
}, },
"kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir") "kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile",
"emptyDir", "name")
// kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile. // kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile.
func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath, func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
@@ -61,6 +63,9 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
deps = append(deps, flags.kotlincClasspath...) deps = append(deps, flags.kotlincClasspath...)
deps = append(deps, srcJars...) deps = append(deps, srcJars...)
kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: kotlinc, Rule: kotlinc,
Description: "kotlinc", Description: "kotlinc",
@@ -77,6 +82,7 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
"emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(),
// http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8 // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
"kotlinJvmTarget": "1.8", "kotlinJvmTarget": "1.8",
"name": kotlinName,
}, },
}) })
} }
@@ -85,7 +91,7 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && mkdir -p "$srcJarDir" "$kaptDir" && ` + Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && mkdir -p "$srcJarDir" "$kaptDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.GenKotlinBuildFileCmd} $classpath "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` + `${config.GenKotlinBuildFileCmd} $classpath "$name" "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
`${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` + `${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
`-Xplugin=${config.KotlinKaptJar} ` + `-Xplugin=${config.KotlinKaptJar} ` +
`-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` + `-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` +
@@ -111,7 +117,7 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
RspfileContent: `$in`, RspfileContent: `$in`,
}, },
"kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor", "kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor",
"classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile") "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name")
// kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs // kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs
// annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be // annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be
@@ -138,6 +144,9 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
{"-target", flags.javaVersion}, {"-target", flags.javaVersion},
}) })
kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: kapt, Rule: kapt,
Description: "kapt", Description: "kapt",
@@ -154,6 +163,7 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
"kaptProcessor": kaptProcessor, "kaptProcessor": kaptProcessor,
"kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(), "kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(),
"encodedJavacFlags": encodedJavacFlags, "encodedJavacFlags": encodedJavacFlags,
"name": kotlinName,
}, },
}) })
} }

View File

@@ -17,7 +17,7 @@
# Generates kotlinc module xml file to standard output based on rsp files # Generates kotlinc module xml file to standard output based on rsp files
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
echo "usage: $0 <classpath> <outDir> <rspFiles>..." >&2 echo "usage: $0 <classpath> <name> <outDir> <rspFiles>..." >&2
exit 1 exit 1
fi fi
@@ -27,8 +27,9 @@ if [[ $1 == "-classpath" ]]; then
fi; fi;
classpath=$1 classpath=$1
out_dir=$2 name=$2
shift 2 out_dir=$3
shift 3
# Path in the build file may be relative to the build file, we need to make them # Path in the build file may be relative to the build file, we need to make them
# absolute # absolute
@@ -44,7 +45,7 @@ get_abs_path () {
} }
# Print preamble # Print preamble
echo "<modules><module name=\"name\" type=\"java-production\" outputDir=\"${out_dir}\">" echo "<modules><module name=\"${name}\" type=\"java-production\" outputDir=\"${out_dir}\">"
# Print classpath entries # Print classpath entries
for file in $(echo "$classpath" | tr ":" "\n"); do for file in $(echo "$classpath" | tr ":" "\n"); do