aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-02-01 06:55:56 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-01 06:57:25 -0800
commit5a50a7c403e567b850d5037d1ee0dad96be0b39d (patch)
tree30dbf38a3f2d0da6c362d6387f2f5ea720abbda8 /src
parent109e4b4dc9e786e3a2d8d7cb245d18320dbe9216 (diff)
http_archive: allow top-level BUILD files to be overridden
..by the `build_file` parameter, even if the external repository contains a top-level BUILD file. While there, also add a test verifying that this is also possible via the `build_file_content`. Change-Id: I1b875c147cfcd6f1c70b8efeb10c2b406eeacf6a PiperOrigin-RevId: 184134041
Diffstat (limited to 'src')
-rwxr-xr-xsrc/test/shell/bazel/external_patching_test.sh172
1 files changed, 172 insertions, 0 deletions
diff --git a/src/test/shell/bazel/external_patching_test.sh b/src/test/shell/bazel/external_patching_test.sh
index fd9c807f00..1458b2d886 100755
--- a/src/test/shell/bazel/external_patching_test.sh
+++ b/src/test/shell/bazel/external_patching_test.sh
@@ -25,6 +25,8 @@ source "${CURRENT_DIR}/remote_helpers.sh" \
set_up() {
+ WRKDIR=$(mktemp -d "${TEST_TMPDIR}/testXXXXXX")
+ cd "${WRKDIR}"
# create an archive file with files interesting for patching
mkdir ext-0.1.2
cat > ext-0.1.2/foo.sh <<'EOF'
@@ -108,4 +110,174 @@ EOF
grep -q 'env' $foopath || fail "expected unpatched file"
}
+test_override_buildfile() {
+ ## Verify that the BUILD file of an external repository can be overriden
+ ## via the http_archive rule.
+ EXTREPODIR=`pwd`
+
+ mkdir withbuild
+ cat > withbuild/BUILD <<'EOF'
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp $< $@ && echo BAD >> $@",
+)
+EOF
+ cat > withbuild/file.txt <<'EOF'
+from external repo
+EOF
+ zip withbuild.zip withbuild/*
+ rm -rf withbuild
+
+ mkdir main
+ cd main
+ cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name="withbuild",
+ strip_prefix="withbuild",
+ urls=["file://${EXTREPODIR}/withbuild.zip"],
+ build_file="@//:ext.BUILD",
+)
+EOF
+ cat > BUILD <<'EOF'
+genrule(
+ name = "local",
+ outs = ["local.txt"],
+ srcs = ["@withbuild//:target"],
+ cmd = "cp $< $@",
+)
+EOF
+ cat > ext.BUILD <<'EOF'
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp $< $@ && echo GOOD >> $@",
+ visibility=["//visibility:public"],
+)
+EOF
+
+ bazel build //:local || fail "Expected success"
+
+ cat `bazel info bazel-genfiles`/local.txt > "${TEST_log}"
+ expect_log "from external repo"
+ expect_log "GOOD"
+ expect_not_log "BAD"
+}
+
+test_override_buildfile_content() {
+ ## Verify that the BUILD file of an external repository can be overriden
+ ## via specified content in the http_archive rule.
+ EXTREPODIR=`pwd`
+
+ mkdir withbuild
+ cat > withbuild/BUILD <<'EOF'
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp $< $@ && echo BAD >> $@",
+)
+EOF
+ cat > withbuild/file.txt <<'EOF'
+from external repo
+EOF
+ zip withbuild.zip withbuild/*
+ rm -rf withbuild
+
+ mkdir main
+ cd main
+ cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name="withbuild",
+ strip_prefix="withbuild",
+ urls=["file://${EXTREPODIR}/withbuild.zip"],
+ build_file_content="""
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp \$< \$@ && echo GOOD >> \$@",
+ visibility=["//visibility:public"],
+)
+ """,
+)
+EOF
+ cat > BUILD <<'EOF'
+genrule(
+ name = "local",
+ outs = ["local.txt"],
+ srcs = ["@withbuild//:target"],
+ cmd = "cp $< $@",
+)
+EOF
+
+ bazel build //:local || fail "Expected success"
+
+ cat `bazel info bazel-genfiles`/local.txt > "${TEST_log}"
+ expect_log "from external repo"
+ expect_log "GOOD"
+ expect_not_log "BAD"
+}
+
+test_build_file_build_bazel() {
+ ## Verify that the BUILD file of an external repository can be overriden
+ ## via the http_archive rule.
+ EXTREPODIR=`pwd`
+
+ mkdir withbuild
+ cat > withbuild/BUILD.bazel <<'EOF'
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp $< $@ && echo BAD >> $@",
+)
+EOF
+ cat > withbuild/file.txt <<'EOF'
+from external repo
+EOF
+ zip withbuild.zip withbuild/*
+ rm -rf withbuild
+
+ mkdir main
+ cd main
+ cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name="withbuild",
+ strip_prefix="withbuild",
+ urls=["file://${EXTREPODIR}/withbuild.zip"],
+ build_file="@//:ext.BUILD",
+)
+EOF
+ cat > BUILD <<'EOF'
+genrule(
+ name = "local",
+ outs = ["local.txt"],
+ srcs = ["@withbuild//:target"],
+ cmd = "cp $< $@",
+)
+EOF
+ cat > ext.BUILD <<'EOF'
+genrule(
+ name="target",
+ srcs=["file.txt"],
+ outs=["target.txt"],
+ cmd="cp $< $@ && echo GOOD >> $@",
+ visibility=["//visibility:public"],
+)
+EOF
+
+ bazel build //:local || fail "Expected success"
+
+ cat `bazel info bazel-genfiles`/local.txt > "${TEST_log}"
+ expect_log "from external repo"
+ expect_log "GOOD"
+ expect_not_log "BAD"
+}
+
run_suite "external patching tests"