aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar brandjon <brandjon@google.com>2017-10-23 19:02:31 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-24 10:39:30 +0200
commitdbff8b81bec72dd0f8a2fef825128e5f33c650d0 (patch)
tree68ba03941dfb5647a567848252b9f98033395b54 /src/test/shell
parente287d4bf333e412033c8f484018cc431100eeee6 (diff)
Propagate skylark flags to WORKSPACE and repo rules
RELNOTES: Skylark semantics flags now affect WORKSPACE files and repository rules. PiperOrigin-RevId: 173130286
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/skylark_repository_test.sh22
-rwxr-xr-xsrc/test/shell/bazel/workspace_test.sh26
2 files changed, 48 insertions, 0 deletions
diff --git a/src/test/shell/bazel/skylark_repository_test.sh b/src/test/shell/bazel/skylark_repository_test.sh
index c1d9608fea..72c08bb8cf 100755
--- a/src/test/shell/bazel/skylark_repository_test.sh
+++ b/src/test/shell/bazel/skylark_repository_test.sh
@@ -24,6 +24,8 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
source "${CURRENT_DIR}/remote_helpers.sh" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
+SKYLARK_FLAG_MARKER="<== skylark flag test ==>"
+
# Basic test.
function test_macro_local_repository() {
create_new_workspace
@@ -334,6 +336,26 @@ EOF
cat > BUILD
}
+function test_skylark_flags_affect_repository_rule() {
+ setup_skylark_repository
+
+ cat >test.bzl <<EOF
+def _impl(repository_ctx):
+ print("In repo rule: ")
+ # Symlink so a repository is created
+ repository_ctx.symlink(repository_ctx.path("$repo2"), repository_ctx.path(""))
+
+repo = repository_rule(implementation=_impl, local=True)
+EOF
+
+ # Build with the special testing flag that appends a marker string to all
+ # print() calls.
+ bazel build @foo//:bar --internal_skylark_flag_test_canary >& $TEST_log \
+ || fail "Expected build to succeed"
+ expect_log "In repo rule: $SKYLARK_FLAG_MARKER" \
+ "Skylark flags are not propagating to repository rules"
+}
+
function test_skylark_repository_which_and_execute() {
setup_skylark_repository
diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh
index 5b4b7de3db..bd0010564d 100755
--- a/src/test/shell/bazel/workspace_test.sh
+++ b/src/test/shell/bazel/workspace_test.sh
@@ -21,6 +21,8 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
export JAVA_RUNFILES=$BAZEL_RUNFILES
+SKYLARK_FLAG_MARKER="<== skylark flag test ==>"
+
function setup_repo() {
mkdir -p $1
touch $1/WORKSPACE
@@ -173,6 +175,30 @@ EOF
[ ! -L bazel-x ] || fail "bazel-x should have been removed"
}
+function test_skylark_flags_affect_workspace() {
+ cat > WORKSPACE <<EOF
+load("//:macro.bzl", "macro")
+print("In workspace: ")
+macro()
+EOF
+ cat > macro.bzl <<EOF
+def macro():
+ print("In workspace macro: ")
+EOF
+ cat > BUILD <<'EOF'
+genrule(name = "x", cmd = "echo hi > $@", outs = ["x.out"], srcs = [])
+EOF
+
+ # Build with the special testing flag that appends a marker string to all
+ # print() calls.
+ bazel build //:x --internal_skylark_flag_test_canary &>"$TEST_log" \
+ || fail "Expected build to succeed"
+ expect_log "In workspace: $SKYLARK_FLAG_MARKER" \
+ "Skylark flags are not propagating to workspace evaluation"
+ expect_log "In workspace macro: $SKYLARK_FLAG_MARKER" \
+ "Skylark flags are not propagating to workspace macro evaluation"
+}
+
function test_workspace_name() {
mkdir -p foo
mkdir -p bar