Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f18997

Browse filesBrowse files
authored
Added support for custom strip_prefix args in toolchains (bazel-contrib#664)
1 parent ce2911b commit 0f18997
Copy full SHA for 0f18997

File tree

Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed

‎python/repositories.bzl

Copy file name to clipboardExpand all lines: python/repositories.bzl
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _python_repository_impl(rctx):
8181
rctx.download_and_extract(
8282
url = url,
8383
sha256 = rctx.attr.sha256,
84-
stripPrefix = "python",
84+
stripPrefix = rctx.attr.strip_prefix,
8585
)
8686

8787
# Write distutils.cfg to the Python installation.
@@ -157,6 +157,7 @@ py_runtime_pair(
157157
"python_version": python_version,
158158
"release_filename": release_filename,
159159
"sha256": rctx.attr.sha256,
160+
"strip_prefix": rctx.attr.strip_prefix,
160161
"url": url,
161162
}
162163

@@ -192,6 +193,10 @@ python_repository = repository_rule(
192193
doc = "The SHA256 integrity hash for the Python interpreter tarball.",
193194
mandatory = True,
194195
),
196+
"strip_prefix": attr.string(
197+
doc = "A directory prefix to strip from the extracted files.",
198+
mandatory = True,
199+
),
195200
"url": attr.string(
196201
doc = "The URL of the interpreter to download",
197202
mandatory = True,
@@ -244,7 +249,7 @@ def python_register_toolchains(
244249
if not sha256:
245250
continue
246251

247-
(release_filename, url) = get_release_url(platform, python_version, base_url, tool_versions)
252+
(release_filename, url, strip_prefix) = get_release_url(platform, python_version, base_url, tool_versions)
248253

249254
python_repository(
250255
name = "{name}_{platform}".format(
@@ -258,6 +263,7 @@ def python_register_toolchains(
258263
url = url,
259264
distutils = distutils,
260265
distutils_content = distutils_content,
266+
strip_prefix = strip_prefix,
261267
**kwargs
262268
)
263269
native.register_toolchains("@{name}_toolchains//:{platform}_toolchain".format(

‎python/versions.bzl

Copy file name to clipboardExpand all lines: python/versions.bzl
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ TOOL_VERSIONS = {
3434
"x86_64-apple-darwin": "8d06bec08db8cdd0f64f4f05ee892cf2fcbc58cfb1dd69da2caab78fac420238",
3535
"x86_64-unknown-linux-gnu": "aec8c4c53373b90be7e2131093caa26063be6d9d826f599c935c0e1042af3355",
3636
},
37+
"strip_prefix": "python",
3738
},
3839
"3.8.12": {
3940
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
@@ -43,6 +44,7 @@ TOOL_VERSIONS = {
4344
"x86_64-pc-windows-msvc": "924f9fd51ff6ccc533ed8e96c5461768da5781eb3dfc11d846f9e300fab44eda",
4445
"x86_64-unknown-linux-gnu": "5be9c6d61e238b90dfd94755051c0d3a2d8023ebffdb4b0fa4e8fedd09a6cab6",
4546
},
47+
"strip_prefix": "python",
4648
},
4749
"3.9.10": {
4850
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
@@ -52,6 +54,7 @@ TOOL_VERSIONS = {
5254
"x86_64-pc-windows-msvc": "5bc65ce023614bf496a6748e41dca934b70fc5fac6dfacc46aa8dbcad772afc2",
5355
"x86_64-unknown-linux-gnu": "455089cc576bd9a58db45e919d1fc867ecdbb0208067dffc845cc9bbf0701b70",
5456
},
57+
"strip_prefix": "python",
5558
},
5659
"3.10.2": {
5760
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
@@ -61,6 +64,7 @@ TOOL_VERSIONS = {
6164
"x86_64-pc-windows-msvc": "a293c5838dd9c8438a84372fb95dda9752df63928a8a2ae516438f187f89567d",
6265
"x86_64-unknown-linux-gnu": "9b64eca2a94f7aff9409ad70bdaa7fbbf8148692662e764401883957943620dd",
6366
},
67+
"strip_prefix": "python",
6468
},
6569
}
6670

@@ -118,21 +122,25 @@ def get_release_url(platform, python_version, base_url = DEFAULT_RELEASE_BASE_UR
118122
tool_versions: A dict listing the interpreter versions, their SHAs and URL
119123
120124
Returns:
121-
filename and url pair
125+
A tuple of (filename, url, and archive strip prefix)
122126
"""
123127

124128
url = tool_versions[python_version]["url"]
125129

126130
if type(url) == type({}):
127131
url = url[platform]
128132

133+
strip_prefix = tool_versions[python_version].get("strip_prefix", None)
134+
if type(strip_prefix) == type({}):
135+
strip_prefix = strip_prefix[platform]
136+
129137
release_filename = url.format(
130138
platform = platform,
131139
python_version = python_version,
132140
build = "static-install_only" if (WINDOWS_NAME in platform) else "install_only",
133141
)
134142
url = "/".join([base_url, release_filename])
135-
return (release_filename, url)
143+
return (release_filename, url, strip_prefix)
136144

137145
def print_toolchains_checksums(name):
138146
native.genrule(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.