[diff] suppress console output in report called from diff analysis

Summary: That was too noisy. Propagate `--quiet` to the Python reporting hook so as to still emit bugs.txt and so on.

Reviewed By: martinoluca

Differential Revision: D5501106

fbshipit-source-id: 63b6451
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 6a4e4d4b6a
commit de86c12a9a

@ -49,6 +49,8 @@ base_group.add_argument('-nf', '--no-filtering', action='store_true',
base_group.add_argument('--pmd-xml', base_group.add_argument('--pmd-xml',
action='store_true', action='store_true',
help='''Output issues in (PMD) XML format.''') help='''Output issues in (PMD) XML format.''')
base_group.add_argument('--quiet', action='store_true',
help='Silence console output.')
infer_parser = argparse.ArgumentParser(parents=[base_parser]) infer_parser = argparse.ArgumentParser(parents=[base_parser])

@ -139,8 +139,8 @@ def get_output_jars(targets):
def collect_results(args, start_time, targets): def collect_results(args, start_time, targets):
"""Walks through buck-gen, collects results for the different buck targets """Walks through buck-out/, collects results for the different buck targets
and stores them in in args.infer_out/results.csv. and stores them in in args.infer_out/results.json.
""" """
all_json_rows = set() all_json_rows = set()
@ -166,7 +166,8 @@ def collect_results(args, start_time, targets):
bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME)
issues.print_and_save_errors(args.infer_out, args.project_root, issues.print_and_save_errors(args.infer_out, args.project_root,
json_report, bugs_out, args.pmd_xml) json_report, bugs_out, args.pmd_xml,
console_out=not args.quiet)
def cleanup(temp_files): def cleanup(temp_files):

@ -258,7 +258,8 @@ class BuckAnalyzer:
json_report = os.path.join(infer_out, config.JSON_REPORT_FILENAME) json_report = os.path.join(infer_out, config.JSON_REPORT_FILENAME)
bugs_out = os.path.join(infer_out, config.BUGS_FILENAME) bugs_out = os.path.join(infer_out, config.BUGS_FILENAME)
issues.print_and_save_errors(infer_out, self.args.project_root, issues.print_and_save_errors(infer_out, self.args.project_root,
json_report, bugs_out, self.args.pmd_xml) json_report, bugs_out, self.args.pmd_xml,
console_out=not self.args.quiet)
return os.EX_OK return os.EX_OK
def capture_without_flavors(self): def capture_without_flavors(self):

@ -182,7 +182,7 @@ def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None,
return bug_list + summary return bug_list + summary
def _is_user_visible(project_root, report): def _is_user_visible(report):
kind = report[JSON_INDEX_KIND] kind = report[JSON_INDEX_KIND]
return kind in [ return kind in [
ISSUE_KIND_ERROR, ISSUE_KIND_ERROR,
@ -192,9 +192,10 @@ def _is_user_visible(project_root, report):
def print_and_save_errors(infer_out, project_root, json_report, bugs_out, def print_and_save_errors(infer_out, project_root, json_report, bugs_out,
pmd_xml): pmd_xml, console_out):
errors = utils.load_json_from_path(json_report) errors = utils.load_json_from_path(json_report)
errors = [e for e in errors if _is_user_visible(project_root, e)] errors = [e for e in errors if _is_user_visible(e)]
if console_out:
utils.stderr('') utils.stderr('')
_text_of_report_list(project_root, errors, bugs_out, console_out=True, _text_of_report_list(project_root, errors, bugs_out, console_out=True,
limit=10) limit=10)

@ -31,6 +31,8 @@ arg_parser.add_argument('--pmd-xml', action='store_true',
help='Output issues in (PMD) XML format.') help='Output issues in (PMD) XML format.')
arg_parser.add_argument('--project-root', metavar='<directory>', required=True, arg_parser.add_argument('--project-root', metavar='<directory>', required=True,
help='Location of the project root') help='Location of the project root')
arg_parser.add_argument('--quiet', action='store_true',
help='Silence console output.')
arg_parser.add_argument('--results-dir', metavar='<directory>', required=True, arg_parser.add_argument('--results-dir', metavar='<directory>', required=True,
help='Location of the results directory') help='Location of the results directory')
@ -40,7 +42,7 @@ def main():
args = arg_parser.parse_args(sys_argv[1:]) args = arg_parser.parse_args(sys_argv[1:])
issues.print_and_save_errors(args.results_dir, args.project_root, issues.print_and_save_errors(args.results_dir, args.project_root,
args.issues_json, args.issues_txt, args.issues_json, args.issues_txt,
args.pmd_xml) args.pmd_xml, console_out=not args.quiet)
if __name__ == '__main__': if __name__ == '__main__':

@ -67,7 +67,7 @@ let diff driver_mode =
Driver.run_prologue driver_mode ; Driver.run_prologue driver_mode ;
let changed_files = Driver.read_config_changed_files () in let changed_files = Driver.read_config_changed_files () in
Driver.capture driver_mode ~changed_files ; Driver.capture driver_mode ~changed_files ;
Driver.analyze_and_report driver_mode ~changed_files ; Driver.analyze_and_report ~suppress_console_report:true driver_mode ~changed_files ;
let current_report = Some (save_report Current) in let current_report = Some (save_report Current) in
(* Some files in the current checkout may be deleted in the old checkout. If we kept the results of the previous capture and analysis around, we would report issues on these files again in the previous checkout, which is wrong. Do not do anything too smart for now and just delete all results from the analysis of the current checkout. *) (* Some files in the current checkout may be deleted in the old checkout. If we kept the results of the previous capture and analysis around, we would report issues on these files again in the previous checkout, which is wrong. Do not do anything too smart for now and just delete all results from the analysis of the current checkout. *)
delete_capture_and_analysis_artifacts () ; delete_capture_and_analysis_artifacts () ;
@ -79,7 +79,7 @@ let diff driver_mode =
Config.gen_previous_build_command_script Config.gen_previous_build_command_script
in in
Driver.capture previous_driver_mode ~changed_files ; Driver.capture previous_driver_mode ~changed_files ;
Driver.analyze_and_report previous_driver_mode ~changed_files ; Driver.analyze_and_report ~suppress_console_report:true previous_driver_mode ~changed_files ;
checkout Current ; checkout Current ;
let previous_report = Some (save_report Previous) in let previous_report = Some (save_report Previous) in
(* compute differential *) (* compute differential *)

@ -309,6 +309,7 @@ let capture ~changed_files = function
-> ["-l"; string_of_float l] ) -> ["-l"; string_of_float l] )
@ (if not Config.pmd_xml then [] else ["--pmd-xml"]) @ (if not Config.pmd_xml then [] else ["--pmd-xml"])
@ ["--project-root"; Config.project_root] @ ["--project-root"; Config.project_root]
@ (if not Config.quiet then [] else ["--quiet"])
@ (if not Config.reactive_mode then [] else ["--reactive"]) @ (if not Config.reactive_mode then [] else ["--reactive"])
@ "--out" @ "--out"
:: Config.results_dir :: Config.results_dir
@ -370,7 +371,7 @@ let execute_analyze ~changed_files =
InferAnalyze.main ~changed_files ~makefile:"" InferAnalyze.main ~changed_files ~makefile:""
else run_parallel_analysis ~changed_files else run_parallel_analysis ~changed_files
let report () = let report ?(suppress_console= false) () =
let report_csv = let report_csv =
if Config.buck_cache_mode then None else Some (Config.results_dir ^/ "report.csv") if Config.buck_cache_mode then None else Some (Config.results_dir ^/ "report.csv")
in in
@ -379,8 +380,8 @@ let report () =
(* Post-process the report according to the user config. By default, calls report.py to create a (* Post-process the report according to the user config. By default, calls report.py to create a
human-readable report. human-readable report.
Do not bother calling the report hook when called from within Buck or in quiet mode. *) Do not bother calling the report hook when called from within Buck. *)
match (Config.quiet || Config.buck_cache_mode, Config.report_hook) with match (Config.buck_cache_mode, Config.report_hook) with
| true, _ | false, None | true, _ | false, None
-> () -> ()
| false, Some prog | false, Some prog
@ -388,8 +389,8 @@ let report () =
let if_true key opt args = if not opt then args else key :: args in let if_true key opt args = if not opt then args else key :: args in
let bugs_txt = Option.value ~default:(Config.results_dir ^/ "bugs.txt") Config.bugs_txt in let bugs_txt = Option.value ~default:(Config.results_dir ^/ "bugs.txt") Config.bugs_txt in
let args = let args =
if_some "--issues-csv" report_csv if_some "--issues-csv" report_csv @@ if_true "--pmd-xml" Config.pmd_xml
@@ if_true "--pmd-xml" Config.pmd_xml @@ if_true "--quiet" (Config.quiet || suppress_console)
[ "--issues-json" [ "--issues-json"
; report_json ; report_json
; "--issues-txt" ; "--issues-txt"
@ -404,7 +405,7 @@ let report () =
"** Error running the reporting script:@\n** %s %s@\n** See error above@." prog "** Error running the reporting script:@\n** %s %s@\n** See error above@." prog
(String.concat ~sep:" " args) (String.concat ~sep:" " args)
let analyze_and_report ~changed_files mode = let analyze_and_report ?suppress_console_report ~changed_files mode =
let should_analyze, should_report = let should_analyze, should_report =
match (mode, Config.analyzer) with match (mode, Config.analyzer) with
| PythonCapture (BBuck, _), _ when not Config.flavors | PythonCapture (BBuck, _), _ when not Config.flavors
@ -433,7 +434,7 @@ let analyze_and_report ~changed_files mode =
&& (Sys.file_exists Config.captured_dir <> `Yes || check_captured_empty mode) && (Sys.file_exists Config.captured_dir <> `Yes || check_captured_empty mode)
then L.user_error "There was nothing to analyze.@\n@." then L.user_error "There was nothing to analyze.@\n@."
else if should_analyze then execute_analyze ~changed_files ; else if should_analyze then execute_analyze ~changed_files ;
if should_report && Config.report then report () if should_report && Config.report then report ?suppress_console:suppress_console_report ()
(** as the Config.fail_on_bug flag mandates, exit with error when an issue is reported *) (** as the Config.fail_on_bug flag mandates, exit with error when an issue is reported *)
let fail_on_issue_epilogue () = let fail_on_issue_epilogue () =

@ -41,7 +41,8 @@ val run_prologue : mode -> unit
val capture : changed_files:SourceFile.Set.t option -> mode -> unit val capture : changed_files:SourceFile.Set.t option -> mode -> unit
(** run the capture for the given mode *) (** run the capture for the given mode *)
val analyze_and_report : changed_files:SourceFile.Set.t option -> mode -> unit val analyze_and_report :
?suppress_console_report:bool -> changed_files:SourceFile.Set.t option -> mode -> unit
(** run the analysis for the given mode *) (** run the analysis for the given mode *)
val run_epilogue : mode -> unit val run_epilogue : mode -> unit

@ -16,7 +16,6 @@ INFER_OPTIONS = \
--previous-to-current-script '$(COPY) $(SRC_DIR)/some_bugs.c src/hello.c' \ --previous-to-current-script '$(COPY) $(SRC_DIR)/some_bugs.c src/hello.c' \
--current-to-previous-script '$(COPY) $(SRC_DIR)/some_different_bugs.c src/hello.c' \ --current-to-previous-script '$(COPY) $(SRC_DIR)/some_different_bugs.c src/hello.c' \
--changed-files-index changed_files.txt \ --changed-files-index changed_files.txt \
--report-hook '/bin/true' \
-- clang -c src/hello.c -- clang -c src/hello.c
SOURCES = $(SRC_DIR)/some_bugs.c $(SRC_DIR)/some_different_bugs.c SOURCES = $(SRC_DIR)/some_bugs.c $(SRC_DIR)/some_different_bugs.c

@ -18,7 +18,6 @@ INFER_OPTIONS = \
--gen-previous-build-command-script 'echo "clang -c src/some_bugs.c"' \ --gen-previous-build-command-script 'echo "clang -c src/some_bugs.c"' \
--changed-files-index changed_files.txt \ --changed-files-index changed_files.txt \
--file-renamings file_renamings.json \ --file-renamings file_renamings.json \
--report-hook '/bin/true' \
-- clang -c src/some_different_bugs.c -- clang -c src/some_different_bugs.c
SOURCES = $(SRC_DIR)/some_bugs.c $(SRC_DIR)/some_different_bugs.c SOURCES = $(SRC_DIR)/some_bugs.c $(SRC_DIR)/some_different_bugs.c

Loading…
Cancel
Save