Fix compilation of global path activated packages (#4541)

diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart
index 2d4eae3..e0db64f 100644
--- a/lib/src/global_packages.dart
+++ b/lib/src/global_packages.dart
@@ -506,7 +506,12 @@
         try {
           result = await log.spinner(
             'Resolving dependencies',
-            () => resolveVersions(SolveType.get, cache, root),
+            () => resolveVersions(
+              SolveType.get,
+              cache,
+              root,
+              lockFile: entrypoint.lockFile,
+            ),
           );
         } on SolveFailure catch (e) {
           log.error(e.message);
diff --git a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
index caa2b02..9f7e511 100644
--- a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
+++ b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
@@ -2,6 +2,8 @@
 // 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 'dart:io';
+
 import 'package:path/path.dart' as p;
 import 'package:pub/src/exit_codes.dart';
 import 'package:pub/src/io.dart';
@@ -89,6 +91,8 @@
 
     await runPub(args: ['global', 'run', 'foo'], output: 'original');
 
+    // Serve an updated version of bar, to validate that the recompilation
+    // validates content hashes.
     server.serve(
       'bar',
       '1.0.0',
@@ -97,6 +101,11 @@
       ],
     );
 
+    // Delete the existing download of bar to trigger a redownload.
+    Directory(
+      p.join(d.sandbox, d.hostedCachePath(port: server.port), 'bar-1.0.0'),
+    ).deleteSync(recursive: true);
+
     await runPub(
       args: ['global', 'run', 'foo'],
       environment: {
@@ -214,7 +223,7 @@
       await d.dir('dart', [
         d.dir('packages', [
           d.dir('bar', [
-            // Doesn't fulfill constraint, but doesn't satisfy pubspec.lock.
+            // Doesn't fulfill constraint.
             d.libPubspec('bar', '2.0.0', deps: {}),
           ]),
         ]),
@@ -227,7 +236,8 @@
         },
         error: allOf(
           contains(
-            'Because every version of foo depends on bar ^1.0.0 from sdk',
+            'So, because pub global activate depends on foo 1.0.0 '
+            'which depends on bar ^1.0.0 from sdk',
           ),
           contains('The package `foo` as currently activated cannot resolve.'),
           contains('Try reactivating the package'),
diff --git a/test/global/run/runs_path_script_test.dart b/test/global/run/runs_path_script_test.dart
index fdd6fe8..8058794 100644
--- a/test/global/run/runs_path_script_test.dart
+++ b/test/global/run/runs_path_script_test.dart
@@ -2,6 +2,7 @@
 // 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:test/test.dart';
 
 import '../../descriptor.dart' as d;
@@ -20,4 +21,24 @@
     expect(pub.stdout, emitsThrough('ok'));
     await pub.shouldExit();
   });
+
+  // Regression test of https://github.com/dart-lang/pub/issues/4536
+  test('respects existing lockfile', () async {
+    final server = await servePackages();
+    server.serve('dep', '1.0.0');
+
+    await d.dir('foo', [
+      d.libPubspec('foo', '1.0.0', deps: {'dep': '^1.0.0'}),
+      d.dir('bin', [d.file('foo.dart', "main() => print('ok');")]),
+    ]).create();
+
+    await pubGet(workingDirectory: p.join(d.sandbox, 'foo'));
+    await runPub(args: ['global', 'activate', '--source', 'path', '../foo']);
+
+    server.serve('dep', '1.0.1');
+
+    final pub = await pubRun(global: true, args: ['foo']);
+    expect(pub.stdout, emitsThrough('ok'));
+    await pub.shouldExit();
+  });
 }