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

Commit b5275328 authored by Yu Liu's avatar Yu Liu
Browse files

Use VisitAllModuleVariantProxies in generateModuleTarget.

Also rename android.CommonPropertiesProvider to android.CommonModuleInfo.

Bug: 377723687
Test: Compare the ninja and mk files generated.
Change-Id: Iea46c16234204eef808b590b5cc1b43b5a874636
parent 059af370
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -211,6 +211,12 @@ type BaseModuleContext interface {
	// data modified by the current mutator.
	VisitAllModuleVariants(visit func(Module))

	// VisitAllModuleVariantProxies calls visit for each variant of the current module.  Variants of a module are always
	// visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
	// from all variants if the current module is the last one. Otherwise, care must be taken to not access any
	// data modified by the current mutator.
	VisitAllModuleVariantProxies(visit func(proxy ModuleProxy))

	// GetTagPath is supposed to be called in visit function passed in WalkDeps()
	// and returns a top-down dependency tags path from a start module to current child module.
	// It has one less entry than GetWalkPath() as it contains the dependency tags that
@@ -382,7 +388,7 @@ func (b *baseModuleContext) validateAndroidModuleProxy(
		return &aModule
	}

	if !OtherModuleProviderOrDefault(b, module, CommonPropertiesProviderKey).Enabled {
	if !OtherModuleProviderOrDefault(b, module, CommonModuleInfoKey).Enabled {
		if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependencyProxy(b, aModule) {
			if b.Config().AllowMissingDependencies() {
				b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
@@ -594,6 +600,10 @@ func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
	})
}

func (b *baseModuleContext) VisitAllModuleVariantProxies(visit func(ModuleProxy)) {
	b.bp.VisitAllModuleVariantProxies(visitProxyAdaptor(visit))
}

func (b *baseModuleContext) PrimaryModule() Module {
	return b.bp.PrimaryModule().(Module)
}
+16 −12
Original line number Diff line number Diff line
@@ -1643,25 +1643,27 @@ func (m *ModuleBase) generateVariantTarget(ctx *moduleContext) {
func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) {
	var allInstalledFiles InstallPaths
	var allCheckbuildTargets Paths
	ctx.VisitAllModuleVariants(func(module Module) {
		a := module.base()
	ctx.VisitAllModuleVariantProxies(func(module ModuleProxy) {
		var checkbuildTarget Path
		var uncheckedModule bool
		if a == m {
		var skipAndroidMkProcessing bool
		if ctx.EqualModules(m.module, module) {
			allInstalledFiles = append(allInstalledFiles, ctx.installFiles...)
			checkbuildTarget = ctx.checkbuildTarget
			uncheckedModule = ctx.uncheckedModule
			skipAndroidMkProcessing = shouldSkipAndroidMkProcessing(ctx, m)
		} else {
			info := OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider)
			allInstalledFiles = append(allInstalledFiles, info.InstallFiles...)
			checkbuildTarget = info.CheckbuildTarget
			uncheckedModule = info.UncheckedModule
			skipAndroidMkProcessing = OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).SkipAndroidMkProcessing
		}
		// A module's -checkbuild phony targets should
		// not be created if the module is not exported to make.
		// Those could depend on the build target and fail to compile
		// for the current build target.
		if (!ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, a)) && !uncheckedModule && checkbuildTarget != nil {
		if (!ctx.Config().KatiEnabled() || !skipAndroidMkProcessing) && !uncheckedModule && checkbuildTarget != nil {
			allCheckbuildTargets = append(allCheckbuildTargets, checkbuildTarget)
		}
	})
@@ -1850,15 +1852,16 @@ type FinalModuleBuildTargetsInfo struct {

var FinalModuleBuildTargetsProvider = blueprint.NewProvider[FinalModuleBuildTargetsInfo]()

type CommonPropertiesProviderData struct {
type CommonModuleInfo struct {
	Enabled bool
	// Whether the module has been replaced by a prebuilt
	ReplacedByPrebuilt bool
	// The Target of artifacts that this module variant is responsible for creating.
	CompileTarget           Target
	SkipAndroidMkProcessing bool
}

var CommonPropertiesProviderKey = blueprint.NewProvider[CommonPropertiesProviderData]()
var CommonModuleInfoKey = blueprint.NewProvider[CommonModuleInfo]()

type PrebuiltModuleProviderData struct {
	// Empty for now
@@ -2120,16 +2123,17 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
	}
	buildComplianceMetadataProvider(ctx, m)

	commonData := CommonPropertiesProviderData{
	commonData := CommonModuleInfo{
		ReplacedByPrebuilt:      m.commonProperties.ReplacedByPrebuilt,
		CompileTarget:           m.commonProperties.CompileTarget,
		SkipAndroidMkProcessing: shouldSkipAndroidMkProcessing(ctx, m),
	}
	if m.commonProperties.ForcedDisabled {
		commonData.Enabled = false
	} else {
		commonData.Enabled = m.commonProperties.Enabled.GetOrDefault(m.ConfigurableEvaluator(ctx), !m.Os().DefaultDisabled)
	}
	SetProvider(ctx, CommonPropertiesProviderKey, commonData)
	SetProvider(ctx, CommonModuleInfoKey, commonData)
	if p, ok := m.module.(PrebuiltInterface); ok && p.Prebuilt() != nil {
		SetProvider(ctx, PrebuiltModuleProviderKey, PrebuiltModuleProviderData{})
	}
@@ -2138,7 +2142,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
			HostToolPath: h.HostToolPath()})
	}

	if p, ok := m.module.(AndroidMkProviderInfoProducer); ok && !shouldSkipAndroidMkProcessing(ctx, m) {
	if p, ok := m.module.(AndroidMkProviderInfoProducer); ok && !commonData.SkipAndroidMkProcessing {
		SetProvider(ctx, AndroidMkInfoProvider, p.PrepareAndroidMKProviderInfo(ctx.Config()))
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag
	if module == nil {
		return nil, missingDependencyError{[]string{moduleName}}
	}
	if !OtherModuleProviderOrDefault(ctx, *module, CommonPropertiesProviderKey).Enabled {
	if !OtherModuleProviderOrDefault(ctx, *module, CommonModuleInfoKey).Enabled {
		return nil, missingDependencyError{[]string{moduleName}}
	}

+1 −1
Original line number Diff line number Diff line
@@ -381,7 +381,7 @@ func GetEmbeddedPrebuilt(module Module) *Prebuilt {
// the right module. This function is only safe to call after all TransitionMutators
// have run, e.g. in GenerateAndroidBuildActions.
func PrebuiltGetPreferred(ctx BaseModuleContext, module Module) Module {
	if !OtherModuleProviderOrDefault(ctx, module, CommonPropertiesProviderKey).ReplacedByPrebuilt {
	if !OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ReplacedByPrebuilt {
		return module
	}
	if _, ok := OtherModuleProvider(ctx, module, PrebuiltModuleProviderKey); ok {
+1 −1
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ func collectTidyObjModuleTargets(ctx android.SingletonContext, module android.Mo

	// (1) Collect all obj/tidy files into OS-specific groups.
	ctx.VisitAllModuleVariantProxies(module, func(variant android.ModuleProxy) {
		osName := android.OtherModuleProviderOrDefault(ctx, variant, android.CommonPropertiesProviderKey).CompileTarget.Os.Name
		osName := android.OtherModuleProviderOrDefault(ctx, variant, android.CommonModuleInfoKey).CompileTarget.Os.Name
		info := android.OtherModuleProviderOrDefault(ctx, variant, CcObjectInfoProvider)
		addToOSGroup(osName, info.objFiles, allObjFileGroups, subsetObjFileGroups)
		addToOSGroup(osName, info.tidyFiles, allTidyFileGroups, subsetTidyFileGroups)
Loading