Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Pub-specific scheduled_test descriptors. | 5 /// Pub-specific scheduled_test descriptors. |
| 6 library descriptor.packages_file; | 6 library descriptor.packages_file; |
| 7 | 7 |
| 8 import "dart:io" show File; | 8 import "dart:io" show File; |
| 9 import "dart:async" show Future; | 9 import "dart:async" show Future; |
| 10 import "dart:convert" show UTF8; | 10 import "dart:convert" show UTF8; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 if (parent == null) parent = defaultRoot; | 37 if (parent == null) parent = defaultRoot; |
| 38 var contents = const <int>[]; | 38 var contents = const <int>[]; |
| 39 if (_dependencies != null) { | 39 if (_dependencies != null) { |
| 40 var mapping = {}; | 40 var mapping = {}; |
| 41 _dependencies.forEach((package, version) { | 41 _dependencies.forEach((package, version) { |
| 42 var packagePath; | 42 var packagePath; |
| 43 if (_semverRE.hasMatch(version)) { | 43 if (_semverRE.hasMatch(version)) { |
| 44 // If it's a semver, it's a cache reference. | 44 // If it's a semver, it's a cache reference. |
| 45 packagePath = p.join(cachePath, "$package-$version"); | 45 packagePath = p.join(cachePath, "$package-$version"); |
| 46 } else { | 46 } else { |
| 47 // Otherwise it's a path relative to the .pubspec file, | 47 // Otherwise it's a path relative to the pubspec file, |
| 48 // which is also the relative path wrt. the .packages file. | 48 // which is also relative to the .packages file. |
| 49 packagePath = p.fromUri(version); | 49 packagePath = p.fromUri(version); |
| 50 } | 50 } |
| 51 mapping[package] = p.toUri(p.join(packagePath, "lib", "")); | 51 mapping[package] = p.toUri(p.join(packagePath, "lib", "")); |
| 52 }); | 52 }); |
| 53 var buffer = new StringBuffer(); | 53 var buffer = new StringBuffer(); |
| 54 packages_file.write(buffer, mapping); | 54 packages_file.write(buffer, mapping); |
| 55 contents = UTF8.encode(buffer.toString()); | 55 contents = UTF8.encode(buffer.toString()); |
| 56 } | 56 } |
| 57 return new File(p.join(parent, name)).writeAsBytes(contents); | 57 return new File(p.join(parent, name)).writeAsBytes(contents); |
| 58 }, "creating file '$name'"); | 58 }, "creating file '$name'"); |
| 59 | 59 |
| 60 Future validate([String parent]) => | 60 Future validate([String parent]) => |
| 61 schedule(() => validateNow(parent), "validating file '$name'"); | 61 schedule(() => validateNow(parent), "validating file '$name'"); |
| 62 | 62 |
| 63 Future validateNow([String parent]) { | 63 Future validateNow([String parent]) { |
| 64 // Copied from FileDescriptor in scheduled_test. | 64 // Copied from FileDescriptor in scheduled_test. |
| 65 if (parent == null) parent = defaultRoot; | 65 if (parent == null) parent = defaultRoot; |
| 66 var fullPath = p.join(parent, name); | 66 var fullPath = p.join(parent, name); |
| 67 if (!new File(fullPath).existsSync()) { | 67 if (!new File(fullPath).existsSync()) { |
| 68 fail("File not found: '$fullPath'."); | 68 fail("File not found: '$fullPath'."); |
| 69 } | 69 } |
| 70 return new File(fullPath).readAsBytes() | 70 return new File(fullPath).readAsBytes() |
| 71 .then((bytes) => _validateNow(bytes, fullPath)); | 71 .then((bytes) => _validateNow(bytes, fullPath)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 /// A function that throws an error if [binaryContents] doesn't match the | 74 /// A function that throws an error if [binaryContents] doesn't match the |
| 75 /// expected contents of the descriptor. | 75 /// expected contents of the descriptor. |
| 76 void _validateNow(List<int> binaryContents, String fullPath) { | 76 void _validateNow(List<int> binaryContents, String fullPath) { |
| 77 var fileUri = p.toUri(fullPath); | 77 // Resolve against a dummy URL so that we can test whether the URLs in |
| 78 var map = packages_file.parse(binaryContents, fileUri); | 78 // the package file are themselves relative. We can't resolve against just |
| 79 // "." due to sdk#23809. | |
| 80 var base = "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p"; | |
|
Bob Nystrom
2015/07/09 19:42:56
Does this really need to be so long?
nweiz
2015/07/09 19:46:05
Probably not in practice, but it doesn't cost much
| |
| 81 var map = packages_file.parse(binaryContents, Uri.parse(base)); | |
| 79 | 82 |
| 80 for (var package in _dependencies.keys) { | 83 for (var package in _dependencies.keys) { |
| 81 if (!map.containsKey(package)) { | 84 if (!map.containsKey(package)) { |
| 82 fail(".packages does not contain $package entry"); | 85 fail(".packages does not contain $package entry"); |
| 83 } | 86 } |
| 84 | 87 |
| 85 var description = _dependencies[package]; | 88 var description = _dependencies[package]; |
| 86 if (_semverRE.hasMatch(description)) { | 89 if (_semverRE.hasMatch(description)) { |
| 87 if (!map[package].path.contains(description)) { | 90 if (!map[package].path.contains(description)) { |
| 88 fail(".packages of $package has incorrect version. " | 91 fail(".packages of $package has incorrect version. " |
| 89 "Expected $description, found location: ${map[package]}."); | 92 "Expected $description, found location: ${map[package]}."); |
| 90 } | 93 } |
| 91 } else { | 94 } else { |
| 92 var expected = p.normalize(p.join( | 95 var expected = p.normalize(p.join(p.fromUri(description), 'lib')); |
| 93 p.dirname(fullPath), p.fromUri(description), 'lib')); | 96 var actual = p.normalize(p.fromUri( |
| 94 expected = new File(expected).resolveSymbolicLinksSync(); | 97 p.url.relative(map[package].toString(), from: p.dirname(base)))); |
| 95 var actual = new File(p.normalize(p.absolute(p.fromUri(map[package])))) | |
| 96 .resolveSymbolicLinksSync(); | |
| 97 | 98 |
| 98 if (expected != actual) { | 99 if (expected != actual) { |
| 99 fail("Relative path: Expected $description, found ${map[package]}"); | 100 fail("Relative path: Expected $expected, found $actual"); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 104 if (map.length != _dependencies.length) { | 105 if (map.length != _dependencies.length) { |
| 105 for (var key in map.keys) { | 106 for (var key in map.keys) { |
| 106 if (!_dependencies.containsKey(key)) { | 107 if (!_dependencies.containsKey(key)) { |
| 107 fail(".packages file contains unexpected entry: $key"); | 108 fail(".packages file contains unexpected entry: $key"); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 String describe() => name; | 114 String describe() => name; |
| 114 } | 115 } |
| OLD | NEW |