Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17ef5635 authored by David Brazdil's avatar David Brazdil
Browse files

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
parent 17bef8f0
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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 {