diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index dd6c2c950..79f74a40f 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -161,33 +161,6 @@ infer_group.add_argument('--specs-dir-list-file', 'in to the list of directories to be ' 'searched for spec files') -def detect_javac(args): - for index, arg in enumerate(args): - if arg == 'javac': - return index - - -def get_infer_args(args): - index = detect_javac(args) - if index is None: - cmd_args = args - else: - cmd_args = args[:index] - return infer_parser.parse_args(cmd_args) - - -def get_javac_args(args): - javac_args = args[detect_javac(args) + 1:] - if len(javac_args) == 0: - return None - else: - # replace any -g:.* flag with -g to preserve debugging symbols - args = map(lambda arg: '-g' if '-g:' in arg else arg, javac_args) - # skip -Werror - args = filter(lambda arg: arg != '-Werror', args) - return args - - def remove_infer_out(infer_out): # it is safe to ignore errors here because recreating the infer_out # directory will fail later diff --git a/infer/lib/python/inferlib/capture/ant.py b/infer/lib/python/inferlib/capture/ant.py index f3717a915..e4ff051a0 100644 --- a/infer/lib/python/inferlib/capture/ant.py +++ b/infer/lib/python/inferlib/capture/ant.py @@ -8,7 +8,8 @@ import os import logging -import util +from . import util +from inferlib import jwlib MODULE_NAME = __name__ MODULE_DESCRIPTION = '''Run analysis of code built with a command like: @@ -59,7 +60,7 @@ class AntCapture: if argument_start_pattern in line: collect = True if javac_arguments != []: - capture = util.create_infer_command(self.args, + capture = jwlib.create_infer_command(self.args, javac_arguments) calls.append(capture) javac_arguments = [] @@ -70,7 +71,7 @@ class AntCapture: arg = self.remove_quotes(content) javac_arguments.append(arg) if javac_arguments != []: - capture = util.create_infer_command(self.args, javac_arguments) + capture = jwlib.create_infer_command(self.args, javac_arguments) calls.append(capture) javac_arguments = [] return calls diff --git a/infer/lib/python/inferlib/capture/gradle.py b/infer/lib/python/inferlib/capture/gradle.py index 6b2841ab3..bb7850bb7 100644 --- a/infer/lib/python/inferlib/capture/gradle.py +++ b/infer/lib/python/inferlib/capture/gradle.py @@ -77,7 +77,7 @@ class GradleCapture: sources.write("\n".join(java_files)) sources.flush() java_args.append("@" + sources.name) - capture = util.create_infer_command(self.args, + capture = jwlib.create_infer_command(self.args, java_args) calls.append(capture) return calls diff --git a/infer/lib/python/inferlib/capture/mvn.py b/infer/lib/python/inferlib/capture/mvn.py index a330a2f26..c93abbde1 100644 --- a/infer/lib/python/inferlib/capture/mvn.py +++ b/infer/lib/python/inferlib/capture/mvn.py @@ -45,7 +45,7 @@ class MavenCapture: if options_next: # line has format [Debug] javac_args = line.split(' ')[1:] + files_to_compile - capture = util.create_infer_command(self.args, javac_args) + capture = jwlib.create_infer_command(self.args, javac_args) calls.append(capture) options_next = False files_to_compile = [] diff --git a/infer/lib/python/inferlib/capture/util.py b/infer/lib/python/inferlib/capture/util.py index 04a05ac86..baf4fa5ad 100644 --- a/infer/lib/python/inferlib/capture/util.py +++ b/infer/lib/python/inferlib/capture/util.py @@ -20,18 +20,6 @@ import traceback from inferlib import analyze, utils - -def create_infer_command(args, javac_arguments): - infer_args = ['-o', args.infer_out] - if args.debug: - infer_args.append('--debug') - infer_args += ['--analyzer', 'capture'] - - return analyze.Infer(analyze.infer_parser.parse_args(infer_args), - 'javac', - analyze.get_javac_args(['javac'] + javac_arguments)) - - def get_build_output(build_cmd): # TODO make it return generator to be able to handle large builds proc = subprocess.Popen(build_cmd, stdout=subprocess.PIPE) diff --git a/infer/lib/python/inferlib/jwlib.py b/infer/lib/python/inferlib/jwlib.py index 9951aabe9..7d967d6ca 100644 --- a/infer/lib/python/inferlib/jwlib.py +++ b/infer/lib/python/inferlib/jwlib.py @@ -11,6 +11,7 @@ import os import tempfile import subprocess +import analyze import config import utils @@ -29,6 +30,33 @@ parser.add_argument('-processorpath', type=str, dest='processorpath') parser.add_argument('-processor', type=str, dest='processor') +def _get_javac_args(args): + try: + javac_pos = args.index('javac') + except ValueError: + return None + javac_args = args[javac_pos + 1:] + if len(javac_args) == 0: + return None + else: + # replace any -g:.* flag with -g to preserve debugging symbols + args = map(lambda arg: '-g' if '-g:' in arg else arg, javac_args) + # skip -Werror + args = filter(lambda arg: arg != '-Werror', args) + return args + + +def create_infer_command(args, javac_arguments): + infer_args = ['-o', args.infer_out] + if args.debug: + infer_args.append('--debug') + infer_args += ['--analyzer', 'capture'] + + return analyze.Infer(analyze.infer_parser.parse_args(infer_args), + 'javac', + _get_javac_args(['javac'] + javac_arguments)) + + class AnnotationProcessorNotFound(Exception): def __init__(self, path):