Skip to content

Commit e710324

Browse files
helly25fmeum
andauthored
Tweaks (#489)
Tweaks: * Sort known distro names. * Function `_os_version_arch` returns a dist(ribution) name and not an os name, so we rename it `_dist_version_arch`. * Move `_resolve_version_for_suse` above `_linux` to follow order of the other helpers. * Improve strip_prefix detection (also added `.exe` as we predict it, though we cannot really handle it (yet)). --------- Co-authored-by: Fabian Meumertzheim <[email protected]>
1 parent 947af23 commit e710324

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

toolchain/internal/common.bzl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,28 @@ _toolchain_tools_darwin = {
5555
}
5656

5757
def exec_os_key(rctx):
58-
(os, version, arch) = os_version_arch(rctx)
58+
(os, version, arch) = dist_version_arch(rctx)
5959
if version == "":
6060
return "%s-%s" % (os, arch)
6161
else:
6262
return "%s-%s-%s" % (os, version, arch)
6363

6464
_known_distros = [
65-
"freebsd",
66-
"suse",
67-
"ubuntu",
65+
# keep sorted
66+
"almalinux",
67+
"amzn",
6868
"arch",
69-
"manjaro",
69+
"centos",
7070
"debian",
7171
"fedora",
72-
"centos",
73-
"amzn",
74-
"raspbian",
72+
"freebsd",
73+
"manjaro",
74+
"ol",
7575
"pop",
76+
"raspbian",
7677
"rhel",
77-
"ol",
78-
"almalinux",
78+
"suse",
79+
"ubuntu",
7980
]
8081

8182
def _linux_dist(rctx):
@@ -102,7 +103,7 @@ def _linux_dist(rctx):
102103

103104
return distname, version
104105

105-
def os_version_arch(rctx):
106+
def dist_version_arch(rctx):
106107
_os = os(rctx)
107108
_arch = arch(rctx)
108109

toolchain/internal/llvm_distributions.bzl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,12 @@ def _distribution_urls(rctx):
748748

749749
sha256 = _llvm_distributions[basename]
750750

751-
if basename.endswith(".tar.xz"):
752-
strip_prefix = basename[:(len(basename) - len(".tar.xz"))]
753-
elif basename.endswith(".tar.zst"):
754-
strip_prefix = basename[:(len(basename) - len(".tar.zst"))]
755-
else:
751+
strip_prefix = ""
752+
for suffix in [".exe", ".tar.gz", ".tar.xz", ".tar.zst"]:
753+
if basename.endswith(suffix):
754+
strip_prefix = basename.removesuffix(suffix)
755+
break
756+
if not strip_prefix:
756757
fail("Unknown URL file extension {url}", url = basename)
757758

758759
strip_prefix = strip_prefix.rstrip("-rhel86")
@@ -776,7 +777,10 @@ def _write_distributions_impl(ctx):
776777
verify that predicted distributions have been configured. Otherwise the
777778
algorithm could not know the hash value.
778779
"""
779-
arch_list = ["aarch64", "x86_64"]
780+
arch_list = [
781+
"aarch64",
782+
"x86_64",
783+
]
780784
os_list = [
781785
"darwin",
782786
"linux",
@@ -789,11 +793,11 @@ def _write_distributions_impl(ctx):
789793
version_list = []
790794
for name in _llvm_distributions.keys():
791795
for prefix in ["LLVM-", "clang+llvm-"]:
792-
name = name.removeprefix(prefix)
793-
version = name.split("-", 1)[0]
794-
if not _version_ge(version, MIN_VERSION):
795-
continue
796-
version_list.append(version)
796+
if name.startswith(prefix):
797+
version = name.split("-", 2)[1]
798+
if not _version_ge(version, MIN_VERSION):
799+
continue
800+
version_list.append(version)
797801
for version in _llvm_distributions_base_url.keys():
798802
if not _version_ge(version, MIN_VERSION):
799803
continue

toolchain/internal/release_name.bzl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
load(
22
"//toolchain/internal:common.bzl",
33
_arch = "arch",
4+
_dist_version_arch = "dist_version_arch",
45
_os = "os",
5-
_os_version_arch = "os_version_arch",
66
)
77

88
def _major_llvm_version(llvm_version):
@@ -140,6 +140,18 @@ def _rhel_osname(arch, version, major_llvm_version, llvm_version):
140140

141141
return None
142142

143+
def _resolve_version_for_suse(major_llvm_version, llvm_version):
144+
minor_llvm_version = _minor_llvm_version(llvm_version)
145+
if major_llvm_version < 10:
146+
os_name = "linux-sles11.3"
147+
elif major_llvm_version == 10 and minor_llvm_version == 0:
148+
os_name = "linux-sles11.3"
149+
elif major_llvm_version < 13 or (major_llvm_version == 14 and minor_llvm_version == 0):
150+
os_name = "linux-sles12.4"
151+
else:
152+
os_name = _ubuntu_osname("x86_64", "20.04", major_llvm_version, llvm_version)
153+
return os_name
154+
143155
def _linux(llvm_version, distname, version, arch):
144156
major_llvm_version = _major_llvm_version(llvm_version)
145157

@@ -199,18 +211,6 @@ def _linux(llvm_version, distname, version, arch):
199211
os_name = os_name,
200212
)
201213

202-
def _resolve_version_for_suse(major_llvm_version, llvm_version):
203-
minor_llvm_version = _minor_llvm_version(llvm_version)
204-
if major_llvm_version < 10:
205-
os_name = "linux-sles11.3"
206-
elif major_llvm_version == 10 and minor_llvm_version == 0:
207-
os_name = "linux-sles11.3"
208-
elif major_llvm_version < 13 or (major_llvm_version == 14 and minor_llvm_version == 0):
209-
os_name = "linux-sles12.4"
210-
else:
211-
os_name = _ubuntu_osname("x86_64", "20.04", major_llvm_version, llvm_version)
212-
return os_name
213-
214214
def llvm_release_name_19(llvm_version, rctx_arch, rctx_os):
215215
arch = {
216216
"aarch64": "ARM64",
@@ -236,7 +236,7 @@ def llvm_release_name(rctx, llvm_version):
236236
if major_llvm_version >= 19:
237237
return llvm_release_name_19(llvm_version, _arch(rctx), _os(rctx))
238238
else:
239-
(os, version, arch) = _os_version_arch(rctx)
239+
(os, version, arch) = _dist_version_arch(rctx)
240240
if os == "darwin":
241241
return _darwin(llvm_version, arch)
242242
elif os == "windows":

0 commit comments

Comments
 (0)