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 #import('../../lib/compiler/implementation/util/uri_extras.dart'); |
| 9 #import('../../lib/compiler/implementation/filenames.dart'); |
| 10 |
8 main() { | 11 main() { |
9 List<String> arguments = new Options().arguments; | 12 List<String> arguments = new Options().arguments; |
10 Uri uri = new Uri(scheme: 'file', path: '${arguments[0]}/'); | 13 Uri cwd = getCurrentDirectory(); |
11 String dartVmLocation = uri.resolve(arguments[1]).path; | 14 String productDir = appendSlash(nativeToUriPath(arguments[0])); |
12 Uri productionLauncher = uri.resolve(arguments[2]); | 15 String dartVmPath = nativeToUriPath(arguments[1]); |
13 Uri developerLauncher = uri.resolve(arguments[3]); | 16 String productionName = nativeToUriPath(arguments[2]); |
14 String launcherScript = buildScript(uri); | 17 String developerName = nativeToUriPath(arguments[3]); |
| 18 String dartDir = appendSlash(nativeToUriPath(arguments[4])); |
15 | 19 |
16 writeScript(productionLauncher, | 20 Uri dartUri = cwd.resolve(dartDir); |
17 ['#!$dartVmLocation\n', | 21 Uri productUri = cwd.resolve(productDir); |
18 launcherScript]); | 22 |
19 writeScript(developerLauncher, | 23 Uri dartVmUri = productUri.resolve(dartVmPath); |
20 ['#!$dartVmLocation --enable_checked_mode\n', | 24 Uri productionUri = productUri.resolve(arguments[2]); |
21 launcherScript]); | 25 Uri developerUri = productUri.resolve(arguments[3]); |
| 26 String productionScript = buildScript(dartUri, dartVmUri, ''); |
| 27 String developerScript = buildScript(dartUri, dartVmUri, |
| 28 ' --enable_checked_mode'); |
| 29 |
| 30 writeScript(productionUri, productionScript); |
| 31 writeScript(developerUri, developerScript); |
22 } | 32 } |
23 | 33 |
24 writeScript(Uri uri, List<String> chunks) { | 34 writeScript(Uri uri, String script) { |
25 var f = new File(uri.path); | 35 var f = new File(uriPathToNative(uri.path)); |
26 var stream = f.openSync(FileMode.WRITE); | 36 var stream = f.openSync(FileMode.WRITE); |
27 for (String chunk in chunks) { | 37 try { |
28 stream.writeStringSync(chunk); | 38 stream.writeStringSync(script); |
| 39 } finally { |
| 40 stream.closeSync(); |
29 } | 41 } |
30 stream.closeSync(); | |
31 | 42 |
32 // TODO(ahe): Also make a .bat file for Windows. | 43 // TODO(ahe): Also make a .bat file for Windows. |
33 | 44 |
34 if (Platform.operatingSystem() != 'windows') { | 45 if (Platform.operatingSystem() != 'windows') { |
35 onExit(int exitCode, String stdout, String stderr) { | 46 onExit(int exitCode, String stdout, String stderr) { |
36 if (exitCode != 0) { | 47 if (exitCode != 0) { |
37 print(stdout); | 48 print(stdout); |
38 print(stderr); | 49 print(stderr); |
39 exit(exitCode); | 50 exit(exitCode); |
40 } | 51 } |
41 } | 52 } |
42 new Process.run('/bin/chmod', ['+x', uri.path], null, onExit); | 53 new Process.run('/bin/chmod', ['+x', uri.path], null, onExit); |
43 } | 54 } |
44 } | 55 } |
45 | 56 |
46 buildScript(Uri uri) { | 57 buildScript(Uri dartUri, Uri dartVmLocation, String options) { |
47 String dart2jsPath = | 58 Uri dart2jsUri = dartUri.resolve('lib/compiler/implementation/dart2js.dart'); |
48 uri.resolve('../../lib/compiler/implementation/dart2js.dart').path; | 59 String dart2jsPath = relativize(dartVmLocation, dart2jsUri); |
49 String libraryRoot = uri.resolve('../../').path; | 60 String libraryRoot = relativize(dartVmLocation, dartUri); |
| 61 libraryRoot = uriPathToNative('/../$libraryRoot'); |
| 62 |
| 63 print('dartUri = $dartUri'); |
| 64 print('dartVmLocation = $dartVmLocation'); |
| 65 print('dart2jsUri = $dart2jsUri'); |
| 66 print('dart2jsPath = $dart2jsPath'); |
| 67 print('libraryRoot = $libraryRoot'); |
| 68 |
50 return """ | 69 return """ |
| 70 #!${dartVmLocation.path}$options |
51 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 71 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
52 // for details. All rights reserved. Use of this source code is governed by a | 72 // for details. All rights reserved. Use of this source code is governed by a |
53 // BSD-style license that can be found in the LICENSE file. | 73 // BSD-style license that can be found in the LICENSE file. |
54 | 74 |
55 #import('dart:io'); | 75 #import('dart:io'); |
56 | 76 |
57 #import('$dart2jsPath'); | 77 #import('$dart2jsPath'); |
58 | 78 |
59 class Helper { | 79 void main() { |
60 void run() { | 80 try { |
| 81 String libraryRoot = @'$libraryRoot'; |
| 82 String script = new Options().script; |
| 83 List<String> argv = ['--library-root=\$script\$libraryRoot']; |
| 84 argv.addAll(new Options().arguments); |
| 85 compile(argv); |
| 86 } catch (var exception, var trace) { |
61 try { | 87 try { |
62 List<String> argv = ['--library-root=$libraryRoot']; | 88 print('Internal error: \$exception'); |
63 argv.addAll(new Options().arguments); | 89 } catch (var ignored) { |
64 compile(argv); | 90 print('Internal error: error while printing exception'); |
65 } catch (var exception, var trace) { | 91 } |
66 try { | 92 try { |
67 print('Internal error: \$exception'); | 93 print(trace); |
68 } catch (var ignored) { | 94 } finally { |
69 print('Internal error: error while printing exception'); | 95 exit(253); // 253 is recognized as a crash by our test scripts. |
70 } | |
71 try { | |
72 print(trace); | |
73 } finally { | |
74 exit(253); // 253 is recognized as a crash by our test scripts. | |
75 } | |
76 } | 96 } |
77 } | 97 } |
78 } | 98 } |
79 | |
80 void main() { | |
81 new Helper().run(); | |
82 } | |
83 """; | 99 """; |
84 } | 100 } |
OLD | NEW |