Skip to content

Commit a359e9e

Browse files
committed
Special case global-run message for updated sdk
1 parent e0df88b commit a359e9e

File tree

2 files changed

+135
-4
lines changed

2 files changed

+135
-4
lines changed

lib/src/global_packages.dart

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import 'source/git.dart';
2828
import 'source/hosted.dart';
2929
import 'source/path.dart';
3030
import 'source/root.dart';
31+
import 'source/sdk.dart';
3132
import 'system_cache.dart';
3233
import 'utils.dart';
3334

@@ -474,14 +475,44 @@ Try reactivating the package.
474475
result.packages.removeWhere((id) => id.name == 'pub global activate');
475476

476477
final newLockFile = await result.downloadCachedPackages(cache);
478+
final report = SolveReport(
479+
SolveType.get,
480+
entrypoint.workspaceRoot.dir,
481+
entrypoint.workspaceRoot.pubspec,
482+
entrypoint.workspaceRoot.allOverridesInWorkspace,
483+
entrypoint.lockFile,
484+
newLockFile,
485+
result.availableVersions,
486+
cache,
487+
dryRun: true,
488+
enforceLockfile: true,
489+
quiet: false,
490+
);
491+
await report.show(summary: true);
492+
477493
final sameVersions = entrypoint.lockFile.samePackageIds(newLockFile);
494+
478495
if (!sameVersions) {
479-
dataError('''
480-
The package `$name` as currently activated cannot resolve to the same packages.
496+
if (newLockFile.packages.values.any((p) {
497+
return p.source is SdkSource &&
498+
p.version != entrypoint.lockFile.packages[p.name]?.version;
499+
})) {
500+
// More specific error message for the case of a version match with
501+
// an sdk package.
502+
dataError('''
503+
The current activation of `$name` is not compatible with your current SDK.
481504
482505
Try reactivating the package.
483506
`$topLevelProgram pub global activate $name`
484507
''');
508+
} else {
509+
dataError('''
510+
The current activation of `$name` cannot resolve to the same set of dependencies.
511+
512+
Try reactivating the package.
513+
`$topLevelProgram pub global activate $name`
514+
''');
515+
}
485516
}
486517
await recompile(exectuable);
487518
_refreshBinStubs(entrypoint, executable);

test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void main() {
4848
// all output we see the precompilation messages as well.
4949
expect(pub.stdout, emits('Resolving dependencies...'));
5050
expect(pub.stdout, emits('Downloading packages...'));
51+
expect(pub.stdout, emits(startsWith('No dependencies would change in ')));
5152
expect(pub.stdout, emits('Building package executable...'));
5253
expect(pub.stdout, emitsThrough('ok'));
5354
await pub.shouldExit();
@@ -66,6 +67,102 @@ void main() {
6667

6768
test('validate resolution before recompilation', () async {
6869
final server = await servePackages();
70+
server.serve(
71+
'foo',
72+
'1.0.0',
73+
deps: {
74+
'bar': 'any',
75+
},
76+
contents: [
77+
d.dir('bin', [
78+
d.file('foo.dart', 'import "package:bar/bar.dart"; main() => bar();'),
79+
]),
80+
],
81+
);
82+
83+
server.serve(
84+
'bar',
85+
'1.0.0',
86+
contents: [
87+
d.dir('lib', [
88+
d.file('bar.dart', 'bar() => print("original");'),
89+
]),
90+
],
91+
);
92+
93+
await runPub(
94+
args: ['global', 'activate', 'foo'],
95+
);
96+
97+
await runPub(
98+
args: ['global', 'run', 'foo'],
99+
output: 'original',
100+
);
101+
102+
server.serve(
103+
'bar',
104+
'1.0.0',
105+
contents: [
106+
d.dir('lib', [
107+
d.file('foo.dart', 'foo() => print("updated");'),
108+
]),
109+
],
110+
);
111+
112+
await runPub(
113+
args: ['global', 'run', 'foo'],
114+
environment: {
115+
'DART_ROOT': p.join(d.sandbox, 'dart'),
116+
// Updated sdk version makes the old snapshot obsolete
117+
'_PUB_TEST_SDK_VERSION': '3.2.1+4',
118+
},
119+
output: contains('~ bar 1.0.0 (was 1.0.0)'),
120+
error: allOf(
121+
contains(
122+
'The current activation of `foo` cannot resolve to the same set of '
123+
'dependencies.',
124+
),
125+
contains(
126+
"The existing content-hash from pubspec.lock doesn't match "
127+
'contents for:',
128+
),
129+
contains('Try reactivating the package'),
130+
),
131+
exitCode: DATA,
132+
);
133+
134+
await d.dir('dart', [
135+
d.dir('packages', [
136+
d.dir('bar', [
137+
// Doesn't fulfill constraint, but doesn't satisfy pubspec.lock.
138+
d.libPubspec('bar', '2.0.0', deps: {}),
139+
]),
140+
]),
141+
]).create();
142+
await runPub(
143+
args: ['global', 'run', 'foo'],
144+
environment: {
145+
'DART_ROOT': p.join(d.sandbox, 'dart'),
146+
'_PUB_TEST_SDK_VERSION': '3.2.1+4',
147+
},
148+
error: allOf(
149+
contains(
150+
'The existing content-hash from pubspec.lock doesn\'t match '
151+
'contents for:',
152+
),
153+
contains(
154+
'The current activation of `foo` cannot resolve to the same '
155+
'set of dependencies.',
156+
),
157+
contains('Try reactivating the package'),
158+
),
159+
exitCode: DATA,
160+
);
161+
});
162+
163+
test('validate resolution before recompilation - updated sdk package',
164+
() async {
165+
final server = await servePackages();
69166
server.serve(
70167
'foo',
71168
'1.0.0',
@@ -120,9 +217,12 @@ void main() {
120217
'DART_ROOT': p.join(d.sandbox, 'dart'),
121218
'_PUB_TEST_SDK_VERSION': '3.2.1+4',
122219
},
220+
output: contains('> bar 1.2.0 from sdk dart (was 1.0.0 from sdk dart)'),
123221
error: allOf(
124-
contains('The package `foo` as currently activated cannot resolve to '
125-
'the same packages'),
222+
contains(
223+
'The current activation of `foo` is not compatible with your '
224+
'current SDK.',
225+
),
126226
contains('Try reactivating the package'),
127227
),
128228
exitCode: DATA,

0 commit comments

Comments
 (0)