Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:front_end/compiler_options.dart'; | 8 import 'package:front_end/compiler_options.dart'; |
| 9 import 'package:front_end/dependency_grapher.dart'; | 9 import 'package:front_end/dependency_grapher.dart'; |
| 10 import 'package:path/path.dart' as pathos; | 10 import 'package:path/path.dart' as pathos; |
| 11 | 11 |
| 12 main() async { | 12 main() async { |
| 13 exit(await new _SubpackageRelationshipsTest().run()); | 13 exit(await new _SubpackageRelationshipsTest().run()); |
| 14 } | 14 } |
| 15 | 15 |
| 16 /// List of packages that front_end is allowed to directly depend on. | |
| 17 /// | |
| 18 /// TODO(paulberry): remove dependencies on analyzer. | |
| 19 final allowedPackageDependencies = [ | |
|
Siggi Cherem (dart-lang)
2017/06/15 17:45:57
do we need to also make the distinction between de
Paul Berry
2017/06/15 17:58:27
This script only checks files in pkg/front_end/lib
| |
| 20 'analyzer', | |
| 21 'charcode', | |
| 22 'convert', | |
| 23 'crypto', | |
| 24 'kernel', | |
| 25 'meta', | |
| 26 'package_config', | |
| 27 'path', | |
| 28 'source_span', | |
| 29 'testing', | |
| 30 ]; | |
| 31 | |
| 16 /// Map from subpackage name to the rules for what the subpackage is allowed to | 32 /// Map from subpackage name to the rules for what the subpackage is allowed to |
| 17 /// depend directly on. | 33 /// depend directly on. |
| 18 /// | 34 /// |
| 19 /// Each listed directory is considered a subpackage. Each package contains all | 35 /// Each listed directory is considered a subpackage. Each package contains all |
| 20 /// of its descendant files that are not in a more deeply nested subpackage. | 36 /// of its descendant files that are not in a more deeply nested subpackage. |
| 21 /// | 37 /// |
| 22 /// TODO(paulberry): stuff in lib/src shouldn't depend on lib; lib should just | 38 /// TODO(paulberry): stuff in lib/src shouldn't depend on lib; lib should just |
| 23 /// re-export stuff in lib/src. | 39 /// re-export stuff in lib/src. |
| 24 /// TODO(paulberry): remove dependencies on analyzer. | 40 /// TODO(paulberry): remove dependencies on analyzer. |
| 25 final subpackageRules = { | 41 final subpackageRules = { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 this.allowedDependencies: const []}); | 187 this.allowedDependencies: const []}); |
| 172 } | 188 } |
| 173 | 189 |
| 174 class _SubpackageRelationshipsTest { | 190 class _SubpackageRelationshipsTest { |
| 175 /// File uri of the front_end package's "lib" directory. | 191 /// File uri of the front_end package's "lib" directory. |
| 176 final frontEndLibUri = Platform.script.resolve('../lib/'); | 192 final frontEndLibUri = Platform.script.resolve('../lib/'); |
| 177 | 193 |
| 178 /// Indicates whether any problems have been reported yet. | 194 /// Indicates whether any problems have been reported yet. |
| 179 bool problemsReported = false; | 195 bool problemsReported = false; |
| 180 | 196 |
| 197 /// Package dependencies that were actually discovered | |
| 198 final actualPackageDependencies = <String>[]; | |
| 199 | |
| 181 /// Check for problems resulting from URI [src] having a direct dependency on | 200 /// Check for problems resulting from URI [src] having a direct dependency on |
| 182 /// URI [dst]. | 201 /// URI [dst]. |
| 183 void checkDependency(Uri src, Uri dst) { | 202 void checkDependency(Uri src, Uri dst) { |
| 184 if (dst.scheme == 'dart') return; | 203 if (dst.scheme == 'dart') return; |
| 185 if (dst.scheme != 'package') { | 204 if (dst.scheme != 'package') { |
| 186 problem('$src depends on $dst, which is neither a package: or dart: URI'); | 205 problem('$src depends on $dst, which is neither a package: or dart: URI'); |
| 187 return; | 206 return; |
| 188 } | 207 } |
| 208 if (src.scheme == 'package' && | |
| 209 src.pathSegments[0] == 'front_end' && | |
| 210 dst.scheme == 'package' && | |
| 211 dst.pathSegments[0] != 'front_end') { | |
| 212 if (allowedPackageDependencies.contains(dst.pathSegments[0])) { | |
| 213 actualPackageDependencies.add(dst.pathSegments[0]); | |
| 214 } else { | |
| 215 problem('$src depends on package "${dst.pathSegments[0]}", which is ' | |
| 216 'not found in allowedPackageDependencies'); | |
| 217 } | |
| 218 } | |
| 189 var srcSubpackage = subpackageForUri(src); | 219 var srcSubpackage = subpackageForUri(src); |
| 190 if (srcSubpackage == null) return; | 220 if (srcSubpackage == null) return; |
| 191 var srcSubpackageRules = subpackageRules[srcSubpackage]; | 221 var srcSubpackageRules = subpackageRules[srcSubpackage]; |
| 192 if (srcSubpackageRules == null) { | 222 if (srcSubpackageRules == null) { |
| 193 problem('$src is in subpackage "$srcSubpackage", which is not found in ' | 223 problem('$src is in subpackage "$srcSubpackage", which is not found in ' |
| 194 'subpackageRules'); | 224 'subpackageRules'); |
| 195 return; | 225 return; |
| 196 } | 226 } |
| 197 srcSubpackageRules.actuallyContainsFiles = true; | 227 srcSubpackageRules.actuallyContainsFiles = true; |
| 198 if (dst.pathSegments[0] == 'analyzer') { | 228 if (dst.pathSegments[0] == 'analyzer') { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 new CompilerOptions() | 276 new CompilerOptions() |
| 247 ..packagesFileUri = packagesFileUri | 277 ..packagesFileUri = packagesFileUri |
| 248 ..chaseDependencies = true); | 278 ..chaseDependencies = true); |
| 249 for (var i = 0; i < graph.topologicallySortedCycles.length; i++) { | 279 for (var i = 0; i < graph.topologicallySortedCycles.length; i++) { |
| 250 for (var library in graph.topologicallySortedCycles[i].libraries.values) { | 280 for (var library in graph.topologicallySortedCycles[i].libraries.values) { |
| 251 for (var dependency in library.dependencies) { | 281 for (var dependency in library.dependencies) { |
| 252 checkDependency(library.uri, dependency.uri); | 282 checkDependency(library.uri, dependency.uri); |
| 253 } | 283 } |
| 254 } | 284 } |
| 255 } | 285 } |
| 286 for (var package in allowedPackageDependencies) { | |
| 287 if (!actualPackageDependencies.contains(package)) { | |
| 288 problem( | |
| 289 '$package is listed in allowedPackageDependencies, but is not used') ; | |
|
Siggi Cherem (dart-lang)
2017/06/15 17:45:57
nit: maybe split line
Paul Berry
2017/06/15 17:58:27
Done.
| |
| 290 } | |
| 291 } | |
| 256 subpackageRules.forEach((subpackage, rule) { | 292 subpackageRules.forEach((subpackage, rule) { |
| 257 if (!rule.actuallyContainsFiles) { | 293 if (!rule.actuallyContainsFiles) { |
| 258 problem("$subpackage contains no files"); | 294 problem("$subpackage contains no files"); |
| 259 } | 295 } |
| 260 if (rule.mayImportAnalyzer && !rule.actuallyImportsAnalyzer) { | 296 if (rule.mayImportAnalyzer && !rule.actuallyImportsAnalyzer) { |
| 261 problem("$subpackage is allowed to import analyzer, but doesn't"); | 297 problem("$subpackage is allowed to import analyzer, but doesn't"); |
| 262 } | 298 } |
| 263 if (rule.allowSubdirs && !rule.actuallyHasSubdirs) { | 299 if (rule.allowSubdirs && !rule.actuallyHasSubdirs) { |
| 264 problem("$subpackage is allowed to have subdirectories, but doesn't"); | 300 problem("$subpackage is allowed to have subdirectories, but doesn't"); |
| 265 } | 301 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (subpackageRules[subpackage].allowSubdirs) { | 333 if (subpackageRules[subpackage].allowSubdirs) { |
| 298 subpackageRules[subpackage].actuallyHasSubdirs = true; | 334 subpackageRules[subpackage].actuallyHasSubdirs = true; |
| 299 } else { | 335 } else { |
| 300 problem('Uri $src is in a subfolder of $subpackage, but that ' | 336 problem('Uri $src is in a subfolder of $subpackage, but that ' |
| 301 'subpackage does not allow dart files in subdirectories.'); | 337 'subpackage does not allow dart files in subdirectories.'); |
| 302 } | 338 } |
| 303 } | 339 } |
| 304 return subpackage; | 340 return subpackage; |
| 305 } | 341 } |
| 306 } | 342 } |
| OLD | NEW |