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

Commit 648daea6 authored by Colin Cross's avatar Colin Cross
Browse files

Remove blueprint.Module helper functions

Now that blueprint_go_binary modules are wrapped in a module type
that implements android.Module Soong should never see a blueprint.Module.
Remove the versions of the context methods that allow working with
blueprint.Modules.

Genrules still need VisitDirectDepsAllowDisabled, as they use a hack
that adds dependencies on host tools after the prebuilts mutators have
run, which means they may have a dependency on a disabled prebuilt
and need to manually forward it to the corresponding source module.

Test: all soong tests pass
Flag: EXEMPT refactor
Change-Id: I9147b450269749326e8fe75c5af310bd2d898d8c
parent 87427354
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ func aconfigUpdateAndroidBuildActions(ctx ModuleContext) {
	mergedAconfigFiles := make(map[string]Paths)
	mergedModeInfos := make(map[string]ModeInfo)

	ctx.VisitDirectDepsIgnoreBlueprint(func(module Module) {
	ctx.VisitDirectDeps(func(module Module) {
		if aconfig_dep, ok := OtherModuleProvider(ctx, module, CodegenInfoProvider); ok && len(aconfig_dep.ModeInfos) > 0 {
			maps.Copy(mergedModeInfos, aconfig_dep.ModeInfos)
		}
+24 −66
Original line number Diff line number Diff line
@@ -113,31 +113,22 @@ type BaseModuleContext interface {
	// the first DependencyTag.
	GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)

	// VisitDirectDepsBlueprint calls visit for each direct dependency.  If there are multiple
	// direct dependencies on the same module visit will be called multiple times on that module
	// and OtherModuleDependencyTag will return a different tag for each.
	//
	// The Module passed to the visit function should not be retained outside of the visit
	// function, it may be invalidated by future mutators.
	VisitDirectDepsBlueprint(visit func(blueprint.Module))

	// VisitDirectDepsIgnoreBlueprint calls visit for each direct dependency.  If there are multiple
	// VisitDirectDeps calls visit for each direct dependency.  If there are multiple
	// direct dependencies on the same module visit will be called multiple times on that module
	// and OtherModuleDependencyTag will return a different tag for each.  It silently ignores any
	// dependencies that are not an android.Module.
	// and OtherModuleDependencyTag will return a different tag for each.  It raises an error if any of the
	// dependencies are disabled.
	//
	// The Module passed to the visit function should not be retained outside of the visit
	// function, it may be invalidated by future mutators.
	VisitDirectDepsIgnoreBlueprint(visit func(Module))
	VisitDirectDeps(visit func(Module))

	// VisitDirectDeps calls visit for each direct dependency.  If there are multiple
	// direct dependencies on the same module visit will be called multiple times on that module
	// and OtherModuleDependencyTag will return a different tag for each.  It raises an error if any of the
	// dependencies are not an android.Module.
	// and OtherModuleDependencyTag will return a different tag for each.
	//
	// The Module passed to the visit function should not be retained outside of the visit
	// function, it may be invalidated by future mutators.
	VisitDirectDeps(visit func(Module))
	VisitDirectDepsAllowDisabled(visit func(Module))

	VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))

@@ -164,17 +155,6 @@ type BaseModuleContext interface {
	// invalidated by future mutators.
	WalkDeps(visit func(child, parent Module) bool)

	// WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
	// tree in top down order.  visit may be called multiple times for the same (child, parent)
	// pair if there are multiple direct dependencies between the child and parent with different
	// tags.  OtherModuleDependencyTag will return the tag for the currently visited
	// (child, parent) pair.  If visit returns false WalkDeps will not continue recursing down
	// to child.
	//
	// The Modules passed to the visit function should not be retained outside of the visit function, they may be
	// invalidated by future mutators.
	WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)

	// GetWalkPath is supposed to be called in visit function passed in WalkDeps()
	// and returns a top-down dependency path from a start module to current child module.
	GetWalkPath() []Module
@@ -319,7 +299,7 @@ func (t AlwaysAllowDisabledModuleDependencyTag) AllowDisabledModuleDependency(Mo
	return true
}

func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool, ignoreBlueprint bool) Module {
func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
	aModule, _ := module.(Module)

	if !strict {
@@ -327,10 +307,7 @@ func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag b
	}

	if aModule == nil {
		if !ignoreBlueprint {
			b.ModuleErrorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)
		}
		return nil
		panic(fmt.Errorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag))
	}

	if !aModule.Enabled(b) {
@@ -353,15 +330,8 @@ type dep struct {

func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
	var deps []dep
	b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
		if aModule, _ := module.(Module); aModule != nil {
			if aModule.base().BaseModuleName() == name {
				returnedTag := b.bp.OtherModuleDependencyTag(aModule)
				if tag == nil || returnedTag == tag {
					deps = append(deps, dep{aModule, returnedTag})
				}
			}
		} else if b.bp.OtherModuleName(module) == name {
	b.VisitDirectDeps(func(module Module) {
		if module.base().BaseModuleName() == name {
			returnedTag := b.bp.OtherModuleDependencyTag(module)
			if tag == nil || returnedTag == tag {
				deps = append(deps, dep{module, returnedTag})
@@ -404,11 +374,9 @@ func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module,

func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
	var deps []Module
	b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
		if aModule, _ := module.(Module); aModule != nil {
			if b.bp.OtherModuleDependencyTag(aModule) == tag {
				deps = append(deps, aModule)
			}
	b.VisitDirectDeps(func(module Module) {
		if b.bp.OtherModuleDependencyTag(module) == tag {
			deps = append(deps, module)
		}
	})
	return deps
@@ -421,30 +389,24 @@ func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, bluepri
	return b.getDirectDepFirstTag(name)
}

func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
	b.bp.VisitDirectDeps(visit)
}

func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
	b.visitDirectDeps(visit, false)
	b.bp.VisitDirectDeps(func(module blueprint.Module) {
		if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
			visit(aModule)
		}

func (b *baseModuleContext) VisitDirectDepsIgnoreBlueprint(visit func(Module)) {
	b.visitDirectDeps(visit, true)
	})
}

func (b *baseModuleContext) visitDirectDeps(visit func(Module), ignoreBlueprint bool) {
func (b *baseModuleContext) VisitDirectDepsAllowDisabled(visit func(Module)) {
	b.bp.VisitDirectDeps(func(module blueprint.Module) {
		if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, ignoreBlueprint); aModule != nil {
			visit(aModule)
		}
		visit(module.(Module))
	})
}

func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
	b.bp.VisitDirectDeps(func(module blueprint.Module) {
		if b.bp.OtherModuleDependencyTag(module) == tag {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
				visit(aModule)
			}
		}
@@ -455,7 +417,7 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func
	b.bp.VisitDirectDepsIf(
		// pred
		func(module blueprint.Module) bool {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
				return pred(aModule)
			} else {
				return false
@@ -469,7 +431,7 @@ func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func

func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
	b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
		if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
		if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
			visit(aModule)
		}
	})
@@ -479,7 +441,7 @@ func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit
	b.bp.VisitDepsDepthFirstIf(
		// pred
		func(module blueprint.Module) bool {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps, false); aModule != nil {
			if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
				return pred(aModule)
			} else {
				return false
@@ -491,10 +453,6 @@ func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit
		})
}

func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
	b.bp.WalkDeps(visit)
}

func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
	b.walkPath = []Module{b.Module()}
	b.tagPath = []blueprint.DependencyTag{}
+1 −1
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ func setContainerInfo(ctx ModuleContext) {
func checkContainerViolations(ctx ModuleContext) {
	if _, ok := ctx.Module().(InstallableModule); ok {
		containersInfo, _ := getContainerModuleInfo(ctx, ctx.Module())
		ctx.VisitDirectDepsIgnoreBlueprint(func(dep Module) {
		ctx.VisitDirectDeps(func(dep Module) {
			if !dep.Enabled(ctx) {
				return
			}
+1 −5
Original line number Diff line number Diff line
@@ -63,11 +63,7 @@ func buildLicenseMetadata(ctx *moduleContext, licenseMetadataFile WritablePath)
	var allDepOutputFiles Paths
	var allDepMetadataDepSets []*DepSet[Path]

	ctx.VisitDirectDepsBlueprint(func(bpdep blueprint.Module) {
		dep, _ := bpdep.(Module)
		if dep == nil {
			return
		}
	ctx.VisitDirectDeps(func(dep Module) {
		if !dep.Enabled(ctx) {
			return
		}
+2 −4
Original line number Diff line number Diff line
@@ -1861,10 +1861,8 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)

	if m.Enabled(ctx) {
		// ensure all direct android.Module deps are enabled
		ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
			if m, ok := bm.(Module); ok {
				ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps, false)
			}
		ctx.VisitDirectDeps(func(m Module) {
			ctx.validateAndroidModule(m, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps)
		})

		if m.Device() {
Loading