message: third_party/repo: add TF_SYSTEM_LIBS to unbundle deps
diff: @@ -35,6 +35,15 @@ def _get_env_var(ctx, name):
  else:
  return None
  +# Checks if we should use the system lib instead of the bundled one
  +def _use_system_lib(ctx, name):
  + syslibenv = _get_env_var(ctx, "TF_SYSTEM_LIBS")
  + if syslibenv:
  + for n in syslibenv.strip().split(","):
  + if n.strip() == name:
  + return True
  + return False
  +
  # Executes specified command with arguments and calls 'fail' if it exited with
  # non-zero code
  def _execute_and_check_ret_code(repo_ctx, cmd_and_args):
  @@ -75,6 +84,9 @@ def _tf_http_archive(ctx):
  "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.")
  +
  + use_syslib = _use_system_lib(ctx, ctx.attr.name)
  + if not use_syslib:
  ctx.download_and_extract(
  ctx.attr.urls,
  "",
  @@ -85,7 +97,15 @@ def _tf_http_archive(ctx):
  _apply_delete(ctx, ctx.attr.delete)
  if ctx.attr.patch_file != None:
  _apply_patch(ctx, ctx.attr.patch_file)
  - if ctx.attr.build_file != None:
  +
  + if use_syslib and ctx.attr.system_build_file != None:
  + # Use BUILD.bazel to avoid conflict with third party projects with
  + # BUILD or build (directory) underneath.
  + ctx.template("BUILD.bazel", ctx.attr.system_build_file, {
  + "%prefix%": ".." if _repos_are_siblings() else "external",
  + }, False)
  +
  + elif ctx.attr.build_file != None:
  # Use BUILD.bazel to avoid conflict with third party projects with
  # BUILD or build (directory) underneath.
  ctx.template("BUILD.bazel", ctx.attr.build_file, {
  @@ -102,6 +122,7 @@ tf_http_archive = repository_rule(
  "delete": attr.string_list(),
  "patch_file": attr.label(),
  "build_file": attr.label(),
  + "system_build_file": attr.label(),
  })
  """Downloads and creates Bazel repos for dependencies.
  