From 31238e1a0056984a3e40abe6668e60933cc29d6b Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 12 Jan 2017 00:14:04 +0100 Subject: Add temporary output dir to classpath This means you have to do real build less often as you change the API of different classes. However, it instead means that we can end up with outdated class files if you check out new code and build without revisiting the buffer in Emacs. So, to work around that, we check that no class file is older than the ones in the real output dir. But to keep everything fast, this is launched in a background process --- bin/flycheck-android-java.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/flycheck-android-java.py b/bin/flycheck-android-java.py index 111ff3a..7e75068 100644 --- a/bin/flycheck-android-java.py +++ b/bin/flycheck-android-java.py @@ -53,6 +53,22 @@ def filter_source_files(files): """Remove any item not looking like a Java source file.""" return [f for f in files if f.endswith('.java')] +def cleanup_output(tmp, real): + """Remove any file in tmp that is older than the one in real""" + offset = len(tmp) + if tmp[-1] != '/': + offset = offset + 1 + for (dirpath, _, files) in os.walk(tmp): + realpath = os.path.join(real, dirpath[offset:]) + for filename in files: + try: + mtime = os.path.getmtime(os.path.join(realpath, filename)) + tmp = os.path.join(dirpath, filename) + if os.path.getmtime(tmp) <= mtime: + os.remove(tmp) + except OSError: + pass + def run_javac(encoding, source, target, bootcp, cp, files, output, args, sourcefile, outdir): """Execute javac with the given options.""" @@ -67,13 +83,17 @@ def run_javac(encoding, source, target, bootcp, cp, files, output, args, command.extend(['-bootclasspath', bootcp]) if outdir: command.extend(['-d', outdir]) - tmp = [] + tmp = [outdir] if output: tmp.append(output) if cp: tmp.extend(cp) if tmp: command.extend(['-cp', ':'.join(tmp)]) + + if os.fork() == 0: + cleanup_output(outdir, output) + sys.exit(0) else: if cp: command.extend(['-cp', ':'.join(cp)]) -- cgit v1.2.3-70-g09d2