aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/tools/go_bin_runner/BUILD.bazel11
-rw-r--r--go/tools/go_bin_runner/process.go2
-rw-r--r--go/tools/go_bin_runner/process_unix.go11
-rw-r--r--tests/bcr/BUILD.bazel8
-rwxr-xr-xtests/bcr/go_version_test.sh19
5 files changed, 30 insertions, 21 deletions
diff --git a/go/tools/go_bin_runner/BUILD.bazel b/go/tools/go_bin_runner/BUILD.bazel
index a0e26d65..91be016e 100644
--- a/go/tools/go_bin_runner/BUILD.bazel
+++ b/go/tools/go_bin_runner/BUILD.bazel
@@ -12,18 +12,13 @@ go_library(
name = "go_bin_runner_lib",
srcs = [
"main.go",
- ] + select({
- "@platforms//os:windows": ["process.go"],
- "//conditions:default": ["process_unix.go"],
- }),
+ "process.go",
+ ],
importpath = "github.com/bazelbuild/rules_go/go/tools/go_bin_runner",
visibility = ["//visibility:private"],
deps = [
"//go/runfiles",
- ] + select({
- "@platforms//os:windows": [],
- "//conditions:default": ["@org_golang_x_sys//unix"],
- }),
+ ],
)
go_binary(
diff --git a/go/tools/go_bin_runner/process.go b/go/tools/go_bin_runner/process.go
index 8b344c96..af236549 100644
--- a/go/tools/go_bin_runner/process.go
+++ b/go/tools/go_bin_runner/process.go
@@ -1,5 +1,3 @@
-//go:build !unix
-
package main
import (
diff --git a/go/tools/go_bin_runner/process_unix.go b/go/tools/go_bin_runner/process_unix.go
deleted file mode 100644
index f59af5d2..00000000
--- a/go/tools/go_bin_runner/process_unix.go
+++ /dev/null
@@ -1,11 +0,0 @@
-//go:build unix
-
-package main
-
-import (
- "golang.org/x/sys/unix"
-)
-
-func ReplaceWithProcess(args, env []string) error {
- return unix.Exec(args[0], args, env)
-}
diff --git a/tests/bcr/BUILD.bazel b/tests/bcr/BUILD.bazel
index 813d72fe..d5c5f6f1 100644
--- a/tests/bcr/BUILD.bazel
+++ b/tests/bcr/BUILD.bazel
@@ -45,3 +45,11 @@ go_test(
embed = [":mockable"],
deps = ["@my_rules_go//extras/gomock"],
)
+
+sh_test(
+ name = "go_version_test",
+ srcs = ["go_version_test.sh"],
+ data = ["@my_rules_go//go"],
+ env = {"GO_TOOL_RLOCATION": "$(rlocationpath @my_rules_go//go)"},
+ deps = ["@bazel_tools//tools/bash/runfiles"],
+)
diff --git a/tests/bcr/go_version_test.sh b/tests/bcr/go_version_test.sh
new file mode 100755
index 00000000..986d91d7
--- /dev/null
+++ b/tests/bcr/go_version_test.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+# --- begin runfiles.bash initialization v3 ---
+# Copy-pasted from the Bazel Bash runfiles library v3.
+set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
+source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
+ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
+ source "$0.runfiles/$f" 2>/dev/null || \
+ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
+ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
+ { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
+# --- end runfiles.bash initialization v3 ---
+
+GO_TOOL=$(rlocation "$GO_TOOL_RLOCATION")
+# Set runfiles variables for subprocess.
+runfiles_export_envvars
+# Simulate a bazel run environment.
+export BUILD_WORKING_DIRECTORY=$(pwd)
+[[ "$("$GO_TOOL" version)" =~ ^go ]]