Skip to content

Commit f21e56f

Browse files
committed
Tweaks
1 parent b1514f0 commit f21e56f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

toolchain/internal/llvm_distributions.bzl

+11-13
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ def _dist_to_os_names(dist, default_os_names = []):
788788
"linux-gnu-Fedora27",
789789
"linux-gnu",
790790
"unknown-linux-gnu",
791+
# The ubuntu list could be replaced with _UBUNTU_VERSIONS which
792+
# spawns more selections and changes a few to neer ubuntu versions.
791793
"linux-gnu-ubuntu-22.04",
792794
"linux-gnu-ubuntu-20.04",
793795
"linux-gnu-ubuntu-18.04",
@@ -810,7 +812,7 @@ def _dist_to_os_names(dist, default_os_names = []):
810812
] + _UBUNTU_VERSIONS
811813
return default_os_names
812814

813-
def _find_llvm_basenames_by_stem(prefixes, is_prefix = False):
815+
def _find_llvm_basenames_by_stem(prefixes, *, is_prefix = False, return_first_match = False):
814816
basenames = []
815817
for prefix in prefixes:
816818
for suffix in [".tar.gz", ".tar.xz"]:
@@ -824,6 +826,8 @@ def _find_llvm_basenames_by_stem(prefixes, is_prefix = False):
824826
continue
825827
for suffix in [".tar.gz", ".tar.xz"]:
826828
if llvm_dist.endswith(suffix) and llvm_dist not in basenames:
829+
if return_first_match:
830+
return [llvm_dist]
827831
basenames.append(llvm_dist)
828832
return basenames
829833

@@ -859,7 +863,7 @@ def _find_llvm_basename_list(llvm_version, arch, os, dist):
859863
os = select_os,
860864
)
861865
for select_os in ["apple-darwin", "apple-macos", "darwin-apple"]
862-
], True)
866+
], is_prefix = True)
863867
elif os == "windows":
864868
return _find_llvm_basenames_by_stem([
865869
"clang+llvm-{llvm_version}-{arch}-{os}".format(
@@ -869,33 +873,27 @@ def _find_llvm_basename_list(llvm_version, arch, os, dist):
869873
),
870874
])
871875
elif dist.name in ["amzn", "suse"] and arch == "x86_64":
872-
names = _find_llvm_basenames_by_stem([
876+
return _find_llvm_basenames_by_stem([
873877
"clang+llvm-{llvm_version}-{arch}-{os}".format(
874878
llvm_version = llvm_version,
875879
arch = arch,
876880
os = suse_os,
877881
)
878882
for suse_os in _dist_to_os_names(dist)
879-
], True)
880-
if names:
881-
return [names[0]]
882-
return []
883+
], is_prefix = True, return_first_match = True)
883884
elif dist.name in _UBUNTU_NAMES:
884885
arch_list = {
885886
"sparcv9": ["sparc64", "sparcv9"],
886887
}.get(arch, [arch])
887-
names = _find_llvm_basenames_by_stem([
888+
return _find_llvm_basenames_by_stem([
888889
"clang+llvm-{llvm_version}-{arch}-{os}".format(
889890
llvm_version = llvm_version,
890891
arch = select_arch,
891892
os = select_os,
892893
)
893894
for select_os in _dist_to_os_names(dist)
894895
for select_arch in arch_list
895-
])
896-
if names:
897-
return [names[0]]
898-
return []
896+
], return_first_match = True)
899897
elif dist.name == "fedora" and arch not in ["sparc64", "sparcv9"]:
900898
return _find_llvm_basenames_by_stem([
901899
"clang+llvm-{llvm_version}-{arch}-{os}".format(
@@ -956,7 +954,7 @@ def _find_llvm_basename_list(llvm_version, arch, os, dist):
956954
arch = arch_alias,
957955
dist_name = dist_name,
958956
))
959-
names = _find_llvm_basenames_by_stem(prefixes, True)
957+
names = _find_llvm_basenames_by_stem(prefixes, is_prefix = True)
960958
if names and dist.name == "ubuntu":
961959
return [names[-1]]
962960
return names

0 commit comments

Comments
 (0)