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

Unified Diff: utils/pub/entrypoint.dart

Issue 10874051: Support self-referential package: imports with Pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | utils/pub/git_source.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/entrypoint.dart
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart
index bd860f42bd6f6fed6a8d82038ad1959bc78eb0ed..213e3899ddf5bce638eb5e9156902fd37d8709cf 100644
--- a/utils/pub/entrypoint.dart
+++ b/utils/pub/entrypoint.dart
@@ -106,7 +106,8 @@ class Entrypoint {
* completes when all dependencies are installed.
*/
Future installDependencies() {
- return _loadLockFile()
+ return _validatePubspec()
+ .chain((_) => _loadLockFile())
.chain((lockFile) => resolveVersions(cache.sources, root, lockFile))
.chain(_installDependencies);
}
@@ -117,8 +118,9 @@ class Entrypoint {
* [Future] that completes when all dependencies are installed.
*/
Future updateAllDependencies() {
- return resolveVersions(cache.sources, root, new LockFile.empty()).
- chain(_installDependencies);
+ return _validatePubspec()
+ .chain((_) => resolveVersions(cache.sources, root, new LockFile.empty()))
+ .chain(_installDependencies);
}
/**
@@ -127,7 +129,7 @@ class Entrypoint {
* [Future] that completes when all dependencies are installed.
*/
Future updateDependencies(List<String> dependencies) {
- return _loadLockFile().chain((lockFile) {
+ return _validatePubspec().chain((_) => _loadLockFile()).chain((lockFile) {
var versionSolver = new VersionSolver(cache.sources, root, lockFile);
for (var dependency in dependencies) {
versionSolver.useLatestVersion(dependency);
@@ -144,7 +146,7 @@ class Entrypoint {
return Futures.wait(packageVersions.map((id) {
if (id.source is RootSource) return new Future.immediate(id);
return install(id);
- })).chain(_saveLockFile);
+ })).chain(_saveLockFile).chain(_installSelfReference);
}
/**
@@ -160,13 +162,13 @@ class Entrypoint {
var future = readTextFile(lockFilePath);
future.handleException((_) {
- completer.complete(new LockFile.empty());
-
// If we failed to load the lockfile but it does exist, something's
// probably wrong and we should notify the user.
- fileExists(lockFilePath).then((exists) {
+ fileExists(lockFilePath).transform((exists) {
if (!exists) return;
printError("Error reading pubspec.lock: ${future.exception}");
+ }).then((_) {
+ completer.complete(new LockFile.empty());
});
return true;
@@ -188,4 +190,35 @@ class Entrypoint {
return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize());
}
+
+ /**
+ * Installs a self-referential symlink in the `packages` directory that will
+ * allow a package to import its own files using `package:`.
+ */
+ Future _installSelfReference(_) {
+ var linkPath = join(path, root.name);
+ return exists(linkPath).chain((exists) {
+ if (exists) return new Future.immediate(null);
+ return ensureDir(path).chain((_) => createSymlink(root.dir, linkPath));
+ });
+ }
+
+ /**
+ * Validate that the pubspec for the entrypoint exists and specifies the name
+ * of the root package.
+ */
+ Future _validatePubspec() {
+ var future = new Future.immediate(null);;
+ if (root.pubspec.isEmpty) {
+ future = exists(join(path, "pubspec.yaml")).transform((exists) {
+ if (exists) return;
+ throw '"pubspec.yaml" not found.';
Bob Nystrom 2012/08/24 00:58:49 We should do friendly error messages here. Somethi
nweiz 2012/08/24 01:12:12 Done.
+ });
+ }
+
+ return future.transform((_) {
+ if (root.pubspec.name != null) return;
+ throw '"pubspec.yaml" must contain a "name" key.';
Bob Nystrom 2012/08/24 00:58:49 Make this a friendly complete sentence, please.
nweiz 2012/08/24 01:12:12 This one is a complete sentence. I'd be happy to r
+ });
+ }
}
« no previous file with comments | « no previous file | utils/pub/git_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698