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

Commit 64c9cd24 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Wrap blueprint_go_binary and bootstrap_go_package into android.Modules"...

Merge "Wrap blueprint_go_binary and bootstrap_go_package into android.Modules" into main am: 82e99ce3

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



Change-Id: Ica8a29fbf3b942bbba6cd764b92ce0661dc811b5
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e7057c90 82e99ce3
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import (
	"strings"

	"github.com/google/blueprint"
	"github.com/google/blueprint/bootstrap"
	"github.com/google/blueprint/pathtools"
	"github.com/google/blueprint/proptools"
)
@@ -815,8 +814,6 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs
		switch x := mod.(type) {
		case AndroidMkDataProvider:
			err = translateAndroidModule(ctx, w, moduleInfoJSONs, mod, x)
		case bootstrap.GoBinaryTool:
			err = translateGoBinaryModule(ctx, w, mod, x)
		case AndroidMkEntriesProvider:
			err = translateAndroidMkEntriesModule(ctx, w, moduleInfoJSONs, mod, x)
		default:
@@ -831,23 +828,6 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs
	return err
}

// A simple, special Android.mk entry output func to make it possible to build blueprint tools using
// m by making them phony targets.
func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
	goBinary bootstrap.GoBinaryTool) error {

	name := ctx.ModuleName(mod)
	fmt.Fprintln(w, ".PHONY:", name)
	fmt.Fprintln(w, name+":", goBinary.InstallPath())
	fmt.Fprintln(w, "")
	// Assuming no rules in make include go binaries in distributables.
	// If the assumption is wrong, make will fail to build without the necessary .meta_lic and .meta_module files.
	// In that case, add the targets and rules here to build a .meta_lic file for `name` and a .meta_module for
	// `goBinary.InstallPath()` pointing to the `name`.meta_lic file.

	return nil
}

func (data *AndroidMkData) fillInData(ctx fillInEntriesContext, mod blueprint.Module) {
	// Get the preamble content through AndroidMkEntries logic.
	data.Entries = AndroidMkEntries{
+4 −46
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import (
	"strings"

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

@@ -397,33 +396,8 @@ func (target Target) Variations() []blueprint.Variation {
// device_supported and host_supported properties to determine which OsTypes are enabled for this
// module, then searches through the Targets to determine which have enabled Targets for this
// module.
func osMutator(bpctx blueprint.BottomUpMutatorContext) {
	var module Module
	var ok bool
	if module, ok = bpctx.Module().(Module); !ok {
		// The module is not a Soong module, it is a Blueprint module.
		if bootstrap.IsBootstrapModule(bpctx.Module()) {
			// Bootstrap Go modules are always the build OS or linux bionic.
			config := bpctx.Config().(Config)
			osNames := []string{config.BuildOSTarget.OsVariation()}
			for _, hostCrossTarget := range config.Targets[LinuxBionic] {
				if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType {
					osNames = append(osNames, hostCrossTarget.OsVariation())
				}
			}
			osNames = FirstUniqueStrings(osNames)
			bpctx.CreateVariations(osNames...)
		}
		return
	}

	// Bootstrap Go module support above requires this mutator to be a
	// blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
	// filters out non-Soong modules.  Now that we've handled them, create a
	// normal android.BottomUpMutatorContext.
	mctx := bottomUpMutatorContextFactory(bpctx, module, false)
	defer bottomUpMutatorContextPool.Put(mctx)

func osMutator(mctx BottomUpMutatorContext) {
	module := mctx.Module()
	base := module.base()

	// Nothing to do for modules that are not architecture specific (e.g. a genrule).
@@ -553,24 +527,8 @@ var DarwinUniversalVariantTag = archDepTag{name: "darwin universal binary"}
//
// Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass,
// but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets().
func archMutator(bpctx blueprint.BottomUpMutatorContext) {
	var module Module
	var ok bool
	if module, ok = bpctx.Module().(Module); !ok {
		if bootstrap.IsBootstrapModule(bpctx.Module()) {
			// Bootstrap Go modules are always the build architecture.
			bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation())
		}
		return
	}

	// Bootstrap Go module support above requires this mutator to be a
	// blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
	// filters out non-Soong modules.  Now that we've handled them, create a
	// normal android.BottomUpMutatorContext.
	mctx := bottomUpMutatorContextFactory(bpctx, module, false)
	defer bottomUpMutatorContextPool.Put(mctx)

func archMutator(mctx BottomUpMutatorContext) {
	module := mctx.Module()
	base := module.base()

	if !base.ArchSpecific() {
+4 −2
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ type ModuleBuildParams BuildParams
type ModuleContext interface {
	BaseModuleContext

	blueprintModuleContext() blueprint.ModuleContext
	// BlueprintModuleContext returns the blueprint.ModuleContext that the ModuleContext wraps.  It may only be
	// used by the golang module types that need to call into the bootstrap module types.
	BlueprintModuleContext() blueprint.ModuleContext

	// Deprecated: use ModuleContext.Build instead.
	ModuleBuild(pctx PackageContext, params ModuleBuildParams)
@@ -779,7 +781,7 @@ func (m *moduleContext) UncheckedModule() {
	m.uncheckedModule = true
}

func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
func (m *moduleContext) BlueprintModuleContext() blueprint.ModuleContext {
	return m.bp
}

+2 −2
Original line number Diff line number Diff line
@@ -148,9 +148,9 @@ var preArch = []RegisterMutatorFunc{
}

func registerArchMutator(ctx RegisterMutatorsContext) {
	ctx.BottomUpBlueprint("os", osMutator).Parallel()
	ctx.BottomUp("os", osMutator).Parallel()
	ctx.Transition("image", &imageTransitionMutator{})
	ctx.BottomUpBlueprint("arch", archMutator).Parallel()
	ctx.BottomUp("arch", archMutator).Parallel()
}

var preDeps = []RegisterMutatorFunc{
+0 −12
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import (
	"strings"

	"github.com/google/blueprint"
	"github.com/google/blueprint/bootstrap"
	"github.com/google/blueprint/pathtools"
)

@@ -555,13 +554,6 @@ func (p OutputPaths) Strings() []string {
	return ret
}

// PathForGoBinary returns the path to the installed location of a bootstrap_go_binary module.
func PathForGoBinary(ctx PathContext, goBinary bootstrap.GoBinaryTool) Path {
	goBinaryInstallDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin")
	rel := Rel(ctx, goBinaryInstallDir.String(), goBinary.InstallPath())
	return goBinaryInstallDir.Join(ctx, rel)
}

// Expands Paths to a SourceFileProducer or OutputFileProducer module dependency referenced via ":name" or ":name{.tag}" syntax.
// If the dependency is not found, a missingErrorDependency is returned.
// If the module dependency is not a SourceFileProducer or OutputFileProducer, appropriate errors will be returned.
@@ -573,10 +565,6 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag
	if aModule, ok := module.(Module); ok && !aModule.Enabled(ctx) {
		return nil, missingDependencyError{[]string{moduleName}}
	}
	if goBinary, ok := module.(bootstrap.GoBinaryTool); ok && tag == "" {
		goBinaryPath := PathForGoBinary(ctx, goBinary)
		return Paths{goBinaryPath}, nil
	}
	outputFiles, err := outputFilesForModule(ctx, module, tag)
	if outputFiles != nil && err == nil {
		return outputFiles, nil
Loading