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

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: fixed arg named 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
« tools/testing/frogpad/command.py ('K') | « tools/testing/frogpad/command.py ('k') | 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..51c0df578562b52553cbfb0ecf2a88f7f7cb6328 100755
--- a/tools/testing/frogpad/frogpad.py
+++ b/tools/testing/frogpad/frogpad.py
@@ -25,11 +25,36 @@ 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
import optparse
import os.path
import re
import sys
+import command
+
+class Error(Exception):
+ """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
+
+# 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 +87,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 +125,30 @@ 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)
+
+ # directory of this script
+ self.frogpad_dir = os.path.abspath(os.path.dirname(argv[0]))
+
# directory of frog compiler source code
- self.frog_dir = frog_dir
+ self.frog_dir = os.path.abspath(os.path.join(self.frogpad_dir, "../../../frog"))
Emily Fortuna 2012/02/21 19:05:57 line break needed, > 80 char Also the combination
mattsh 2012/02/21 20:13:28 Good point. Switches to use dirname now.
+
+ # root of dart source repo
+ self.dart_dir = os.path.abspath(os.path.join(self.frog_dir, ".."))
Emily Fortuna 2012/02/21 19:05:57 Perhaps obtain location of the root of the dart so
mattsh 2012/02/21 20:13:28 Done.
- # which .dart file to compile
- self.main_file = main_file
+ # name of frogpad_js file
+ self.frogpad_js = os.path.join(self.frogpad_dir, FROGPAD_JS)
+
+ if not options.main:
+ usage()
+ self.main_file = os.path.abspath(options.main)
+
+ 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,8 +157,52 @@ 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)
+ self.load_file(options.main)
+
+ 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)
+
+ # command line arguments for the dart vm
+ args = []
+ args.append(command.Arg("enable_type_checks", None, False))
+ args.append(command.Arg("enable_asserts", None, False))
+
+ # the dart program we're going to run on the dart vm
Emily Fortuna 2012/02/21 19:05:57 Capital letter for first word, here, and elsewhere
mattsh 2012/02/21 20:13:28 Done.
+ args.append(command.Arg(frogc_dart, None, True))
+
+ # command line arguments for frogc.dart
+ args.append(command.Arg("libdir", "%s/lib" % self.frog_dir, False))
Emily Fortuna 2012/02/21 19:05:57 is creating this command object really gain us any
mattsh 2012/02/21 20:13:28 Good suggestion. command.Arg removed now.
+ args.append(command.Arg("compile-only", None, False))
+ args.append(command.Arg("enable_type_checks", None, False))
+ args.append(command.Arg("enable_asserts", None, False))
+ args.append(command.Arg("out", self.frogpad_js, False))
+
+ # the dart program that we want frogc.dart to compile
+ args.append(command.Arg(frogpad_dart, None, True))
+
+ # Now run the dart vm.
+ command.RunCommand(dart_vm, args)
+ check_exists(self.frogpad_js)
def generate_html(self):
tags = []
@@ -123,6 +210,7 @@ class Pad(object):
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)
return html
@staticmethod
@@ -145,7 +233,7 @@ class Pad(object):
def load_file(self, 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 +247,10 @@ 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)))
Emily Fortuna 2012/02/21 19:05:57 80 char
mattsh 2012/02/21 20:13:28 Done.
def _make_id(self):
"""
@@ -195,23 +282,21 @@ class File(object):
self.pad.load_file(path)
-def main(argv):
- parser = optparse.OptionParser()
- parser.add_option("-o", "--out", dest="out_file")
-
- (options, args) = parser.parse_args(argv)
- main_file = os.path.abspath(args[1])
+def usage():
+ print("""
+ Usage:
+ frogpad.py --main=hello.dart
Emily Fortuna 2012/02/21 19:05:57 Can we make hello.dart a required positional argum
mattsh 2012/02/21 20:13:28 Done.
+ """)
+ sys.exit(1)
- script_dir = os.path.abspath(os.path.dirname(argv[0]))
- frog_dir = os.path.abspath(os.path.join(script_dir, "../../../frog"))
+def check_exists(file_name):
+ if not os.path.exists(file_name):
+ raise FileNotFoundException(file_name)
- 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 main(argv):
+ logging.basicConfig(level=logging.INFO)
+ Pad(argv)
if __name__ == "__main__":
sys.exit(main(sys.argv))
« tools/testing/frogpad/command.py ('K') | « tools/testing/frogpad/command.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698