| 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 imp | |
| 12 import optparse | |
| 13 import os | |
| 14 import platform | |
| 15 import shutil | |
| 16 import subprocess | |
| 17 import sys | |
| 18 | |
| 19 from os.path import join | |
| 20 | |
| 21 def GetUtils(): | |
| 22 '''Dynamically load the tools/utils.py python module.''' | |
| 23 dart_dir = os.path.abspath(os.path.join(__file__, '..', '..', '..')) | |
| 24 return imp.load_source('utils', os.path.join(dart_dir, 'tools', 'utils.py')) | |
| 25 | |
| 26 utils = GetUtils() | |
| 27 | |
| 28 def GetOptions(): | |
| 29 options = optparse.OptionParser(usage='usage: %prog [options] <output>') | |
| 30 options.add_option("--class_path_file", | |
| 31 help='File describing the classpath in manifest style') | |
| 32 options.add_option("--output_dir", | |
| 33 help='Where to output files') | |
| 34 options.add_option("--jar_file_name", | |
| 35 help='Name of the resulting jar file') | |
| 36 options.add_option("--jar_entry_directory", | |
| 37 help='Which directory within output to pack into the jar files') | |
| 38 options.add_option("--entry_point", | |
| 39 help='The entry point for running the program.') | |
| 40 options.add_option("--dependent_jar_files", | |
| 41 help='The jar files that we link against, space separated.') | |
| 42 return options.parse_args() | |
| 43 | |
| 44 def CompileAnalyzer(options, args): | |
| 45 # We rely on all jar files being copied to the output dir. | |
| 46 if sys.platform == 'win32': | |
| 47 class_path = options.output_dir + '*;' | |
| 48 else: | |
| 49 class_path = options.output_dir + '*' | |
| 50 javac_path = VerifyJavacGetPath() | |
| 51 cmd = [javac_path, | |
| 52 '-sourcepath', 'foobar', | |
| 53 '-source', '6', | |
| 54 '-target', '6', | |
| 55 '-implicit:none', | |
| 56 '-encoding', 'UTF-8', | |
| 57 '-d', options.output_dir, | |
| 58 '-cp', class_path, | |
| 59 ] | |
| 60 cmd.extend(args) | |
| 61 exit_code = subprocess.call(cmd) | |
| 62 if exit_code: | |
| 63 raise Exception("Executing command [%s] failed" % cmd) | |
| 64 | |
| 65 def CreateJarFile(options): | |
| 66 class_path_file_name = options.output_dir + options.class_path_file | |
| 67 jar_file_name = options.output_dir + options.jar_file_name | |
| 68 cmd = [GetJarToolPath(), 'cfem', jar_file_name, options.entry_point, | |
| 69 class_path_file_name, | |
| 70 '-C', options.output_dir, options.jar_entry_directory] | |
| 71 exit_code = subprocess.call(cmd) | |
| 72 if exit_code: | |
| 73 raise Exception("Executing command [%s] failed" % cmd) | |
| 74 | |
| 75 def CopyFiles(options): | |
| 76 # Strip " from the string | |
| 77 files = options.dependent_jar_files.replace('"', '') | |
| 78 for f in files.split(" "): | |
| 79 shutil.copy(f, options.output_dir) | |
| 80 | |
| 81 def CreateManifestFile(options): | |
| 82 class_path_file_name = options.output_dir + options.class_path_file | |
| 83 with open(class_path_file_name, 'w') as output: | |
| 84 # classpath | |
| 85 print >> output, 'Class-Path:', '.', | |
| 86 for r,d,f in os.walk(options.output_dir): | |
| 87 for file in f: | |
| 88 if file.endswith('.jar'): | |
| 89 print >> output, file, | |
| 90 print >> output | |
| 91 | |
| 92 # version | |
| 93 print >> output, 'Implementation-Version: %s' % GetDartVersion() | |
| 94 | |
| 95 def VerifyJavacGetPath(): | |
| 96 javac_path = GetJavacPath() | |
| 97 try: | |
| 98 subprocess.check_output([javac_path, "-version"]) | |
| 99 except: | |
| 100 print "You do not have JDK installed, can't build the analyzer" | |
| 101 exit(1) | |
| 102 return javac_path | |
| 103 | |
| 104 def GetJavacPath(): | |
| 105 if 'JAVA_HOME' in os.environ: | |
| 106 return join(os.environ['JAVA_HOME'], 'bin', | |
| 107 'javac' + GetExecutableExtension()) | |
| 108 else: | |
| 109 return "javac" | |
| 110 | |
| 111 def GetJarToolPath(): | |
| 112 if 'JAVA_HOME' in os.environ: | |
| 113 return join(os.environ['JAVA_HOME'], 'bin', 'jar' + GetExecutableExtension()
) | |
| 114 else: | |
| 115 return "jar" | |
| 116 | |
| 117 def GetExecutableExtension(): | |
| 118 id = platform.system() | |
| 119 if id == "Windows" or id == "Microsoft": | |
| 120 return '.exe' | |
| 121 else: | |
| 122 return '' | |
| 123 | |
| 124 def GetDartVersion(): | |
| 125 # 0.1.2.0_r13661 | |
| 126 return utils.GetVersion() | |
| 127 | |
| 128 def main(): | |
| 129 (options, args) = GetOptions() | |
| 130 # Clean out everything whenever we do a build, guarantees that we don't have | |
| 131 # any leftover jar files. | |
| 132 shutil.rmtree(options.output_dir, ignore_errors=True) | |
| 133 os.makedirs(options.output_dir) | |
| 134 | |
| 135 CopyFiles(options) | |
| 136 CreateManifestFile(options) | |
| 137 CompileAnalyzer(options, args) | |
| 138 CreateJarFile(options) | |
| 139 | |
| 140 | |
| 141 if __name__ == '__main__': | |
| 142 main() | |
| OLD | NEW |