| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 # A script which makes it easy to execute common DOM-related tasks | 7 # A script which makes it easy to execute common DOM-related tasks |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import subprocess | 10 import subprocess |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ' dom.py gen test_drt html/element_test\n' | 27 ' dom.py gen test_drt html/element_test\n' |
| 28 '\n' | 28 '\n' |
| 29 'Or re-generate DOM classes and run the Dart analyzer:\n' | 29 'Or re-generate DOM classes and run the Dart analyzer:\n' |
| 30 ' dom.py gen analyze\n') | 30 ' dom.py gen analyze\n') |
| 31 print('Commands: ') | 31 print('Commands: ') |
| 32 for cmd in sorted(commands.keys()): | 32 for cmd in sorted(commands.keys()): |
| 33 print('\t%s - %s' % (cmd, commands[cmd][1])) | 33 print('\t%s - %s' % (cmd, commands[cmd][1])) |
| 34 | 34 |
| 35 def analyze(): | 35 def analyze(): |
| 36 ''' Runs the dart analyzer. ''' | 36 ''' Runs the dart analyzer. ''' |
| 37 call([ | 37 return call([ |
| 38 os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart_analyzer'), | 38 os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart_analyzer'), |
| 39 os.path.join('tests', 'html', 'element_test.dart'), | 39 os.path.join('tests', 'html', 'element_test.dart'), |
| 40 '--dart-sdk', 'sdk', | 40 '--dart-sdk', 'sdk', |
| 41 '--show-sdk-warnings', | 41 '--show-sdk-warnings', |
| 42 ]) | 42 ]) |
| 43 | 43 |
| 44 def build(): | 44 def build(): |
| 45 ''' Builds the Dart binary ''' | 45 ''' Builds the Dart binary ''' |
| 46 call([ | 46 return call([ |
| 47 os.path.join('tools', 'build.py'), | 47 os.path.join('tools', 'build.py'), |
| 48 '--mode=release', | 48 '--mode=release', |
| 49 '--arch=ia32', | 49 '--arch=ia32', |
| 50 'runtime', | 50 'runtime', |
| 51 ]) | 51 ]) |
| 52 | 52 |
| 53 def dart2js(): | 53 def dart2js(): |
| 54 compile_dart2js(argv.pop(0), True) | 54 compile_dart2js(argv.pop(0), True) |
| 55 | 55 |
| 56 def dartc(): | 56 def dartc(): |
| 57 call([ | 57 return call([ |
| 58 os.path.join('tools', 'test.py'), | 58 os.path.join('tools', 'test.py'), |
| 59 '-m', | 59 '-m', |
| 60 'release', | 60 'release', |
| 61 '-c', | 61 '-c', |
| 62 'dartc', | 62 'dartc', |
| 63 '-r', | 63 '-r', |
| 64 'none' | 64 'none' |
| 65 ]) | 65 ]) |
| 66 | 66 |
| 67 def docs(): |
| 68 return call([ |
| 69 os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart'), |
| 70 '--package-root=%s' % os.path.join(dart_out_dir, 'packages/'), |
| 71 os.path.join('tools', 'dom', 'docs', 'bin', 'docs.dart'), |
| 72 ]) |
| 73 |
| 74 def test_docs(): |
| 75 return call([ |
| 76 os.path.join('tools', 'test.py'), |
| 77 '--mode=release', |
| 78 '--checked', |
| 79 'docs' |
| 80 ]) |
| 81 |
| 67 def compile_dart2js(dart_file, checked): | 82 def compile_dart2js(dart_file, checked): |
| 68 out_file = dart_file + '.js' | 83 out_file = dart_file + '.js' |
| 69 dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js') | 84 dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js') |
| 70 args = [ | 85 args = [ |
| 71 dart2js_path, | 86 dart2js_path, |
| 72 dart_file, | 87 dart_file, |
| 73 '--library-root=sdk/', | 88 '--library-root=sdk/', |
| 74 '--disallow-unsafe-eval', | 89 '--disallow-unsafe-eval', |
| 75 '-o%s' % out_file | 90 '-o%s' % out_file |
| 76 ] | 91 ] |
| 77 if checked: | 92 if checked: |
| 78 args.append('--checked') | 93 args.append('--checked') |
| 79 | 94 |
| 80 call(args) | 95 call(args) |
| 81 return out_file | 96 return out_file |
| 82 | 97 |
| 83 def gen(): | 98 def gen(): |
| 84 os.chdir(os.path.join('tools', 'dom', 'scripts')) | 99 os.chdir(os.path.join('tools', 'dom', 'scripts')) |
| 85 call([ | 100 return call(os.path.join(os.getcwd(), 'go.sh')) |
| 86 'go.sh', | |
| 87 ]) | |
| 88 | 101 |
| 89 def http_server(): | 102 def http_server(): |
| 90 print('Browse tests at ' | 103 print('Browse tests at ' |
| 91 '\033[94mhttp://localhost:5400/root_build/generated_tests/\033[0m') | 104 '\033[94mhttp://localhost:5400/root_build/generated_tests/\033[0m') |
| 92 call([ | 105 return call([ |
| 93 utils.DartBinary(), | 106 utils.DartBinary(), |
| 94 os.path.join('tools', 'testing', 'dart', 'http_server.dart'), | 107 os.path.join('tools', 'testing', 'dart', 'http_server.dart'), |
| 95 '--port=5400', | 108 '--port=5400', |
| 96 '--crossOriginPort=5401', | 109 '--crossOriginPort=5401', |
| 97 '--network=0.0.0.0', | 110 '--network=0.0.0.0', |
| 98 '--build-directory=%s' % os.path.join('out', 'ReleaseIA32') | 111 '--build-directory=%s' % os.path.join('out', 'ReleaseIA32') |
| 99 ]) | 112 ]) |
| 100 | 113 |
| 101 def size_check(): | 114 def size_check(): |
| 102 ''' Displays the dart2js size of swarm. ''' | 115 ''' Displays the dart2js size of swarm. ''' |
| 103 dart_file = os.path.join('samples', 'swarm', 'swarm.dart') | 116 dart_file = os.path.join('samples', 'swarm', 'swarm.dart') |
| 104 out_file = compile_dart2js(dart_file, False) | 117 out_file = compile_dart2js(dart_file, False) |
| 105 | 118 |
| 106 subprocess.call([ | 119 return call([ |
| 107 'du', | 120 'du', |
| 108 '-kh', | 121 '-kh', |
| 109 '--apparent-size', | 122 '--apparent-size', |
| 110 out_file, | 123 out_file, |
| 111 ]) | 124 ]) |
| 112 | 125 |
| 113 os.remove(out_file) | 126 os.remove(out_file) |
| 114 os.remove(out_file + '.deps') | 127 os.remove(out_file + '.deps') |
| 115 os.remove(out_file + '.map') | 128 os.remove(out_file + '.map') |
| 116 | 129 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 '--checked', | 145 '--checked', |
| 133 '--arch=ia32', | 146 '--arch=ia32', |
| 134 '-v', | 147 '-v', |
| 135 ] | 148 ] |
| 136 if argv: | 149 if argv: |
| 137 cmd.append(argv.pop(0)) | 150 cmd.append(argv.pop(0)) |
| 138 else: | 151 else: |
| 139 print( | 152 print( |
| 140 'Test commands should be followed by tests to run. Defaulting to html') | 153 'Test commands should be followed by tests to run. Defaulting to html') |
| 141 cmd.append('html') | 154 cmd.append('html') |
| 142 call(cmd) | 155 return call(cmd) |
| 143 | 156 |
| 144 def call(args): | 157 def call(args): |
| 145 print (' '.join(args)) | 158 print ' '.join(args) |
| 146 subprocess.call(args) | 159 return subprocess.call(args, |
| 160 stdout=subprocess.STDOUT, |
| 161 stderr=subprocess.STDERR) |
| 147 | 162 |
| 148 def init_dir(): | 163 def init_dir(): |
| 149 ''' Makes sure that we're always rooted in the dart root folder.''' | 164 ''' Makes sure that we're always rooted in the dart root folder.''' |
| 150 dart_dir = os.path.abspath(os.path.join( | 165 dart_dir = os.path.abspath(os.path.join( |
| 151 os.path.dirname(os.path.realpath(__file__)), | 166 os.path.dirname(os.path.realpath(__file__)), |
| 152 os.path.pardir, os.path.pardir)) | 167 os.path.pardir, os.path.pardir)) |
| 153 os.chdir(dart_dir) | 168 os.chdir(dart_dir) |
| 154 | 169 |
| 155 commands = { | 170 commands = { |
| 156 'analyze': [analyze, 'Run the dart analyzer'], | 171 'analyze': [analyze, 'Run the dart analyzer'], |
| 157 'build': [build, 'Build dart in release mode'], | 172 'build': [build, 'Build dart in release mode'], |
| 158 'dart2js': [dart2js, 'Run dart2js on the .dart file specified'], | 173 'dart2js': [dart2js, 'Run dart2js on the .dart file specified'], |
| 159 'dartc': [dartc, 'Runs dartc in release mode'], | 174 'dartc': [dartc, 'Runs dartc in release mode'], |
| 175 'docs': [docs, 'Generates docs.json'], |
| 160 'gen': [gen, 'Re-generate DOM generated files (run go.sh)'], | 176 'gen': [gen, 'Re-generate DOM generated files (run go.sh)'], |
| 161 'size_check': [size_check, 'Check the size of dart2js compiled Swarm'], | 177 'size_check': [size_check, 'Check the size of dart2js compiled Swarm'], |
| 178 'test_docs': [test_docs, 'Tests docs.dart'], |
| 162 'test_chrome': [test_chrome, 'Run tests in checked mode in Chrome.\n' | 179 'test_chrome': [test_chrome, 'Run tests in checked mode in Chrome.\n' |
| 163 '\t\tOptionally provide name of test to run.'], | 180 '\t\tOptionally provide name of test to run.'], |
| 164 'test_drt': [test_drt, 'Run tests in checked mode in DumpRenderTree.\n' | 181 'test_drt': [test_drt, 'Run tests in checked mode in DumpRenderTree.\n' |
| 165 '\t\tOptionally provide name of test to run.'], | 182 '\t\tOptionally provide name of test to run.'], |
| 166 'test_ff': [test_ff, 'Run tests in checked mode in Firefox.\n' | 183 'test_ff': [test_ff, 'Run tests in checked mode in Firefox.\n' |
| 167 '\t\tOptionally provide name of test to run.'], | 184 '\t\tOptionally provide name of test to run.'], |
| 168 'http_server': [http_server, 'Starts the testing server for manually ' | 185 'http_server': [http_server, 'Starts the testing server for manually ' |
| 169 'running browser tests.'], | 186 'running browser tests.'], |
| 170 } | 187 } |
| 171 | 188 |
| 172 def main(argv): | 189 def main(argv): |
| 190 success = True |
| 173 argv.pop(0) | 191 argv.pop(0) |
| 174 | 192 |
| 175 if not argv: | 193 if not argv: |
| 176 help() | 194 help() |
| 195 success = False |
| 177 | 196 |
| 178 while (argv): | 197 while (argv): |
| 179 init_dir() | 198 init_dir() |
| 180 command = argv.pop(0) | 199 command = argv.pop(0) |
| 181 | 200 |
| 182 if not command in commands: | 201 if not command in commands: |
| 183 help(); | 202 help(); |
| 184 return | 203 success = False |
| 185 commands[command][0]() | 204 break |
| 205 success = success and bool(commands[command][0]()) |
| 206 |
| 207 sys.exit(not success) |
| 186 | 208 |
| 187 if __name__ == '__main__': | 209 if __name__ == '__main__': |
| 188 main(sys.argv) | 210 main(sys.argv) |
| OLD | NEW |