OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 4 # BSD-style license that can be found in the LICENSE file. |
5 # | 5 # |
6 # Script to compile the analyzer. | 6 # Script to compile the analyzer. |
7 # | 7 # |
8 # Usage: compile_analyzer.py OPTIONS files | 8 # Usage: compile_analyzer.py OPTIONS files |
9 # | 9 # |
10 | 10 |
| 11 import imp |
11 import optparse | 12 import optparse |
12 import os | 13 import os |
13 import platform | 14 import platform |
14 import shutil | 15 import shutil |
15 import subprocess | 16 import subprocess |
16 import sys | 17 import sys |
17 | 18 |
18 from os.path import join | 19 from os.path import join |
19 | 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 |
20 def GetOptions(): | 28 def GetOptions(): |
21 options = optparse.OptionParser(usage='usage: %prog [options] <output>') | 29 options = optparse.OptionParser(usage='usage: %prog [options] <output>') |
22 options.add_option("--class_path_file", | 30 options.add_option("--class_path_file", |
23 help='File describing the classpath in manifest style') | 31 help='File describing the classpath in manifest style') |
24 options.add_option("--output_dir", | 32 options.add_option("--output_dir", |
25 help='Where to output files') | 33 help='Where to output files') |
26 options.add_option("--jar_file_name", | 34 options.add_option("--jar_file_name", |
27 help='Name of the resulting jar file') | 35 help='Name of the resulting jar file') |
28 options.add_option("--jar_entry_directory", | 36 options.add_option("--jar_entry_directory", |
29 help='Which directory within output to pack into the jar files') | 37 help='Which directory within output to pack into the jar files') |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 # classpath | 83 # classpath |
76 print >> output, 'Class-Path:', '.', | 84 print >> output, 'Class-Path:', '.', |
77 for r,d,f in os.walk(options.output_dir): | 85 for r,d,f in os.walk(options.output_dir): |
78 for file in f: | 86 for file in f: |
79 if file.endswith('.jar'): | 87 if file.endswith('.jar'): |
80 print >> output, file, | 88 print >> output, file, |
81 print >> output | 89 print >> output |
82 | 90 |
83 # version | 91 # version |
84 print >> output, 'Implementation-Version: %s' % GetDartVersion() | 92 print >> output, 'Implementation-Version: %s' % GetDartVersion() |
85 | 93 |
86 def GetJavacPath(): | 94 def GetJavacPath(): |
87 if 'JAVA_HOME' in os.environ: | 95 if 'JAVA_HOME' in os.environ: |
88 return join(os.environ['JAVA_HOME'], 'bin', 'javac' + GetExecutableExtension
()) | 96 return join(os.environ['JAVA_HOME'], 'bin', 'javac' + GetExecutableExtension
()) |
89 else: | 97 else: |
90 return "javac" | 98 return "javac" |
91 | 99 |
92 def GetJarToolPath(): | 100 def GetJarToolPath(): |
93 if 'JAVA_HOME' in os.environ: | 101 if 'JAVA_HOME' in os.environ: |
94 return join(os.environ['JAVA_HOME'], 'bin', 'jar' + GetExecutableExtension()
) | 102 return join(os.environ['JAVA_HOME'], 'bin', 'jar' + GetExecutableExtension()
) |
95 else: | 103 else: |
96 return "jar" | 104 return "jar" |
97 | 105 |
98 def GetExecutableExtension(): | 106 def GetExecutableExtension(): |
99 id = platform.system() | 107 id = platform.system() |
100 if id == "Windows" or id == "Microsoft": | 108 if id == "Windows" or id == "Microsoft": |
101 return '.exe' | 109 return '.exe' |
102 else: | 110 else: |
103 return '' | 111 return '' |
104 | 112 |
105 def GetDartVersion(): | 113 def GetDartVersion(): |
106 # 0.1.2.0_r13661 | 114 # 0.1.2.0_r13661 |
107 return RunDart("../tools/version.dart") | 115 return utils.GetVersion() |
108 | |
109 def RunDart(scriptPath): | |
110 if sys.platform == 'darwin': | |
111 pipe = subprocess.Popen( | |
112 ['../tools/testing/bin/macos/dart', scriptPath], | |
113 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
114 elif os.name == 'posix': | |
115 pipe = subprocess.Popen( | |
116 ['../tools/testing/bin/linux/dart', scriptPath], | |
117 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
118 else: | |
119 pipe = subprocess.Popen( | |
120 ['..\\tools\\testing\\bin\\windows\\dart.exe', scriptPath], | |
121 stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
122 | |
123 output = pipe.communicate() | |
124 return output[0] | |
125 | 116 |
126 def main(): | 117 def main(): |
127 (options, args) = GetOptions() | 118 (options, args) = GetOptions() |
128 # Clean out everything whenever we do a build, guarantees that we don't have | 119 # Clean out everything whenever we do a build, guarantees that we don't have |
129 # any leftover jar files. | 120 # any leftover jar files. |
130 shutil.rmtree(options.output_dir, ignore_errors=True) | 121 shutil.rmtree(options.output_dir, ignore_errors=True) |
131 os.makedirs(options.output_dir) | 122 os.makedirs(options.output_dir) |
132 | 123 |
133 CopyFiles(options) | 124 CopyFiles(options) |
134 CreateManifestFile(options) | 125 CreateManifestFile(options) |
135 CompileAnalyzer(options, args) | 126 CompileAnalyzer(options, args) |
136 CreateJarFile(options) | 127 CreateJarFile(options) |
137 | 128 |
138 | 129 |
139 if __name__=='__main__': | 130 if __name__ == '__main__': |
140 main() | 131 main() |
OLD | NEW |