Skip to content

Commit 8cb1a07

Browse files
authored
Use Windows separator and Update starlark_repository_test.sh
1 parent baa8d8e commit 8cb1a07

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/test/shell/bazel/starlark_repository_test.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,49 @@ EOF
880880
|| fail "Expected unrelated action to not be rerun"
881881
}
882882

883+
function test_repo_env_workspace_interpolation() {
884+
setup_starlark_repository
885+
886+
cat > test.bzl <<'EOF'
887+
def _impl(ctx):
888+
result = ctx.execute(["my_tool"])
889+
if result.return_code != 0:
890+
fail("my_tool failed ({}, PATH = {}): {}".format(result.return_code, ctx.os.environ["PATH"], result.stderr))
891+
ctx.file("out.txt", result.stdout)
892+
ctx.file("BUILD", 'exports_files(["out.txt"])')
893+
894+
repo = repository_rule(
895+
implementation = _impl,
896+
)
897+
EOF
898+
cat > BUILD <<'EOF'
899+
genrule(
900+
name = "repoenv",
901+
outs = ["repoenv.txt"],
902+
srcs = ["@foo//:out.txt"],
903+
cmd = "cp $< $@",
904+
)
905+
EOF
906+
if "$is_windows"; then
907+
local repo_env_path="%bazel_workspace%/repo_tools;$PATH"
908+
else
909+
local repo_env_path="%bazel_workspace%/repo_tools:$PATH"
910+
fi
911+
cat > .bazelrc <<EOF
912+
common --repo_env=PATH="$repo_env_path"
913+
EOF
914+
915+
mkdir -p repo_tools
916+
cat > repo_tools/my_tool.bat <<'EOF'
917+
echo Hello from my_tool
918+
EOF
919+
cp repo_tools/my_tool.bat repo_tools/my_tool
920+
chmod +x repo_tools/my_tool
921+
922+
bazel build //:repoenv &> $TEST_log || fail "Failed to build"
923+
assert_contains "Hello from my_tool" `bazel info bazel-bin 2>/dev/null`/repoenv.txt
924+
}
925+
883926
function test_repo_env_inverse() {
884927
# This test makes sure that a repository rule that has no dependencies on
885928
# environment variables does _not_ get refetched when --repo_env changes.

0 commit comments

Comments
 (0)