@@ -786,23 +786,28 @@ def _get_llvm_version(rctx):
786786 )
787787 return llvm_version
788788
789- def _get_all_llvm_distributions (* , extra_llvm_distributions ):
790- dists = {
791- basename : struct (
789+ def _get_all_llvm_distributions (* , llvm_distributions , extra_llvm_distributions , parsed_llvm_version ):
790+ distributions = {}
791+ for basename , sha256 in llvm_distributions .items ():
792+ version = _distribution_version (basename )
793+ if parsed_llvm_version and parsed_llvm_version != version :
794+ continue
795+ distributions [basename ] = struct (
792796 distribution = basename ,
793797 sha256 = sha256 ,
798+ version = version ,
794799 )
795- for basename , sha256 in _llvm_distributions .items ()
796- }
797800 if extra_llvm_distributions :
798- dists = dists | {
799- _distribution_basename (dist ): struct (
801+ for dist , sha256 in extra_llvm_distributions .items ():
802+ version = _distribution_version (dist )
803+ if parsed_llvm_version and parsed_llvm_version != version :
804+ continue
805+ distributions [_distribution_basename (dist )] = struct (
800806 distribution = dist ,
801807 sha256 = sha256 ,
808+ version = version ,
802809 )
803- for dist , sha256 in extra_llvm_distributions .items ()
804- }
805- return dists
810+ return distributions
806811
807812_UBUNTU_NAMES = [
808813 "arch" ,
@@ -1093,7 +1098,11 @@ def _find_llvm_basename_or_error(llvm_version, all_llvm_distributions, host_info
10931098def _distribution_urls (rctx ):
10941099 """Return LLVM `urls`, `shha256` and `strip_prefix` for the given context."""
10951100 llvm_version = _get_llvm_version (rctx )
1096- all_llvm_distributions = _get_all_llvm_distributions (extra_llvm_distributions = rctx .attr .extra_llvm_distributions )
1101+ all_llvm_distributions = _get_all_llvm_distributions (
1102+ llvm_distributions = _llvm_distributions ,
1103+ extra_llvm_distributions = rctx .attr .extra_llvm_distributions ,
1104+ parsed_llvm_version = _parse_version (llvm_version ),
1105+ )
10971106 _ , sha256 , strip_prefix , _ = _key_attrs (rctx )
10981107
10991108 if rctx .attr .distribution == "auto" :
@@ -1145,17 +1154,18 @@ def _write_distributions_impl(ctx):
11451154 verify that predicted distributions have been configured. Otherwise the
11461155 algorithm could not know the hash value.
11471156 """
1148- all_llvm_distributions = _get_all_llvm_distributions (
1149- # Inject version '0.0.0' that verifies additional behavior using `extra_llvm_distributions`.
1150- extra_llvm_distributions = {
1151- "LLVM-0.0.0-Linux-ARM64.tar.xz" : "a6b8679be46bdaa383e0c7f13a473ca8f7a4f87233f2cc0e0a7ab19e1b6265e7" ,
1152- "/foo/bar/LLVM-0.0.0-Linux-X64.tar.xz?xyz" : "0a764a8ca521606532ca9ec4e5745c933b16b7d30f4701a47ee851d448fcdb74" ,
1153- "http://server/foo/bar/LLVM-0.0.0-macOS-ARM64.tar.xz#xyz" : "9da86f64a99f5ce9b679caf54e938736ca269c5e069d0c94ad08b995c5f25c16" ,
1154- "http://server/foo/bar/LLVM-0.0.0-macOS-X64.tar.xz" : "264f2f1e8b67f066749349ae8b4943d346cd44e099464164ef21b42a57663540" ,
1155- "http://server/clang%2Bllvm-0.0.0-aarch64-pc-windows-msvc.tar.xz" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1156- "http://server/path-to-file/clang%2Bllvm-0.0.0-x86_64-pc-windows-msvc.tar.xz#bla" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1157- },
1158- )
1157+ use_llvm_distributions = _llvm_distributions
1158+
1159+ # Inject version '0.0.0' that verifies additional behavior using `extra_llvm_distributions`.
1160+ extra_llvm_distributions = {
1161+ "LLVM-0.0.0-Linux-ARM64.tar.xz" : "a6b8679be46bdaa383e0c7f13a473ca8f7a4f87233f2cc0e0a7ab19e1b6265e7" ,
1162+ "/foo/bar/LLVM-0.0.0-Linux-X64.tar.xz?xyz" : "0a764a8ca521606532ca9ec4e5745c933b16b7d30f4701a47ee851d448fcdb74" ,
1163+ "http://server/foo/bar/LLVM-0.0.0-macOS-ARM64.tar.xz#xyz" : "9da86f64a99f5ce9b679caf54e938736ca269c5e069d0c94ad08b995c5f25c16" ,
1164+ "http://server/foo/bar/LLVM-0.0.0-macOS-X64.tar.xz" : "264f2f1e8b67f066749349ae8b4943d346cd44e099464164ef21b42a57663540" ,
1165+ "http://server/clang%2Bllvm-0.0.0-aarch64-pc-windows-msvc.tar.xz" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1166+ "http://server/path-to-file/clang%2Bllvm-0.0.0-x86_64-pc-windows-msvc.tar.xz#bla" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1167+ }
1168+
11591169 arch_list = [
11601170 "aarch64" ,
11611171 "armv7a" ,
@@ -1181,7 +1191,6 @@ def _write_distributions_impl(ctx):
11811191 dist_dict_list = {
11821192 "linux" : [
11831193 # keep sorted
1184- struct (name = "ibm-aix" , version = "7.2" ),
11851194 struct (name = "amzn" , version = ANY_VERSION ),
11861195 struct (name = "arch" , version = ANY_VERSION ),
11871196 struct (name = "centos" , version = "6" ),
@@ -1196,6 +1205,7 @@ def _write_distributions_impl(ctx):
11961205 struct (name = "freebsd" , version = "11" ),
11971206 struct (name = "freebsd" , version = "12" ),
11981207 struct (name = "freebsd" , version = "13" ),
1208+ struct (name = "ibm-aix" , version = "7.2" ),
11991209 struct (name = "linuxmint" , version = "18" ),
12001210 struct (name = "linuxmint" , version = "19" ),
12011211 struct (name = "pc-solaris" , version = "2.11" ),
@@ -1228,7 +1238,7 @@ def _write_distributions_impl(ctx):
12281238 MAX_VERSION = _parse_version ("20.1.3" )
12291239 version_dict = {
12301240 _distribution_version (basename ): None
1231- for basename in all_llvm_distributions .keys ()
1241+ for basename in use_llvm_distributions . keys () + extra_llvm_distributions .keys ()
12321242 } | {
12331243 _parse_version (v ): None
12341244 for v in _llvm_distributions_base_url .keys ()
@@ -1244,8 +1254,8 @@ def _write_distributions_impl(ctx):
12441254 # We keep track of versions in `not_found` and remove the ones we found.
12451255 # So at the end all version that were not found remain, hence the name.
12461256 not_found = {
1247- basename : None
1248- for basename in all_llvm_distributions .keys ()
1257+ _distribution_basename ( distribution ) : None
1258+ for distribution in use_llvm_distributions . keys () + extra_llvm_distributions .keys ()
12491259 }
12501260
12511261 # While computing we add predicted versions that are not configured as True.
@@ -1257,6 +1267,11 @@ def _write_distributions_impl(ctx):
12571267
12581268 # For all versions X arch X os check if we can compute the distribution.
12591269 for version in versions :
1270+ all_llvm_distributions = _get_all_llvm_distributions (
1271+ llvm_distributions = use_llvm_distributions ,
1272+ extra_llvm_distributions = extra_llvm_distributions ,
1273+ parsed_llvm_version = version ,
1274+ )
12601275 for arch in arch_list :
12611276 for os in os_list :
12621277 if version < MIN_VERSION :
@@ -1283,17 +1298,17 @@ def _write_distributions_impl(ctx):
12831298 all_llvm_distributions ,
12841299 host_info ,
12851300 )
1301+ skip_output = False
12861302 if error :
12871303 if error .startswith ("ERROR: No matching config could be found for version" ):
1288- # Simplify test output:
1289- error = "ERROR: No version selected"
1304+ skip_output = True
12901305 else :
12911306 if predicted .endswith (".exe" ):
12921307 error = "ERROR: Windows .exe is not supported: " + predicted
12931308 elif predicted not in all_llvm_distributions :
12941309 error = "ERROR: Unavailable prediction: " + predicted
12951310 elif len (basenames ) == 0 :
1296- error = "ERROR: No version selected"
1311+ skip_output = True
12971312 elif len (basenames ) == 1 :
12981313 predicted = basenames [0 ]
12991314 else :
@@ -1302,14 +1317,15 @@ def _write_distributions_impl(ctx):
13021317 arch_found = [arch for arch in arch_list if arch in predicted ]
13031318 if len (arch_found ) == 1 and arch_found [0 ] not in arch_alias_dict .get (arch , [arch ]):
13041319 error = "ERROR: Bad arch selection: " + predicted
1305- select .append ("{version}-{arch}-{os}/{dist_name}/{dist_version} -> {basename}" .format (
1306- version = _version_string (version ),
1307- arch = arch ,
1308- os = os ,
1309- dist_name = dist .name ,
1310- dist_version = dist .version ,
1311- basename = error or predicted ,
1312- ))
1320+ if not skip_output :
1321+ select .append ("{version}-{arch}-{os}/{dist_name}/{dist_version} -> {basename}" .format (
1322+ version = _version_string (version ),
1323+ arch = arch ,
1324+ os = os ,
1325+ dist_name = dist .name ,
1326+ dist_version = dist .version ,
1327+ basename = error or predicted ,
1328+ ))
13131329 if len (basenames ) != 1 :
13141330 if basenames :
13151331 dupes .append ("dup: {version}-{arch}-{os}-{dist_name}-{dist_version} -> {count}" .format (
0 commit comments