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 # Compile the Dart dromaeo test down to JavaScript, and also insert two scripts | |
12 # that enable us to run this test as a browser test with the Dart browser | |
13 # controller. | |
14 | |
15 SAMPLES_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(_
_file__)))) | |
16 DART_PATH = os.path.dirname(SAMPLES_PATH) | |
17 TOOLS_PATH = os.path.join(DART_PATH, 'tools') | |
18 | |
19 sys.path.append(TOOLS_PATH) | |
20 import utils | |
21 | |
22 def Compile(source, target, compiler): | |
23 executable = 'dart2js' | |
24 binary = os.path.abspath(os.path.join(DART_PATH, | |
25 utils.GetBuildRoot(utils.GuessOS(), | |
26 'release', 'ia32'), | |
27 'dart-sdk', 'bin', executable)) | |
28 | |
29 cmd = [binary, '--out=' + target] | |
30 cmd.append(source) | |
31 print 'Executing: ' + ' '.join(cmd) | |
32 if platform.system() == "Windows": | |
33 subprocess.call(cmd, shell=True) | |
34 else: | |
35 subprocess.call(cmd) | |
36 | |
37 def HtmlConvert(infile, compiler): | |
38 (head, tail) = os.path.split(infile) | |
39 | |
40 if head == 'tests': | |
41 outdir = compiler | |
42 os.chdir('tests') | |
43 if not os.path.exists(outdir): | |
44 os.makedirs(outdir) | |
45 elif head == '': | |
46 outdir = '.' | |
47 else: | |
48 raise 'Illegal input: ' + infile | |
49 | |
50 pattern = r'<script type="application/dart" src="([\w-]+).dart">' | |
51 infile = open(tail, 'r') | |
52 outfilename = os.path.join(outdir, tail.replace('.html', '-js.html')) | |
53 outfile = open(outfilename, 'w') | |
54 | |
55 print 'Converting %s to %s' % (tail, outfilename) | |
56 for line in infile: | |
57 result = re.search(pattern, line) | |
58 if result: | |
59 testname = result.group(1) | |
60 dartname = testname + '.dart' | |
61 jsname = '%s.%s.js' % (testname, compiler) | |
62 outname = os.path.join(outdir, jsname) | |
63 Compile(dartname, outname, compiler) | |
64 script = '<script type="text/javascript" src="%s" defer>' % jsname | |
65 outfile.write(re.sub(pattern, script, line)) | |
66 else: | |
67 outfile.write(line) | |
68 | |
69 if head == 'tests': | |
70 os.chdir('..') | |
71 | |
72 # Compile individual html tests. | |
73 tests = glob.glob('tests/dom-*-html.html') | |
74 | |
75 for test in tests: | |
76 HtmlConvert(test, 'dart2js') | |
77 | |
78 # Update index.html to run as a performance test with the dart browser | |
79 # controller. Output the result as index-dart.html. | |
80 with open('index.html', 'r') as infile: | |
81 with open('index-dart.html', 'w') as outfile: | |
82 for line in infile: | |
83 if re.search('<script src="../../../pkg/browser/lib/dart.js">', line): | |
84 line += (' <script src="../../../tools/testing/dart/test_controller' + | |
85 '.js"></script>\n <script src="../../../tools/testing/dart/' + | |
86 'perf_test_controller.js"></script>\n') | |
87 outfile.write(line) | |
88 | |
89 # Compile driver to index-js.html. | |
90 HtmlConvert('index-dart.html', 'dart2js') | |
91 os.rename('index-dart-js.html', 'index-js.html') | |
OLD | NEW |