Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for netrc in jvm_maven_import_external #1509

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scala/scala_maven_import_external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ the following macros are defined below that utilize jvm_import_external:
- java_import_external - to demonstrate that the original functionality of `java_import_external` stayed intact.
"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "read_user_netrc", "use_netrc")

# https://github.com/bazelbuild/bazel/issues/13709#issuecomment-1336699672
def _get_auth(ctx, urls):
"""Given the list of URLs obtain the correct auth dict."""
if ctx.attr.netrc:
netrc = read_netrc(ctx, ctx.attr.netrc)
else:
netrc = read_user_netrc(ctx)
return use_netrc(netrc, urls, ctx.attr.auth_patterns)

_HEADER = "# DO NOT EDIT: generated by jvm_import_external()"
_PASS_PROPS = (
"neverlink",
Expand Down Expand Up @@ -109,7 +120,7 @@ def _jvm_import_external(repository_ctx):
lines.append(extra)
if not extra.endswith("\n"):
lines.append("")
repository_ctx.download(urls, path, sha)
repository_ctx.download(urls, path, sha, auth = _get_auth(repository_ctx, urls))
if srcurls and _should_fetch_sources_in_current_env(repository_ctx):
repository_ctx.download(srcurls, srcpath, srcsha)
repository_ctx.file("BUILD", "\n".join(lines))
Expand Down Expand Up @@ -227,6 +238,8 @@ jvm_import_external = repository_rule(
default = ["//visibility:public"],
),
"extra_build_file_content": attr.string(),
"auth_patterns": attr.string_dict(),
"netrc": attr.string(),
},
environ = [_FETCH_SOURCES_ENV_VAR_NAME],
)
Expand Down