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

Side by Side Diff: pkg/analyzer/lib/src/dart/sdk/sdk.dart

Issue 2209873002: Attempt to fix failures under Windows (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/sdk/sdk_test.dart » ('j') | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.src.generated.sdk2; 5 library analyzer.src.generated.sdk2;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void set useSummary(bool use) { 109 void set useSummary(bool use) {
110 if (_analysisContext != null) { 110 if (_analysisContext != null) {
111 throw new StateError( 111 throw new StateError(
112 'The "useSummary" flag cannot be changed after context creation.'); 112 'The "useSummary" flag cannot be changed after context creation.');
113 } 113 }
114 _useSummary = use; 114 _useSummary = use;
115 } 115 }
116 116
117 @override 117 @override
118 Source fromFileUri(Uri uri) { 118 Source fromFileUri(Uri uri) {
119 File file = resourceProvider.getFile(uri.toFilePath(windows: false)); 119 bool isWindows = resourceProvider.pathContext == pathos.windows;
120 120 File file = resourceProvider.getFile(uri.toFilePath(windows: isWindows));
scheglov 2016/08/03 20:03:31 Maybe pathos.fromUri(uri) to avoid checking for Wi
Brian Wilkerson 2016/08/03 20:26:32 Done
121 String path = _getPath(file); 121 String path = _getPath(file);
122 if (path == null) { 122 if (path == null) {
123 return null; 123 return null;
124 } 124 }
125 try { 125 try {
126 return file.createSource(parseUriWithException(path)); 126 return file.createSource(parseUriWithException(path));
127 } on URISyntaxException catch (exception, stackTrace) { 127 } on URISyntaxException catch (exception, stackTrace) {
128 AnalysisEngine.instance.logger.logInformation( 128 AnalysisEngine.instance.logger.logInformation(
129 "Failed to create URI: $path", 129 "Failed to create URI: $path",
130 new CaughtException(exception, stackTrace)); 130 new CaughtException(exception, stackTrace));
(...skipping 28 matching lines...) Expand all
159 } 159 }
160 SdkLibrary library = getSdkLibrary(libraryName); 160 SdkLibrary library = getSdkLibrary(libraryName);
161 if (library == null) { 161 if (library == null) {
162 return null; 162 return null;
163 } 163 }
164 String srcPath; 164 String srcPath;
165 if (relativePath.isEmpty) { 165 if (relativePath.isEmpty) {
166 srcPath = library.path; 166 srcPath = library.path;
167 } else { 167 } else {
168 String libraryPath = library.path; 168 String libraryPath = library.path;
169 int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator ); 169 int index =
170 libraryPath.lastIndexOf(resourceProvider.pathContext.separator);
scheglov 2016/08/03 20:03:31 Maybe extract separator into a field or a getter t
Brian Wilkerson 2016/08/03 20:26:32 Done
170 if (index == -1) { 171 if (index == -1) {
171 index = libraryPath.lastIndexOf('/'); 172 index = libraryPath.lastIndexOf('/');
172 if (index == -1) { 173 if (index == -1) {
173 return null; 174 return null;
174 } 175 }
175 } 176 }
176 String prefix = libraryPath.substring(0, index + 1); 177 String prefix = libraryPath.substring(0, index + 1);
177 srcPath = '$prefix$relativePath'; 178 srcPath = '$prefix$relativePath';
178 } 179 }
179 String filePath = srcPath.replaceAll('/', resourceProvider.pathContext.separ ator); 180 String filePath =
181 srcPath.replaceAll('/', resourceProvider.pathContext.separator);
180 try { 182 try {
181 File file = resourceProvider.getFile(filePath); 183 File file = resourceProvider.getFile(filePath);
182 return file.createSource(parseUriWithException(dartUri)); 184 return file.createSource(parseUriWithException(dartUri));
183 } on URISyntaxException { 185 } on URISyntaxException {
184 return null; 186 return null;
185 } 187 }
186 } 188 }
187 189
188 @override 190 @override
189 Source mapDartUri(String dartUri) { 191 Source mapDartUri(String dartUri) {
190 Source source = _uriToSourceMap[dartUri]; 192 Source source = _uriToSourceMap[dartUri];
191 if (source == null) { 193 if (source == null) {
192 source = internalMapDartUri(dartUri); 194 source = internalMapDartUri(dartUri);
193 _uriToSourceMap[dartUri] = source; 195 _uriToSourceMap[dartUri] = source;
194 } 196 }
195 return source; 197 return source;
196 } 198 }
197 199
198 String _getPath(File file) { 200 String _getPath(File file) {
199 List<SdkLibrary> libraries = libraryMap.sdkLibraries; 201 List<SdkLibrary> libraries = libraryMap.sdkLibraries;
200 int length = libraries.length; 202 int length = libraries.length;
201 List<String> paths = new List(length); 203 List<String> paths = new List(length);
202 String filePath = getRelativePathFromFile(file); 204 String filePath = getRelativePathFromFile(file);
203 if (filePath == null) { 205 if (filePath == null) {
204 return null; 206 return null;
205 } 207 }
206 for (int i = 0; i < length; i++) { 208 for (int i = 0; i < length; i++) {
207 SdkLibrary library = libraries[i]; 209 SdkLibrary library = libraries[i];
208 String libraryPath = library.path.replaceAll('/', resourceProvider.pathCon text.separator); 210 String libraryPath =
211 library.path.replaceAll('/', resourceProvider.pathContext.separator);
209 if (filePath == libraryPath) { 212 if (filePath == libraryPath) {
210 return library.shortName; 213 return library.shortName;
211 } 214 }
212 paths[i] = libraryPath; 215 paths[i] = libraryPath;
213 } 216 }
214 for (int i = 0; i < length; i++) { 217 for (int i = 0; i < length; i++) {
215 SdkLibrary library = libraries[i]; 218 SdkLibrary library = libraries[i];
216 String libraryPath = paths[i]; 219 String libraryPath = paths[i];
217 int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator ); 220 int index =
221 libraryPath.lastIndexOf(resourceProvider.pathContext.separator);
218 if (index >= 0) { 222 if (index >= 0) {
219 String prefix = libraryPath.substring(0, index + 1); 223 String prefix = libraryPath.substring(0, index + 1);
220 if (filePath.startsWith(prefix)) { 224 if (filePath.startsWith(prefix)) {
221 String relPath = filePath 225 String relPath = filePath
222 .substring(prefix.length) 226 .substring(prefix.length)
223 .replaceAll(resourceProvider.pathContext.separator, '/'); 227 .replaceAll(resourceProvider.pathContext.separator, '/');
224 return '${library.shortName}/$relPath'; 228 return '${library.shortName}/$relPath';
225 } 229 }
226 } 230 }
227 } 231 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 277 }
274 SdkLibrary library = getSdkLibrary(libraryName); 278 SdkLibrary library = getSdkLibrary(libraryName);
275 if (library == null) { 279 if (library == null) {
276 return null; 280 return null;
277 } 281 }
278 String srcPath; 282 String srcPath;
279 if (relativePath.isEmpty) { 283 if (relativePath.isEmpty) {
280 srcPath = library.path; 284 srcPath = library.path;
281 } else { 285 } else {
282 String libraryPath = library.path; 286 String libraryPath = library.path;
283 int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator ); 287 int index =
288 libraryPath.lastIndexOf(resourceProvider.pathContext.separator);
284 if (index == -1) { 289 if (index == -1) {
285 index = libraryPath.lastIndexOf('/'); 290 index = libraryPath.lastIndexOf('/');
286 if (index == -1) { 291 if (index == -1) {
287 return null; 292 return null;
288 } 293 }
289 } 294 }
290 String prefix = libraryPath.substring(0, index + 1); 295 String prefix = libraryPath.substring(0, index + 1);
291 srcPath = '$prefix$relativePath'; 296 srcPath = '$prefix$relativePath';
292 } 297 }
293 String filePath = srcPath.replaceAll('/', resourceProvider.pathContext.separ ator); 298 String filePath =
299 srcPath.replaceAll('/', resourceProvider.pathContext.separator);
294 try { 300 try {
295 File file = resourceProvider.getFile(filePath); 301 File file = resourceProvider.getFile(filePath);
296 return file.createSource(parseUriWithException(dartUri)); 302 return file.createSource(parseUriWithException(dartUri));
297 } on URISyntaxException { 303 } on URISyntaxException {
298 return null; 304 return null;
299 } 305 }
300 } 306 }
301 307
302 /** 308 /**
303 * Install the mapping from [name] to [libDir]/[file]. 309 * Install the mapping from [name] to [libDir]/[file].
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 .getChildAssumingFile(_LIBRARIES_FILE); 515 .getChildAssumingFile(_LIBRARIES_FILE);
510 yield libraryDirectory 516 yield libraryDirectory
511 .getChildAssumingFolder(_INTERNAL_DIR) 517 .getChildAssumingFolder(_INTERNAL_DIR)
512 .getChildAssumingFile(_LIBRARIES_FILE); 518 .getChildAssumingFile(_LIBRARIES_FILE);
513 } 519 }
514 520
515 @override 521 @override
516 String getRelativePathFromFile(File file) { 522 String getRelativePathFromFile(File file) {
517 String filePath = file.path; 523 String filePath = file.path;
518 String libPath = libraryDirectory.path; 524 String libPath = libraryDirectory.path;
519 if (!filePath.startsWith("$libPath${resourceProvider.pathContext.separator}" )) { 525 if (!filePath
526 .startsWith("$libPath${resourceProvider.pathContext.separator}")) {
520 return null; 527 return null;
521 } 528 }
522 return filePath.substring(libPath.length + 1); 529 return filePath.substring(libPath.length + 1);
523 } 530 }
524 531
525 /** 532 /**
526 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. 533 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise.
527 * This method should not be used outside of `analyzer` and `analyzer_cli` 534 * This method should not be used outside of `analyzer` and `analyzer_cli`
528 * packages. 535 * packages.
529 */ 536 */
530 PackageBundle getSummarySdkBundle(bool strongMode) { 537 PackageBundle getSummarySdkBundle(bool strongMode) {
531 String rootPath = directory.path; 538 String rootPath = directory.path;
532 String name = strongMode ? 'strong.sum' : 'spec.sum'; 539 String name = strongMode ? 'strong.sum' : 'spec.sum';
533 String path = resourceProvider.pathContext.join(rootPath, 'lib', '_internal' , name); 540 String path =
541 resourceProvider.pathContext.join(rootPath, 'lib', '_internal', name);
534 try { 542 try {
535 File file = resourceProvider.getFile(path); 543 File file = resourceProvider.getFile(path);
536 if (file.exists) { 544 if (file.exists) {
537 List<int> bytes = file.readAsBytesSync(); 545 List<int> bytes = file.readAsBytesSync();
538 return new PackageBundle.fromBuffer(bytes); 546 return new PackageBundle.fromBuffer(bytes);
539 } 547 }
540 } catch (exception, stackTrace) { 548 } catch (exception, stackTrace) {
541 AnalysisEngine.instance.logger.logError( 549 AnalysisEngine.instance.logger.logError(
542 'Failed to load SDK analysis summary from $path', 550 'Failed to load SDK analysis summary from $path',
543 new CaughtException(exception, stackTrace)); 551 new CaughtException(exception, stackTrace));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 SdkLibrariesReader_LibraryBuilder libraryBuilder = 699 SdkLibrariesReader_LibraryBuilder libraryBuilder =
692 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); 700 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths);
693 // If any syntactic errors were found then don't try to visit the AST 701 // If any syntactic errors were found then don't try to visit the AST
694 // structure. 702 // structure.
695 if (!errorListener.errorReported) { 703 if (!errorListener.errorReported) {
696 unit.accept(libraryBuilder); 704 unit.accept(libraryBuilder);
697 } 705 }
698 return libraryBuilder.librariesMap; 706 return libraryBuilder.librariesMap;
699 } 707 }
700 } 708 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/sdk/sdk_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698