Skip to content

Commit

Permalink
Do not watch .netrc in read_netrc
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
  • Loading branch information
fmeum authored and copybara-github committed Apr 29, 2024
1 parent d0af714 commit 3fc76be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
8 changes: 4 additions & 4 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 @@ -1963,6 +1963,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 @@ -2044,9 +2045,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
16 changes: 8 additions & 8 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 3fc76be

Please sign in to comment.