Always collect the statistics and create a report file for Buck projects, even when the target contains no Java source code

Summary: It is preferable to always create error reports as a proof of succesful termination, even when the Buck target contains no source file to analyze

Reviewed By: sblackshear, jvillard

Differential Revision: D3362581

fbshipit-source-id: 4f27666
master
Jeremy Dubreil 9 years ago committed by Facebook Github Bot 3
parent 08c1c5bbf0
commit 6d37b5ee6d

@ -171,6 +171,7 @@ def store_performances_csv(infer_out, stats):
flat_stats = dict(int_stats + normal_stats) flat_stats = dict(int_stats + normal_stats)
values = [] values = []
for key in keys: for key in keys:
if key in flat_stats:
values.append(flat_stats[key]) values.append(flat_stats[key])
csv_writer.writerow(keys) csv_writer.writerow(keys)
csv_writer.writerow(values) csv_writer.writerow(values)
@ -190,13 +191,13 @@ def get_harness_code():
def get_basic_stats(stats): def get_basic_stats(stats):
files_analyzed = '{0} files ({1} lines) analyzed in {2}s\n\n'.format( files_analyzed = '{0} files ({1} lines) analyzed in {2}s\n\n'.format(
stats['int']['files'], stats['int'].get('files', 0),
stats['int']['lines'], stats['int'].get('lines', 0),
stats['int']['total_time'], stats['int']['total_time'],
) )
phase_times = 'Capture time: {0}s\nAnalysis time: {1}s\n\n'.format( phase_times = 'Capture time: {0}s\nAnalysis time: {1}s\n\n'.format(
stats['int']['capture_time'], stats['int'].get('capture_time', 0),
stats['int']['analysis_time'], stats['int'].get('analysis_time', 0),
) )
to_skip = { to_skip = {
@ -344,12 +345,7 @@ def collect_results(args, start_time):
json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME)
bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME)
if len(headers) == 0: if len(headers) > 1:
with open(csv_report, 'w'):
pass
logging.info('No reports found')
return
elif len(headers) > 1:
if any(map(lambda x: x != headers[0], headers)): if any(map(lambda x: x != headers[0], headers)):
raise Exception('Inconsistent reports found') raise Exception('Inconsistent reports found')
@ -361,6 +357,7 @@ def collect_results(args, start_time):
del(stats['float']) del(stats['float'])
with open(csv_report, 'w') as report: with open(csv_report, 'w') as report:
if len(headers) > 0:
writer = csv.writer(report) writer = csv.writer(report)
all_csv_rows = [list(row) for row in all_csv_rows] all_csv_rows = [list(row) for row in all_csv_rows]
writer.writerows([headers[0]] + all_csv_rows) writer.writerows([headers[0]] + all_csv_rows)
@ -467,7 +464,7 @@ class Wrapper:
if not os.path.isdir(self.infer_args.infer_out): if not os.path.isdir(self.infer_args.infer_out):
os.mkdir(self.infer_args.infer_out) os.mkdir(self.infer_args.infer_out)
self.timer.start('Preparing build...') self.timer.start('Preparing build ...')
temp_files2, infer_script = prepare_build(self.infer_args) temp_files2, infer_script = prepare_build(self.infer_args)
temp_files += temp_files2 temp_files += temp_files2
self.timer.stop('Build prepared') self.timer.stop('Build prepared')
@ -475,12 +472,12 @@ class Wrapper:
if len(self.normalized_targets) == 0: if len(self.normalized_targets) == 0:
logging.info('Nothing to analyze') logging.info('Nothing to analyze')
else: else:
self.timer.start('Running buck...') self.timer.start('Running Buck ...')
javac_config = ['--config', 'tools.javac=' + infer_script] javac_config = ['--config', 'tools.javac=' + infer_script]
buck_cmd = self.buck_cmd + javac_config buck_cmd = self.buck_cmd + javac_config
subprocess.check_call(buck_cmd) subprocess.check_call(buck_cmd)
self.timer.stop('Buck finished') self.timer.stop('Buck finished')
self.timer.start('Collecting results...') self.timer.start('Collecting results ...')
collect_results(self.infer_args, start_time) collect_results(self.infer_args, start_time)
self.timer.stop('Done') self.timer.stop('Done')
return os.EX_OK return os.EX_OK

Loading…
Cancel
Save