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

Commit c012dfc5 authored by Paul Duffin's avatar Paul Duffin Committed by Automerger Merge Worker
Browse files

Merge "Generalize deapexer module to export any files" am: d8561166

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1697666

Change-Id: I055c7f96e30cba9cbb3dfd09d0e6e9194e35a4f0
parents 977a1c20 d8561166
Loading
Loading
Loading
Loading
+29 −15
Original line number Original line Diff line number Diff line
@@ -40,17 +40,29 @@ import (
// This is intentionally not registered by name as it is not intended to be used from within an
// This is intentionally not registered by name as it is not intended to be used from within an
// `Android.bp` file.
// `Android.bp` file.


// Properties that are specific to `deapexer` but which need to be provided on the `prebuilt_apex`
// DeapexerExportedFile defines the properties needed to expose a file from the deapexer module.
// module.`
type DeapexerExportedFile struct {
	// The tag parameter which must be passed to android.OutputFileProducer OutputFiles(tag) method
	// to retrieve the path to the unpacked file.
	Tag string

	// The path within the APEX that needs to be exported.
	Path string `android:"path"`
}

// DeapexerProperties specifies the properties supported by the deapexer module.
//
// As these are never intended to be supplied in a .bp file they use a different naming convention
// to make it clear that they are different.
type DeapexerProperties struct {
type DeapexerProperties struct {
	// List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
	// List of common modules that may need access to files exported by this module.
	// APEX bundle will create an APEX variant and provide dex implementation jars for use by
	//
	// dexpreopt and boot jars package check.
	// A common module in this sense is one that is not arch specific but uses a common variant for
	Exported_java_libs []string
	// all architectures, e.g. java.

	CommonModules []string
	// List of bootclasspath fragments inside this prebuiltd APEX bundle and for which this APEX

	// bundle will create an APEX variant.
	// List of files exported from the .apex file by this module
	Exported_bootclasspath_fragments []string
	ExportedFiles []DeapexerExportedFile
}
}


type SelectedApexProperties struct {
type SelectedApexProperties struct {
@@ -81,7 +93,7 @@ func privateDeapexerFactory() android.Module {
func (p *Deapexer) DepsMutator(ctx android.BottomUpMutatorContext) {
func (p *Deapexer) DepsMutator(ctx android.BottomUpMutatorContext) {
	// Add dependencies from the java modules to which this exports files from the `.apex` file onto
	// Add dependencies from the java modules to which this exports files from the `.apex` file onto
	// this module so that they can access the `DeapexerInfo` object that this provides.
	// this module so that they can access the `DeapexerInfo` object that this provides.
	for _, lib := range p.properties.Exported_java_libs {
	for _, lib := range p.properties.CommonModules {
		dep := prebuiltApexExportedModuleName(ctx, lib)
		dep := prebuiltApexExportedModuleName(ctx, lib)
		ctx.AddReverseDependency(ctx.Module(), android.DeapexerTag, dep)
		ctx.AddReverseDependency(ctx.Module(), android.DeapexerTag, dep)
	}
	}
@@ -96,10 +108,12 @@ func (p *Deapexer) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	exports := make(map[string]android.Path)
	exports := make(map[string]android.Path)


	// Create mappings from name+tag to all the required exported paths.
	// Create mappings from name+tag to all the required exported paths.
	for _, l := range p.properties.Exported_java_libs {
	for _, e := range p.properties.ExportedFiles {
		// Populate the exports that this makes available. The path here must match the path of the
		tag := e.Tag
		// file in the APEX created by apexFileForJavaModule(...).
		path := e.Path
		exports[l+"{.dexjar}"] = deapexerOutput.Join(ctx, "javalib", l+".jar")

		// Populate the exports that this makes available.
		exports[tag] = deapexerOutput.Join(ctx, path)
	}
	}


	// If the prebuilt_apex exports any files then create a build rule that unpacks the apex using
	// If the prebuilt_apex exports any files then create a build rule that unpacks the apex using
+32 −7
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@ package apex


import (
import (
	"fmt"
	"fmt"
	"path/filepath"
	"strconv"
	"strconv"
	"strings"
	"strings"


@@ -57,10 +58,18 @@ type sanitizedPrebuilt interface {
}
}


type prebuiltCommonProperties struct {
type prebuiltCommonProperties struct {
	DeapexerProperties
	SelectedApexProperties
	SelectedApexProperties


	ForceDisable bool `blueprint:"mutated"`
	ForceDisable bool `blueprint:"mutated"`

	// List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
	// APEX bundle will create an APEX variant and provide dex implementation jars for use by
	// dexpreopt and boot jars package check.
	Exported_java_libs []string

	// List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
	// bundle will create an APEX variant.
	Exported_bootclasspath_fragments []string
}
}


func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
@@ -411,15 +420,20 @@ func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerNam
	}
	}


	// Compute the deapexer properties from the transitive dependencies of this module.
	// Compute the deapexer properties from the transitive dependencies of this module.
	deapexerProperties := &DeapexerProperties{}
	javaModules := []string{}
	exportedFiles := map[string]string{}
	ctx.WalkDeps(func(child, parent android.Module) bool {
	ctx.WalkDeps(func(child, parent android.Module) bool {
		tag := ctx.OtherModuleDependencyTag(child)
		tag := ctx.OtherModuleDependencyTag(child)


		name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
		name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
		if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
		if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
			deapexerProperties.Exported_java_libs = append(deapexerProperties.Exported_java_libs, name)
			javaModules = append(javaModules, name)

			// Add the dex implementation jar to the set of exported files. The path here must match the
			// path of the file in the APEX created by apexFileForJavaModule(...).
			exportedFiles[name+"{.dexjar}"] = filepath.Join("javalib", name+".jar")

		} else if tag == exportedBootclasspathFragmentTag {
		} else if tag == exportedBootclasspathFragmentTag {
			deapexerProperties.Exported_bootclasspath_fragments = append(deapexerProperties.Exported_bootclasspath_fragments, name)
			// Only visit the children of the bootclasspath_fragment for now.
			// Only visit the children of the bootclasspath_fragment for now.
			return true
			return true
		}
		}
@@ -427,9 +441,20 @@ func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerNam
		return false
		return false
	})
	})


	// Remove any duplicates from the deapexer lists.
	// Create properties for deapexer module.
	deapexerProperties.Exported_bootclasspath_fragments = android.FirstUniqueStrings(deapexerProperties.Exported_bootclasspath_fragments)
	deapexerProperties := &DeapexerProperties{
	deapexerProperties.Exported_java_libs = android.FirstUniqueStrings(deapexerProperties.Exported_java_libs)
		// Remove any duplicates from the java modules lists as a module may be included via a direct
		// dependency as well as transitive ones.
		CommonModules: android.SortedUniqueStrings(javaModules),
	}

	// Populate the exported files property in a fixed order.
	for _, tag := range android.SortedStringKeys(exportedFiles) {
		deapexerProperties.ExportedFiles = append(deapexerProperties.ExportedFiles, DeapexerExportedFile{
			Tag:  tag,
			Path: exportedFiles[tag],
		})
	}


	props := struct {
	props := struct {
		Name          *string
		Name          *string