Expose build-globs.ninja write function to android/soong. am: 8979d4c54c

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1794227

Change-Id: I49abb29bd1f36146b414be3add8026269531ccb6
This commit is contained in:
Jingwen Chen 2021-08-12 14:24:23 +00:00 committed by Automerger Merge Worker
commit a8b7ca3812
2 changed files with 22 additions and 16 deletions

View file

@ -208,7 +208,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(bootstrapConfig, ctx))
ctx.RegisterSingletonType("glob", globSingletonFactory(stage, ctx))
blueprintFiles, errs := ctx.ParseFileList(filepath.Dir(args.TopFile), filesToParse, config)
if len(errs) > 0 {
@ -273,15 +273,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
}
if args.GlobFile != "" {
buffer, errs := generateGlobNinjaFile(bootstrapConfig, config, ctx.Globs)
if len(errs) > 0 {
fatalErrors(errs)
}
err = ioutil.WriteFile(absolutePath(args.GlobFile), buffer, outFilePermissions)
if err != nil {
fatalf("error writing %s: %s", args.GlobFile, err)
}
WriteBuildGlobsNinjaFile(stage, ctx, args, config)
}
err = ctx.WriteBuildFile(out)

View file

@ -19,6 +19,7 @@ import (
"fmt"
"hash/fnv"
"io"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
@ -148,15 +149,15 @@ 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 {
config *Config
stage Stage
globLister func() pathtools.MultipleGlobResults
writeRule bool
}
func globSingletonFactory(config *Config, ctx *blueprint.Context) func() blueprint.Singleton {
func globSingletonFactory(stage Stage, ctx *blueprint.Context) func() blueprint.Singleton {
return func() blueprint.Singleton {
return &globSingleton{
config: config,
stage: stage,
globLister: ctx.Globs,
}
}
@ -173,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.config.stage)
globsDir := globsDir(ctx.Config().(BootstrapConfig), s.stage)
for i, globs := range globBuckets {
fileListFile := filepath.Join(globsDir, strconv.Itoa(i))
@ -205,13 +206,26 @@ func (s *globSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
}
}
func generateGlobNinjaFile(bootstrapConfig *Config, config interface{},
func WriteBuildGlobsNinjaFile(stage Stage, ctx *blueprint.Context, args Args, config interface{}) {
buffer, errs := generateGlobNinjaFile(stage, config, ctx.Globs)
if len(errs) > 0 {
fatalErrors(errs)
}
const outFilePermissions = 0666
err := ioutil.WriteFile(absolutePath(args.GlobFile), buffer, outFilePermissions)
if err != nil {
fatalf("error writing %s: %s", args.GlobFile, err)
}
}
func generateGlobNinjaFile(stage Stage, config interface{},
globLister func() pathtools.MultipleGlobResults) ([]byte, []error) {
ctx := blueprint.NewContext()
ctx.RegisterSingletonType("glob", func() blueprint.Singleton {
return &globSingleton{
config: bootstrapConfig,
stage: stage,
globLister: globLister,
writeRule: true,
}