1919import signal
2020import subprocess
2121import sys
22- from typing import ClassVar , List
22+ from typing import ClassVar , List , Optional
2323
2424
2525@dataclass
2626class TestEnvironment :
2727 rust_dir : str
2828 sdk_dir : str
29- target_arch : str
30- package_server_pid : int = None
31- emu_addr : str = None
32- libstd_name : str = None
33- libtest_name : str = None
29+ target : str
30+ package_server_pid : Optional [ int ] = None
31+ emu_addr : Optional [ str ] = None
32+ libstd_name : Optional [ str ] = None
33+ libtest_name : Optional [ str ] = None
3434 verbose : bool = False
3535
3636 @staticmethod
@@ -40,6 +40,15 @@ def tmp_dir():
4040 return os .path .abspath (tmp_dir )
4141 return os .path .join (os .path .dirname (__file__ ), "tmp~" )
4242
43+ @staticmethod
44+ def triple_to_arch (triple ):
45+ if "x86_64" in triple :
46+ return "x64"
47+ elif "aarch64" in triple :
48+ return "arm64"
49+ else :
50+ raise Exception (f"Unrecognized target triple { triple } " )
51+
4352 @classmethod
4453 def env_file_path (cls ):
4554 return os .path .join (cls .tmp_dir (), "test_env.json" )
@@ -49,7 +58,7 @@ def from_args(cls, args):
4958 return cls (
5059 os .path .abspath (args .rust ),
5160 os .path .abspath (args .sdk ),
52- args .target_arch ,
61+ args .target ,
5362 verbose = args .verbose ,
5463 )
5564
@@ -60,21 +69,14 @@ def read_from_file(cls):
6069 return cls (
6170 test_env ["rust_dir" ],
6271 test_env ["sdk_dir" ],
63- test_env ["target_arch " ],
72+ test_env ["target " ],
6473 libstd_name = test_env ["libstd_name" ],
6574 libtest_name = test_env ["libtest_name" ],
6675 emu_addr = test_env ["emu_addr" ],
6776 package_server_pid = test_env ["package_server_pid" ],
6877 verbose = test_env ["verbose" ],
6978 )
7079
71- def image_name (self ):
72- if self .target_arch == "x64" :
73- return "qemu-x64"
74- if self .target_arch == "arm64" :
75- return "qemu-arm64"
76- raise Exception (f"Unrecognized target architecture { self .target_arch } " )
77-
7880 def write_to_file (self ):
7981 with open (self .env_file_path (), "w" , encoding = "utf-8" ) as f :
8082 f .write (json .dumps (self .__dict__ ))
@@ -108,13 +110,6 @@ def output_dir(self):
108110 def repo_dir (self ):
109111 return os .path .join (self .tmp_dir (), self .TEST_REPO_NAME )
110112
111- def rustlib_dir (self ):
112- if self .target_arch == "x64" :
113- return "x86_64-unknown-fuchsia"
114- if self .target_arch == "arm64" :
115- return "aarch64-unknown-fuchsia"
116- raise Exception (f"Unrecognized target architecture { self .target_arch } " )
117-
118113 def libs_dir (self ):
119114 return os .path .join (
120115 self .rust_dir ,
@@ -125,7 +120,7 @@ def rustlibs_dir(self):
125120 return os .path .join (
126121 self .libs_dir (),
127122 "rustlib" ,
128- self .rustlib_dir () ,
123+ self .target ,
129124 "lib" ,
130125 )
131126
@@ -384,7 +379,7 @@ def start(self):
384379 "--emulator-log" ,
385380 self .emulator_log_path (),
386381 "--image-name" ,
387- self .image_name ( ),
382+ "qemu-" + self .triple_to_arch ( self . target ),
388383 ],
389384 stdout = self .subprocess_output (),
390385 stderr = self .subprocess_output (),
@@ -642,11 +637,11 @@ def log(msg):
642637 package_dir = package_dir ,
643638 package_name = package_name ,
644639 rust_dir = self .rust_dir ,
645- rustlib_dir = self .rustlib_dir () ,
640+ rustlib_dir = self .target ,
646641 sdk_dir = self .sdk_dir ,
647642 libstd_name = self .libstd_name ,
648643 libtest_name = self .libtest_name ,
649- target_arch = self .target_arch ,
644+ target_arch = self .triple_to_arch ( self . target ) ,
650645 )
651646 )
652647 for shared_lib in shared_libs :
@@ -969,8 +964,8 @@ def print_help(args):
969964 action = "store_true" ,
970965 )
971966 start_parser .add_argument (
972- "--target-arch " ,
973- help = "the architecture of the image to test" ,
967+ "--target" ,
968+ help = "the target platform to test" ,
974969 required = True ,
975970 )
976971 start_parser .set_defaults (func = start )
0 commit comments