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

Commit 8be1e6db authored by Martin Stjernholm's avatar Martin Stjernholm
Browse files

Propagate the dex jar path as an OptionalPath which is either valid or

invalid with a message.

This will allow propagating any error from the deapexer module for
prebuilt APEXes to the location where the dex jars get used. It's only
at those points that we can raise errors about not being able to
extract files from the deapexer modules if they are invalid, and this
way we avoid encoding knowledge there about why they may be invalid.

To keep the refactoring limited it intentionally does not change any of
the existing logic for when dexJarFiles are set or not (non-nil vs nil
prior to this change), although there may be opportunity to use this
for more conditions when dex jars aren't available.

The refactoring is also not extended to
dexpreopt.ClassLoaderContextMap.

Test: m nothing
Bug: 192006406
Change-Id: I68986dccd9a9b3fee4d24caa1947ea17a36caedc
parent b13daf2b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1545,7 +1545,7 @@ func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.Platform
type javaModule interface {
	android.Module
	BaseModuleName() string
	DexJarBuildPath() android.Path
	DexJarBuildPath() java.OptionalDexJarPath
	JacocoReportClassesFile() android.Path
	LintDepSets() java.LintDepSets
	Stem() string
@@ -1559,7 +1559,7 @@ var _ javaModule = (*java.SdkLibraryImport)(nil)

// apexFileForJavaModule creates an apexFile for a java module's dex implementation jar.
func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile {
	return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath())
	return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath().PathOrNil())
}

// apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file.
+4 −1
Original line number Diff line number Diff line
@@ -4799,9 +4799,10 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
	transform := android.NullFixturePreparer

	checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) {
		t.Helper()
		// Make sure the import has been given the correct path to the dex jar.
		p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency)
		dexJarBuildPath := p.DexJarBuildPath()
		dexJarBuildPath := p.DexJarBuildPath().PathOrNil()
		stem := android.RemoveOptionalPrebuiltPrefix(name)
		android.AssertStringEquals(t, "DexJarBuildPath should be apex-related path.",
			".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar",
@@ -4809,6 +4810,7 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
	}

	checkDexJarInstallPath := func(t *testing.T, ctx *android.TestContext, name string) {
		t.Helper()
		// Make sure the import has been given the correct path to the dex jar.
		p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency)
		dexJarBuildPath := p.DexJarInstallPath()
@@ -4819,6 +4821,7 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
	}

	ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) {
		t.Helper()
		// Make sure that an apex variant is not created for the source module.
		android.AssertArrayString(t, "Check if there is no source variant",
			[]string{"android_common"},
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import (

	"android/soong/android"
	"android/soong/java"

	"github.com/google/blueprint/proptools"
)

@@ -737,7 +738,7 @@ func TestBootclasspathFragmentContentsNoName(t *testing.T) {

func getDexJarPath(result *android.TestResult, name string) string {
	module := result.Module(name, "android_common")
	return module.(java.UsesLibraryDependency).DexJarBuildPath().RelativeToTop().String()
	return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String()
}

// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
+5 −3
Original line number Diff line number Diff line
@@ -176,13 +176,15 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
		name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
		if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
			// If the exported java module provides a dex jar path then add it to the list of apexFiles.
			path := child.(interface{ DexJarBuildPath() android.Path }).DexJarBuildPath()
			if path != nil {
			path := child.(interface {
				DexJarBuildPath() java.OptionalDexJarPath
			}).DexJarBuildPath()
			if path.IsSet() {
				af := apexFile{
					module:              child,
					moduleDir:           ctx.OtherModuleDir(child),
					androidMkModuleName: name,
					builtFile:           path,
					builtFile:           path.Path(),
					class:               javaSharedLib,
				}
				if module, ok := child.(java.DexpreopterInterface); ok {
+15 −15
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {

	if hostDexNeeded {
		var output android.Path
		if library.dexJarFile != nil {
			output = library.dexJarFile
		if library.dexJarFile.IsSet() {
			output = library.dexJarFile.Path()
		} else {
			output = library.implementationAndResourcesJar
		}
@@ -44,8 +44,8 @@ func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
				func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
					entries.SetBool("LOCAL_IS_HOST_MODULE", true)
					entries.SetPath("LOCAL_PREBUILT_MODULE_FILE", output)
					if library.dexJarFile != nil {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile)
					if library.dexJarFile.IsSet() {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
					}
					entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
@@ -106,8 +106,8 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
					if library.installFile == nil {
						entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
					}
					if library.dexJarFile != nil {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile)
					if library.dexJarFile.IsSet() {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
					}
					if len(library.dexpreopter.builtInstalled) > 0 {
						entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
@@ -207,8 +207,8 @@ func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
				entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !Bool(prebuilt.properties.Installable))
				if prebuilt.dexJarFile != nil {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile)
				if prebuilt.dexJarFile.IsSet() {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
				}
				entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile)
				entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
@@ -227,12 +227,12 @@ func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
	}
	return []android.AndroidMkEntries{android.AndroidMkEntries{
		Class:      "JAVA_LIBRARIES",
		OutputFile: android.OptionalPathForPath(prebuilt.dexJarFile),
		OutputFile: android.OptionalPathForPath(prebuilt.dexJarFile.Path()),
		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
				if prebuilt.dexJarFile != nil {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile)
				if prebuilt.dexJarFile.IsSet() {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
				}
				if len(prebuilt.dexpreopter.builtInstalled) > 0 {
					entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", prebuilt.dexpreopter.builtInstalled)
@@ -279,8 +279,8 @@ func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries {
				func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
					entries.SetPath("LOCAL_SOONG_HEADER_JAR", binary.headerJarFile)
					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", binary.implementationAndResourcesJar)
					if binary.dexJarFile != nil {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", binary.dexJarFile)
					if binary.dexJarFile.IsSet() {
						entries.SetPath("LOCAL_SOONG_DEX_JAR", binary.dexJarFile.Path())
					}
					if len(binary.dexpreopter.builtInstalled) > 0 {
						entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
@@ -336,8 +336,8 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
				entries.SetString("LOCAL_MODULE", app.installApkName)
				entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall)
				entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage)
				if app.dexJarFile != nil {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile)
				if app.dexJarFile.IsSet() {
					entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path())
				}
				if app.implementationAndResourcesJar != nil {
					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", app.implementationAndResourcesJar)
Loading