Skip to content

Commit

Permalink
fix(packagesdriver): bazelFlags should prefix the command (bazel-cont…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyDev authored and jacqueline.lee committed Jul 19, 2023
1 parent a24ffb2 commit 8efb85f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions go/tools/gopackagesdriver/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const (
)

type Bazel struct {
bazelBin string
workspaceRoot string
info map[string]string
bazelBin string
workspaceRoot string
bazelStartupFlags []string
info map[string]string
}

// Minimal BEP structs to access the build outputs
Expand All @@ -49,10 +50,11 @@ type BEPNamedSet struct {
} `json:"namedSetOfFiles"`
}

func NewBazel(ctx context.Context, bazelBin, workspaceRoot string) (*Bazel, error) {
func NewBazel(ctx context.Context, bazelBin, workspaceRoot string, bazelStartupFlags []string) (*Bazel, error) {
b := &Bazel{
bazelBin: bazelBin,
workspaceRoot: workspaceRoot,
bazelBin: bazelBin,
workspaceRoot: workspaceRoot,
bazelStartupFlags: bazelStartupFlags,
}
if err := b.fillInfo(ctx); err != nil {
return nil, fmt.Errorf("unable to query bazel info: %w", err)
Expand All @@ -75,11 +77,12 @@ func (b *Bazel) fillInfo(ctx context.Context) error {
}

func (b *Bazel) run(ctx context.Context, command string, args ...string) (string, error) {
cmd := exec.CommandContext(ctx, b.bazelBin, append([]string{
defaultArgs := []string{
command,
"--tool_tag=" + toolTag,
"--ui_actions_shown=0",
}, args...)...)
}
cmd := exec.CommandContext(ctx, b.bazelBin, concatStringsArrays(b.bazelStartupFlags, defaultArgs, args)...)
fmt.Fprintln(os.Stderr, "Running:", cmd.Args)
cmd.Dir = b.WorkspaceRoot()
cmd.Stderr = os.Stderr
Expand Down
4 changes: 2 additions & 2 deletions go/tools/gopackagesdriver/bazel_json_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (b *BazelJSONBuilder) outputGroupsForMode(mode LoadMode) string {
}

func (b *BazelJSONBuilder) query(ctx context.Context, query string) ([]string, error) {
queryArgs := concatStringsArrays(bazelFlags, bazelQueryFlags, []string{
queryArgs := concatStringsArrays(bazelQueryFlags, []string{
"--ui_event_filters=-info,-stderr",
"--noshow_progress",
"--order_output=no",
Expand Down Expand Up @@ -166,7 +166,7 @@ func (b *BazelJSONBuilder) Build(ctx context.Context, mode LoadMode) ([]string,
"--aspects=" + strings.Join(aspects, ","),
"--output_groups=" + b.outputGroupsForMode(mode),
"--keep_going", // Build all possible packages
}, bazelFlags, bazelBuildFlags, labels)
}, bazelBuildFlags, labels)
files, err := b.bazel.Build(ctx, buildArgs...)
if err != nil {
return nil, fmt.Errorf("unable to bazel build %v: %w", buildArgs, err)
Expand Down
4 changes: 2 additions & 2 deletions go/tools/gopackagesdriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
rulesGoRepositoryName = getenvDefault("GOPACKAGESDRIVER_RULES_GO_REPOSITORY_NAME", "@io_bazel_rules_go")
goDefaultAspect = rulesGoRepositoryName + "//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect"
bazelBin = getenvDefault("GOPACKAGESDRIVER_BAZEL", "bazel")
bazelFlags = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_FLAGS"))
bazelStartupFlags = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_FLAGS"))
bazelQueryFlags = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_QUERY_FLAGS"))
bazelQueryScope = getenvDefault("GOPACKAGESDRIVER_BAZEL_QUERY_SCOPE", "")
bazelBuildFlags = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_BUILD_FLAGS"))
Expand All @@ -80,7 +80,7 @@ func run() (*driverResponse, error) {
return emptyResponse, fmt.Errorf("unable to read request: %w", err)
}

bazel, err := NewBazel(ctx, bazelBin, workspaceRoot)
bazel, err := NewBazel(ctx, bazelBin, workspaceRoot, bazelStartupFlags)
if err != nil {
return emptyResponse, fmt.Errorf("unable to create bazel instance: %w", err)
}
Expand Down

0 comments on commit 8efb85f

Please sign in to comment.