Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
|
vsm
2013/02/05 20:29:24
2013 :-)
blois
2013/02/06 22:36:27
Done.
| |
| 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. | |
| 6 | |
| 7 # A script which makes it easy to execute common DOM-related tasks | |
| 8 | |
| 9 import subprocess | |
| 10 import sys | |
| 11 import re | |
| 12 import os | |
| 13 import glob | |
|
vsm
2013/02/05 20:29:24
nit: alphabetize imports
blois
2013/02/06 22:36:27
Done.
| |
| 14 | |
| 15 dart_out_dir = 'out/ReleaseIA32/' | |
|
vsm
2013/02/05 20:29:24
'out' is 'xcodebuild' on the Mac. I think most of
Emily Fortuna
2013/02/06 18:36:14
and 'out' is called 'build' on Windows. the file i
blois
2013/02/06 22:36:27
Done.
| |
| 16 dart_bin = os.path.join(dart_out_dir, 'dart') | |
|
Emily Fortuna
2013/02/06 18:36:14
same here ... on Windows it's dart.exe see the fun
blois
2013/02/06 22:36:27
Done.
| |
| 17 | |
| 18 class Processor: | |
| 19 argv = [] | |
|
Anton Muhin
2013/02/06 11:52:28
this is not necessary and does slightly different
blois
2013/02/06 22:36:27
Done.
| |
| 20 | |
| 21 def process(self, argv): | |
|
vsm
2013/02/05 20:29:24
You might consider the optparse python module for
Emily Fortuna
2013/02/06 18:36:14
+1 Then you won't need to to add the logic for hel
blois
2013/02/06 22:36:27
From what I can tell, opt parse primarily handles
Emily Fortuna
2013/02/06 22:52:39
Gotcha. Argparse is just what you want then, but i
| |
| 22 self.argv = argv | |
| 23 | |
| 24 if not argv: | |
| 25 self.help() | |
| 26 | |
| 27 while (len(argv) > 0): | |
| 28 init_dir() | |
| 29 command = argv.pop(0) | |
| 30 | |
| 31 if not hasattr(self, command): | |
|
Anton Muhin
2013/02/06 11:52:28
I'd rather have an explicit map 'command name' : f
blois
2013/02/06 22:36:27
Done.
| |
| 32 self.help() | |
| 33 return | |
| 34 getattr(self, command)() | |
| 35 | |
| 36 def help(self): | |
| 37 print('Commands: ') | |
| 38 privates = ['argv', 'process'] | |
| 39 for attr in dir(self): | |
| 40 if not attr in privates and not attr.startswith('__'): | |
|
Anton Muhin
2013/02/06 11:52:28
map will help here too
blois
2013/02/06 22:36:27
Done.
| |
| 41 print('\t%s' % attr) | |
| 42 | |
| 43 def analyze(self): | |
| 44 ''' Runs the dart analyzer. ''' | |
| 45 call([ | |
| 46 './out/ReleaseIA32/dart-sdk/bin/dart_analyzer', | |
| 47 './tests/html/element_test.dart', | |
| 48 '--dart-sdk', 'sdk/', | |
| 49 '--show-sdk-warnings', | |
| 50 ]) | |
| 51 | |
| 52 def build(self): | |
| 53 ''' Builds the SDK ''' | |
| 54 call([ | |
| 55 './tools/build.py', | |
| 56 '--mode=release', | |
| 57 '--arch=ia32', | |
| 58 ]) | |
| 59 | |
| 60 def gen(self): | |
| 61 os.chdir('tools/dom/scripts/') | |
| 62 call([ | |
| 63 './go.sh', | |
| 64 ]) | |
| 65 | |
| 66 def size_check(self): | |
| 67 ''' Displays the dart2js size of swarm. ''' | |
| 68 dartfile = 'samples/swarm/swarm.dart' | |
| 69 dartfile = os.path.abspath(dartfile) | |
| 70 outfile = dartfile + '.js' | |
| 71 | |
| 72 dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js') | |
| 73 | |
| 74 call([ | |
| 75 dart2js_path, | |
| 76 dartfile, | |
| 77 '--library-root=sdk/', | |
| 78 '-o%s' % outfile | |
| 79 ]) | |
| 80 subprocess.call([ | |
| 81 'du', | |
| 82 '-kh', | |
| 83 '--apparent-size', | |
| 84 outfile, | |
| 85 ]) | |
| 86 | |
| 87 os.remove(outfile) | |
| 88 os.remove(outfile + '.deps') | |
| 89 os.remove(outfile + '.map') | |
| 90 | |
| 91 def test_ff(self): | |
| 92 test_dart2js('ff', self.argv) | |
| 93 | |
| 94 def test_drt(self): | |
| 95 test_dart2js('drt', self.argv) | |
| 96 | |
| 97 def test_chrome(self): | |
| 98 test_dart2js('chrome', self.argv) | |
| 99 | |
| 100 | |
| 101 def call(args): | |
| 102 print (' '.join(args)) | |
| 103 subprocess.call(args) | |
| 104 | |
| 105 def init_dir(): | |
| 106 ''' Makes sure that we're always rooted in the dart root folder.''' | |
| 107 dart_dir = os.path.abspath(os.path.join( | |
| 108 os.path.dirname(os.path.realpath(__file__)), | |
| 109 os.path.pardir, os.path.pardir)) | |
| 110 os.chdir(dart_dir) | |
| 111 | |
| 112 def test_dart2js(browser, argv): | |
| 113 cmd = [ | |
| 114 './tools/test.py', | |
| 115 '-c', 'dart2js', | |
| 116 '-r', browser, | |
| 117 '--mode=release', | |
| 118 '--checked', | |
| 119 '--arch=ia32', | |
| 120 '-v', | |
| 121 ] | |
| 122 if argv: | |
| 123 cmd.append(self.argv.pop(0)) | |
| 124 else: | |
| 125 print( | |
| 126 'Test commands should be followed by tests to run. Defaulting to html') | |
| 127 cmd.append('html') | |
| 128 call(cmd) | |
| 129 | |
| 130 def main(argv): | |
| 131 argv.pop(0) | |
| 132 Processor().process(argv) | |
| 133 | |
| 134 | |
| 135 if __name__ == '__main__': | |
| 136 main(sys.argv) | |
| OLD | NEW |