Skip to content

Commit d5a05b1

Browse files
committed
Only define repository dependencies if they haven't been already.
This will improve the situation if multiple repositories define the same dependencies (such as someone depending on rules_apple and rules_swift, and then rules_apple also itself depending on rules_swift). It does not address the situation where the same dependency is used but with different versions; Bazel does not have a great answer to this at this moment, as far as I know.
1 parent 6397ef3 commit d5a05b1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Diff for: swift/repositories.bzl

+20-4
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,51 @@ _swift_autoconfiguration = repository_rule(
7979
implementation=_swift_autoconfiguration_impl,
8080
)
8181

82+
def _maybe(repo_rule, name, **kwargs):
83+
"""Executes the given repository rule if it hasn't been executed already.
84+
85+
Args:
86+
repo_rule: The repository rule to be executed (e.g.,
87+
`native.git_repository`.)
88+
name: The name of the repository to be defined by the rule.
89+
**kwargs: Additional arguments passed directly to the repository rule.
90+
"""
91+
if name not in native.existing_rules():
92+
repo_rule(name = name, **kwargs)
93+
8294
def swift_rules_dependencies():
8395
"""Fetches repositories that are dependencies of the `rules_swift` workspace.
8496
8597
Users should call this macro in their `WORKSPACE` to ensure that all of the
8698
dependencies of the Swift rules are downloaded and that they are isolated from
8799
changes to those dependencies.
88100
"""
89-
native.git_repository(
101+
_maybe(
102+
native.git_repository,
90103
name = "bazel_skylib",
91104
remote = "https://github.com/bazelbuild/bazel-skylib.git",
92105
tag = "0.4.0",
93106
)
94107

95-
native.new_http_archive(
108+
_maybe(
109+
native.new_http_archive,
96110
name = "com_github_apple_swift_swift_protobuf",
97111
urls = ["https://github.com/apple/swift-protobuf/archive/1.0.3.zip"],
98112
strip_prefix = "swift-protobuf-1.0.3/",
99113
type = "zip",
100114
build_file = "@build_bazel_rules_swift//third_party:com_github_apple_swift_swift_protobuf/BUILD.overlay",
101115
)
102116

103-
native.http_archive(
117+
_maybe(
118+
native.http_archive,
104119
name = "com_google_protobuf",
105120
# v3.5.1, latest as of 2018-01-11
106121
urls = ["https://codeload.github.com/google/protobuf/zip/106ffc04be1abf3ff3399f54ccf149815b287dd9"],
107122
strip_prefix = "protobuf-106ffc04be1abf3ff3399f54ccf149815b287dd9",
108123
type = "zip",
109124
)
110125

111-
_swift_autoconfiguration(
126+
_maybe(
127+
_swift_autoconfiguration,
112128
name = "build_bazel_rules_swift_local_config",
113129
)

0 commit comments

Comments
 (0)