Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / scripts / compiler-runner / build_compiler_runner_jar.py
blobc0e8daca82b02d90782ef9052244fed72eb65109
1 #!/usr/bin/python
3 import os
4 import shutil
5 import subprocess
6 import sys
7 import tempfile
10 def rel_to_abs(rel_path):
11 return os.path.join(script_path, rel_path)
14 java_bin_path = os.getenv('JAVA_HOME', '')
15 if java_bin_path:
16 java_bin_path = os.path.join(java_bin_path, 'bin')
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)
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)
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))
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')
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, manifest_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)
60 def help():
61 print 'usage: %s' % os.path.basename(__file__)
62 print 'Builds compiler-runner.jar from the %s directory contents' % src_dir
65 def main():
66 if len(sys.argv) > 1:
67 help()
68 return
69 build_artifacts()
70 print 'Done.'
72 if __name__ == '__main__':
73 main()