From d782b504e0939970c4f542a5e0a6a86f1b4eedd4 Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Thu, 2 Sep 2021 09:57:30 +0200 Subject: [PATCH] Remove the bootstrap.Config class. It was confusing because there are two concepts with the same name: thebootstrapping config special-cased in the bootstrap modules / singletons and the "global" config. This change folds the first into the second. A further next step would be to split the Go parts and the Ninja parts (subninjas + primary builder invocation) apart, but at some point, I should stop gold-plating this. Test: Presubmits. Change-Id: Id341dee664a9d2527535f4f9980e5f0d10139eef --- bootstrap/bootstrap.go | 52 +++++++++++++----------------------------- bootstrap/command.go | 29 +++-------------------- bootstrap/config.go | 18 +++++++-------- 3 files changed, 28 insertions(+), 71 deletions(-) diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 65d0147..1f261e1 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -236,18 +236,13 @@ type goPackage struct { // The path of the test result file. testResultFile []string - - // The bootstrap Config - config *Config } var _ goPackageProducer = (*goPackage)(nil) -func newGoPackageModuleFactory(config *Config) func() (blueprint.Module, []interface{}) { +func newGoPackageModuleFactory() func() (blueprint.Module, []interface{}) { return func() (blueprint.Module, []interface{}) { - module := &goPackage{ - config: config, - } + module := &goPackage{} return module, []interface{}{&module.properties, &module.SimpleName.Properties} } } @@ -331,12 +326,11 @@ func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { testSrcs = append(g.properties.TestSrcs, g.properties.Linux.TestSrcs...) } - if g.config.runGoTests { + if ctx.Config().(BootstrapConfig).RunGoTests() { testArchiveFile := filepath.Join(testRoot(ctx), filepath.FromSlash(g.properties.PkgPath)+".a") g.testResultFile = buildGoTest(ctx, testRoot(ctx), testArchiveFile, - g.properties.PkgPath, srcs, genSrcs, - testSrcs, g.config.useValidations) + g.properties.PkgPath, srcs, genSrcs, testSrcs) } // Don't build for test-only packages @@ -371,24 +365,16 @@ type goBinary struct { Srcs []string TestSrcs []string } - - Tool_dir bool `blueprint:"mutated"` } installPath string - - // The bootstrap Config - config *Config } var _ GoBinaryTool = (*goBinary)(nil) -func newGoBinaryModuleFactory(config *Config, tooldir bool) func() (blueprint.Module, []interface{}) { +func newGoBinaryModuleFactory() func() (blueprint.Module, []interface{}) { return func() (blueprint.Module, []interface{}) { - module := &goBinary{ - config: config, - } - module.properties.Tool_dir = tooldir + module := &goBinary{} return module, []interface{}{&module.properties, &module.SimpleName.Properties} } } @@ -448,9 +434,9 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { testSrcs = append(g.properties.TestSrcs, g.properties.Linux.TestSrcs...) } - if g.config.runGoTests { + if ctx.Config().(BootstrapConfig).RunGoTests() { testDeps = buildGoTest(ctx, testRoot(ctx), testArchiveFile, - name, srcs, genSrcs, testSrcs, g.config.useValidations) + name, srcs, genSrcs, testSrcs) } buildGoPackage(ctx, objDir, "main", archiveFile, srcs, genSrcs) @@ -481,7 +467,7 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { }) var orderOnlyDeps, validationDeps []string - if g.config.useValidations { + if ctx.Config().(BootstrapConfig).UseValidationsForGoTests() { validationDeps = testDeps } else { orderOnlyDeps = testDeps @@ -558,7 +544,7 @@ func buildGoPackage(ctx blueprint.ModuleContext, pkgRoot string, } func buildGoTest(ctx blueprint.ModuleContext, testRoot, testPkgArchive, - pkgPath string, srcs, genSrcs, testSrcs []string, useValidations bool) []string { + pkgPath string, srcs, genSrcs, testSrcs []string) []string { if len(testSrcs) == 0 { return nil @@ -621,7 +607,7 @@ func buildGoTest(ctx blueprint.ModuleContext, testRoot, testPkgArchive, }) var orderOnlyDeps, validationDeps []string - if useValidations { + if ctx.Config().(BootstrapConfig).UseValidationsForGoTests() { validationDeps = testDeps } else { orderOnlyDeps = testDeps @@ -644,15 +630,11 @@ func buildGoTest(ctx blueprint.ModuleContext, testRoot, testPkgArchive, } type singleton struct { - // The bootstrap Config - config *Config } -func newSingletonFactory(config *Config) func() blueprint.Singleton { +func newSingletonFactory() func() blueprint.Singleton { return func() blueprint.Singleton { - return &singleton{ - config: config, - } + return &singleton{} } } @@ -669,9 +651,7 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { func(module blueprint.Module) { if ctx.PrimaryModule(module) == module { if binaryModule, ok := module.(*goBinary); ok { - if binaryModule.properties.Tool_dir { - blueprintTools = append(blueprintTools, binaryModule.InstallPath()) - } + blueprintTools = append(blueprintTools, binaryModule.InstallPath()) if binaryModule.properties.PrimaryBuilder { primaryBuilders = append(primaryBuilders, binaryModule) } @@ -706,11 +686,11 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { primaryBuilderFile := filepath.Join("$ToolDir", primaryBuilderName) ctx.SetOutDir(pctx, "${outDir}") - for _, subninja := range s.config.subninjas { + for _, subninja := range ctx.Config().(BootstrapConfig).Subninjas() { ctx.AddSubninja(subninja) } - for _, i := range s.config.primaryBuilderInvocations { + for _, i := range ctx.Config().(BootstrapConfig).PrimaryBuilderInvocations() { flags := make([]string, 0) flags = append(flags, primaryBuilderCmdlinePrefix...) flags = append(flags, i.Args...) diff --git a/bootstrap/command.go b/bootstrap/command.go index f4eddc2..010f28f 100644 --- a/bootstrap/command.go +++ b/bootstrap/command.go @@ -122,33 +122,10 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin soongOutDir := config.(BootstrapConfig).SoongOutDir() - mainNinjaFile := filepath.Join("$soongOutDir", "build.ninja") - - var invocations []PrimaryBuilderInvocation - - if args.PrimaryBuilderInvocations != nil { - invocations = args.PrimaryBuilderInvocations - } else { - primaryBuilderArgs := PrimaryBuilderExtraFlags(args, mainNinjaFile) - - invocations = []PrimaryBuilderInvocation{{ - Inputs: []string{}, - Outputs: []string{mainNinjaFile}, - Args: primaryBuilderArgs, - }} - } - - bootstrapConfig := &Config{ - subninjas: args.Subninjas, - runGoTests: args.RunGoTests, - useValidations: args.UseValidations, - primaryBuilderInvocations: invocations, - } - ctx.RegisterBottomUpMutator("bootstrap_plugin_deps", pluginDeps) - ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModuleFactory(bootstrapConfig)) - ctx.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory(bootstrapConfig, true)) - ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig)) + ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModuleFactory()) + ctx.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory()) + ctx.RegisterSingletonType("bootstrap", newSingletonFactory()) blueprintFiles, errs := ctx.ParseFileList(".", filesToParse, config) if len(errs) > 0 { diff --git a/bootstrap/config.go b/bootstrap/config.go index 31d2f57..6d37eb5 100644 --- a/bootstrap/config.go +++ b/bootstrap/config.go @@ -88,6 +88,15 @@ type BootstrapConfig interface { // Whether to compile Go code in such a way that it can be debugged DebugCompilation() bool + + // Whether to run tests for Go code + RunGoTests() bool + + // Whether to use Ninja validations for running Go tests + UseValidationsForGoTests() bool + + Subninjas() []string + PrimaryBuilderInvocations() []PrimaryBuilderInvocation } type ConfigRemoveAbandonedFilesUnder interface { @@ -114,12 +123,3 @@ type PrimaryBuilderInvocation struct { Outputs []string Args []string } - -type Config struct { - subninjas []string - - runGoTests bool - useValidations bool - - primaryBuilderInvocations []PrimaryBuilderInvocation -}