@@ -246,12 +246,19 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
246
246
i += 1
247
247
time .sleep (60 )
248
248
mod_env ["PATH" ] = one_click_loaner_gcc + ":" + mod_env ["PATH" ]
249
- fout = open (output_path , "w" )
250
- cmd = [grcov_path , "-t" , output_format , "-p" , "/home/worker/workspace/build/src/" ]
249
+ cmd = [
250
+ grcov_path ,
251
+ "-t" ,
252
+ output_format ,
253
+ "-p" ,
254
+ "/home/worker/workspace/build/src/" ,
255
+ "-o" ,
256
+ output_path ,
257
+ ]
251
258
if output_format in ["coveralls" , "coveralls+" ]:
252
259
cmd += ["--token" , "UNUSED" , "--commit-sha" , "UNUSED" ]
253
260
cmd .extend (artifact_paths )
254
- proc = subprocess .Popen (cmd , stdout = fout , stderr = subprocess .PIPE , env = mod_env )
261
+ proc = subprocess .Popen (cmd , stderr = subprocess .PIPE , env = mod_env )
255
262
i = 0
256
263
while proc .poll () is None :
257
264
if i % 60 == 0 :
@@ -265,40 +272,6 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
265
272
raise Exception ("Error while running grcov: {}\n " .format (proc .stderr .read ()))
266
273
267
274
268
- def generate_html_report (
269
- src_dir ,
270
- info_file = os .path .join (os .getcwd (), "output.info" ),
271
- output_dir = os .path .join (os .getcwd (), "report" ),
272
- silent = False ,
273
- style_file = None ,
274
- ):
275
- cwd = os .getcwd ()
276
- os .chdir (src_dir )
277
-
278
- with open (os .devnull , "w" ) as fnull :
279
- command = [
280
- os .path .join (cwd , "lcov-bin/usr/local/bin/genhtml" ),
281
- "-o" ,
282
- output_dir ,
283
- "--show-details" ,
284
- "--highlight" ,
285
- "--ignore-errors" ,
286
- "source" ,
287
- "--legend" ,
288
- info_file ,
289
- ]
290
- if style_file is not None :
291
- command += ["--css-file" , style_file ]
292
- ret = subprocess .call (
293
- command , stdout = fnull if silent else None , stderr = fnull if silent else None
294
- )
295
-
296
- if ret != 0 :
297
- raise Exception ("Error while running genhtml." )
298
-
299
- os .chdir (cwd )
300
-
301
-
302
275
def download_grcov ():
303
276
local_path = "grcov"
304
277
local_version = "grcov_ver"
@@ -337,21 +310,6 @@ def download_grcov():
337
310
return local_path
338
311
339
312
340
- def download_genhtml ():
341
- if os .path .isdir ("lcov" ):
342
- os .chdir ("lcov" )
343
- subprocess .check_call (["git" , "pull" ])
344
- else :
345
- subprocess .check_call (
346
- ["git" , "clone" , "https://github.com/linux-test-project/lcov.git" ]
347
- )
348
- os .chdir ("lcov" )
349
-
350
- subprocess .check_call (["make" , "install" , "DESTDIR=../lcov-bin" ])
351
-
352
- os .chdir (".." )
353
-
354
-
355
313
def main ():
356
314
parser = argparse .ArgumentParser ()
357
315
@@ -418,8 +376,16 @@ def main():
418
376
action = "store_true" ,
419
377
help = "Only generate high-level stats, not a full HTML report" ,
420
378
)
379
+ parser .add_argument (
380
+ "-o" ,
381
+ "--output-dir" ,
382
+ help = "The output directory for generated report" ,
383
+ default = os .path .join (os .getcwd (), "ccov-report" ),
384
+ )
421
385
args = parser .parse_args ()
422
386
387
+ os .makedirs (args .output_dir , exist_ok = True )
388
+
423
389
if (args .branch is None ) != (args .commit is None ):
424
390
parser .print_help ()
425
391
return
@@ -444,9 +410,10 @@ def main():
444
410
grcov_path = download_grcov ()
445
411
446
412
if args .stats :
447
- generate_report (grcov_path , "coveralls" , "output.json" , artifact_paths )
413
+ output = os .path .join (args .output_dir , "output.json" )
414
+ generate_report (grcov_path , "coveralls" , output , artifact_paths )
448
415
449
- with open (" output.json" , "r" ) as f :
416
+ with open (output , "r" ) as f :
450
417
report = json .load (f )
451
418
452
419
total_lines = 0
@@ -468,10 +435,7 @@ def main():
468
435
)
469
436
)
470
437
else :
471
- generate_report (grcov_path , "lcov" , "output.info" , artifact_paths )
472
-
473
- download_genhtml ()
474
- generate_html_report (os .path .abspath (args .src_dir ))
438
+ generate_report (grcov_path , "html" , args .output_dir , artifact_paths )
475
439
476
440
477
441
if __name__ == "__main__" :
0 commit comments