|
569 | 569 | assert_contains '/link_two$' *-bin/a/go
|
570 | 570 | }
|
571 | 571 |
|
572 |
| -function test_spaces_in_runfiles_source_paths() { |
| 572 | +function setup_spaces_in_runfiles_source_paths() { |
573 | 573 | mkdir -p pkg
|
574 | 574 | cat > pkg/defs.bzl <<'EOF'
|
575 | 575 | def _spaces_impl(ctx):
|
@@ -598,11 +598,21 @@ if [[ "$(cat "pkg/ a b .txt")" != "my content" ]]; then
|
598 | 598 | fi
|
599 | 599 | EOF
|
600 | 600 | chmod +x pkg/foo.sh
|
| 601 | +} |
| 602 | + |
| 603 | +function test_spaces_in_runfiles_source_paths_out_of_process() { |
| 604 | + setup_spaces_in_runfiles_source_paths |
| 605 | + bazel test --noexperimental_inprocess_symlink_creation \ |
| 606 | + //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
| 607 | +} |
601 | 608 |
|
602 |
| - bazel test //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
| 609 | +function test_spaces_in_runfiles_source_paths_in_process() { |
| 610 | + setup_spaces_in_runfiles_source_paths |
| 611 | + bazel test --experimental_inprocess_symlink_creation \ |
| 612 | + //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
603 | 613 | }
|
604 | 614 |
|
605 |
| -function test_spaces_in_runfiles_source_and_target_paths() { |
| 615 | +function setup_spaces_in_runfiles_source_and_target_paths() { |
606 | 616 | dir=$(mktemp -d 'runfiles test.XXXXXX')
|
607 | 617 | cd "$dir" || fail "failed to cd to $dir"
|
608 | 618 | touch MODULE.bazel
|
@@ -635,8 +645,84 @@ if [[ "$(cat "pkg/ a b .txt")" != "my content" ]]; then
|
635 | 645 | fi
|
636 | 646 | EOF
|
637 | 647 | chmod +x pkg/foo.sh
|
| 648 | +} |
| 649 | + |
| 650 | +function test_spaces_in_runfiles_source_and_target_paths_out_of_process() { |
| 651 | + setup_spaces_in_runfiles_source_and_target_paths |
| 652 | + bazel test --noexperimental_inprocess_symlink_creation \ |
| 653 | + //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
| 654 | +} |
| 655 | + |
| 656 | +function test_spaces_in_runfiles_source_and_target_paths_in_process() { |
| 657 | + setup_spaces_in_runfiles_source_and_target_paths |
| 658 | + bazel test --experimental_inprocess_symlink_creation \ |
| 659 | + //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
| 660 | +} |
| 661 | + |
| 662 | +# Verify that Bazel's runfiles manifest is compatible with v3 of the Bash |
| 663 | +# runfiles library snippet, even if the workspace path contains a space. |
| 664 | +function test_compatibility_with_bash_runfiles_library_snippet() { |
| 665 | + # Create a workspace path with a space. |
| 666 | + WORKSPACE_NAME="my workspace" |
| 667 | + trap "rm -rf \"$PWD/$WORKSPACE_NAME\"" EXIT |
| 668 | + mkdir -p "$WORKSPACE_NAME" |
| 669 | + cd "$WORKSPACE_NAME" || fail "failed to cd to $WORKSPACE_NAME" |
| 670 | + cat > MODULE.bazel <<'EOF' |
| 671 | +module(name = "my_module") |
| 672 | +EOF |
| 673 | + |
| 674 | + mkdir pkg |
| 675 | + cat > pkg/BUILD <<'EOF' |
| 676 | +sh_binary( |
| 677 | + name = "tool", |
| 678 | + srcs = ["tool.sh"], |
| 679 | + deps = ["@bazel_tools//tools/bash/runfiles"], |
| 680 | +) |
| 681 | +
|
| 682 | +genrule( |
| 683 | + name = "gen", |
| 684 | + outs = ["out"], |
| 685 | + tools = [":tool"], |
| 686 | + cmd = "$(execpath :tool) $@", |
| 687 | +) |
| 688 | +EOF |
| 689 | + cat > pkg/tool.sh <<'EOF' |
| 690 | +#!/bin/bash |
| 691 | +# --- begin runfiles.bash initialization v3 --- |
| 692 | +# Copy-pasted from the Bazel Bash runfiles library v3. |
| 693 | +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash |
| 694 | +# shellcheck disable=SC1090 |
| 695 | +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ |
| 696 | + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ |
| 697 | + source "$0.runfiles/$f" 2>/dev/null || \ |
| 698 | + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 699 | + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 700 | + { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e |
| 701 | +# --- end runfiles.bash initialization v3 --- |
| 702 | +
|
| 703 | +if [[ ! -z "${RUNFILES_DIR+x}" ]]; then |
| 704 | + echo "RUNFILES_DIR is set" |
| 705 | + exit 1 |
| 706 | +fi |
| 707 | +
|
| 708 | +if [[ -z "${RUNFILES_MANIFEST_FILE+x}" ]]; then |
| 709 | + echo "RUNFILES_MANIFEST_FILE is not set" |
| 710 | + exit 1 |
| 711 | +fi |
| 712 | +
|
| 713 | +if [[ -z "$(rlocation "my_module/pkg/tool.sh")" ]]; then |
| 714 | + echo "rlocation failed" |
| 715 | + exit 1 |
| 716 | +fi |
| 717 | +
|
| 718 | +touch $1 |
| 719 | +EOF |
| 720 | + chmod +x pkg/tool.sh |
638 | 721 |
|
639 |
| - bazel test //pkg:foo $EXTRA_BUILD_FLAGS >&$TEST_log || fail "test failed" |
| 722 | + bazel build --noenable_runfiles \ |
| 723 | + --spawn_strategy=local \ |
| 724 | + --action_env=RUNFILES_LIB_DEBUG=1 \ |
| 725 | + //pkg:gen >&$TEST_log || fail "build failed" |
640 | 726 | }
|
641 | 727 |
|
642 | 728 | run_suite "runfiles"
|
0 commit comments