-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
1 changed file
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]>" -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 '[email protected]' \ | ||
&& git config user.name 'E X Ample' ) | ||
echo Hello World > gitdir/hello.txt | ||
(cd gitdir | ||
git add . | ||
git commit --author="A U Thor <[email protected]>" -m 'initial commit') | ||
echo Hello Stable World > gitdir/hello.txt | ||
(cd gitdir | ||
git checkout -b stable | ||
git add . | ||
git commit --author="A U Thor <[email protected]>" -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 <[email protected]>" -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 | ||
|