diff --git a/infer/bin/infer b/infer/bin/infer index fada0c91e..c54f8a749 100755 --- a/infer/bin/infer +++ b/infer/bin/infer @@ -4,6 +4,7 @@ import argparse import imp import utils import inferlib +import json import logging import os import sys @@ -164,5 +165,16 @@ def main(): analysis.analyze_and_report() analysis.save_stats() + if args.fail_on_bug: + bugs_filename = os.path.join(args.infer_out, + utils.JSON_REPORT_FILENAME) + try: + with open(bugs_filename) as bugs_file: + bugs = json.load(bugs_file) + if len(bugs) > 0: + sys.exit(inferlib.BUG_FOUND_ERROR_CODE) + except OSError: + pass + if __name__ == '__main__': main() diff --git a/infer/bin/inferTraceBugs b/infer/bin/inferTraceBugs index 052959ddb..703674ebe 100755 --- a/infer/bin/inferTraceBugs +++ b/infer/bin/inferTraceBugs @@ -21,7 +21,6 @@ import sys import utils BASE_INDENT = 2 -JSON_REPORT = 'report.json' # how many lines of context around each report SOURCE_CONTEXT = 2 @@ -249,7 +248,8 @@ class Selector(object): def main(): args = base_parser.parse_args() - with open(os.path.join(args.infer_out, JSON_REPORT)) as report_file: + report_filename = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME) + with open(report_filename) as report_file: reports = json.load(report_file) sel = Selector(args, reports) diff --git a/infer/bin/inferlib.py b/infer/bin/inferlib.py index b73ae241f..c8f8f788c 100644 --- a/infer/bin/inferlib.py +++ b/infer/bin/inferlib.py @@ -47,6 +47,7 @@ ERROR = 'ERROR' WARNING = 'WARNING' INFO = 'INFO' +BUG_FOUND_ERROR_CODE = 2 def get_infer_version(): try: @@ -102,13 +103,20 @@ base_group.add_argument('-nf', '--no-filtering', action='store_true', help='''Also show the results from the experimental checks. Warning: some checks may contain many false alarms''') +base_group.add_argument('--fail-on-bug', action='store_true', + help='''Exit with error code %d if Infer found + something to report''' + % BUG_FOUND_ERROR_CODE) + base_group.add_argument('-l', '--llvm', action='store_true', - help='Analyze C or C++ file using LLVM translation') + help='''[experimental] Analyze C or C++ file using the + experimental LLVM frontend''') base_group.add_argument('--log_to_stderr', action='store_true', help='''When set, all logging will go to stderr instead - of log file''') -base_parser.add_argument('-v', '--version', help='Get version of the analyzer', + of the log file''') +base_parser.add_argument('-v', '--version', + help='''Print the version of Infer and exit''', action=VersionAction)