| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 import os | |
| 4 import shutil | |
| 5 import subprocess | |
| 6 import sys | |
| 7 import tempfile | |
| 8 | |
| 9 | |
| 10 def rel_to_abs(rel_path): | |
| 11 return os.path.join(script_path, rel_path) | |
| 12 | |
| 13 | |
| 14 java_bin_path = os.getenv('JAVA_HOME', '') | |
| 15 if java_bin_path: | |
| 16 java_bin_path = os.path.join(java_bin_path, 'bin') | |
| 17 | |
| 18 main_class = 'org.chromium.devtools.compiler.Runner' | |
| 19 jar_name = 'closure-runner.jar' | |
| 20 src_dir = 'src' | |
| 21 script_path = os.path.dirname(os.path.abspath(__file__)) | |
| 22 closure_jar_relpath = os.path.join('..', 'closure', 'compiler.jar') | |
| 23 src_path = rel_to_abs(src_dir) | |
| 24 | |
| 25 | |
| 26 def run_and_communicate(command, error_template): | |
| 27 proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) | |
| 28 proc.communicate() | |
| 29 if proc.returncode: | |
| 30 print >> sys.stderr, error_template % proc.returncode | |
| 31 sys.exit(proc.returncode) | |
| 32 | |
| 33 | |
| 34 def build_artifacts(): | |
| 35 print 'Compiling...' | |
| 36 java_files = [] | |
| 37 for root, dirs, files in sorted(os.walk(src_path)): | |
| 38 for file_name in files: | |
| 39 java_files.append(os.path.join(root, file_name)) | |
| 40 | |
| 41 bin_path = tempfile.mkdtemp() | |
| 42 manifest_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) | |
| 43 try: | |
| 44 manifest_file.write('Class-Path: %s\n' % closure_jar_relpath) | |
| 45 manifest_file.close() | |
| 46 javac_path = os.path.join(java_bin_path, 'javac') | |
| 47 javac_command = '%s -d %s -cp %s %s' % (javac_path, bin_path, rel_to_abs
(closure_jar_relpath), ' '.join(java_files)) | |
| 48 run_and_communicate(javac_command, 'Error: javac returned %d') | |
| 49 | |
| 50 print 'Building jar...' | |
| 51 artifact_path = rel_to_abs(jar_name) | |
| 52 jar_path = os.path.join(java_bin_path, 'jar') | |
| 53 jar_command = '%s cvfme %s %s %s -C %s .' % (jar_path, artifact_path, ma
nifest_file.name, main_class, bin_path) | |
| 54 run_and_communicate(jar_command, 'Error: jar returned %d') | |
| 55 finally: | |
| 56 os.remove(manifest_file.name) | |
| 57 shutil.rmtree(bin_path, True) | |
| 58 | |
| 59 | |
| 60 def help(): | |
| 61 print 'usage: %s' % os.path.basename(__file__) | |
| 62 print 'Builds compiler-runner.jar from the %s directory contents' % src_dir | |
| 63 | |
| 64 | |
| 65 def main(): | |
| 66 if len(sys.argv) > 1: | |
| 67 help() | |
| 68 return | |
| 69 build_artifacts() | |
| 70 print 'Done.' | |
| 71 | |
| 72 if __name__ == '__main__': | |
| 73 main() | |
| OLD | NEW |