diff options
author | Jason Zaman <jason@perfinion.com> | 2018-05-30 16:14:42 +0800 |
---|---|---|
committer | Jason Zaman <jason@perfinion.com> | 2018-07-13 11:25:39 +0800 |
commit | 4910a2bb53cda036ea78b3eba90c6f30a1fa67da (patch) | |
tree | aa8207e897f85f0f8d1f474e90d8b8b87f96ff7d /third_party/repo.bzl | |
parent | 59bfc71a71df63c2859e17179a0d375e4bb96fb0 (diff) |
third_party/repo: add TF_SYSTEM_LIBS to unbundle deps
Signed-off-by: Jason Zaman <jason@perfinion.com>
Diffstat (limited to 'third_party/repo.bzl')
-rw-r--r-- | third_party/repo.bzl | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/third_party/repo.bzl b/third_party/repo.bzl index 9cee1fcc4b..fb33c389ac 100644 --- a/third_party/repo.bzl +++ b/third_party/repo.bzl @@ -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,17 +84,28 @@ 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.") - ctx.download_and_extract( - ctx.attr.urls, - "", - ctx.attr.sha256, - ctx.attr.type, - ctx.attr.strip_prefix) - if ctx.attr.delete: - _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: + + use_syslib = _use_system_lib(ctx, ctx.attr.name) + if not use_syslib: + ctx.download_and_extract( + ctx.attr.urls, + "", + ctx.attr.sha256, + ctx.attr.type, + ctx.attr.strip_prefix) + if ctx.attr.delete: + _apply_delete(ctx, ctx.attr.delete) + if ctx.attr.patch_file != None: + _apply_patch(ctx, ctx.attr.patch_file) + + 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. |