@@ -787,23 +787,19 @@ def _get_llvm_version(rctx):
787
787
)
788
788
return llvm_version
789
789
790
- def _get_all_llvm_distributions (* , extra_llvm_distributions ):
791
- dists = {
792
- basename : struct (
790
+ def _get_all_llvm_distributions (* , llvm_distributions , extra_llvm_distributions , parsed_llvm_version ):
791
+ distributions = {}
792
+ for dist , sha256 in llvm_distributions .items () + (extra_llvm_distributions .items () if extra_llvm_distributions else []):
793
+ basename = _distribution_basename (dist )
794
+ version = _distribution_version (basename )
795
+ if parsed_llvm_version and parsed_llvm_version != version :
796
+ continue
797
+ distributions [basename ] = struct (
793
798
distribution = basename ,
794
799
sha256 = sha256 ,
800
+ version = version ,
795
801
)
796
- for basename , sha256 in _llvm_distributions .items ()
797
- }
798
- if extra_llvm_distributions :
799
- dists = dists | {
800
- _distribution_basename (dist ): struct (
801
- distribution = dist ,
802
- sha256 = sha256 ,
803
- )
804
- for dist , sha256 in extra_llvm_distributions .items ()
805
- }
806
- return dists
802
+ return distributions
807
803
808
804
_UBUNTU_NAMES = [
809
805
"arch" ,
@@ -1130,7 +1126,11 @@ def _required_llvm_release_name(*, version_or_requirements, all_llvm_distributio
1130
1126
return None , None , "ERROR: No matching distribution found."
1131
1127
1132
1128
def required_llvm_release_name_rctx (rctx , llvm_version ):
1133
- all_llvm_distributions = _get_all_llvm_distributions (rctx )
1129
+ all_llvm_distributions = _get_all_llvm_distributions (
1130
+ llvm_distributions = _llvm_distributions ,
1131
+ extra_llvm_distributions = rctx .attr .extra_llvm_distributions ,
1132
+ parsed_llvm_version = _parse_version (llvm_version ),
1133
+ )
1134
1134
return _required_llvm_release_name (
1135
1135
version_or_requirements = llvm_version ,
1136
1136
all_llvm_distributions = all_llvm_distributions ,
@@ -1215,17 +1215,18 @@ def _distributions_test_writer_impl(ctx):
1215
1215
verify that predicted distributions have been configured. Otherwise the
1216
1216
algorithm could not know the hash value.
1217
1217
"""
1218
- all_llvm_distributions = _get_all_llvm_distributions (
1219
- # Inject version '0.0.0' that verifies additional behavior using `extra_llvm_distributions`.
1220
- extra_llvm_distributions = {
1221
- "LLVM-0.0.0-Linux-ARM64.tar.xz" : "a6b8679be46bdaa383e0c7f13a473ca8f7a4f87233f2cc0e0a7ab19e1b6265e7" ,
1222
- "/foo/bar/LLVM-0.0.0-Linux-X64.tar.xz?xyz" : "0a764a8ca521606532ca9ec4e5745c933b16b7d30f4701a47ee851d448fcdb74" ,
1223
- "http://server/foo/bar/LLVM-0.0.0-macOS-ARM64.tar.xz#xyz" : "9da86f64a99f5ce9b679caf54e938736ca269c5e069d0c94ad08b995c5f25c16" ,
1224
- "http://server/foo/bar/LLVM-0.0.0-macOS-X64.tar.xz" : "264f2f1e8b67f066749349ae8b4943d346cd44e099464164ef21b42a57663540" ,
1225
- "http://server/clang%2Bllvm-0.0.0-aarch64-pc-windows-msvc.tar.xz" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1226
- "http://server/path-to-file/clang%2Bllvm-0.0.0-x86_64-pc-windows-msvc.tar.xz#bla" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1227
- },
1228
- )
1218
+ use_llvm_distributions = _llvm_distributions
1219
+
1220
+ # Inject version '0.0.0' that verifies additional behavior using `extra_llvm_distributions`.
1221
+ extra_llvm_distributions = {
1222
+ "LLVM-0.0.0-Linux-ARM64.tar.xz" : "a6b8679be46bdaa383e0c7f13a473ca8f7a4f87233f2cc0e0a7ab19e1b6265e7" ,
1223
+ "/foo/bar/LLVM-0.0.0-Linux-X64.tar.xz?xyz" : "0a764a8ca521606532ca9ec4e5745c933b16b7d30f4701a47ee851d448fcdb74" ,
1224
+ "http://server/foo/bar/LLVM-0.0.0-macOS-ARM64.tar.xz#xyz" : "9da86f64a99f5ce9b679caf54e938736ca269c5e069d0c94ad08b995c5f25c16" ,
1225
+ "http://server/foo/bar/LLVM-0.0.0-macOS-X64.tar.xz" : "264f2f1e8b67f066749349ae8b4943d346cd44e099464164ef21b42a57663540" ,
1226
+ "http://server/clang%2Bllvm-0.0.0-aarch64-pc-windows-msvc.tar.xz" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1227
+ "http://server/path-to-file/clang%2Bllvm-0.0.0-x86_64-pc-windows-msvc.tar.xz#bla" : "5916d93bf80e3ae504022cdd8cb8887be001f9b68a7a08bd268727e8d858afa4" ,
1228
+ }
1229
+
1229
1230
arch_list = [
1230
1231
"aarch64" ,
1231
1232
"armv7a" ,
@@ -1251,7 +1252,6 @@ def _distributions_test_writer_impl(ctx):
1251
1252
dist_dict_list = {
1252
1253
"linux" : [
1253
1254
# keep sorted
1254
- struct (name = "ibm-aix" , version = "7.2" ),
1255
1255
struct (name = "amzn" , version = ANY_VERSION ),
1256
1256
struct (name = "arch" , version = ANY_VERSION ),
1257
1257
struct (name = "centos" , version = "6" ),
@@ -1266,6 +1266,7 @@ def _distributions_test_writer_impl(ctx):
1266
1266
struct (name = "freebsd" , version = "11" ),
1267
1267
struct (name = "freebsd" , version = "12" ),
1268
1268
struct (name = "freebsd" , version = "13" ),
1269
+ struct (name = "ibm-aix" , version = "7.2" ),
1269
1270
struct (name = "linuxmint" , version = "18" ),
1270
1271
struct (name = "linuxmint" , version = "19" ),
1271
1272
struct (name = "pc-solaris" , version = "2.11" ),
@@ -1298,7 +1299,7 @@ def _distributions_test_writer_impl(ctx):
1298
1299
MAX_VERSION = _parse_version ("20.1.3" )
1299
1300
version_dict = {
1300
1301
_distribution_version (basename ): None
1301
- for basename in all_llvm_distributions .keys ()
1302
+ for basename in use_llvm_distributions . keys () + extra_llvm_distributions .keys ()
1302
1303
} | {
1303
1304
_parse_version (v ): None
1304
1305
for v in _llvm_distributions_base_url .keys ()
@@ -1314,8 +1315,8 @@ def _distributions_test_writer_impl(ctx):
1314
1315
# We keep track of versions in `not_found` and remove the ones we found.
1315
1316
# So at the end all version that were not found remain, hence the name.
1316
1317
not_found = {
1317
- basename : None
1318
- for basename in all_llvm_distributions .keys ()
1318
+ _distribution_basename ( distribution ) : None
1319
+ for distribution in use_llvm_distributions . keys () + extra_llvm_distributions .keys ()
1319
1320
}
1320
1321
1321
1322
# While computing we add predicted versions that are not configured as True.
@@ -1327,6 +1328,11 @@ def _distributions_test_writer_impl(ctx):
1327
1328
1328
1329
# For all versions X arch X os check if we can compute the distribution.
1329
1330
for version in versions :
1331
+ all_llvm_distributions = _get_all_llvm_distributions (
1332
+ llvm_distributions = use_llvm_distributions ,
1333
+ extra_llvm_distributions = extra_llvm_distributions ,
1334
+ parsed_llvm_version = version ,
1335
+ )
1330
1336
for arch in arch_list :
1331
1337
for os in os_list :
1332
1338
if version < MIN_VERSION :
@@ -1353,17 +1359,17 @@ def _distributions_test_writer_impl(ctx):
1353
1359
all_llvm_distributions ,
1354
1360
host_info ,
1355
1361
)
1362
+ skip_output = False
1356
1363
if error :
1357
1364
if error .startswith ("ERROR: No matching config could be found for version" ):
1358
- # Simplify test output:
1359
- error = "ERROR: No version selected"
1365
+ skip_output = True
1360
1366
else :
1361
1367
if predicted .endswith (".exe" ):
1362
1368
error = "ERROR: Windows .exe is not supported: " + predicted
1363
1369
elif predicted not in all_llvm_distributions :
1364
1370
error = "ERROR: Unavailable prediction: " + predicted
1365
1371
elif len (basenames ) == 0 :
1366
- error = "ERROR: No version selected"
1372
+ skip_output = True
1367
1373
elif len (basenames ) == 1 :
1368
1374
predicted = basenames [0 ]
1369
1375
else :
@@ -1372,14 +1378,15 @@ def _distributions_test_writer_impl(ctx):
1372
1378
arch_found = [arch for arch in arch_list if arch in predicted ]
1373
1379
if len (arch_found ) == 1 and arch_found [0 ] not in arch_alias_dict .get (arch , [arch ]):
1374
1380
error = "ERROR: Bad arch selection: " + predicted
1375
- select .append ("{version}-{arch}-{os}/{dist_name}/{dist_version} -> {basename}" .format (
1376
- version = _version_string (version ),
1377
- arch = arch ,
1378
- os = os ,
1379
- dist_name = dist .name ,
1380
- dist_version = dist .version ,
1381
- basename = error or predicted ,
1382
- ))
1381
+ if not skip_output :
1382
+ select .append ("{version}-{arch}-{os}/{dist_name}/{dist_version} -> {basename}" .format (
1383
+ version = _version_string (version ),
1384
+ arch = arch ,
1385
+ os = os ,
1386
+ dist_name = dist .name ,
1387
+ dist_version = dist .version ,
1388
+ basename = error or predicted ,
1389
+ ))
1383
1390
if len (basenames ) != 1 :
1384
1391
if basenames :
1385
1392
dupes .append ("dup: {version}-{arch}-{os}-{dist_name}-{dist_version} -> {count}" .format (
@@ -1408,7 +1415,7 @@ def _distributions_test_writer_impl(ctx):
1408
1415
ctx .actions .write (ctx .outputs .select , "\n " .join (select ) + "\n " )
1409
1416
1410
1417
write_distributions = rule (
1411
- implementation = _write_distributions_impl ,
1418
+ implementation = _distributions_test_writer_impl ,
1412
1419
attrs = {
1413
1420
"output" : attr .output (mandatory = True ),
1414
1421
"select" : attr .output (mandatory = True ),
0 commit comments