@@ -246,12 +246,19 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
246246 i += 1
247247 time .sleep (60 )
248248 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+ ]
251258 if output_format in ["coveralls" , "coveralls+" ]:
252259 cmd += ["--token" , "UNUSED" , "--commit-sha" , "UNUSED" ]
253260 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 )
255262 i = 0
256263 while proc .poll () is None :
257264 if i % 60 == 0 :
@@ -265,40 +272,6 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
265272 raise Exception ("Error while running grcov: {}\n " .format (proc .stderr .read ()))
266273
267274
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-
302275def download_grcov ():
303276 local_path = "grcov"
304277 local_version = "grcov_ver"
@@ -337,21 +310,6 @@ def download_grcov():
337310 return local_path
338311
339312
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-
355313def main ():
356314 parser = argparse .ArgumentParser ()
357315
@@ -418,8 +376,16 @@ def main():
418376 action = "store_true" ,
419377 help = "Only generate high-level stats, not a full HTML report" ,
420378 )
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+ )
421385 args = parser .parse_args ()
422386
387+ os .makedirs (args .output_dir , exist_ok = True )
388+
423389 if (args .branch is None ) != (args .commit is None ):
424390 parser .print_help ()
425391 return
@@ -444,9 +410,10 @@ def main():
444410 grcov_path = download_grcov ()
445411
446412 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 )
448415
449- with open (" output.json" , "r" ) as f :
416+ with open (output , "r" ) as f :
450417 report = json .load (f )
451418
452419 total_lines = 0
@@ -468,10 +435,7 @@ def main():
468435 )
469436 )
470437 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 )
475439
476440
477441if __name__ == "__main__" :
0 commit comments