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