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

Commit cf6bf37d authored by Martin Stjernholm's avatar Martin Stjernholm Committed by Gerrit Code Review
Browse files

Merge changes I957f3df8,I68986dcc

* changes:
  Consolidate the code to resolve a deapexer module dependency.
  Propagate the dex jar path as an OptionalPath which is either valid or invalid with a message.
parents e1bb74e7 4482560c
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ import (

// The information exported by the `deapexer` module, access it using `DeapxerInfoProvider`.
type DeapexerInfo struct {
	apexModuleName string

	// map from the name of an exported file from a prebuilt_apex to the path to that file. The
	// exported file name is the apex relative path, e.g. javalib/core-libart.jar.
	//
@@ -76,6 +78,11 @@ type DeapexerInfo struct {
	exports map[string]WritablePath
}

// ApexModuleName returns the name of the APEX module that provided the info.
func (i DeapexerInfo) ApexModuleName() string {
	return i.apexModuleName
}

// PrebuiltExportPath provides the path, or nil if not available, of a file exported from the
// prebuilt_apex that created this ApexInfo.
//
@@ -95,8 +102,9 @@ var DeapexerProvider = blueprint.NewProvider(DeapexerInfo{})
// for use with a prebuilt_apex module.
//
// See apex/deapexer.go for more information.
func NewDeapexerInfo(exports map[string]WritablePath) DeapexerInfo {
func NewDeapexerInfo(apexModuleName string, exports map[string]WritablePath) DeapexerInfo {
	return DeapexerInfo{
		apexModuleName: apexModuleName,
		exports:        exports,
	}
}
@@ -133,3 +141,20 @@ type RequiresFilesFromPrebuiltApexTag interface {
	// Method that differentiates this interface from others.
	RequiresFilesFromPrebuiltApex()
}

// FindDeapexerProviderForModule searches through the direct dependencies of the current context
// module for a DeapexerTag dependency and returns its DeapexerInfo. If there is an error then it is
// reported with ctx.ModuleErrorf and nil is returned.
func FindDeapexerProviderForModule(ctx ModuleContext) *DeapexerInfo {
	var di *DeapexerInfo
	ctx.VisitDirectDepsWithTag(DeapexerTag, func(m Module) {
		p := ctx.OtherModuleProvider(m, DeapexerProvider).(DeapexerInfo)
		di = &p
	})
	if di != nil {
		return di
	}
	ai := ctx.Provider(ApexInfoProvider).(ApexInfo)
	ctx.ModuleErrorf("No prebuilt APEX provides a deapexer module for APEX variant %s", ai.ApexVariationName)
	return nil
}
+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.
+8 −2
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"},
@@ -4856,8 +4859,11 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
		// Make sure that dexpreopt can access dex implementation files from the prebuilt.
		ctx := testDexpreoptWithApexes(t, bp, "", transform)

		deapexerName := deapexerModuleName("myapex")
		android.AssertStringEquals(t, "APEX module name from deapexer name", "myapex", apexModuleName(deapexerName))

		// Make sure that the deapexer has the correct input APEX.
		deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common")
		deapexer := ctx.ModuleForTests(deapexerName, "android_common")
		rule := deapexer.Rule("deapexer")
		if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) {
			t.Errorf("expected: %q, found: %q", expected, actual)
+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
+16 −2
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
package apex

import (
	"strings"

	"android/soong/android"
)

@@ -75,6 +77,17 @@ type Deapexer struct {
	inputApex android.Path
}

// Returns the name of the deapexer module corresponding to an APEX module with the given name.
func deapexerModuleName(apexModuleName string) string {
	return apexModuleName + ".deapexer"
}

// Returns the name of the APEX module corresponding to an deapexer module with
// the given name. This reverses deapexerModuleName.
func apexModuleName(deapexerModuleName string) string {
	return strings.TrimSuffix(deapexerModuleName, ".deapexer")
}

func privateDeapexerFactory() android.Module {
	module := &Deapexer{}
	module.AddProperties(&module.properties, &module.selectedApexProperties)
@@ -113,7 +126,8 @@ func (p *Deapexer) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	// apex relative path to extracted file path available for other modules.
	if len(exports) > 0 {
		// Make the information available for other modules.
		ctx.SetProvider(android.DeapexerProvider, android.NewDeapexerInfo(exports))
		di := android.NewDeapexerInfo(apexModuleName(ctx.ModuleName()), exports)
		ctx.SetProvider(android.DeapexerProvider, di)

		// Create a sorted list of the files that this exports.
		exportedPaths = android.SortedUniquePaths(exportedPaths)
@@ -131,6 +145,6 @@ func (p *Deapexer) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		for _, p := range exportedPaths {
			command.Output(p.(android.WritablePath))
		}
		builder.Build("deapexer", "deapex "+ctx.ModuleName())
		builder.Build("deapexer", "deapex "+apexModuleName(ctx.ModuleName()))
	}
}
Loading