From 092e447ce36247ca992118f4685ce36dec87b1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3FUTF-8=3Fq=3FDeniz=3D20T=3DC3=3DBCrkoglu=3F=3D?= Date: Tue, 14 Jul 2015 09:14:40 -0100 Subject: [PATCH] Handle java sources from a file Summary: The current way gradle plugin works is by parsing the verbose output to figure out which files to compile. This becomes a problem when the number of files exceed allowed argument parameter length. Use javac's @sources file instead. This patch will leave the tempfiles behind (also noted by Jyrki during the review), however I would like to leave that to a follow up commit and first make sure the tool works for people experiencing this problem. Fixes #22 Closes https://github.com/facebook/infer/pull/131 Github Author: =?UTF-8?q?Deniz=20T=C3=BCrkoglu?= --- infer/bin/inferlib.py | 2 +- infer/lib/capture/gradle.py | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/infer/bin/inferlib.py b/infer/bin/inferlib.py index 162247ad7..86ab68c9c 100644 --- a/infer/bin/inferlib.py +++ b/infer/bin/inferlib.py @@ -177,7 +177,7 @@ def create_results_dir(results_dir): def clean_infer_out(infer_out): - directories = ['multicore', 'classnames', 'sources'] + directories = ['multicore', 'classnames', 'sources', 'filelists'] extensions = ['.cfg', '.cg'] for root, dirs, files in os.walk(infer_out): diff --git a/infer/lib/capture/gradle.py b/infer/lib/capture/gradle.py index 9fef2d136..9187b3d44 100644 --- a/infer/lib/capture/gradle.py +++ b/infer/lib/capture/gradle.py @@ -2,6 +2,7 @@ import os import util import logging import subprocess +import tempfile MODULE_NAME = __name__ MODULE_DESCRIPTION = '''Run analysis of code built with a command like: @@ -11,6 +12,7 @@ Analysis examples: infer -- gradle build infer -- ./gradlew build''' +FILELISTS = 'filelists' def gen_instance(*args): return GradleCapture(*args) @@ -28,6 +30,9 @@ class GradleCapture: self.build_cmd = [cmd[0], '--debug'] + cmd[1:] # That contains javac version as well version_str = util.run_cmd_ignore_fail([cmd[0], '--version']) + path = os.path.join(self.args.infer_out, FILELISTS) + if not os.path.exists(path): + os.mkdir(path) logging.info("Running with:\n" + version_str) def get_inferJ_commands(self, verbose_output): @@ -37,9 +42,25 @@ class GradleCapture: if argument_start_pattern in line: content = line.partition(argument_start_pattern)[2].strip() javac_arguments = content.split(' ') - capture = util.create_inferJ_command(self.args, - javac_arguments) - calls.append(capture) + java_files = [] + java_args = [] + for java_arg in javac_arguments: + if java_arg.endswith('.java'): + java_files.append(java_arg) + else: + java_args.append(java_arg) + with tempfile.NamedTemporaryFile( + mode='w', + suffix='.txt', + prefix='gradle_', + dir=os.path.join(self.args.infer_out, FILELISTS), + delete=False) as sources: + sources.write("\n".join(java_files)) + sources.flush() + java_args.append("@" + sources.name) + capture = util.create_inferJ_command(self.args, + java_args) + calls.append(capture) return calls def capture(self):