aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-06-21 06:02:16 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-21 06:04:04 -0700
commite926cfc8f5ce4c6db666ceb7058bba263fbede36 (patch)
treec5d2c1752fce20ff13a9fd433df41ef00709c7da
parentdc986d290bad8a76d3429f73c8244376b4c59494 (diff)
shell tests, windows: enable more tests
Enable on Windows: //src/test/shell/bazel:bazel_experimental_ui_test //src/test/shell/bazel:bazel_random_characters_test Also document the (surprising) semantics of http_file() on Windows. See https://github.com/bazelbuild/bazel/issues/4292 Change-Id: Id636b9cf03cc8d12449eed2be493dcfc176146c7 Closes #5409. Change-Id: I15677548f2f3fd6b4822e8e6af4b78d8517f953a PiperOrigin-RevId: 201512812
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java31
-rw-r--r--src/test/shell/bazel/BUILD12
-rwxr-xr-xsrc/test/shell/bazel/bazel_experimental_ui_test.sh34
-rwxr-xr-xsrc/test/shell/bazel/bazel_random_characters_test.sh32
-rw-r--r--tools/build_defs/repo/http.bzl5
5 files changed, 90 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
index 4f13114982..63a4db1478 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
@@ -79,21 +79,26 @@ public class HttpFileRule implements RuleDefinition {
}
/*<!-- #BLAZE_RULE (NAME = http_file, TYPE = OTHER, FAMILY = Workspace)[GENERIC_RULE] -->
- <p>Downloads a file from a URL and makes it available to be used as a file group.</p>
+<p>Downloads a file from a URL and makes it available to be used as a file group.</p>
- <h4 id="http_file_examples">Examples</h4>
+<h4 id="http_file_examples">Examples</h4>
- <p>Suppose you need to have a debian package for your custom rules. This package is available from
- <i>http://example.com/package.deb</i>. Then you can add to your WORKSPACE file:</p>
+<p>Suppose you need to have a debian package for your custom rules. This package is available from
+<i>http://example.com/package.deb</i>. Then you can add to your WORKSPACE file:</p>
- <pre class="code">
- http_file(
- name = "my_deb",
- url = "http://example.com/package.deb",
- sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4",
- )
- </pre>
+<pre class="code">
+http_file(
+ name = "my_deb",
+ url = "http://example.com/package.deb",
+ sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4",
+)
+</pre>
- <p>Targets would specify <code>@my_deb//file</code> as a dependency to depend on this file.</p>
+<p>Targets would specify <code>@my_deb//file</code> as a dependency to depend on this file.</p>
- <!-- #END_BLAZE_RULE -->*/
+<p>You may also reference files on the current system (localhost) by using "file:///path/to/file"
+if you are on Unix-based systems. If you're on Windows, use "file:///c:/path/to/file". In both
+examples, note the three slashes (<code>/</code>) -- the first two slashes belong to
+<code>file://</code> and the third one belongs to the absolute path to the file.</p>
+
+<!-- #END_BLAZE_RULE -->*/
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 430a00add5..7fa364176b 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -108,8 +108,10 @@ sh_test(
name = "bazel_random_characters_test",
size = "large",
srcs = ["bazel_random_characters_test.sh"],
- data = [":test-deps"],
- tags = ["no_windows"],
+ data = [
+ ":test-deps",
+ "@bazel_tools//tools/bash/runfiles",
+ ],
)
sh_test(
@@ -133,8 +135,10 @@ sh_test(
name = "bazel_experimental_ui_test",
size = "medium",
srcs = ["bazel_experimental_ui_test.sh"],
- data = [":test-deps"],
- tags = ["no_windows"],
+ data = [
+ ":test-deps",
+ "@bazel_tools//tools/bash/runfiles",
+ ],
)
sh_test(
diff --git a/src/test/shell/bazel/bazel_experimental_ui_test.sh b/src/test/shell/bazel/bazel_experimental_ui_test.sh
index e2fb24dcac..b9a0607103 100755
--- a/src/test/shell/bazel/bazel_experimental_ui_test.sh
+++ b/src/test/shell/bazel/bazel_experimental_ui_test.sh
@@ -16,9 +16,29 @@
#
# An end-to-end test that Bazel's experimental UI produces reasonable output.
-# Load the test setup defined in the parent directory
-CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-source "${CURRENT_DIR}/../integration_test_setup.sh" \
+set -euo pipefail
+# --- begin runfiles.bash initialization ---
+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; }
#### SETUP #############################################################
@@ -31,8 +51,14 @@ add_to_bazelrc "test --test_strategy=standalone"
function set_up() {
mkdir -p pkg
touch remote_file
+ if is_windows; then
+ # The correct syntax for http_file on Windows is "file:///c:/foo/bar.txt"
+ local -r cwd="/$(cygpath -m "$PWD")"
+ else
+ local -r cwd="$PWD"
+ fi
cat > WORKSPACE <<EOF
-http_file(name="remote", urls=["file://`pwd`/remote_file"])
+http_file(name="remote", urls=["file://${cwd}/remote_file"])
EOF
touch BUILD
}
diff --git a/src/test/shell/bazel/bazel_random_characters_test.sh b/src/test/shell/bazel/bazel_random_characters_test.sh
index 59f4b89138..bc69203f64 100755
--- a/src/test/shell/bazel/bazel_random_characters_test.sh
+++ b/src/test/shell/bazel/bazel_random_characters_test.sh
@@ -17,11 +17,37 @@
# Tests the examples provided in Bazel
#
-# Load the test setup defined in the parent directory
-CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-source "${CURRENT_DIR}/../integration_test_setup.sh" \
+set -euo pipefail
+# --- begin runfiles.bash initialization ---
+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; }
+# Disable MSYS path conversions, so that
+# "bazel build //foo" won't become "bazel build /foo", nor will
+# "bazel build foo/bar" become "bazel build foo\bar".
+export MSYS_NO_PATHCONV=1
+export MSYS2_ARG_CONV_EXCL="*"
+
function basic_glob_scenario_test_template() {
local chars="$1"
local pkg="pkg${chars}"
diff --git a/tools/build_defs/repo/http.bzl b/tools/build_defs/repo/http.bzl
index fffe226d7f..727d3a753b 100644
--- a/tools/build_defs/repo/http.bzl
+++ b/tools/build_defs/repo/http.bzl
@@ -316,6 +316,11 @@ Examples:
Targets would specify <code>@my_ssl//jar</code> as a dependency to depend on this jar.
+ You may also reference files on the current system (localhost) by using "file:///path/to/file"
+ if you are on Unix-based systems. If you're on Windows, use "file:///c:/path/to/file". In both
+ examples, note the three slashes (`/`) -- the first two slashes belong to `file://` and the third
+ one belongs to the absolute path to the file.
+
Args:
name: A unique name for this rule.