Inject KernelCompiler via KernelCompilerFactory (#27211)

This commit is contained in:
Jonah Williams
2019-01-30 08:34:01 -08:00
committed by GitHub
parent 59dc909d0f
commit c219e6f3b1
6 changed files with 25 additions and 5 deletions

View File

@@ -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,

View File

@@ -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 :

View File

@@ -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 {

View File

@@ -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(),

View File

@@ -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',

View File

@@ -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 {}