From ca2733c3ec4d0d5ebfe6b3c4b8dcee3c8855cf6b Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 13 Aug 2018 05:08:47 -0700 Subject: 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 --- src/test/shell/bazel/workspace_resolved_test.sh | 82 +++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'src') 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 @@ -190,12 +190,19 @@ new_git_repository( branch="master", 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 " -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 " -m 'initial commit') + echo Hello Stable World > gitdir/hello.txt + (cd gitdir + git checkout -b stable + git add . + git commit --author="A U Thor " -m 'stable commit') + + # Follow the stable branch of the git repository + mkdir followbranch + cat > followbranch/WORKSPACE < 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 " -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 -- cgit v1.2.3