Skip to content

Commit fbb77a4

Browse files
committed
fix: support netrc auth on bazel 6
1 parent 09495d9 commit fbb77a4

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

ruby/private/bundle_fetch.bzl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"Implementation details for rb_bundle_fetch"
22

33
load("@bazel_skylib//lib:versions.bzl", "versions")
4-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
4+
load(
5+
"@bazel_tools//tools/build_defs/repo:utils.bzl",
6+
"read_netrc",
7+
"read_user_netrc",
8+
"use_netrc",
9+
)
510
load("//ruby/private:bundler_checksums.bzl", "BUNDLER_CHECKSUMS")
611
load(
712
"//ruby/private:utils.bzl",
@@ -64,7 +69,7 @@ def _download_gem(repository_ctx, gem, cache_path, sha256 = None):
6469
kwargs = {}
6570
if sha256:
6671
kwargs["sha256"] = sha256
67-
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), auth = get_auth(repository_ctx, [url]), **kwargs)
72+
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), auth = _get_auth(repository_ctx, [url]), **kwargs)
6873
return download.sha256
6974

7075
def _get_gem_executables(repository_ctx, gem, cache_path):
@@ -234,6 +239,22 @@ def _rb_bundle_fetch_impl(repository_ctx):
234239
}
235240
return None
236241

242+
# The function is copied from the main branch of bazel_tools.
243+
# It should become available there from version 7.1.0,
244+
# We should remove this function when we upgrade minimum supported version to 7.1.0.
245+
# https://github.com/bazelbuild/bazel/blob/d37762b494a4e122d46a5a71e3a8cc77fa15aa25/tools/build_defs/repo/utils.bzl#L424-L446
246+
def _get_auth(ctx, urls):
247+
if hasattr(ctx.attr, "netrc") and ctx.attr.netrc:
248+
netrc = read_netrc(ctx, ctx.attr.netrc)
249+
elif "NETRC" in ctx.os.environ:
250+
netrc = read_netrc(ctx, ctx.os.environ["NETRC"])
251+
else:
252+
netrc = read_user_netrc(ctx)
253+
auth_patterns = {}
254+
if hasattr(ctx.attr, "auth_patterns") and ctx.attr.auth_patterns:
255+
auth_patterns = ctx.attr.auth_patterns
256+
return use_netrc(netrc, urls, auth_patterns)
257+
237258
rb_bundle_fetch = repository_rule(
238259
implementation = _rb_bundle_fetch_impl,
239260
attrs = {

0 commit comments

Comments
 (0)