Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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 | |
|
Emily Fortuna
2013/02/06 22:52:40
Can you write a few brief usage examples here like
| |
| 8 | |
| 9 import os | |
| 10 import subprocess | |
| 11 import sys | |
| 12 | |
| 13 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
| 14 import utils | |
| 15 | |
| 16 dart_out_dir = utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32') | |
| 17 if utils.IsWindows(): | |
| 18 dart_bin = os.path.join(dart_out_dir, 'dart.exe') | |
| 19 else: | |
| 20 dart_bin = os.path.join(dart_out_dir, 'dart') | |
| 21 | |
| 22 def help(): | |
| 23 print('Commands: ') | |
| 24 for cmd in sorted(commands.keys()): | |
| 25 print('\t%s - %s' % (cmd, commands[cmd][1])) | |
| 26 | |
| 27 def analyze(): | |
| 28 ''' Runs the dart analyzer. ''' | |
| 29 call([ | |
| 30 os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart_analyzer'), | |
| 31 os.path.join('tests', 'html', 'element_test.dart'), | |
| 32 '--dart-sdk', 'sdk', | |
| 33 '--show-sdk-warnings', | |
| 34 ]) | |
| 35 | |
| 36 def build(): | |
| 37 ''' Builds the SDK ''' | |
| 38 call([ | |
| 39 os.path.join('tools', 'build.py'), | |
| 40 '--mode=release', | |
| 41 '--arch=ia32', | |
| 42 ]) | |
| 43 | |
| 44 def dart2js(): | |
| 45 compile_dart2js(argv.pop(0)) | |
| 46 | |
| 47 def compile_dart2js(dart_file): | |
| 48 out_file = dart_file + '.js' | |
| 49 dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js') | |
| 50 | |
| 51 call([ | |
| 52 dart2js_path, | |
| 53 dart_file, | |
| 54 '--checked', | |
| 55 '--library-root=sdk/', | |
| 56 '--disallow-unsafe-eval', | |
| 57 '-o%s' % out_file | |
| 58 ]) | |
| 59 return out_file | |
| 60 | |
| 61 def gen(): | |
| 62 os.chdir(os.path.join('tools', 'dom', 'scripts')) | |
| 63 call([ | |
| 64 'go.sh', | |
| 65 ]) | |
| 66 | |
| 67 def size_check(): | |
| 68 ''' Displays the dart2js size of swarm. ''' | |
| 69 dart_file = os.path.join('samples', 'swarm', 'swarm.dart') | |
| 70 out_file = compile_dart2js(dart_file) | |
| 71 | |
| 72 subprocess.call([ | |
| 73 'du', | |
| 74 '-kh', | |
| 75 '--apparent-size', | |
| 76 out_file, | |
| 77 ]) | |
| 78 | |
| 79 os.remove(out_file) | |
| 80 os.remove(out_file + '.deps') | |
| 81 os.remove(out_file + '.map') | |
| 82 | |
| 83 def test_ff(): | |
| 84 test_dart2js('ff', argv) | |
| 85 | |
| 86 def test_drt(): | |
| 87 test_dart2js('drt', argv) | |
| 88 | |
| 89 def test_chrome(): | |
| 90 test_dart2js('chrome', argv) | |
| 91 | |
| 92 def test_dart2js(browser, argv): | |
| 93 cmd = [ | |
| 94 os.path.join('tools', 'test.py'), | |
| 95 '-c', 'dart2js', | |
| 96 '-r', browser, | |
| 97 '--mode=release', | |
| 98 '--checked', | |
| 99 '--arch=ia32', | |
| 100 '-v', | |
| 101 ] | |
| 102 if argv: | |
| 103 cmd.append(argv.pop(0)) | |
| 104 else: | |
| 105 print( | |
| 106 'Test commands should be followed by tests to run. Defaulting to html') | |
| 107 cmd.append('html') | |
| 108 call(cmd) | |
| 109 | |
| 110 def call(args): | |
| 111 print (' '.join(args)) | |
| 112 subprocess.call(args) | |
| 113 | |
| 114 def init_dir(): | |
| 115 ''' Makes sure that we're always rooted in the dart root folder.''' | |
| 116 dart_dir = os.path.abspath(os.path.join( | |
| 117 os.path.dirname(os.path.realpath(__file__)), | |
| 118 os.path.pardir, os.path.pardir)) | |
| 119 os.chdir(dart_dir) | |
| 120 | |
| 121 commands = { | |
| 122 'analyze': [analyze, 'Run the dart analyzer'], | |
| 123 'build': [build, 'Build dart in release mode'], | |
| 124 'dart2js': [dart2js, 'Run dart2js on the .dart file specified'], | |
| 125 'gen': [gen, 'Re-generate DOM generated files (run go.sh)'], | |
| 126 'size_check': [size_check, 'Check the size of dart2js compiled Swarm'], | |
| 127 'test_chrome': [test_chrome, 'Run tests in checked mode in Chrome.\n' | |
| 128 '\t\tOptionally provide name of test to run.'], | |
| 129 'test_drt': [test_drt, 'Run tests in checked mode in DumpRenderTree.\n' | |
| 130 '\t\tOptionally provide name of test to run.'], | |
| 131 'test_ff': [test_ff, 'Run tests in checked mode in Firefox.\n' | |
| 132 '\t\tOptionally provide name of test to run.'], | |
| 133 } | |
| 134 | |
| 135 def main(argv): | |
| 136 argv.pop(0) | |
| 137 | |
| 138 if not argv: | |
| 139 help() | |
| 140 | |
| 141 while (argv): | |
| 142 init_dir() | |
| 143 command = argv.pop(0) | |
| 144 | |
| 145 if not command in commands: | |
| 146 help(); | |
| 147 return | |
| 148 commands[command][0]() | |
| 149 | |
| 150 if __name__ == '__main__': | |
| 151 main(sys.argv) | |
| OLD | NEW |