OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. |
| 5 # |
| 6 # Script to compile the analyzer. |
| 7 # |
| 8 # Usage: compile_analyzer.py OPTIONS files |
| 9 # |
| 10 |
| 11 import optparse |
| 12 import os |
| 13 import shutil |
| 14 import subprocess |
| 15 import sys |
| 16 |
| 17 def GetOptions(): |
| 18 options = optparse.OptionParser(usage='usage: %prog [options] <output>') |
| 19 options.add_option("--class_path_file", |
| 20 help='File describing the classpath in manifest style') |
| 21 options.add_option("--output_dir", |
| 22 help='Where to output files') |
| 23 options.add_option("--jar_file_name", |
| 24 help='Name of the resulting jar file') |
| 25 options.add_option("--jar_entry_directory", |
| 26 help='Which directory within output to pack into the jar files') |
| 27 options.add_option("--entry_point", |
| 28 help='The entry point for running the program.') |
| 29 options.add_option("--dependent_jar_files", |
| 30 help='The jar files that we link against, space separated.') |
| 31 return options.parse_args() |
| 32 |
| 33 def CompileAnalyzer(options, args): |
| 34 # We rely on all jar files being copied to the output dir. |
| 35 class_path = options.output_dir + '*' |
| 36 cmd = ['javac', |
| 37 '-sourcepath', 'foobar', |
| 38 '-source', '6', |
| 39 '-target', '6', |
| 40 '-implicit:none', |
| 41 '-d', options.output_dir, |
| 42 '-cp', class_path, |
| 43 ] |
| 44 cmd.extend(args) |
| 45 subprocess.call(cmd) |
| 46 |
| 47 def CreateJarFile(options): |
| 48 class_path_file_name = options.output_dir + options.class_path_file |
| 49 jar_file_name = options.output_dir + options.jar_file_name |
| 50 cmd = ['jar', 'cfem', jar_file_name, options.entry_point, |
| 51 class_path_file_name, |
| 52 '-C', options.output_dir, options.jar_entry_directory]; |
| 53 subprocess.call(cmd) |
| 54 |
| 55 def CopyFiles(options): |
| 56 # Strip " from the string |
| 57 files = options.dependent_jar_files.replace('"', ''); |
| 58 for f in files.split(" "): |
| 59 shutil.copy(f, options.output_dir) |
| 60 |
| 61 def CreateClassPathFile(options): |
| 62 class_path_file_name = options.output_dir + options.class_path_file |
| 63 with open(class_path_file_name, 'w') as output: |
| 64 print >> output, 'Class-Path:', '.', |
| 65 for r,d,f in os.walk(options.output_dir): |
| 66 for file in f: |
| 67 if file.endswith('.jar'): |
| 68 print >> output, file, |
| 69 # Add new line |
| 70 print >> output |
| 71 |
| 72 def main(): |
| 73 (options, args) = GetOptions() |
| 74 # Clean out everything whenever we do a build, guarantees that we don't have |
| 75 # any leftover jar files. |
| 76 shutil.rmtree(options.output_dir, ignore_errors=True) |
| 77 os.makedirs(options.output_dir) |
| 78 |
| 79 CopyFiles(options) |
| 80 CreateClassPathFile(options) |
| 81 CompileAnalyzer(options, args) |
| 82 CreateJarFile(options) |
| 83 |
| 84 |
| 85 if __name__=='__main__': |
| 86 main() |
OLD | NEW |