Skip to content

Commit 5848f74

Browse files
fmeumbazel-io
authored andcommitted
Do not watch .netrc in read_netrc
Modifying auth information should not result in a repo rule being reevaluated after a successful evaluation. This regressed in a5376aa. Fixes bazelbuild#22118 Closes bazelbuild#22125. PiperOrigin-RevId: 629182408 Change-Id: I0c553e9ded72230b647a37203d51ba779976d7fc
1 parent 1ab19fe commit 5848f74

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

MODULE.bazel.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/shell/bazel/starlark_repository_test.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ EOF
19771977
cat > def.bzl <<'EOF'
19781978
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "use_netrc")
19791979
def _impl(ctx):
1980+
print("authrepo is being evaluated")
19801981
rc = read_netrc(ctx, ctx.attr.path)
19811982
auth = use_netrc(rc, ctx.attr.urls, {"oauthlife.com": "Bearer <password>",})
19821983
ctx.file("data.bzl", "auth = %s" % (auth,))
@@ -2058,9 +2059,16 @@ genrule(
20582059
cmd = "echo %s > $@" % (check_equal_expected(),)
20592060
)
20602061
EOF
2061-
bazel build //:check_expected
2062+
bazel build //:check_expected &> $TEST_log || fail "Expected success"
20622063
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
20632064
|| fail "Authentication merged incorrectly"
2065+
expect_log "authrepo is being evaluated"
2066+
2067+
echo "modified" > .netrc
2068+
bazel build //:check_expected &> $TEST_log || fail "Expected success"
2069+
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
2070+
|| fail "Authentication information should not have been reevaluated"
2071+
expect_not_log "authrepo is being evaluated"
20642072
}
20652073

20662074
function test_disallow_unverified_http() {

src/test/tools/bzlmod/MODULE.bazel.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/build_defs/repo/utils.bzl

+4-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ def read_netrc(ctx, filename):
251251
dict mapping a machine names to a dict with the information provided
252252
about them
253253
"""
254-
contents = ctx.read(filename)
254+
255+
# Do not cause the repo rule to rerun due to changes to auth info when it is
256+
# successful. Failures are not cached.
257+
contents = ctx.read(filename, watch = "no")
255258
return parse_netrc(contents, filename)
256259

257260
def parse_netrc(contents, filename = None):

0 commit comments

Comments
 (0)