Initialize from dill on tests (#20414)
This commit is contained in:
@@ -248,14 +248,16 @@ class _CompileExpressionRequest extends _CompilationRequest {
|
||||
class ResidentCompiler {
|
||||
ResidentCompiler(this._sdkRoot, {bool trackWidgetCreation = false,
|
||||
String packagesPath, List<String> fileSystemRoots, String fileSystemScheme ,
|
||||
CompilerMessageConsumer compilerMessageConsumer = printError})
|
||||
CompilerMessageConsumer compilerMessageConsumer = printError,
|
||||
String initializeFromDill})
|
||||
: assert(_sdkRoot != null),
|
||||
_trackWidgetCreation = trackWidgetCreation,
|
||||
_packagesPath = packagesPath,
|
||||
_fileSystemRoots = fileSystemRoots,
|
||||
_fileSystemScheme = fileSystemScheme,
|
||||
_stdoutHandler = new _StdoutHandler(consumer: compilerMessageConsumer),
|
||||
_controller = new StreamController<_CompilationRequest>() {
|
||||
_controller = new StreamController<_CompilationRequest>(),
|
||||
_initializeFromDill = initializeFromDill {
|
||||
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
||||
if (!_sdkRoot.endsWith('/'))
|
||||
_sdkRoot = '$_sdkRoot/';
|
||||
@@ -268,6 +270,7 @@ class ResidentCompiler {
|
||||
String _sdkRoot;
|
||||
Process _server;
|
||||
final _StdoutHandler _stdoutHandler;
|
||||
String _initializeFromDill;
|
||||
|
||||
final StreamController<_CompilationRequest> _controller;
|
||||
|
||||
@@ -362,6 +365,9 @@ class ResidentCompiler {
|
||||
if (_fileSystemScheme != null) {
|
||||
command.addAll(<String>['--filesystem-scheme', _fileSystemScheme]);
|
||||
}
|
||||
if (_initializeFromDill != null) {
|
||||
command.addAll(<String>['--initialize-from-dill', _initializeFromDill]);
|
||||
}
|
||||
printTrace(command.join(' '));
|
||||
_server = await processManager.start(command);
|
||||
_server.stdout
|
||||
|
||||
@@ -18,6 +18,7 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../compile.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart';
|
||||
@@ -74,6 +75,7 @@ void installHook({
|
||||
bool updateGoldens = false,
|
||||
int observatoryPort,
|
||||
InternetAddressType serverType = InternetAddressType.IPv4,
|
||||
Uri projectRootDirectory,
|
||||
}) {
|
||||
assert(!enableObservatory || (!startPaused && observatoryPort == null));
|
||||
hack.registerPlatformPlugin(
|
||||
@@ -91,6 +93,7 @@ void installHook({
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
projectRootDirectory: projectRootDirectory,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -198,7 +201,7 @@ class _CompilationRequest {
|
||||
// This class is a wrapper around compiler that allows multiple isolates to
|
||||
// enqueue compilation requests, but ensures only one compilation at a time.
|
||||
class _Compiler {
|
||||
_Compiler(bool trackWidgetCreation) {
|
||||
_Compiler(bool trackWidgetCreation, Uri projectRootDirectory) {
|
||||
// Compiler maintains and updates single incremental dill file.
|
||||
// Incremental compilation requests done for each test copy that file away
|
||||
// for independent execution.
|
||||
@@ -223,12 +226,15 @@ class _Compiler {
|
||||
printError('$message');
|
||||
}
|
||||
|
||||
final String testFilePath = fs.path.join(fs.path.fromUri(projectRootDirectory), getBuildDirectory(), 'testfile.dill');
|
||||
|
||||
ResidentCompiler createCompiler() {
|
||||
return new ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
packagesPath: PackageMap.globalPackagesPath,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
compilerMessageConsumer: reportCompilerMessage,
|
||||
initializeFromDill: testFilePath
|
||||
);
|
||||
}
|
||||
|
||||
@@ -244,7 +250,11 @@ class _Compiler {
|
||||
final _CompilationRequest request = compilationQueue.first;
|
||||
printTrace('Compiling ${request.path}');
|
||||
final Stopwatch compilerTime = new Stopwatch()..start();
|
||||
compiler ??= createCompiler();
|
||||
bool firstCompile = false;
|
||||
if (compiler == null) {
|
||||
compiler = createCompiler();
|
||||
firstCompile = true;
|
||||
}
|
||||
suppressOutput = false;
|
||||
final CompilerOutput compilerOutput = await handleTimeout<CompilerOutput>(
|
||||
compiler.recompile(
|
||||
@@ -262,8 +272,16 @@ class _Compiler {
|
||||
request.result.complete(null);
|
||||
await _shutdown();
|
||||
} else {
|
||||
final File kernelReadyToRun =
|
||||
await fs.file(outputPath).copy('${request.path}.dill');
|
||||
final File outputFile = fs.file(outputPath);
|
||||
final File kernelReadyToRun = await outputFile.copy('${request.path}.dill');
|
||||
final File testCache = fs.file(testFilePath);
|
||||
if (firstCompile || !testCache.existsSync() || (testCache.lengthSync() < outputFile.lengthSync())) {
|
||||
// The idea is to keep the cache file up-to-date and include as
|
||||
// much as possible in an effort to re-use as many packages as
|
||||
// possible.
|
||||
ensureDirectoryExists(testFilePath);
|
||||
await outputFile.copy(testFilePath);
|
||||
}
|
||||
request.result.complete(kernelReadyToRun.path);
|
||||
compiler.accept();
|
||||
compiler.reset();
|
||||
@@ -326,6 +344,7 @@ class _FlutterPlatform extends PlatformPlugin {
|
||||
this.precompiledDillPath,
|
||||
this.trackWidgetCreation,
|
||||
this.updateGoldens,
|
||||
this.projectRootDirectory,
|
||||
}) : assert(shellPath != null);
|
||||
|
||||
final String shellPath;
|
||||
@@ -340,6 +359,7 @@ class _FlutterPlatform extends PlatformPlugin {
|
||||
final String precompiledDillPath;
|
||||
final bool trackWidgetCreation;
|
||||
final bool updateGoldens;
|
||||
final Uri projectRootDirectory;
|
||||
|
||||
Directory fontsDirectory;
|
||||
_Compiler compiler;
|
||||
@@ -437,7 +457,7 @@ class _FlutterPlatform extends PlatformPlugin {
|
||||
|
||||
if (previewDart2 && precompiledDillPath == null) {
|
||||
// Lazily instantiate compiler so it is built only if it is actually used.
|
||||
compiler ??= new _Compiler(trackWidgetCreation);
|
||||
compiler ??= new _Compiler(trackWidgetCreation, projectRootDirectory);
|
||||
mainDart = await compiler.compile(mainDart);
|
||||
|
||||
if (mainDart == null) {
|
||||
|
||||
@@ -87,6 +87,7 @@ Future<int> runTests(
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
projectRootDirectory: fs.currentDirectory.uri,
|
||||
);
|
||||
|
||||
// Make the global packages path absolute.
|
||||
|
||||
Reference in New Issue
Block a user