OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Legpad is used to compile .dart files to javascript, using the dart2js compiler. | 8 Legpad is used to compile .dart files to javascript, using the dart2js compiler. |
kustermann
2013/05/28 08:17:45
Kasper/ricow said this is no longer used. So we ca
ricow1
2013/05/28 08:21:39
s/file/full directory
Anton Muhin
2013/05/28 16:07:58
Ditto, separate CL.
| |
9 | 9 |
10 This is accomplished by creating an html file (usually called | 10 This is accomplished by creating an html file (usually called |
11 <something>.legpad.html) that executes the dart2js compiler when the page | 11 <something>.legpad.html) that executes the dart2js compiler when the page |
12 is loaded by a web browser (or DumpRenderTree). | 12 is loaded by a web browser (or content shell). |
13 | 13 |
14 The <something>.legpad.html file contains: | 14 The <something>.legpad.html file contains: |
15 | 15 |
16 1. all the dart files that compose a user's dart program | 16 1. all the dart files that compose a user's dart program |
17 2. all the dart files of dart:core and other standard dart libraries | 17 2. all the dart files of dart:core and other standard dart libraries |
18 (or any other symbol that can follow "dart:" in an import statement | 18 (or any other symbol that can follow "dart:" in an import statement |
19 3. legpad.dart (compiled to javascript) | 19 3. legpad.dart (compiled to javascript) |
20 | 20 |
21 The contents of each dart file is placed in a separate <script> tag. | 21 The contents of each dart file is placed in a separate <script> tag. |
22 | 22 |
23 When the html page is loaded by a browser, the leg compiler is invoked | 23 When the html page is loaded by a browser, the leg compiler is invoked |
24 and the dart program is compiled to javascript. The generated javascript is | 24 and the dart program is compiled to javascript. The generated javascript is |
25 placed in a <pre> element with id "output". | 25 placed in a <pre> element with id "output". |
26 | 26 |
27 When the html page is passed to DumpRenderTree, the dumped output will | 27 When the html page is passed to content shell, the dumped output will |
28 have the generated javascript. | 28 have the generated javascript. |
29 | 29 |
30 See 'example.sh' for an example of how to run legpad. | 30 See 'example.sh' for an example of how to run legpad. |
31 """ | 31 """ |
32 | 32 |
33 import logging | 33 import logging |
34 import optparse | 34 import optparse |
35 import os.path | 35 import os.path |
36 import platform | 36 import platform |
37 import re | 37 import re |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 if options.out: | 174 if options.out: |
175 # user has specified an output file name | 175 # user has specified an output file name |
176 self.js_file = os.path.abspath(options.out) | 176 self.js_file = os.path.abspath(options.out) |
177 else: | 177 else: |
178 # User didn't specify an output file, so use the input | 178 # User didn't specify an output file, so use the input |
179 # file name as the base of the output file name. | 179 # file name as the base of the output file name. |
180 self.js_file = self.main_file + ".legpad.js" | 180 self.js_file = self.main_file + ".legpad.js" |
181 | 181 |
182 logging.debug("js_file: '%s" % self.js_file) | 182 logging.debug("js_file: '%s" % self.js_file) |
183 | 183 |
184 # this is the html file that we pass to DumpRenderTree | 184 # this is the html file that we pass to content shell. |
185 self.html_file = self.main_file + ".legpad.html" | 185 self.html_file = self.main_file + ".legpad.html" |
186 logging.debug("html_file: '%s'" % self.html_file) | 186 logging.debug("html_file: '%s'" % self.html_file) |
187 | 187 |
188 # map from file name to File object (contains entries for all corelib | 188 # map from file name to File object (contains entries for all corelib |
189 # and all other dart files needed to compile main_file) | 189 # and all other dart files needed to compile main_file) |
190 self.name_to_file = {} | 190 self.name_to_file = {} |
191 | 191 |
192 # map from script tag id to File object | 192 # map from script tag id to File object |
193 self.id_to_file = {} | 193 self.id_to_file = {} |
194 | 194 |
(...skipping 20 matching lines...) Expand all Loading... | |
215 tags.append(self._create_tag(MAIN_ID, self.shorten(self.main_file))) | 215 tags.append(self._create_tag(MAIN_ID, self.shorten(self.main_file))) |
216 html = HTML.replace("{{script_tags}}", "".join(tags)) | 216 html = HTML.replace("{{script_tags}}", "".join(tags)) |
217 | 217 |
218 legpad_js = os.path.join(self.legpad_dir, "legpad.dart.js") | 218 legpad_js = os.path.join(self.legpad_dir, "legpad.dart.js") |
219 check_exists(legpad_js) | 219 check_exists(legpad_js) |
220 | 220 |
221 html = html.replace("{{LEGPAD_JS}}", read_file(legpad_js)) | 221 html = html.replace("{{LEGPAD_JS}}", read_file(legpad_js)) |
222 return html | 222 return html |
223 | 223 |
224 def generate_js(self): | 224 def generate_js(self): |
225 drt = os.path.join(self.dart_dir, "client/tests/drt/DumpRenderTree") | 225 drt = os.path.join(self.dart_dir, "client/tests/drt/content_shell") |
226 if platform.system() == 'Darwin': | 226 if platform.system() == 'Darwin': |
227 drt += ".app" | 227 drt = os.path.join(self.dart_dir, "client/tests/drt/Content Shell.app") |
228 elif platform.system() == 'Windows': | 228 elif platform.system() == 'Windows': |
229 raise Exception("legpad does not run on Windows") | 229 raise Exception("legpad does not run on Windows") |
230 | 230 |
231 check_exists(drt) | 231 check_exists(drt) |
232 args = [] | 232 args = [] |
233 args.append(drt) | 233 args.append(drt) |
234 args.append(self.html_file) | 234 args.append(self.html_file) |
235 | 235 |
236 stdout = run_command(args) | 236 stdout = run_command(args) |
237 match = OUTPUT_JAVASCRIPT_REGEX.match(stdout) | 237 match = OUTPUT_JAVASCRIPT_REGEX.match(stdout) |
238 if not match: | 238 if not match: |
239 raise Exception("can't find regex in DumpRenderTree output") | 239 raise Exception("can't find regex in content shell output") |
240 return match.group(1) | 240 return match.group(1) |
241 | 241 |
242 @staticmethod | 242 @staticmethod |
243 def _create_tag(id, contents): | 243 def _create_tag(id, contents): |
244 s = SCRIPT_TAG | 244 s = SCRIPT_TAG |
245 s = s.replace("{{id}}", id) | 245 s = s.replace("{{id}}", id) |
246 # TODO(mattsh) - need to html escape here | 246 # TODO(mattsh) - need to html escape here |
247 s = s.replace("{{contents}}", contents) | 247 s = s.replace("{{contents}}", contents) |
248 return s | 248 return s |
249 | 249 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 raise CommandFailedException(msg) | 358 raise CommandFailedException(msg) |
359 logging.debug("SUCCEEDED (%d bytes)" % len(stdout)) | 359 logging.debug("SUCCEEDED (%d bytes)" % len(stdout)) |
360 return stdout | 360 return stdout |
361 | 361 |
362 | 362 |
363 def main(argv): | 363 def main(argv): |
364 Pad(argv) | 364 Pad(argv) |
365 | 365 |
366 if __name__ == "__main__": | 366 if __name__ == "__main__": |
367 sys.exit(main(sys.argv)) | 367 sys.exit(main(sys.argv)) |
OLD | NEW |