Restructure hot mode test so it runs interactively. (#12519)
* Restructure hot mode test so it runs interactively. This allows to add a benchmark for hot reload after actual source code change. * Add curly braces, refactory copyRecursive
This commit is contained in:
committed by
GitHub
parent
0999fca99d
commit
be1467e0cd
@@ -98,6 +98,21 @@ void copy(File sourceFile, Directory targetDirectory, {String name}) {
|
||||
target.writeAsBytesSync(sourceFile.readAsBytesSync());
|
||||
}
|
||||
|
||||
void recursiveCopy(Directory source, Directory target) {
|
||||
if (!target.existsSync())
|
||||
target.createSync();
|
||||
|
||||
for (FileSystemEntity entity in source.listSync(followLinks: false)) {
|
||||
final String name = path.basename(entity.path);
|
||||
if (entity is Directory)
|
||||
recursiveCopy(entity, new Directory(path.join(target.path, name)));
|
||||
else if (entity is File) {
|
||||
final File dest = new File(path.join(target.path, name));
|
||||
dest.writeAsBytesSync(entity.readAsBytesSync());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileSystemEntity move(FileSystemEntity whatToMove,
|
||||
{Directory to, String name}) {
|
||||
return whatToMove
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -10,30 +12,81 @@ import '../framework/adb.dart';
|
||||
import '../framework/framework.dart';
|
||||
import '../framework/utils.dart';
|
||||
|
||||
final Directory _editedFlutterGalleryDir = dir(path.join(Directory.systemTemp.path, 'edited_flutter_gallery'));
|
||||
final Directory flutterGalleryDir = dir(path.join(flutterDirectory.path, 'examples/flutter_gallery'));
|
||||
|
||||
TaskFunction createHotModeTest({ bool isPreviewDart2: false }) {
|
||||
return () async {
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
final Directory appDir =
|
||||
dir(path.join(flutterDirectory.path, 'examples/flutter_gallery'));
|
||||
final File benchmarkFile = file(path.join(appDir.path, 'hot_benchmark.json'));
|
||||
final File benchmarkFile = file(path.join(_editedFlutterGalleryDir.path, 'hot_benchmark.json'));
|
||||
rm(benchmarkFile);
|
||||
final List<String> options = <String>[
|
||||
'--hot', '-d', device.deviceId, '--benchmark', '--verbose'
|
||||
'--hot', '-d', device.deviceId, '--benchmark', '--verbose', '--resident'
|
||||
];
|
||||
if (isPreviewDart2)
|
||||
options.add('--preview-dart-2');
|
||||
await inDirectory(appDir, () async {
|
||||
return await flutter('run', options: options, canFail: false);
|
||||
int hotReloadCount = 0;
|
||||
await inDirectory(flutterDirectory, () async {
|
||||
rmTree(_editedFlutterGalleryDir);
|
||||
mkdirs(_editedFlutterGalleryDir);
|
||||
recursiveCopy(flutterGalleryDir, _editedFlutterGalleryDir);
|
||||
await inDirectory(_editedFlutterGalleryDir, () async {
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
<String>['run']..addAll(options),
|
||||
environment: null
|
||||
);
|
||||
|
||||
final Completer<Null> stdoutDone = new Completer<Null>();
|
||||
final Completer<Null> stderrDone = new Completer<Null>();
|
||||
process.stdout
|
||||
.transform(UTF8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
if (line.contains('\] Hot reload performed in')) {
|
||||
if (hotReloadCount == 0) {
|
||||
// Update the file and reload again.
|
||||
final File appDartSource = file(path.join(
|
||||
_editedFlutterGalleryDir.path, 'lib/gallery/app.dart'
|
||||
));
|
||||
appDartSource.writeAsStringSync(
|
||||
appDartSource.readAsStringSync().replaceFirst(
|
||||
"'Flutter Gallery'", "'Updated Flutter Gallery'"
|
||||
)
|
||||
);
|
||||
process.stdin.writeln('r');
|
||||
++hotReloadCount;
|
||||
} else {
|
||||
// Quit after second hot reload.
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
}
|
||||
print('stdout: $line');
|
||||
}, onDone: () { stdoutDone.complete(); });
|
||||
process.stderr
|
||||
.transform(UTF8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
print('stderr: $line');
|
||||
}, onDone: () { stderrDone.complete(); });
|
||||
|
||||
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]);
|
||||
return await process.exitCode;
|
||||
});
|
||||
});
|
||||
final Map<String, dynamic> twoReloadsData = JSON.decode(
|
||||
benchmarkFile.readAsStringSync());
|
||||
return new TaskResult.success(<String, dynamic> {
|
||||
'hotReloadInitialDevFSSyncMilliseconds': twoReloadsData['hotReloadInitialDevFSSyncMilliseconds'][0],
|
||||
'hotRestartMillisecondsToFrame': twoReloadsData['hotRestartMillisecondsToFrame'][0],
|
||||
'hotReloadMillisecondsToFrame' : twoReloadsData['hotReloadMillisecondsToFrame'][0],
|
||||
'hotReloadDevFSSyncMilliseconds': twoReloadsData['hotReloadDevFSSyncMilliseconds'][0],
|
||||
'hotReloadFlutterReassembleMilliseconds': twoReloadsData['hotReloadFlutterReassembleMilliseconds'][0],
|
||||
'hotReloadVMReloadMilliseconds': twoReloadsData['hotReloadVMReloadMilliseconds'][0],
|
||||
'hotReloadDevFSSyncMillisecondsAfterChange': twoReloadsData['hotReloadDevFSSyncMilliseconds'][1],
|
||||
'hotReloadFlutterReassembleMillisecondsAfterChange': twoReloadsData['hotReloadFlutterReassembleMilliseconds'][1],
|
||||
'hotReloadVMReloadMillisecondsAfterChange': twoReloadsData['hotReloadVMReloadMilliseconds'][1]
|
||||
});
|
||||
return new TaskResult.successFromFile(benchmarkFile,
|
||||
benchmarkScoreKeys: <String>[
|
||||
'hotReloadInitialDevFSSyncMilliseconds',
|
||||
'hotReloadMillisecondsToFrame',
|
||||
'hotRestartMillisecondsToFrame',
|
||||
'hotReloadDevFSSyncMilliseconds',
|
||||
'hotReloadFlutterReassembleMilliseconds',
|
||||
'hotReloadVMReloadMilliseconds',
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user