15
15
load ("@bazel_tools//tools/build_defs/repo:utils.bzl" , "read_netrc" , "use_netrc" )
16
16
load (
17
17
"//toolchain/internal:common.bzl" ,
18
- _attr_dict = "attr_dict" ,
19
- _exec_os_arch_dict_value = "exec_os_arch_dict_value" ,
20
- _host_info = "host_info" ,
18
+ "attr_dict" ,
19
+ "exec_os_arch_dict_value" ,
20
+ "host_info" ,
21
21
)
22
- load ("//toolchain/internal:release_name.bzl" , _llvm_release_name_context = "llvm_release_name_context" )
23
22
24
23
# If a new LLVM version is missing from this list, please add the shasums here
25
24
# and the new version in toolchain/internal/llvm_distributions.golden.txt.
@@ -677,7 +676,7 @@ def _get_auth(ctx, urls):
677
676
return {}
678
677
679
678
def download_llvm (rctx ):
680
- """Download the LLVM for the given context."""
679
+ """Download the LLVM distribution for the given context."""
681
680
urls = []
682
681
sha256 = None
683
682
strip_prefix = None
@@ -705,7 +704,7 @@ def download_llvm(rctx):
705
704
lib_path = clang_version .get_child ("lib" , lib_name )
706
705
rctx .file (lib_path , libclang_rt_content , legacy_utf8 = False )
707
706
708
- updated_attrs = _attr_dict (rctx .attr )
707
+ updated_attrs = attr_dict (rctx .attr )
709
708
if update_sha256 :
710
709
updated_attrs ["sha256" ].update ([(key , res .sha256 )])
711
710
return updated_attrs
@@ -725,9 +724,9 @@ def _get_llvm_version(rctx):
725
724
return rctx .attr .llvm_version
726
725
if not rctx .attr .llvm_versions :
727
726
fail ("Neither 'llvm_version' nor 'llvm_versions' given." )
728
- (_ , llvm_version ) = _exec_os_arch_dict_value (rctx , "llvm_versions" )
729
- info = _host_info (rctx )
727
+ (_ , llvm_version ) = exec_os_arch_dict_value (rctx , "llvm_versions" )
730
728
if not llvm_version :
729
+ info = host_info (rctx )
731
730
fail (
732
731
"LLVM version string missing for ({os}/{dist_name}/{dist_verison}, {arch})" ,
733
732
os = info .os ,
@@ -737,7 +736,14 @@ def _get_llvm_version(rctx):
737
736
)
738
737
return llvm_version
739
738
740
- _UBUNTU_NAMES = ["arch" , "linuxmint" , "manjaro" , "nixos" , "pop" , "ubuntu" ]
739
+ _UBUNTU_NAMES = [
740
+ "arch" ,
741
+ "linuxmint" ,
742
+ "manjaro" ,
743
+ "nixos" ,
744
+ "pop" ,
745
+ "ubuntu" ,
746
+ ]
741
747
742
748
_UBUNTU_VERSIONS = [
743
749
"linux-ubuntu-20.04" ,
@@ -783,8 +789,8 @@ def _dist_to_os_names(dist, default_os_names = []):
783
789
"linux-gnu-Fedora27" ,
784
790
"linux-gnu" ,
785
791
"unknown-linux-gnu" ,
786
- # The ubuntu list could be replaced with _UBUNTU_VERSIONS which
787
- # spawns more selections and changes a few to neer ubuntu versions.
792
+ # The Ubuntu list could be replaced with _UBUNTU_VERSIONS which
793
+ # Spawns more selections and changes a few to near Ubuntu versions.
788
794
"linux-gnu-ubuntu-22.04" ,
789
795
"linux-gnu-ubuntu-20.04" ,
790
796
"linux-gnu-ubuntu-18.04" ,
@@ -796,6 +802,10 @@ def _dist_to_os_names(dist, default_os_names = []):
796
802
return ["linux-gnueabihf" , "linux-gnu" ]
797
803
if dist .name in ["rhel" , "ol" , "almalinux" ]:
798
804
return ["linux-rhel-" , "linux-gnu-rhel-" ]
805
+ if dist .name == "debian" :
806
+ return [
807
+ "linux-gnu-debian8" ,
808
+ ] + _UBUNTU_VERSIONS
799
809
if dist .name in _UBUNTU_NAMES :
800
810
return [
801
811
"linux-gnu-ubuntu-" + dist .version ,
@@ -822,8 +832,11 @@ def _find_llvm_basenames_by_stem(prefixes, *, is_prefix = False, return_first_ma
822
832
basenames .append (llvm_dist )
823
833
return basenames
824
834
825
- def _find_llvm_basename_list (llvm_version , arch , os , dist ):
835
+ def _find_llvm_basename_list (llvm_version , host_info ):
826
836
"""Lookup (llvm_version, arch, os) in the list of basenames in `_llvm_distributions.`"""
837
+ arch = host_info .arch
838
+ os = host_info .os
839
+ dist = host_info .dist
827
840
828
841
# Prefer new LLVM- distributions is available
829
842
basenames = _find_llvm_basenames_by_stem ([
@@ -945,71 +958,38 @@ def _find_llvm_basename_list(llvm_version, arch, os, dist):
945
958
arch = arch_alias ,
946
959
dist_name = dist_name ,
947
960
))
948
- names = _find_llvm_basenames_by_stem (prefixes , is_prefix = True )
949
- if names and dist .name == "ubuntu" :
950
- return [names [- 1 ]]
951
- return names
952
- else :
953
- fail ("ERROR: Unknown OS: {os}" .format (os = os ))
961
+ return _find_llvm_basenames_by_stem (prefixes , is_prefix = True , return_first_match = True )
962
+ return []
954
963
955
- def _find_llvm_basename_maybe_fail (llvm_version , arch , os , dist , should_fail ):
956
- basenames = _find_llvm_basename_list (llvm_version , arch , os , dist )
964
+ def _find_llvm_basename_or_error (llvm_version , host_info ):
965
+ basenames = _find_llvm_basename_list (llvm_version , host_info )
957
966
if len (basenames ) > 1 :
958
- if fail :
959
- fail ("ERROR: Multiple configurations found [{basenames}]." .format (
960
- basenames = ", " .join (basenames ),
961
- ))
962
- return None
967
+ return None , "ERROR: Multiple configurations found [{basenames}]." .format (
968
+ basenames = ", " .join (basenames ),
969
+ )
963
970
if not basenames :
964
- if should_fail :
965
- fail ( "ERROR: No matching config could be found for version {llvm_version} on {os}/{dist_name}/{dist_version} with arch {arch}." . format (
966
- llvm_version = llvm_version ,
967
- os = os ,
968
- dist_name = dist . name ,
969
- dist_version = dist .version ,
970
- arch = arch ,
971
- ))
972
- return None
971
+ return None , "ERROR: No version selected"
972
+ # TODO(helly25): Enable better error message:
973
+ #"ERROR: No matching config could be found for version { llvm_version} on {os}/{dist_name}/{dist_version} with arch {arch}.".format(
974
+ # llvm_version = llvm_version ,
975
+ # os = host_info.os ,
976
+ # dist_name = host_info. dist.name ,
977
+ # dist_version = host_info.dist.version ,
978
+ # arch = host_info.arch,
979
+ #)
973
980
974
981
# Use the following for debugging:
975
982
# print("Found LLVM: " + basenames[0]) # buildifier: disable=print
976
- return basenames [0 ]
977
-
978
- def _major_llvm_version (llvm_version ):
979
- """Return the major version given `<major>['.' <minor> [ '.' <mini> [.*]]]."""
980
- return int (llvm_version .split ("." )[0 ])
981
-
982
- def _host_can_be_found (major_llvm_version , host_info ):
983
- """Return whether the basename can be found or needs to be predicted."""
984
- if major_llvm_version >= 19 :
985
- return True
986
- if host_info .os in ["darwin" , "windows" ]:
987
- return True
988
- if _dist_to_os_names (host_info .dist , []):
989
- return True
990
- if host_info .arch in ["aarch64" , "armv7a" , "mips" , "mipsel" ]:
991
- return True
992
-
993
- return False
994
-
995
- def _llvm_release_name (rctx , llvm_version ):
996
- """Try to find the distribution in the configured list. Otherwise predict version name by input.
997
-
998
- For versions 19+ or we os==darwin fail if the distribution cannot be found automatically."""
999
- major_llvm_version = _major_llvm_version (llvm_version )
1000
- host_info = _host_info (rctx )
1001
- should_fail = _host_can_be_found (major_llvm_version , host_info )
1002
- basename = _find_llvm_basename_maybe_fail (llvm_version , host_info .arch , host_info .os , host_info .dist , should_fail )
1003
- if basename :
1004
- return basename
1005
- return _llvm_release_name_context (rctx , llvm_version )
983
+ return basenames [0 ], None
1006
984
1007
985
def _distribution_urls (rctx ):
1008
986
"""Return LLVM `urls`, `shha256` and `strip_prefix` for the given context."""
1009
987
llvm_version = _get_llvm_version (rctx )
1010
988
1011
989
if rctx .attr .distribution == "auto" :
1012
- basename = llvm_release_name_context (rctx , llvm_version )
990
+ basename , error = _find_llvm_basename_or_error (rctx , llvm_version )
991
+ if error :
992
+ fail (error )
1013
993
else :
1014
994
basename = rctx .attr .distribution
1015
995
@@ -1043,11 +1023,8 @@ def _distribution_urls(rctx):
1043
1023
def _parse_version (v ):
1044
1024
return tuple ([int (s ) for s in v .split ("." )])
1045
1025
1046
- def _version_ge (lhs , rhs ):
1047
- return _parse_version (lhs ) >= _parse_version (rhs )
1048
-
1049
- def _version_le (lhs , rhs ):
1050
- return _parse_version (lhs ) <= _parse_version (rhs )
1026
+ def _version_string (version ):
1027
+ return "." .join ([str (v ) for v in version ])
1051
1028
1052
1029
def _write_distributions_impl (ctx ):
1053
1030
"""Analyze the configured versions and write to a file for test consumption.
@@ -1076,15 +1053,13 @@ def _write_distributions_impl(ctx):
1076
1053
"linux" ,
1077
1054
"windows" ,
1078
1055
]
1079
- ANY_VER = "0" # Version does not matter, but must be valie integer
1056
+ ANY_VERSION = "0" # Version does not matter, but must be a valid integer
1080
1057
dist_dict_list = {
1081
1058
"linux" : [
1082
1059
# struct(name = "ibm-aix", version = "7.2"), unreachable
1083
- # struct(name = "linux-gnu-debian", version = "8"), unreachable
1084
- # struct(name = "linux-gnu-rhel", version = "8.4"), unreachable
1085
1060
# keep sorted
1086
- struct (name = "amzn" , version = ANY_VER ),
1087
- struct (name = "arch" , version = ANY_VER ),
1061
+ struct (name = "amzn" , version = ANY_VERSION ),
1062
+ struct (name = "arch" , version = ANY_VERSION ),
1088
1063
struct (name = "centos" , version = "6" ),
1089
1064
struct (name = "centos" , version = "7" ),
1090
1065
struct (name = "debian" , version = "0" ),
@@ -1100,8 +1075,8 @@ def _write_distributions_impl(ctx):
1100
1075
struct (name = "linuxmint" , version = "18" ),
1101
1076
struct (name = "linuxmint" , version = "19" ),
1102
1077
struct (name = "pc-solaris" , version = "2.11" ),
1103
- struct (name = "raspbian" , version = ANY_VER ),
1104
- struct (name = "rhel" , version = ANY_VER ),
1078
+ struct (name = "raspbian" , version = ANY_VERSION ),
1079
+ struct (name = "rhel" , version = ANY_VERSION ),
1105
1080
struct (name = "sun-solaris" , version = "2.11" ),
1106
1081
struct (name = "suse" , version = "11.3" ),
1107
1082
struct (name = "suse" , version = "12.2" ),
@@ -1123,19 +1098,20 @@ def _write_distributions_impl(ctx):
1123
1098
}
1124
1099
1125
1100
# Compute all unique version strings starting with `MIN_VERSION`.
1126
- MIN_VERSION = "6.0.0"
1101
+ MIN_VERSION = _parse_version ("6.0.0" )
1102
+ MAX_VERSION = _parse_version ("20.1.3" )
1127
1103
version_list = []
1128
1104
for name in _llvm_distributions .keys ():
1129
1105
for prefix in ["LLVM-" , "clang+llvm-" ]:
1130
1106
if name .startswith (prefix ):
1131
- version = name .split ("-" , 2 )[1 ]
1132
- if _version_ge ( version , MIN_VERSION ) :
1107
+ version = _parse_version ( name .split ("-" , 2 )[1 ])
1108
+ if version >= MIN_VERSION :
1133
1109
version_list .append (version )
1134
1110
break
1135
- for version in _llvm_distributions_base_url .keys ():
1136
- if not _version_ge ( version , MIN_VERSION ):
1137
- continue
1138
- version_list .append (version )
1111
+ for v in _llvm_distributions_base_url .keys ():
1112
+ version = _parse_version ( v )
1113
+ if version >= MIN_VERSION :
1114
+ version_list .append (version )
1139
1115
versions = {v : None for v in version_list }
1140
1116
1141
1117
# Write versions to output to check which versions we take into account.
@@ -1156,6 +1132,7 @@ def _write_distributions_impl(ctx):
1156
1132
# At the end we add the not-found versions as False.
1157
1133
result = {}
1158
1134
1135
+ # Collect cases that produce duplicates (or multiple) basenames.
1159
1136
dupes = []
1160
1137
1161
1138
# For all versions X arch X os check if we can compute the distribution.
@@ -1164,35 +1141,44 @@ def _write_distributions_impl(ctx):
1164
1141
for os in os_list :
1165
1142
dist_list = dist_dict_list .get (os , [struct (name = os , version = "" )])
1166
1143
for dist in dist_list :
1167
- basenames = _find_llvm_basename_list (version , arch , os , dist )
1168
- if _version_le (version , "20.1.3" ):
1169
- if len (basenames ) == 0 :
1170
- predicted = "ERROR: No version selected"
1171
- elif len (basenames ) == 1 :
1172
- predicted = basenames [0 ]
1173
- else :
1174
- predicted = "ERROR: Multiple selections"
1175
- if not predicted .startswith ("ERROR:" ):
1144
+ host_info = struct (
1145
+ arch = arch ,
1146
+ os = os ,
1147
+ dist = dist ,
1148
+ )
1149
+ basenames = _find_llvm_basename_list (_version_string (version ), host_info )
1150
+ if version <= MAX_VERSION :
1151
+ predicted , error = _find_llvm_basename_or_error (
1152
+ _version_string (version ),
1153
+ host_info ,
1154
+ )
1155
+ if not error :
1176
1156
if predicted .endswith (".exe" ):
1177
- predicted = "ERROR: Windows .exe is not supported: " + predicted
1157
+ error = "ERROR: Windows .exe is not supported: " + predicted
1178
1158
elif predicted not in _llvm_distributions :
1179
- predicted = "ERROR: Unavailable prediction: " + predicted
1159
+ error = "ERROR: Unavailable prediction: " + predicted
1160
+ elif len (basenames ) == 0 :
1161
+ predicted = "ERROR: No version selected"
1162
+ elif len (basenames ) == 1 :
1163
+ predicted = basenames [0 ]
1180
1164
else :
1165
+ predicted = "ERROR: Multiple selections"
1166
+ if not error :
1181
1167
arch_found = [arch for arch in arch_list if arch in predicted ]
1182
1168
if len (arch_found ) == 1 and arch_found [0 ] != arch :
1183
- predicted = "ERROR: Bad arch selection: " + predicted
1169
+ error = "ERROR: Bad arch selection: " + predicted
1184
1170
select .append ("{version}-{arch}-{os}/{dist_name}/{dist_version} -> {basename}" .format (
1185
- version = version ,
1171
+ version = _version_string ( version ) ,
1186
1172
arch = arch ,
1187
1173
os = os ,
1188
1174
dist_name = dist .name ,
1189
1175
dist_version = dist .version ,
1190
- basename = predicted ,
1176
+ basename = error or predicted ,
1191
1177
))
1192
1178
if len (basenames ) != 1 :
1193
1179
if basenames :
1194
1180
dupes .append ("dup: {version}-{arch}-{os}-{dist_name}-{dist_version} -> {count}" .format (
1195
- version = version ,
1181
+ version = _version_string ( version ) ,
1196
1182
arch = arch ,
1197
1183
os = os ,
1198
1184
dist_name = dist .name ,
0 commit comments