Expose build-globs.ninja write function to android/soong. am: 8979d4c54c
am: a8b7ca3812
am: 8d49ffc799
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1794227 Change-Id: I364aca5bb983252635271d50a4c2863ba699a769
This commit is contained in:
commit
cdb1e3e267
2 changed files with 22 additions and 16 deletions
|
@ -208,7 +208,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(bootstrapConfig, ctx))
|
ctx.RegisterSingletonType("glob", globSingletonFactory(stage, 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,15 +273,7 @@ func RunBlueprint(args Args, ctx *blueprint.Context, config interface{}) []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.GlobFile != "" {
|
if args.GlobFile != "" {
|
||||||
buffer, errs := generateGlobNinjaFile(bootstrapConfig, config, ctx.Globs)
|
WriteBuildGlobsNinjaFile(stage, ctx, args, config)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ctx.WriteBuildFile(out)
|
err = ctx.WriteBuildFile(out)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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
|
// 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 {
|
||||||
config *Config
|
stage Stage
|
||||||
globLister func() pathtools.MultipleGlobResults
|
globLister func() pathtools.MultipleGlobResults
|
||||||
writeRule bool
|
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 func() blueprint.Singleton {
|
||||||
return &globSingleton{
|
return &globSingleton{
|
||||||
config: config,
|
stage: stage,
|
||||||
globLister: ctx.Globs,
|
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
|
// The directory for the intermediates needs to be different for bootstrap and the primary
|
||||||
// builder.
|
// builder.
|
||||||
globsDir := globsDir(ctx.Config().(BootstrapConfig), s.config.stage)
|
globsDir := globsDir(ctx.Config().(BootstrapConfig), s.stage)
|
||||||
|
|
||||||
for i, globs := range globBuckets {
|
for i, globs := range globBuckets {
|
||||||
fileListFile := filepath.Join(globsDir, strconv.Itoa(i))
|
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) {
|
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{
|
||||||
config: bootstrapConfig,
|
stage: stage,
|
||||||
globLister: globLister,
|
globLister: globLister,
|
||||||
writeRule: true,
|
writeRule: true,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue