Add option to compile dex for a Java library

Currently Soong will only compile a Java library into dex if the
library has device support and is installable. For our use case of
inspecting the dex at build time this is not sufficient. Add a new
"compile_dex" device property which forces the creation of a dex
rule. In this case, the class jar remains the output file of the
module.

Bug: 79409988
Test: on related CL
Change-Id: Ia908a47148a03a0bdb0da4315cce6efc86c51865
This commit is contained in:
David Brazdil
2018-06-27 10:27:45 +01:00
parent 17bef8f034
commit 17ef5635fa

View File

@@ -192,6 +192,9 @@ type CompilerDeviceProperties struct {
// If true, export a copy of the module as a -hostdex module for host testing.
Hostdex *bool
// If set to true, compile dex regardless of installable. Defaults to false.
Compile_dex *bool
Dex_preopt struct {
// If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
// true.
@@ -1134,11 +1137,15 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
outputFile = j.instrument(ctx, flags, outputFile, jarName)
}
if ctx.Device() && j.installable() {
outputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Device() && j.createDexRule() {
var dexOutputFile android.Path
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Failed() {
return
}
if j.installable() {
outputFile = dexOutputFile
}
}
ctx.CheckbuildFile(outputFile)
j.outputFile = outputFile
@@ -1213,6 +1220,10 @@ func (j *Module) installable() bool {
return BoolDefault(j.properties.Installable, true)
}
func (j *Module) createDexRule() bool {
return Bool(j.deviceProperties.Compile_dex) || j.installable()
}
var _ Dependency = (*Library)(nil)
func (j *Module) HeaderJars() android.Paths {