diff options
-rwxr-xr-x | src/test/shell/bazel/external_integration_test.sh | 9 | ||||
-rw-r--r-- | tools/build_defs/repo/http.bzl | 27 |
2 files changed, 31 insertions, 5 deletions
diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index 451c49e809..9356fd8e75 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -123,6 +123,7 @@ EOF cd ${WORKSPACE_DIR} if [[ $write_workspace = 0 ]]; then cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = 'endangered', url = 'http://127.0.0.1:$nc_port/$repo2_name', @@ -181,6 +182,7 @@ function test_http_archive_zip() { # Test with the extension serve_file $repo2_zip cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = 'endangered', url = 'http://127.0.0.1:$nc_port/bleh', @@ -206,6 +208,7 @@ function test_http_archive_tar_xz() { function test_http_archive_no_server() { cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive(name = 'endangered', url = 'http://bad.example/repo.zip', sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826') EOF @@ -242,6 +245,7 @@ function test_http_archive_mismatched_sha256() { cd ${WORKSPACE_DIR} cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = 'endangered', url = 'http://127.0.0.1:$nc_port/repo.zip', @@ -469,6 +473,7 @@ function test_empty_file() { serve_file x.tar.gz cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") new_http_archive( name = "x", url = "http://127.0.0.1:$nc_port/x.tar.gz", @@ -853,6 +858,7 @@ local_repository( ) EOF cat > remote_ws <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "repo", url = "http://127.0.0.1:$fileserver_port/repo.zip", @@ -883,6 +889,7 @@ function test_sha256_weird() { cd - cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "repo", sha256 = "a random string", @@ -904,6 +911,7 @@ function test_sha256_incorrect() { cd - cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "repo", sha256 = "61a6f762aaf60652cbf332879b8dcc2cfd81be2129a061da957d039eae77f0b0", @@ -929,6 +937,7 @@ function test_same_name() { mkdir main cd main cat > WORKSPACE <<EOF +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") new_http_archive( name="ext", strip_prefix="ext", diff --git a/tools/build_defs/repo/http.bzl b/tools/build_defs/repo/http.bzl index ade8f68889..051466b329 100644 --- a/tools/build_defs/repo/http.bzl +++ b/tools/build_defs/repo/http.bzl @@ -47,6 +47,8 @@ def _patch(ctx): def _http_archive_impl(ctx): """Implementation of the http_archive rule.""" + if not ctx.attr.url and not ctx.attr.urls: + ctx.fail("At least of of url and urls must be provided") if ctx.attr.build_file and ctx.attr.build_file_content: ctx.fail("Only one of build_file and build_file_content can be provided.") @@ -62,7 +64,13 @@ def _http_archive_impl(ctx): for patchfile in ctx.attr.patches: print("patch file %s, path %s" % (patchfile, ctx.path(patchfile))) - ctx.download_and_extract(ctx.attr.urls, "", ctx.attr.sha256, ctx.attr.type, + all_urls = [] + if ctx.attr.urls: + all_urls = ctx.attr.urls + if ctx.attr.url: + all_urls = [ctx.attr.url] + all_urls + + ctx.download_and_extract(all_urls, "", ctx.attr.sha256, ctx.attr.type, ctx.attr.strip_prefix) _patch(ctx) ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name=ctx.name)) @@ -94,7 +102,8 @@ def _http_file_impl(ctx): _http_archive_attrs = { - "urls": attr.string_list(mandatory=True), + "url": attr.string(), + "urls": attr.string_list(), "sha256": attr.string(), "strip_prefix": attr.string(), "type": attr.string(), @@ -198,10 +207,18 @@ Args: URL. If the file has no extension, you can explicitly specify one of the following: `"zip"`, `"jar"`, `"war"`, `"tar.gz"`, `"tgz"`, `"tar.xz"`, or `tar.bz2`. - urls: A URL to a file that will be made available to Bazel. + url: A URL to a file that will be made available to Bazel. This must be an file, http or https URL. Redirections are followed. Authentication is not supported. + + This parameter is to simplify the transition from the native http_archive + rule. More flexibility can be achieved by the urls parameter that allows + to specify alternative URLs to fetch from. + urls: A list of URLs to a file that will be made available to Bazel. + + Each entry must be an file, http or https URL. Redirections are followed. + Authentication is not supported. patches: A list of files that are to be applied as patches after extracting the archive. patch_tool: the patch(1) utility to use. @@ -245,8 +262,8 @@ Args: to omit the SHA-256 as remote files can change._ At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. - urls: A URL to a file that will be made available to Bazel. + urls: A list of URLs to a file that will be made available to Bazel. - This must be an file, http, or https URL. Redirections are followed. + Each entry must be an file, http or https URL. Redirections are followed. Authentication is not supported. """ |