Move bpglob out of ToolDir

ToolDir is going to become unstable when switching between KatiEnabled
and Soong-only builds while the duplication between out/soong/host and
out/host is resolved.  bpglob gets executed very early during bootstrap,
before the primary builder has run to update the paths to match the
current configuration.  Move it into SoongOutDir() so that its path
is more stable.

The copy of bpglob in ToolDir is still used when bpglob is used by the
primary builder through bootstrap.GlobFile.

Bug: 204136549
Test: m nothing
Change-Id: Ida51997b6408d7c265f3ba343278e5e2968467d3
This commit is contained in:
Colin Cross 2021-10-29 13:09:09 -07:00
parent 0e306e7a89
commit 37d151ff95
2 changed files with 27 additions and 7 deletions

View file

@ -149,6 +149,13 @@ var (
},
"depfile")
noop = pctx.StaticRule("noop",
blueprint.RuleParams{
Command: "true",
Description: "noop",
Restat: true,
})
_ = pctx.VariableFunc("ToolDir", func(config interface{}) (string, error) {
return config.(BootstrapConfig).HostToolDir(), nil
})
@ -709,6 +716,13 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Inputs: blueprintGoPackages,
Optional: true,
})
// out/soong/bpglob is built by microfactory before any ninja runs, write a rule that
// convinces ninja that it has been built to avoid tripping Soong's dangling rules check.
ctx.Build(pctx, blueprint.BuildParams{
Rule: noop,
Outputs: []string{"$bootstrapGlobCmd"},
})
}
// packageRoot returns the module-specific package root directory path. This

View file

@ -44,22 +44,26 @@ import (
// in a build failure with a "missing and no known rule to make it" error.
var (
globCmd = filepath.Join("$ToolDir", "bpglob")
_ = pctx.VariableFunc("bootstrapGlobCmd", func(config interface{}) (string, error) {
return filepath.Join(config.(BootstrapConfig).SoongOutDir(), "bpglob"), nil
})
_ = pctx.StaticVariable("primaryBuilderGlobCmd", filepath.Join("$ToolDir", "bpglob"))
// globRule rule traverses directories to produce a list of files that match $glob
// and writes it to $out if it has changed, and writes the directories to $out.d
GlobRule = pctx.StaticRule("GlobRule",
blueprint.RuleParams{
Command: fmt.Sprintf(`%s -o $out -v %d $args`,
globCmd, pathtools.BPGlobArgumentVersion),
CommandDeps: []string{globCmd},
Command: fmt.Sprintf(`$globCmd -o $out -v %d $args`,
pathtools.BPGlobArgumentVersion),
CommandDeps: []string{"$globCmd"},
Description: "glob",
Restat: true,
Deps: blueprint.DepsGCC,
Depfile: "$out.d",
},
"args")
"args", "globCmd")
)
// GlobFileContext is the subset of ModuleContext and SingletonContext needed by GlobFile
@ -81,7 +85,8 @@ func GlobFile(ctx GlobFileContext, pattern string, excludes []string, fileListFi
Rule: GlobRule,
Outputs: []string{fileListFile},
Args: map[string]string{
"args": args,
"args": args,
"globCmd": "$primaryBuilderGlobCmd",
},
Description: "glob " + pattern,
})
@ -112,7 +117,8 @@ func multipleGlobFilesRule(ctx GlobFileContext, fileListFile string, shard int,
Rule: GlobRule,
Outputs: []string{fileListFile},
Args: map[string]string{
"args": args.String(),
"args": args.String(),
"globCmd": "$bootstrapGlobCmd",
},
Description: fmt.Sprintf("regenerate globs shard %d of %d", shard, numGlobBuckets),
})