Unverified Commit c219e6f3 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Inject KernelCompiler via KernelCompilerFactory (#27211)

parent 59dc909d
......@@ -302,6 +302,7 @@ class AOTSnapshotter {
printTrace('Extra front-end options: $extraFrontEndOptions');
final String depfilePath = fs.path.join(outputPath, 'kernel_compile.d');
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create();
final CompilerOutput compilerOutput = await kernelCompiler.compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
mainPath: mainPath,
......
......@@ -99,6 +99,7 @@ Future<void> build({
if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty)
printTrace('Extra front-end options: $extraFrontEndOptions');
ensureDirectoryExists(applicationKernelFilePath);
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create();
final CompilerOutput compilerOutput = await kernelCompiler.compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
incrementalCompilerByteStorePath: compilationTraceFilePath != null ? null :
......
......@@ -20,10 +20,21 @@ import 'convert.dart';
import 'dart/package_map.dart';
import 'globals.dart';
KernelCompiler get kernelCompiler => context[KernelCompiler];
KernelCompilerFactory get kernelCompilerFactory => context[KernelCompilerFactory];
typedef CompilerMessageConsumer = void Function(String message, {bool emphasis, TerminalColor color});
/// Injectable factory to allow async construction of a [KernelCompiler].
class KernelCompilerFactory {
const KernelCompilerFactory();
/// Return the correct [KernelCompiler] instance for the given project
/// configuration.
FutureOr<KernelCompiler> create() async {
return const KernelCompiler();
}
}
/// The target model describes the set of core libraries that are availible within
/// the SDK.
class TargetModel {
......
......@@ -81,7 +81,7 @@ Future<T> runInContext<T>(
IOSSimulatorUtils: () => IOSSimulatorUtils(),
IOSWorkflow: () => const IOSWorkflow(),
IOSValidator: () => const IOSValidator(),
KernelCompiler: () => const KernelCompiler(),
KernelCompilerFactory: () => const KernelCompilerFactory(),
LinuxWorkflow: () => const LinuxWorkflow(),
Logger: () => platform.isWindows ? WindowsStdoutLogger() : StdoutLogger(),
MacOSWorkflow: () => const MacOSWorkflow(),
......
......@@ -117,6 +117,7 @@ example:org-dartlang-app:///lib/
'result abc\nline1\nline2\nabc /path/to/main.dart.dill 0'
))
));
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create();
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
trackWidgetCreation: false,
......@@ -140,7 +141,7 @@ example:org-dartlang-app:///lib/
'result abc\nline1\nline2\nabc'
))
));
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create();
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
trackWidgetCreation: false,
......@@ -166,7 +167,7 @@ example:org-dartlang-app:///lib/
'result abc\nline1\nline2\nabc'
))
));
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create();
final CompilerOutput output = await kernelCompiler.compile(
sdkRoot: '/path/to/sdkroot',
mainPath: '/path/to/main.dart',
......
......@@ -102,6 +102,7 @@ void main() {
MockArtifacts mockArtifacts;
MockKernelCompiler mockKernelCompiler;
MockProcessManager mockProcessManager;
MockKernelCompilerFactory mockKernelCompilerFactory;
MockProcess mockProcess;
final Map<Type, Generator> startOverrides = <Type, Generator>{
......@@ -109,7 +110,7 @@ void main() {
FileSystem: () => fs,
Cache: () => Cache(rootOverride: fs.directory(flutterRoot)),
ProcessManager: () => mockProcessManager,
KernelCompiler: () => mockKernelCompiler,
KernelCompilerFactory: () => mockKernelCompilerFactory,
Artifacts: () => mockArtifacts,
};
......@@ -135,6 +136,10 @@ void main() {
when(mockArtifacts.getArtifactPath(any)).thenReturn(artifactPath);
mockKernelCompiler = MockKernelCompiler();
mockKernelCompilerFactory = MockKernelCompilerFactory();
when(mockKernelCompilerFactory.create()).thenAnswer((Invocation invocation) async {
return mockKernelCompiler;
});
});
testUsingContext('not debug', () async {
......@@ -194,3 +199,4 @@ Hello!
class MockArtifacts extends Mock implements Artifacts {}
class MockKernelCompiler extends Mock implements KernelCompiler {}
class MockKernelCompilerFactory extends Mock implements KernelCompilerFactory {}
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