| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 import glob | |
| 4 import os | |
| 5 import os.path | |
| 6 import platform | |
| 7 import re | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 SAMPLES_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(_
_file__)))) | |
| 12 DART_PATH = os.path.dirname(SAMPLES_PATH) | |
| 13 TOOLS_PATH = os.path.join(DART_PATH, 'tools') | |
| 14 | |
| 15 sys.path.append(TOOLS_PATH) | |
| 16 import utils | |
| 17 | |
| 18 EXECUTABLE_MAP = { | |
| 19 'frog': 'frogc', | |
| 20 'dart2js': 'dart2js' | |
| 21 } | |
| 22 | |
| 23 def Compile(source, target, compiler): | |
| 24 executable = EXECUTABLE_MAP[compiler] | |
| 25 binary = os.path.abspath(os.path.join(DART_PATH, | |
| 26 utils.GetBuildRoot(utils.GuessOS(), | |
| 27 'release', 'ia32'), | |
| 28 'dart-sdk', 'bin', executable)) | |
| 29 | |
| 30 cmd = [binary, '--out=' + target] | |
| 31 cmd.append(source) | |
| 32 print 'Executing: ' + ' '.join(cmd) | |
| 33 if platform.system() == "Windows": | |
| 34 subprocess.call(cmd, shell=True) | |
| 35 else: | |
| 36 subprocess.call(cmd) | |
| 37 | |
| 38 def HtmlConvert(infile, compiler): | |
| 39 (head, tail) = os.path.split(infile) | |
| 40 | |
| 41 if head == 'tests': | |
| 42 outdir = compiler | |
| 43 os.chdir('tests') | |
| 44 if not os.path.exists(outdir): | |
| 45 os.makedirs(outdir) | |
| 46 elif head == '': | |
| 47 outdir = '.' | |
| 48 else: | |
| 49 raise 'Illegal input: ' + infile | |
| 50 | |
| 51 pattern = r'<script type="application/dart" src="([\w-]+).dart">' | |
| 52 infile = open(tail, 'r') | |
| 53 outfilename = os.path.join(outdir, tail.replace('.html', '-js.html')) | |
| 54 outfile = open(outfilename, 'w') | |
| 55 | |
| 56 print 'Converting %s to %s' % (tail, outfilename) | |
| 57 for line in infile: | |
| 58 result = re.search(pattern, line) | |
| 59 if result: | |
| 60 testname = result.group(1) | |
| 61 dartname = testname + '.dart' | |
| 62 jsname = '%s.%s.js' % (testname, compiler) | |
| 63 outname = os.path.join(outdir, jsname) | |
| 64 Compile(dartname, outname, compiler) | |
| 65 script = '<script type="text/javascript" src="%s" defer>' % jsname | |
| 66 outfile.write(re.sub(pattern, script, line)) | |
| 67 else: | |
| 68 outfile.write(line) | |
| 69 | |
| 70 if head == 'tests': | |
| 71 os.chdir('..') | |
| 72 | |
| 73 # Compile individual html tests. | |
| 74 tests = glob.glob('tests/dom-*-html.html') | |
| 75 | |
| 76 for test in tests: | |
| 77 HtmlConvert(test, 'dart2js') | |
| 78 | |
| 79 # Compile driver to index-js.html. | |
| 80 HtmlConvert('index.html', 'dart2js') | |
| OLD | NEW |