@@ -7,6 +7,46 @@ local util = require 'utility'
77
88local export = {}
99
10+ local function logFileForThread (threadId )
11+ return LOGPATH .. ' /check-partial-' .. threadId .. ' .json'
12+ end
13+
14+ local function buildArgs (exe , numThreads , threadId , format , quiet )
15+ local args = {exe }
16+ local skipNext = false
17+ for i = 1 , # arg do
18+ local arg = arg [i ]
19+ -- --check needs to be transformed into --check_worker
20+ if arg :lower ():match (' ^%-%-check$' ) or arg :lower ():match (' ^%-%-check=' ) then
21+ args [# args + 1 ] = arg :gsub (' %-%-%w*' , ' --check_worker' )
22+ -- --check_out_path needs to be removed if we have more than one thread
23+ elseif arg :lower ():match (' %-%-check_out_path' ) and numThreads > 1 then
24+ if not arg :match (' %-%-%w*=' ) then
25+ skipNext = true
26+ end
27+ else
28+ if skipNext then
29+ skipNext = false
30+ else
31+ args [# args + 1 ] = arg
32+ end
33+ end
34+ end
35+ args [# args + 1 ] = ' --thread_id'
36+ args [# args + 1 ] = tostring (threadId )
37+ if numThreads > 1 then
38+ if quiet then
39+ args [# args + 1 ] = ' --quiet'
40+ end
41+ if format then
42+ args [# args + 1 ] = ' --check_format=' .. format
43+ end
44+ args [# args + 1 ] = ' --check_out_path'
45+ args [# args + 1 ] = logFileForThread (threadId )
46+ end
47+ return args
48+ end
49+
1050function export .runCLI ()
1151 local numThreads = tonumber (NUM_THREADS or 1 )
1252
@@ -21,48 +61,13 @@ function export.runCLI()
2161 exe = exe .. ' .exe'
2262 end
2363
24- local function logFileForThread (threadId )
25- return LOGPATH .. ' /check-partial-' .. threadId .. ' .json'
26- end
27-
28- local function buildArgs (threadId )
29- local args = {exe }
30- local skipNext = false
31- for i = 1 , # arg do
32- local arg = arg [i ]
33- -- --check needs to be transformed into --check_worker
34- if arg :lower ():match (' ^%-%-check$' ) or arg :lower ():match (' ^%-%-check=' ) then
35- args [# args + 1 ] = arg :gsub (' %-%-%w*' , ' --check_worker' )
36- -- --check_out_path needs to be removed if we have more than one thread
37- elseif arg :lower ():match (' %-%-check_out_path' ) and numThreads > 1 then
38- if not arg :match (' %-%-%w*=' ) then
39- skipNext = true
40- end
41- else
42- if skipNext then
43- skipNext = false
44- else
45- args [# args + 1 ] = arg
46- end
47- end
48- end
49- args [# args + 1 ] = ' --thread_id'
50- args [# args + 1 ] = tostring (threadId )
51- if numThreads > 1 then
52- args [# args + 1 ] = ' --quiet'
53- args [# args + 1 ] = ' --check_out_path'
54- args [# args + 1 ] = logFileForThread (threadId )
55- end
56- return args
57- end
58-
59- if numThreads > 1 then
64+ if not QUIET and numThreads > 1 then
6065 print (lang .script (' CLI_CHECK_MULTIPLE_WORKERS' , numThreads ))
6166 end
6267
6368 local procs = {}
6469 for i = 1 , numThreads do
65- local process , err = subprocess .spawn ({buildArgs (i )})
70+ local process , err = subprocess .spawn ({buildArgs (exe , numThreads , i , CHECK_FORMAT , QUIET )})
6671 if err then
6772 print (err )
6873 end
@@ -76,11 +81,6 @@ function export.runCLI()
7681 checkPassed = process :wait () == 0 and checkPassed
7782 end
7883
79- local outpath = CHECK_OUT_PATH
80- if outpath == nil then
81- outpath = LOGPATH .. ' /check.json'
82- end
83-
8484 if numThreads > 1 then
8585 local mergedResults = {}
8686 local count = 0
@@ -95,11 +95,22 @@ function export.runCLI()
9595 end
9696 end
9797 end
98- util .saveFile (outpath , jsonb .beautify (mergedResults ))
99- if count == 0 then
100- print (lang .script (' CLI_CHECK_SUCCESS' ))
101- else
102- print (lang .script (' CLI_CHECK_RESULTS' , count , outpath ))
98+
99+ local outpath = nil
100+
101+ if CHECK_FORMAT == ' json' or CHECK_OUT_PATH then
102+ outpath = CHECK_OUT_PATH or LOGPATH .. ' /check.json'
103+ util .saveFile (outpath , jsonb .beautify (mergedResults ))
104+ end
105+
106+ if not QUIET then
107+ if count == 0 then
108+ print (lang .script (' CLI_CHECK_SUCCESS' ))
109+ elseif outpath then
110+ print (lang .script (' CLI_CHECK_RESULTS_OUTPATH' , count , outpath ))
111+ else
112+ print (lang .script (' CLI_CHECK_RESULTS_PRETTY' , count ))
113+ end
103114 end
104115 end
105116 return checkPassed and 0 or 1
0 commit comments