[infer][java] Add the possibility to choose a compiler jar that is different from the system Java compiler to generate the bytecode

Reviewed By: jberdine

Differential Revision: D4026697

fbshipit-source-id: 4b02a53
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent 08509fb2ab
commit 587d829a1a

@ -173,6 +173,8 @@ infer_group.add_argument('--specs-dir-list-file',
'in <file> to the list of directories to be '
'searched for spec files')
infer_group.add_argument('--java-jar-compiler',
metavar='<file>')
def remove_infer_out(infer_out):
# it is safe to ignore errors here because recreating the infer_out

@ -45,11 +45,11 @@ INFER_JSON_REPORT = os.path.join(config.BUCK_INFER_OUT,
INFER_STATS = os.path.join(config.BUCK_INFER_OUT, config.STATS_FILENAME)
INFER_SCRIPT = """\
#!/usr/bin/env {0}
#!/usr/bin/env {python_executable}
import subprocess
import sys
cmd = {1} + ['--', 'javac'] + sys.argv[1:]
cmd = {infer_command} + ['--', 'javac'] + sys.argv[1:]
subprocess.check_call(cmd)
"""
@ -64,6 +64,12 @@ def prepare_build(args):
'--analyzer', args.analyzer,
]
if args.java_jar_compiler is not None:
infer_options += [
'--java-jar-compiler',
args.java_jar_compiler,
]
if args.debug:
infer_options.append('--debug')
@ -102,7 +108,9 @@ def prepare_build(args):
dir='.') as infer_script:
logging.info('Creating %s' % infer_script.name)
infer_script.file.write(
utils.encode(INFER_SCRIPT.format(sys.executable, infer_command)))
utils.encode(INFER_SCRIPT.format(
python_executable=sys.executable,
infer_command=infer_command)))
st = os.stat(infer_script.name)
os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

@ -45,12 +45,13 @@ def parse_command_line(cmd):
class JavaJarCapture:
def __init__(self, args, cmd):
java_binary, java_jar, other_args = parse_command_line(cmd)
if args.java_jar_compiler is not None:
java_jar = args.java_jar_compiler
self.analysis = jwlib.AnalyzerWithJavaJar(
args,
java_binary,
java_jar,
other_args
)
other_args)
def capture(self):
try:

@ -32,11 +32,17 @@ create_argparser = util.base_argparser(MODULE_DESCRIPTION, MODULE_NAME)
class JavacCapture:
def __init__(self, args, cmd):
self.analysis = jwlib.AnalyzerWithJavac(
args,
cmd[0],
cmd[1:],
)
if args.java_jar_compiler is not None:
self.analysis = jwlib.AnalyzerWithJavaJar(
args,
'java',
args.java_jar_compiler,
cmd[1:])
else:
self.analysis = jwlib.AnalyzerWithJavac(
args,
cmd[0],
cmd[1:])
def capture(self):
try:

@ -33,12 +33,6 @@ parser.add_argument('-bootclasspath', type=utils.decode)
parser.add_argument('-d', dest='classes_out', default=current_directory)
parser.add_argument('-processorpath', type=utils.decode, dest='processorpath')
parser.add_argument('-processor', type=utils.decode, dest='processor')
parser.add_argument('-o', '--out', metavar='<directory>',
default=utils.encode(config.DEFAULT_INFER_OUT),
dest='infer_out',
type=utils.decode,
action=utils.AbsolutePathAction,
help='Set the Infer results directory')
def _get_javac_args(args):

@ -58,8 +58,8 @@ let () =
(if not Config.absolute_paths then [] else
["--absolute-paths"]) @
(match Config.analyzer with None -> [] | Some a ->
["--analyzer";
IList.assoc (=) a (IList.map (fun (n,a) -> (a,n)) Config.string_to_analyzer)]) @
["--analyzer";
IList.assoc (=) a (IList.map (fun (n,a) -> (a,n)) Config.string_to_analyzer)]) @
(match Config.blacklist with
| Some s when in_buck_mode -> ["--blacklist-regex"; s]
| _ -> []) @
@ -67,6 +67,8 @@ let () =
["--android-harness"]) @
(if not Config.buck then [] else
["--buck"]) @
(match Config.java_jar_compiler with None -> [] | Some p ->
["--java-jar-compiler"; p]) @
(match IList.rev Config.buck_build_args with
| args when in_buck_mode ->
IList.map (fun arg -> ["--Xbuck"; "'" ^ arg ^ "'"]) args |> IList.flatten
@ -88,7 +90,7 @@ let () =
(if Option.is_none Config.use_compilation_database || not in_buck_mode then [] else
["--use-compilation-database"]) @
(match Config.infer_cache with None -> [] | Some s ->
["--infer_cache"; s]) @
["--infer_cache"; s]) @
"-j" :: (string_of_int Config.jobs) ::
"-l" :: (string_of_float Config.load_average) ::
(if not Config.pmd_xml then [] else
@ -97,9 +99,9 @@ let () =
["--reactive"]) @
"--out" :: Config.results_dir ::
(match Config.project_root with None -> [] | Some pr ->
["--project_root"; pr]) @
["--project_root"; pr]) @
(match Config.xcode_developer_dir with None -> [] | Some d ->
["--xcode-developer-dir"; d]) @
["--xcode-developer-dir"; d]) @
(if Config.rest = [] then [] else
("--" :: build_cmd))
) in

@ -1189,6 +1189,11 @@ and zip_specs_library =
CLOpt.mk_string_list ~long:"zip-specs-library" ~short:"ziplib" ~f:resolve
~meta:"zip file" "Search for .spec files in a zip file"
and java_jar_compiler =
CLOpt.mk_string_opt
~long:"java-jar-compiler"
~exes:CLOpt.[Java]
~meta:"path" "Specifify the Java compiler jar used to generate the bytecode"
(** Configuration values specified by environment variables *)
@ -1430,6 +1435,7 @@ and frontend_stats = !frontend_stats
and headers = !headers
and infer_cache = !infer_cache
and iterations = !iterations
and java_jar_compiler = !java_jar_compiler
and javac_verbose_out = !verbose_out
and jobs = !jobs
and join_cond = !join_cond

@ -270,7 +270,7 @@ val write_html : bool
val xcode_developer_dir : string option
val xml_specs : bool
val zip_libraries : zip_library list
val java_jar_compiler : string option
(** Global variables *)

Loading…
Cancel
Save