diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index 2265e53a0de0b182be40bdb1c687c2f97580e21d..117f701d21c59b4f027df63cbe84d6e3f014a336 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -10,6 +10,7 @@ import 'package:barback/barback.dart'; import 'package:pub_semver/pub_semver.dart'; import 'barback/asset_environment.dart'; +import 'dart.dart' as dart; import 'entrypoint.dart'; import 'exceptions.dart'; import 'executable.dart' as exe; @@ -146,6 +147,7 @@ class GlobalPackages { _updateBinStubs(entrypoint.root, executables, overwriteBinStubs: overwriteBinStubs); + log.message('Activated ${_formatPackage(id)}.'); } /// Installs the package [dep] and its dependencies into the system cache. @@ -169,41 +171,88 @@ class GlobalPackages { // Make sure all of the dependencies are locally installed. await Future.wait(result.packages.map(_cacheDependency)); + var lockFile = result.lockFile; + _writeLockFile(dep.name, lockFile); + writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile(cache)); + // Load the package graph from [result] so we don't need to re-parse all // the pubspecs. var entrypoint = new Entrypoint.fromSolveResult(root, cache, result, isGlobal: true); var snapshots = await _precompileExecutables(entrypoint, dep.name); - var lockFile = result.lockFile; - _writeLockFile(dep.name, lockFile); - writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile(cache)); - _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); + + var id = lockFile.packages[dep.name]; + log.message('Activated ${_formatPackage(id)}.'); } - /// Precompiles the executables for [package] and saves them in the global + /// Precompiles the executables for [packageName] and saves them in the global /// cache. /// /// Returns a map from executable name to path for the snapshots that were /// successfully precompiled. Future<Map<String, String>> _precompileExecutables(Entrypoint entrypoint, - String package) { - return log.progress("Precompiling executables", () async { - var binDir = p.join(_directory, package, 'bin'); + String packageName) { + return log.progress("Precompiling executables", () { + var binDir = p.join(_directory, packageName, 'bin'); cleanDir(binDir); - var environment = await AssetEnvironment.create( - entrypoint, BarbackMode.RELEASE, - entrypoints: entrypoint.packageGraph.packages[package].executableIds, - useDart2JS: false); - environment.barback.errors.listen((error) { - log.error(log.red("Build error:\n$error")); - }); + // Try to avoid starting up an asset server to precompile packages if + // possible. This is faster and produces better error messages. + var package = entrypoint.packageGraph.packages[packageName]; + if (entrypoint.packageGraph.transitiveDependencies(packageName) + .every((package) => package.pubspec.transformers.isEmpty)) { + return _precompileExecutablesWithoutBarback(package, binDir); + } else { + return _precompileExecutablesWithBarback(entrypoint, package, binDir); + } + }); + } - return environment.precompileExecutables(package, binDir); + //// Precompiles all executables in [package] to snapshots from the + //// filesystem. + //// + //// The snapshots are placed in [dir]. + //// + //// Returns a map from executable basenames without extensions to the paths + //// to those executables. + Future<Map<String, String>> _precompileExecutablesWithoutBarback( + Package package, String dir) async { + var precompiled = {}; + await waitAndPrintErrors(package.executableIds.map((id) async { + var url = p.toUri(package.dir); + url = url.replace(path: p.url.join(url.path, id.path)); + var basename = p.url.basename(id.path); + var snapshotPath = p.join(dir, '$basename.snapshot'); + await dart.snapshot( + url, snapshotPath, + packagesFile: p.toUri(_getPackagesFilePath(package.name)), + id: id); + precompiled[p.withoutExtension(basename)] = snapshotPath; + })); + return precompiled; + } + + //// Precompiles all executables in [package] to snapshots from a barback + //// asset environment. + //// + //// The snapshots are placed in [dir]. + //// + //// Returns a map from executable basenames without extensions to the paths + //// to those executables. + Future<Map<String, String>> _precompileExecutablesWithBarback( + Entrypoint entrypoint, Package package, String dir) async { + var environment = await AssetEnvironment.create( + entrypoint, BarbackMode.RELEASE, + entrypoints: package.executableIds, + useDart2JS: false); + environment.barback.errors.listen((error) { + log.error(log.red("Build error:\n$error")); }); + + return environment.precompileExecutables(package.name, dir); } /// Downloads [id] into the system cache if it's a cached package. @@ -225,9 +274,6 @@ class GlobalPackages { if (fileExists(oldPath)) deleteEntry(oldPath); writeTextFile(_getLockFilePath(package), lockFile.serialize(cache.rootDir)); - - var id = lockFile.packages[package]; - log.message('Activated ${_formatPackage(id)}.'); } /// Shows the user the currently active package with [name], if any. diff --git a/test/cache/repair/recompiles_snapshots_test.dart b/test/cache/repair/recompiles_snapshots_test.dart index a831c8caaa7ac9e4fce6a5bc1bbea3a059e22181..e0d37a7c28fb673abce24b5f62a5061558f62ddb 100644 --- a/test/cache/repair/recompiles_snapshots_test.dart +++ b/test/cache/repair/recompiles_snapshots_test.dart @@ -29,7 +29,6 @@ main() { Reinstalled 1 package. Reactivating foo 1.0.0... Precompiling executables... - Loading source assets... Precompiled foo:script. Reactivated 1 package.'''); diff --git a/test/global/activate/activate_git_after_hosted_test.dart b/test/global/activate/activate_git_after_hosted_test.dart index 2e55210100be59130c12357cb8d2e97fc382908d..16b2c7402d3c42913146a8c72f558e67b22a45af 100644 --- a/test/global/activate/activate_git_after_hosted_test.dart +++ b/test/global/activate/activate_git_after_hosted_test.dart @@ -37,7 +37,6 @@ main() { // Specific revision number goes here. endsWith( 'Precompiling executables...\n' - 'Loading source assets...\n' 'Precompiled foo:foo.\n' 'Activated foo 1.0.0 from Git repository "../foo.git".'))); diff --git a/test/global/activate/activate_hosted_after_git_test.dart b/test/global/activate/activate_hosted_after_git_test.dart index 000f04118ae09fd33e1ed296cfc6385739dfd4fd..d7329bb6e0260f63f61515d5a73d12e66804d8f8 100644 --- a/test/global/activate/activate_hosted_after_git_test.dart +++ b/test/global/activate/activate_hosted_after_git_test.dart @@ -30,7 +30,6 @@ main() { + foo 2.0.0 Downloading foo 2.0.0... Precompiling executables... - Loading source assets... Precompiled foo:foo. Activated foo 2.0.0."""); diff --git a/test/global/activate/activate_hosted_after_path_test.dart b/test/global/activate/activate_hosted_after_path_test.dart index bc0ac0101b3c321847511e6e1efea4c715ef09d5..92b12346fbf09a198e138b2001f9dd0748a09848 100644 --- a/test/global/activate/activate_hosted_after_path_test.dart +++ b/test/global/activate/activate_hosted_after_path_test.dart @@ -34,7 +34,6 @@ main() { + foo 2.0.0 Downloading foo 2.0.0... Precompiling executables... - Loading source assets... Precompiled foo:foo. Activated foo 2.0.0."""); diff --git a/test/global/activate/cached_package_test.dart b/test/global/activate/cached_package_test.dart index ef5be8f4fb09dca40bf1157289b106ecf4be9624..af24e7c5f8e1915f258796823704f961b9df4bb5 100644 --- a/test/global/activate/cached_package_test.dart +++ b/test/global/activate/cached_package_test.dart @@ -19,7 +19,6 @@ main() { Resolving dependencies... + foo 1.0.0 Precompiling executables... - Loading source assets... Activated foo 1.0.0."""); // Should be in global package cache. diff --git a/test/global/activate/different_version_test.dart b/test/global/activate/different_version_test.dart index a920df367413cdba85870634af97fa94545253ca..9d78d0c3d14e7c13b65e1df94fde48a86321d0d1 100644 --- a/test/global/activate/different_version_test.dart +++ b/test/global/activate/different_version_test.dart @@ -22,7 +22,6 @@ main() { + foo 2.0.0 Downloading foo 2.0.0... Precompiling executables... - Loading source assets... Activated foo 2.0.0."""); }); } diff --git a/test/global/activate/git_package_test.dart b/test/global/activate/git_package_test.dart index fe2a9b4b378a2570f7522f8e2f9f582d410fe8e5..4d53ead9ea1f75e18cc824ee8552fe03240554bd 100644 --- a/test/global/activate/git_package_test.dart +++ b/test/global/activate/git_package_test.dart @@ -26,7 +26,6 @@ main() { // Specific revision number goes here. endsWith( 'Precompiling executables...\n' - 'Loading source assets...\n' 'Precompiled foo:foo.\n' 'Activated foo 1.0.0 from Git repository "../foo.git".'))); }); diff --git a/test/global/activate/ignores_active_version_test.dart b/test/global/activate/ignores_active_version_test.dart index e6969d18a17e081f27bcf4df27bb5862f1374ef9..d66c146aeeda22ebb249543d88b8c2ac0409716b 100644 --- a/test/global/activate/ignores_active_version_test.dart +++ b/test/global/activate/ignores_active_version_test.dart @@ -22,7 +22,6 @@ main() { + foo 1.3.0 Downloading foo 1.3.0... Precompiling executables... - Loading source assets... Activated foo 1.3.0."""); }); } diff --git a/test/global/activate/reactivating_git_upgrades_test.dart b/test/global/activate/reactivating_git_upgrades_test.dart index d75382e47c6655ada72bb340753fc034e72c3410..148ffe89991b53d0bb75bca99eff9f1916a710a1 100644 --- a/test/global/activate/reactivating_git_upgrades_test.dart +++ b/test/global/activate/reactivating_git_upgrades_test.dart @@ -24,7 +24,6 @@ main() { // Specific revision number goes here. endsWith( 'Precompiling executables...\n' - 'Loading source assets...\n' 'Activated foo 1.0.0 from Git repository "../foo.git".'))); d.git('foo.git', [ @@ -42,7 +41,6 @@ main() { // Specific revision number goes here. endsWith( 'Precompiling executables...\n' - 'Loading source assets...\n' 'Activated foo 1.0.1 from Git repository "../foo.git".'))); }); } diff --git a/test/global/activate/uncached_package_test.dart b/test/global/activate/uncached_package_test.dart index 8b706faa2e240e056a345260e73616069a0a5592..129be88c76dadb685ae809e38a0703e064092be1 100644 --- a/test/global/activate/uncached_package_test.dart +++ b/test/global/activate/uncached_package_test.dart @@ -20,7 +20,6 @@ main() { + foo 1.2.3 (2.0.0-wildly.unstable available) Downloading foo 1.2.3... Precompiling executables... - Loading source assets... Activated foo 1.2.3."""); // Should be in global package cache. diff --git a/test/global/deactivate/deactivate_and_reactivate_package_test.dart b/test/global/deactivate/deactivate_and_reactivate_package_test.dart index 0f8f6d857da4c65b652bdca4a17e470e159b2dc6..b4bf9482c19950a127231dd262c3567aa2ce7153 100644 --- a/test/global/deactivate/deactivate_and_reactivate_package_test.dart +++ b/test/global/deactivate/deactivate_and_reactivate_package_test.dart @@ -23,7 +23,6 @@ main() { + foo 2.0.0 Downloading foo 2.0.0... Precompiling executables... - Loading source assets... Activated foo 2.0.0."""); }); }