|
1 | 1 | "Implementation details for rb_bundle_fetch" |
2 | 2 |
|
3 | 3 | 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 | +) |
5 | 10 | load("//ruby/private:bundler_checksums.bzl", "BUNDLER_CHECKSUMS") |
6 | 11 | load( |
7 | 12 | "//ruby/private:utils.bzl", |
@@ -64,7 +69,7 @@ def _download_gem(repository_ctx, gem, cache_path, sha256 = None): |
64 | 69 | kwargs = {} |
65 | 70 | if sha256: |
66 | 71 | 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) |
68 | 73 | return download.sha256 |
69 | 74 |
|
70 | 75 | def _get_gem_executables(repository_ctx, gem, cache_path): |
@@ -234,6 +239,22 @@ def _rb_bundle_fetch_impl(repository_ctx): |
234 | 239 | } |
235 | 240 | return None |
236 | 241 |
|
| 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 | + |
237 | 258 | rb_bundle_fetch = repository_rule( |
238 | 259 | implementation = _rb_bundle_fetch_impl, |
239 | 260 | attrs = { |
|
0 commit comments