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

Unified Diff: lib/src/driver.dart

Issue 1229993002: Add support for sdk extensions when launched with a package root (Closed) Base URL: git@github.com:dart-lang/analyzer_cli.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/driver.dart
diff --git a/lib/src/driver.dart b/lib/src/driver.dart
index 5a5dc4efca4f18b909ad13ebda357a96447d8697..d39a39e6fb86a491833716a23437c6612e2356c1 100644
--- a/lib/src/driver.dart
+++ b/lib/src/driver.dart
@@ -273,6 +273,12 @@ class Driver {
printAndFail(
'Package config files are not supported yet. For status see: https://github.com/dart-lang/sdk/issues/23373');
} else if (options.packageRootPath != null) {
+ Map<String, List<fileSystem.Folder>> packageMap =
+ _PackageRootPackageMapBuilder.buildPackageMap(
+ options.packageRootPath);
+ if (packageMap != null) {
+ resolvers.add(new SdkExtUriResolver(packageMap));
+ }
JavaFile packageDirectory = new JavaFile(options.packageRootPath);
resolvers.add(new PackageUriResolver([packageDirectory]));
} else {
@@ -436,6 +442,28 @@ class Driver {
}
}
+/// [SdkExtUriResolver] needs a Map from package name to folder. In the case
+/// that the analyzer is invoked with a --package-root option, we need to
+/// manually create this mapping. Given [packageRootPath],
+/// [_PackageRootPackageMapBuilder] creates a simple mapping from package name
+/// to full path on disk (resolving any symbolic links).
+class _PackageRootPackageMapBuilder {
+ static Map<String, List<fileSystem.Folder>> buildPackageMap(
+ String packageRootPath) {
+ var packageRoot = new Directory(packageRootPath);
+ var packages = packageRoot.listSync(followLinks: false);
+ var result = new Map<String, List<fileSystem.Folder>>();
+ for (var package in packages) {
+ var packageName = path.basename(package.path);
+ var realPath = package.resolveSymbolicLinksSync();
+ result[packageName] = [
+ PhysicalResourceProvider.INSTANCE.getFolder(realPath)
+ ];
+ }
+ return result;
+ }
+}
+
/// Provides a framework to read command line options from stdin and feed them
/// to a callback.
class _BatchRunner {
« 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