|
880 | 880 | || fail "Expected unrelated action to not be rerun"
|
881 | 881 | }
|
882 | 882 |
|
| 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 | + |
883 | 926 | function test_repo_env_inverse() {
|
884 | 927 | # This test makes sure that a repository rule that has no dependencies on
|
885 | 928 | # environment variables does _not_ get refetched when --repo_env changes.
|
|
0 commit comments