@@ -39,7 +39,7 @@ def invoke(invocation, *, cwd=None, log_prefix=""):
3939
4040def error (message ):
4141 print (f"{ ERROR } { message } " , file = sys .stderr )
42-
42+ raise SystemExit ( 1 )
4343
4444class _Parser (argparse .ArgumentParser ):
4545 """An `argparse` parser that fails the way the rest of this script does.
@@ -51,7 +51,6 @@ class _Parser(argparse.ArgumentParser):
5151
5252 def error (self , message ):
5353 error (message )
54- raise SystemExit (1 )
5554
5655
5756def build_parser ():
@@ -83,10 +82,7 @@ def parse_arguments():
8382 )
8483
8584 for arg in rest :
86- # An empty argument can come from a caller interpolating an unset variable.
87- if not arg :
88- pass
89- elif arg .startswith ("-" ):
85+ if arg .startswith ("-" ):
9086 args .flags .append (arg )
9187 elif m := ENV_RE .match (arg ):
9288 k , v = m .groups ()
@@ -101,18 +97,23 @@ def resolve_codeql(args: argparse.Namespace) -> Path:
10197 match args .codeql :
10298 case "built" | "build" :
10399 return Path (
104- SEMMLE_CODE , "target" , "intree" , f"codeql-{ args .language } " , "codeql"
105- ). with_suffix ( suffix )
100+ SEMMLE_CODE , "target" , "intree" , f"codeql-{ args .language } " , "codeql" + suffix
101+ )
106102 case "host" :
107- return Path (shutil .which ("codeql" + suffix ))
103+ codeql = shutil .which ("codeql" + suffix )
104+ if not codeql :
105+ error ("CodeQL executable not found in PATH" )
106+ return Path (codeql )
108107 case _:
109108 codeql = Path (args .codeql )
110109 if codeql .is_dir ():
111- codeql /= "codeql"
112- return codeql . with_suffix ( suffix )
110+ codeql /= "codeql" + suffix
111+ return codeql
113112
114113
115114def main ():
115+ # An empty argument can come from a caller interpolating an unset variable.
116+ sys .argv = [a for a in sys .argv if a ]
116117 args = parse_arguments ()
117118
118119 if args .all :
@@ -129,8 +130,8 @@ def main():
129130 # Resolve these only once all arguments are known, so that a `RAM_PER_THREAD=` test
130131 # argument can lower the default on memory-heavy suites.
131132 default_ram = 3000 if sys .platform == "linux" else 2048
132- ram_per_thread = int (os .environ .get ("RAM_PER_THREAD" , default_ram ) )
133- cpus = int (os .environ .get ("CPUS" , os .cpu_count () or 1 ) )
133+ ram_per_thread = int (os .environ .get ("RAM_PER_THREAD" ) or default_ram )
134+ cpus = int (os .environ .get ("CPUS" ) or os .cpu_count () or 1 )
134135 args .flags [:0 ] = [f"--ram={ ram_per_thread * cpus } " , f"-j{ cpus } " ]
135136
136137 if args .codeql == "build" :
@@ -146,7 +147,6 @@ def main():
146147
147148 if not codeql .exists ():
148149 error (f"CodeQL executable not found: { codeql } " )
149- return 1
150150
151151 return invoke (
152152 [codeql , "test" , "run" , * args .flags , "--" , * args .tests ],
0 commit comments