|
17 | 17 |
|
18 | 18 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
19 | 19 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") |
20 | | -load("//python/private:version_label.bzl", "version_label") |
| 20 | +load("//python/private/pypi:hub_repository.bzl", "hub_repository", "whl_config_settings_to_json") |
| 21 | +load("//python/private/pypi:whl_config_setting.bzl", "whl_config_setting") |
21 | 22 |
|
22 | 23 | # START: maintained by 'bazel run //tools/private/update_deps:update_coverage_deps <version>' |
23 | 24 | _coverage_deps = { |
@@ -142,49 +143,63 @@ _coverage_deps = { |
142 | 143 |
|
143 | 144 | _coverage_patch = Label("//python/private:coverage.patch") |
144 | 145 |
|
145 | | -def coverage_dep(name, python_version, platform, visibility): |
146 | | - """Register a single coverage dependency based on the python version and platform. |
| 146 | +def coverage_deps(name): |
| 147 | + """Register all coverage dependencies. |
147 | 148 |
|
148 | | - Args: |
149 | | - name: The name of the registered repository. |
150 | | - python_version: The full python version. |
151 | | - platform: The platform, which can be found in //python:versions.bzl PLATFORMS dict. |
152 | | - visibility: The visibility of the coverage tool. |
| 149 | + This exposes them through a hub repository. |
153 | 150 |
|
154 | | - Returns: |
155 | | - The label of the coverage tool if the platform is supported, otherwise - None. |
| 151 | + Args: |
| 152 | + name: The name of the hub repository. |
156 | 153 | """ |
157 | | - if "windows" in platform: |
158 | | - # NOTE @aignas 2023-01-19: currently we do not support windows as the |
159 | | - # upstream coverage wrapper is written in shell. Do not log any warning |
160 | | - # for now as it is not actionable. |
161 | | - return None |
162 | 154 |
|
163 | | - abi = "cp" + version_label(python_version) |
164 | | - url, sha256 = _coverage_deps.get(abi, {}).get(platform, (None, "")) |
| 155 | + whl_map = { |
| 156 | + str(Label("//python:none")): [ |
| 157 | + whl_config_setting(config_setting = "//conditions:default"), |
| 158 | + ], |
| 159 | + } |
| 160 | + for abi, values in _coverage_deps.items(): |
| 161 | + for platform, (url, sha256) in values.items(): |
| 162 | + spoke_name = "{}_{}_{}".format(name, abi, platform).replace("-", "_") |
| 163 | + _, _, filename = url.rpartition("/") |
165 | 164 |
|
166 | | - if url == None: |
167 | | - # Some wheels are not present for some builds, so let's silently ignore those. |
168 | | - return None |
| 165 | + config_setting = whl_config_setting( |
| 166 | + version = "3.{}".format(abi[3:]), |
| 167 | + filename = filename, |
| 168 | + ) |
169 | 169 |
|
170 | | - maybe( |
171 | | - http_archive, |
172 | | - name = name, |
173 | | - build_file_content = """ |
| 170 | + whl_map[spoke_name] = [config_setting] |
| 171 | + |
| 172 | + # NOTE @aignas 2025-02-04: under `bzlmod` the `maybe` function is noop. |
| 173 | + # This is only kept for `WORKSPACE` compatibility. |
| 174 | + maybe( |
| 175 | + http_archive, |
| 176 | + name = spoke_name, |
| 177 | + build_file_content = """ |
174 | 178 | filegroup( |
175 | | - name = "coverage", |
| 179 | + name = "pkg", |
176 | 180 | srcs = ["coverage/__main__.py"], |
177 | 181 | data = glob(["coverage/*.py", "coverage/**/*.py", "coverage/*.so"]), |
178 | | - visibility = {visibility}, |
| 182 | + visibility = ["{visibility}"], |
179 | 183 | ) |
180 | | - """.format( |
181 | | - visibility = visibility, |
182 | | - ), |
183 | | - patch_args = ["-p1"], |
184 | | - patches = [_coverage_patch], |
185 | | - sha256 = sha256, |
186 | | - type = "zip", |
187 | | - urls = [url], |
188 | | - ) |
| 184 | + """.format( |
| 185 | + visibility = "@{}//:__subpackages__".format(name), |
| 186 | + ), |
| 187 | + patch_args = ["-p1"], |
| 188 | + patches = [_coverage_patch], |
| 189 | + sha256 = sha256, |
| 190 | + type = "zip", |
| 191 | + urls = [url], |
| 192 | + ) |
189 | 193 |
|
190 | | - return "@{name}//:coverage".format(name = name) |
| 194 | + maybe( |
| 195 | + hub_repository, |
| 196 | + name = name, |
| 197 | + repo_name = name, |
| 198 | + whl_map = { |
| 199 | + "coverage": whl_config_settings_to_json(whl_map), |
| 200 | + }, |
| 201 | + add_requirements_bzl = False, |
| 202 | + extra_hub_aliases = {}, |
| 203 | + packages = [], |
| 204 | + groups = {}, |
| 205 | + ) |
0 commit comments