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

Unified Diff: lib/src/analyzer/multi_package_resolver.dart

Issue 1917863005: Qualify library names in packages (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Use restoreAbsolute Created 4 years, 8 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 | lib/src/compiler/code_generator.dart » ('j') | lib/src/compiler/code_generator.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/analyzer/multi_package_resolver.dart
diff --git a/lib/src/analyzer/multi_package_resolver.dart b/lib/src/analyzer/multi_package_resolver.dart
index 66905eca920fb7b54801265e105d244a7fd2b67d..5d12f5e7393c4d3b79bda4b49dc13132defb790c 100644
--- a/lib/src/analyzer/multi_package_resolver.dart
+++ b/lib/src/analyzer/multi_package_resolver.dart
@@ -7,7 +7,7 @@ import 'dart:io';
import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
-import 'package:path/path.dart' show join;
+import 'package:path/path.dart' as path;
/// A package resolver that supports a non-standard package layout, where
/// packages with dotted names are expanded to a hierarchy of directories, and
@@ -31,11 +31,33 @@ class MultiPackageResolver extends UriResolver {
return null;
}
- /// Resolve [path] by looking at each prefix in [searchPaths] and returning
- /// the first location where `prefix + path` exists.
- String _resolve(String path) {
+ @override
+ Uri restoreAbsolute(Source source) {
Paul Berry 2016/04/27 19:19:57 FYI, technically this breaks the interface contrac
+ var uri = source.uri;
+ if (uri.scheme == 'package' || uri.scheme == 'dart') {
+ return uri;
+ }
+ if (uri.scheme == '' || uri.scheme == 'file') {
+ var filePath = path.absolute(uri.path);
Paul Berry 2016/04/27 19:19:57 This won't work on Windows, since uri.path uses '/
+ for (var searchPath in searchPaths) {
+ if (path.isWithin(searchPath, filePath)) {
+ var relativePath = path.relative(filePath, from: searchPath);
+ var segments = path.split(relativePath);
+ var libIndex = segments.lastIndexOf('lib');
vsm 2016/04/27 18:24:35 This is not yet tested and seems brittle...
+ var packageName = segments.sublist(0, libIndex).join('.');
+ var packageRelativePath = segments.sublist(libIndex + 1).join('/');
+ return Uri.parse('package:$packageName/$packageRelativePath');
+ }
+ }
+ }
+ return null;
+ }
+
+ /// Resolve [packagePath] by looking at each prefix in [searchPaths] and returning
Jennifer Messerly 2016/04/27 18:30:05 long line
+ /// the first location where `prefix + packagePath` exists.
+ String _resolve(String packagePath) {
for (var prefix in searchPaths) {
- var resolvedPath = join(prefix, path);
+ var resolvedPath = path.join(prefix, packagePath);
if (new File(resolvedPath).existsSync()) return resolvedPath;
}
return null;
« no previous file with comments | « no previous file | lib/src/compiler/code_generator.dart » ('j') | lib/src/compiler/code_generator.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698