| Index: sdk/lib/_internal/pub/lib/src/entrypoint.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/entrypoint.dart b/sdk/lib/_internal/pub/lib/src/entrypoint.dart
|
| index 25bb14f1d3222eabfde2f4cc35f2584d01bab7bd..c1f0e7d50960e254b1b10581de90999d77065845 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/entrypoint.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/entrypoint.dart
|
| @@ -5,13 +5,11 @@
|
| library pub.entrypoint;
|
|
|
| import 'dart:async';
|
| -import 'dart:io';
|
|
|
| import 'package:path/path.dart' as path;
|
| import 'package:barback/barback.dart';
|
|
|
| import 'barback/asset_environment.dart';
|
| -import 'exceptions.dart';
|
| import 'io.dart';
|
| import 'lock_file.dart';
|
| import 'log.dart' as log;
|
| @@ -144,15 +142,8 @@ class Entrypoint {
|
|
|
| /// Build a package graph from the version solver results so we don't
|
| /// have to reload and reparse all the pubspecs.
|
| - return Future.wait(ids.map((id) {
|
| - return cache.sources[id.source].getDirectory(id).then((dir) {
|
| - return new Package(result.pubspecs[id.name], dir);
|
| - });
|
| - }));
|
| - }).then((packages) {
|
| - _packageGraph = new PackageGraph(this, _lockFile,
|
| - new Map.fromIterable(packages, key: (package) => package.name));
|
| -
|
| + return loadPackageGraph(result);
|
| + }).then((packageGraph) {
|
| return precompileExecutables(changed: result.changedPackages)
|
| .catchError((error, stackTrace) {
|
| // Just log exceptions here. Since the method is just about acquiring
|
| @@ -207,8 +198,11 @@ class Entrypoint {
|
| });
|
|
|
| return waitAndPrintErrors(executables.keys.map((package) {
|
| - return _precompileExecutablesForPackage(
|
| - environment, package, executables[package]);
|
| + var dir = path.join(binDir, package);
|
| + cleanDir(dir);
|
| + return environment.precompileExecutables(
|
| + package, dir,
|
| + executableIds: executables[package]);
|
| }));
|
| });
|
| });
|
| @@ -236,15 +230,7 @@ class Entrypoint {
|
| });
|
| if (hasUncachedDependency) return [];
|
|
|
| - var executables =
|
| - ordered(package.listFiles(beneath: binDir, recursive: false))
|
| - .where((executable) => path.extension(executable) == '.dart')
|
| - .map((executable) {
|
| - return new AssetId(
|
| - package.name,
|
| - path.toUri(path.relative(executable, from: package.dir))
|
| - .toString());
|
| - }).toList();
|
| + var executables = package.executableIds;
|
|
|
| // If we don't know which packages were changed, always precompile the
|
| // executables.
|
| @@ -267,51 +253,6 @@ class Entrypoint {
|
| return [];
|
| }
|
|
|
| - /// Precompiles all [executables] for [package].
|
| - ///
|
| - /// [executables] is assumed to be a list of Dart executables in [package]'s
|
| - /// bin directory.
|
| - Future _precompileExecutablesForPackage(
|
| - AssetEnvironment environment, String package, List<AssetId> executables) {
|
| - var cacheDir = path.join('.pub', 'bin', package);
|
| - cleanDir(cacheDir);
|
| -
|
| - // TODO(nweiz): Unserve this directory when we're done with it.
|
| - return environment.servePackageBinDirectory(package).then((server) {
|
| - return waitAndPrintErrors(executables.map((id) {
|
| - var basename = path.url.basename(id.path);
|
| - var snapshotPath = path.join(cacheDir, "$basename.snapshot");
|
| - return runProcess(Platform.executable, [
|
| - '--snapshot=$snapshotPath',
|
| - server.url.resolve(basename).toString()
|
| - ]).then((result) {
|
| - if (result.success) {
|
| - log.message("Precompiled ${_executableName(id)}.");
|
| - } else {
|
| - // TODO(nweiz): Stop manually deleting this when issue 20504 is
|
| - // fixed.
|
| - deleteEntry(snapshotPath);
|
| - throw new ApplicationException(
|
| - log.yellow("Failed to precompile "
|
| - "${_executableName(id)}:\n") +
|
| - result.stderr.join('\n'));
|
| - }
|
| - });
|
| - })).whenComplete(() {
|
| - // Don't return this future, since we have no need to wait for the
|
| - // server to fully shut down.
|
| - server.close();
|
| - });
|
| - });
|
| - }
|
| -
|
| - /// Returns the executable name for [id].
|
| - ///
|
| - /// [id] is assumed to be an executable in a bin directory. The return value
|
| - /// is intended for log output and may contain formatting.
|
| - String _executableName(AssetId id) =>
|
| - log.bold("${id.package}:${path.basenameWithoutExtension(id.path)}");
|
| -
|
| /// Makes sure the package at [id] is locally available.
|
| ///
|
| /// This automatically downloads the package to the system-wide cache as well
|
| @@ -421,22 +362,37 @@ class Entrypoint {
|
| /// Loads the package graph for the application and all of its transitive
|
| /// dependencies.
|
| ///
|
| - /// Before loading, makes sure the lockfile and dependencies are installed
|
| - /// and up to date.
|
| - Future<PackageGraph> loadPackageGraph() {
|
| + /// If [result] is passed, this loads the graph from it without re-parsing the
|
| + /// lockfile or any pubspecs. Otherwise, before loading, this makes sure the
|
| + /// lockfile and dependencies are installed and up to date.
|
| + Future<PackageGraph> loadPackageGraph([SolveResult result]) {
|
| if (_packageGraph != null) return new Future.value(_packageGraph);
|
|
|
| - return ensureLockFileIsUpToDate().then((_) {
|
| - return Future.wait(lockFile.packages.values.map((id) {
|
| - var source = cache.sources[id.source];
|
| - return source.getDirectory(id)
|
| - .then((dir) => new Package.load(id.name, dir, cache.sources));
|
| - })).then((packages) {
|
| - var packageMap = new Map.fromIterable(packages, key: (p) => p.name);
|
| - packageMap[root.name] = root;
|
| - _packageGraph = new PackageGraph(this, lockFile, packageMap);
|
| - return _packageGraph;
|
| - });
|
| + return syncFuture(() {
|
| + if (result != null) {
|
| + return Future.wait(result.packages.map((id) {
|
| + return cache.sources[id.source].getDirectory(id)
|
| + .then((dir) => new Package(result.pubspecs[id.name], dir));
|
| + })).then((packages) {
|
| + return new PackageGraph(this, new LockFile(result.packages),
|
| + new Map.fromIterable(packages, key: (package) => package.name));
|
| + });
|
| + } else {
|
| + return ensureLockFileIsUpToDate().then((_) {
|
| + return Future.wait(lockFile.packages.values.map((id) {
|
| + var source = cache.sources[id.source];
|
| + return source.getDirectory(id)
|
| + .then((dir) => new Package.load(id.name, dir, cache.sources));
|
| + })).then((packages) {
|
| + var packageMap = new Map.fromIterable(packages, key: (p) => p.name);
|
| + packageMap[root.name] = root;
|
| + return new PackageGraph(this, lockFile, packageMap);
|
| + });
|
| + });
|
| + }
|
| + }).then((graph) {
|
| + _packageGraph = graph;
|
| + return graph;
|
| });
|
| }
|
|
|
|
|