Skip to content

Commit 528f510

Browse files
authored
Fix compilation of global path activated packages (#4541)
1 parent b665189 commit 528f510

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

lib/src/global_packages.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,12 @@ try:
506506
try {
507507
result = await log.spinner(
508508
'Resolving dependencies',
509-
() => resolveVersions(SolveType.get, cache, root),
509+
() => resolveVersions(
510+
SolveType.get,
511+
cache,
512+
root,
513+
lockFile: entrypoint.lockFile,
514+
),
510515
);
511516
} on SolveFailure catch (e) {
512517
log.error(e.message);

test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io';
6+
57
import 'package:path/path.dart' as p;
68
import 'package:pub/src/exit_codes.dart';
79
import 'package:pub/src/io.dart';
@@ -89,6 +91,8 @@ void main() {
8991

9092
await runPub(args: ['global', 'run', 'foo'], output: 'original');
9193

94+
// Serve an updated version of bar, to validate that the recompilation
95+
// validates content hashes.
9296
server.serve(
9397
'bar',
9498
'1.0.0',
@@ -97,6 +101,11 @@ void main() {
97101
],
98102
);
99103

104+
// Delete the existing download of bar to trigger a redownload.
105+
Directory(
106+
p.join(d.sandbox, d.hostedCachePath(port: server.port), 'bar-1.0.0'),
107+
).deleteSync(recursive: true);
108+
100109
await runPub(
101110
args: ['global', 'run', 'foo'],
102111
environment: {
@@ -214,7 +223,7 @@ void main() {
214223
await d.dir('dart', [
215224
d.dir('packages', [
216225
d.dir('bar', [
217-
// Doesn't fulfill constraint, but doesn't satisfy pubspec.lock.
226+
// Doesn't fulfill constraint.
218227
d.libPubspec('bar', '2.0.0', deps: {}),
219228
]),
220229
]),
@@ -227,7 +236,8 @@ void main() {
227236
},
228237
error: allOf(
229238
contains(
230-
'Because every version of foo depends on bar ^1.0.0 from sdk',
239+
'So, because pub global activate depends on foo 1.0.0 '
240+
'which depends on bar ^1.0.0 from sdk',
231241
),
232242
contains('The package `foo` as currently activated cannot resolve.'),
233243
contains('Try reactivating the package'),

test/global/run/runs_path_script_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:path/path.dart' as p;
56
import 'package:test/test.dart';
67

78
import '../../descriptor.dart' as d;
@@ -20,4 +21,24 @@ void main() {
2021
expect(pub.stdout, emitsThrough('ok'));
2122
await pub.shouldExit();
2223
});
24+
25+
// Regression test of https://github.com/dart-lang/pub/issues/4536
26+
test('respects existing lockfile', () async {
27+
final server = await servePackages();
28+
server.serve('dep', '1.0.0');
29+
30+
await d.dir('foo', [
31+
d.libPubspec('foo', '1.0.0', deps: {'dep': '^1.0.0'}),
32+
d.dir('bin', [d.file('foo.dart', "main() => print('ok');")]),
33+
]).create();
34+
35+
await pubGet(workingDirectory: p.join(d.sandbox, 'foo'));
36+
await runPub(args: ['global', 'activate', '--source', 'path', '../foo']);
37+
38+
server.serve('dep', '1.0.1');
39+
40+
final pub = await pubRun(global: true, args: ['foo']);
41+
expect(pub.stdout, emitsThrough('ok'));
42+
await pub.shouldExit();
43+
});
2344
}

0 commit comments

Comments
 (0)