Skip to content

Commit c255996

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ DartDev ] Print error to console when trying to launch a missing SDK
artifact (e.g., snapshots) This should never happen in a stable release unless the SDK installation is corrupted, but can happen when only building the 'runtime' build target. Fixes #42601 Change-Id: I00bd9538984b26350780fc58754169e79e91d24e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156023 Reviewed-by: Jaime Wren <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 91d4601 commit c255996

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class CompileJSCommand extends DartdevCommand<int> {
6565

6666
@override
6767
FutureOr<int> run() async {
68+
if (!Sdk.checkSnapshotExists(sdk.dart2js)) {
69+
return 255;
70+
}
6871
// We expect a single rest argument; the dart entry point.
6972
if (argResults.rest.length != 1) {
7073
log.stderr('Missing Dart entry point.');
@@ -176,6 +179,10 @@ Remove debugging information from the output and save it separately to the speci
176179

177180
@override
178181
FutureOr<int> run() async {
182+
if (!Sdk.checkSnapshotExists(genKernel) ||
183+
!Sdk.checkSnapshotExists(genSnapshot)) {
184+
return 255;
185+
}
179186
// We expect a single rest argument; the dart entry point.
180187
if (argResults.rest.length != 1) {
181188
log.stderr('Missing Dart entry point.');

pkg/dartdev/lib/src/commands/create.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class CreateCommand extends DartdevCommand {
9696
);
9797

9898
if (argResults['pub']) {
99+
if (!Sdk.checkSnapshotExists(sdk.pub)) {
100+
return 255;
101+
}
99102
log.stdout('');
100103
var progress = log.progress('Running pub get');
101104
var process = await startProcess(

pkg/dartdev/lib/src/commands/pub.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class PubCommand extends DartdevCommand<int> {
2222
// Override [printUsage] for invocations of 'dart help pub' which won't
2323
// execute [run] below. Without this, the 'dart help pub' reports the
2424
// command pub with no commands or flags.
25+
if (!Sdk.checkSnapshotExists(sdk.pub)) {
26+
return;
27+
}
2528
final command = sdk.pub;
2629
final args = ['help'];
2730

@@ -42,6 +45,9 @@ class PubCommand extends DartdevCommand<int> {
4245

4346
@override
4447
FutureOr<int> run() async {
48+
if (!Sdk.checkSnapshotExists(sdk.pub)) {
49+
return 255;
50+
}
4551
final command = sdk.pub;
4652
var args = argResults.arguments;
4753

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ Run a Dart file.''');
122122
_DebuggingSession debugSession;
123123
if (launchDds) {
124124
debugSession = _DebuggingSession();
125-
await debugSession.start();
125+
if (!await debugSession.start()) {
126+
return 255;
127+
}
126128
}
127129

128130
final script = Directory.current.uri
@@ -135,8 +137,14 @@ Run a Dart file.''');
135137
}
136138

137139
class _DebuggingSession {
138-
Future<void> start() async {
140+
Future<bool> start() async {
139141
final serviceInfo = await Service.getInfo();
142+
final ddsSnapshot = (dirname(sdk.dart).endsWith('bin'))
143+
? sdk.ddsSnapshot
144+
: absolute(dirname(sdk.dart), 'gen', 'dds.dart.snapshot');
145+
if (!Sdk.checkSnapshotExists(ddsSnapshot)) {
146+
return false;
147+
}
140148
final process = await Process.start(
141149
sdk.dart,
142150
[
@@ -157,5 +165,6 @@ class _DebuggingSession {
157165
});
158166

159167
await completer.future;
168+
return true;
160169
}
161170
}

pkg/dartdev/lib/src/commands/test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class TestCommand extends DartdevCommand<int> {
1919

2020
@override
2121
void printUsage() {
22+
if (!Sdk.checkSnapshotExists(sdk.pub)) {
23+
return;
24+
}
2225
final command = sdk.pub;
2326
final args = ['run', 'test', '--help'];
2427

@@ -42,6 +45,9 @@ class TestCommand extends DartdevCommand<int> {
4245

4346
@override
4447
FutureOr<int> run() async {
48+
if (!Sdk.checkSnapshotExists(sdk.pub)) {
49+
return 255;
50+
}
4551
final command = sdk.pub;
4652
final testArgs = argResults.arguments.toList();
4753

pkg/dartdev/lib/src/sdk.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'dart:io';
66

77
import 'package:path/path.dart' as path;
88

9+
import 'core.dart';
10+
911
final Sdk sdk = Sdk();
1012

1113
String get _computeSdkPath {
@@ -59,4 +61,13 @@ class Sdk {
5961

6062
static String _binName(String base) =>
6163
Platform.isWindows ? '$base.bat' : base;
64+
65+
static bool checkSnapshotExists(String snapshotPath) {
66+
if (!File(snapshotPath).existsSync()) {
67+
log.stderr('Could not find $snapshotPath. Have you built the full '
68+
'Dart SDK?');
69+
return false;
70+
}
71+
return true;
72+
}
6273
}

0 commit comments

Comments
 (0)