19
19
import signal
20
20
import subprocess
21
21
import sys
22
- from typing import ClassVar, List
22
+ from typing import ClassVar, List, Optional
23
23
24
24
25
25
@dataclass
26
26
class TestEnvironment:
27
27
rust_dir: str
28
28
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
34
34
verbose: bool = False
35
35
36
36
@staticmethod
@@ -40,6 +40,15 @@ def tmp_dir():
40
40
return os.path.abspath(tmp_dir)
41
41
return os.path.join(os.path.dirname(__file__), "tmp~")
42
42
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
+
43
52
@classmethod
44
53
def env_file_path(cls):
45
54
return os.path.join(cls.tmp_dir(), "test_env.json")
@@ -49,7 +58,7 @@ def from_args(cls, args):
49
58
return cls(
50
59
os.path.abspath(args.rust),
51
60
os.path.abspath(args.sdk),
52
- args.target_arch ,
61
+ args.target ,
53
62
verbose=args.verbose,
54
63
)
55
64
@@ -60,21 +69,14 @@ def read_from_file(cls):
60
69
return cls(
61
70
test_env["rust_dir"],
62
71
test_env["sdk_dir"],
63
- test_env["target_arch "],
72
+ test_env["target "],
64
73
libstd_name=test_env["libstd_name"],
65
74
libtest_name=test_env["libtest_name"],
66
75
emu_addr=test_env["emu_addr"],
67
76
package_server_pid=test_env["package_server_pid"],
68
77
verbose=test_env["verbose"],
69
78
)
70
79
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
-
78
80
def write_to_file(self):
79
81
with open(self.env_file_path(), "w", encoding="utf-8") as f:
80
82
f.write(json.dumps(self.__dict__))
@@ -108,13 +110,6 @@ def output_dir(self):
108
110
def repo_dir(self):
109
111
return os.path.join(self.tmp_dir(), self.TEST_REPO_NAME)
110
112
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
-
118
113
def libs_dir(self):
119
114
return os.path.join(
120
115
self.rust_dir,
@@ -125,7 +120,7 @@ def rustlibs_dir(self):
125
120
return os.path.join(
126
121
self.libs_dir(),
127
122
"rustlib",
128
- self.rustlib_dir() ,
123
+ self.target ,
129
124
"lib",
130
125
)
131
126
@@ -384,7 +379,7 @@ def start(self):
384
379
"--emulator-log",
385
380
self.emulator_log_path(),
386
381
"--image-name",
387
- self.image_name( ),
382
+ "qemu-" + self.triple_to_arch(self.target ),
388
383
],
389
384
stdout=self.subprocess_output(),
390
385
stderr=self.subprocess_output(),
@@ -642,11 +637,11 @@ def log(msg):
642
637
package_dir=package_dir,
643
638
package_name=package_name,
644
639
rust_dir=self.rust_dir,
645
- rustlib_dir=self.rustlib_dir() ,
640
+ rustlib_dir=self.target ,
646
641
sdk_dir=self.sdk_dir,
647
642
libstd_name=self.libstd_name,
648
643
libtest_name=self.libtest_name,
649
- target_arch=self.target_arch ,
644
+ target_arch=self.triple_to_arch(self.target) ,
650
645
)
651
646
)
652
647
for shared_lib in shared_libs:
@@ -969,8 +964,8 @@ def print_help(args):
969
964
action="store_true",
970
965
)
971
966
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",
974
969
required=True,
975
970
)
976
971
start_parser.set_defaults(func=start)
0 commit comments