@@ -7,6 +7,46 @@ local util = require 'utility'
7
7
8
8
local export = {}
9
9
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
+
10
50
function export .runCLI ()
11
51
local numThreads = tonumber (NUM_THREADS or 1 )
12
52
@@ -21,48 +61,13 @@ function export.runCLI()
21
61
exe = exe .. ' .exe'
22
62
end
23
63
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
60
65
print (lang .script (' CLI_CHECK_MULTIPLE_WORKERS' , numThreads ))
61
66
end
62
67
63
68
local procs = {}
64
69
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 )})
66
71
if err then
67
72
print (err )
68
73
end
@@ -76,11 +81,6 @@ function export.runCLI()
76
81
checkPassed = process :wait () == 0 and checkPassed
77
82
end
78
83
79
- local outpath = CHECK_OUT_PATH
80
- if outpath == nil then
81
- outpath = LOGPATH .. ' /check.json'
82
- end
83
-
84
84
if numThreads > 1 then
85
85
local mergedResults = {}
86
86
local count = 0
@@ -95,11 +95,22 @@ function export.runCLI()
95
95
end
96
96
end
97
97
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
103
114
end
104
115
end
105
116
return checkPassed and 0 or 1
0 commit comments