OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2015, 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 """Helper for building and deploying Observatory""" | 5 """Helper for building and deploying Observatory""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import os | 8 import os |
9 import platform | 9 import platform |
10 import shutil | 10 import shutil |
(...skipping 30 matching lines...) Expand all Loading... |
41 def CreateTimestampFile(options): | 41 def CreateTimestampFile(options): |
42 if options.stamp != '': | 42 if options.stamp != '': |
43 dir_name = os.path.dirname(options.stamp) | 43 dir_name = os.path.dirname(options.stamp) |
44 if dir_name != '': | 44 if dir_name != '': |
45 if not os.path.exists(dir_name): | 45 if not os.path.exists(dir_name): |
46 os.mkdir(dir_name) | 46 os.mkdir(dir_name) |
47 open(options.stamp, 'w').close() | 47 open(options.stamp, 'w').close() |
48 | 48 |
49 def BuildArguments(): | 49 def BuildArguments(): |
50 result = argparse.ArgumentParser(usage=usage) | 50 result = argparse.ArgumentParser(usage=usage) |
51 result.add_argument("--package-root", help="package root", default=None) | |
52 result.add_argument("--dart-executable", help="dart executable", default=None) | 51 result.add_argument("--dart-executable", help="dart executable", default=None) |
53 result.add_argument("--pub-executable", help="pub executable", default=None) | 52 result.add_argument("--pub-executable", help="pub executable", default=None) |
54 result.add_argument("--directory", help="observatory root", default=None) | 53 result.add_argument("--directory", help="observatory root", default=None) |
55 result.add_argument("--command", help="[get, build, deploy]", default=None) | 54 result.add_argument("--command", help="[get, build, deploy]", default=None) |
56 result.add_argument("--silent", help="silence all output", default=None) | 55 result.add_argument("--silent", help="silence all output", default=None) |
57 result.add_argument("--sdk", help="Use prebuilt sdk", default=None) | 56 result.add_argument("--sdk", help="Use prebuilt sdk", default=None) |
58 result.add_argument("--stamp", help="Write a stamp file", default='') | 57 result.add_argument("--stamp", help="Write a stamp file", default='') |
59 return result | 58 return result |
60 | 59 |
61 def ProcessOptions(options, args): | 60 def ProcessOptions(options, args): |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), | 105 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), |
107 options.pub_snapshot, | 106 options.pub_snapshot, |
108 '--version'], | 107 '--version'], |
109 stdout=silent_sink, | 108 stdout=silent_sink, |
110 stderr=silent_sink): | 109 stderr=silent_sink): |
111 return True | 110 return True |
112 except OSError as e: | 111 except OSError as e: |
113 pass | 112 pass |
114 options.pub_snapshot = None | 113 options.pub_snapshot = None |
115 | 114 |
116 # We need a dart executable and a package root. | 115 # We need a dart executable. |
117 return (options.package_root is not None and | 116 return (options.dart_executable is not None) |
118 options.dart_executable is not None) | |
119 | 117 |
120 def ChangeDirectory(directory): | 118 def ChangeDirectory(directory): |
121 os.chdir(directory); | 119 os.chdir(directory); |
122 | 120 |
123 def DisplayBootstrapWarning(): | 121 def DisplayBootstrapWarning(): |
124 print """\ | 122 print """\ |
125 | 123 |
126 | 124 |
127 WARNING: Your system cannot run the checked-in Dart SDK. Using the | 125 WARNING: Your system cannot run the checked-in Dart SDK. Using the |
128 bootstrap Dart executable will make debug builds slow. | 126 bootstrap Dart executable will make debug builds slow. |
129 Please see the Wiki for instructions on replacing the checked-in Dart SDK. | 127 Please see the Wiki for instructions on replacing the checked-in Dart SDK. |
130 | 128 |
131 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools | 129 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools |
132 | 130 |
133 To use the dart_bootstrap binary please update the PubCommand function | 131 To use the dart_bootstrap binary please update the PubCommand function |
134 in the tools/observatory_tool.py script. | 132 in the tools/observatory_tool.py script. |
135 | 133 |
136 """ | 134 """ |
137 | 135 |
138 def PubCommand(dart_executable, | 136 def PubCommand(dart_executable, |
139 pub_executable, | 137 pub_executable, |
140 pub_snapshot, | 138 pub_snapshot, |
141 pkg_root, | |
142 command, | 139 command, |
143 silent): | 140 silent): |
144 with open(os.devnull, 'wb') as silent_sink: | 141 with open(os.devnull, 'wb') as silent_sink: |
145 if pub_executable is not None: | 142 if pub_executable is not None: |
146 executable = [pub_executable] | 143 executable = [pub_executable] |
147 elif pub_snapshot is not None: | 144 elif pub_snapshot is not None: |
148 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] | 145 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] |
149 else: | 146 else: |
150 DisplayBootstrapWarning() | 147 DisplayBootstrapWarning() |
151 executable = [dart_executable, '--package-root=' + pkg_root, PUB_PATH] | 148 executable = [dart_executable, PUB_PATH] |
152 # Prevent the bootstrap Dart executable from running in regular | 149 # Prevent the bootstrap Dart executable from running in regular |
153 # development flow. | 150 # development flow. |
154 # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. | 151 # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. |
155 # return False | 152 # return False |
156 if not silent: | 153 if not silent: |
157 print >> sys.stderr, ('Running command "%s"') % (executable + command) | 154 print >> sys.stderr, ('Running command "%s"') % (executable + command) |
158 return subprocess.call(executable + command, | 155 return subprocess.call(executable + command, |
159 stdout=silent_sink if silent else None, | 156 stdout=silent_sink if silent else None, |
160 stderr=silent_sink if silent else None) | 157 stderr=silent_sink if silent else None) |
161 | 158 |
(...skipping 15 matching lines...) Expand all Loading... |
177 cmd = options.command | 174 cmd = options.command |
178 if (cmd == 'get'): | 175 if (cmd == 'get'): |
179 # Always remove pubspec.lock before running 'pub get'. | 176 # Always remove pubspec.lock before running 'pub get'. |
180 try: | 177 try: |
181 os.remove('pubspec.lock'); | 178 os.remove('pubspec.lock'); |
182 except OSError as e: | 179 except OSError as e: |
183 pass | 180 pass |
184 return PubCommand(options.dart_executable, | 181 return PubCommand(options.dart_executable, |
185 options.pub_executable, | 182 options.pub_executable, |
186 options.pub_snapshot, | 183 options.pub_snapshot, |
187 options.package_root, | |
188 ['get', '--offline'], | 184 ['get', '--offline'], |
189 options.silent) | 185 options.silent) |
190 elif (cmd == 'build'): | 186 elif (cmd == 'build'): |
191 return PubCommand(options.dart_executable, | 187 return PubCommand(options.dart_executable, |
192 options.pub_executable, | 188 options.pub_executable, |
193 options.pub_snapshot, | 189 options.pub_snapshot, |
194 options.package_root, | |
195 ['build', | 190 ['build', |
196 '-DOBS_VER=' + utils.GetVersion(), | 191 '-DOBS_VER=' + utils.GetVersion(), |
197 '--output', args[0]], | 192 '--output', args[0]], |
198 options.silent) | 193 options.silent) |
199 elif (cmd == 'deploy'): | 194 elif (cmd == 'deploy'): |
200 Deploy('build', 'deployed') | 195 Deploy('build', 'deployed') |
201 elif (cmd == 'rewrite'): | 196 elif (cmd == 'rewrite'): |
202 RewritePubSpec(args[0], args[1], args[2], args[3]) | 197 RewritePubSpec(args[0], args[1], args[2], args[3]) |
203 else: | 198 else: |
204 print >> sys.stderr, ('ERROR: command "%s" not supported') % (cmd) | 199 print >> sys.stderr, ('ERROR: command "%s" not supported') % (cmd) |
205 return -1; | 200 return -1; |
206 | 201 |
207 def main(): | 202 def main(): |
208 # Parse the options. | 203 # Parse the options. |
209 parser = BuildArguments() | 204 parser = BuildArguments() |
210 (options, args) = parser.parse_known_args() | 205 (options, args) = parser.parse_known_args() |
211 if not ProcessOptions(options, args): | 206 if not ProcessOptions(options, args): |
212 parser.print_help() | 207 parser.print_help() |
213 return 1 | 208 return 1 |
214 # Calculate absolute paths before changing directory. | 209 # Calculate absolute paths before changing directory. |
215 if (options.package_root != None): | |
216 options.package_root = os.path.abspath(options.package_root) | |
217 if (options.dart_executable != None): | 210 if (options.dart_executable != None): |
218 options.dart_executable = os.path.abspath(options.dart_executable) | 211 options.dart_executable = os.path.abspath(options.dart_executable) |
219 if (options.pub_executable != None): | 212 if (options.pub_executable != None): |
220 options.pub_executable = os.path.abspath(options.pub_executable) | 213 options.pub_executable = os.path.abspath(options.pub_executable) |
221 if (options.pub_snapshot != None): | 214 if (options.pub_snapshot != None): |
222 options.pub_snapshot = os.path.abspath(options.pub_snapshot) | 215 options.pub_snapshot = os.path.abspath(options.pub_snapshot) |
223 if (options.stamp != ''): | 216 if (options.stamp != ''): |
224 options.stamp = os.path.abspath(options.stamp) | 217 options.stamp = os.path.abspath(options.stamp) |
225 if len(args) == 1: | 218 if len(args) == 1: |
226 args[0] = os.path.abspath(args[0]) | 219 args[0] = os.path.abspath(args[0]) |
227 # Pub must be run from the project's root directory. | 220 # Pub must be run from the project's root directory. |
228 ChangeDirectory(options.directory) | 221 ChangeDirectory(options.directory) |
229 result = ExecuteCommand(options, args) | 222 result = ExecuteCommand(options, args) |
230 if result == 0: | 223 if result == 0: |
231 CreateTimestampFile(options) | 224 CreateTimestampFile(options) |
232 return result | 225 return result |
233 | 226 |
234 | 227 |
235 if __name__ == '__main__': | 228 if __name__ == '__main__': |
236 sys.exit(main()); | 229 sys.exit(main()); |
OLD | NEW |