#!/bin/bash # # Copyright 2015 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${CURRENT_DIR}/../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up() { LOCAL=$(pwd) REMOTE=$TEST_TMPDIR/remote # Set up empty remote repo. mkdir -p $REMOTE touch $REMOTE/WORKSPACE cat > $REMOTE/BUILD < $LOCAL/WORKSPACE < $LOCAL/BUILD < $REMOTE/BUILD < $TEST_log && fail "Build succeeded" expect_log "syntax error at 'ERROR'" cat > $REMOTE/BUILD < $TEST_log || fail "Build failed" assert_contains "I come from @a" bazel-genfiles/b.out } function test_external_file_changes_are_noticed() { version="1.0" cat > $REMOTE/input < $TEST_log || fail "Build failed" assert_contains $version bazel-genfiles/b.out version="2.0" cat > $REMOTE/input < $TEST_log || fail "Build failed" assert_contains $version bazel-genfiles/b.out } function test_symlink_changes_are_noticed() { cat > $REMOTE/version1 < $REMOTE/version2 < $TEST_log || fail "Build failed" assert_contains 1.0 bazel-genfiles/b.out rm $REMOTE/input ln -s $REMOTE/version2 $REMOTE/input bazel build //:b &> $TEST_log || fail "Build failed" assert_contains 2.0 bazel-genfiles/b.out } function test_parent_symlink_change() { REMOTE1=$TEST_TMPDIR/remote1 REMOTE2=$TEST_TMPDIR/remote2 mkdir -p $REMOTE1 $REMOTE2 cp -R $REMOTE/* $REMOTE1 cp -R $REMOTE/* $REMOTE2 cat > $REMOTE1/input < $REMOTE2/input < $TEST_log || fail "Build failed" assert_contains 1.0 bazel-genfiles/b.out rm $REMOTE ln -s $REMOTE2 $REMOTE bazel build //:b &> $TEST_log || fail "Build failed" assert_contains 2.0 bazel-genfiles/b.out } function test_genrule_d_correctness() { subdir=$REMOTE/b/c mkdir -p $subdir cat > $subdir/BUILD < $TEST_log || fail "Build failed" assert_contains "bazel-out/.*-fastbuild/.*/external/a/b/c" \ "bazel-genfiles/external/a/b/c/d" } function test_package_group_in_external_repos() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/v $REMOTE/a v a touch $REMOTE/WORKSPACE echo 'filegroup(name="rv", srcs=["//:fg"])' > $REMOTE/v/BUILD echo 'filegroup(name="ra", srcs=["//:fg"])' > $REMOTE/a/BUILD echo 'filegroup(name="mv", srcs=["@r//:fg"])' > v/BUILD echo 'filegroup(name="ma", srcs=["@r//:fg"])' > a/BUILD cat > $REMOTE/BUILD < WORKSPACE bazel build @r//v:rv >& $TEST_log || fail "Build failed" bazel build @r//a:ra >& $TEST_log && fail "Build succeeded" expect_log "target '@r//:fg' is not visible" bazel build //a:ma >& $TEST_log && fail "Build succeeded" expect_log "target '@r//:fg' is not visible" bazel build //v:mv >& $TEST_log && fail "Build succeeded" expect_log "target '@r//:fg' is not visible" } # Regression test for #517. function test_refs_btwn_repos() { REMOTE1=$TEST_TMPDIR/remote1 REMOTE2=$TEST_TMPDIR/remote2 mkdir -p $REMOTE1 $REMOTE2 touch $REMOTE1/WORKSPACE $REMOTE2/WORKSPACE cat > $REMOTE1/input < $REMOTE1/BUILD < $REMOTE2/BUILD < WORKSPACE < $TEST_log || fail "Build failed" assert_contains 1.0 bazel-genfiles/external/remote2/x.out } function test_visibility_attributes_in_external_repos() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/v $REMOTE/r touch $REMOTE/WORKSPACE cat > $REMOTE/r/BUILD < $REMOTE/v/BUILD <$REMOTE/BUILD < WORKSPACE < BUILD <& $TEST_log && fail "Build succeeded" expect_log "target '@r//r:fg1' is not visible" } function test_select_in_external_repo() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/a $REMOTE/c d touch $REMOTE/WORKSPACE cat > $REMOTE/a/BUILD <<'EOF' genrule( name = "gr", srcs = [], outs = ["gro"], cmd = select({ "//c:one": "echo one > $@", ":two": "echo two > $@", "@//d:three": "echo three > $@", "@//:four": "echo four > $@", "//conditions:default": "echo default > $@", })) config_setting(name = "two", values = { "define": "ARG=two" }) EOF cat > $REMOTE/c/BUILD < WORKSPACE < d/BUILD < BUILD < m/WORKSPACE <<'EOF' new_local_repository( name = "r", path = "../r", build_file_content = """ genrule( name = "fg", cmd = "ls $(SRCS) > $@", srcs=glob(["**"]), outs = ["fg.out"], )""", ) EOF cd m bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" touch ../r/three bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" assert_contains "external/r/three" bazel-genfiles/external/r/fg.out touch ../r/subdir/four bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" assert_contains "external/r/subdir/four" bazel-genfiles/external/r/fg.out } function test_top_level_dir_changes_batch() { top_level_dir_changes_helper --batch } function test_top_level_dir_changes_nobatch() { top_level_dir_changes_helper --nobatch } function test_non_extsietnt_repo_in_pattern() { bazel build @non_existent_repo//... &> $TEST_log && fail "Expected build to fail" expect_log "ERROR: No such repository '@non_existent_repo'" } run_suite "//external correctness tests"