Skip to content

Commit 3fc76be

Browse files
fmeumcopybara-github
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 #22118 Closes #22125. PiperOrigin-RevId: 629182408 Change-Id: I0c553e9ded72230b647a37203d51ba779976d7fc
1 parent d0af714 commit 3fc76be

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

MODULE.bazel.lock

Lines changed: 4 additions & 4 deletions
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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,7 @@ EOF
19631963
cat > def.bzl <<'EOF'
19641964
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "use_netrc")
19651965
def _impl(ctx):
1966+
print("authrepo is being evaluated")
19661967
rc = read_netrc(ctx, ctx.attr.path)
19671968
auth = use_netrc(rc, ctx.attr.urls, {"oauthlife.com": "Bearer <password>",})
19681969
ctx.file("data.bzl", "auth = %s" % (auth,))
@@ -2044,9 +2045,16 @@ genrule(
20442045
cmd = "echo %s > $@" % (check_equal_expected(),)
20452046
)
20462047
EOF
2047-
bazel build //:check_expected
2048+
bazel build //:check_expected &> $TEST_log || fail "Expected success"
20482049
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
20492050
|| fail "Authentication merged incorrectly"
2051+
expect_log "authrepo is being evaluated"
2052+
2053+
echo "modified" > .netrc
2054+
bazel build //:check_expected &> $TEST_log || fail "Expected success"
2055+
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
2056+
|| fail "Authentication information should not have been reevaluated"
2057+
expect_not_log "authrepo is being evaluated"
20502058
}
20512059

20522060
function test_disallow_unverified_http() {

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

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/build_defs/repo/utils.bzl

Lines changed: 4 additions & 1 deletion
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)