Merge "Print error code when bazel invocation fails"
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -260,11 +259,11 @@ func (m MockBazelContext) GetCcUnstrippedInfo(label string, _ configKey) (cquery
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MockBazelContext) InvokeBazel(_ Config, ctx *Context) error {
|
func (m MockBazelContext) InvokeBazel(_ Config, _ *Context) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MockBazelContext) BazelAllowlisted(moduleName string) bool {
|
func (m MockBazelContext) BazelAllowlisted(_ string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +355,7 @@ func (n noopBazelContext) GetCcUnstrippedInfo(_ string, _ configKey) (cquery.CcU
|
|||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n noopBazelContext) InvokeBazel(_ Config, ctx *Context) error {
|
func (n noopBazelContext) InvokeBazel(_ Config, _ *Context) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +363,7 @@ func (m noopBazelContext) OutputBase() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n noopBazelContext) BazelAllowlisted(moduleName string) bool {
|
func (n noopBazelContext) BazelAllowlisted(_ string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,7 +402,7 @@ func NewBazelContext(c *config) (BazelContext, error) {
|
|||||||
// Don't use partially-converted cc_library targets in mixed builds,
|
// Don't use partially-converted cc_library targets in mixed builds,
|
||||||
// since mixed builds would generally rely on both static and shared
|
// since mixed builds would generally rely on both static and shared
|
||||||
// variants of a cc_library.
|
// variants of a cc_library.
|
||||||
for staticOnlyModule, _ := range GetBp2BuildAllowList().ccLibraryStaticOnly {
|
for staticOnlyModule := range GetBp2BuildAllowList().ccLibraryStaticOnly {
|
||||||
disabledModules[staticOnlyModule] = true
|
disabledModules[staticOnlyModule] = true
|
||||||
}
|
}
|
||||||
for _, disabledDevModule := range allowlists.MixedBuildsDisabledList {
|
for _, disabledDevModule := range allowlists.MixedBuildsDisabledList {
|
||||||
@@ -509,7 +508,7 @@ type mockBazelRunner struct {
|
|||||||
extraFlags []string
|
extraFlags []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockBazelRunner) createBazelCommand(paths *bazelPaths, runName bazel.RunName,
|
func (r *mockBazelRunner) createBazelCommand(_ *bazelPaths, _ bazel.RunName,
|
||||||
command bazelCommand, extraFlags ...string) *exec.Cmd {
|
command bazelCommand, extraFlags ...string) *exec.Cmd {
|
||||||
r.commands = append(r.commands, command)
|
r.commands = append(r.commands, command)
|
||||||
r.extraFlags = append(r.extraFlags, strings.Join(extraFlags, " "))
|
r.extraFlags = append(r.extraFlags, strings.Join(extraFlags, " "))
|
||||||
@@ -534,13 +533,13 @@ type builtinBazelRunner struct{}
|
|||||||
// Returns (stdout, stderr, error). The first and second return values are strings
|
// Returns (stdout, stderr, error). The first and second return values are strings
|
||||||
// containing the stdout and stderr of the run command, and an error is returned if
|
// containing the stdout and stderr of the run command, and an error is returned if
|
||||||
// the invocation returned an error code.
|
// the invocation returned an error code.
|
||||||
|
|
||||||
func (r *builtinBazelRunner) issueBazelCommand(bazelCmd *exec.Cmd) (string, string, error) {
|
func (r *builtinBazelRunner) issueBazelCommand(bazelCmd *exec.Cmd) (string, string, error) {
|
||||||
stderr := &bytes.Buffer{}
|
stderr := &bytes.Buffer{}
|
||||||
bazelCmd.Stderr = stderr
|
bazelCmd.Stderr = stderr
|
||||||
if output, err := bazelCmd.Output(); err != nil {
|
if output, err := bazelCmd.Output(); err != nil {
|
||||||
return "", string(stderr.Bytes()),
|
return "", string(stderr.Bytes()),
|
||||||
fmt.Errorf("bazel command failed. command: [%s], env: [%s], error [%s]", bazelCmd, bazelCmd.Env, stderr)
|
fmt.Errorf("bazel command failed: %s\n---command---\n%s\n---env---\n%s\n---stderr---\n%s---",
|
||||||
|
err, bazelCmd, strings.Join(bazelCmd.Env, "\n"), stderr)
|
||||||
} else {
|
} else {
|
||||||
return string(output), string(stderr.Bytes()), nil
|
return string(output), string(stderr.Bytes()), nil
|
||||||
}
|
}
|
||||||
@@ -916,17 +915,17 @@ func (context *bazelContext) runCquery(ctx *Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(filepath.Join(soongInjectionPath, "WORKSPACE.bazel"), []byte{}, 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(soongInjectionPath, "WORKSPACE.bazel"), []byte{}, 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(filepath.Join(mixedBuildsPath, "main.bzl"), context.mainBzlFileContents(), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(mixedBuildsPath, "main.bzl"), context.mainBzlFileContents(), 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(filepath.Join(mixedBuildsPath, "BUILD.bazel"), context.mainBuildFileContents(), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(mixedBuildsPath, "BUILD.bazel"), context.mainBuildFileContents(), 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cqueryFileRelpath := filepath.Join(context.paths.injectedFilesDir(), "buildroot.cquery")
|
cqueryFileRelpath := filepath.Join(context.paths.injectedFilesDir(), "buildroot.cquery")
|
||||||
if err := ioutil.WriteFile(absolutePath(cqueryFileRelpath), context.cqueryStarlarkFileContents(), 0666); err != nil {
|
if err := os.WriteFile(absolutePath(cqueryFileRelpath), context.cqueryStarlarkFileContents(), 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +936,7 @@ func (context *bazelContext) runCquery(ctx *Context) error {
|
|||||||
return cqueryErr
|
return cqueryErr
|
||||||
}
|
}
|
||||||
cqueryCommandPrint := fmt.Sprintf("cquery command line:\n %s \n\n\n", printableCqueryCommand(cqueryCommandWithFlag))
|
cqueryCommandPrint := fmt.Sprintf("cquery command line:\n %s \n\n\n", printableCqueryCommand(cqueryCommandWithFlag))
|
||||||
if err := ioutil.WriteFile(filepath.Join(soongInjectionPath, "cquery.out"), []byte(cqueryCommandPrint+cqueryOutput), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(soongInjectionPath, "cquery.out"), []byte(cqueryCommandPrint+cqueryOutput), 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cqueryResults := map[string]string{}
|
cqueryResults := map[string]string{}
|
||||||
@@ -972,7 +971,7 @@ func (context *bazelContext) runAquery(config Config, ctx *Context) error {
|
|||||||
extraFlags = append(extraFlags, "--collect_code_coverage")
|
extraFlags = append(extraFlags, "--collect_code_coverage")
|
||||||
paths := make([]string, 0, 2)
|
paths := make([]string, 0, 2)
|
||||||
if p := config.productVariables.NativeCoveragePaths; len(p) > 0 {
|
if p := config.productVariables.NativeCoveragePaths; len(p) > 0 {
|
||||||
for i, _ := range p {
|
for i := range p {
|
||||||
// TODO(b/259404593) convert path wildcard to regex values
|
// TODO(b/259404593) convert path wildcard to regex values
|
||||||
if p[i] == "*" {
|
if p[i] == "*" {
|
||||||
p[i] = ".*"
|
p[i] = ".*"
|
||||||
@@ -1039,7 +1038,7 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|||||||
filepath.Dir(ctx.Config().moduleListFile), "bazel.list"))
|
filepath.Dir(ctx.Config().moduleListFile), "bazel.list"))
|
||||||
ctx.AddNinjaFileDeps(bazelBuildList)
|
ctx.AddNinjaFileDeps(bazelBuildList)
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(bazelBuildList)
|
data, err := os.ReadFile(bazelBuildList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Errorf(err.Error())
|
ctx.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user