Skip to content

Commit

Permalink
Clean up unused explicit command line overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-lou committed Oct 11, 2024
1 parent c3f3c88 commit 9707efd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
13 changes: 0 additions & 13 deletions app/invocation/invocation_model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,6 @@ export default class InvocationModel {
}

explicitCommandLine() {
// We allow overriding EXPLICIT_COMMAND_LINE to enable tools that wrap bazel
// to append bazel args but still preserve the appearance of the original
// command line. The effective command line can still be used to see the
// effective configuration used by bazel.
const overrideJSON = this.buildMetadataMap.get("EXPLICIT_COMMAND_LINE");
if (overrideJSON) {
try {
return this.quote(JSON.parse(overrideJSON));
} catch (_) {
// Invalid JSON; fall back to showing BES event.
}
}

return this.bazelCommandAndPatternWithOptions(this.optionsParsed?.explicitCmdLine ?? []);
}

Expand Down
12 changes: 3 additions & 9 deletions cli/cmd/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func main() {

func run() (exitCode int, err error) {
start := time.Now()
// Record original arguments so we can show them in the UI.
originalArgs := append([]string{}, os.Args...)

args := handleGlobalCliFlags(os.Args[1:])

log.Debugf("CLI started at %s", start)
Expand Down Expand Up @@ -106,7 +103,7 @@ func run() (exitCode int, err error) {

// If none of the CLI subcommand handlers were triggered, assume we should
// handle it as a bazel command.
return handleBazelCommand(start, args, originalArgs)
return handleBazelCommand(start, args)
}

// handleGlobalCliFlags processes global cli args that don't apply to any specific subcommand
Expand Down Expand Up @@ -134,10 +131,7 @@ func handleGlobalCliFlags(args []string) []string {

// handleBazelCommand handles a native bazel command (i.e. commands that are
// directly forwarded to bazel, as opposed to bb cli-specific commands)
//
// originalArgs contains the command as originally typed. We pass it as
// EXPLICIT_COMMAND_LINE metadata to the bazel invocation.
func handleBazelCommand(start time.Time, args []string, originalArgs []string) (int, error) {
func handleBazelCommand(start time.Time, args []string) (int, error) {
// Maybe run interactively (watching for changes to files).
if exitCode, err := watcher.Watch(); exitCode >= 0 || err != nil {
return exitCode, err
Expand Down Expand Up @@ -191,7 +185,7 @@ func handleBazelCommand(start time.Time, args []string, originalArgs []string) (
}
// Append metadata just before running bazelisk.
// Note, this means plugins cannot modify this metadata.
bazelArgs, err = metadata.AppendBuildMetadata(bazelArgs, originalArgs)
bazelArgs, err = metadata.AppendBuildMetadata(bazelArgs)
if err != nil {
return 1, err
}
Expand Down
19 changes: 2 additions & 17 deletions cli/metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package metadata

import (
"encoding/json"
"fmt"
"os"
"os/exec"
Expand All @@ -15,22 +14,8 @@ import (
"github.com/buildbuddy-io/buildbuddy/server/util/git"
)

func AppendBuildMetadata(args, originalArgs []string) ([]string, error) {
originalArgs = append(
// os.Args[0] might be something like /usr/local/bin/bb.
// filepath.Base gets just the "bb" part.
[]string{filepath.Base(originalArgs[0])},
originalArgs[1:]...,
)

originalArgsJSON, err := json.Marshal(originalArgs)
if err != nil {
return nil, fmt.Errorf("failed to marshal original command arguments: %s", err)
}

metadataFlags := []string{
"--build_metadata=EXPLICIT_COMMAND_LINE=" + string(originalArgsJSON),
}
func AppendBuildMetadata(args []string) ([]string, error) {
metadataFlags := make([]string, 0)

// If the user already has a workspace status script, don't set any default
// build_metadata flags since those would override the workspace status
Expand Down

0 comments on commit 9707efd

Please sign in to comment.