diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 93fcb65..73ea502 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -742,9 +742,11 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { primaryBuilderFile := filepath.Join("$BinDir", primaryBuilderName) ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}") - if s.config.stage == StagePrimary { - ctx.AddSubninja(s.config.globFile) + for _, subninja := range s.config.subninjas { + ctx.AddSubninja(subninja) + } + if s.config.stage == StagePrimary { for _, i := range s.config.primaryBuilderInvocations { flags := make([]string, 0) flags = append(flags, primaryBuilderCmdlinePrefix...) @@ -759,6 +761,7 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { "builder": primaryBuilderFile, "extra": strings.Join(flags, " "), }, + Optional: true, }) } } diff --git a/bootstrap/command.go b/bootstrap/command.go index b2e229d..d352d52 100644 --- a/bootstrap/command.go +++ b/bootstrap/command.go @@ -33,7 +33,9 @@ import ( type Args struct { OutFile string + Subninjas []string GlobFile string + GlobListDir string DepFile string DocFile string Cpuprofile string @@ -62,6 +64,7 @@ var ( func init() { flag.StringVar(&CmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output") flag.StringVar(&CmdlineArgs.GlobFile, "globFile", "build-globs.ninja", "the Ninja file of globs to output") + flag.StringVar(&CmdlineArgs.GlobListDir, "globListDir", "", "the directory containing the glob list files") flag.StringVar(&CmdlineArgs.BuildDir, "b", ".", "the build output directory") flag.StringVar(&CmdlineArgs.NinjaBuildDir, "n", "", "the ninja builddir directory") flag.StringVar(&CmdlineArgs.DepFile, "d", "", "the dependency file to output") @@ -94,7 +97,7 @@ func Main(ctx *blueprint.Context, config interface{}, generatingPrimaryBuilder b } } -func PrimaryBuilderExtraFlags(args Args, globFile, mainNinjaFile string) []string { +func PrimaryBuilderExtraFlags(args Args, mainNinjaFile string) []string { result := make([]string, 0) if args.RunGoTests { @@ -102,7 +105,6 @@ func PrimaryBuilderExtraFlags(args Args, globFile, mainNinjaFile string) []strin } result = append(result, "-l", args.ModuleListFile) - result = append(result, "-globFile", globFile) result = append(result, "-o", mainNinjaFile) if args.EmptyNinjaFile { @@ -174,7 +176,6 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin stage = StagePrimary } - primaryBuilderNinjaGlobFile := absolutePath(filepath.Join(args.BuildDir, bootstrapSubDir, "build-globs.ninja")) mainNinjaFile := filepath.Join("$buildDir", "build.ninja") var invocations []PrimaryBuilderInvocation @@ -182,7 +183,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin if args.PrimaryBuilderInvocations != nil { invocations = args.PrimaryBuilderInvocations } else { - primaryBuilderArgs := PrimaryBuilderExtraFlags(args, primaryBuilderNinjaGlobFile, mainNinjaFile) + primaryBuilderArgs := PrimaryBuilderExtraFlags(args, mainNinjaFile) primaryBuilderArgs = append(primaryBuilderArgs, args.TopFile) invocations = []PrimaryBuilderInvocation{{ @@ -196,7 +197,8 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin stage: stage, topLevelBlueprintsFile: args.TopFile, - globFile: primaryBuilderNinjaGlobFile, + subninjas: args.Subninjas, + globListDir: args.GlobListDir, runGoTests: args.RunGoTests, useValidations: args.UseValidations, primaryBuilderInvocations: invocations, @@ -208,7 +210,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin ctx.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory(bootstrapConfig, true)) ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig)) - ctx.RegisterSingletonType("glob", globSingletonFactory(stage, ctx)) + ctx.RegisterSingletonType("glob", globSingletonFactory(bootstrapConfig.globListDir, ctx)) blueprintFiles, errs := ctx.ParseFileList(filepath.Dir(args.TopFile), filesToParse, config) if len(errs) > 0 { @@ -273,7 +275,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin } if args.GlobFile != "" { - WriteBuildGlobsNinjaFile(stage, ctx, args, config) + WriteBuildGlobsNinjaFile(args.GlobListDir, ctx, args, config) } err = ctx.WriteBuildFile(out) diff --git a/bootstrap/config.go b/bootstrap/config.go index a29ba76..7ab1ea2 100644 --- a/bootstrap/config.go +++ b/bootstrap/config.go @@ -133,7 +133,8 @@ type Config struct { stage Stage topLevelBlueprintsFile string - globFile string + subninjas []string + globListDir string runGoTests bool useValidations bool diff --git a/bootstrap/glob.go b/bootstrap/glob.go index be3fe97..c843ae1 100644 --- a/bootstrap/glob.go +++ b/bootstrap/glob.go @@ -149,16 +149,16 @@ func joinWithPrefixAndQuote(strs []string, prefix string) string { // re-evaluate them whenever the contents of the searched directories change, and retrigger the // primary builder if the results change. type globSingleton struct { - stage Stage - globLister func() pathtools.MultipleGlobResults - writeRule bool + globListDir string + globLister func() pathtools.MultipleGlobResults + writeRule bool } -func globSingletonFactory(stage Stage, ctx *blueprint.Context) func() blueprint.Singleton { +func globSingletonFactory(globListDir string, ctx *blueprint.Context) func() blueprint.Singleton { return func() blueprint.Singleton { return &globSingleton{ - stage: stage, - globLister: ctx.Globs, + globListDir: globListDir, + globLister: ctx.Globs, } } } @@ -174,7 +174,7 @@ func (s *globSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { // The directory for the intermediates needs to be different for bootstrap and the primary // builder. - globsDir := globsDir(ctx.Config().(BootstrapConfig), s.stage) + globsDir := globsDir(ctx.Config().(BootstrapConfig), s.globListDir) for i, globs := range globBuckets { fileListFile := filepath.Join(globsDir, strconv.Itoa(i)) @@ -206,8 +206,8 @@ func (s *globSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { } } -func WriteBuildGlobsNinjaFile(stage Stage, ctx *blueprint.Context, args Args, config interface{}) { - buffer, errs := generateGlobNinjaFile(stage, config, ctx.Globs) +func WriteBuildGlobsNinjaFile(globListDir string, ctx *blueprint.Context, args Args, config interface{}) { + buffer, errs := generateGlobNinjaFile(globListDir, config, ctx.Globs) if len(errs) > 0 { fatalErrors(errs) } @@ -218,16 +218,15 @@ func WriteBuildGlobsNinjaFile(stage Stage, ctx *blueprint.Context, args Args, co fatalf("error writing %s: %s", args.GlobFile, err) } } - -func generateGlobNinjaFile(stage Stage, config interface{}, +func generateGlobNinjaFile(globListDir string, config interface{}, globLister func() pathtools.MultipleGlobResults) ([]byte, []error) { ctx := blueprint.NewContext() ctx.RegisterSingletonType("glob", func() blueprint.Singleton { return &globSingleton{ - stage: stage, - globLister: globLister, - writeRule: true, + globListDir: globListDir, + globLister: globLister, + writeRule: true, } }) @@ -258,18 +257,14 @@ func generateGlobNinjaFile(stage Stage, config interface{}, // globsDir returns a different directory to store glob intermediates for the bootstrap and // primary builder executions. -func globsDir(config BootstrapConfig, stage Stage) string { +func globsDir(config BootstrapConfig, globsDir string) string { buildDir := config.BuildDir() - if stage == StageMain { - return filepath.Join(buildDir, mainSubDir, "globs") - } else { - return filepath.Join(buildDir, bootstrapSubDir, "globs") - } + return filepath.Join(buildDir, bootstrapSubDir, globsDir) } // GlobFileListFiles returns the list of sharded glob file list files for the main stage. -func GlobFileListFiles(config BootstrapConfig) []string { - globsDir := globsDir(config, StageMain) +func GlobFileListFiles(config BootstrapConfig, globListDir string) []string { + globsDir := globsDir(config, globListDir) var fileListFiles []string for i := 0; i < numGlobBuckets; i++ { fileListFiles = append(fileListFiles, filepath.Join(globsDir, strconv.Itoa(i)))