Files
openide/lib/http-lib.bzl
Vladimir Krivosheev 98799639aa do not use _test as lib - test targets do not support this
GitOrigin-RevId: f2f49db4294b6a64040dbbd5f1d95e972cbd70a3
2024-12-15 18:32:30 +00:00

53 lines
1.4 KiB
Python

load("@bazel_tools//tools/build_defs/repo:cache.bzl", "CANONICAL_ID_DOC", "DEFAULT_CANONICAL_ID_ENV", "get_default_canonical_id")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
_HTTP_JAR_BUILD = """\
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_import")
kt_jvm_import(
name = "jar",
jar = "{jar}",
visibility = ["//visibility:public"],
)
"""
def _http_jvm_lib(ctx):
url = ctx.attr.url
urls = [url]
downloaded_file_name = ctx.attr.downloaded_file_name
if len(downloaded_file_name) == 0:
downloaded_file_name = url.split("/")[-1]
if not downloaded_file_name.endswith(".jar"):
fail("downloaded_file_name must have .jar extension")
ctx.download(
urls,
downloaded_file_name,
ctx.attr.sha256,
canonical_id = get_default_canonical_id(ctx, urls),
auth = get_auth(ctx, urls),
)
ctx.file("BUILD", _HTTP_JAR_BUILD.format(
jar = downloaded_file_name,
))
return None
_http_jar_attrs = {
"sha256": attr.string(mandatory = True),
"url": attr.string(mandatory = True),
"netrc": attr.string(doc = "Location of the .netrc file to use for authentication"),
"auth_patterns": attr.string_dict(),
"downloaded_file_name": attr.string(
default = "",
doc = "Filename assigned to the jar downloaded",
),
}
http_jvm_lib = repository_rule(
implementation = _http_jvm_lib,
attrs = _http_jar_attrs,
environ = [DEFAULT_CANONICAL_ID_ENV],
)