@@ -128,6 +128,48 @@ def doc():
128
128
'--package' , 'uefi-services' ,
129
129
], check = True )
130
130
131
+ def get_rustc_cfg ():
132
+ 'Run and parse "rustc --print=cfg" as key, val pairs.'
133
+ output = sp .run ([
134
+ 'rustc' , '--print=cfg'
135
+ ], check = True , capture_output = True , text = True ).stdout
136
+ for line in output .splitlines ():
137
+ parts = line .split ('=' , maxsplit = 1 )
138
+ # Only interested in the lines that look like this: key="val"
139
+ if len (parts ) == 2 :
140
+ key = parts [0 ]
141
+ val = parts [1 ]
142
+ # Strip the quotes
143
+ if val .startswith ('"' ) and val .endswith ('"' ):
144
+ val = val [1 :- 1 ]
145
+ yield key , val
146
+
147
+ def get_host_target ():
148
+ 'Get the host target, e.g. "x86_64-unknown-linux-gnu".'
149
+ cfg = dict (get_rustc_cfg ())
150
+ arch = cfg ['target_arch' ]
151
+ vendor = cfg ['target_vendor' ]
152
+ os = cfg ['target_os' ]
153
+ env = cfg ['target_env' ]
154
+ return f'{ arch } -{ vendor } -{ os } -{ env } '
155
+
156
+ def test ():
157
+ 'Run tests and doctests using the host target.'
158
+ repo_dir = Path (__file__ ).resolve ().parent .parent
159
+ sp .run ([
160
+ 'cargo' , 'test' ,
161
+ # Specifying the manifest path allows this command to
162
+ # run successfully regardless of the CWD.
163
+ '--manifest-path' , repo_dir / 'Cargo.toml' ,
164
+ '-Zbuild-std=std' ,
165
+ '--target' , get_host_target (),
166
+ '--features' , 'exts' ,
167
+ '--package' , 'uefi' ,
168
+ '--package' , 'uefi-macros' ,
169
+ # Don't test uefi-services (or the packages that depend on it)
170
+ # as it has lang items that conflict with `std`.
171
+ ], check = True )
172
+
131
173
def ovmf_files (ovmf_dir ):
132
174
'Returns the tuple of paths to the OVMF code and vars firmware files, given the directory'
133
175
if SETTINGS ['arch' ] == 'x86_64' :
@@ -348,7 +390,7 @@ def main():
348
390
parser = argparse .ArgumentParser (description = desc )
349
391
350
392
parser .add_argument ('verb' , help = 'command to run' , type = str ,
351
- choices = ['build' , 'run' , 'doc' , 'clippy' ])
393
+ choices = ['build' , 'run' , 'doc' , 'clippy' , 'test' ])
352
394
353
395
parser .add_argument ('--target' , help = 'target to build for (default: %(default)s)' , type = str ,
354
396
choices = ['x86_64' , 'aarch64' ], default = 'x86_64' )
@@ -382,6 +424,8 @@ def main():
382
424
clippy ()
383
425
elif verb == 'doc' :
384
426
doc ()
427
+ elif verb == 'test' :
428
+ test ()
385
429
elif verb == 'run' or verb is None or opts .verb == '' :
386
430
# Run the program, by default.
387
431
run_qemu ()
0 commit comments