2
2
import os
3
3
import subprocess
4
4
import sys
5
+ import argparse
5
6
6
7
def read_from_file (path : str ) -> str :
7
8
with open (path , "r" ) as f :
@@ -19,7 +20,7 @@ def write_to_file(path: str, content: str):
19
20
with open (path , "w" ) as f :
20
21
f .write (content )
21
22
22
- def process_test (test_dir : str ):
23
+ def process_test (test_dir : str , release_mode : bool ):
23
24
test_name = os .path .basename (test_dir )
24
25
normalized = normalize_name (test_name )
25
26
print (f"|-- Test '{ test_name } ' ({ normalized } )" )
@@ -36,14 +37,14 @@ def process_test(test_dir: str):
36
37
37
38
# Run cargo build.
38
39
print ("|--- ⚒️ Building with Cargo..." )
39
- # see if the file no_jvm_target.flag exists in the test directory
40
+ build_cmd = [ "cargo" , "build" , "--release" ] if release_mode else [ "cargo" , "build" ]
40
41
no_jvm_target = os .path .join (test_dir , "no_jvm_target.flag" )
41
42
if os .path .exists (no_jvm_target ):
42
43
print ("|---- ⚠️ Skipping JVM target build due to no_jvm_target.flag" )
43
- proc = run_command (["cargo" , "build" ], cwd = test_dir )
44
44
else :
45
45
print ("|---- 🛠️ Building with JVM target..." )
46
- proc = run_command (["cargo" , "build" , "--target" , "../../../jvm-unknown-unknown.json" ], cwd = test_dir )
46
+ build_cmd .extend (["--target" , "../../../jvm-unknown-unknown.json" ])
47
+ proc = run_command (build_cmd , cwd = test_dir )
47
48
if proc .returncode != 0 :
48
49
fail_path = os .path .join (test_dir , "cargo-build-fail.generated" )
49
50
output = f"STDOUT:\n { proc .stdout } \n \n STDERR:\n { proc .stderr } "
@@ -53,26 +54,22 @@ def process_test(test_dir: str):
53
54
54
55
# Run java with the generated jar.
55
56
print ("|--- 🤖 Running with Java..." )
56
- # if no_jvm_target flag is set, we first need to move target/debug/deps/{test_name}-{hash}.jar to target/jvm-unknown-unknown/debug/{test_name}.jar
57
- # we might need to make the directory first
57
+ target_dir = "release" if release_mode else "debug"
58
58
if os .path .exists (no_jvm_target ):
59
59
print ("|---- ⚠️ Doing some needed moving around due to no_jvm_target.flag" )
60
- # move the jar file to the target/jvm-unknown-unknown/debug directory
61
- jar_path = os .path .join (test_dir , "target" , "debug" , "deps" , f"{ test_name } -*.jar" )
62
- # find the jar file
60
+ jar_path = os .path .join (test_dir , "target" , target_dir , "deps" , f"{ test_name } -*.jar" )
63
61
jar_file = None
64
- for file in os .listdir (os .path .join (test_dir , "target" , "debug" , "deps" )):
62
+ for file in os .listdir (os .path .join (test_dir , "target" , target_dir , "deps" )):
65
63
if file .startswith (test_name ) and file .endswith (".jar" ):
66
64
jar_file = file
67
65
break
68
66
if jar_file is None :
69
- print ("|---- ❌ No jar file found in target/debug /deps" )
67
+ print ("|---- ❌ No jar file found in target/{target_dir} /deps" )
70
68
return False
71
- # move the file
72
- os .makedirs (os .path .join (test_dir , "target" , "jvm-unknown-unknown" , "debug" ), exist_ok = True )
73
- os .rename (os .path .join (test_dir , "target" , "debug" , "deps" , jar_file ), os .path .join (test_dir , "target" , "jvm-unknown-unknown" , "debug" , f"{ test_name } .jar" ))
74
- jar_path = os .path .join (test_dir , "target" , "jvm-unknown-unknown" , "debug" , f"{ test_name } .jar" )
75
- proc = run_command (["java" , "-jar" , jar_path ])
69
+ os .makedirs (os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir ), exist_ok = True )
70
+ os .rename (os .path .join (test_dir , "target" , target_dir , "deps" , jar_file ), os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir , f"{ test_name } .jar" ))
71
+ jar_path = os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir , f"{ test_name } .jar" )
72
+ proc = run_command (["java" , "-jar" , jar_path ])
76
73
if proc .returncode != 0 :
77
74
fail_path = os .path .join (test_dir , "java-fail.generated" )
78
75
output = f"STDOUT:\n { proc .stdout } \n \n STDERR:\n { proc .stderr } "
@@ -100,9 +97,16 @@ def process_test(test_dir: str):
100
97
return True
101
98
102
99
def main ():
100
+ parser = argparse .ArgumentParser (description = "Tester for Rustc's JVM Codegen Backend" )
101
+ parser .add_argument ("--release" , action = "store_true" , help = "Run cargo in release mode" )
102
+ args = parser .parse_args ()
103
+
103
104
print ("🧪 Tester for Rustc's JVM Codegen Backend started!" )
104
105
overall_success = True
105
106
107
+ if args .release :
108
+ print ("|- ⚒️ Running in release mode" )
109
+
106
110
print (" " )
107
111
108
112
# Process binary tests.
@@ -113,7 +117,7 @@ def main():
113
117
binary_tests = []
114
118
print (f"|- 📦 Running { len (binary_tests )} binary build tests..." )
115
119
for idx , test_dir in enumerate (binary_tests ):
116
- if not process_test (test_dir ):
120
+ if not process_test (test_dir , args . release ):
117
121
overall_success = False
118
122
119
123
print ("" )
0 commit comments