From 855c4c0ee34257b98ce2d01121940efb5423a059 Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Thu, 25 Feb 2021 12:59:15 -0800 Subject: [PATCH] Allow other mirrors in tf_http_archive(urls) and move check to macro so it gets evaluated even if the external repository is not used. PiperOrigin-RevId: 359592620 Change-Id: I0c17e164f3f29f0fd0334f88a2192a97c5284e51 --- third_party/repo.bzl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/third_party/repo.bzl b/third_party/repo.bzl index 965d51d3a41..38a8805f31c 100644 --- a/third_party/repo.bzl +++ b/third_party/repo.bzl @@ -34,14 +34,6 @@ def _get_link_dict(ctx, link_files, build_file): return {ctx.path(v): Label(k) for k, v in link_files.items()} def _tf_http_archive_impl(ctx): - # if len(ctx.attr.urls) < 2 or "mirror.tensorflow.org" not in ctx.attr.urls[0]: - if False: # TODO(b/174771515): fix call sites and enable check again. - fail("tf_http_archive(urls) must have redundant URLs. The " + - "mirror.tensorflow.org URL must be present and it must come first. " + - "Even if you don't have permission to mirror the file, please " + - "put the correctly formatted mirror URL there anyway, because " + - "someone will come along shortly thereafter and mirror the file.") - # Construct all labels early on to prevent rule restart. We want the # attributes to be strings instead of labels because they refer to files # in the TensorFlow repository, not files in repos depending on TensorFlow. @@ -98,6 +90,20 @@ def tf_http_archive(name, sha256, urls, **kwargs): labels (e.g. '@foo//:bar') or from a label created in their repository (e.g. 'str(Label("//:bar"))'). """ + if len(urls) < 2: + fail("tf_http_archive(urls) must have redundant URLs.") + + if not any([mirror in urls[0] for mirror in ( + "mirror.tensorflow.org", + "mirror.bazel.build", + "storage.googleapis.com", + )]): + fail("The first entry of tf_http_archive(urls) must be a mirror " + + "URL, preferrably mirror.tensorflow.org. Even if you don't have " + + "permission to mirror the file, please put the correctly " + + "formatted mirror URL there anyway, because someone will come " + + "along shortly thereafter and mirror the file.") + if native.existing_rule(name): print("\n\033[1;33mWarning:\033[0m skipping import of repository '" + name + "' because it already exists.\n")