Don't crash for pre-1.12 global packages.
We were assuming that all globally-activated packages have a .packages
file, but this isn't true for packages that were activated by earlier
versions of pub.
Closes #1316
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//1292003005 .
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index 749277f..65b276e 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -111,7 +111,12 @@
// If we're running an executable directly from the filesystem, make sure that
// it knows where to load the packages. If it's a dependency's executable, for
// example, it may not have the right packages directory itself.
- if (executableUrl.scheme == 'file' || executableUrl.scheme == '') {
+ //
+ // We don't do this for global executables because older ones may not have a
+ // `.packages` file generated. If they do, the VM's logic will find it
+ // automatically.
+ if (!isGlobal &&
+ (executableUrl.scheme == 'file' || executableUrl.scheme == '')) {
// We use an absolute path here not because the VM insists but because it's
// helpful for the subprocess to be able to spawn Dart with
// Platform.executableArguments and have that work regardless of the working
diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart
index ec0f541..c58ed54 100644
--- a/lib/src/global_packages.dart
+++ b/lib/src/global_packages.dart
@@ -353,7 +353,6 @@
var snapshotPath = p.join(binDir, '$executable.dart.snapshot');
return exe.runSnapshot(snapshotPath, args,
checked: checked,
- packagesFile: _getPackagesFilePath(package),
recompile: () async {
log.fine("$package:$executable is out of date and needs to be "
"recompiled.");
diff --git a/test/global/run/runs_script_without_packages_file_test.dart b/test/global/run/runs_script_without_packages_file_test.dart
new file mode 100644
index 0000000..6aed90d
--- /dev/null
+++ b/test/global/run/runs_script_without_packages_file_test.dart
@@ -0,0 +1,55 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:path/path.dart' as p;
+import 'package:pub/src/io.dart';
+import 'package:scheduled_test/scheduled_test.dart';
+
+import '../../descriptor.dart' as d;
+import '../../test_pub.dart';
+
+main() {
+ integration('runs a snapshotted script without a .packages file', () {
+ servePackages((builder) {
+ builder.serve("foo", "1.0.0", contents: [
+ d.dir("bin", [
+ d.file("script.dart", "main(args) => print('ok');")
+ ])
+ ]);
+ });
+
+ schedulePub(args: ["global", "activate", "foo"]);
+
+ // Mimic the global packages installed by pub <1.12, which didn't create a
+ // .packages file for global installs.
+ schedule(() {
+ deleteEntry(p.join(sandboxDir, cachePath,
+ 'global_packages/foo/.packages'));
+ });
+
+ var pub = pubRun(global: true, args: ["foo:script"]);
+ pub.stdout.expect("ok");
+ pub.shouldExit();
+ });
+
+ integration('runs an unsnapshotted script without a .packages file', () {
+ d.dir("foo", [
+ d.libPubspec("foo", "1.0.0"),
+ d.dir("bin", [
+ d.file("foo.dart", "main() => print('ok');")
+ ])
+ ]).create();
+
+ schedulePub(args: ["global", "activate", "--source", "path", "../foo"]);
+
+ schedule(() {
+ deleteEntry(p.join(sandboxDir, cachePath,
+ 'global_packages/foo/.packages'));
+ });
+
+ var pub = pubRun(global: true, args: ["foo"]);
+ pub.stdout.expect("ok");
+ pub.shouldExit();
+ });
+}