aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-07-12 12:28:41 -0700
committerColin Cross <ccross@android.com>2018-07-12 16:59:59 -0700
commit37f6d79c7ea557c117d119a89bb46d7a6a5d19ff (patch)
treead4c52af3781293d6dc968b3be931a94d0f0d441
parent7f09c40c4924ac2e8510036bfa6ce264216bc964 (diff)
downloadbuild_soong-37f6d79c7ea557c117d119a89bb46d7a6a5d19ff.tar.gz
build_soong-37f6d79c7ea557c117d119a89bb46d7a6a5d19ff.tar.bz2
build_soong-37f6d79c7ea557c117d119a89bb46d7a6a5d19ff.zip
Add exclude_files and exclude_dirs properties to java_import
Prebuilt jars sometime contain files that we don't want. In Make we would delete everything in META-INF when importing jars, but that caused problems when there were necessary files in there, so we added LOCAL_DONT_DELETE_JAR_META_INF. Soong does the opposite, keeping everything by default. Add properties to allow explicitly stripping unwanted files instead. Bug: 111389216 Test: m checkbuild Change-Id: I6d07f519ebc7d0e1bf0af93416bb569e3c2b1500
-rw-r--r--java/builder.go20
-rw-r--r--java/java.go35
-rw-r--r--java/java_test.go11
3 files changed, 40 insertions, 26 deletions
diff --git a/java/builder.go b/java/builder.go
index 15e96313..55be3a6b 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -318,7 +318,8 @@ func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.Writa
}
func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath, desc string,
- jars android.Paths, manifest android.OptionalPath, stripDirs bool, dirsToStrip []string) {
+ jars android.Paths, manifest android.OptionalPath, stripDirEntries bool, filesToStrip []string,
+ dirsToStrip []string) {
var deps android.Paths
@@ -328,22 +329,19 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
deps = append(deps, manifest.Path())
}
- if dirsToStrip != nil {
- for _, dir := range dirsToStrip {
- jarArgs = append(jarArgs, "-stripDir ", dir)
- }
+ for _, dir := range dirsToStrip {
+ jarArgs = append(jarArgs, "-stripDir ", dir)
+ }
+
+ for _, file := range filesToStrip {
+ jarArgs = append(jarArgs, "-stripFile ", file)
}
// Remove any module-info.class files that may have come from prebuilt jars, they cause problems
// for downstream tools like desugar.
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 stripDirEntries {
jarArgs = append(jarArgs, "-D")
}
diff --git a/java/java.go b/java/java.go
index 9ae05f3c..5cbd8bac 100644
--- a/java/java.go
+++ b/java/java.go
@@ -995,6 +995,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
}
+ var stripFiles []string
+
if srcFiles.HasExt(".kt") {
// 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
@@ -1027,9 +1029,13 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
// Jar kotlin classes into the final jar after javac
jars = append(jars, kotlinJar)
- // Don't add kotlin-stdlib if using (on-device) renamed stdlib
- // (it's expected to be on device bootclasspath)
- if !Bool(j.properties.Renamed_kotlin_stdlib) {
+ if Bool(j.properties.Renamed_kotlin_stdlib) {
+ // Remove any kotlin-reflect related files
+ // TODO(pszczepaniak): Support kotlin-reflect
+ stripFiles = append(stripFiles, "*.kotlin_module", "*.kotlin_builtin")
+ } else {
+ // Only add kotlin-stdlib if not using (on-device) renamed stdlib
+ // (it's expected to be on device bootclasspath)
jars = append(jars, deps.kotlinStdlib...)
}
}
@@ -1143,7 +1149,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
outputFile = jars[0]
} else {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
- TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
+ TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
+ false, stripFiles, nil)
outputFile = combinedJar
}
@@ -1219,7 +1226,8 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
// we cannot skip the combine step for now if there is only one jar
// since we have to strip META-INF/TRANSITIVE dir from turbine.jar
combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
- TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
+ TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
+ false, nil, []string{"META-INF"})
headerJar = combinedJar
if j.properties.Jarjar_rules != nil {
@@ -1477,6 +1485,12 @@ type ImportProperties struct {
// List of shared java libs that this module has dependencies to
Libs []string
+
+ // List of files to remove from the jar file(s)
+ Exclude_files []string
+
+ // List of directories to remove from the jar file(s)
+ Exclude_dirs []string
}
type Import struct {
@@ -1485,7 +1499,6 @@ type Import struct {
properties ImportProperties
- classpathFiles android.Paths
combinedClasspathFile android.Path
exportedSdkLibs []string
}
@@ -1511,14 +1524,16 @@ func (j *Import) Name() string {
}
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
+ android.ExtractSourcesDeps(ctx, j.properties.Jars)
ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
}
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
+ jars := ctx.ExpandSources(j.properties.Jars, nil)
outputFile := android.PathForModuleOut(ctx, "classes.jar")
- TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
+ TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
+ false, j.properties.Exclude_files, j.properties.Exclude_dirs)
j.combinedClasspathFile = outputFile
ctx.VisitDirectDeps(func(module android.Module) {
@@ -1547,11 +1562,11 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var _ Dependency = (*Import)(nil)
func (j *Import) HeaderJars() android.Paths {
- return j.classpathFiles
+ return android.Paths{j.combinedClasspathFile}
}
func (j *Import) ImplementationJars() android.Paths {
- return j.classpathFiles
+ return android.Paths{j.combinedClasspathFile}
}
func (j *Import) AidlIncludeDirs() android.Paths {
diff --git a/java/java_test.go b/java/java_test.go
index 537bdb92..6bba29b8 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -598,14 +598,15 @@ func TestPrebuilts(t *testing.T) {
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
+ barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output
+ bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output
- bar := "a.jar"
- if !strings.Contains(javac.Args["classpath"], bar) {
- t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
+ if !strings.Contains(javac.Args["classpath"], barJar.String()) {
+ t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
}
- if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != "b.jar" {
- t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, "b.jar")
+ if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() {
+ t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
}
}