Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/closure_compiler/runner/build_runner_jar.py

Issue 369643002: Lay groudwork to Closure compile JavaScript (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more nits Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import shutil
8 import subprocess
9 import sys
10 import tempfile
11
12
13 def rel_to_abs(rel_path):
14 script_path = os.path.dirname(os.path.abspath(__file__))
15 return os.path.join(script_path, rel_path)
16
17
18 java_bin_path = os.getenv('JAVA_HOME', '')
19 if java_bin_path:
20 java_bin_path = os.path.join(java_bin_path, 'bin')
21
22 main_class = 'org.chromium.closure.compiler.Runner'
23 jar_name = 'runner.jar'
24 src_dir = 'src'
25 closure_jar_relpath = os.path.join('..', 'compiler', 'compiler.jar')
26 src_path = rel_to_abs(src_dir)
27
28
29 def run_and_communicate(command, error_template):
30 proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
31 proc.communicate()
32 if proc.returncode:
33 print >> sys.stderr, error_template % proc.returncode
34 sys.exit(proc.returncode)
35
36
37 def build_artifacts():
38 print 'Compiling...'
39 java_files = []
40 for root, dirs, files in sorted(os.walk(src_path)):
41 for file_name in files:
42 java_files.append(os.path.join(root, file_name))
43
44 bin_path = tempfile.mkdtemp()
45 manifest_file = tempfile.NamedTemporaryFile(mode='wt', delete=False)
46 try:
47 manifest_file.write('Class-Path: %s\n' % closure_jar_relpath)
48 manifest_file.close()
49 javac_path = os.path.join(java_bin_path, 'javac')
50 javac_command = '%s -d %s -cp %s %s' % (
51 javac_path, bin_path, rel_to_abs(closure_jar_relpath),
52 ' '.join(java_files))
53 run_and_communicate(javac_command, 'Error: javac returned %d')
54
55 print 'Building jar...'
56 artifact_path = rel_to_abs(jar_name)
57 jar_path = os.path.join(java_bin_path, 'jar')
58 jar_command = '%s cvfme %s %s %s -C %s .' % (
59 jar_path, artifact_path, manifest_file.name, main_class, bin_path)
60 run_and_communicate(jar_command, 'Error: jar returned %d')
61 finally:
62 os.remove(manifest_file.name)
63 shutil.rmtree(bin_path, True)
64
65 print 'Done.'
66
67
68 def show_usage_and_die():
69 print 'usage: %s' % os.path.basename(__file__)
70 print 'Builds runner.jar from the %s directory contents' % src_dir
71 sys.exit(1)
72
73
74 def main():
75 if len(sys.argv) > 1:
76 show_usage_and_die()
77
78 build_artifacts()
79
80
81 if __name__ == '__main__':
82 main()
OLDNEW
« no previous file with comments | « third_party/closure_compiler/compiler/compiler.jar ('k') | third_party/closure_compiler/runner/runner.jar » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698