Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: runtime/bin/builtin.dart

Issue 534273002: Remove debug logging from builtin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Default to false. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library builtin; 5 library builtin;
6 import 'dart:io'; 6 import 'dart:io';
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 // import 'root_library'; happens here from C Code 9 // import 'root_library'; happens here from C Code
10 10
11 // The root library (aka the script) is imported into this library. The 11 // The root library (aka the script) is imported into this library. The
12 // standalone embedder uses this to lookup the main entrypoint in the 12 // standalone embedder uses this to lookup the main entrypoint in the
13 // root library's namespace. 13 // root library's namespace.
14 Function _getMainClosure() => main; 14 Function _getMainClosure() => main;
15 15
16 16
17 // Corelib 'print' implementation. 17 // Corelib 'print' implementation.
18 void _print(arg) { 18 void _print(arg) {
19 _Logger._printString(arg.toString()); 19 _Logger._printString(arg.toString());
20 } 20 }
21 21
22 22
23 class _Logger { 23 class _Logger {
24 static void _printString(String s) native "Logger_PrintString"; 24 static void _printString(String s) native "Logger_PrintString";
25 } 25 }
26 26
27 27
28 _getPrintClosure() => _print; 28 _getPrintClosure() => _print;
29 29
30 30 final _logBuiltin = false;
Ivan Posva 2014/09/04 15:35:25 const?
Anders Johnsen 2014/09/05 05:36:58 Done.
31 void _logResolution(String msg) {
32 final enabled = false;
33 if (enabled) {
34 _Logger._printString(msg);
35 }
36 }
37
38 31
39 // Corelib 'Uri.base' implementation. 32 // Corelib 'Uri.base' implementation.
40 Uri _uriBase() { 33 Uri _uriBase() {
41 return new Uri.file(Directory.current.path + "/"); 34 return new Uri.file(Directory.current.path + "/");
42 } 35 }
43 36
44 37
45 _getUriBaseClosure() => _uriBase; 38 _getUriBaseClosure() => _uriBase;
46 39
47 40
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 98 }
106 return null; 99 return null;
107 } 100 }
108 101
109 102
110 void _setWorkingDirectory(cwd) { 103 void _setWorkingDirectory(cwd) {
111 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); 104 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd);
112 cwd = _sanitizeWindowsPath(cwd); 105 cwd = _sanitizeWindowsPath(cwd);
113 cwd = _enforceTrailingSlash(cwd); 106 cwd = _enforceTrailingSlash(cwd);
114 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd); 107 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd);
115 _logResolution('# Working Directory: $cwd'); 108 if (_logBuiltin) _print('# Working Directory: $cwd');
Ivan Posva 2014/09/04 15:35:25 {}?
Anders Johnsen 2014/09/05 05:36:58 Done.
116 } 109 }
117 110
118 111
119 _setPackageRoot(String packageRoot) { 112 _setPackageRoot(String packageRoot) {
120 packageRoot = _enforceTrailingSlash(packageRoot); 113 packageRoot = _enforceTrailingSlash(packageRoot);
121 if (packageRoot.startsWith('file:') || 114 if (packageRoot.startsWith('file:') ||
122 packageRoot.startsWith('http:') || 115 packageRoot.startsWith('http:') ||
123 packageRoot.startsWith('https:')) { 116 packageRoot.startsWith('https:')) {
124 _packageRoot = _workingDirectoryUri.resolve(packageRoot); 117 _packageRoot = _workingDirectoryUri.resolve(packageRoot);
125 } else { 118 } else {
126 _packageRoot = _workingDirectoryUri.resolveUri(new Uri.file(packageRoot)); 119 _packageRoot = _workingDirectoryUri.resolveUri(new Uri.file(packageRoot));
127 } 120 }
128 _logResolution('# Package root: $packageRoot -> $_packageRoot'); 121 if (_logBuiltin) _print('# Package root: $packageRoot -> $_packageRoot');
129 } 122 }
130 123
131 124
132 String _resolveScriptUri(String scriptName) { 125 String _resolveScriptUri(String scriptName) {
133 if (_workingDirectoryUri == null) { 126 if (_workingDirectoryUri == null) {
134 throw 'No current working directory set.'; 127 throw 'No current working directory set.';
135 } 128 }
136 scriptName = _sanitizeWindowsPath(scriptName); 129 scriptName = _sanitizeWindowsPath(scriptName);
137 130
138 var scriptUri = Uri.parse(scriptName); 131 var scriptUri = Uri.parse(scriptName);
139 if (scriptUri.scheme != '') { 132 if (scriptUri.scheme != '') {
140 // Script has a scheme, assume that it is fully formed. 133 // Script has a scheme, assume that it is fully formed.
141 _entryPointScript = scriptUri; 134 _entryPointScript = scriptUri;
142 } else { 135 } else {
143 // Script does not have a scheme, assume that it is a path, 136 // Script does not have a scheme, assume that it is a path,
144 // resolve it against the working directory. 137 // resolve it against the working directory.
145 _entryPointScript = _workingDirectoryUri.resolve(scriptName); 138 _entryPointScript = _workingDirectoryUri.resolve(scriptName);
146 } 139 }
147 _logResolution('# Resolved entry point to: $_entryPointScript'); 140 if (_logBuiltin) _print('# Resolved entry point to: $_entryPointScript');
148 return _entryPointScript.toString(); 141 return _entryPointScript.toString();
149 } 142 }
150 143
151 const _DART_EXT = 'dart-ext:'; 144 const _DART_EXT = 'dart-ext:';
152 145
153 String _resolveUri(String base, String userString) { 146 String _resolveUri(String base, String userString) {
154 _logResolution('# Resolving: $userString from $base'); 147 if (_logBuiltin) _print('# Resolving: $userString from $base');
155 var baseUri = Uri.parse(base); 148 var baseUri = Uri.parse(base);
156 if (userString.startsWith(_DART_EXT)) { 149 if (userString.startsWith(_DART_EXT)) {
157 var uri = userString.substring(_DART_EXT.length); 150 var uri = userString.substring(_DART_EXT.length);
158 return '$_DART_EXT${baseUri.resolve(uri)}'; 151 return '$_DART_EXT${baseUri.resolve(uri)}';
159 } else { 152 } else {
160 return baseUri.resolve(userString).toString(); 153 return baseUri.resolve(userString).toString();
161 } 154 }
162 } 155 }
163 156
164 157
165 // Returns either a file path or a URI starting with http:, as a String. 158 // Returns either a file path or a URI starting with http:, as a String.
166 String _filePathFromUri(String userUri) { 159 String _filePathFromUri(String userUri) {
167 var uri = Uri.parse(userUri); 160 var uri = Uri.parse(userUri);
168 _logResolution('# Getting file path from: $uri'); 161 if (_logBuiltin) _print('# Getting file path from: $uri');
169 162
170 var path; 163 var path;
171 switch (uri.scheme) { 164 switch (uri.scheme) {
172 case '': 165 case '':
173 case 'file': 166 case 'file':
174 return uri.toFilePath(); 167 return uri.toFilePath();
175 break; 168 break;
176 case 'package': 169 case 'package':
177 return _filePathFromPackageUri(uri); 170 return _filePathFromPackageUri(uri);
178 break; 171 break;
179 case 'http': 172 case 'http':
180 return uri.toString(); 173 return uri.toString();
181 default: 174 default:
182 // Only handling file, http, and package URIs 175 // Only handling file, http, and package URIs
183 // in standalone binary. 176 // in standalone binary.
184 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); 177 if (_logBuiltin) _print('# Unknown scheme (${uri.scheme}) in $uri.');
185 throw 'Not a known scheme: $uri'; 178 throw 'Not a known scheme: $uri';
186 } 179 }
187 } 180 }
188 181
189 182
190 String _filePathFromPackageUri(Uri uri) { 183 String _filePathFromPackageUri(Uri uri) {
191 if (!uri.host.isEmpty) { 184 if (!uri.host.isEmpty) {
192 var path = '${uri.host}${uri.path}'; 185 var path = '${uri.host}${uri.path}';
193 var right = 'package:$path'; 186 var right = 'package:$path';
194 var wrong = 'package://$path'; 187 var wrong = 'package://$path';
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void _loadScriptCallback(int tag, String uri, String libraryUri, List<int> data) 244 void _loadScriptCallback(int tag, String uri, String libraryUri, List<int> data)
252 native "Builtin_LoadScript"; 245 native "Builtin_LoadScript";
253 246
254 void _loadScript(int tag, String uri, String libraryUri, List<int> data) { 247 void _loadScript(int tag, String uri, String libraryUri, List<int> data) {
255 // TODO: Currently a compilation error while loading the script is 248 // TODO: Currently a compilation error while loading the script is
256 // fatal for the isolate. _loadScriptCallback() does not return and 249 // fatal for the isolate. _loadScriptCallback() does not return and
257 // the _numOutstandingLoadRequests counter remains out of sync. 250 // the _numOutstandingLoadRequests counter remains out of sync.
258 _loadScriptCallback(tag, uri, libraryUri, data); 251 _loadScriptCallback(tag, uri, libraryUri, data);
259 assert(_numOutstandingLoadRequests > 0); 252 assert(_numOutstandingLoadRequests > 0);
260 _numOutstandingLoadRequests--; 253 _numOutstandingLoadRequests--;
261 _logResolution("native Builtin_LoadScript($uri) completed, " 254 if (_logBuiltin) {
262 "${_numOutstandingLoadRequests} requests remaining"); 255 _print("native Builtin_LoadScript($uri) completed, "
256 "${_numOutstandingLoadRequests} requests remaining");
257 }
263 if (_numOutstandingLoadRequests == 0) { 258 if (_numOutstandingLoadRequests == 0) {
264 _signalDoneLoading(); 259 _signalDoneLoading();
265 _cleanup(); 260 _cleanup();
266 } 261 }
267 } 262 }
268 263
269 264
270 void _asyncLoadErrorCallback(uri, libraryUri, error) 265 void _asyncLoadErrorCallback(uri, libraryUri, error)
271 native "Builtin_AsyncLoadError"; 266 native "Builtin_AsyncLoadError";
272 267
273 void _asyncLoadError(uri, libraryUri, error) { 268 void _asyncLoadError(uri, libraryUri, error) {
274 assert(_numOutstandingLoadRequests > 0); 269 assert(_numOutstandingLoadRequests > 0);
275 _logResolution("_asyncLoadError($uri), error: $error"); 270 if (_logBuiltin) _print("_asyncLoadError($uri), error: $error");
276 _numOutstandingLoadRequests--; 271 _numOutstandingLoadRequests--;
277 _asyncLoadErrorCallback(uri, libraryUri, error); 272 _asyncLoadErrorCallback(uri, libraryUri, error);
278 if (_numOutstandingLoadRequests == 0) { 273 if (_numOutstandingLoadRequests == 0) {
279 _signalDoneLoading(); 274 _signalDoneLoading();
280 _cleanup(); 275 _cleanup();
281 } 276 }
282 } 277 }
283 278
284 279
285 // Asynchronously loads script data through a http or file uri. 280 // Asynchronously loads script data through a http or file uri.
286 _loadDataAsync(int tag, String uri, String libraryUri) { 281 _loadDataAsync(int tag, String uri, String libraryUri) {
287 var filePath; 282 var filePath;
288 Uri sourceUri; 283 Uri sourceUri;
289 if (tag == null) { 284 if (tag == null) {
290 uri = _resolveScriptUri(uri); 285 uri = _resolveScriptUri(uri);
291 sourceUri = Uri.parse(uri); 286 sourceUri = Uri.parse(uri);
292 filePath = _filePathFromUri(uri); 287 filePath = _filePathFromUri(uri);
293 } else { 288 } else {
294 filePath = _filePathFromUri(uri); 289 filePath = _filePathFromUri(uri);
295 sourceUri = Uri.parse(filePath); 290 sourceUri = Uri.parse(filePath);
296 } 291 }
297 _numOutstandingLoadRequests++; 292 _numOutstandingLoadRequests++;
298 _logResolution("_loadDataAsync($uri), " 293 if (_logBuiltin) {
299 "${_numOutstandingLoadRequests} requests outstanding"); 294 _print("_loadDataAsync($uri), "
295 "${_numOutstandingLoadRequests} requests outstanding");
296 }
300 if (sourceUri.scheme == 'http') { 297 if (sourceUri.scheme == 'http') {
301 _httpGet(sourceUri, libraryUri, (data) { 298 _httpGet(sourceUri, libraryUri, (data) {
302 _loadScript(tag, uri, libraryUri, data); 299 _loadScript(tag, uri, libraryUri, data);
303 }); 300 });
304 } else { 301 } else {
305 var sourceFile = new File(filePath); 302 var sourceFile = new File(filePath);
306 sourceFile.readAsBytes().then((data) { 303 sourceFile.readAsBytes().then((data) {
307 _loadScript(tag, uri, libraryUri, data); 304 _loadScript(tag, uri, libraryUri, data);
308 }, 305 },
309 onError: (e) { 306 onError: (e) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 340
344 path = _filePathFromUri(path); 341 path = _filePathFromUri(path);
345 342
346 if (Platform.isLinux || Platform.isAndroid) { 343 if (Platform.isLinux || Platform.isAndroid) {
347 filename = 'lib$name.so'; 344 filename = 'lib$name.so';
348 } else if (Platform.isMacOS) { 345 } else if (Platform.isMacOS) {
349 filename = 'lib$name.dylib'; 346 filename = 'lib$name.dylib';
350 } else if (Platform.isWindows) { 347 } else if (Platform.isWindows) {
351 filename = '$name.dll'; 348 filename = '$name.dll';
352 } else { 349 } else {
353 _logResolution( 350 if (_logBuiltin) {
354 'Native extensions not supported on ${Platform.operatingSystem}'); 351 _print('Native extensions not supported on ${Platform.operatingSystem}');
352 }
355 throw 'Native extensions not supported on ${Platform.operatingSystem}'; 353 throw 'Native extensions not supported on ${Platform.operatingSystem}';
356 } 354 }
357 355
358 return [path, filename, name]; 356 return [path, filename, name];
359 } 357 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698