Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dom.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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
8
9import os
10import subprocess
11import sys
12from sys import argv
13
14sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
15import utils
16
17dart_out_dir = utils.GetBuildRoot(utils.GuessOS(), 'release', '64')
19 dart_bin = os.path.join(dart_out_dir, 'dart.exe')
20else:
21 dart_bin = os.path.join(dart_out_dir, 'dart')
22
23dart_dir = os.path.abspath(
24 os.path.join(
25 os.path.dirname(os.path.realpath(__file__)), os.path.pardir,
26 os.path.pardir))
27
28
29def help():
30 print('Helper script to make it easy to perform common tasks encountered '
31 'during the life of a Dart DOM developer.\n'
32 '\n'
33 'For example, to re-generate DOM classes then run a specific test:\n'
34 ' dom.py gen test_drt html/element_test\n'
35 '\n'
36 'Or re-generate DOM classes and run the Dart analyzer:\n'
37 ' dom.py gen analyze\n')
38 print('Commands: ')
39 for cmd in sorted(commands.keys()):
40 print('\t%s - %s' % (cmd, commands[cmd][1]))
41
42
43def analyze():
44 ''' Runs the dart analyzer. '''
45 return call([
46 os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart'),
47 'analyze',
48 os.path.join('tests', 'lib', 'html', 'element_test.dart'),
49 ])
50
51
52def build():
53 ''' Builds the Dart binary '''
54 return call([
55 os.path.join('tools', 'build.py'),
56 '--mode=release',
57 '--arch=ia32',
58 'runtime',
59 ])
60
61
62def dart2js():
63 compile_dart2js(argv.pop(0), True)
64
65
66def compile_dart2js(dart_file, checked):
67 out_file = dart_file + '.js'
68 dart2js_path = os.path.join(dart_out_dir, 'dart-sdk', 'bin', 'dart2js')
69 args = [dart2js_path, dart_file, '--library-root=sdk/', '-o%s' % out_file]
70 if checked:
71 args.append('--checked')
72
73 call(args)
74 return out_file
75
76
77def gen():
78 os.chdir(os.path.join('tools', 'dom', 'scripts'))
79 result = call([
80 os.path.join(os.getcwd(), 'dartdomgenerator.py'), '--rebuild',
81 '--parallel', '--systems=htmldart2js,htmldartium'
82 ])
83 os.chdir(os.path.join('..', '..', '..'))
84 return result
85
86
88 ''' Displays the dart2js size of swarm. '''
89 dart_file = os.path.join('samples', 'swarm', 'swarm.dart')
90 out_file = compile_dart2js(dart_file, False)
91
92 return call([
93 'du',
94 '-kh',
95 '--apparent-size',
96 out_file,
97 ])
98
99 os.remove(out_file)
100 os.remove(out_file + '.deps')
101 os.remove(out_file + '.map')
102
103
105 test_dart2js('ff', argv)
106
107
109 test_dart2js('drt', argv)
110
111
113 test_dart2js('chrome', argv)
114
115
116def test_dart2js(browser, argv):
117 cmd = [
118 os.path.join('tools', 'test.py'),
119 '-c',
120 'dart2js',
121 '-r',
122 browser,
123 '--mode=release',
124 '--checked',
125 '--arch=ia32',
126 '-v',
127 ]
128 if argv:
129 cmd.append(argv.pop(0))
130 else:
131 print(
132 'Test commands should be followed by tests to run. Defaulting to html'
133 )
134 cmd.append('html')
135 return call(cmd)
136
137
139 start_test_server(5400, os.path.join('out', 'ReleaseX64'))
140
141
143 start_test_server(5500, os.path.join('..', 'out', 'Release'))
144
145
146def start_test_server(port, build_directory):
147 print(
148 'Browse tests at '
149 '\033[94mhttp://localhost:%d/root_build/generated_tests/\033[0m' % port)
150 return call([
152 os.path.join('tools', 'testing', 'dart', 'http_server.dart'),
153 '--port=%d' % port,
154 '--crossOriginPort=%d' % (port + 1), '--network=0.0.0.0',
155 '--build-directory=%s' % build_directory
156 ])
157
158
159def call(args):
160 print(' '.join(args))
161 pipe = subprocess.Popen(
162 args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
163 output, error = pipe.communicate()
164 if output:
165 print(output)
166 if error:
167 print(error)
168 return pipe.returncode
169
170
171commands = {
172 'analyze': [analyze, 'Run the dart analyzer'],
173 'build': [build, 'Build dart in release mode'],
174 'dart2js': [dart2js, 'Run dart2js on the .dart file specified'],
175 'gen': [gen, 'Re-generate DOM generated files (run go.sh)'],
176 'size_check': [size_check, 'Check the size of dart2js compiled Swarm'],
177 'test_chrome': [
178 test_chrome, 'Run tests in checked mode in Chrome.\n'
179 '\t\tOptionally provide name of test to run.'
180 ],
181 # TODO(antonm): fix option name.
182 'test_drt': [
183 test_drt, 'Run tests in checked mode in content shell.\n'
184 '\t\tOptionally provide name of test to run.'
185 ],
186 'test_ff': [
187 test_ff, 'Run tests in checked mode in Firefox.\n'
188 '\t\tOptionally provide name of test to run.'
189 ],
190 'test_server': [
191 test_server, 'Starts the testing server for manually '
192 'running browser tests.'
193 ],
194 'test_server_dartium': [
195 test_server_dartium, 'Starts the testing server for '
196 'manually running browser tests from a dartium enlistment.'
197 ],
198}
199
200
201def main():
202 success = True
203 argv.pop(0)
204
205 if not argv:
206 help()
207 success = False
208
209 while (argv):
210 # Make sure that we're always rooted in the dart root folder.
211 os.chdir(dart_dir)
212 command = argv.pop(0)
213
214 if not command in commands:
215 help()
216 success = False
217 break
218 returncode = commands[command][0]()
219 success = success and not bool(returncode)
220
221 sys.exit(not success)
222
223
224if __name__ == '__main__':
225 main()
void print(void *str)
Definition bridge.cpp:126
main()
Definition dom.py:201
analyze()
Definition dom.py:43
help()
Definition dom.py:29
start_test_server(port, build_directory)
Definition dom.py:146
test_drt()
Definition dom.py:108
test_chrome()
Definition dom.py:112
gen()
Definition dom.py:77
size_check()
Definition dom.py:87
test_ff()
Definition dom.py:104
test_server_dartium()
Definition dom.py:142
test_dart2js(browser, argv)
Definition dom.py:116
build()
Definition dom.py:52
dart2js()
Definition dom.py:62
test_server()
Definition dom.py:138
compile_dart2js(dart_file, checked)
Definition dom.py:66
call(args)
Definition dom.py:159
Definition main.py:1
IsWindows()
Definition utils.py:72
CheckedInSdkExecutable()
Definition utils.py:504
GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
Definition utils.py:143
GuessOS()
Definition utils.py:21