Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Package spec CL support.
Browse files Browse the repository at this point in the history
  • Loading branch information
pq committed Jul 14, 2015
1 parent d60ae88 commit 37fbb7a
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions lib/src/driver.dart
Expand Up @@ -28,7 +28,9 @@ import 'package:analyzer_cli/src/analyzer_impl.dart';
import 'package:analyzer_cli/src/options.dart';
import 'package:dev_compiler/strong_mode.dart';
import 'package:linter/src/plugin/linter_plugin.dart';
import 'package:package_config/packages.dart' show Packages;
import 'package:package_config/packages_file.dart' as pkgfile show parse;
import 'package:package_config/src/packages_impl.dart' show MapPackages;
import 'package:path/path.dart' as path;
import 'package:plugin/manager.dart';
import 'package:plugin/plugin.dart';
Expand Down Expand Up @@ -257,31 +259,33 @@ class Driver {
new DartUriResolver(sdk)
];

Packages packages;

if (options.packageConfigPath != null) {
String packageConfigPath = options.packageConfigPath;
Uri fileUri = new Uri.file(packageConfigPath);
try {
File configFile = new File.fromUri(fileUri);
List<int> bytes = configFile.readAsBytesSync();
/*Map<String, Uri> map = */pkgfile.parse(bytes, fileUri);
// TODO(pquitslund): plug into new resolver once implemented
// https://github.com/dart-lang/sdk/issues/23615
Map<String, Uri> map = pkgfile.parse(bytes, fileUri);
packages = new MapPackages(map);
} catch (e) {
printAndFail(
'Unable to read package config data from $packageConfigPath: $e');
}
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);
_PackageRootPackageMapBuilder
.buildPackageMap(options.packageRootPath);
if (packageMap != null) {
resolvers.add(new SdkExtUriResolver(packageMap));
}
JavaFile packageDirectory = new JavaFile(options.packageRootPath);
resolvers.add(new PackageUriResolver([packageDirectory]));
} else {

//TODO(pquitslund): add .packages config discovery

PubPackageMapProvider pubPackageMapProvider =
new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk);
PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap(
Expand All @@ -295,7 +299,7 @@ class Driver {
}
}
resolvers.add(new FileUriResolver());
return new SourceFactory(resolvers);
return new SourceFactory(resolvers, packages);
}

/// Convert the given [sourcePath] (which may be relative to the current
Expand Down Expand Up @@ -442,28 +446,6 @@ 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 {
Expand Down Expand Up @@ -521,3 +503,24 @@ class _BatchRunner {
});
}
}

/// [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;
}
}

0 comments on commit 37fbb7a

Please sign in to comment.