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 } |
| 30 stream.closeSync(); |
| 31 |
| 32 // TODO(ahe): Make script executable. |
| 33 // TODO(ahe): Also make a .bat file for Windows. |
| 34 } |
| 35 |
| 36 buildScript(Uri uri) { |
| 37 return """ |
17 | 38 |
18 #import('dart:io'); | 39 #import('dart:io'); |
19 | 40 |
20 #import('${uri.resolve('../../frog/file_system_vm.dart').path}', prefix: 'fs'); | 41 #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 | 42 |
24 void main() { | 43 class Helper { |
25 lang.legCompile = leg.compile; | 44 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 { | 45 try { |
57 print('Internal error: \$exception'); | 46 List<String> argv = |
58 } catch (var ignored) { | 47 ['--library-root=${uri.resolve('../../frog/leg/lib').path}']; |
59 print('Internal error: error while printing exception'); | 48 argv.addAll(new Options().arguments); |
60 } | 49 compile(argv); |
61 try { | 50 } catch (var exception, var trace) { |
62 print(trace); | 51 try { |
63 } finally { | 52 print('Internal error: \$exception'); |
64 exit(253); | 53 } catch (var ignored) { |
| 54 print('Internal error: error while printing exception'); |
| 55 } |
| 56 try { |
| 57 print(trace); |
| 58 } finally { |
| 59 exit(253); // 253 is recognized as a crash by our test scripts. |
| 60 } |
65 } | 61 } |
66 } | 62 } |
67 } | 63 } |
| 64 |
| 65 void main() { |
| 66 new Helper().run(); |
| 67 } |
68 """; | 68 """; |
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 } | 69 } |
OLD | NEW |