Unverified Commit 4bcf8fb4 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate compile to null safety (#83153)

parent ade6e1f9
This diff is collapsed.
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart';
......@@ -24,10 +22,10 @@ void main() {
stdoutHandler.reset();
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'.split('\n').forEach(stdoutHandler.handler);
final CompilerOutput output = await stdoutHandler.compilerOutput.future;
final CompilerOutput? output = await stdoutHandler.compilerOutput?.future;
expect(logger.errorText, equals('line1\nline2\n'));
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
});
testWithoutContext('StdoutHandler can parse output for failed batch compilation', () async {
......@@ -36,7 +34,7 @@ void main() {
stdoutHandler.reset();
'result abc\nline1\nline2\nabc\nabc'.split('\n').forEach(stdoutHandler.handler);
final CompilerOutput output = await stdoutHandler.compilerOutput.future;
final CompilerOutput? output = await stdoutHandler.compilerOutput?.future;
expect(logger.errorText, equals('line1\nline2\n'));
expect(output, equals(null));
......@@ -73,7 +71,7 @@ void main() {
]),
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -81,10 +79,10 @@ void main() {
packageConfig: PackageConfig.empty,
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect((await output).outputFilename, '');
expect((await output)?.outputFilename, '');
});
testWithoutContext('KernelCompiler returns null if StdoutHandler returns null', () async {
......@@ -118,7 +116,7 @@ void main() {
]),
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -126,7 +124,7 @@ void main() {
packageConfig: PackageConfig.empty,
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(null);
stdoutHandler.compilerOutput?.complete(null);
completer.complete();
expect(await output, null);
......@@ -163,7 +161,7 @@ void main() {
]),
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -171,7 +169,7 @@ void main() {
packageConfig: PackageConfig.empty,
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect(await output, null);
......@@ -209,7 +207,7 @@ void main() {
]),
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.profile,
trackWidgetCreation: false,
......@@ -218,10 +216,10 @@ void main() {
packageConfig: PackageConfig.empty,
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect((await output).outputFilename, '');
expect((await output)?.outputFilename, '');
});
testWithoutContext('passes correct AOT config to kernel compiler in aot/release mode', () async {
......@@ -256,7 +254,7 @@ void main() {
]),
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.release,
trackWidgetCreation: false,
......@@ -265,10 +263,10 @@ void main() {
packageConfig: PackageConfig.empty,
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect((await output).outputFilename, '');
expect((await output)?.outputFilename, '');
});
testWithoutContext('KernelCompiler passes dartDefines to the frontend_server', () async {
......@@ -305,7 +303,7 @@ void main() {
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -314,10 +312,10 @@ void main() {
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect((await output).outputFilename, '');
expect((await output)?.outputFilename, '');
});
testWithoutContext('KernelCompiler maps a file to a multi-root scheme if provided', () async {
......@@ -354,7 +352,7 @@ void main() {
stdoutHandler: stdoutHandler,
);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/foo/bar/fizz/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -363,10 +361,10 @@ void main() {
packagesPath: '.packages',
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
expect((await output).outputFilename, '');
expect((await output)?.outputFilename, '');
});
testWithoutContext('KernelCompiler uses generated entrypoint', () async {
......@@ -409,7 +407,7 @@ void main() {
buildDir.parent.childFile('generated_main.dart').createSync(recursive: true);
final Future<CompilerOutput> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
final Future<CompilerOutput?> output = kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/foo/bar/fizz/main.dart',
buildMode: BuildMode.debug,
trackWidgetCreation: false,
......@@ -420,7 +418,7 @@ void main() {
checkDartPluginRegistry: true,
);
stdoutHandler.compilerOutput.complete(const CompilerOutput('', 0, <Uri>[]));
stdoutHandler.compilerOutput?.complete(const CompilerOutput('', 0, <Uri>[]));
completer.complete();
await output;
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart';
......@@ -24,12 +22,12 @@ import '../src/fake_process_manager.dart';
import '../src/fakes.dart';
void main() {
FakeProcessManager processManager;
ResidentCompiler generator;
MemoryIOSink frontendServerStdIn;
StreamController<String> stdErrStreamController;
BufferLogger testLogger;
MemoryFileSystem fileSystem;
late FakeProcessManager processManager;
late ResidentCompiler generator;
late MemoryIOSink frontendServerStdIn;
late StreamController<String> stdErrStreamController;
late BufferLogger testLogger;
late MemoryFileSystem fileSystem;
setUp(() {
testLogger = BufferLogger.test();
......@@ -52,7 +50,7 @@ void main() {
});
testWithoutContext('compile expression fails if not previously compiled', () async {
final CompilerOutput result = await generator.compileExpression(
final CompilerOutput? result = await generator.compileExpression(
'2+2', null, null, null, null, false);
expect(result, isNull);
......@@ -82,12 +80,12 @@ void main() {
packageConfig: PackageConfig.empty,
projectRootPath: '',
fs: fileSystem,
).then((CompilerOutput output) {
).then((CompilerOutput? output) {
expect(frontendServerStdIn.getAndClear(),
'compile file:///path/to/main.dart\n');
expect(testLogger.errorText,
equals('line1\nline2\n'));
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
expect(output!.outputFilename, equals('/path/to/main.dart.dill'));
compileExpressionResponseCompleter.complete(
Future<List<int>>.value(utf8.encode(
......@@ -95,9 +93,9 @@ void main() {
)));
generator.compileExpression(
'2+2', null, null, null, null, false).then(
(CompilerOutput outputExpression) {
(CompilerOutput? outputExpression) {
expect(outputExpression, isNotNull);
expect(outputExpression.expressionData, <int>[1, 2, 3, 4]);
expect(outputExpression!.expressionData, <int>[1, 2, 3, 4]);
}
);
});
......@@ -126,10 +124,10 @@ void main() {
packageConfig: PackageConfig.empty,
projectRootPath: '',
fs: MemoryFileSystem(),
).then((CompilerOutput outputCompile) {
).then((CompilerOutput? outputCompile) {
expect(testLogger.errorText,
equals('line1\nline2\n'));
expect(outputCompile.outputFilename, equals('/path/to/main.dart.dill'));
expect(outputCompile!.outputFilename, equals('/path/to/main.dart.dill'));
fileSystem.file('/path/to/main.dart.dill.incremental')
..createSync(recursive: true)
......@@ -144,9 +142,9 @@ void main() {
final Completer<bool> lastExpressionCompleted = Completer<bool>();
unawaited(
generator.compileExpression('0+1', null, null, null, null, false).then(
(CompilerOutput outputExpression) {
(CompilerOutput? outputExpression) {
expect(outputExpression, isNotNull);
expect(outputExpression.expressionData, <int>[0, 1, 2, 3]);
expect(outputExpression!.expressionData, <int>[0, 1, 2, 3]);
fileSystem.file('/path/to/main.dart.dill.incremental')
..createSync(recursive: true)
......@@ -161,9 +159,9 @@ void main() {
// The test manages timing via completers.
unawaited(
generator.compileExpression('1+1', null, null, null, null, false).then(
(CompilerOutput outputExpression) {
(CompilerOutput? outputExpression) {
expect(outputExpression, isNotNull);
expect(outputExpression.expressionData, <int>[4, 5, 6, 7]);
expect(outputExpression!.expressionData, <int>[4, 5, 6, 7]);
lastExpressionCompleted.complete(true);
},
),
......@@ -179,13 +177,13 @@ void main() {
class FakeProcess extends Fake implements Process {
@override
Stream<List<int>> stdout;
Stream<List<int>> stdout = const Stream<List<int>>.empty();
@override
Stream<List<int>> stderr;
Stream<List<int>> stderr = const Stream<List<int>>.empty();
@override
IOSink stdin;
IOSink stdin = IOSink(StreamController<List<int>>().sink);
@override
Future<int> get exitCode => Completer<int>().future;
......@@ -195,12 +193,12 @@ class FakeProcessManager extends Fake implements ProcessManager {
final FakeProcess process = FakeProcess();
@override
bool canRun(dynamic executable, {String workingDirectory}) {
bool canRun(dynamic executable, {String? workingDirectory}) {
return true;
}
@override
Future<Process> start(List<Object> command, {String workingDirectory, Map<String, String> environment, bool includeParentEnvironment = true, bool runInShell = false, ProcessStartMode mode = ProcessStartMode.normal}) async {
Future<Process> start(List<Object> command, {String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false, ProcessStartMode mode = ProcessStartMode.normal}) async {
return process;
}
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart';
......@@ -21,13 +19,13 @@ import '../src/fake_process_manager.dart';
import '../src/fakes.dart';
void main() {
ResidentCompiler generator;
ResidentCompiler generatorWithScheme;
MemoryIOSink frontendServerStdIn;
BufferLogger testLogger;
StdoutHandler generatorStdoutHandler;
StdoutHandler generatorWithSchemeStdoutHandler;
FakeProcessManager fakeProcessManager;
late ResidentCompiler generator;
late ResidentCompiler generatorWithScheme;
late MemoryIOSink frontendServerStdIn;
late BufferLogger testLogger;
late StdoutHandler generatorStdoutHandler;
late StdoutHandler generatorWithSchemeStdoutHandler;
late FakeProcessManager fakeProcessManager;
const List<String> frontendServerCommand = <String>[
'HostArtifact.engineDartBinary',
......@@ -87,7 +85,7 @@ void main() {
stdin: frontendServerStdIn,
));
final CompilerOutput output = await generator.recompile(
final CompilerOutput? output = await generator.recompile(
Uri.parse('/path/to/main.dart'),
null /* invalidatedFiles */,
outputPath: '/build/',
......@@ -97,7 +95,7 @@ void main() {
);
expect(frontendServerStdIn.getAndClear(), 'compile /path/to/main.dart\n');
expect(testLogger.errorText, equals('line1\nline2\n'));
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
expect(fakeProcessManager, hasNoRemainingExpectations);
});
......@@ -114,7 +112,7 @@ void main() {
stdin: frontendServerStdIn,
));
final CompilerOutput output = await generatorWithScheme.recompile(
final CompilerOutput? output = await generatorWithScheme.recompile(
Uri.parse('file:///foo/bar/fizz/main.dart'),
null /* invalidatedFiles */,
outputPath: '/build/',
......@@ -124,7 +122,7 @@ void main() {
);
expect(frontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
expect(testLogger.errorText, equals('line1\nline2\n'));
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
expect(fakeProcessManager, hasNoRemainingExpectations);
});
......@@ -401,16 +399,16 @@ Future<void> _recompile(
MemoryIOSink frontendServerStdIn,
String mockCompilerOutput, {
bool suppressErrors = false,
Uri mainUri,
Uri? mainUri,
String expectedMainUri = '/path/to/main.dart',
List<Uri> updatedUris,
List<String> expectedUpdatedUris,
List<Uri>? updatedUris,
List<String>? expectedUpdatedUris,
}) async {
mainUri ??= Uri.parse('/path/to/main.dart');
updatedUris ??= <Uri>[mainUri];
expectedUpdatedUris ??= <String>[expectedMainUri];
final Future<CompilerOutput> recompileFuture = generator.recompile(
final Future<CompilerOutput?> recompileFuture = generator.recompile(
mainUri,
updatedUris,
outputPath: '/build/',
......@@ -425,8 +423,8 @@ Future<void> _recompile(
scheduleMicrotask(() {
LineSplitter.split(mockCompilerOutput).forEach(stdoutHandler.handler);
});
final CompilerOutput output = await recompileFuture;
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
final CompilerOutput? output = await recompileFuture;
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
final String commands = frontendServerStdIn.getAndClear();
final RegExp whitespace = RegExp(r'\s+');
final List<String> parts = commands.split(whitespace);
......@@ -459,11 +457,11 @@ Future<void> _reject(
) async {
// Put content into the output stream after generator.recompile gets
// going few lines below, resets completer.
final Future<CompilerOutput> rejectFuture = generator.reject();
final Future<CompilerOutput?> rejectFuture = generator.reject();
scheduleMicrotask(() {
LineSplitter.split(mockCompilerOutput).forEach(stdoutHandler.handler);
});
final CompilerOutput output = await rejectFuture;
final CompilerOutput? output = await rejectFuture;
expect(output, isNull);
final String commands = frontendServerStdIn.getAndClear();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart';
......@@ -19,10 +17,10 @@ void main() {
expect(stdoutHandler.boundaryKey, '12345');
stdoutHandler.handler('12345');
stdoutHandler.handler('12345 message 0');
final CompilerOutput output = await stdoutHandler.compilerOutput.future;
expect(output.errorCount, 0);
expect(output.outputFilename, 'message');
expect(output.expressionData, null);
final CompilerOutput? output = await stdoutHandler.compilerOutput?.future;
expect(output?.errorCount, 0);
expect(output?.outputFilename, 'message');
expect(output?.expressionData, null);
});
testWithoutContext('StdoutHandler can read output bytes', () async {
......@@ -35,11 +33,11 @@ void main() {
expect(stdoutHandler.boundaryKey, '12345');
stdoutHandler.handler('12345');
stdoutHandler.handler('12345 message 0');
final CompilerOutput output = await stdoutHandler.compilerOutput.future;
final CompilerOutput? output = await stdoutHandler.compilerOutput?.future;
expect(output.errorCount, 0);
expect(output.outputFilename, 'message');
expect(output.expressionData, <int>[1, 2, 3, 4]);
expect(output?.errorCount, 0);
expect(output?.outputFilename, 'message');
expect(output?.expressionData, <int>[1, 2, 3, 4]);
});
testWithoutContext('StdoutHandler reads output bytes if errorCount > 0', () async {
......@@ -52,11 +50,11 @@ void main() {
expect(stdoutHandler.boundaryKey, '12345');
stdoutHandler.handler('12345');
stdoutHandler.handler('12345 message 1');
final CompilerOutput output = await stdoutHandler.compilerOutput.future;
final CompilerOutput? output = await stdoutHandler.compilerOutput?.future;
expect(output.errorCount, 1);
expect(output.outputFilename, 'message');
expect(output.expressionData, <int>[1, 2, 3, 4]);
expect(output?.errorCount, 1);
expect(output?.outputFilename, 'message');
expect(output?.expressionData, <int>[1, 2, 3, 4]);
});
testWithoutContext('TargetModel values', () {
......@@ -72,7 +70,7 @@ void main() {
expect(TargetModel('dartdevc'), TargetModel.dartdevc);
expect(TargetModel.dartdevc.toString(), 'dartdevc');
expect(() => TargetModel('foobar'), throwsAssertionError);
expect(() => TargetModel('foobar'), throwsException);
});
testWithoutContext('toMultiRootPath maps different URIs', () async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment