diff options
author | Fabian Meumertzheim <fabian@meumertzhe.im> | 2023-01-25 10:55:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 10:55:26 +0100 |
commit | fe6975120bcaf6d43d367e4380d95f724e2cbba8 (patch) | |
tree | 348a34ec2213c1969f381a59f66d5da827ea0e91 /go/tools/go_bin_runner/process.go | |
parent | cf78385a58e278b542511d246bb1cef287d528e9 (diff) | |
download | bazelbuild-rules_go-fe6975120bcaf6d43d367e4380d95f724e2cbba8.tar.gz |
Make the toolchain's `go` binary available as a target (#3429)
This allows developers to use the `go` command provided by the
registered toolchain to e.g. add dependencies to `go.mod`. This ensures
that everyone uses the same version of Go and does not require a local
installation of Go.
Diffstat (limited to 'go/tools/go_bin_runner/process.go')
-rw-r--r-- | go/tools/go_bin_runner/process.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/go/tools/go_bin_runner/process.go b/go/tools/go_bin_runner/process.go new file mode 100644 index 00000000..8b344c96 --- /dev/null +++ b/go/tools/go_bin_runner/process.go @@ -0,0 +1,22 @@ +//go:build !unix + +package main + +import ( + "os" + "os/exec" +) + +func ReplaceWithProcess(args, env []string) error { + cmd := exec.Command(args[0], args[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Env = env + err := cmd.Run() + if exitErr, ok := err.(*exec.ExitError); ok { + os.Exit(exitErr.ExitCode()) + } else if err == nil { + os.Exit(0) + } + return err +} |