From 8efb85f8a6e8fd9a2634f250e21a5508ee693cc9 Mon Sep 17 00:00:00 2001 From: Jamy Timmermans Date: Fri, 2 Dec 2022 08:13:21 -0800 Subject: [PATCH] fix(packagesdriver): bazelFlags should prefix the command (#3371) --- go/tools/gopackagesdriver/bazel.go | 19 +++++++++++-------- .../gopackagesdriver/bazel_json_builder.go | 4 ++-- go/tools/gopackagesdriver/main.go | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/go/tools/gopackagesdriver/bazel.go b/go/tools/gopackagesdriver/bazel.go index c2e5290cf7..e5cab746df 100644 --- a/go/tools/gopackagesdriver/bazel.go +++ b/go/tools/gopackagesdriver/bazel.go @@ -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 @@ -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) @@ -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 diff --git a/go/tools/gopackagesdriver/bazel_json_builder.go b/go/tools/gopackagesdriver/bazel_json_builder.go index 616367a77c..3b82b0537d 100644 --- a/go/tools/gopackagesdriver/bazel_json_builder.go +++ b/go/tools/gopackagesdriver/bazel_json_builder.go @@ -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", @@ -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) diff --git a/go/tools/gopackagesdriver/main.go b/go/tools/gopackagesdriver/main.go index 6836addcc2..06da64823b 100644 --- a/go/tools/gopackagesdriver/main.go +++ b/go/tools/gopackagesdriver/main.go @@ -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")) @@ -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) }