Skip to content

Commit

Permalink
Add tests for the Skylark-based implementation of git repository rules.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#3825.

Change-Id: I59cb0edb50af30991153a1a684e613853df22dd2
PiperOrigin-RevId: 171687620
  • Loading branch information
katre authored and hlopko committed Oct 11, 2017
1 parent 00d128c commit 61c97c0
Show file tree
Hide file tree
Showing 4 changed files with 488 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ sh_test(
],
)

sh_test(
name = "skylark_git_repository_test",
size = "large",
srcs = ["skylark_git_repository_test.sh"],
data = [
":test-deps",
"//src/test/shell/bazel/testdata:git-repos",
],
)

sh_test(
name = "local_repository_test",
size = "large",
Expand Down
30 changes: 21 additions & 9 deletions src/test/shell/bazel/git_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ new_git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
tag = "0-initial",
build_file = "pluto.BUILD",
build_file = "//:pluto.BUILD",
)
EOF

cat > BUILD <<EOF
exports_files(['pluto.BUILD'])
EOF
cat > pluto.BUILD <<EOF
filegroup(
name = "pluto",
Expand Down Expand Up @@ -215,10 +218,13 @@ new_git_repository(
remote = "$outer_planets_repo_dir",
tag = "1-submodule",
init_submodules = 1,
build_file = "outer_planets.BUILD",
build_file = "//:outer_planets.BUILD",
)
EOF

cat > BUILD <<EOF
exports_files(['outer_planets.BUILD'])
EOF
cat > outer_planets.BUILD <<EOF
filegroup(
name = "neptune",
Expand Down Expand Up @@ -266,30 +272,35 @@ function test_git_repository_not_refetched_on_server_restart() {
git_repository(name='g', remote='$repo_dir', commit='f0b79ff0')
EOF

bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
# Use batch to force server restarts.
bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_log "Cloning"
assert_contains "GIT 1" bazel-genfiles/external/g/go
bazel --batch build @g//:g >& $TEST_log || fail "Build failed"

# Without changing anything, restart the server, which should not cause the checkout to be re-cloned.
bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_not_log "Cloning"
assert_contains "GIT 1" bazel-genfiles/external/g/go

# Change the commit id, which should cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
git_repository(name='g', remote='$repo_dir', commit='62777acc')
EOF

bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_log "Cloning"
assert_contains "GIT 2" bazel-genfiles/external/g/go

# Change the WORKSPACE but not the commit id, which should not cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
# This comment line is to change the line numbers, which should not cause Bazel
# to refetch the repository
git_repository(name='g', remote='$repo_dir', commit='62777acc')
EOF

bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_not_log "Cloning"
assert_contains "GIT 2" bazel-genfiles/external/g/go

}


Expand All @@ -301,16 +312,17 @@ function test_git_repository_refetched_when_commit_changes() {
git_repository(name='g', remote='$repo_dir', commit='f0b79ff0')
EOF

bazel build @g//:g >& $TEST_log || fail "Build failed"
bazel build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_log "Cloning"
assert_contains "GIT 1" bazel-genfiles/external/g/go

# Change the commit id, which should cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
git_repository(name='g', remote='$repo_dir', commit='62777acc')
EOF


bazel build @g//:g >& $TEST_log || fail "Build failed"
bazel build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
expect_log "Cloning"
assert_contains "GIT 2" bazel-genfiles/external/g/go
}
Expand Down
Loading

0 comments on commit 61c97c0

Please sign in to comment.