diff options
author | Klaus Aehlig <aehlig@google.com> | 2018-08-13 05:08:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-13 05:10:50 -0700 |
commit | ca2733c3ec4d0d5ebfe6b3c4b8dcee3c8855cf6b (patch) | |
tree | fe58c7c5a8e46781e0b105faa57940fbec7538e3 | |
parent | 2cf23303144969fd66d88dd105b09d17fda989d0 (diff) |
bazel sync: add a test verifying following branches
Add a test verifying that bazel sync can be used to follow a branch
of an upstream git repository. As this is a standard use case for
bazel sync, we better verify it works properly.
Change-Id: Ia08686376e6c7a89e7f1c130129b46764e43918b
PiperOrigin-RevId: 208464247
-rwxr-xr-x | src/test/shell/bazel/workspace_resolved_test.sh | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/src/test/shell/bazel/workspace_resolved_test.sh b/src/test/shell/bazel/workspace_resolved_test.sh index cfcd485944..8ab05e34b9 100755 --- a/src/test/shell/bazel/workspace_resolved_test.sh +++ b/src/test/shell/bazel/workspace_resolved_test.sh @@ -191,11 +191,18 @@ new_git_repository( build_file_content="exports_files([\"hello.txt\"])", ) EOF + cat > BUILD <<'EOF' +genrule( + name = "out", + outs = ["out.txt"], + srcs = ["@ext//:hello.txt"], + cmd = "cp $< $@", +) +EOF bazel sync --experimental_repository_resolved_file=../repo.bzl - # some of the file systems on our test machines are really slow to - # notice the creation of a file---even after the call to sync(1). - bazel shutdown; sync; sleep 10 - + bazel build :out + grep "CHANGED" `bazel info bazel-genfiles`/out.txt \ + && fail "Unexpected content in out.txt" || : cd .. echo; cat repo.bzl; echo @@ -205,6 +212,17 @@ EOF git add . git commit --author="A U Thor <author@example.com>" -m 'change hello.txt') + + # First verify that `bazel sync` sees the new commit (we don't record it). + cd branchcheckout + bazel sync + bazel build :out + grep "CHANGED" `bazel info bazel-genfiles`/out.txt \ + || fail "sync did not update the external repository" + bazel shutdown; sync; sleep 10 + cd .. + echo + # Verify that the recorded resolved information is what we expect. In # particular, verify that we don't get the new upstream commit. mkdir analysisrepo @@ -238,6 +256,62 @@ EOF && fail "not taking the frozen commit" || : } +test_sync_follows_git_branch() { + EXTREPODIR=`pwd` + export GIT_CONFIG_NOSYSTEM=YES + + rm -f gitdir + mkdir gitdir + (cd gitdir && git init \ + && git config user.email 'me@example.com' \ + && git config user.name 'E X Ample' ) + echo Hello World > gitdir/hello.txt + (cd gitdir + git add . + git commit --author="A U Thor <author@example.com>" -m 'initial commit') + echo Hello Stable World > gitdir/hello.txt + (cd gitdir + git checkout -b stable + git add . + git commit --author="A U Thor <author@example.com>" -m 'stable commit') + + # Follow the stable branch of the git repository + mkdir followbranch + cat > followbranch/WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") +new_git_repository( + name="ext", + remote="file://${EXTREPODIR}/gitdir/.git", + branch="stable", + build_file_content="exports_files([\"hello.txt\"])", +) +EOF + cat > followbranch/BUILD <<'EOF' +genrule( + name = "out", + outs = ["out.txt"], + srcs = ["@ext//:hello.txt"], + cmd = "cp $< $@", +) +EOF + (cd followbranch && bazel build :out \ + && cat `bazel info bazel-genfiles`/out.txt > "${TEST_log}") + expect_log 'Hello Stable World' + + # New upstream commits on the branch followed + echo CHANGED > gitdir/hello.txt + (cd gitdir + git checkout stable + git add . + git commit --author="A U Thor <author@example.com>" -m 'stable commit') + + # Verify that sync followed by build gets the correct version + (cd followbranch && bazel sync && bazel build :out \ + && cat `bazel info bazel-genfiles`/out.txt > "${TEST_log}") + expect_log 'CHANGED' + expect_not_log 'Hello Stable World' +} + test_sync_calls_all() { mkdir sync_calls_all && cd sync_calls_all |