From ce04a9b278401ba31265738cac594ba9844852ea Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Tue, 14 Aug 2018 00:57:15 -0700 Subject: Windows,tests: port skylark_flag_test //src/test/shell/integration:skylark_flag_test now runs on Windows. See https://github.com/bazelbuild/bazel/issues/4292 Change-Id: Ib698ddcfb2106fe4b9830da9b969e51271e91f58 Closes #5871. Change-Id: I382c01d4dd8d9ee030dc8fe190a50bd7a57f8ee4 PiperOrigin-RevId: 208606660 --- src/test/shell/integration/BUILD | 6 +- src/test/shell/integration/skylark_flag_test.sh | 91 +++++++++++++++++++------ 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index e496e69c63..6adab3550c 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -244,8 +244,10 @@ sh_test( name = "skylark_flag_test", size = "medium", srcs = ["skylark_flag_test.sh"], - data = [":test-deps"], - tags = ["no_windows"], + data = [ + ":test-deps", + "@bazel_tools//tools/bash/runfiles", + ], ) sh_test( diff --git a/src/test/shell/integration/skylark_flag_test.sh b/src/test/shell/integration/skylark_flag_test.sh index 9e1e0a1be9..171ed17e6a 100755 --- a/src/test/shell/integration/skylark_flag_test.sh +++ b/src/test/shell/integration/skylark_flag_test.sh @@ -20,11 +20,54 @@ # The --internal_skylark_flag_test_canary flag is built into # SkylarkSemanticsOptions specifically for this test suite. -# Load the test setup defined in the parent directory -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${CURRENT_DIR}/../integration_test_setup.sh" \ +# --- begin runfiles.bash initialization --- +# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). +set -euo pipefail +if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$0.runfiles_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" + elif [[ -f "$0.runfiles/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" + elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + export RUNFILES_DIR="$0.runfiles" + fi +fi +if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" +elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ + "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" +else + echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" + exit 1 +fi +# --- end runfiles.bash initialization --- + +source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +# `uname` returns the current platform, e.g "MSYS_NT-10.0" or "Linux". +# `tr` converts all upper case letters to lower case. +# `case` matches the result if the `uname | tr` expression to string prefixes +# that use the same wildcards as names do in Bash, i.e. "msys*" matches strings +# starting with "msys", and "*" matches everything (it's the default case). +case "$(uname -s | tr [:upper:] [:lower:])" in +msys*) + # As of 2018-08-14, Bazel on Windows only supports MSYS Bash. + declare -r is_windows=true + ;; +*) + declare -r is_windows=false + ;; +esac + +if "$is_windows"; then + # Disable MSYS path conversion that converts path-looking command arguments to + # Windows paths (even if they arguments are not in fact paths). + export MSYS_NO_PATHCONV=1 + export MSYS2_ARG_CONV_EXCL="*" +fi + # Text that will be appended to every print() output when the flag is enabled. MARKER="<== skylark flag test ==>" @@ -33,8 +76,9 @@ sanity_fail_msg+="--internal_skylark_flag_test_canary wasn't passed" function test_build_file() { - mkdir -p test - cat > test/BUILD <<'EOF' || fail "couldn't create file" + local -r pkg=$FUNCNAME + mkdir -p $pkg + cat > $pkg/BUILD <<'EOF' || fail "couldn't create file" print("In BUILD: ") genrule( @@ -45,12 +89,12 @@ genrule( EOF # Sanity check. - bazel build //test:dummy \ + bazel build //$pkg:dummy \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In BUILD: " "Did not find BUILD print output" expect_not_log "$MARKER" "$sanity_fail_msg" - bazel build //test:dummy \ + bazel build //$pkg:dummy \ --internal_skylark_flag_test_canary \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In BUILD: $MARKER" \ @@ -58,13 +102,14 @@ EOF } function test_bzl_file_and_macro() { - mkdir -p test - cat > test/BUILD <<'EOF' || fail "couldn't create file" + local -r pkg=$FUNCNAME + mkdir -p $pkg + cat > $pkg/BUILD <<'EOF' || fail "couldn't create file" load(":test.bzl", "macro") macro() EOF - cat >test/test.bzl <<'EOF' || fail "couldn't create file" + cat >$pkg/test.bzl <<'EOF' || fail "couldn't create file" print("In bzl: ") def macro(): @@ -77,13 +122,13 @@ def macro(): EOF # Sanity check. - bazel build //test:dummy \ + bazel build //$pkg:dummy \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In bzl: " "Did not find .bzl print output" expect_log "In macro: " "Did not find macro print output" expect_not_log "$MARKER" "$sanity_fail_msg" - bazel build //test:dummy \ + bazel build //$pkg:dummy \ --internal_skylark_flag_test_canary \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In bzl: $MARKER" \ @@ -93,15 +138,16 @@ EOF } function test_rule() { - mkdir -p test - cat > test/BUILD <<'EOF' || fail "couldn't create file" + local -r pkg=$FUNCNAME + mkdir -p $pkg + cat > $pkg/BUILD <<'EOF' || fail "couldn't create file" load(":test.bzl", "some_rule") some_rule( name = "dummy", ) EOF - cat >test/test.bzl <<'EOF' || fail "couldn't create file" + cat >$pkg/test.bzl <<'EOF' || fail "couldn't create file" def _rule_impl(ctx): print("In rule: ") @@ -111,12 +157,12 @@ some_rule = rule( EOF # Sanity check. - bazel build //test:dummy \ + bazel build //$pkg:dummy \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In rule: " "Did not find rule print output" expect_not_log "$MARKER" "$sanity_fail_msg" - bazel build //test:dummy \ + bazel build //$pkg:dummy \ --internal_skylark_flag_test_canary \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In rule: $MARKER" \ @@ -129,15 +175,16 @@ EOF # Skylark function iff the flag is set. function test_aspect() { - mkdir -p test - cat > test/BUILD <<'EOF' || fail "couldn't create file" + local -r pkg=$FUNCNAME + mkdir -p $pkg + cat > $pkg/BUILD <<'EOF' || fail "couldn't create file" load(":test.bzl", "some_rule") some_rule( name = "dummy", ) EOF - cat >test/test.bzl <<'EOF' || fail "couldn't create file" + cat >$pkg/test.bzl <<'EOF' || fail "couldn't create file" def _rule_impl(ctx): pass @@ -155,12 +202,12 @@ some_aspect = aspect( EOF # Sanity check. - bazel build //test:dummy --aspects test/test.bzl%some_aspect \ + bazel build //$pkg:dummy --aspects $pkg/test.bzl%some_aspect \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In aspect: " "Did not find aspect print output" expect_not_log "$MARKER" "$sanity_fail_msg" - bazel build //test:dummy --aspects test/test.bzl%some_aspect \ + bazel build //$pkg:dummy --aspects $pkg/test.bzl%some_aspect \ --internal_skylark_flag_test_canary \ &>"$TEST_log" || fail "bazel build failed"; expect_log "In aspect: $MARKER" \ -- cgit v1.2.3