Skip to content

Commit

Permalink
bazel sync: add a test verifying following branches
Browse files Browse the repository at this point in the history
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
aehlig authored and Copybara-Service committed Aug 13, 2018
1 parent 2cf2330 commit ca2733c
Showing 1 changed file with 78 additions and 4 deletions.
82 changes: 78 additions & 4 deletions src/test/shell/bazel/workspace_resolved_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ca2733c

Please sign in to comment.