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