message: Use custom mirror to download TensorFlow dependencies
  Test Plan:
  Tested locally with a local mirror
  Reviewers: #tensorflow, georgep
  Maniphest Tasks: T13845
diff: @@ -79,6 +79,27 @@ def _apply_delete(ctx, paths):
  cmd = _wrap_bash_cmd(ctx, ["rm", "-rf"] + [ctx.path(path) for path in paths])
  _execute_and_check_ret_code(ctx, cmd)
  +def _update_urls(ctx, original_urls):
  + mirror = _get_env_var(ctx, "HTTP_MIRROR")
  + if mirror:
  + url = original_urls[0]
  + roots = ["mirror.tensorflow.org", "mirror.bazel.build"]
  + for r in roots:
  + index = url.find(r)
  + if index >= 0:
  + index += len(r)
  + break
  + if index < 0:
  + fail("Couldn't substitute the mirror's url in " + url)
  + if _get_env_var(ctx, "ENABLE_MIRROR_FALLBACK"):
  + urls = [ mirror + url[index:] ] + original_urls
  + else:
  + urls = [ mirror + url[index:] ]
  + else:
  + urls = ctx.attr.urls;
  +
  + return urls
  +
  def _tf_http_archive(ctx):
  if ("mirror.tensorflow.org" not in ctx.attr.urls[0] and
  (len(ctx.attr.urls) < 2 and
  @@ -89,10 +110,12 @@ def _tf_http_archive(ctx):
  "put the correctly formatted mirror URL there anyway, because " +
  "someone will come along shortly thereafter and mirror the file.")
  +
  use_syslib = _use_system_lib(ctx, ctx.attr.name)
  if not use_syslib:
  + urls = _update_urls(ctx, ctx.attr.urls)
  ctx.download_and_extract(
  - ctx.attr.urls,
  + urls,
  "",
  ctx.attr.sha256,
  ctx.attr.type,
  @@ -170,8 +193,10 @@ def _third_party_http_archive(ctx):
  ctx.symlink(Label(ctx.attr.system_build_file), buildfile_path)
  else:
  + urls = _update_urls(ctx, ctx.attr.urls)
  +
  ctx.download_and_extract(
  - ctx.attr.urls,
  + urls,
  "",
  ctx.attr.sha256,
  ctx.attr.type,
  