Skip to content

Commit

Permalink
[7.1.2] Do not watch .netrc in read_netrc (#22186)
Browse files Browse the repository at this point in the history
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

Commit
3fc76be

Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
bazel-io and fmeum authored May 6, 2024
1 parent a7c65af commit a01c443
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
12 changes: 6 additions & 6 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/test/shell/bazel/starlark_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,7 @@ EOF
cat > def.bzl <<'EOF'
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "use_netrc")
def _impl(ctx):
print("authrepo is being evaluated")
rc = read_netrc(ctx, ctx.attr.path)
auth = use_netrc(rc, ctx.attr.urls, {"oauthlife.com": "Bearer <password>",})
ctx.file("data.bzl", "auth = %s" % (auth,))
Expand Down Expand Up @@ -2058,9 +2059,16 @@ genrule(
cmd = "echo %s > $@" % (check_equal_expected(),)
)
EOF
bazel build //:check_expected
bazel build //:check_expected &> $TEST_log || fail "Expected success"
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
|| fail "Authentication merged incorrectly"
expect_log "authrepo is being evaluated"

echo "modified" > .netrc
bazel build //:check_expected &> $TEST_log || fail "Expected success"
grep 'OK' `bazel info bazel-bin`/check_expected.txt \
|| fail "Authentication information should not have been reevaluated"
expect_not_log "authrepo is being evaluated"
}

function test_disallow_unverified_http() {
Expand Down
14 changes: 7 additions & 7 deletions src/test/tools/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tools/build_defs/repo/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def read_netrc(ctx, filename):
dict mapping a machine names to a dict with the information provided
about them
"""
contents = ctx.read(filename)

# Do not cause the repo rule to rerun due to changes to auth info when it is
# successful. Failures are not cached.
contents = ctx.read(filename, watch = "no")
return parse_netrc(contents, filename)

def parse_netrc(contents, filename = None):
Expand Down

0 comments on commit a01c443

Please sign in to comment.