Skip to content

Commit 7ed9c67

Browse files
chsiggtensorflower-gardener
authored andcommitted
Warn and skip existing repositories instead of blindly importing them.
This is basically the maybe() functionality that seems to be standard process. PiperOrigin-RevId: 359339954 Change-Id: I5ce2f14672b84c2b2199c426599447f0c7dcf517
1 parent 28f1284 commit 7ed9c67

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

‎third_party/repo.bzl‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _tf_http_archive_impl(ctx):
6969
ctx.delete(path)
7070
ctx.symlink(label, path)
7171

72-
tf_http_archive = repository_rule(
72+
_tf_http_archive = repository_rule(
7373
implementation = _tf_http_archive_impl,
7474
attrs = {
7575
"sha256": attr.string(mandatory = True),
@@ -83,17 +83,31 @@ tf_http_archive = repository_rule(
8383
"system_link_files": attr.string_dict(),
8484
},
8585
environ = ["TF_SYSTEM_LIBS"],
86-
doc = """Downloads and creates Bazel repos for dependencies.
86+
)
8787

88-
This is a swappable replacement for both http_archive() and
89-
new_http_archive() that offers some additional features. It also helps
90-
ensure best practices are followed.
88+
def tf_http_archive(name, sha256, urls, **kwargs):
89+
"""Downloads and creates Bazel repos for dependencies.
9190
92-
File arguments are relative to the TensorFlow repository by default. Dependent
93-
repositories that use this rule should refer to files either with absolute
94-
labels (e.g. '@foo//:bar') or from a label created in their repository (e.g.
95-
'str(Label("//:bar"))').""",
96-
)
91+
This is a swappable replacement for both http_archive() and
92+
new_http_archive() that offers some additional features. It also helps
93+
ensure best practices are followed.
94+
95+
File arguments are relative to the TensorFlow repository by default. Dependent
96+
repositories that use this rule should refer to files either with absolute
97+
labels (e.g. '@foo//:bar') or from a label created in their repository (e.g.
98+
'str(Label("//:bar"))').
99+
"""
100+
if native.existing_rule(name):
101+
print("\n\033[1;33mWarning:\033[0m skipping import of repository '" +
102+
name + "' because it already exists.\n")
103+
return
104+
105+
_tf_http_archive(
106+
name = name,
107+
sha256 = sha256,
108+
urls = urls,
109+
**kwargs
110+
)
97111

98112
# Introduced for go/tfbr-thirdparty, now alias of tf_http_archive.
99113
# TODO(csigg): Update call sites and remove.

0 commit comments

Comments
 (0)