diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/flycheck-android-java.py | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/bin/flycheck-android-java.py b/bin/flycheck-android-java.py index 6f14425..4c9c82f 100644 --- a/bin/flycheck-android-java.py +++ b/bin/flycheck-android-java.py @@ -1,6 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +import errno import os import subprocess import sys @@ -50,7 +51,7 @@ def filter_source_files(files): return [f for f in files if f.endswith('.java')] def run_javac(encoding, source, target, bootcp, cp, files, output, args, - sourcefile): + sourcefile, outdir): """Execute javac with the given options.""" command = ['javac'] if encoding: @@ -61,19 +62,32 @@ def run_javac(encoding, source, target, bootcp, cp, files, output, args, command.extend(['-target', target]) if bootcp: command.extend(['-bootclasspath', bootcp]) - if cp: - command.extend(['-cp', ':'.join(cp)]) - if output: - command.extend(['-d', output]) + if outdir: + command.extend(['-d', outdir]) + tmp = [] + if output: + tmp.append(output) + if cp: + tmp.extend(cp) + if tmp: + command.extend(['-cp', ':'.join(tmp)]) + else: + if cp: + command.extend(['-cp', ':'.join(cp)]) + if output: + command.extend(['-d', output]) command.extend(args) command.append(sourcefile) - with tempfile.NamedTemporaryFile(mode='w') as f: - command.append('@' + f.name) - for source in filter_source_files(files): - f.write(source) - f.write('\n') - f.flush() + if outdir: return subprocess.call(command) + else: + with tempfile.NamedTemporaryFile(mode='w') as f: + command.append('@' + f.name) + for source in filter_source_files(files): + f.write(source) + f.write('\n') + f.flush() + return subprocess.call(command) def file_in_list(needle, files): """Find needle in files and if so, return the list without needle. @@ -89,6 +103,13 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile): os.path.dirname(sourcefile)) output = None if sessiondir != None: + outdir = os.path.join(sessiondir, 'java_output') + try: + os.mkdir(outdir) + except OSError as exc: + if exc.errno != errno.EEXIST or not os.path.isdir(outdir): + outdir = None + pass cachefile = os.path.join(sessiondir, 'gradle_output') try: if os.path.getmtime(cachefile) >= mtime: @@ -96,6 +117,8 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile): output = f.read() except (OSError, IOError): pass + else: + outdir = None if not output: cmd.extend(['-q', 'flycheckAndroidJava']) @@ -117,7 +140,7 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile): return run_javac(data['encoding'], data['source'], data['target'], data['bootcp'], data['cp'], files, data['output'], - data['args'], tempfile) + data['args'], tempfile, outdir) data = {} elif data != None: if line.startswith('args='): @@ -141,7 +164,7 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile): if files: return run_javac(data['encoding'], data['source'], data['target'], data['bootcp'], data['cp'], files, data['output'], - data['args'], tempfile) + data['args'], tempfile, outdir) return 0 def main(argv): |
