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

Side by Side Diff: samples/third_party/dromaeo/generate_dart2js_tests.py

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

Powered by Google App Engine
This is Rietveld 408576698