Enable variants of bootstrap modules

The primary builder may want to create variants of bootstrap
modules if they need to fit in to the primary builder's dependency
graph.  Enable arbitrary variants of bootstrap modules by only
running the module's actions on the primary variant and then
copying the result to any other variants that exist.

Test: m checkbuild
Change-Id: I24b97771bb11faeacab4079ed8cf69aef59da140
This commit is contained in:
Colin Cross 2020-09-09 13:03:57 -07:00
parent 18926521dc
commit d2458a23bf

View file

@ -180,8 +180,10 @@ func toolDir(config interface{}) string {
func pluginDeps(ctx blueprint.BottomUpMutatorContext) { func pluginDeps(ctx blueprint.BottomUpMutatorContext) {
if pkg, ok := ctx.Module().(*goPackage); ok { if pkg, ok := ctx.Module().(*goPackage); ok {
for _, plugin := range pkg.properties.PluginFor { if ctx.PrimaryModule() == ctx.Module() {
ctx.AddReverseDependency(ctx.Module(), nil, plugin) for _, plugin := range pkg.properties.PluginFor {
ctx.AddReverseDependency(ctx.Module(), nil, plugin)
}
} }
} }
} }
@ -211,7 +213,7 @@ func isGoPluginFor(name string) func(blueprint.Module) bool {
} }
} }
func isBootstrapModule(module blueprint.Module) bool { func IsBootstrapModule(module blueprint.Module) bool {
_, isPackage := module.(*goPackage) _, isPackage := module.(*goPackage)
_, isBinary := module.(*goBinary) _, isBinary := module.(*goBinary)
return isPackage || isBinary return isPackage || isBinary
@ -268,6 +270,9 @@ func newGoPackageModuleFactory(config *Config) func() (blueprint.Module, []inter
} }
func (g *goPackage) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { func (g *goPackage) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
if ctx.Module() != ctx.PrimaryModule() {
return nil
}
return g.properties.Deps return g.properties.Deps
} }
@ -297,6 +302,16 @@ func (g *goPackage) IsPluginFor(name string) bool {
} }
func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) {
// Allow the primary builder to create multiple variants. Any variants after the first
// will copy outputs from the first.
if ctx.Module() != ctx.PrimaryModule() {
primary := ctx.PrimaryModule().(*goPackage)
g.pkgRoot = primary.pkgRoot
g.archiveFile = primary.archiveFile
g.testResultFile = primary.testResultFile
return
}
var ( var (
name = ctx.ModuleName() name = ctx.ModuleName()
hasPlugins = false hasPlugins = false
@ -386,6 +401,9 @@ func newGoBinaryModuleFactory(config *Config, tooldir bool) func() (blueprint.Mo
} }
func (g *goBinary) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { func (g *goBinary) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
if ctx.Module() != ctx.PrimaryModule() {
return nil
}
return g.properties.Deps return g.properties.Deps
} }
@ -395,6 +413,14 @@ func (g *goBinary) InstallPath() string {
} }
func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
// Allow the primary builder to create multiple variants. Any variants after the first
// will copy outputs from the first.
if ctx.Module() != ctx.PrimaryModule() {
primary := ctx.PrimaryModule().(*goBinary)
g.installPath = primary.installPath
return
}
var ( var (
name = ctx.ModuleName() name = ctx.ModuleName()
objDir = moduleObjDir(ctx, g.config) objDir = moduleObjDir(ctx, g.config)
@ -653,13 +679,15 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
var blueprintTools []string var blueprintTools []string
ctx.VisitAllModulesIf(isBootstrapBinaryModule, ctx.VisitAllModulesIf(isBootstrapBinaryModule,
func(module blueprint.Module) { func(module blueprint.Module) {
binaryModule := module.(*goBinary) if ctx.PrimaryModule(module) == module {
binaryModule := module.(*goBinary)
if binaryModule.properties.Tool_dir { if binaryModule.properties.Tool_dir {
blueprintTools = append(blueprintTools, binaryModule.InstallPath()) blueprintTools = append(blueprintTools, binaryModule.InstallPath())
} }
if binaryModule.properties.PrimaryBuilder { if binaryModule.properties.PrimaryBuilder {
primaryBuilders = append(primaryBuilders, binaryModule) primaryBuilders = append(primaryBuilders, binaryModule)
}
} }
}) })