move get_javac_args to jwlib.py

Summary:public
java-specific code such as this belongs in jwlib.py. It will also help the
refactoring in the next diff.

Reviewed By: sblackshear

Differential Revision: D2965814

fb-gh-sync-id: c3adc03
shipit-source-id: c3adc03
master
Jules Villard 9 years ago committed by facebook-github-bot-7
parent 2c489371dd
commit 9d080cadb1

@ -161,33 +161,6 @@ infer_group.add_argument('--specs-dir-list-file',
'in <file> to the list of directories to be ' 'in <file> to the list of directories to be '
'searched for spec files') '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): def remove_infer_out(infer_out):
# it is safe to ignore errors here because recreating the infer_out # it is safe to ignore errors here because recreating the infer_out
# directory will fail later # directory will fail later

@ -8,7 +8,8 @@
import os import os
import logging import logging
import util from . import util
from inferlib import jwlib
MODULE_NAME = __name__ MODULE_NAME = __name__
MODULE_DESCRIPTION = '''Run analysis of code built with a command like: MODULE_DESCRIPTION = '''Run analysis of code built with a command like:
@ -59,7 +60,7 @@ class AntCapture:
if argument_start_pattern in line: if argument_start_pattern in line:
collect = True collect = True
if javac_arguments != []: if javac_arguments != []:
capture = util.create_infer_command(self.args, capture = jwlib.create_infer_command(self.args,
javac_arguments) javac_arguments)
calls.append(capture) calls.append(capture)
javac_arguments = [] javac_arguments = []
@ -70,7 +71,7 @@ class AntCapture:
arg = self.remove_quotes(content) arg = self.remove_quotes(content)
javac_arguments.append(arg) javac_arguments.append(arg)
if javac_arguments != []: if javac_arguments != []:
capture = util.create_infer_command(self.args, javac_arguments) capture = jwlib.create_infer_command(self.args, javac_arguments)
calls.append(capture) calls.append(capture)
javac_arguments = [] javac_arguments = []
return calls return calls

@ -77,7 +77,7 @@ class GradleCapture:
sources.write("\n".join(java_files)) sources.write("\n".join(java_files))
sources.flush() sources.flush()
java_args.append("@" + sources.name) java_args.append("@" + sources.name)
capture = util.create_infer_command(self.args, capture = jwlib.create_infer_command(self.args,
java_args) java_args)
calls.append(capture) calls.append(capture)
return calls return calls

@ -45,7 +45,7 @@ class MavenCapture:
if options_next: if options_next:
# line has format [Debug] <space separated options> # line has format [Debug] <space separated options>
javac_args = line.split(' ')[1:] + files_to_compile 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) calls.append(capture)
options_next = False options_next = False
files_to_compile = [] files_to_compile = []

@ -20,18 +20,6 @@ import traceback
from inferlib import analyze, utils 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): def get_build_output(build_cmd):
# TODO make it return generator to be able to handle large builds # TODO make it return generator to be able to handle large builds
proc = subprocess.Popen(build_cmd, stdout=subprocess.PIPE) proc = subprocess.Popen(build_cmd, stdout=subprocess.PIPE)

@ -11,6 +11,7 @@ import os
import tempfile import tempfile
import subprocess import subprocess
import analyze
import config import config
import utils import utils
@ -29,6 +30,33 @@ parser.add_argument('-processorpath', type=str, dest='processorpath')
parser.add_argument('-processor', type=str, dest='processor') 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): class AnnotationProcessorNotFound(Exception):
def __init__(self, path): def __init__(self, path):

Loading…
Cancel
Save