Make :module provide the output file for java modules am: 3063b78ea5

am: 976957aa2c

Change-Id: I91bf52ae960b178e7c1d513a1011d58840b12fe4
This commit is contained in:
Colin Cross
2018-08-16 22:48:13 -07:00
committed by android-build-merger
4 changed files with 30 additions and 14 deletions

View File

@@ -663,6 +663,11 @@ func (p OutputPath) withRel(rel string) OutputPath {
return p return p
} }
func (p OutputPath) WithoutRel() OutputPath {
p.basePath.rel = filepath.Base(p.basePath.path)
return p
}
var _ Path = OutputPath{} var _ Path = OutputPath{}
// PathForOutput joins the provided paths and returns an OutputPath that is // PathForOutput joins the provided paths and returns an OutputPath that is

View File

@@ -125,6 +125,7 @@ var (
) )
func init() { func init() {
pctx.Import("android/soong/common")
pctx.Import("android/soong/java/config") pctx.Import("android/soong/java/config")
} }

View File

@@ -140,7 +140,7 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F
} }
func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, 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) useR8 := Bool(j.deviceProperties.Optimize.Enabled)

View File

@@ -300,7 +300,7 @@ type Module struct {
} }
func (j *Module) Srcs() android.Paths { func (j *Module) Srcs() android.Paths {
return android.Paths{j.implementationJarFile} return android.Paths{j.outputFile}
} }
var _ android.SourceFileProducer = (*Module)(nil) 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 // 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. // 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() { if len(jars) == 1 && !manifest.Valid() {
// Optimization: skip the combine step if there is nothing to do if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
// TODO(ccross): this leaves any module-info.class files, but those should only come from // Optimization: skip the combine step if there is nothing to do
// prebuilt dependencies until we support modules in the platform build, so there shouldn't be // TODO(ccross): this leaves any module-info.class files, but those should only come from
// any if len(jars) == 1. // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
outputFile = jars[0] // 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 { } else {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName) combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, 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)) { 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) dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Failed() { if ctx.Failed() {
return return
} }
if Bool(j.properties.Installable) { outputFile = dexOutputFile
outputFile = dexOutputFile
}
} }
ctx.CheckbuildFile(outputFile) 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, 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, 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) specs := j.jacocoModuleToZipCommand(ctx)