Chromium Code Reviews

Side by Side Diff: lib/src/utils.dart

Issue 1013363002: locating runtime files automatically (fixes #96) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « lib/src/testing.dart ('k') | pubspec.yaml » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 library dev_compiler.src.utils; 6 library dev_compiler.src.utils;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 280 matching lines...)
291 return new SourceSpan(locationForOffset(unit, uri, begin), 291 return new SourceSpan(locationForOffset(unit, uri, begin),
292 locationForOffset(unit, uri, end), '$text'); 292 locationForOffset(unit, uri, end), '$text');
293 } 293 }
294 294
295 /// Computes a hash for the given contents. 295 /// Computes a hash for the given contents.
296 String computeHash(String contents) { 296 String computeHash(String contents) {
297 if (contents == null || contents == '') return null; 297 if (contents == null || contents == '') return null;
298 return CryptoUtils.bytesToHex((new MD5()..add(contents.codeUnits)).close()); 298 return CryptoUtils.bytesToHex((new MD5()..add(contents.codeUnits)).close());
299 } 299 }
300 300
301 String resourceOutputPath(Uri resourceUri) => resourceUri.path; 301 String resourceOutputPath(Uri resourceUri) {
302 if (resourceUri.scheme == 'package') return resourceUri.path;
303
304 // Only support file:/// urls for resources in the dev_compiler package
305 if (resourceUri.scheme != 'file') return null;
306 var segments = resourceUri.pathSegments;
307 var len = segments.length;
308 if (segments.length < 4 ||
309 segments[len - 2] != 'runtime' ||
310 segments[len - 3] != 'lib' ||
311 // If loaded from sources this will be exactly dev_compiler, otherwise it
312 // can be the name in the pub cache (typically dev_compiler-version).
313 !segments[len - 4].startsWith('dev_compiler')) {
314 return null;
315 }
316 return path.joinAll(['dev_compiler']..addAll(segments.skip(len - 2)));
317 }
OLDNEW
« no previous file with comments | « lib/src/testing.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine