77import difflib , os , re , shutil , random
88import tomli
99
10+ def read_rust_version ():
11+ toolchain_path = os .path .join (os .path .dirname (__file__ ),
12+ '../../../../libcc2rs/rust-toolchain.toml' )
13+ with open (toolchain_path , 'rb' ) as f :
14+ return tomli .load (f )['toolchain' ]['channel' ]
15+
16+ def shared_target_dir ():
17+ return os .path .abspath (os .path .join (
18+ os .path .dirname (__file__ ),
19+ '../../../../build/tmp/cargo-target' ))
20+
21+ def cargo_env ():
22+ return dict (os .environ , CARGO_TARGET_DIR = os .path .abspath (shared_target_dir ()))
23+
1024class Cpp2RustTest (TestFormat ):
1125 def __init__ (self ):
1226 self .regex_xfail = re .compile (r"//\s*XFAIL:\s*(.*)" )
1327 self .regex_panic = re .compile (r"//\s*panic\s*(?::\s*(.*))?$" , re .MULTILINE )
1428 self .regex_nocompile = re .compile (r"//\s*no-compile\s*(?::\s*(.*))?$" , re .MULTILINE )
1529 self .regex_nondet_result = re .compile (r"//\s*nondet-result\s*(?::\s*(.*))?$" , re .MULTILINE )
16- self .rust_version = self . readRustVersion ()
30+ self .rust_version = read_rust_version ()
1731 os .environ ['RUSTFLAGS' ] = '-Awarnings -A dangerous-implicit-autorefs'
1832
19- def readRustVersion (self ):
20- toolchain_path = os .path .join (os .path .dirname (__file__ ),
21- '../../../../libcc2rs/rust-toolchain.toml' )
22- with open (toolchain_path , 'rb' ) as f :
23- return tomli .load (f )['toolchain' ]['channel' ]
24-
25- def sharedTargetDir (self ):
26- return os .path .abspath (os .path .join (
27- os .path .dirname (__file__ ),
28- '../../../../build/tmp/cargo-target' ))
29-
30- def cargoEnv (self ):
31- return dict (os .environ , CARGO_TARGET_DIR = os .path .abspath (self .sharedTargetDir ()))
32-
3333 def updateExpected (self , generated , expected_path ):
3434 os .makedirs (os .path .dirname (expected_path ), exist_ok = True )
3535 with open (expected_path , 'w' ) as f :
@@ -152,7 +152,7 @@ def fail(str, code = fail_code):
152152""" )
153153
154154 cmd = ['cargo' , 'build' , '--release' , '--quiet' ]
155- _ , err , returncode = lit .util .executeCommand (cmd , tmp_dir , env = self . cargoEnv ())
155+ _ , err , returncode = lit .util .executeCommand (cmd , tmp_dir , env = cargo_env ())
156156 if should_not_compile :
157157 if returncode != 0 :
158158 shutil .rmtree (tmp_dir , True )
@@ -161,7 +161,7 @@ def fail(str, code = fail_code):
161161 if returncode != 0 :
162162 return fail ('cargo failed\n ' + err )
163163
164- rust_bin = os .path .join (self . sharedTargetDir (), "release" , pkg_name )
164+ rust_bin = os .path .join (shared_target_dir (), "release" , pkg_name )
165165
166166 if not skip_run :
167167 if should_panic :
0 commit comments