Handle aquery build statements in a goroutine
Creation of build statements is largely parallelizable because each action is independent apart from updates/reads to depsetHashToArtifactPathsCache. Locally resulted in build statements taking ~.45 seconds on staging mode to ~.02 seconds Test: CI Change-Id: Iab00c8394a9eab17353f71230885ff0870e17f24
This commit is contained in:
@@ -188,7 +188,7 @@ type BazelContext interface {
|
||||
OutputBase() string
|
||||
|
||||
// Returns build statements which should get registered to reflect Bazel's outputs.
|
||||
BuildStatementsToRegister() []bazel.BuildStatement
|
||||
BuildStatementsToRegister() []*bazel.BuildStatement
|
||||
|
||||
// Returns the depsets defined in Bazel's aquery response.
|
||||
AqueryDepsets() []bazel.AqueryDepset
|
||||
@@ -222,7 +222,7 @@ type mixedBuildBazelContext struct {
|
||||
results map[cqueryKey]string // Results of cquery requests after Bazel invocations
|
||||
|
||||
// Build statements which should get registered to reflect Bazel's outputs.
|
||||
buildStatements []bazel.BuildStatement
|
||||
buildStatements []*bazel.BuildStatement
|
||||
|
||||
// Depsets which should be used for Bazel's build statements.
|
||||
depsets []bazel.AqueryDepset
|
||||
@@ -314,8 +314,8 @@ func (m MockBazelContext) IsModuleNameAllowed(_ string) bool {
|
||||
|
||||
func (m MockBazelContext) OutputBase() string { return m.OutputBaseDir }
|
||||
|
||||
func (m MockBazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
|
||||
return []bazel.BuildStatement{}
|
||||
func (m MockBazelContext) BuildStatementsToRegister() []*bazel.BuildStatement {
|
||||
return []*bazel.BuildStatement{}
|
||||
}
|
||||
|
||||
func (m MockBazelContext) AqueryDepsets() []bazel.AqueryDepset {
|
||||
@@ -434,8 +434,8 @@ func (n noopBazelContext) IsModuleNameAllowed(_ string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m noopBazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
|
||||
return []bazel.BuildStatement{}
|
||||
func (m noopBazelContext) BuildStatementsToRegister() []*bazel.BuildStatement {
|
||||
return []*bazel.BuildStatement{}
|
||||
}
|
||||
|
||||
func (m noopBazelContext) AqueryDepsets() []bazel.AqueryDepset {
|
||||
@@ -1128,7 +1128,7 @@ func (context *mixedBuildBazelContext) generateBazelSymlinks(config Config, ctx
|
||||
return err
|
||||
}
|
||||
|
||||
func (context *mixedBuildBazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
|
||||
func (context *mixedBuildBazelContext) BuildStatementsToRegister() []*bazel.BuildStatement {
|
||||
return context.buildStatements
|
||||
}
|
||||
|
||||
@@ -1196,6 +1196,11 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
executionRoot := path.Join(ctx.Config().BazelContext.OutputBase(), "execroot", "__main__")
|
||||
bazelOutDir := path.Join(executionRoot, "bazel-out")
|
||||
for index, buildStatement := range ctx.Config().BazelContext.BuildStatementsToRegister() {
|
||||
// nil build statements are a valid case where we do not create an action because it is
|
||||
// unnecessary or handled by other processing
|
||||
if buildStatement == nil {
|
||||
continue
|
||||
}
|
||||
if len(buildStatement.Command) > 0 {
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
createCommand(rule.Command(), buildStatement, executionRoot, bazelOutDir, ctx)
|
||||
@@ -1240,7 +1245,7 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
}
|
||||
|
||||
// Register bazel-owned build statements (obtained from the aquery invocation).
|
||||
func createCommand(cmd *RuleBuilderCommand, buildStatement bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx BuilderContext) {
|
||||
func createCommand(cmd *RuleBuilderCommand, buildStatement *bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx BuilderContext) {
|
||||
// executionRoot is the action cwd.
|
||||
cmd.Text(fmt.Sprintf("cd '%s' &&", executionRoot))
|
||||
|
||||
|
Reference in New Issue
Block a user