10 def rel_to_abs(rel_path
):
11 return os
.path
.join(script_path
, rel_path
)
14 java_bin_path
= os
.getenv('JAVA_HOME', '')
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'
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)
30 print >> sys
.stderr
, error_template
% proc
.returncode
31 sys
.exit(proc
.returncode
)
34 def build_artifacts():
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)
44 manifest_file
.write('Class-Path: %s\n' % closure_jar_relpath
)
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')
56 os
.remove(manifest_file
.name
)
57 shutil
.rmtree(bin_path
, True)
61 print 'usage: %s' % os
.path
.basename(__file__
)
62 print 'Builds compiler-runner.jar from the %s directory contents' % src_dir
72 if __name__
== '__main__':