From 88881581b356d614cc4ce32c9d6a428bcaa2622d Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 23 Feb 2016 06:55:26 -0800 Subject: [PATCH] use supplied javac instead of the one from PATH Summary:public When running `infer -- /path/to/javac Hello.java`, use `/path/to/javac` as the java compiler, not `javac`. closes #279 Reviewed By: jeremydubreil, martinoluca Differential Revision: D2943885 fb-gh-sync-id: 970f07b shipit-source-id: 970f07b --- infer/lib/python/infer | 2 +- infer/lib/python/inferlib/analyze.py | 4 ++-- infer/lib/python/inferlib/capture/javac.py | 5 +++-- infer/lib/python/inferlib/capture/util.py | 1 + infer/lib/python/inferlib/jwlib.py | 8 ++++---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/infer/lib/python/infer b/infer/lib/python/infer index f4569af8c..817dbd245 100755 --- a/infer/lib/python/infer +++ b/infer/lib/python/infer @@ -154,7 +154,7 @@ def main(): if not os.path.exists(os.path.join(args.infer_out, 'captured')): print('There was nothing to analyze, exiting') exit(os.EX_USAGE) - analysis = analyze.Infer(args, []) + analysis = analyze.Infer(args) analysis.analyze_and_report() analysis.save_stats() diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index 5c7ea4961..dbfee65b8 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -246,13 +246,13 @@ def run_command(cmd, debug_mode, javac_arguments, step, analyzer): class Infer: - def __init__(self, args, javac_args): + def __init__(self, args, javac_cmd=None, javac_args=[]): self.args = args if self.args.analyzer not in config.ANALYZERS: help_exit('Unknown analysis mode \"{0}\"' .format(self.args.analyzer)) - self.javac = jwlib.CompilerCall(javac_args) + self.javac = jwlib.CompilerCall(javac_cmd, javac_args) if not self.javac.args.version: if javac_args is None: diff --git a/infer/lib/python/inferlib/capture/javac.py b/infer/lib/python/inferlib/capture/javac.py index 36b02a832..f9b19ac70 100644 --- a/infer/lib/python/inferlib/capture/javac.py +++ b/infer/lib/python/inferlib/capture/javac.py @@ -17,7 +17,8 @@ MODULE_DESCRIPTION = '''Run analysis of code built with a command like: javac Analysis examples: -infer -- javac srcfile.java''' +infer -- javac srcfile.java +infer -- /path/to/javac srcfile.java''' def gen_instance(*args): @@ -30,7 +31,7 @@ create_argparser = util.base_argparser(MODULE_DESCRIPTION, MODULE_NAME) class JavacCapture: def __init__(self, args, cmd): - self.analysis = analyze.Infer(args, cmd[1:]) + self.analysis = analyze.Infer(args, cmd[0], cmd[1:]) def capture(self): try: diff --git a/infer/lib/python/inferlib/capture/util.py b/infer/lib/python/inferlib/capture/util.py index 6fd2a6ed0..a0d645f62 100644 --- a/infer/lib/python/inferlib/capture/util.py +++ b/infer/lib/python/inferlib/capture/util.py @@ -23,6 +23,7 @@ def create_infer_command(args, javac_arguments): infer_args += ['--analyzer', 'capture'] return analyze.Infer(analyze.infer_parser.parse_args(infer_args), + 'javac', analyze.get_javac_args(['javac'] + javac_arguments)) diff --git a/infer/lib/python/inferlib/jwlib.py b/infer/lib/python/inferlib/jwlib.py index 5cac00b30..14c678508 100644 --- a/infer/lib/python/inferlib/jwlib.py +++ b/infer/lib/python/inferlib/jwlib.py @@ -42,8 +42,8 @@ class AnnotationProcessorNotFound(Exception): class CompilerCall: - def __init__(self, arguments): - + def __init__(self, javac_cmd, arguments): + self.javac_cmd = javac_cmd self.original_arguments = arguments self.args, self.remaining_args = parser.parse_known_args(arguments) self.verbose_out = None @@ -51,9 +51,9 @@ class CompilerCall: def run(self): if self.args.version: - return subprocess.call(['javac'] + self.original_arguments) + return subprocess.call([self.javac_cmd] + self.original_arguments) else: - javac_cmd = ['javac', '-verbose', '-g'] + javac_cmd = [self.javac_cmd, '-verbose', '-g'] if self.args.bootclasspath is not None: javac_cmd += ['-bootclasspath', self.args.bootclasspath]