| Index: tools/testing/frogpad/frogpad.py
|
| diff --git a/tools/testing/frogpad/frogpad.py b/tools/testing/frogpad/frogpad.py
|
| index fcd3069483e926d1bd857a11656431ef73103e08..0b5dda90006d326fce73c067ff61d37a7f7b8de6 100755
|
| --- a/tools/testing/frogpad/frogpad.py
|
| +++ b/tools/testing/frogpad/frogpad.py
|
| @@ -25,11 +25,40 @@ 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 subprocess
|
| import sys
|
|
|
| +class FileNotFoundException(Exception):
|
| + def __init__(self, file_name):
|
| + self._name = file_name
|
| +
|
| + def __str__(self):
|
| + return self._name
|
| +
|
| +
|
| +class CommandFailedException(Exception):
|
| + 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 +91,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 +129,35 @@ 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("-r", "--rebuild", action="store_true",
|
| + help="forces rebuild of frogpad_js")
|
| + (options, args) = parser.parse_args(argv)
|
| +
|
| + if len(args) < 2:
|
| + usage()
|
| +
|
| + 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 +166,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)
|
| return html
|
|
|
| @staticmethod
|
| @@ -143,9 +244,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 +261,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 +297,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
|
| + """)
|
| + sys.exit(1)
|
| +
|
| +
|
| +def main(argv):
|
| + logging.basicConfig(level=logging.INFO)
|
| + Pad(argv)
|
|
|
| if __name__ == "__main__":
|
| sys.exit(main(sys.argv))
|
| -
|
|
|