OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import('dart:io'); | 5 #import('dart:io'); |
6 #import('dart:uri'); | 6 #import('dart:uri'); |
7 | 7 |
8 main() { | 8 main() { |
9 List<String> arguments = new Options().arguments; | 9 List<String> arguments = new Options().arguments; |
10 Uri uri = new Uri(scheme: 'file', path: '${arguments[0]}/'); | 10 Uri uri = new Uri(scheme: 'file', path: '${arguments[0]}/'); |
11 String dartVmLocation = uri.resolve(arguments[1]).path; | 11 String dartVmLocation = uri.resolve(arguments[1]).path; |
12 String productionLauncherLocation = uri.resolve(arguments[2]).path; | 12 Uri productionLauncher = uri.resolve(arguments[2]); |
13 String developerLauncherLocation = uri.resolve(arguments[3]).path; | 13 Uri developerLauncher = uri.resolve(arguments[3]); |
14 String productionLaunch = '#!$dartVmLocation\n'; | 14 String launcherScript = buildScript(uri); |
15 String developerLaunch = '#!$dartVmLocation --enable_checked_mode\n'; | 15 |
16 String launcherScript = """ | 16 writeScript(productionLauncher, |
17 ['#!$dartVmLocation\n', | |
18 launcherScript]); | |
19 writeScript(developerLauncher, | |
20 ['#!$dartVmLocation --enable_checked_mode\n', | |
21 launcherScript]); | |
22 } | |
23 | |
24 writeScript(Uri uri, List<String> chunks) { | |
25 var f = new File(uri.path); | |
26 var stream = f.openSync(FileMode.WRITE); | |
27 for (String chunk in chunks) { | |
28 stream.writeStringSync(chunk); | |
29 stream.writeStringSync(chunk); | |
ahe
2012/03/17 18:56:13
Doh! Remove second line.
ahe
2012/03/18 22:07:58
Done.
| |
30 } | |
31 stream.closeSync(); | |
32 | |
33 // TODO(ahe): Make script executable. | |
34 // TODO(ahe): Also make a .bat file for Windows. | |
35 } | |
36 | |
37 buildScript(Uri uri) { | |
38 return """ | |
17 | 39 |
18 #import('dart:io'); | 40 #import('dart:io'); |
19 | 41 |
20 #import('${uri.resolve('../../frog/file_system_vm.dart').path}', prefix: 'fs'); | 42 #import('${uri.resolve('../../utils/compiler/dart2js.dart').path}'); |
21 #import('${uri.resolve('../../frog/lang.dart').path}', prefix: 'lang'); | |
22 #import('${uri.resolve('../../frog/leg/frog_leg.dart').path}', prefix: 'leg'); | |
23 | 43 |
24 void main() { | 44 class Helper { |
25 lang.legCompile = leg.compile; | 45 void run() { |
26 try { | |
27 | |
28 List<String> argv = (new Options()).arguments; | |
29 | |
30 // Infer --out if there is none defined. | |
31 var outFileDefined = false; | |
32 for (var arg in argv) { | |
33 if (arg.startsWith('--out=')) outFileDefined = true; | |
34 } | |
35 | |
36 if (!outFileDefined) { | |
37 argv.insertRange(0, 1, '--out=' + argv[argv.length-1] + '.js'); | |
38 } | |
39 | |
40 // TODO(dgrove) we're simulating node by placing the arguments to frogc | |
41 // starting at index 2. | |
42 argv.insertRange(0, 4, null); | |
43 | |
44 argv[2] = '--leg'; | |
45 argv[3] = '--libdir=${uri.resolve('../../frog/lib').path}'; | |
46 | |
47 // TODO(dgrove) Until we have a way of getting the executable's path, we'll | |
48 // run from '.' | |
49 var homedir = (new File('.')).fullPathSync(); | |
50 | |
51 if (!lang.compile(homedir, argv, new fs.VMFileSystem())) { | |
52 print('Compilation failed'); | |
53 exit(1); | |
54 } | |
55 } catch (var exception, var trace) { | |
56 try { | 46 try { |
57 print('Internal error: \$exception'); | 47 List<String> argv = |
58 } catch (var ignored) { | 48 ['--library-root=${uri.resolve('../../frog/leg/lib').path}']; |
59 print('Internal error: error while printing exception'); | 49 argv.addAll(new Options().arguments); |
60 } | 50 compile(argv); |
61 try { | 51 } catch (var exception, var trace) { |
62 print(trace); | 52 try { |
63 } finally { | 53 print('Internal error: \$exception'); |
64 exit(253); | 54 } catch (var ignored) { |
55 print('Internal error: error while printing exception'); | |
56 } | |
57 try { | |
58 print(trace); | |
59 } finally { | |
60 exit(253); // 253 is recognized as a crash by our test scripts. | |
61 } | |
65 } | 62 } |
66 } | 63 } |
67 } | 64 } |
65 | |
66 void main() { | |
67 new Helper().run(); | |
68 } | |
68 """; | 69 """; |
69 var f = new File(productionLauncherLocation); | |
70 var stream = f.openSync(FileMode.WRITE); | |
71 stream.writeStringSync(productionLaunch); | |
72 stream.writeStringSync(launcherScript); | |
73 stream.closeSync(); | |
74 f = new File(developerLauncherLocation); | |
75 stream = f.openSync(FileMode.WRITE); | |
76 stream.writeStringSync(developerLaunch); | |
77 stream.writeStringSync(launcherScript); | |
78 stream.closeSync(); | |
79 // TODO(ahe): Make scripts executable. | |
80 // TODO(ahe): Also make .bat files for Windows. | |
81 } | 70 } |
OLD | NEW |