@@ -2,13 +2,22 @@ import * as child_process from "child_process";
22import * as path from "path" ;
33import * as os from "os" ;
44
5-
6-
7- function invoke ( invocation : string [ ] , options : { cwd ?: string , log_prefix ?: string } = { } ) : number {
8- const log_prefix = options . log_prefix && options . log_prefix !== "" ? `${ options . log_prefix } ` : "" ;
9- console . log ( `${ process . env [ "CMD_BEGIN" ] || "" } ${ log_prefix } ${ invocation . join ( " " ) } ${ process . env [ "CMD_END" ] || "" } ` ) ;
5+ function invoke (
6+ invocation : string [ ] ,
7+ options : { cwd ?: string ; log_prefix ?: string } = { } ,
8+ ) : number {
9+ const log_prefix =
10+ options . log_prefix && options . log_prefix !== ""
11+ ? `${ options . log_prefix } `
12+ : "" ;
13+ console . log (
14+ `${ process . env [ "CMD_BEGIN" ] || "" } ${ log_prefix } ${ invocation . join ( " " ) } ${ process . env [ "CMD_END" ] || "" } ` ,
15+ ) ;
1016 try {
11- child_process . execFileSync ( invocation [ 0 ] , invocation . slice ( 1 ) , { stdio : "inherit" , cwd : options . cwd } ) ;
17+ child_process . execFileSync ( invocation [ 0 ] , invocation . slice ( 1 ) , {
18+ stdio : "inherit" ,
19+ cwd : options . cwd ,
20+ } ) ;
1221 } catch ( error ) {
1322 return 1 ;
1423 }
@@ -24,43 +33,40 @@ type Args = {
2433} ;
2534
2635function parseArgs ( args : Args , argv : string ) {
27- argv
28- . split ( / (?< ! \\ ) / )
29- . forEach ( ( arg ) => {
30- if ( arg === "--no-build" ) {
31- args . build = false ;
32- } else if ( arg . startsWith ( "-" ) ) {
33- args . flags . push ( arg ) ;
34- } else if ( / ^ [ A - Z _ ] [ A - Z _ 0 - 9 ] * = .* $ / . test ( arg ) ) {
35- args . env . push ( arg ) ;
36- } else if ( / ^ \+ + $ / . test ( arg ) ) {
37- args . testing_level = Math . max ( args . testing_level , arg . length ) ;
38- } else if ( arg !== "" ) {
39- args . tests . push ( arg ) ;
40- }
41- } ) ;
36+ argv . split ( / (?< ! \\ ) / ) . forEach ( ( arg ) => {
37+ if ( arg === "--no-build" ) {
38+ args . build = false ;
39+ } else if ( arg . startsWith ( "-" ) ) {
40+ args . flags . push ( arg ) ;
41+ } else if ( / ^ [ A - Z _ ] [ A - Z _ 0 - 9 ] * = .* $ / . test ( arg ) ) {
42+ args . env . push ( arg ) ;
43+ } else if ( / ^ \+ + $ / . test ( arg ) ) {
44+ args . testing_level = Math . max ( args . testing_level , arg . length ) ;
45+ } else if ( arg !== "" ) {
46+ args . tests . push ( arg ) ;
47+ }
48+ } ) ;
4249}
4350
44-
4551function codeqlTestRun ( argv : string [ ] ) : number {
4652 const [ language , extra_args , ...plus ] = argv ;
47- let codeql =
48- process . env [ "SEMMLE_CODE" ] ?
49- path . join ( process . env [ "SEMMLE_CODE" ] , "target" , "intree" , `codeql-${ language } ` , "codeql" )
50- :
51- "codeql"
52- ;
53+ let codeql = process . env [ "SEMMLE_CODE" ]
54+ ? path . join (
55+ process . env [ "SEMMLE_CODE" ] ,
56+ "target" ,
57+ "intree" ,
58+ `codeql-${ language } ` ,
59+ "codeql" ,
60+ )
61+ : "codeql" ;
5362 const ram_per_thread = process . platform === "linux" ? 3000 : 2048 ;
5463 const cpus = os . cpus ( ) . length ;
5564 let args : Args = {
5665 tests : [ ] ,
57- flags : [
58- `--ram=${ ram_per_thread * cpus } ` ,
59- `-j${ cpus } ` ,
60- ] ,
66+ flags : [ `--ram=${ ram_per_thread * cpus } ` , `-j${ cpus } ` ] ,
6167 env : [ ] ,
6268 build : true ,
63- testing_level : 0
69+ testing_level : 0 ,
6470 } ;
6571 parseArgs ( args , extra_args ) ;
6672 for ( let i = 0 ; i < Math . min ( plus . length , args . testing_level ) ; i ++ ) {
@@ -72,11 +78,15 @@ function codeqlTestRun(argv: string[]): number {
7278 if ( args . build && process . env [ "SEMMLE_CODE" ] ) {
7379 // If SEMMLE_CODE is set, we are in the semmle-code repo, so we build the codeql binary.
7480 // Otherwise, we use codeql from PATH.
75- if ( invoke ( [ "python3" , "build" , `target/intree/codeql-${ language } ` ] , { cwd : process . env [ "SEMMLE_CODE" ] } ) !== 0 ) {
81+ if (
82+ invoke ( [ "python3" , "build" , `target/intree/codeql-${ language } ` ] , {
83+ cwd : process . env [ "SEMMLE_CODE" ] ,
84+ } ) !== 0
85+ ) {
7686 return 1 ;
7787 }
7888 }
79- process . env [ "CODEQL_CONFIG_FILE" ] ||= "." // disable the default implicit config file, but keep an explicit one
89+ process . env [ "CODEQL_CONFIG_FILE" ] ||= "." ; // disable the default implicit config file, but keep an explicit one
8090 // Set and unset environment variables
8191 args . env . forEach ( ( envVar ) => {
8292 const [ key , value ] = envVar . split ( "=" , 2 ) ;
@@ -91,7 +101,9 @@ function codeqlTestRun(argv: string[]): number {
91101 process . exit ( 1 ) ;
92102 }
93103 } ) ;
94- return invoke ( [ codeql , "test" , "run" , ...args . flags , "--" , ...args . tests ] , { log_prefix : args . env . join ( " " ) } ) ;
104+ return invoke ( [ codeql , "test" , "run" , ...args . flags , "--" , ...args . tests ] , {
105+ log_prefix : args . env . join ( " " ) ,
106+ } ) ;
95107}
96108
97109process . exit ( codeqlTestRun ( process . argv . slice ( 2 ) ) ) ;
0 commit comments