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
This commit is contained in:
Colin Cross
2018-08-15 11:19:12 -07:00
parent b628ea5327
commit 3063b78ea5
4 changed files with 30 additions and 14 deletions

View File

@@ -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)