Separate the concept of subninjas and glob files.

This makes the distinction between what the bootstrap .ninja file and
the main .ninja files do clearer: the bootstrap .ninja file includes the
build-globs.ninja file(s) which the main .ninja file writes.

This required removing the "default" statement from said bootstrap
.ninja file: now we can build more than one thing instead of just
build.ninja and thus soong_ui explicitly tells Ninja what to do instead.

On the side, stop catering for the use case where the bootstrap
Blueprint invocation uses globs: Soong's does not and that's our only
use case.

Test: Presubmits.

Change-Id: Icffce31928242cfe9cdab56b290a37598d32a58c
This commit is contained in:
Lukacs T. Berki 2021-08-12 15:29:03 +02:00
parent 8979d4c54c
commit d3a0637702
4 changed files with 33 additions and 32 deletions

View file

@ -742,9 +742,11 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
primaryBuilderFile := filepath.Join("$BinDir", primaryBuilderName) primaryBuilderFile := filepath.Join("$BinDir", primaryBuilderName)
ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}") ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}")
if s.config.stage == StagePrimary { for _, subninja := range s.config.subninjas {
ctx.AddSubninja(s.config.globFile) ctx.AddSubninja(subninja)
}
if s.config.stage == StagePrimary {
for _, i := range s.config.primaryBuilderInvocations { for _, i := range s.config.primaryBuilderInvocations {
flags := make([]string, 0) flags := make([]string, 0)
flags = append(flags, primaryBuilderCmdlinePrefix...) flags = append(flags, primaryBuilderCmdlinePrefix...)
@ -759,6 +761,7 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
"builder": primaryBuilderFile, "builder": primaryBuilderFile,
"extra": strings.Join(flags, " "), "extra": strings.Join(flags, " "),
}, },
Optional: true,
}) })
} }
} }

View file

@ -33,7 +33,9 @@ import (
type Args struct { type Args struct {
OutFile string OutFile string
Subninjas []string
GlobFile string GlobFile string
GlobListDir string
DepFile string DepFile string
DocFile string DocFile string
Cpuprofile string Cpuprofile string
@ -62,6 +64,7 @@ var (
func init() { func init() {
flag.StringVar(&CmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output") 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.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.BuildDir, "b", ".", "the build output directory")
flag.StringVar(&CmdlineArgs.NinjaBuildDir, "n", "", "the ninja builddir directory") flag.StringVar(&CmdlineArgs.NinjaBuildDir, "n", "", "the ninja builddir directory")
flag.StringVar(&CmdlineArgs.DepFile, "d", "", "the dependency file to output") 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) result := make([]string, 0)
if args.RunGoTests { if args.RunGoTests {
@ -102,7 +105,6 @@ func PrimaryBuilderExtraFlags(args Args, globFile, mainNinjaFile string) []strin
} }
result = append(result, "-l", args.ModuleListFile) result = append(result, "-l", args.ModuleListFile)
result = append(result, "-globFile", globFile)
result = append(result, "-o", mainNinjaFile) result = append(result, "-o", mainNinjaFile)
if args.EmptyNinjaFile { if args.EmptyNinjaFile {
@ -174,7 +176,6 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
stage = StagePrimary stage = StagePrimary
} }
primaryBuilderNinjaGlobFile := absolutePath(filepath.Join(args.BuildDir, bootstrapSubDir, "build-globs.ninja"))
mainNinjaFile := filepath.Join("$buildDir", "build.ninja") mainNinjaFile := filepath.Join("$buildDir", "build.ninja")
var invocations []PrimaryBuilderInvocation var invocations []PrimaryBuilderInvocation
@ -182,7 +183,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
if args.PrimaryBuilderInvocations != nil { if args.PrimaryBuilderInvocations != nil {
invocations = args.PrimaryBuilderInvocations invocations = args.PrimaryBuilderInvocations
} else { } else {
primaryBuilderArgs := PrimaryBuilderExtraFlags(args, primaryBuilderNinjaGlobFile, mainNinjaFile) primaryBuilderArgs := PrimaryBuilderExtraFlags(args, mainNinjaFile)
primaryBuilderArgs = append(primaryBuilderArgs, args.TopFile) primaryBuilderArgs = append(primaryBuilderArgs, args.TopFile)
invocations = []PrimaryBuilderInvocation{{ invocations = []PrimaryBuilderInvocation{{
@ -196,7 +197,8 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
stage: stage, stage: stage,
topLevelBlueprintsFile: args.TopFile, topLevelBlueprintsFile: args.TopFile,
globFile: primaryBuilderNinjaGlobFile, subninjas: args.Subninjas,
globListDir: args.GlobListDir,
runGoTests: args.RunGoTests, runGoTests: args.RunGoTests,
useValidations: args.UseValidations, useValidations: args.UseValidations,
primaryBuilderInvocations: invocations, 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.RegisterModuleType("blueprint_go_binary", newGoBinaryModuleFactory(bootstrapConfig, true))
ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig)) 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) blueprintFiles, errs := ctx.ParseFileList(filepath.Dir(args.TopFile), filesToParse, config)
if len(errs) > 0 { if len(errs) > 0 {
@ -273,7 +275,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
} }
if args.GlobFile != "" { if args.GlobFile != "" {
WriteBuildGlobsNinjaFile(stage, ctx, args, config) WriteBuildGlobsNinjaFile(args.GlobListDir, ctx, args, config)
} }
err = ctx.WriteBuildFile(out) err = ctx.WriteBuildFile(out)

View file

@ -133,7 +133,8 @@ type Config struct {
stage Stage stage Stage
topLevelBlueprintsFile string topLevelBlueprintsFile string
globFile string subninjas []string
globListDir string
runGoTests bool runGoTests bool
useValidations bool useValidations bool

View file

@ -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 // re-evaluate them whenever the contents of the searched directories change, and retrigger the
// primary builder if the results change. // primary builder if the results change.
type globSingleton struct { type globSingleton struct {
stage Stage globListDir string
globLister func() pathtools.MultipleGlobResults globLister func() pathtools.MultipleGlobResults
writeRule bool 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 func() blueprint.Singleton {
return &globSingleton{ return &globSingleton{
stage: stage, globListDir: globListDir,
globLister: ctx.Globs, 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 // The directory for the intermediates needs to be different for bootstrap and the primary
// builder. // builder.
globsDir := globsDir(ctx.Config().(BootstrapConfig), s.stage) globsDir := globsDir(ctx.Config().(BootstrapConfig), s.globListDir)
for i, globs := range globBuckets { for i, globs := range globBuckets {
fileListFile := filepath.Join(globsDir, strconv.Itoa(i)) 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{}) { func WriteBuildGlobsNinjaFile(globListDir string, ctx *blueprint.Context, args Args, config interface{}) {
buffer, errs := generateGlobNinjaFile(stage, config, ctx.Globs) buffer, errs := generateGlobNinjaFile(globListDir, config, ctx.Globs)
if len(errs) > 0 { if len(errs) > 0 {
fatalErrors(errs) fatalErrors(errs)
} }
@ -218,16 +218,15 @@ func WriteBuildGlobsNinjaFile(stage Stage, ctx *blueprint.Context, args Args, co
fatalf("error writing %s: %s", args.GlobFile, err) fatalf("error writing %s: %s", args.GlobFile, err)
} }
} }
func generateGlobNinjaFile(globListDir string, config interface{},
func generateGlobNinjaFile(stage Stage, config interface{},
globLister func() pathtools.MultipleGlobResults) ([]byte, []error) { globLister func() pathtools.MultipleGlobResults) ([]byte, []error) {
ctx := blueprint.NewContext() ctx := blueprint.NewContext()
ctx.RegisterSingletonType("glob", func() blueprint.Singleton { ctx.RegisterSingletonType("glob", func() blueprint.Singleton {
return &globSingleton{ return &globSingleton{
stage: stage, globListDir: globListDir,
globLister: globLister, globLister: globLister,
writeRule: true, 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 // globsDir returns a different directory to store glob intermediates for the bootstrap and
// primary builder executions. // primary builder executions.
func globsDir(config BootstrapConfig, stage Stage) string { func globsDir(config BootstrapConfig, globsDir string) string {
buildDir := config.BuildDir() buildDir := config.BuildDir()
if stage == StageMain { return filepath.Join(buildDir, bootstrapSubDir, globsDir)
return filepath.Join(buildDir, mainSubDir, "globs")
} else {
return filepath.Join(buildDir, bootstrapSubDir, "globs")
}
} }
// GlobFileListFiles returns the list of sharded glob file list files for the main stage. // GlobFileListFiles returns the list of sharded glob file list files for the main stage.
func GlobFileListFiles(config BootstrapConfig) []string { func GlobFileListFiles(config BootstrapConfig, globListDir string) []string {
globsDir := globsDir(config, StageMain) globsDir := globsDir(config, globListDir)
var fileListFiles []string var fileListFiles []string
for i := 0; i < numGlobBuckets; i++ { for i := 0; i < numGlobBuckets; i++ {
fileListFiles = append(fileListFiles, filepath.Join(globsDir, strconv.Itoa(i))) fileListFiles = append(fileListFiles, filepath.Join(globsDir, strconv.Itoa(i)))