diff --git a/infer/lib/python/BuckAnalyze b/infer/lib/python/BuckAnalyze index 9acd2d0ed..e6d8db084 100755 --- a/infer/lib/python/BuckAnalyze +++ b/infer/lib/python/BuckAnalyze @@ -30,7 +30,7 @@ import time import traceback import zipfile -from inferlib import analyze, issues, utils +from inferlib import analyze, config, issues, utils ANALYSIS_SUMMARY_OUTPUT = 'analysis_summary.txt' @@ -40,11 +40,11 @@ BUCK_CONFIG_BACKUP = '.buckconfig.local.backup_generated_by_infer' DEFAULT_BUCK_OUT = os.path.join(os.getcwd(), 'buck-out') DEFAULT_BUCK_OUT_GEN = os.path.join(DEFAULT_BUCK_OUT, 'gen') -INFER_CSV_REPORT = os.path.join(utils.BUCK_INFER_OUT, - utils.CSV_REPORT_FILENAME) -INFER_JSON_REPORT = os.path.join(utils.BUCK_INFER_OUT, - utils.JSON_REPORT_FILENAME) -INFER_STATS = os.path.join(utils.BUCK_INFER_OUT, utils.STATS_FILENAME) +INFER_CSV_REPORT = os.path.join(config.BUCK_INFER_OUT, + config.CSV_REPORT_FILENAME) +INFER_JSON_REPORT = os.path.join(config.BUCK_INFER_OUT, + config.JSON_REPORT_FILENAME) +INFER_STATS = os.path.join(config.BUCK_INFER_OUT, config.STATS_FILENAME) INFER_SCRIPT = """\ #!/usr/bin/env {0} @@ -233,7 +233,7 @@ def init_stats(args, start_time): def store_performances_csv(infer_out, stats): """Stores the statistics about perfromances into a CSV file to be exported to a database""" - perf_filename = os.path.join(infer_out, utils.CSV_PERF_FILENAME) + perf_filename = os.path.join(infer_out, config.CSV_PERF_FILENAME) with open(perf_filename, 'w') as csv_file_out: csv_writer = csv.writer(csv_file_out) keys = ['infer_version', 'project', 'revision', 'files', 'lines', @@ -414,9 +414,9 @@ def collect_results(args, start_time): except zipfile.BadZipfile: logging.warn('Bad zip file %s', path) - csv_report = os.path.join(args.infer_out, utils.CSV_REPORT_FILENAME) - json_report = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME) - bugs_out = os.path.join(args.infer_out, utils.BUGS_FILENAME) + csv_report = os.path.join(args.infer_out, config.CSV_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) if len(headers) == 0: with open(csv_report, 'w'): @@ -454,7 +454,7 @@ def collect_results(args, start_time): store_performances_csv(args.infer_out, stats) - stats_filename = os.path.join(args.infer_out, utils.STATS_FILENAME) + stats_filename = os.path.join(args.infer_out, config.STATS_FILENAME) with open(stats_filename, 'w') as stats_out: json.dump(stats, stats_out, indent=2) diff --git a/infer/lib/python/infer b/infer/lib/python/infer index 07f138e35..351aa5647 100755 --- a/infer/lib/python/infer +++ b/infer/lib/python/infer @@ -168,7 +168,7 @@ def main(): if args.fail_on_bug: bugs_filename = os.path.join(args.infer_out, - utils.JSON_REPORT_FILENAME) + config.JSON_REPORT_FILENAME) try: with codecs.open(bugs_filename, 'r', encoding=config.LOCALE) as bugs_file: diff --git a/infer/lib/python/inferTraceBugs b/infer/lib/python/inferTraceBugs index d116dae92..b87087401 100755 --- a/infer/lib/python/inferTraceBugs +++ b/infer/lib/python/inferTraceBugs @@ -34,7 +34,7 @@ SOURCE_REMOTE_GITHUB_RE = re.compile('.*github.com[:/](?P.*)') base_parser = argparse.ArgumentParser( description='Explore the error traces in Infer reports.') base_parser.add_argument('-o', '--out', metavar='', - default=utils.DEFAULT_INFER_OUT, dest='infer_out', + default=config.DEFAULT_INFER_OUT, dest='infer_out', action=utils.AbsolutePathAction, help='Set the Infer results directory') base_parser.add_argument('--only-show', @@ -375,7 +375,7 @@ def generate_html_report(args, reports): def main(): args = base_parser.parse_args() - report_filename = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME) + report_filename = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) with codecs.open(report_filename, 'r', encoding=config.LOCALE) as report_file: reports = json.load(report_file) diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index 2d32b6e78..98578a804 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -65,7 +65,7 @@ class ConfirmIncrementalAction(argparse._StoreTrueAction): base_parser = argparse.ArgumentParser(add_help=False) base_group = base_parser.add_argument_group('global arguments') base_group.add_argument('-o', '--out', metavar='', - default=utils.DEFAULT_INFER_OUT, dest='infer_out', + default=config.DEFAULT_INFER_OUT, dest='infer_out', action=utils.AbsolutePathAction, help='Set the Infer results directory') base_group.add_argument('-i', '--incremental', action='store_true', @@ -263,7 +263,7 @@ class Infer: if self.args.buck: self.args.infer_out = os.path.join( self.javac.args.classes_out, - utils.BUCK_INFER_OUT) + config.BUCK_INFER_OUT) self.args.infer_out = os.path.abspath(self.args.infer_out) try: @@ -304,8 +304,8 @@ class Infer: '-verbose_out', self.javac.verbose_out, ] - if os.path.isfile(utils.MODELS_JAR): - infer_cmd += ['-models', utils.MODELS_JAR] + if os.path.isfile(config.MODELS_JAR): + infer_cmd += ['-models', config.MODELS_JAR] infer_cmd.append('-no-static_final') @@ -347,8 +347,8 @@ class Infer: else: if self.args.analyzer == config.ANALYZER_TRACING: infer_options.append('-tracing') - if os.path.isfile(utils.MODELS_JAR): - infer_options += ['-models', utils.MODELS_JAR] + if os.path.isfile(config.MODELS_JAR): + infer_options += ['-models', config.MODELS_JAR] if self.args.infer_cache: infer_options += ['-infer_cache', self.args.infer_cache] @@ -469,8 +469,8 @@ class Infer: containing the list or errors found during the analysis""" out_dir = self.args.infer_out - csv_report = os.path.join(out_dir, utils.CSV_REPORT_FILENAME) - json_report = os.path.join(out_dir, utils.JSON_REPORT_FILENAME) + csv_report = os.path.join(out_dir, config.CSV_REPORT_FILENAME) + json_report = os.path.join(out_dir, config.JSON_REPORT_FILENAME) procs_report = os.path.join(self.args.infer_out, 'procs.csv') infer_print_cmd = [utils.get_cmd_in_bin_dir('InferPrint')] @@ -501,7 +501,7 @@ class Infer: def read_proc_stats(self): proc_stats_path = os.path.join( self.args.infer_out, - utils.PROC_STATS_FILENAME) + config.PROC_STATS_FILENAME) # capture and compile mode do not create proc_stats.json if os.path.isfile(proc_stats_path): @@ -524,7 +524,7 @@ class Infer: 'infer_version': utils.infer_version() } - stats_path = os.path.join(self.args.infer_out, utils.STATS_FILENAME) + stats_path = os.path.join(self.args.infer_out, config.STATS_FILENAME) with codecs.open(stats_path, 'w', encoding=config.LOCALE) as stats_file: json.dump(self.stats, stats_file, indent=2) @@ -547,9 +547,9 @@ class Infer: self.print_analysis_stats() if report_status == os.EX_OK and not self.args.buck: json_report = os.path.join(self.args.infer_out, - utils.JSON_REPORT_FILENAME) + config.JSON_REPORT_FILENAME) bugs_out = os.path.join(self.args.infer_out, - utils.BUGS_FILENAME) + config.BUGS_FILENAME) issues.print_errors(json_report, bugs_out) def print_analysis_stats(self): diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index a1207a637..6ed872b44 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -13,7 +13,7 @@ import subprocess import traceback import util -from inferlib import utils +from inferlib import config, utils MODULE_NAME = __name__ MODULE_DESCRIPTION = '''Run analysis of code built with a command like: @@ -79,7 +79,7 @@ class BuckAnalyzer: def create_cxx_buck_configuration_args(self): # return a string that can be passed in input to buck # and configures the paths to infer/clang/plugin/xcode - facebook_clang_plugins_root = utils.FCP_DIRECTORY + facebook_clang_plugins_root = config.FCP_DIRECTORY clang_path = os.path.join( facebook_clang_plugins_root, 'clang', @@ -138,7 +138,7 @@ class BuckAnalyzer: result_files = self._get_analysis_result_files() all_results = utils.merge_json_arrays_from_files(result_files) merged_results_path = os.path.join(self.args.infer_out, - utils.JSON_REPORT_FILENAME) + config.JSON_REPORT_FILENAME) with open(merged_results_path, 'w') as file_out: json.dump(all_results, file_out, indent=2) # TODO: adapt issues.print_errors to support json and print on screen diff --git a/infer/lib/python/inferlib/capture/javac.py b/infer/lib/python/inferlib/capture/javac.py index 73ac57260..36b02a832 100644 --- a/infer/lib/python/inferlib/capture/javac.py +++ b/infer/lib/python/inferlib/capture/javac.py @@ -8,8 +8,8 @@ import os import subprocess import traceback -import util +import util from inferlib import analyze MODULE_NAME = __name__ diff --git a/infer/lib/python/inferlib/capture/make.py b/infer/lib/python/inferlib/capture/make.py index b6c9ea7e3..ca0ac3d0b 100644 --- a/infer/lib/python/inferlib/capture/make.py +++ b/infer/lib/python/inferlib/capture/make.py @@ -11,7 +11,7 @@ import subprocess import traceback import util -from inferlib import utils +from inferlib import config, utils MODULE_NAME = 'make/cc/clang/gcc' MODULE_DESCRIPTION = '''Run analysis of code built with commands like: @@ -41,7 +41,7 @@ class MakeCapture: def get_envvars(self): env_vars = dict(os.environ) - wrappers_path = utils.WRAPPERS_DIRECTORY + wrappers_path = config.WRAPPERS_DIRECTORY env_vars['INFER_OLD_PATH'] = env_vars['PATH'] env_vars['PATH'] = '{wrappers}{sep}{path}'.format( wrappers=wrappers_path, diff --git a/infer/lib/python/inferlib/capture/xcodebuild.py b/infer/lib/python/inferlib/capture/xcodebuild.py index 72ea3fef0..70191c46f 100644 --- a/infer/lib/python/inferlib/capture/xcodebuild.py +++ b/infer/lib/python/inferlib/capture/xcodebuild.py @@ -11,7 +11,7 @@ import subprocess import traceback import util -from inferlib import utils +from inferlib import config, utils MODULE_NAME = __name__ @@ -22,8 +22,9 @@ Analysis examples: infer -- xcodebuild -target HelloWorldApp -sdk iphonesimulator infer -- xcodebuild -workspace HelloWorld.xcworkspace -scheme HelloWorld''' -CLANG_WRAPPER = os.path.join(utils.XCODE_WRAPPERS_DIRECTORY, 'clang') -CLANGPLUSPLUS_WRAPPER = os.path.join(utils.XCODE_WRAPPERS_DIRECTORY, 'clang++') +CLANG_WRAPPER = os.path.join(config.XCODE_WRAPPERS_DIRECTORY, 'clang') +CLANGPLUSPLUS_WRAPPER = os.path.join(config.XCODE_WRAPPERS_DIRECTORY, + 'clang++') def gen_instance(*args): diff --git a/infer/lib/python/inferlib/config.py b/infer/lib/python/inferlib/config.py index 67907677d..4236e414a 100644 --- a/infer/lib/python/inferlib/config.py +++ b/infer/lib/python/inferlib/config.py @@ -11,10 +11,41 @@ from __future__ import print_function from __future__ import unicode_literals import locale +import os LOCALE = locale.getpreferredencoding() +# this assumes that this file lives in infer/lib/python/infer/ and the binaries +# are in infer/bin/ +INFER_PYTHON_DIRECTORY = os.path.dirname(os.path.realpath(__file__) + .decode(LOCALE)) +INFER_INFER_DIRECTORY = os.path.join(INFER_PYTHON_DIRECTORY, + os.pardir, os.pardir, os.pardir) +INFER_ROOT_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, os.pardir) +FCP_DIRECTORY = os.path.join(INFER_ROOT_DIRECTORY, 'facebook-clang-plugins') +LIB_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'lib') +BIN_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'bin') +JAVA_LIB_DIRECTORY = os.path.join(LIB_DIRECTORY, 'java') +MODELS_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'models.jar') +ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar') +WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers') +XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers') + +DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(LOCALE), 'infer-out') +CSV_PERF_FILENAME = 'performances.csv' +STATS_FILENAME = 'stats.json' +PROC_STATS_FILENAME = 'proc_stats.json' + +CSV_REPORT_FILENAME = 'report.csv' +JSON_REPORT_FILENAME = 'report.json' +BUGS_FILENAME = 'bugs.txt' + +IOS_CAPTURE_ERRORS = 'errors' +IOS_BUILD_OUTPUT = 'build_output' + +BUCK_INFER_OUT = 'infer' + # exit value when infer finds something to report BUG_FOUND_ERROR_CODE = 2 diff --git a/infer/lib/python/inferlib/jwlib.py b/infer/lib/python/inferlib/jwlib.py index 3dbdc259c..229549ddb 100644 --- a/infer/lib/python/inferlib/jwlib.py +++ b/infer/lib/python/inferlib/jwlib.py @@ -55,14 +55,14 @@ class CompilerCall: if self.args.bootclasspath is not None: javac_cmd += ['-bootclasspath', self.args.bootclasspath] - if not os.path.isfile(utils.ANNOT_PROCESSOR_JAR): - raise AnnotationProcessorNotFound(utils.ANNOT_PROCESSOR_JAR) + if not os.path.isfile(config.ANNOT_PROCESSOR_JAR): + raise AnnotationProcessorNotFound(config.ANNOT_PROCESSOR_JAR) if self.args.classpath is None: - classpath = utils.ANNOT_PROCESSOR_JAR + classpath = config.ANNOT_PROCESSOR_JAR else: classpath = os.pathsep.join([ - utils.ANNOT_PROCESSOR_JAR, + config.ANNOT_PROCESSOR_JAR, self.args.classpath]) javac_cmd += ['-cp', classpath] diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index b94d4c260..115b4d2db 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -27,33 +27,6 @@ import time from . import config -# this assumes that this file lives in infer/lib/python/infer/ and the binaries -# are in infer/bin/ -INFER_PYTHON_DIRECTORY = os.path.dirname(os.path.realpath(__file__) - .decode(config.LOCALE)) -INFER_INFER_DIRECTORY = os.path.join(INFER_PYTHON_DIRECTORY, - os.pardir, os.pardir, os.pardir) -INFER_ROOT_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, os.pardir) -FCP_DIRECTORY = os.path.join(INFER_ROOT_DIRECTORY, 'facebook-clang-plugins') -LIB_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'lib') -BIN_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'bin') -TMP_DIRECTORY = tempfile.gettempdir() -JAVA_LIB_DIRECTORY = os.path.join(LIB_DIRECTORY, 'java') -MODELS_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'models.jar') -ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar') -WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers') -XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers') - -DEFAULT_INFER_OUT = os.path.join(os.getcwd().decode(config.LOCALE), - 'infer-out') -CSV_PERF_FILENAME = 'performances.csv' -STATS_FILENAME = 'stats.json' -PROC_STATS_FILENAME = 'proc_stats.json' - -CSV_REPORT_FILENAME = 'report.csv' -JSON_REPORT_FILENAME = 'report.json' -BUGS_FILENAME = 'bugs.txt' - # indices in rows of csv reports CSV_INDEX_CLASS = 0 CSV_INDEX_KIND = 1 @@ -94,11 +67,6 @@ JSON_INDEX_TRACE_NODE_TAGS_VALUE = 'value' QUALIFIER_TAGS = 'qualifier_tags' BUCKET_TAGS = 'bucket' -IOS_CAPTURE_ERRORS = 'errors' -IOS_BUILD_OUTPUT = 'build_output' - -BUCK_INFER_OUT = 'infer' - FORMAT = '[%(levelname)s] %(message)s' DEBUG_FORMAT = '[%(levelname)s:%(filename)s:%(lineno)03d] %(message)s' @@ -159,7 +127,7 @@ def error(msg): def get_cmd_in_bin_dir(binary_name): - return os.path.join(BIN_DIRECTORY, binary_name) + return os.path.join(config.BIN_DIRECTORY, binary_name) def write_cmd_streams_to_file(logfile, cmd=None, out=None, err=None): diff --git a/scripts/build_integration_tests.py b/scripts/build_integration_tests.py index f78c2c76d..ab8716c4c 100755 --- a/scripts/build_integration_tests.py +++ b/scripts/build_integration_tests.py @@ -19,7 +19,7 @@ sys.path.insert(0, os.path.join(SCRIPTS_DIRECTORY, os.pardir, 'infer', 'lib', 'python')) -from inferlib import utils +from inferlib import config, utils CURRENT_DIR = os.getcwd()