OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:io'; | |
6 import 'dart:uri'; | |
7 | |
8 import '../../sdk/lib/_internal/compiler/implementation/util/uri_extras.dart'; | |
9 import '../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | |
10 | |
11 main() { | |
12 List<String> arguments = new Options().arguments; | |
13 Uri cwd = getCurrentDirectory(); | |
14 String productDir = appendSlash(nativeToUriPath(arguments[0])); | |
15 String dartVmPath = nativeToUriPath(arguments[1]); | |
16 String productionName = nativeToUriPath(arguments[2]); | |
17 String developerName = nativeToUriPath(arguments[3]); | |
18 String dartdocName = nativeToUriPath(arguments[4]); | |
19 String dartDir = appendSlash(nativeToUriPath(arguments[5])); | |
20 | |
21 Uri dartUri = cwd.resolve(dartDir); | |
22 Uri productUri = cwd.resolve(productDir); | |
23 | |
24 Uri dartVmUri = productUri.resolve(dartVmPath); | |
25 Uri productionUri = productUri.resolve(arguments[2]); | |
26 Uri developerUri = productUri.resolve(arguments[3]); | |
27 Uri dartdocUri = productUri.resolve(arguments[4]); | |
28 | |
29 List<String> productionScript = buildScript( | |
30 'dart2js-production', | |
31 dartUri, dartVmUri, | |
32 'sdk/lib/_internal/compiler/implementation/dart2js.dart', ''); | |
33 writeScript(productionUri, productionScript); | |
34 | |
35 List<String> developerScript = buildScript( | |
36 'dart2js-developer', | |
37 dartUri, dartVmUri, | |
38 'sdk/lib/_internal/compiler/implementation/dart2js.dart', | |
39 r' ${DART_VM_FLAGS:---enable_checked_mode}'); | |
40 writeScript(developerUri, developerScript); | |
41 | |
42 List<String> dartdocScript = buildScript( | |
43 'dartdoc', | |
44 dartUri, dartVmUri, | |
45 'sdk/lib/_internal/dartdoc/bin/dartdoc.dart', ''); | |
46 writeScript(dartdocUri, dartdocScript); | |
47 } | |
48 | |
49 writeScript(Uri uri, List<String> scripts) { | |
50 String unixScript = scripts[0]; | |
51 String batFile = scripts[1]; | |
52 var f = new File(uriPathToNative(uri.path)); | |
53 var stream = f.openSync(FileMode.WRITE); | |
54 try { | |
55 stream.writeStringSync(unixScript); | |
56 } finally { | |
57 stream.closeSync(); | |
58 } | |
59 | |
60 f = new File('${uriPathToNative(uri.path)}.bat'); | |
61 stream = f.openSync(FileMode.WRITE); | |
62 try { | |
63 stream.writeStringSync(batFile); | |
64 } finally { | |
65 stream.closeSync(); | |
66 } | |
67 | |
68 if (Platform.operatingSystem != 'windows') { | |
69 onExit(ProcessResult result) { | |
70 if (result.exitCode != 0) { | |
71 print(result.stdout); | |
72 print(result.stderr); | |
73 exit(result.exitCode); | |
74 } | |
75 } | |
76 Process.run('/bin/chmod', ['+x', uri.path]).then(onExit); | |
77 } | |
78 } | |
79 | |
80 List<String> buildScript(String name, | |
81 Uri dartUri, Uri dartVmLocation, | |
82 String entrypoint, String options) { | |
83 bool isWindows = (Platform.operatingSystem == 'windows'); | |
84 Uri uri = dartUri.resolve(entrypoint); | |
85 String path = relativize(dartVmLocation, uri, isWindows); | |
86 String pathWin = path.replaceAll("/", "\\"); | |
87 | |
88 print('dartUri = $dartUri'); | |
89 print('dartVmLocation = $dartVmLocation'); | |
90 print('${name}Uri = $uri'); | |
91 print('${name}Path = $path'); | |
92 print('${name}PathWin = $pathWin'); | |
93 | |
94 // Tell the VM to grow the heap more aggressively. This should only | |
95 // be necessary temporarily until the VM is better at detecting how | |
96 // applications use memory. | |
97 // TODO(ahe): Remove this option (http://dartbug.com/6495). | |
98 options = ' --heap_growth_rate=512$options'; | |
99 | |
100 // Tell the VM to don't bother inlining methods. So far it isn't | |
101 // paying off but the VM team is working on fixing that. | |
102 // TODO(ahe): Remove this option (http://dartbug.com/6495). | |
103 options = ' --no_use_inlining$options'; | |
104 | |
105 return [ | |
106 ''' | |
107 #!/bin/bash | |
108 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
109 # for details. All rights reserved. Use of this source code is governed by a | |
110 # BSD-style license that can be found in the LICENSE file. | |
111 | |
112 # Setting BIN_DIR this way is ugly, but is needed to handle the case where | |
113 # dart-sdk/bin has been symlinked to. On MacOS, readlink doesn't work | |
114 # with this case. | |
115 BIN_DIR="\$(cd "\${0%/*}" ; pwd -P)" | |
116 | |
117 unset COLORS | |
118 if test -t 1; then | |
119 # Stdout is a terminal. | |
120 if test 8 -le `tput colors`; then | |
121 # Stdout has at least 8 colors, so enable colors. | |
122 COLORS="--enable-diagnostic-colors" | |
123 fi | |
124 fi | |
125 | |
126 unset SNAPSHOT | |
127 if test -f "\$BIN_DIR/${path}.snapshot"; then | |
128 # TODO(ahe): Remove the following line when we are relatively sure it works. | |
129 echo Using snapshot "\$BIN_DIR/${path}.snapshot" 1>&2 | |
130 SNAPSHOT="--use_script_snapshot=\$BIN_DIR/${path}.snapshot" | |
131 fi | |
132 exec "\$BIN_DIR"/dart$options \$SNAPSHOT "\$BIN_DIR/$path" \$COLORS "\$@" | |
133 ''', | |
134 ''' | |
135 @echo off | |
136 REM Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
137 REM for details. All rights reserved. Use of this source code is governed by a | |
138 REM BSD-style license that can be found in the LICENSE file. | |
139 | |
140 set SCRIPTPATH=%~dp0 | |
141 | |
142 REM Does the path have a trailing slash? If so, remove it. | |
143 if %SCRIPTPATH:~-1%==\ set SCRIPTPATH=%SCRIPTPATH:~0,-1% | |
144 | |
145 set arguments=%* | |
146 set SNAPSHOT= | |
147 set SNAPSHOTNAME=%SCRIPTPATH%${pathWin}.snapshot | |
148 if exist %SNAPSHOTNAME% ( | |
149 echo Using snapshot "%SNAPSHOTNAME%" 1>&2 | |
150 set SNAPSHOT=--use_script_snapshot=%SNAPSHOTNAME% | |
151 ) | |
152 | |
153 "%SCRIPTPATH%\dart.exe"$options %SNAPSHOT% "%SCRIPTPATH%$pathWin" %arguments% | |
154 '''.replaceAll('\n', '\r\n')]; | |
155 } | |
OLD | NEW |