[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 ' 'in <file> to the list of directories to be '
'searched for spec files') 'searched for spec files')
infer_group.add_argument('--java-jar-compiler',
metavar='<file>')
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

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

@ -45,12 +45,13 @@ def parse_command_line(cmd):
class JavaJarCapture: class JavaJarCapture:
def __init__(self, args, cmd): def __init__(self, args, cmd):
java_binary, java_jar, other_args = parse_command_line(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( self.analysis = jwlib.AnalyzerWithJavaJar(
args, args,
java_binary, java_binary,
java_jar, java_jar,
other_args other_args)
)
def capture(self): def capture(self):
try: try:

@ -32,11 +32,17 @@ create_argparser = util.base_argparser(MODULE_DESCRIPTION, MODULE_NAME)
class JavacCapture: class JavacCapture:
def __init__(self, args, cmd): def __init__(self, args, cmd):
self.analysis = jwlib.AnalyzerWithJavac( if args.java_jar_compiler is not None:
args, self.analysis = jwlib.AnalyzerWithJavaJar(
cmd[0], args,
cmd[1:], 'java',
) args.java_jar_compiler,
cmd[1:])
else:
self.analysis = jwlib.AnalyzerWithJavac(
args,
cmd[0],
cmd[1:])
def capture(self): def capture(self):
try: 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('-d', dest='classes_out', default=current_directory)
parser.add_argument('-processorpath', type=utils.decode, dest='processorpath') parser.add_argument('-processorpath', type=utils.decode, dest='processorpath')
parser.add_argument('-processor', type=utils.decode, dest='processor') 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): def _get_javac_args(args):

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

@ -1189,6 +1189,11 @@ and zip_specs_library =
CLOpt.mk_string_list ~long:"zip-specs-library" ~short:"ziplib" ~f:resolve CLOpt.mk_string_list ~long:"zip-specs-library" ~short:"ziplib" ~f:resolve
~meta:"zip file" "Search for .spec files in a zip file" ~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 *) (** Configuration values specified by environment variables *)
@ -1430,6 +1435,7 @@ and frontend_stats = !frontend_stats
and headers = !headers and headers = !headers
and infer_cache = !infer_cache and infer_cache = !infer_cache
and iterations = !iterations and iterations = !iterations
and java_jar_compiler = !java_jar_compiler
and javac_verbose_out = !verbose_out and javac_verbose_out = !verbose_out
and jobs = !jobs and jobs = !jobs
and join_cond = !join_cond and join_cond = !join_cond

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

Loading…
Cancel
Save