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

Unified Diff: utils/pub/entrypoint.dart

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix after merge. Created 7 years, 11 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 | « utils/pub/command_uploader.dart ('k') | utils/pub/error_group.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 7a940d41ceb4a3b7cdd2ade8f6560b3fa318c820..973081a29223ffeb0aea021bd450b156e801ed61 100644
--- a/utils/pub/entrypoint.dart
+++ b/utils/pub/entrypoint.dart
@@ -40,16 +40,12 @@ class Entrypoint {
/// Packages which are either currently being asynchronously installed to the
/// directory, or have already been installed.
- final Map<PackageId, Future<PackageId>> _installs;
-
- Entrypoint(this.root, this.cache)
- : _installs = new Map<PackageId, Future<PackageId>>();
+ final _installs = new Map<PackageId, Future<PackageId>>();
/// Loads the entrypoint from a package at [rootDir].
- static Future<Entrypoint> load(String rootDir, SystemCache cache) {
- return Package.load(null, rootDir, cache.sources).then((package) =>
- new Entrypoint(package, cache));
- }
+ Entrypoint(String rootDir, SystemCache cache)
+ : root = new Package(null, rootDir, cache.sources),
+ cache = cache;
// TODO(rnystrom): Make this path configurable.
/// The path to this "packages" directory.
@@ -71,10 +67,10 @@ class Entrypoint {
if (pendingOrCompleted != null) return pendingOrCompleted;
var packageDir = join(path, id.name);
- var future = ensureDir(dirname(packageDir)).then((_) {
- return exists(packageDir);
- }).then((exists) {
- if (!exists) return;
+ var future = defer(() {
+ ensureDir(dirname(packageDir));
+ if (!dirExists(packageDir)) return;
+
// TODO(nweiz): figure out when to actually delete the directory, and when
// we can just re-use the existing symlink.
log.fine("Deleting package directory for ${id.name} before install.");
@@ -101,9 +97,9 @@ class Entrypoint {
/// directory, respecting the [LockFile] if present. Returns a [Future] that
/// completes when all dependencies are installed.
Future installDependencies() {
- return loadLockFile()
- .then((lockFile) => resolveVersions(cache.sources, root, lockFile))
- .then(_installDependencies);
+ return defer(() {
+ return resolveVersions(cache.sources, root, loadLockFile());
+ }).then(_installDependencies);
}
/// Installs the latest available versions of all dependencies of the [root]
@@ -111,19 +107,19 @@ class Entrypoint {
/// [Future] that completes when all dependencies are installed.
Future updateAllDependencies() {
return resolveVersions(cache.sources, root, new LockFile.empty())
- .then(_installDependencies);
+ .then(_installDependencies);
}
/// Installs the latest available versions of [dependencies], while leaving
/// other dependencies as specified by the [LockFile] if possible. Returns a
/// [Future] that completes when all dependencies are installed.
Future updateDependencies(List<String> dependencies) {
- return loadLockFile().then((lockFile) {
- var versionSolver = new VersionSolver(cache.sources, root, lockFile);
+ return defer(() {
+ var solver = new VersionSolver(cache.sources, root, loadLockFile());
for (var dependency in dependencies) {
- versionSolver.useLatestVersion(dependency);
+ solver.useLatestVersion(dependency);
}
- return versionSolver.solve();
+ return solver.solve();
}).then(_installDependencies);
}
@@ -144,7 +140,8 @@ class Entrypoint {
/// reached packages. This should only be called after the lockfile has been
/// successfully generated.
Future<List<Package>> walkDependencies() {
- return loadLockFile().then((lockFile) {
+ return defer(() {
+ var lockFile = loadLockFile();
var group = new FutureGroup<Package>();
var visited = new Set<String>();
@@ -199,43 +196,33 @@ class Entrypoint {
/// Loads the list of concrete package versions from the `pubspec.lock`, if it
/// exists. If it doesn't, this completes to an empty [LockFile].
- Future<LockFile> loadLockFile() {
+ LockFile loadLockFile() {
var lockFilePath = join(root.dir, 'pubspec.lock');
-
- log.fine("Loading lockfile.");
- return fileExists(lockFilePath).then((exists) {
- if (!exists) {
- log.fine("No lock file at $lockFilePath, creating empty one.");
- return new LockFile.empty();
- }
-
- return readTextFile(lockFilePath).then((text) =>
- new LockFile.parse(text, cache.sources));
- });
+ if (!fileExists(lockFilePath)) return new LockFile.empty();
+ return new LockFile.parse(readTextFile(lockFilePath), cache.sources);
}
/// Saves a list of concrete package versions to the `pubspec.lock` file.
- Future _saveLockFile(List<PackageId> packageIds) {
+ void _saveLockFile(List<PackageId> packageIds) {
var lockFile = new LockFile.empty();
for (var id in packageIds) {
if (!id.isRoot) lockFile.packages[id.name] = id;
}
var lockFilePath = join(root.dir, 'pubspec.lock');
- log.fine("Saving lockfile.");
- return writeTextFile(lockFilePath, lockFile.serialize());
+ writeTextFile(lockFilePath, 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).then((exists) {
+ return defer(() {
+ var linkPath = join(path, root.name);
// Create the symlink if it doesn't exist.
- if (exists) return;
- return ensureDir(path).then(
- (_) => createPackageSymlink(root.name, root.dir, linkPath,
- isSelfLink: true));
+ if (entryExists(linkPath)) return;
+ ensureDir(path);
+ return createPackageSymlink(root.name, root.dir, linkPath,
+ isSelfLink: true);
});
}
@@ -248,8 +235,8 @@ class Entrypoint {
var testDir = join(root.dir, 'test');
var toolDir = join(root.dir, 'tool');
var webDir = join(root.dir, 'web');
- return dirExists(binDir).then((exists) {
- if (!exists) return;
+ return defer(() {
+ if (!dirExists(binDir)) return;
return _linkSecondaryPackageDir(binDir);
}).then((_) => _linkSecondaryPackageDirsRecursively(exampleDir))
.then((_) => _linkSecondaryPackageDirsRecursively(testDir))
@@ -260,14 +247,14 @@ class Entrypoint {
/// Creates a symlink to the `packages` directory in [dir] and all its
/// subdirectories.
Future _linkSecondaryPackageDirsRecursively(String dir) {
- return dirExists(dir).then((exists) {
- if (!exists) return;
+ return defer(() {
+ if (!dirExists(dir)) return;
return _linkSecondaryPackageDir(dir)
- .then((_) => _listDirWithoutPackages(dir))
- .then((files) {
+ .then((_) => _listDirWithoutPackages(dir))
+ .then((files) {
return Future.wait(files.map((file) {
- return dirExists(file).then((isDir) {
- if (!isDir) return;
+ return defer(() {
+ if (!dirExists(file)) return;
return _linkSecondaryPackageDir(file);
});
}));
@@ -282,8 +269,8 @@ class Entrypoint {
return listDir(dir).then((files) {
return Future.wait(files.map((file) {
if (basename(file) == 'packages') return new Future.immediate([]);
- return dirExists(file).then((isDir) {
- if (!isDir) return [];
+ return defer(() {
+ if (!dirExists(file)) return [];
return _listDirWithoutPackages(file);
}).then((subfiles) {
var fileAndSubfiles = [file];
@@ -296,9 +283,9 @@ class Entrypoint {
/// Creates a symlink to the `packages` directory in [dir] if none exists.
Future _linkSecondaryPackageDir(String dir) {
- var to = join(dir, 'packages');
- return exists(to).then((exists) {
- if (exists) return;
+ return defer(() {
+ var to = join(dir, 'packages');
+ if (entryExists(to)) return;
return createSymlink(path, to);
});
}
« no previous file with comments | « utils/pub/command_uploader.dart ('k') | utils/pub/error_group.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698