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

Unified Diff: tools/testing/frogpad/frogpad.py

Issue 9422027: frogpad now uses vm to bootstrap instead of node (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: small fixes Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/frogpad/frogpad.py
diff --git a/tools/testing/frogpad/frogpad.py b/tools/testing/frogpad/frogpad.py
index fcd3069483e926d1bd857a11656431ef73103e08..2a6e2626ea6a1ef7695881ccebfceee416ad7521 100755
--- a/tools/testing/frogpad/frogpad.py
+++ b/tools/testing/frogpad/frogpad.py
@@ -25,11 +25,44 @@ If using DumpRenderTree, the output javascript can be obtained by dumping
the page as text and looking for the contents of the output textarea.
"""
+import logging
Jennifer Messerly 2012/02/21 21:02:22 nice use of logging :)
mattsh 2012/02/21 21:21:39 thanks
import optparse
import os.path
import re
+import subprocess
import sys
+class Error(Exception):
Jennifer Messerly 2012/02/21 21:02:22 why not use StandardError? http://docs.python.org/
mattsh 2012/02/21 21:21:39 Done.
+ """Base class for exceptions in this module."""
+ pass
+
+class FileNotFoundException(Error):
+ def __init__(self, file_name):
+ self._name = file_name
+
+ def __str__(self):
+ return self._name
+
+
+class CommandFailedException(Error):
+ def __init__(self, message):
+ self._message = message
+
+ def GetMessage(self):
+ return self._message
+
+
+# This file is produced by compiling frogpad.dart to javascript. To do this
+# we run frogc.dart on the dart vm.
+#
+# Note, we use ".frogc.js" as the extension (instead of simply ".js"),
+# because this file is generated by frogc and not by frogpad.
+#
+# (For testing, it's useful to be able to distinguish files that are generated
+# by frogc from files that are generated by frogpad.)
+#
+FROGPAD_JS = "frogpad.dart.frogc.js"
+
# Template for the html page we're going to generate.
HTML = """<html>
<head>
@@ -62,7 +95,7 @@ HTML = """<html>
<pre id="timing"></pre>
<div class="label">Output:</div>
<pre id="output"></pre>
- <script type="text/javascript" src="frogpad.dart.js" ></script>
+ <script type="text/javascript" src={{FROGPAD_JS}} ></script>
</body>
</html>
"""
@@ -100,12 +133,36 @@ class Pad(object):
and places them in <script> tags on an html page.
"""
- def __init__(self, frog_dir, main_file):
+ def __init__(self, argv):
+ parser = optparse.OptionParser()
+ parser.add_option("-m", "--main", help="which dart file to compile")
+ parser.add_option("-r", "--rebuild", action="store_true",
+ help="forces rebuild of frogpad_js")
+ (options, args) = parser.parse_args(argv)
+
+ if len(args) < 2:
+ usage()
Jennifer Messerly 2012/02/21 21:02:22 I'd pull all of the option parsing out of Pad.__in
mattsh 2012/02/21 21:21:39 Yes, but let's do in a later CL if needed. It's s
+
+ self.main_file = os.path.abspath(args[1])
+
+ # directory of this script
+ self.frogpad_dir = os.path.abspath(os.path.dirname(argv[0]))
+
+ # root of dart source repo
+ self.dart_dir = os.path.dirname(os.path.dirname(os.path.dirname(
+ self.frogpad_dir)))
+
# directory of frog compiler source code
- self.frog_dir = frog_dir
+ self.frog_dir = os.path.join(self.dart_dir, "frog")
+
+ logging.debug("dartdir_dir: '%s'" % self.dart_dir)
+ logging.debug("frog_dir: '%s'" % self.frog_dir)
+ logging.debug("frogpad_dir: '%s'" % self.frogpad_dir)
+
+ # name of frogpad_js file
+ self.frogpad_js = os.path.join(self.frogpad_dir, FROGPAD_JS)
- # which .dart file to compile
- self.main_file = main_file
+ html_file = self.main_file + ".frogpad.html"
# map from file name to File object (contains entries for all corelib
# and all other dart files needed to compile main_file)
@@ -114,15 +171,64 @@ class Pad(object):
# map from script tag id to File object
self.id_to_file = {}
+ if not os.path.exists(self.frogpad_js):
+ options.rebuild = True
+
+ if options.rebuild:
+ self.build_frogpad_js()
+
self.load_libraries()
self.load_file(self.main_file)
+ html = self.generate_html()
+
+ with open(html_file, "w") as output:
+ output.write(html)
+ logging.info("generated '%s' (%d bytes)" % (html_file, len(html)))
+
+
+ def build_frogpad_js(self):
+ dart_vm = os.path.join(self.dart_dir, "out/Release_ia32/dart")
+ check_exists(dart_vm)
+
+ frogc_dart = os.path.join(self.frog_dir, "frogc.dart")
+ frogpad_dart = os.path.join(self.frogpad_dir, "frogpad.dart")
+ check_exists(frogc_dart)
+ check_exists(frogpad_dart)
+
+ args = []
+ args.append(dart_vm)
+
+ # command line arguments for the dart vm
+
+ # We leave out --enable_type_checks here for speed.
+ # args.append("--enable_type_checks")
+
+ args.append("--enable_asserts")
+
+ # The dart program we're going to run on the dart vm.
+ args.append(frogc_dart)
+
+ # Command line arguments for frogc.dart
+ args.append("--libdir=%s/lib" % self.frog_dir)
+ args.append("--compile-only")
+ args.append("--enable_type_checks")
+ args.append("--enable_asserts")
+ args.append("--out=%s" % self.frogpad_js)
+
+ # The dart program that we want frogc.dart to compile.
+ args.append(frogpad_dart)
+
+ run_command(args)
+ check_exists(self.frogpad_js)
+
def generate_html(self):
tags = []
for f in self.id_to_file.values():
tags.append(self._create_tag(f.id, f.contents))
tags.append(self._create_tag(MAIN_ID, self.main_file))
html = HTML.replace("{{script_tags}}", "".join(tags))
+ html = html.replace("{{FROGPAD_JS}}", FROGPAD_JS)
Jennifer Messerly 2012/02/21 21:02:22 Another way to do this would be to use "%(FROGPAD_
mattsh 2012/02/21 21:21:39 I think if the source template has any extra %s or
return html
@staticmethod
@@ -143,9 +249,10 @@ class Pad(object):
self.load_file(self.dart_library(name))
def load_file(self, name):
+ logging.debug("load_file " + name)
name = os.path.abspath(name)
if name in self.name_to_file:
- print "already loaded %s, skipping" % name
+ logging.debug("already loaded %s, skipping" % name)
return
f = File(self, name)
self.name_to_file[f.name] = f
@@ -159,11 +266,11 @@ class File(object):
self.pad = pad
self.name = name
self.id = self._make_id()
- if not os.path.exists(name):
- raise Exception("cannot find file '%s'" % name)
+ check_exists(name)
with open(self.name, "r") as f:
self.contents = f.read()
- print "creating File '%s' (%d lines)" % (self.name, len(self.contents))
+ logging.debug("creating File '%s' (%d lines)" %
+ (self.name, len(self.contents)))
def _make_id(self):
"""
@@ -195,24 +302,45 @@ class File(object):
self.pad.load_file(path)
-def main(argv):
- parser = optparse.OptionParser()
- parser.add_option("-o", "--out", dest="out_file")
+def check_exists(file_name):
+ if not os.path.exists(file_name):
+ raise FileNotFoundException(file_name)
- (options, args) = parser.parse_args(argv)
- main_file = os.path.abspath(args[1])
- script_dir = os.path.abspath(os.path.dirname(argv[0]))
- frog_dir = os.path.abspath(os.path.join(script_dir, "../../../frog"))
+def format_command(args):
+ return ' '.join(args)
- pad = Pad(frog_dir, main_file)
- html = pad.generate_html()
- filename = "frogpad.html"
- with open(filename, "w") as output:
- output.write(html)
- print "generated '%s' (%d bytes)" % (filename, len(html))
+def run_command(args):
+ """
+ Args:
+ command: comamnd with arguments to exec
+ """
+
+ command = format_command(args)
+ logging.info("RUNNING " + command)
+ proc = subprocess.Popen(args)
+ exit_code = proc.wait()
+
+ if exit_code:
+ msg = "FAILURE (exit_code=%d): '%s'" % (exit_code, command)
+ logging.error(msg)
+ raise CommandFailedException(msg)
+
+ logging.debug("SUCCEEDED " + command)
+
+
+def usage():
+ print("""
+ Usage:
+ frogpad.py hello.dart
+ """)
Jennifer Messerly 2012/02/21 21:02:22 Perhaps use http://docs.python.org/library/optpars
mattsh 2012/02/21 21:21:39 Yes, reasonable for a later CL.
Jennifer Messerly 2012/02/21 21:40:50 sgtm. It just occurred to me that I don't think a
+ sys.exit(1)
+
+
+def main(argv):
+ logging.basicConfig(level=logging.INFO)
+ Pad(argv)
if __name__ == "__main__":
sys.exit(main(sys.argv))
-
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698