Skip to content

Commit

Permalink
Added support for custom strip_prefix args in toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Mar 19, 2022
1 parent e18e1a3 commit 0625896
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _python_repository_impl(rctx):
rctx.download_and_extract(
url = url,
sha256 = rctx.attr.sha256,
stripPrefix = "python",
stripPrefix = rctx.attr.strip_prefix,
)

# Write distutils.cfg to the Python installation.
Expand Down Expand Up @@ -157,6 +157,7 @@ py_runtime_pair(
"python_version": python_version,
"release_filename": release_filename,
"sha256": rctx.attr.sha256,
"strip_prefix": rctx.attr.strip_prefix,
"url": url,
}

Expand Down Expand Up @@ -192,6 +193,9 @@ python_repository = repository_rule(
doc = "The SHA256 integrity hash for the Python interpreter tarball.",
mandatory = True,
),
"strip_prefix": attr.string(
doc = "A directory prefix to strip from the extracted files.",
),
"url": attr.string(
doc = "The URL of the interpreter to download",
mandatory = True,
Expand Down Expand Up @@ -244,7 +248,7 @@ def python_register_toolchains(
if not sha256:
continue

(release_filename, url) = get_release_url(platform, python_version, base_url, tool_versions)
(release_filename, url, strip_prefix) = get_release_url(platform, python_version, base_url, tool_versions)

python_repository(
name = "{name}_{platform}".format(
Expand All @@ -258,6 +262,7 @@ def python_register_toolchains(
url = url,
distutils = distutils,
distutils_content = distutils_content,
strip_prefix = strip_prefix,
**kwargs
)
native.register_toolchains("@{name}_toolchains//:{platform}_toolchain".format(
Expand Down
12 changes: 10 additions & 2 deletions python/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TOOL_VERSIONS = {
"x86_64-apple-darwin": "8d06bec08db8cdd0f64f4f05ee892cf2fcbc58cfb1dd69da2caab78fac420238",
"x86_64-unknown-linux-gnu": "aec8c4c53373b90be7e2131093caa26063be6d9d826f599c935c0e1042af3355",
},
"strip_prefix": "python",
},
"3.8.12": {
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
Expand All @@ -43,6 +44,7 @@ TOOL_VERSIONS = {
"x86_64-pc-windows-msvc": "924f9fd51ff6ccc533ed8e96c5461768da5781eb3dfc11d846f9e300fab44eda",
"x86_64-unknown-linux-gnu": "5be9c6d61e238b90dfd94755051c0d3a2d8023ebffdb4b0fa4e8fedd09a6cab6",
},
"strip_prefix": "python",
},
"3.9.10": {
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
Expand All @@ -52,6 +54,7 @@ TOOL_VERSIONS = {
"x86_64-pc-windows-msvc": "5bc65ce023614bf496a6748e41dca934b70fc5fac6dfacc46aa8dbcad772afc2",
"x86_64-unknown-linux-gnu": "455089cc576bd9a58db45e919d1fc867ecdbb0208067dffc845cc9bbf0701b70",
},
"strip_prefix": "python",
},
"3.10.2": {
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
Expand All @@ -61,6 +64,7 @@ TOOL_VERSIONS = {
"x86_64-pc-windows-msvc": "a293c5838dd9c8438a84372fb95dda9752df63928a8a2ae516438f187f89567d",
"x86_64-unknown-linux-gnu": "9b64eca2a94f7aff9409ad70bdaa7fbbf8148692662e764401883957943620dd",
},
"strip_prefix": "python",
},
}

Expand Down Expand Up @@ -118,21 +122,25 @@ def get_release_url(platform, python_version, base_url = DEFAULT_RELEASE_BASE_UR
tool_versions: A dict listing the interpreter versions, their SHAs and URL
Returns:
filename and url pair
A tuple of (filename, url, and archive strip prefix)
"""

url = tool_versions[python_version]["url"]

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

strip_prefix = tool_versions[python_version].get("strip_prefix", None)
if type(strip_prefix) == type({}):
strip_prefix = strip_prefix[platform]

release_filename = url.format(
platform = platform,
python_version = python_version,
build = "static-install_only" if (WINDOWS_NAME in platform) else "install_only",
)
url = "/".join([base_url, release_filename])
return (release_filename, url)
return (release_filename, url, strip_prefix)

def print_toolchains_checksums(name):
native.genrule(
Expand Down

0 comments on commit 0625896

Please sign in to comment.