forked from bazelbuild/rules_apple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepositories.bzl
150 lines (131 loc) · 6.24 KB
/
repositories.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Definitions for handling Bazel repositories used by the Apple rules."""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def _colorize(text, color):
"""Applies ANSI color codes around the given text."""
return "\033[1;{color}m{text}{reset}".format(
color = color,
reset = "\033[0m",
text = text,
)
def _green(text):
return _colorize(text, "32")
def _yellow(text):
return _colorize(text, "33")
def _warn(msg):
"""Outputs a warning message."""
# buildifier: disable=print
print("\n{prefix} {msg}\n".format(
msg = msg,
prefix = _yellow("WARNING:"),
))
def _maybe(repo_rule, name, ignore_version_differences, **kwargs):
"""Executes the given repository rule if it hasn't been executed already.
Args:
repo_rule: The repository rule to be executed (e.g.,
`http_archive`.)
name: The name of the repository to be defined by the rule.
ignore_version_differences: If `True`, warnings about potentially
incompatible versions of depended-upon repositories will be silenced.
**kwargs: Additional arguments passed directly to the repository rule.
"""
if native.existing_rule(name):
if not ignore_version_differences:
# Verify that the repository is being loaded from the same URL and tag
# that we asked for, and warn if they differ.
# TODO(allevato): This isn't perfect, because the user could load from the
# same commit SHA as the tag, or load from an HTTP archive instead of a
# Git repository, but this is a good first step toward validating.
# Long-term, we should extend this function to support dependencies other
# than Git.
existing_repo = native.existing_rule(name)
if (existing_repo.get("remote") != kwargs.get("remote") or
existing_repo.get("tag") != kwargs.get("tag")):
expected = "{url} (tag {tag})".format(
tag = kwargs.get("tag"),
url = kwargs.get("remote"),
)
existing = "{url} (tag {tag})".format(
tag = existing_repo.get("tag"),
url = existing_repo.get("remote"),
)
_warn("""\
`build_bazel_rules_apple` depends on `{repo}` loaded from {expected}, but we \
have detected it already loaded into your workspace from {existing}. You may \
run into compatibility issues. To silence this warning, pass \
`ignore_version_differences = True` to `apple_rules_dependencies()`.
""".format(
existing = _yellow(existing),
expected = _green(expected),
repo = name,
))
return
repo_rule(name = name, **kwargs)
def apple_rules_dependencies(ignore_version_differences = False, include_bzlmod_ready_dependencies = True):
"""Fetches repositories that are dependencies of the `rules_apple` workspace.
Users should call this macro in their `WORKSPACE` to ensure that all of the
dependencies of the Apple rules are downloaded and that they are isolated from
changes to those dependencies.
Args:
ignore_version_differences: If `True`, warnings about potentially
incompatible versions of depended-upon repositories will be silenced.
include_bzlmod_ready_dependencies: Whether or not bzlmod-ready
dependencies should be included.
"""
if include_bzlmod_ready_dependencies:
_maybe(
http_archive,
name = "bazel_skylib",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
ignore_version_differences = ignore_version_differences,
)
_maybe(
http_archive,
name = "build_bazel_apple_support",
sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80",
url = "https://github.com/bazelbuild/apple_support/releases/download/1.15.1/apple_support.1.15.1.tar.gz",
ignore_version_differences = ignore_version_differences,
)
_maybe(
http_archive,
name = "build_bazel_rules_swift",
sha256 = "9919ed1d8dae509645bfd380537ae6501528d8de971caebed6d5185b9970dc4d",
url = "https://github.com/bazelbuild/rules_swift/releases/download/2.1.1/rules_swift.2.1.1.tar.gz",
ignore_version_differences = ignore_version_differences,
)
_maybe(
http_archive,
name = "platforms",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz",
],
sha256 = "5eda539c841265031c2f82d8ae7a3a6490bd62176e0c038fc469eabf91f6149b",
ignore_version_differences = ignore_version_differences,
)
_maybe(
http_archive,
name = "xctestrunner",
urls = [
"https://github.com/google/xctestrunner/archive/b7698df3d435b6491b4b4c0f9fc7a63fbed5e3a6.tar.gz",
],
strip_prefix = "xctestrunner-b7698df3d435b6491b4b4c0f9fc7a63fbed5e3a6",
sha256 = "ae3a063c985a8633cb7eb566db21656f8db8eb9a0edb8c182312c7f0db53730d",
ignore_version_differences = ignore_version_differences,
)