Skip to content

Commit ab82887

Browse files
authored
update frontend server compile api to always return a result, but have a nullable dill (#1641)
Also fixes #1637. This is a breaking API change, which I could revert if desired, but this allows us to get compiler output even if there is no output dill file.
1 parent 27c6387 commit ab82887

File tree

7 files changed

+54
-63
lines changed

7 files changed

+54
-63
lines changed

frontend_server_client/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
## 3.0.0-dev
2+
3+
- Update the `compile` api to return a non-null `CompileResult`, and instead
4+
make the `dillOutput` field nullable. This allows you to still get compiler
5+
output if no dill file was produced.
6+
17
## 2.1.3
8+
29
- Update `package:vm_service` to version `^8.0.0`
310

411
## 2.1.2

frontend_server_client/example/vm_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main(List<String> args) async {
3131
Process appProcess;
3232
final vmServiceCompleter = Completer<VmService>();
3333
appProcess = await Process.start(Platform.resolvedExecutable,
34-
['--observe', '--no-pause-isolates-on-exit', result!.dillOutput]);
34+
['--observe', '--no-pause-isolates-on-exit', result.dillOutput!]);
3535
appProcess.stdout
3636
.transform(utf8.decoder)
3737
.transform(const LineSplitter())
@@ -65,7 +65,7 @@ void main(List<String> args) async {
6565
_print('reloading $app');
6666
var vm = await vmService.getVM();
6767
await vmService.reloadSources(vm.isolates!.first.id!,
68-
rootLibUri: result!.dillOutput);
68+
rootLibUri: result.dillOutput!);
6969

7070
_print('restoring $app to original contents');
7171
await appFile.writeAsString(originalContent);

frontend_server_client/example/web_client.dart

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

5-
// @dart = 2.8
65
import 'dart:convert';
76
import 'dart:io';
87

frontend_server_client/lib/src/dartdevc_frontend_server_client.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ class DartDevcFrontendServerClient implements FrontendServerClient {
108108
String bootstrapJs() => throw UnimplementedError();
109109

110110
/// Updates [_assets] for [result].
111-
void _updateAssets(CompileResult? result) {
112-
if (result == null) {
111+
void _updateAssets(CompileResult result) {
112+
if (result.dillOutput == null) {
113113
return;
114114
}
115115
final manifest =
116-
jsonDecode(File(result.jsManifestOutput).readAsStringSync())
116+
jsonDecode(File(result.jsManifestOutput!).readAsStringSync())
117117
as Map<String, dynamic>;
118-
final sourceBytes = File(result.jsSourcesOutput).readAsBytesSync();
119-
final sourceMapBytes = File(result.jsSourceMapsOutput).readAsBytesSync();
118+
final sourceBytes = File(result.jsSourcesOutput!).readAsBytesSync();
119+
final sourceMapBytes = File(result.jsSourceMapsOutput!).readAsBytesSync();
120120

121121
for (var entry in manifest.entries) {
122122
var metadata = entry.value as Map<String, dynamic>;
@@ -130,7 +130,7 @@ class DartDevcFrontendServerClient implements FrontendServerClient {
130130
}
131131

132132
@override
133-
Future<CompileResult?> compile([List<Uri>? invalidatedUris]) async {
133+
Future<CompileResult> compile([List<Uri>? invalidatedUris]) async {
134134
return _lastResult = await _frontendServerClient.compile(invalidatedUris);
135135
}
136136

@@ -168,7 +168,7 @@ class DartDevcFrontendServerClient implements FrontendServerClient {
168168
@override
169169
void accept() {
170170
_frontendServerClient.accept();
171-
_updateAssets(_lastResult);
171+
if (_lastResult != null) _updateAssets(_lastResult!);
172172
_lastResult = null;
173173
}
174174

frontend_server_client/lib/src/frontend_server_client.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class FrontendServerClient {
103103
/// [invalidatedUris] must not be null for all but the very first compile.
104104
///
105105
/// The frontend server _does not_ do any of its own invalidation.
106-
Future<CompileResult?> compile([List<Uri>? invalidatedUris]) async {
106+
Future<CompileResult> compile([List<Uri>? invalidatedUris]) async {
107107
String action;
108108
switch (_state) {
109109
case _ClientState.waitingForFirstCompile:
@@ -190,10 +190,6 @@ class FrontendServerClient {
190190
}
191191
}
192192

193-
if (outputDillPath == null) {
194-
return null;
195-
}
196-
197193
return CompileResult._(
198194
dillOutput: outputDillPath,
199195
errorCount: errorCount,
@@ -339,9 +335,9 @@ class CompileResult {
339335
required this.newSources,
340336
required this.removedSources});
341337

342-
/// The produced dill output file, this will either be a full dill file or an
343-
/// incremental dill file.
344-
final String dillOutput;
338+
/// The produced dill output file, this will either be a full dill file, an
339+
/// incremental dill file, or `null` if no file was produced.
340+
final String? dillOutput;
345341

346342
/// All output from the compiler, typically this would contain errors or
347343
/// warnings.
@@ -354,16 +350,19 @@ class CompileResult {
354350
/// A single file containing all source maps for all JS outputs.
355351
///
356352
/// Read [jsManifestOutput] for file offsets for each sourcemap.
357-
String get jsSourceMapsOutput => '$dillOutput.map';
353+
String? get jsSourceMapsOutput =>
354+
dillOutput == null ? null : '$dillOutput.map';
358355

359356
/// A single file containing all JS outputs.
360357
///
361358
/// Read [jsManifestOutput] for file offsets for each source.
362-
String get jsSourcesOutput => '$dillOutput.sources';
359+
String? get jsSourcesOutput =>
360+
dillOutput == null ? null : '$dillOutput.sources';
363361

364362
/// A JSON manifest containing offsets for the sources and source maps in
365363
/// the [jsSourcesOutput] and [jsSourceMapsOutput] files.
366-
String get jsManifestOutput => '$dillOutput.json';
364+
String? get jsManifestOutput =>
365+
dillOutput == null ? null : '$dillOutput.json';
367366

368367
/// All the transitive source dependencies that were added as a part of this
369368
/// compile.

frontend_server_client/pubspec.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: frontend_server_client
2-
version: 2.1.3
2+
version: 3.0.0-dev
33
description: >-
44
Client code to start and interact with the frontend_server compiler from the
55
Dart SDK.
@@ -20,3 +20,8 @@ dev_dependencies:
2020
test: ^1.16.0
2121
test_descriptor: ^2.0.0
2222
vm_service: ^8.0.0
23+
24+
dependency_overrides:
25+
# Necessary to get a version solve until test_core allows version 3.x of
26+
# this package
27+
test_core: ^0.4.13

frontend_server_client/test/frontend_sever_client_test.dart

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ dependencies:
2828
path: ^1.0.0
2929
3030
environment:
31-
sdk: '>=2.12.0-0 <3.0.0'
31+
sdk: '>=2.12.0 <3.0.0'
3232
'''),
3333
d.dir('bin', [
3434
d.file('main.dart', '''
35-
// @dart = 2.8
3635
import 'package:path/path.dart' as p;
3736
3837
void main() async {
@@ -64,9 +63,6 @@ String get message => p.join('hello', 'world');
6463
client = await FrontendServerClient.start(
6564
entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill);
6665
var result = await client.compile();
67-
if (result == null) {
68-
fail('Expected compilation to be non-null');
69-
}
7066
client.accept();
7167
expect(result.compilerOutputLines, isEmpty);
7268
expect(result.errorCount, 0);
@@ -77,12 +73,13 @@ String get message => p.join('hello', 'world');
7773
packageConfig.resolve(Uri.parse('package:path/path.dart')),
7874
]));
7975
expect(result.removedSources, isEmpty);
80-
expect(File(result.dillOutput).existsSync(), true);
76+
expect(result.dillOutput, isNotNull);
77+
expect(File(result.dillOutput!).existsSync(), true);
8178
var process = await Process.start(Platform.resolvedExecutable, [
8279
'--observe',
8380
'--no-pause-isolates-on-exit',
8481
'--pause-isolates-on-start',
85-
result.dillOutput
82+
result.dillOutput!
8683
]);
8784
addTearDown(process.kill);
8885
var stdoutLines = StreamQueue(
@@ -102,9 +99,6 @@ String get message => p.join('hello', 'world');
10299
await appFile.writeAsString(newContent);
103100

104101
result = await client.compile([File(entrypoint).uri]);
105-
if (result == null) {
106-
fail('Expected compilation to be non-null');
107-
}
108102

109103
client.accept();
110104
expect(result.newSources, isEmpty);
@@ -130,9 +124,6 @@ String get message => p.join('hello', 'world');
130124
client = await FrontendServerClient.start(
131125
entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill);
132126
var result = await client.compile();
133-
if (result == null) {
134-
fail('Expected compilation to be non-null');
135-
}
136127

137128
client.accept();
138129
expect(result.errorCount, 2);
@@ -145,13 +136,14 @@ String get message => p.join('hello', 'world');
145136
packageConfig.resolve(Uri.parse('package:path/path.dart')),
146137
]));
147138
expect(result.removedSources, isEmpty);
148-
expect(File(result.dillOutput).existsSync(), true);
139+
expect(result.dillOutput, isNotNull);
140+
expect(File(result.dillOutput!).existsSync(), true);
149141

150142
var process = await Process.start(Platform.resolvedExecutable, [
151143
'--observe',
152144
'--no-pause-isolates-on-exit',
153145
'--pause-isolates-on-start',
154-
result.dillOutput
146+
result.dillOutput!
155147
]);
156148
addTearDown(process.kill);
157149
var stdoutLines = StreamQueue(
@@ -170,15 +162,13 @@ String get message => p.join('hello', 'world');
170162
await entrypointFile
171163
.writeAsString(originalContent.replaceFirst('hello', 'goodbye'));
172164
result = await client.compile([entrypointFile.uri]);
173-
if (result == null) {
174-
fail('Expected compilation to be non-null');
175-
}
176165
client.accept();
177166
expect(result.errorCount, 0);
178167
expect(result.compilerOutputLines, isEmpty);
179168
expect(result.newSources, isEmpty);
180169
expect(result.removedSources, isEmpty);
181-
expect(File(result.dillOutput).existsSync(), true);
170+
expect(result.dillOutput, isNotNull);
171+
expect(File(result.dillOutput!).existsSync(), true);
182172

183173
await vmService.reloadSources(isolate.id!, rootLibUri: result.dillOutput);
184174

@@ -190,11 +180,12 @@ String get message => p.join('hello', 'world');
190180
var entrypoint =
191181
p.toUri(p.join(packageRoot, 'bin', 'main.dart')).toString();
192182
var dartDevcClient = client = await DartDevcFrontendServerClient.start(
193-
entrypoint, p.join(packageRoot, 'out.dill'));
183+
entrypoint, p.join(packageRoot, 'out.dill'),
184+
platformKernel: p
185+
.toUri(
186+
p.join(sdkDir, 'lib', '_internal', 'ddc_platform_sound.dill'))
187+
.toString());
194188
var result = await client.compile();
195-
if (result == null) {
196-
fail('Expected compilation to be non-null');
197-
}
198189
client.accept();
199190

200191
expect(result.compilerOutputLines, isEmpty);
@@ -207,9 +198,10 @@ String get message => p.join('hello', 'world');
207198
]));
208199
expect(result.removedSources, isEmpty);
209200

210-
expect(File(result.jsManifestOutput).existsSync(), true);
211-
expect(File(result.jsSourcesOutput).existsSync(), true);
212-
expect(File(result.jsSourceMapsOutput).existsSync(), true);
201+
expect(result.dillOutput, isNotNull);
202+
expect(File(result.jsManifestOutput!).existsSync(), true);
203+
expect(File(result.jsSourcesOutput!).existsSync(), true);
204+
expect(File(result.jsSourceMapsOutput!).existsSync(), true);
213205

214206
var entrypointUri = Uri.parse(entrypoint);
215207
expect(
@@ -222,9 +214,6 @@ String get message => p.join('hello', 'world');
222214
await appFile.writeAsString(newContent);
223215

224216
result = await client.compile([entrypointUri]);
225-
if (result == null) {
226-
fail('Expected compilation to be non-null');
227-
}
228217
client.accept();
229218
expect(result.newSources, isEmpty);
230219
expect(result.removedSources, isEmpty);
@@ -257,9 +246,6 @@ void main() {
257246
entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill,
258247
enabledExperiments: ['non-nullable']);
259248
var result = await client.compile();
260-
if (result == null) {
261-
fail('Expected compilation to be non-null');
262-
}
263249
client.accept();
264250
expect(result.errorCount, 1);
265251
expect(result.compilerOutputLines, contains(contains('int x;')));
@@ -280,9 +266,6 @@ void main() {
280266
client = await FrontendServerClient.start(entrypoint,
281267
p.join(packageRoot, 'out with spaces.dill'), vmPlatformDill);
282268
var result = await client.compile();
283-
if (result == null) {
284-
fail('Expected compilation to be non-null');
285-
}
286269
client.accept();
287270
expect(result.compilerOutputLines, isEmpty);
288271
expect(result.errorCount, 0);
@@ -292,9 +275,10 @@ void main() {
292275
File(entrypoint).uri,
293276
]));
294277
expect(result.removedSources, isEmpty);
295-
expect(File(result.dillOutput).existsSync(), true);
278+
expect(result.dillOutput, isNotNull);
279+
expect(File(result.dillOutput!).existsSync(), true);
296280
var processResult =
297-
await Process.run(Platform.resolvedExecutable, [result.dillOutput]);
281+
await Process.run(Platform.resolvedExecutable, [result.dillOutput!]);
298282

299283
expect(processResult.stdout, startsWith('hello world'));
300284
expect(processResult.exitCode, 0);
@@ -304,16 +288,13 @@ void main() {
304288
var newContent = originalContent.replaceFirst('hello', 'goodbye');
305289
await appFile.writeAsString(newContent);
306290
result = await client.compile([appFile.uri]);
307-
if (result == null) {
308-
fail('Expected compilation to be non-null');
309-
}
310291
expect(result.compilerOutputLines, isEmpty);
311292
expect(result.errorCount, 0);
312293
expect(result.newSources, isEmpty);
313294
expect(result.removedSources, isEmpty);
314295

315296
processResult =
316-
await Process.run(Platform.resolvedExecutable, [result.dillOutput]);
297+
await Process.run(Platform.resolvedExecutable, [result.dillOutput!]);
317298
expect(processResult.stdout, startsWith('goodbye world'));
318299
expect(processResult.exitCode, 0);
319300
});

0 commit comments

Comments
 (0)