aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-08-15 11:19:12 -0700
committerColin Cross <ccross@android.com>2018-08-16 16:13:58 -0700
commit3063b78ea57a4c206996332c3eb5cb79f65a0c92 (patch)
treea5caf341e2b5478c638010c87707165f9f988dc2
parentb628ea532772ff33d2582cfa2e2fb28f23bf6462 (diff)
downloadbuild_soong-3063b78ea57a4c206996332c3eb5cb79f65a0c92.tar.gz
build_soong-3063b78ea57a4c206996332c3eb5cb79f65a0c92.tar.bz2
build_soong-3063b78ea57a4c206996332c3eb5cb79f65a0c92.zip
Make :module provide the output file for java modules
Make :module on a java_library provide the output file, which is normally the implementation jar. For java_library modules with installable: true or compile_dex: true this will be the dexjar instead. For android_app modules this will be the apk. Bug: 80144045 Test: no change to out/soong/build.ninja Change-Id: I739674aee60a38bfccb859369e4414b46f293d82
-rw-r--r--android/paths.go5
-rw-r--r--java/builder.go1
-rw-r--r--java/dex.go2
-rw-r--r--java/java.go36
4 files changed, 30 insertions, 14 deletions
diff --git a/android/paths.go b/android/paths.go
index c9e71503..e69fbe72 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -663,6 +663,11 @@ func (p OutputPath) withRel(rel string) OutputPath {
return p
}
+func (p OutputPath) WithoutRel() OutputPath {
+ p.basePath.rel = filepath.Base(p.basePath.path)
+ return p
+}
+
var _ Path = OutputPath{}
// PathForOutput joins the provided paths and returns an OutputPath that is
diff --git a/java/builder.go b/java/builder.go
index 55be3a6b..4bdea283 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -125,6 +125,7 @@ var (
)
func init() {
+ pctx.Import("android/soong/common")
pctx.Import("android/soong/java/config")
}
diff --git a/java/dex.go b/java/dex.go
index 8363a7db..d0ca06e4 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -140,7 +140,7 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F
}
func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
- classesJar android.Path, jarName string) android.Path {
+ classesJar android.Path, jarName string) android.ModuleOutPath {
useR8 := Bool(j.deviceProperties.Optimize.Enabled)
diff --git a/java/java.go b/java/java.go
index b183e2ba..43af2c6b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -300,7 +300,7 @@ type Module struct {
}
func (j *Module) Srcs() android.Paths {
- return android.Paths{j.implementationJarFile}
+ return android.Paths{j.outputFile}
}
var _ android.SourceFileProducer = (*Module)(nil)
@@ -1152,14 +1152,24 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
// Combine the classes built from sources, any manifests, and any static libraries into
// classes.jar. If there is only one input jar this step will be skipped.
- var outputFile android.Path
+ var outputFile android.ModuleOutPath
if len(jars) == 1 && !manifest.Valid() {
- // Optimization: skip the combine step if there is nothing to do
- // TODO(ccross): this leaves any module-info.class files, but those should only come from
- // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
- // any if len(jars) == 1.
- outputFile = jars[0]
+ if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
+ // Optimization: skip the combine step if there is nothing to do
+ // TODO(ccross): this leaves any module-info.class files, but those should only come from
+ // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
+ // any if len(jars) == 1.
+ outputFile = moduleOutPath
+ } else {
+ combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: jars[0],
+ Output: combinedJar,
+ })
+ outputFile = combinedJar
+ }
} else {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
@@ -1204,17 +1214,17 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
- var dexOutputFile android.Path
+ var dexOutputFile android.ModuleOutPath
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Failed() {
return
}
- if Bool(j.properties.Installable) {
- outputFile = dexOutputFile
- }
+ outputFile = dexOutputFile
}
ctx.CheckbuildFile(outputFile)
- j.outputFile = outputFile
+
+ // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
+ j.outputFile = outputFile.WithoutRel()
}
func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
@@ -1258,7 +1268,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
}
func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
- classesJar android.Path, jarName string) android.Path {
+ classesJar android.Path, jarName string) android.ModuleOutPath {
specs := j.jacocoModuleToZipCommand(ctx)