Merge "Provide Bazel timing breakdown for the mixed builds" am: 0351be5adc
am: d96ff0d685
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2299299 Change-Id: Idd0420635184f66038193465480439184075940c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -150,8 +150,9 @@ type BazelContext interface {
|
|||||||
// ** end Cquery Results Retrieval Functions
|
// ** end Cquery Results Retrieval Functions
|
||||||
|
|
||||||
// Issues commands to Bazel to receive results for all cquery requests
|
// Issues commands to Bazel to receive results for all cquery requests
|
||||||
// queued in the BazelContext.
|
// queued in the BazelContext. The ctx argument is optional and is only
|
||||||
InvokeBazel(config Config) error
|
// used for performance data collection
|
||||||
|
InvokeBazel(config Config, ctx *Context) error
|
||||||
|
|
||||||
// Returns true if Bazel handling is enabled for the module with the given name.
|
// Returns true if Bazel handling is enabled for the module with the given name.
|
||||||
// Note that this only implies "bazel mixed build" allowlisting. The caller
|
// Note that this only implies "bazel mixed build" allowlisting. The caller
|
||||||
@@ -259,7 +260,7 @@ func (m MockBazelContext) GetCcUnstrippedInfo(label string, _ configKey) (cquery
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MockBazelContext) InvokeBazel(_ Config) error {
|
func (m MockBazelContext) InvokeBazel(_ Config, ctx *Context) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +356,7 @@ func (n noopBazelContext) GetCcUnstrippedInfo(_ string, _ configKey) (cquery.CcU
|
|||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n noopBazelContext) InvokeBazel(_ Config) error {
|
func (n noopBazelContext) InvokeBazel(_ Config, ctx *Context) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,11 +866,48 @@ func (p *bazelPaths) outDir() string {
|
|||||||
return filepath.Dir(p.soongOutDir)
|
return filepath.Dir(p.soongOutDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildrootLabel = "@soong_injection//mixed_builds:buildroot"
|
||||||
|
|
||||||
|
var (
|
||||||
|
cqueryCmd = bazelCommand{"cquery", fmt.Sprintf("deps(%s, 2)", buildrootLabel)}
|
||||||
|
aqueryCmd = bazelCommand{"aquery", fmt.Sprintf("deps(%s)", buildrootLabel)}
|
||||||
|
buildCmd = bazelCommand{"build", "@soong_injection//mixed_builds:phonyroot"}
|
||||||
|
)
|
||||||
|
|
||||||
// Issues commands to Bazel to receive results for all cquery requests
|
// Issues commands to Bazel to receive results for all cquery requests
|
||||||
// queued in the BazelContext.
|
// queued in the BazelContext.
|
||||||
func (context *bazelContext) InvokeBazel(config Config) error {
|
func (context *bazelContext) InvokeBazel(config Config, ctx *Context) error {
|
||||||
context.results = make(map[cqueryKey]string)
|
if ctx != nil {
|
||||||
|
ctx.EventHandler.Begin("bazel")
|
||||||
|
defer ctx.EventHandler.End("bazel")
|
||||||
|
}
|
||||||
|
|
||||||
|
if metricsDir := context.paths.BazelMetricsDir(); metricsDir != "" {
|
||||||
|
if err := os.MkdirAll(metricsDir, 0777); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.results = make(map[cqueryKey]string)
|
||||||
|
if err := context.runCquery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := context.runAquery(config, ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := context.generateBazelSymlinks(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear requests.
|
||||||
|
context.requests = map[cqueryKey]bool{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *bazelContext) runCquery(ctx *Context) error {
|
||||||
|
if ctx != nil {
|
||||||
|
ctx.EventHandler.Begin("cquery")
|
||||||
|
defer ctx.EventHandler.End("cquery")
|
||||||
|
}
|
||||||
soongInjectionPath := absolutePath(context.paths.injectedFilesDir())
|
soongInjectionPath := absolutePath(context.paths.injectedFilesDir())
|
||||||
mixedBuildsPath := filepath.Join(soongInjectionPath, "mixed_builds")
|
mixedBuildsPath := filepath.Join(soongInjectionPath, "mixed_builds")
|
||||||
if _, err := os.Stat(mixedBuildsPath); os.IsNotExist(err) {
|
if _, err := os.Stat(mixedBuildsPath); os.IsNotExist(err) {
|
||||||
@@ -878,13 +916,6 @@ func (context *bazelContext) InvokeBazel(config Config) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if metricsDir := context.paths.BazelMetricsDir(); metricsDir != "" {
|
|
||||||
err := os.MkdirAll(metricsDir, 0777)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(soongInjectionPath, "WORKSPACE.bazel"), []byte{}, 0666); err != nil {
|
if err := ioutil.WriteFile(filepath.Join(soongInjectionPath, "WORKSPACE.bazel"), []byte{}, 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -899,8 +930,6 @@ func (context *bazelContext) InvokeBazel(config Config) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildrootLabel = "@soong_injection//mixed_builds:buildroot"
|
|
||||||
cqueryCmd := bazelCommand{"cquery", fmt.Sprintf("deps(%s, 2)", buildrootLabel)}
|
|
||||||
cqueryCommandWithFlag := context.createBazelCommand(context.paths, bazel.CqueryBuildRootRunName, cqueryCmd,
|
cqueryCommandWithFlag := context.createBazelCommand(context.paths, bazel.CqueryBuildRootRunName, cqueryCmd,
|
||||||
"--output=starlark", "--starlark:file="+absolutePath(cqueryFileRelpath))
|
"--output=starlark", "--starlark:file="+absolutePath(cqueryFileRelpath))
|
||||||
cqueryOutput, cqueryErrorMessage, cqueryErr := context.issueBazelCommand(cqueryCommandWithFlag)
|
cqueryOutput, cqueryErrorMessage, cqueryErr := context.issueBazelCommand(cqueryCommandWithFlag)
|
||||||
@@ -926,7 +955,14 @@ func (context *bazelContext) InvokeBazel(config Config) error {
|
|||||||
getCqueryId(val), cqueryOutput, cqueryErrorMessage)
|
getCqueryId(val), cqueryOutput, cqueryErrorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *bazelContext) runAquery(config Config, ctx *Context) error {
|
||||||
|
if ctx != nil {
|
||||||
|
ctx.EventHandler.Begin("aquery")
|
||||||
|
defer ctx.EventHandler.End("aquery")
|
||||||
|
}
|
||||||
// Issue an aquery command to retrieve action information about the bazel build tree.
|
// Issue an aquery command to retrieve action information about the bazel build tree.
|
||||||
//
|
//
|
||||||
// Use jsonproto instead of proto; actual proto parsing would require a dependency on Bazel's
|
// Use jsonproto instead of proto; actual proto parsing would require a dependency on Bazel's
|
||||||
@@ -951,25 +987,25 @@ func (context *bazelContext) InvokeBazel(config Config) error {
|
|||||||
extraFlags = append(extraFlags, "--instrumentation_filter="+strings.Join(paths, ","))
|
extraFlags = append(extraFlags, "--instrumentation_filter="+strings.Join(paths, ","))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aqueryCmd := bazelCommand{"aquery", fmt.Sprintf("deps(%s)", buildrootLabel)}
|
aqueryOutput, _, err := context.issueBazelCommand(context.createBazelCommand(context.paths, bazel.AqueryBuildRootRunName, aqueryCmd,
|
||||||
if aqueryOutput, _, err := context.issueBazelCommand(context.createBazelCommand(context.paths, bazel.AqueryBuildRootRunName, aqueryCmd,
|
extraFlags...))
|
||||||
extraFlags...)); err == nil {
|
if err != nil {
|
||||||
context.buildStatements, context.depsets, err = bazel.AqueryBuildStatements([]byte(aqueryOutput))
|
|
||||||
} else {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
context.buildStatements, context.depsets, err = bazel.AqueryBuildStatements([]byte(aqueryOutput))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *bazelContext) generateBazelSymlinks(ctx *Context) error {
|
||||||
|
if ctx != nil {
|
||||||
|
ctx.EventHandler.Begin("symlinks")
|
||||||
|
defer ctx.EventHandler.End("symlinks")
|
||||||
|
}
|
||||||
// Issue a build command of the phony root to generate symlink forests for dependencies of the
|
// Issue a build command of the phony root to generate symlink forests for dependencies of the
|
||||||
// Bazel build. This is necessary because aquery invocations do not generate this symlink forest,
|
// Bazel build. This is necessary because aquery invocations do not generate this symlink forest,
|
||||||
// but some of symlinks may be required to resolve source dependencies of the build.
|
// but some of symlinks may be required to resolve source dependencies of the build.
|
||||||
buildCmd := bazelCommand{"build", "@soong_injection//mixed_builds:phonyroot"}
|
_, _, err := context.issueBazelCommand(context.createBazelCommand(context.paths, bazel.BazelBuildPhonyRootRunName, buildCmd))
|
||||||
if _, _, err := context.issueBazelCommand(context.createBazelCommand(context.paths, bazel.BazelBuildPhonyRootRunName, buildCmd)); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear requests.
|
|
||||||
context.requests = map[cqueryKey]bool{}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *bazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
|
func (context *bazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
|
||||||
|
@@ -23,7 +23,7 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) {
|
|||||||
bazelCommand{command: "cquery", expression: "deps(@soong_injection//mixed_builds:buildroot, 2)"}: `@//foo:bar|arm64_armv8-a|android>>out/foo/bar.txt`,
|
bazelCommand{command: "cquery", expression: "deps(@soong_injection//mixed_builds:buildroot, 2)"}: `@//foo:bar|arm64_armv8-a|android>>out/foo/bar.txt`,
|
||||||
})
|
})
|
||||||
bazelContext.QueueBazelRequest(label, cquery.GetOutputFiles, cfg)
|
bazelContext.QueueBazelRequest(label, cquery.GetOutputFiles, cfg)
|
||||||
err := bazelContext.InvokeBazel(testConfig)
|
err := bazelContext.InvokeBazel(testConfig, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) {
|
|||||||
|
|
||||||
func TestInvokeBazelWritesBazelFiles(t *testing.T) {
|
func TestInvokeBazelWritesBazelFiles(t *testing.T) {
|
||||||
bazelContext, baseDir := testBazelContext(t, map[bazelCommand]string{})
|
bazelContext, baseDir := testBazelContext(t, map[bazelCommand]string{})
|
||||||
err := bazelContext.InvokeBazel(testConfig)
|
err := bazelContext.InvokeBazel(testConfig, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
|
|||||||
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
||||||
bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: string(data)})
|
bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: string(data)})
|
||||||
|
|
||||||
err = bazelContext.InvokeBazel(testConfig)
|
err = bazelContext.InvokeBazel(testConfig, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("testCase #%d: did not expect error invoking Bazel, but got %s", i+1, err)
|
t.Fatalf("testCase #%d: did not expect error invoking Bazel, but got %s", i+1, err)
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ func TestCoverageFlagsAfterInvokeBazel(t *testing.T) {
|
|||||||
func verifyExtraFlags(t *testing.T, config Config, expected string) string {
|
func verifyExtraFlags(t *testing.T, config Config, expected string) string {
|
||||||
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{})
|
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{})
|
||||||
|
|
||||||
err := bazelContext.InvokeBazel(config)
|
err := bazelContext.InvokeBazel(config, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
t.Fatalf("Did not expect error invoking Bazel, but got %s", err)
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ func testBazelContext(t *testing.T, bazelCommandResults map[bazelCommand]string)
|
|||||||
}
|
}
|
||||||
aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}
|
aqueryCommand := bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}
|
||||||
if _, exists := bazelCommandResults[aqueryCommand]; !exists {
|
if _, exists := bazelCommandResults[aqueryCommand]; !exists {
|
||||||
bazelCommandResults[aqueryCommand] = "{}\n"
|
bazelCommandResults[aqueryCommand] = ""
|
||||||
}
|
}
|
||||||
runner := &mockBazelRunner{bazelCommandResults: bazelCommandResults}
|
runner := &mockBazelRunner{bazelCommandResults: bazelCommandResults}
|
||||||
return &bazelContext{
|
return &bazelContext{
|
||||||
|
@@ -157,9 +157,7 @@ func runMixedModeBuild(configuration android.Config, ctx *android.Context, extra
|
|||||||
defer ctx.EventHandler.End("mixed_build")
|
defer ctx.EventHandler.End("mixed_build")
|
||||||
|
|
||||||
bazelHook := func() error {
|
bazelHook := func() error {
|
||||||
ctx.EventHandler.Begin("bazel")
|
return configuration.BazelContext.InvokeBazel(configuration, ctx)
|
||||||
defer ctx.EventHandler.End("bazel")
|
|
||||||
return configuration.BazelContext.InvokeBazel(configuration)
|
|
||||||
}
|
}
|
||||||
ctx.SetBeforePrepareBuildActionsHook(bazelHook)
|
ctx.SetBeforePrepareBuildActionsHook(bazelHook)
|
||||||
ninjaDeps := bootstrap.RunBlueprint(cmdlineArgs, bootstrap.DoEverything, ctx.Context, configuration)
|
ninjaDeps := bootstrap.RunBlueprint(cmdlineArgs, bootstrap.DoEverything, ctx.Context, configuration)
|
||||||
|
Reference in New Issue
Block a user