Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: tools/testing/frogpad/frogpad.py

Issue 9610002: remove node.js dependency by running the frog compiler in (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated test_options Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/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 """ 8 """
9 Frogpad is used to compile .dart files to javascript. 9 Frogpad is used to compile .dart files to javascript.
10 10
11 This is accomplished by first creating an html file (usually called 11 This is accomplished by first creating an html file (usually called
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 # id of script tag that holds name of the top dart file to be compiled, 123 # id of script tag that holds name of the top dart file to be compiled,
124 # (This file name passed will be passed to the frog compiler by frogpad.dart.) 124 # (This file name passed will be passed to the frog compiler by frogpad.dart.)
125 MAIN_ID = "main_id" 125 MAIN_ID = "main_id"
126 126
127 DART_LIBRARIES = { 127 DART_LIBRARIES = {
128 "core": "lib/corelib.dart", 128 "core": "lib/corelib.dart",
129 "coreimpl": "lib/corelib_impl.dart", 129 "coreimpl": "lib/corelib_impl.dart",
130 "dom": "../client/dom/frog/dom_frog.dart", 130 "dom": "../client/dom/frog/dom_frog.dart",
131 "html": "../client/html/release/html.dart", 131 "html": "../client/html/release/html.dart",
132 "htmlimpl": "../client/html/release/htmlimpl.dart", 132 "htmlimpl": "../client/html/release/htmlimpl.dart",
133 "isolate": "../lib/isolate/isolate_frog.dart",
133 "json": "../lib/json/json_frog.dart" 134 "json": "../lib/json/json_frog.dart"
134 } 135 }
135 136
136 137
137 class Pad(object): 138 class Pad(object):
138 """ 139 """
139 Accumulates all source files that are needed to compile a dart program, 140 Accumulates all source files that are needed to compile a dart program,
140 and places them in <script> tags on an html page. 141 and places them in <script> tags on an html page.
141 """ 142 """
142 143
143 def __init__(self, argv): 144 def __init__(self, argv):
144 parser = optparse.OptionParser(usage= 145 parser = optparse.OptionParser(usage=
145 "%prog [options] file_to_compile.dart" 146 "%prog [options] file_to_compile.dart"
146 ) 147 )
147 parser.add_option("-r", "--rebuild", action="store_true", 148 parser.add_option("-f", "--frogpad_js",
148 help="forces rebuild of the frogpad javascript") 149 help="location of frogpad.js file")
149 parser.add_option("-o", "--out", 150 parser.add_option("-o", "--out",
150 help="name of javascript output file") 151 help="name of javascript output file")
151 parser.add_option("-v", "--verbose", action="store_true", 152 parser.add_option("-v", "--verbose", action="store_true",
152 help="more verbose logging") 153 help="more verbose logging")
153 (options, args) = parser.parse_args(argv) 154 (options, args) = parser.parse_args(argv)
154 155
155 log_level = logging.INFO 156 log_level = logging.INFO
156 if options.verbose: 157 if options.verbose:
157 log_level = logging.DEBUG 158 log_level = logging.DEBUG
158 logging.basicConfig(level=log_level) 159 logging.basicConfig(level=log_level)
(...skipping 11 matching lines...) Expand all
170 self.dart_dir = os.path.dirname(os.path.dirname(os.path.dirname( 171 self.dart_dir = os.path.dirname(os.path.dirname(os.path.dirname(
171 self.frogpad_dir))) 172 self.frogpad_dir)))
172 173
173 # directory of frog compiler source code 174 # directory of frog compiler source code
174 self.frog_dir = os.path.join(self.dart_dir, "frog") 175 self.frog_dir = os.path.join(self.dart_dir, "frog")
175 176
176 logging.debug("dartdir_dir: '%s'" % self.dart_dir) 177 logging.debug("dartdir_dir: '%s'" % self.dart_dir)
177 logging.debug("frog_dir: '%s'" % self.frog_dir) 178 logging.debug("frog_dir: '%s'" % self.frog_dir)
178 logging.debug("frogpad_dir: '%s'" % self.frogpad_dir) 179 logging.debug("frogpad_dir: '%s'" % self.frogpad_dir)
179 180
180 # name of frogpad_js file 181 # location frogpad.js file
181 self.frogpad_js = os.path.join(self.frogpad_dir, FROGPAD_JS) 182 if not options.frogpad_js:
183 raise Exception("--frogpad_js is required")
184
185 if not os.path.exists(options.frogpad_js):
186 raise FileNotFoundException(options.frogpad_js)
187
188 self.frogpad_js = options.frogpad_js
182 189
183 if options.out: 190 if options.out:
184 # user has specified an output file 191 # user has specified an output file
185 self.js_file = os.path.abspath(options.out) 192 self.js_file = os.path.abspath(options.out)
186 else: 193 else:
187 # user didn't specify an output file, so base the name on the 194 # user didn't specify an output file, so base the name on the
188 # input file 195 # input file
189 self.js_file = self.main_file + ".frogpad.js" 196 self.js_file = self.main_file + ".frogpad.js"
190 197
191 logging.debug("js_file: '%s" % self.js_file) 198 logging.debug("js_file: '%s" % self.js_file)
192 199
193 # this is the html file that we pass to DumpRenderTree 200 # this is the html file that we pass to DumpRenderTree
194 self.html_file = self.js_file + ".frogpad.html" 201 self.html_file = self.js_file + ".frogpad.html"
195 logging.debug("html_file: '%s'" % self.html_file) 202 logging.debug("html_file: '%s'" % self.html_file)
196 203
197 # map from file name to File object (contains entries for all corelib 204 # map from file name to File object (contains entries for all corelib
198 # and all other dart files needed to compile main_file) 205 # and all other dart files needed to compile main_file)
199 self.name_to_file = {} 206 self.name_to_file = {}
200 207
201 # map from script tag id to File object 208 # map from script tag id to File object
202 self.id_to_file = {} 209 self.id_to_file = {}
203 210
204 if not os.path.exists(self.frogpad_js):
205 options.rebuild = True
206
207 if options.rebuild:
208 self.build_frogpad_js()
209
210 self.load_libraries() 211 self.load_libraries()
211 self.load_file(self.main_file) 212 self.load_file(self.main_file)
212 213
213 html = self.generate_html() 214 html = self.generate_html()
214 write_file(self.html_file, html) 215 write_file(self.html_file, html)
215 216
216 js = self.generate_js() 217 js = self.generate_js()
217 write_file(self.js_file, js) 218 write_file(self.js_file, js)
218 219
219 line_count = len(js.splitlines()) 220 line_count = len(js.splitlines())
220 logging.info("generated '%s' (%d lines)", self.js_file, line_count) 221 logging.info("generated '%s' (%d lines)", self.js_file, line_count)
221 222
222 def build_frogpad_js(self):
223 dart_vm = os.path.join(self.dart_dir, "out/Release_ia32/dart")
224 check_exists(dart_vm)
225
226 frogc_dart = os.path.join(self.frog_dir, "frogc.dart")
227 frogpad_dart = os.path.join(self.frogpad_dir, "frogpad.dart")
228 check_exists(frogc_dart)
229 check_exists(frogpad_dart)
230
231 args = []
232 args.append(dart_vm)
233
234 # command line arguments for the dart vm
235
236 # We leave out --enable_type_checks here for speed.
237 # args.append("--enable_type_checks")
238
239 args.append("--enable_asserts")
240
241 # The dart program we're going to run on the dart vm.
242 args.append(frogc_dart)
243
244 # Command line arguments for frogc.dart
245 args.append("--libdir=%s/lib" % self.frog_dir)
246 args.append("--compile-only")
247 args.append("--enable_type_checks")
248 args.append("--enable_asserts")
249 args.append("--out=%s" % self.frogpad_js)
250
251 # The dart program that we want frogc.dart to compile.
252 args.append(frogpad_dart)
253 logging.info("generating '%s'" % self.frogpad_js)
254
255 run_command(args)
256 check_exists(self.frogpad_js)
257
258 def generate_html(self): 223 def generate_html(self):
259 tags = [] 224 tags = []
260 for f in self.id_to_file.values(): 225 for f in self.id_to_file.values():
261 tags.append(self._create_tag(f.id, f.contents)) 226 tags.append(self._create_tag(f.id, f.contents))
262 tags.append(self._create_tag(MAIN_ID, self.main_file)) 227 tags.append(self._create_tag(MAIN_ID, self.main_file))
263 html = HTML.replace("{{script_tags}}", "".join(tags)) 228 html = HTML.replace("{{script_tags}}", "".join(tags))
264 html = html.replace("{{FROGPAD_JS}}", read_file(self.frogpad_js)) 229 html = html.replace("{{FROGPAD_JS}}", read_file(self.frogpad_js))
265 return html 230 return html
266 231
267 def generate_js(self): 232 def generate_js(self):
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 raise CommandFailedException(msg) 357 raise CommandFailedException(msg)
393 logging.debug("SUCCEEDED (%d bytes)" % len(stdout)) 358 logging.debug("SUCCEEDED (%d bytes)" % len(stdout))
394 return stdout 359 return stdout
395 360
396 361
397 def main(argv): 362 def main(argv):
398 Pad(argv) 363 Pad(argv)
399 364
400 if __name__ == "__main__": 365 if __name__ == "__main__":
401 sys.exit(main(sys.argv)) 366 sys.exit(main(sys.argv))
OLDNEW
« tools/testing/dart/test_suite.dart ('K') | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698