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.
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
)
18 java_bin_path
= os
.getenv('JAVA_HOME', '')
20 java_bin_path
= os
.path
.join(java_bin_path
, 'bin')
22 main_class
= 'org.chromium.closure.compiler.Runner'
23 jar_name
= 'runner.jar'
25 closure_jar_relpath
= os
.path
.join('..', 'compiler', 'compiler.jar')
26 src_path
= rel_to_abs(src_dir
)
29 def run_and_communicate(command
, error_template
):
30 print >> sys
.stderr
, command
31 proc
= subprocess
.Popen(command
, stdout
=subprocess
.PIPE
, shell
=True)
34 print >> sys
.stderr
, error_template
% proc
.returncode
35 sys
.exit(proc
.returncode
)
38 def build_artifacts():
41 for root
, dirs
, files
in sorted(os
.walk(src_path
)):
42 for file_name
in files
:
43 java_files
.append(os
.path
.join(root
, file_name
))
45 bin_path
= tempfile
.mkdtemp()
46 manifest_file
= tempfile
.NamedTemporaryFile(mode
='wt', delete
=False)
48 manifest_file
.write('Class-Path: %s\n' % closure_jar_relpath
)
50 javac_path
= os
.path
.join(java_bin_path
, 'javac')
51 javac_command
= '%s -d %s -cp %s %s' % (
52 javac_path
, bin_path
, rel_to_abs(closure_jar_relpath
),
54 run_and_communicate(javac_command
, 'Error: javac returned %d')
56 print 'Building jar...'
57 artifact_path
= rel_to_abs(jar_name
)
58 jar_path
= os
.path
.join(java_bin_path
, 'jar')
59 jar_command
= '%s cvfme %s %s %s -C %s .' % (
60 jar_path
, artifact_path
, manifest_file
.name
, main_class
, bin_path
)
61 run_and_communicate(jar_command
, 'Error: jar returned %d')
63 os
.remove(manifest_file
.name
)
64 shutil
.rmtree(bin_path
, True)
69 def show_usage_and_die():
70 print 'usage: %s' % os
.path
.basename(__file__
)
71 print 'Builds runner.jar from the %s directory contents' % src_dir
82 if __name__
== '__main__':