11#!/usr/bin/env python3
2- import multiprocessing
3- import subprocess
42import argparse
53import csv
4+ import multiprocessing
5+ import subprocess
66import sys
77from collections import defaultdict
88from pathlib import Path
5252]
5353
5454
55+ class MissingToolchainError (Exception ):
56+ """A toolchain or SDK needed to check a target is not installed."""
57+
58+
5559class Target (str ):
5660 def __new__ (cls , content ):
5761 obj = super ().__new__ (cls , content )
@@ -105,36 +109,38 @@ def check(self, binary):
105109 f"--target={ self } " ,
106110 ]
107111
108- res = subprocess .run (args , capture_output = True )
112+ res = subprocess .run (args , capture_output = True , check = False )
109113 return res .returncode
110114
111115 # Validate that the dependencies for running this target are met
112116 def is_installed (self ):
113117 # check IOS sdk is installed, raise exception otherwise
114118 if "ios" in self :
115- res = subprocess .run (["which" , "xcrun" ], capture_output = True )
119+ res = subprocess .run (["which" , "xcrun" ], capture_output = True , check = False )
116120 if len (res .stdout ) == 0 :
117- raise Exception (
121+ raise MissingToolchainError (
118122 "Error: IOS sdk does not seem to be installed. Please do that manually"
119123 )
120124 if not self .requires_nightly ():
121125 # check std toolchains are installed
122126 toolchains = subprocess .run (
123- ["rustup" , "target" , "list" ], capture_output = True
127+ ["rustup" , "target" , "list" ], capture_output = True , check = False
124128 )
125129 toolchains = toolchains .stdout .decode ("utf-8" ).split ("\n " )
126130 if "installed" not in next (filter (lambda x : self in x , toolchains )):
127- raise Exception (
131+ raise MissingToolchainError (
128132 f"Error: the { self } target is not installed. Please do that manually"
129133 )
130134 else :
131135 # check nightly toolchains are installed
132136 toolchains = subprocess .run (
133- ["rustup" , "+nightly" , "target" , "list" ], capture_output = True
137+ ["rustup" , "+nightly" , "target" , "list" ],
138+ capture_output = True ,
139+ check = False ,
134140 )
135141 toolchains = toolchains .stdout .decode ("utf-8" ).split ("\n " )
136142 if "installed" not in next (filter (lambda x : self in x , toolchains )):
137- raise Exception (
143+ raise MissingToolchainError (
138144 f"Error: the { self } nightly target is not installed. Please do that manually"
139145 )
140146 return True
@@ -143,13 +149,12 @@ def is_installed(self):
143149def install_targets ():
144150 cmd = ["rustup" , "target" , "add" ] + TARGETS
145151 print (" " .join (cmd ))
146- ret = subprocess .run (cmd )
152+ ret = subprocess .run (cmd , check = False )
147153 assert ret .returncode == 0
148154
149155
150156def get_all_bins ():
151- bins = map (lambda x : x .name , BINS_PATH .iterdir ())
152- return sorted (list (bins ))
157+ return sorted (path .name for path in BINS_PATH .iterdir ())
153158
154159
155160def get_targets (selection ):
@@ -180,7 +185,7 @@ def test_all_targets(targets, bins):
180185
181186def save_csv (file , table ):
182187 targets = get_targets (table .keys ()) # preserve order in CSV
183- bins = list (list ( table .values ())[ 0 ] .keys ())
188+ bins = list (next ( iter ( table .values ())) .keys ())
184189 with open (file , "w" ) as csvfile :
185190 header = ["target" ] + bins
186191 writer = csv .DictWriter (csvfile , fieldnames = header )
@@ -215,8 +220,8 @@ def merge_tables(old, new):
215220
216221
217222def render_md (fd , table , headings : str , row_headings : Target ):
218- def print_row (lst , lens = [] ):
219- lens = lens + [0 ] * (len (lst ) - len (lens ))
223+ def print_row (lst , lens = None ):
224+ lens = ( lens or []) + [0 ] * (len (lst ) - len (lens or [] ))
220225 for e , lmd in zip (lst , lens ):
221226 fmt = "|{}" if lmd == 0 else "|{:>%s}" % len (header [0 ])
222227 fd .write (fmt .format (e ))
@@ -227,20 +232,20 @@ def cell_render(target, bin):
227232
228233 # add some 'hard' padding to specific columns
229234 lens = [
230- max (map ( lambda x : len (x .os ), row_headings ) ) + 2 ,
231- max (map ( lambda x : len (x .arch ), row_headings ) ) + 2 ,
235+ max (len (target .os ) for target in row_headings ) + 2 ,
236+ max (len (target .arch ) for target in row_headings ) + 2 ,
232237 ]
233238 header = Target .get_heading ()
234239 header [0 ] = ("{:#^%d}" % lens [0 ]).format (header [0 ])
235240 header [1 ] = ("{:#^%d}" % lens [1 ]).format (header [1 ])
236241
237242 header += headings
238243 print_row (header )
239- lines = list ( map ( lambda x : "-" * len (x ), header ))
244+ lines = [ "-" * len (column ) for column in header ]
240245 print_row (lines )
241246
242247 for t in row_headings :
243- row = list ( map ( lambda b : cell_render (t , b ), headings ))
248+ row = [ cell_render (t , b ) for b in headings ]
244249 row = t .get_row_heading () + row
245250 print_row (row )
246251
0 commit comments