Unverified Commit 398ac1f6 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Remove some async file io (#38654)

parent 28bedb10
...@@ -179,12 +179,12 @@ Future<File> _createLocalCrashReport(List<String> args, dynamic error, StackTrac ...@@ -179,12 +179,12 @@ Future<File> _createLocalCrashReport(List<String> args, dynamic error, StackTrac
buffer.writeln('```\n${await _doctorText()}```'); buffer.writeln('```\n${await _doctorText()}```');
try { try {
await crashFile.writeAsString(buffer.toString()); crashFile.writeAsStringSync(buffer.toString());
} on FileSystemException catch (_) { } on FileSystemException catch (_) {
// Fallback to the system temporary directory. // Fallback to the system temporary directory.
crashFile = getUniqueFile(crashFileSystem.systemTempDirectory, 'flutter', 'log'); crashFile = getUniqueFile(crashFileSystem.systemTempDirectory, 'flutter', 'log');
try { try {
await crashFile.writeAsString(buffer.toString()); crashFile.writeAsStringSync(buffer.toString());
} on FileSystemException catch (e) { } on FileSystemException catch (e) {
printError('Could not write crash report to disk: $e'); printError('Could not write crash report to disk: $e');
printError(buffer.toString()); printError(buffer.toString());
......
...@@ -235,7 +235,7 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -235,7 +235,7 @@ class _ManifestAssetBundle implements AssetBundle {
entries[_fontManifestJson] = DevFSStringContent(json.encode(fonts)); entries[_fontManifestJson] = DevFSStringContent(json.encode(fonts));
// TODO(ianh): Only do the following line if we've changed packages or if our LICENSE file changed // TODO(ianh): Only do the following line if we've changed packages or if our LICENSE file changed
entries[_license] = await _obtainLicenses(packageMap, assetBasePath, reportPackages: reportLicensedPackages); entries[_license] = _obtainLicenses(packageMap, assetBasePath, reportPackages: reportLicensedPackages);
return 0; return 0;
} }
...@@ -325,11 +325,11 @@ List<_Asset> _getMaterialAssets(String fontSet) { ...@@ -325,11 +325,11 @@ List<_Asset> _getMaterialAssets(String fontSet) {
final String _licenseSeparator = '\n' + ('-' * 80) + '\n'; final String _licenseSeparator = '\n' + ('-' * 80) + '\n';
/// Returns a DevFSContent representing the license file. /// Returns a DevFSContent representing the license file.
Future<DevFSContent> _obtainLicenses( DevFSContent _obtainLicenses(
PackageMap packageMap, PackageMap packageMap,
String assetBase, { String assetBase, {
bool reportPackages, bool reportPackages,
}) async { }) {
// Read the LICENSE file from each package in the .packages file, splitting // Read the LICENSE file from each package in the .packages file, splitting
// each one into each component license (so that we can de-dupe if possible). // each one into each component license (so that we can de-dupe if possible).
// //
...@@ -347,30 +347,32 @@ Future<DevFSContent> _obtainLicenses( ...@@ -347,30 +347,32 @@ Future<DevFSContent> _obtainLicenses(
final Set<String> allPackages = <String>{}; final Set<String> allPackages = <String>{};
for (String packageName in packageMap.map.keys) { for (String packageName in packageMap.map.keys) {
final Uri package = packageMap.map[packageName]; final Uri package = packageMap.map[packageName];
if (package != null && package.scheme == 'file') { if (package == null || package.scheme != 'file') {
final File file = fs.file(package.resolve('../LICENSE')); continue;
if (file.existsSync()) { }
final List<String> rawLicenses = final File file = fs.file(package.resolve('../LICENSE'));
(await file.readAsString()).split(_licenseSeparator); if (!file.existsSync()) {
for (String rawLicense in rawLicenses) { continue;
List<String> packageNames; }
String licenseText; final List<String> rawLicenses =
if (rawLicenses.length > 1) { file.readAsStringSync().split(_licenseSeparator);
final int split = rawLicense.indexOf('\n\n'); for (String rawLicense in rawLicenses) {
if (split >= 0) { List<String> packageNames;
packageNames = rawLicense.substring(0, split).split('\n'); String licenseText;
licenseText = rawLicense.substring(split + 2); if (rawLicenses.length > 1) {
} final int split = rawLicense.indexOf('\n\n');
} if (split >= 0) {
if (licenseText == null) { packageNames = rawLicense.substring(0, split).split('\n');
packageNames = <String>[packageName]; licenseText = rawLicense.substring(split + 2);
licenseText = rawLicense;
}
packageLicenses.putIfAbsent(licenseText, () => <String>{})
..addAll(packageNames);
allPackages.addAll(packageNames);
} }
} }
if (licenseText == null) {
packageNames = <String>[packageName];
licenseText = rawLicense;
}
packageLicenses.putIfAbsent(licenseText, () => <String>{})
..addAll(packageNames);
allPackages.addAll(packageNames);
} }
} }
......
...@@ -180,7 +180,7 @@ class AOTSnapshotter { ...@@ -180,7 +180,7 @@ class AOTSnapshotter {
// gen_snapshot would provide an argument to do this automatically. // gen_snapshot would provide an argument to do this automatically.
if (platform == TargetPlatform.ios && bitcode) { if (platform == TargetPlatform.ios && bitcode) {
final IOSink sink = fs.file('$assembly.bitcode').openWrite(); final IOSink sink = fs.file('$assembly.bitcode').openWrite();
for (String line in await fs.file(assembly).readAsLines()) { for (String line in fs.file(assembly).readAsLinesSync()) {
if (line.startsWith('.section __DWARF')) { if (line.startsWith('.section __DWARF')) {
break; break;
} }
...@@ -192,7 +192,7 @@ class AOTSnapshotter { ...@@ -192,7 +192,7 @@ class AOTSnapshotter {
// Write path to gen_snapshot, since snapshots have to be re-generated when we roll // Write path to gen_snapshot, since snapshots have to be re-generated when we roll
// the Dart SDK. // the Dart SDK.
final String genSnapshotPath = GenSnapshot.getSnapshotterPath(snapshotType); final String genSnapshotPath = GenSnapshot.getSnapshotterPath(snapshotType);
await outputDir.childFile('gen_snapshot.d').writeAsString('gen_snapshot.d: $genSnapshotPath\n'); outputDir.childFile('gen_snapshot.d').writeAsStringSync('gen_snapshot.d: $genSnapshotPath\n');
// On iOS, we use Xcode to compile the snapshot into a dynamic library that the // On iOS, we use Xcode to compile the snapshot into a dynamic library that the
// end-developer can link into their app. // end-developer can link into their app.
...@@ -313,7 +313,7 @@ class AOTSnapshotter { ...@@ -313,7 +313,7 @@ class AOTSnapshotter {
// Write path to frontend_server, since things need to be re-generated when that changes. // Write path to frontend_server, since things need to be re-generated when that changes.
final String frontendPath = artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk); final String frontendPath = artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk);
await fs.directory(outputPath).childFile('frontend_server.d').writeAsString('frontend_server.d: $frontendPath\n'); fs.directory(outputPath).childFile('frontend_server.d').writeAsStringSync('frontend_server.d: $frontendPath\n');
return compilerOutput?.outputFilename; return compilerOutput?.outputFilename;
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:crypto/crypto.dart' show md5; import 'package:crypto/crypto.dart' show md5;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:quiver/core.dart' show hash2; import 'package:quiver/core.dart' show hash2;
...@@ -52,12 +50,12 @@ class Fingerprinter { ...@@ -52,12 +50,12 @@ class Fingerprinter {
final List<String> _depfilePaths; final List<String> _depfilePaths;
final FingerprintPathFilter _pathFilter; final FingerprintPathFilter _pathFilter;
Future<Fingerprint> buildFingerprint() async { Fingerprint buildFingerprint() {
final List<String> paths = await _getPaths(); final List<String> paths = _getPaths();
return Fingerprint.fromBuildInputs(_properties, paths); return Fingerprint.fromBuildInputs(_properties, paths);
} }
Future<bool> doesFingerprintMatch() async { bool doesFingerprintMatch() {
if (_disableBuildCache) { if (_disableBuildCache) {
return false; return false;
} }
...@@ -69,12 +67,12 @@ class Fingerprinter { ...@@ -69,12 +67,12 @@ class Fingerprinter {
if (!_depfilePaths.every(fs.isFileSync)) if (!_depfilePaths.every(fs.isFileSync))
return false; return false;
final List<String> paths = await _getPaths(); final List<String> paths = _getPaths();
if (!paths.every(fs.isFileSync)) if (!paths.every(fs.isFileSync))
return false; return false;
final Fingerprint oldFingerprint = Fingerprint.fromJson(await fingerprintFile.readAsString()); final Fingerprint oldFingerprint = Fingerprint.fromJson(fingerprintFile.readAsStringSync());
final Fingerprint newFingerprint = await buildFingerprint(); final Fingerprint newFingerprint = buildFingerprint();
return oldFingerprint == newFingerprint; return oldFingerprint == newFingerprint;
} catch (e) { } catch (e) {
// Log exception and continue, fingerprinting is only a performance improvement. // Log exception and continue, fingerprinting is only a performance improvement.
...@@ -83,9 +81,9 @@ class Fingerprinter { ...@@ -83,9 +81,9 @@ class Fingerprinter {
return false; return false;
} }
Future<void> writeFingerprint() async { void writeFingerprint() {
try { try {
final Fingerprint fingerprint = await buildFingerprint(); final Fingerprint fingerprint = buildFingerprint();
fs.file(fingerprintPath).writeAsStringSync(fingerprint.toJson()); fs.file(fingerprintPath).writeAsStringSync(fingerprint.toJson());
} catch (e) { } catch (e) {
// Log exception and continue, fingerprinting is only a performance improvement. // Log exception and continue, fingerprinting is only a performance improvement.
...@@ -93,11 +91,11 @@ class Fingerprinter { ...@@ -93,11 +91,11 @@ class Fingerprinter {
} }
} }
Future<List<String>> _getPaths() async { List<String> _getPaths() {
final Set<String> paths = <String>{ final Set<String> paths = <String>{
..._paths, ..._paths,
for (String depfilePath in _depfilePaths) for (String depfilePath in _depfilePaths)
...await readDepfile(depfilePath), ...readDepfile(depfilePath),
}; };
final FingerprintPathFilter filter = _pathFilter ?? (String path) => true; final FingerprintPathFilter filter = _pathFilter ?? (String path) => true;
return paths.where(filter).toList()..sort(); return paths.where(filter).toList()..sort();
...@@ -183,10 +181,10 @@ final RegExp _escapeExpr = RegExp(r'\\(.)'); ...@@ -183,10 +181,10 @@ final RegExp _escapeExpr = RegExp(r'\\(.)');
/// outfile : file1.dart fil\\e2.dart fil\ e3.dart /// outfile : file1.dart fil\\e2.dart fil\ e3.dart
/// ///
/// will return a set containing: 'file1.dart', 'fil\e2.dart', 'fil e3.dart'. /// will return a set containing: 'file1.dart', 'fil\e2.dart', 'fil e3.dart'.
Future<Set<String>> readDepfile(String depfilePath) async { Set<String> readDepfile(String depfilePath) {
// Depfile format: // Depfile format:
// outfile1 outfile2 : file1.dart file2.dart file3.dart // outfile1 outfile2 : file1.dart file2.dart file3.dart
final String contents = await fs.file(depfilePath).readAsString(); final String contents = fs.file(depfilePath).readAsStringSync();
final String dependencies = contents.split(': ')[1]; final String dependencies = contents.split(': ')[1];
return dependencies return dependencies
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'context.dart'; import 'context.dart';
...@@ -25,17 +23,17 @@ Platform get platform => context.get<Platform>() ?? _kLocalPlatform; ...@@ -25,17 +23,17 @@ Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
/// subdirectory. /// subdirectory.
/// ///
/// Returns the existing platform. /// Returns the existing platform.
Future<Platform> getRecordingPlatform(String location) async { Platform getRecordingPlatform(String location) {
final Directory dir = getRecordingSink(location, _kRecordingType); final Directory dir = getRecordingSink(location, _kRecordingType);
final File file = _getPlatformManifest(dir); final File file = _getPlatformManifest(dir);
await file.writeAsString(platform.toJson(), flush: true); file.writeAsStringSync(platform.toJson(), flush: true);
return platform; return platform;
} }
Future<FakePlatform> getReplayPlatform(String location) async { FakePlatform getReplayPlatform(String location) {
final Directory dir = getReplaySource(location, _kRecordingType); final Directory dir = getReplaySource(location, _kRecordingType);
final File file = _getPlatformManifest(dir); final File file = _getPlatformManifest(dir);
final String json = await file.readAsString(); final String json = file.readAsStringSync();
return FakePlatform.fromJson(json); return FakePlatform.fromJson(json);
} }
......
...@@ -15,7 +15,7 @@ import 'utils.dart'; ...@@ -15,7 +15,7 @@ import 'utils.dart';
typedef StringConverter = String Function(String string); typedef StringConverter = String Function(String string);
/// A function that will be run before the VM exits. /// A function that will be run before the VM exits.
typedef ShutdownHook = Future<dynamic> Function(); typedef ShutdownHook = FutureOr<dynamic> Function();
// TODO(ianh): We have way too many ways to run subprocesses in this project. // TODO(ianh): We have way too many ways to run subprocesses in this project.
// Convert most of these into one or more lightweight wrappers around the // Convert most of these into one or more lightweight wrappers around the
...@@ -83,8 +83,12 @@ Future<void> runShutdownHooks() async { ...@@ -83,8 +83,12 @@ Future<void> runShutdownHooks() async {
printTrace('Shutdown hook priority ${stage.priority}'); printTrace('Shutdown hook priority ${stage.priority}');
final List<ShutdownHook> hooks = _shutdownHooks.remove(stage); final List<ShutdownHook> hooks = _shutdownHooks.remove(stage);
final List<Future<dynamic>> futures = <Future<dynamic>>[]; final List<Future<dynamic>> futures = <Future<dynamic>>[];
for (ShutdownHook shutdownHook in hooks) for (ShutdownHook shutdownHook in hooks) {
futures.add(shutdownHook()); final FutureOr<dynamic> result = shutdownHook();
if (result is Future<dynamic>) {
futures.add(result);
}
}
await Future.wait<dynamic>(futures); await Future.wait<dynamic>(futures);
} }
} finally { } finally {
......
...@@ -102,7 +102,7 @@ class BuildRunner extends CodeGenerator { ...@@ -102,7 +102,7 @@ class BuildRunner extends CodeGenerator {
} }
stringBuffer.writeln(' build_runner: ^$kMinimumBuildRunnerVersion'); stringBuffer.writeln(' build_runner: ^$kMinimumBuildRunnerVersion');
stringBuffer.writeln(' build_daemon: $kSupportedBuildDaemonVersion'); stringBuffer.writeln(' build_daemon: $kSupportedBuildDaemonVersion');
await syntheticPubspec.writeAsString(stringBuffer.toString()); syntheticPubspec.writeAsStringSync(stringBuffer.toString());
await pubGet( await pubGet(
context: PubContext.pubGet, context: PubContext.pubGet,
......
...@@ -376,7 +376,7 @@ Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async { ...@@ -376,7 +376,7 @@ Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async {
final Iterable<AssetId> allSrcs = allDeps.expand((Module module) => module.sources); final Iterable<AssetId> allSrcs = allDeps.expand((Module module) => module.sources);
await scratchSpace.ensureAssets(allSrcs, buildStep); await scratchSpace.ensureAssets(allSrcs, buildStep);
final String packageFile = await _createPackageFile(allSrcs, buildStep, scratchSpace); final String packageFile = _createPackageFile(allSrcs, buildStep, scratchSpace);
final String dartPath = dartEntrypointId.path.startsWith('lib/') final String dartPath = dartEntrypointId.path.startsWith('lib/')
? 'package:${dartEntrypointId.package}/' ? 'package:${dartEntrypointId.package}/'
'${dartEntrypointId.path.substring('lib/'.length)}' '${dartEntrypointId.path.substring('lib/'.length)}'
...@@ -430,7 +430,7 @@ Future<void> _copyIfExists( ...@@ -430,7 +430,7 @@ Future<void> _copyIfExists(
/// The filename is based off the MD5 hash of the asset path so that files are /// The filename is based off the MD5 hash of the asset path so that files are
/// unique regarless of situations like `web/foo/bar.dart` vs /// unique regarless of situations like `web/foo/bar.dart` vs
/// `web/foo-bar.dart`. /// `web/foo-bar.dart`.
Future<String> _createPackageFile(Iterable<AssetId> inputSources, BuildStep buildStep, ScratchSpace scratchSpace) async { String _createPackageFile(Iterable<AssetId> inputSources, BuildStep buildStep, ScratchSpace scratchSpace) {
final Uri inputUri = buildStep.inputId.uri; final Uri inputUri = buildStep.inputId.uri;
final String packageFileName = final String packageFileName =
'.package-${md5.convert(inputUri.toString().codeUnits)}'; '.package-${md5.convert(inputUri.toString().codeUnits)}';
...@@ -439,8 +439,7 @@ Future<String> _createPackageFile(Iterable<AssetId> inputSources, BuildStep buil ...@@ -439,8 +439,7 @@ Future<String> _createPackageFile(Iterable<AssetId> inputSources, BuildStep buil
final Set<String> packageNames = inputSources.map((AssetId s) => s.package).toSet(); final Set<String> packageNames = inputSources.map((AssetId s) => s.package).toSet();
final String packagesFileContent = final String packagesFileContent =
packageNames.map((String name) => '$name:packages/$name/').join('\n'); packageNames.map((String name) => '$name:packages/$name/').join('\n');
await packagesFile packagesFile .writeAsStringSync('# Generated for $inputUri\n$packagesFileContent');
.writeAsString('# Generated for $inputUri\n$packagesFileContent');
return packageFileName; return packageFileName;
} }
......
...@@ -49,8 +49,8 @@ class BuildScriptGenerator { ...@@ -49,8 +49,8 @@ class BuildScriptGenerator {
// ignore_for_file: directives_ordering // ignore_for_file: directives_ordering
${library.accept(emitter)}'''); ${library.accept(emitter)}''');
final File output = fs.file(location); final File output = fs.file(location);
await output.create(recursive: true); output.createSync(recursive: true);
await fs.file(location).writeAsString(result); fs.file(location).writeAsStringSync(result);
} on FormatterException { } on FormatterException {
throwToolExit('Generated build script could not be parsed. ' throwToolExit('Generated build script could not be parsed. '
'This is likely caused by a misconfigured builder definition.'); 'This is likely caused by a misconfigured builder definition.');
......
...@@ -99,8 +99,8 @@ class BundleBuilder { ...@@ -99,8 +99,8 @@ class BundleBuilder {
} }
kernelContent = DevFSFileContent(fs.file(compilerOutput.outputFilename)); kernelContent = DevFSFileContent(fs.file(compilerOutput.outputFilename));
await fs.directory(getBuildDirectory()).childFile('frontend_server.d') fs.directory(getBuildDirectory()).childFile('frontend_server.d')
.writeAsString('frontend_server.d: ${artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk)}\n'); .writeAsStringSync('frontend_server.d: ${artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk)}\n');
} }
final AssetBundle assets = await buildAssets( final AssetBundle assets = await buildAssets(
......
...@@ -407,7 +407,7 @@ class CreateCommand extends FlutterCommand { ...@@ -407,7 +407,7 @@ class CreateCommand extends FlutterCommand {
break; break;
} }
if (sampleCode != null) { if (sampleCode != null) {
generatedFileCount += await _applySample(relativeDir, sampleCode); generatedFileCount += _applySample(relativeDir, sampleCode);
} }
printStatus('Wrote $generatedFileCount files.'); printStatus('Wrote $generatedFileCount files.');
printStatus('\nAll done!'); printStatus('\nAll done!');
...@@ -566,13 +566,13 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -566,13 +566,13 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
// documentation website in sampleCode. Returns the difference in the number // documentation website in sampleCode. Returns the difference in the number
// of files after applying the sample, since it also deletes the application's // of files after applying the sample, since it also deletes the application's
// test directory (since the template's test doesn't apply to the sample). // test directory (since the template's test doesn't apply to the sample).
Future<int> _applySample(Directory directory, String sampleCode) async { int _applySample(Directory directory, String sampleCode) {
final File mainDartFile = directory.childDirectory('lib').childFile('main.dart'); final File mainDartFile = directory.childDirectory('lib').childFile('main.dart');
await mainDartFile.create(recursive: true); mainDartFile.createSync(recursive: true);
await mainDartFile.writeAsString(sampleCode); mainDartFile.writeAsStringSync(sampleCode);
final Directory testDir = directory.childDirectory('test'); final Directory testDir = directory.childDirectory('test');
final List<FileSystemEntity> files = testDir.listSync(recursive: true); final List<FileSystemEntity> files = testDir.listSync(recursive: true);
await testDir.delete(recursive: true); testDir.deleteSync(recursive: true);
return -files.length; return -files.length;
} }
......
...@@ -79,9 +79,9 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -79,9 +79,9 @@ class PackagesGetCommand extends FlutterCommand {
return usageValues; return usageValues;
} }
final FlutterProject rootProject = FlutterProject.fromPath(target); final FlutterProject rootProject = FlutterProject.fromPath(target);
final bool hasPlugins = await rootProject.flutterPluginsFile.exists(); final bool hasPlugins = rootProject.flutterPluginsFile.existsSync();
if (hasPlugins) { if (hasPlugins) {
final int numberOfPlugins = (await rootProject.flutterPluginsFile.readAsLines()).length; final int numberOfPlugins = (rootProject.flutterPluginsFile.readAsLinesSync()).length;
usageValues[CustomDimensions.commandPackagesNumberPlugins] = '$numberOfPlugins'; usageValues[CustomDimensions.commandPackagesNumberPlugins] = '$numberOfPlugins';
} else { } else {
usageValues[CustomDimensions.commandPackagesNumberPlugins] = '0'; usageValues[CustomDimensions.commandPackagesNumberPlugins] = '0';
......
...@@ -106,7 +106,7 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -106,7 +106,7 @@ class ScreenshotCommand extends FlutterCommand {
} catch (error) { } catch (error) {
throwToolExit('Error taking screenshot: $error'); throwToolExit('Error taking screenshot: $error');
} }
await showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
} }
Future<void> runSkia(File outputFile) async { Future<void> runSkia(File outputFile) async {
...@@ -115,8 +115,8 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -115,8 +115,8 @@ class ScreenshotCommand extends FlutterCommand {
final IOSink sink = outputFile.openWrite(); final IOSink sink = outputFile.openWrite();
sink.add(base64.decode(skp['skp'])); sink.add(base64.decode(skp['skp']));
await sink.close(); await sink.close();
await showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
await _ensureOutputIsNotJsonRpcError(outputFile); _ensureOutputIsNotJsonRpcError(outputFile);
} }
Future<void> runRasterizer(File outputFile) async { Future<void> runRasterizer(File outputFile) async {
...@@ -125,8 +125,8 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -125,8 +125,8 @@ class ScreenshotCommand extends FlutterCommand {
final IOSink sink = outputFile.openWrite(); final IOSink sink = outputFile.openWrite();
sink.add(base64.decode(response['screenshot'])); sink.add(base64.decode(response['screenshot']));
await sink.close(); await sink.close();
await showOutputFileInfo(outputFile); _showOutputFileInfo(outputFile);
await _ensureOutputIsNotJsonRpcError(outputFile); _ensureOutputIsNotJsonRpcError(outputFile);
} }
Future<Map<String, dynamic>> _invokeVmServiceRpc(String method) async { Future<Map<String, dynamic>> _invokeVmServiceRpc(String method) async {
...@@ -135,18 +135,20 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -135,18 +135,20 @@ class ScreenshotCommand extends FlutterCommand {
return await vmService.vm.invokeRpcRaw(method); return await vmService.vm.invokeRpcRaw(method);
} }
Future<void> _ensureOutputIsNotJsonRpcError(File outputFile) async { void _ensureOutputIsNotJsonRpcError(File outputFile) {
if (await outputFile.length() < 1000) { if (outputFile.lengthSync() >= 1000) {
final String content = await outputFile.readAsString( return;
encoding: const AsciiCodec(allowInvalid: true), }
); final String content = outputFile.readAsStringSync(
if (content.startsWith('{"jsonrpc":"2.0", "error"')) encoding: const AsciiCodec(allowInvalid: true),
throwToolExit('\nIt appears the output file contains an error message, not valid skia output.'); );
if (content.startsWith('{"jsonrpc":"2.0", "error"')) {
throwToolExit('It appears the output file contains an error message, not valid skia output.');
} }
} }
Future<void> showOutputFileInfo(File outputFile) async { void _showOutputFileInfo(File outputFile) {
final int sizeKB = (await outputFile.length()) ~/ 1024; final int sizeKB = (outputFile.lengthSync()) ~/ 1024;
printStatus('Screenshot written to ${fs.path.relative(outputFile.path)} (${sizeKB}kB).'); printStatus('Screenshot written to ${fs.path.relative(outputFile.path)} (${sizeKB}kB).');
} }
} }
...@@ -269,7 +269,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -269,7 +269,7 @@ Future<XcodeBuildResult> buildXcodeProject({
bool codesign = true, bool codesign = true,
bool usesTerminalUi = true, bool usesTerminalUi = true,
}) async { }) async {
if (!await upgradePbxProjWithFlutterAssets(app.project)) if (!upgradePbxProjWithFlutterAssets(app.project))
return XcodeBuildResult(success: false); return XcodeBuildResult(success: false);
if (!_checkXcodeVersion()) if (!_checkXcodeVersion())
...@@ -679,10 +679,10 @@ void _copyServiceDefinitionsManifest(List<Map<String, String>> services, File ma ...@@ -679,10 +679,10 @@ void _copyServiceDefinitionsManifest(List<Map<String, String>> services, File ma
manifest.writeAsStringSync(json.encode(jsonObject), mode: FileMode.write, flush: true); manifest.writeAsStringSync(json.encode(jsonObject), mode: FileMode.write, flush: true);
} }
Future<bool> upgradePbxProjWithFlutterAssets(IosProject project) async { bool upgradePbxProjWithFlutterAssets(IosProject project) {
final File xcodeProjectFile = project.xcodeProjectInfoFile; final File xcodeProjectFile = project.xcodeProjectInfoFile;
assert(await xcodeProjectFile.exists()); assert(xcodeProjectFile.existsSync());
final List<String> lines = await xcodeProjectFile.readAsLines(); final List<String> lines = xcodeProjectFile.readAsLinesSync();
final RegExp oldAssets = RegExp(r'\/\* (flutter_assets|app\.flx)'); final RegExp oldAssets = RegExp(r'\/\* (flutter_assets|app\.flx)');
final StringBuffer buffer = StringBuffer(); final StringBuffer buffer = StringBuffer();
...@@ -697,6 +697,6 @@ Future<bool> upgradePbxProjWithFlutterAssets(IosProject project) async { ...@@ -697,6 +697,6 @@ Future<bool> upgradePbxProjWithFlutterAssets(IosProject project) async {
buffer.writeln(line); buffer.writeln(line);
} }
} }
await xcodeProjectFile.writeAsString(buffer.toString()); xcodeProjectFile.writeAsStringSync(buffer.toString());
return true; return true;
} }
...@@ -38,9 +38,9 @@ Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, ...@@ -38,9 +38,9 @@ Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject,
xcodeProject: xcodeProject, xcodeProject: xcodeProject,
engineDir: flutterFrameworkDir(buildMode), engineDir: flutterFrameworkDir(buildMode),
isSwift: xcodeProject.isSwift, isSwift: xcodeProject.isSwift,
dependenciesChanged: !await fingerprinter.doesFingerprintMatch(), dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
); );
if (didPodInstall) { if (didPodInstall) {
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
} }
} }
...@@ -106,7 +106,7 @@ class CocoaPods { ...@@ -106,7 +106,7 @@ class CocoaPods {
bool isSwift = false, bool isSwift = false,
bool dependenciesChanged = true, bool dependenciesChanged = true,
}) async { }) async {
if (!(await xcodeProject.podfile.exists())) { if (!xcodeProject.podfile.existsSync()) {
throwToolExit('Podfile missing'); throwToolExit('Podfile missing');
} }
if (await _checkPodCondition()) { if (await _checkPodCondition()) {
......
...@@ -747,7 +747,7 @@ abstract class ResidentRunner { ...@@ -747,7 +747,7 @@ abstract class ResidentRunner {
} }
} }
} }
final int sizeKB = (await outputFile.length()) ~/ 1024; final int sizeKB = outputFile.lengthSync() ~/ 1024;
status.stop(); status.stop();
printStatus('Screenshot written to ${fs.path.relative(outputFile.path)} (${sizeKB}kB).'); printStatus('Screenshot written to ${fs.path.relative(outputFile.path)} (${sizeKB}kB).');
} catch (error) { } catch (error) {
......
...@@ -303,15 +303,15 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -303,15 +303,15 @@ class FlutterCommandRunner extends CommandRunner<void> {
..writeln() ..writeln()
..writeln('# rest') ..writeln('# rest')
..writeln(topLevelResults.rest); ..writeln(topLevelResults.rest);
await manifest.writeAsString(buffer.toString(), flush: true); manifest.writeAsStringSync(buffer.toString(), flush: true);
// ZIP the recording up once the recording has been serialized. // ZIP the recording up once the recording has been serialized.
addShutdownHook(() async { addShutdownHook(() {
final File zipFile = getUniqueFile(fs.currentDirectory, 'bugreport', 'zip'); final File zipFile = getUniqueFile(fs.currentDirectory, 'bugreport', 'zip');
os.zip(tempDir, zipFile); os.zip(tempDir, zipFile);
printStatus(userMessages.runnerBugReportFinished(zipFile.basename)); printStatus(userMessages.runnerBugReportFinished(zipFile.basename));
}, ShutdownStage.POST_PROCESS_RECORDING); }, ShutdownStage.POST_PROCESS_RECORDING);
addShutdownHook(() => tempDir.delete(recursive: true), ShutdownStage.CLEANUP); addShutdownHook(() => tempDir.deleteSync(recursive: true), ShutdownStage.CLEANUP);
} }
assert(recordTo == null || replayFrom == null); assert(recordTo == null || replayFrom == null);
...@@ -323,7 +323,7 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -323,7 +323,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
contextOverrides.addAll(<Type, dynamic>{ contextOverrides.addAll(<Type, dynamic>{
ProcessManager: getRecordingProcessManager(recordTo), ProcessManager: getRecordingProcessManager(recordTo),
FileSystem: getRecordingFileSystem(recordTo), FileSystem: getRecordingFileSystem(recordTo),
Platform: await getRecordingPlatform(recordTo), Platform: getRecordingPlatform(recordTo),
}); });
VMService.enableRecordingConnection(recordTo); VMService.enableRecordingConnection(recordTo);
} }
...@@ -335,7 +335,7 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -335,7 +335,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
contextOverrides.addAll(<Type, dynamic>{ contextOverrides.addAll(<Type, dynamic>{
ProcessManager: await getReplayProcessManager(replayFrom), ProcessManager: await getReplayProcessManager(replayFrom),
FileSystem: getReplayFileSystem(replayFrom), FileSystem: getReplayFileSystem(replayFrom),
Platform: await getReplayPlatform(replayFrom), Platform: getReplayPlatform(replayFrom),
}); });
VMService.enableReplayConnection(replayFrom); VMService.enableReplayConnection(replayFrom);
} }
......
...@@ -78,12 +78,14 @@ Future<void> downloadStartupTrace(VMService observatory, { bool awaitFirstFrame ...@@ -78,12 +78,14 @@ Future<void> downloadStartupTrace(VMService observatory, { bool awaitFirstFrame
final File traceInfoFile = fs.file(traceInfoFilePath); final File traceInfoFile = fs.file(traceInfoFilePath);
// Delete old startup data, if any. // Delete old startup data, if any.
if (await traceInfoFile.exists()) if (traceInfoFile.existsSync()) {
await traceInfoFile.delete(); traceInfoFile.deleteSync();
}
// Create "build" directory, if missing. // Create "build" directory, if missing.
if (!(await traceInfoFile.parent.exists())) if (!traceInfoFile.parent.existsSync()) {
await traceInfoFile.parent.create(); traceInfoFile.parent.createSync();
}
final Tracing tracing = Tracing(observatory); final Tracing tracing = Tracing(observatory);
......
...@@ -99,8 +99,9 @@ class FlutterVersion { ...@@ -99,8 +99,9 @@ class FlutterVersion {
String get engineRevision => Cache.instance.engineRevision; String get engineRevision => Cache.instance.engineRevision;
String get engineRevisionShort => _shortGitRevision(engineRevision); String get engineRevisionShort => _shortGitRevision(engineRevision);
Future<void> ensureVersionFile() async { Future<void> ensureVersionFile() {
fs.file(fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion); fs.file(fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion);
return Future<void>.value();
} }
@override @override
......
...@@ -24,7 +24,7 @@ const String _kData = 'data'; ...@@ -24,7 +24,7 @@ const String _kData = 'data';
class RecordingVMServiceChannel extends DelegatingStreamChannel<String> { class RecordingVMServiceChannel extends DelegatingStreamChannel<String> {
RecordingVMServiceChannel(StreamChannel<String> delegate, Directory location) RecordingVMServiceChannel(StreamChannel<String> delegate, Directory location)
: super(delegate) { : super(delegate) {
addShutdownHook(() async { addShutdownHook(() {
// Sort the messages such that they are ordered // Sort the messages such that they are ordered
// `[request1, response1, request2, response2, ...]`. This serves no // `[request1, response1, request2, response2, ...]`. This serves no
// purpose other than to make the serialized format more human-readable. // purpose other than to make the serialized format more human-readable.
...@@ -32,7 +32,7 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> { ...@@ -32,7 +32,7 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> {
final File file = _getManifest(location); final File file = _getManifest(location);
final String json = const JsonEncoder.withIndent(' ').convert(_messages); final String json = const JsonEncoder.withIndent(' ').convert(_messages);
await file.writeAsString(json, flush: true); file.writeAsStringSync(json, flush: true);
}, ShutdownStage.SERIALIZE_RECORDING); }, ShutdownStage.SERIALIZE_RECORDING);
} }
......
...@@ -32,10 +32,10 @@ void main() { ...@@ -32,10 +32,10 @@ void main() {
FileSystem: () => fs, FileSystem: () => fs,
}; };
testUsingContext('throws when depfile is malformed', () async { testUsingContext('throws when depfile is malformed', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
await fs.file('depfile').create(); fs.file('depfile').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -46,11 +46,11 @@ void main() { ...@@ -46,11 +46,11 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
expect(() async => await fingerprinter.buildFingerprint(), throwsA(anything)); expect(() => fingerprinter.buildFingerprint(), throwsA(anything));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('creates fingerprint with specified properties and files', () async { testUsingContext('creates fingerprint with specified properties and files', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -60,17 +60,17 @@ void main() { ...@@ -60,17 +60,17 @@ void main() {
'wibble': 'wobble', 'wibble': 'wobble',
}, },
); );
final Fingerprint fingerprint = await fingerprinter.buildFingerprint(); final Fingerprint fingerprint = fingerprinter.buildFingerprint();
expect(fingerprint, Fingerprint.fromBuildInputs(<String, String>{ expect(fingerprint, Fingerprint.fromBuildInputs(<String, String>{
'foo': 'bar', 'foo': 'bar',
'wibble': 'wobble', 'wibble': 'wobble',
}, <String>['a.dart'])); }, <String>['a.dart']));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('creates fingerprint with file checksums', () async { testUsingContext('creates fingerprint with file checksums', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
await fs.file('depfile').writeAsString('depfile : b.dart'); fs.file('depfile').writeAsStringSync('depfile : b.dart');
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -81,16 +81,16 @@ void main() { ...@@ -81,16 +81,16 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
final Fingerprint fingerprint = await fingerprinter.buildFingerprint(); final Fingerprint fingerprint = fingerprinter.buildFingerprint();
expect(fingerprint, Fingerprint.fromBuildInputs(<String, String>{ expect(fingerprint, Fingerprint.fromBuildInputs(<String, String>{
'bar': 'baz', 'bar': 'baz',
'wobble': 'womble', 'wobble': 'womble',
}, <String>['a.dart', 'b.dart'])); }, <String>['a.dart', 'b.dart']));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('fingerprint does not match if not present', () async { testUsingContext('fingerprint does not match if not present', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -100,12 +100,12 @@ void main() { ...@@ -100,12 +100,12 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
expect(await fingerprinter.doesFingerprintMatch(), isFalse); expect(fingerprinter.doesFingerprintMatch(), isFalse);
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('fingerprint does match if different', () async { testUsingContext('fingerprint does match if different', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
final Fingerprinter fingerprinter1 = Fingerprinter( final Fingerprinter fingerprinter1 = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -115,7 +115,7 @@ void main() { ...@@ -115,7 +115,7 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
await fingerprinter1.writeFingerprint(); fingerprinter1.writeFingerprint();
final Fingerprinter fingerprinter2 = Fingerprinter( final Fingerprinter fingerprinter2 = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -125,13 +125,13 @@ void main() { ...@@ -125,13 +125,13 @@ void main() {
'wobble': 'elbmow', 'wobble': 'elbmow',
}, },
); );
expect(await fingerprinter2.doesFingerprintMatch(), isFalse); expect(fingerprinter2.doesFingerprintMatch(), isFalse);
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('fingerprint does not match if depfile is malformed', () async { testUsingContext('fingerprint does not match if depfile is malformed', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
await fs.file('depfile').writeAsString('depfile : b.dart'); fs.file('depfile').writeAsStringSync('depfile : b.dart');
// Write a valid fingerprint // Write a valid fingerprint
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
...@@ -143,10 +143,10 @@ void main() { ...@@ -143,10 +143,10 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
// Write a corrupt depfile. // Write a corrupt depfile.
await fs.file('depfile').writeAsString(''); fs.file('depfile').writeAsStringSync('');
final Fingerprinter badFingerprinter = Fingerprinter( final Fingerprinter badFingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
paths: <String>['a.dart', 'b.dart'], paths: <String>['a.dart', 'b.dart'],
...@@ -157,13 +157,13 @@ void main() { ...@@ -157,13 +157,13 @@ void main() {
}, },
); );
expect(await badFingerprinter.doesFingerprintMatch(), isFalse); expect(badFingerprinter.doesFingerprintMatch(), isFalse);
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('fingerprint does not match if previous fingerprint is malformed', () async { testUsingContext('fingerprint does not match if previous fingerprint is malformed', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
await fs.file('out.fingerprint').writeAsString('** not JSON **'); fs.file('out.fingerprint').writeAsStringSync('** not JSON **');
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -174,12 +174,12 @@ void main() { ...@@ -174,12 +174,12 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
expect(await fingerprinter.doesFingerprintMatch(), isFalse); expect(fingerprinter.doesFingerprintMatch(), isFalse);
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('fingerprint does match if identical', () async { testUsingContext('fingerprint does match if identical', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -189,15 +189,15 @@ void main() { ...@@ -189,15 +189,15 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(await fingerprinter.doesFingerprintMatch(), isTrue); expect(fingerprinter.doesFingerprintMatch(), isTrue);
}, overrides: contextOverrides); }, overrides: contextOverrides);
final Platform mockPlatformDisabledCache = MockPlatform(); final Platform mockPlatformDisabledCache = MockPlatform();
mockPlatformDisabledCache.environment['DISABLE_FLUTTER_BUILD_CACHE'] = 'true'; mockPlatformDisabledCache.environment['DISABLE_FLUTTER_BUILD_CACHE'] = 'true';
testUsingContext('can be disabled with an environment variable', () async { testUsingContext('can be disabled with an environment variable', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -207,8 +207,8 @@ void main() { ...@@ -207,8 +207,8 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(await fingerprinter.doesFingerprintMatch(), isFalse); expect(fingerprinter.doesFingerprintMatch(), isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => mockPlatformDisabledCache, Platform: () => mockPlatformDisabledCache,
...contextOverrides, ...contextOverrides,
...@@ -216,9 +216,9 @@ void main() { ...@@ -216,9 +216,9 @@ void main() {
final Platform mockPlatformEnabledCache = MockPlatform(); final Platform mockPlatformEnabledCache = MockPlatform();
mockPlatformEnabledCache.environment['DISABLE_FLUTTER_BUILD_CACHE'] = 'false'; mockPlatformEnabledCache.environment['DISABLE_FLUTTER_BUILD_CACHE'] = 'false';
testUsingContext('can be not-disabled with an environment variable', () async { testUsingContext('can be not-disabled with an environment variable', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('b.dart').create(); fs.file('b.dart').createSync();
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -228,14 +228,14 @@ void main() { ...@@ -228,14 +228,14 @@ void main() {
'wobble': 'womble', 'wobble': 'womble',
}, },
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(await fingerprinter.doesFingerprintMatch(), isTrue); expect(fingerprinter.doesFingerprintMatch(), isTrue);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => mockPlatformEnabledCache, Platform: () => mockPlatformEnabledCache,
...contextOverrides, ...contextOverrides,
}); });
testUsingContext('fails to write fingerprint if inputs are missing', () async { testUsingContext('fails to write fingerprint if inputs are missing', () {
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
paths: <String>['a.dart'], paths: <String>['a.dart'],
...@@ -244,14 +244,14 @@ void main() { ...@@ -244,14 +244,14 @@ void main() {
'wibble': 'wobble', 'wibble': 'wobble',
}, },
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(fs.file('out.fingerprint').existsSync(), isFalse); expect(fs.file('out.fingerprint').existsSync(), isFalse);
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('applies path filter to inputs paths', () async { testUsingContext('applies path filter to inputs paths', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
await fs.file('ab.dart').create(); fs.file('ab.dart').createSync();
await fs.file('depfile').writeAsString('depfile : ab.dart c.dart'); fs.file('depfile').writeAsStringSync('depfile : ab.dart c.dart');
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: 'out.fingerprint',
...@@ -263,7 +263,7 @@ void main() { ...@@ -263,7 +263,7 @@ void main() {
}, },
pathFilter: (String path) => path.startsWith('a'), pathFilter: (String path) => path.startsWith('a'),
); );
await fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(fs.file('out.fingerprint').existsSync(), isTrue); expect(fs.file('out.fingerprint').existsSync(), isTrue);
}, overrides: contextOverrides); }, overrides: contextOverrides);
}); });
...@@ -284,17 +284,17 @@ void main() { ...@@ -284,17 +284,17 @@ void main() {
fs = MemoryFileSystem(); fs = MemoryFileSystem();
}); });
testUsingContext('throws if any input file does not exist', () async { testUsingContext('throws if any input file does not exist', () {
await fs.file('a.dart').create(); fs.file('a.dart').createSync();
expect( expect(
() => Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']), () => Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']),
throwsArgumentError, throwsArgumentError,
); );
}, overrides: <Type, Generator>{FileSystem: () => fs}); }, overrides: <Type, Generator>{FileSystem: () => fs});
testUsingContext('populates checksums for valid files', () async { testUsingContext('populates checksums for valid files', () {
await fs.file('a.dart').writeAsString('This is a'); fs.file('a.dart').writeAsStringSync('This is a');
await fs.file('b.dart').writeAsString('This is b'); fs.file('b.dart').writeAsStringSync('This is b');
final Fingerprint fingerprint = Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']); final Fingerprint fingerprint = Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']);
final Map<String, dynamic> jsonObject = json.decode(fingerprint.toJson()); final Map<String, dynamic> jsonObject = json.decode(fingerprint.toJson());
...@@ -321,13 +321,13 @@ void main() { ...@@ -321,13 +321,13 @@ void main() {
}); });
group('fromJson', () { group('fromJson', () {
testUsingContext('throws if JSON is invalid', () async { testUsingContext('throws if JSON is invalid', () {
expect(() => Fingerprint.fromJson('<xml></xml>'), throwsA(anything)); expect(() => Fingerprint.fromJson('<xml></xml>'), throwsA(anything));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('creates fingerprint from valid JSON', () async { testUsingContext('creates fingerprint from valid JSON', () {
final String jsonString = json.encode(<String, dynamic>{ final String jsonString = json.encode(<String, dynamic>{
'version': kVersion, 'version': kVersion,
'properties': <String, String>{ 'properties': <String, String>{
...@@ -355,7 +355,7 @@ void main() { ...@@ -355,7 +355,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('throws ArgumentError for unknown versions', () async { testUsingContext('throws ArgumentError for unknown versions', () {
final String jsonString = json.encode(<String, dynamic>{ final String jsonString = json.encode(<String, dynamic>{
'version': 'bad', 'version': 'bad',
'properties': <String, String>{}, 'properties': <String, String>{},
...@@ -366,7 +366,7 @@ void main() { ...@@ -366,7 +366,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('throws ArgumentError if version is not present', () async { testUsingContext('throws ArgumentError if version is not present', () {
final String jsonString = json.encode(<String, dynamic>{ final String jsonString = json.encode(<String, dynamic>{
'properties': <String, String>{}, 'properties': <String, String>{},
'files': <String, String>{}, 'files': <String, String>{},
...@@ -376,7 +376,7 @@ void main() { ...@@ -376,7 +376,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('treats missing properties and files entries as if empty', () async { testUsingContext('treats missing properties and files entries as if empty', () {
final String jsonString = json.encode(<String, dynamic>{ final String jsonString = json.encode(<String, dynamic>{
'version': kVersion, 'version': kVersion,
}); });
...@@ -387,7 +387,7 @@ void main() { ...@@ -387,7 +387,7 @@ void main() {
}); });
group('operator ==', () { group('operator ==', () {
testUsingContext('reports not equal if properties do not match', () async { testUsingContext('reports not equal if properties do not match', () {
final Map<String, dynamic> a = <String, dynamic>{ final Map<String, dynamic> a = <String, dynamic>{
'version': kVersion, 'version': kVersion,
'properties': <String, String>{ 'properties': <String, String>{
...@@ -404,7 +404,7 @@ void main() { ...@@ -404,7 +404,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('reports not equal if file checksums do not match', () async { testUsingContext('reports not equal if file checksums do not match', () {
final Map<String, dynamic> a = <String, dynamic>{ final Map<String, dynamic> a = <String, dynamic>{
'version': kVersion, 'version': kVersion,
'properties': <String, String>{}, 'properties': <String, String>{},
...@@ -423,7 +423,7 @@ void main() { ...@@ -423,7 +423,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('reports not equal if file paths do not match', () async { testUsingContext('reports not equal if file paths do not match', () {
final Map<String, dynamic> a = <String, dynamic>{ final Map<String, dynamic> a = <String, dynamic>{
'version': kVersion, 'version': kVersion,
'properties': <String, String>{}, 'properties': <String, String>{},
...@@ -442,7 +442,7 @@ void main() { ...@@ -442,7 +442,7 @@ void main() {
FlutterVersion: () => mockVersion, FlutterVersion: () => mockVersion,
}); });
testUsingContext('reports equal if properties and file checksums match', () async { testUsingContext('reports equal if properties and file checksums match', () {
final Map<String, dynamic> a = <String, dynamic>{ final Map<String, dynamic> a = <String, dynamic>{
'version': kVersion, 'version': kVersion,
'properties': <String, String>{ 'properties': <String, String>{
...@@ -461,7 +461,7 @@ void main() { ...@@ -461,7 +461,7 @@ void main() {
}); });
}); });
group('hashCode', () { group('hashCode', () {
testUsingContext('is consistent with equals, even if map entries are reordered', () async { testUsingContext('is consistent with equals, even if map entries are reordered', () {
final Fingerprint a = Fingerprint.fromJson('{"version":"$kVersion","properties":{"a":"A","b":"B"},"files":{}}'); final Fingerprint a = Fingerprint.fromJson('{"version":"$kVersion","properties":{"a":"A","b":"B"},"files":{}}');
final Fingerprint b = Fingerprint.fromJson('{"version":"$kVersion","properties":{"b":"B","a":"A"},"files":{}}'); final Fingerprint b = Fingerprint.fromJson('{"version":"$kVersion","properties":{"b":"B","a":"A"},"files":{}}');
expect(a, b); expect(a, b);
...@@ -482,31 +482,31 @@ void main() { ...@@ -482,31 +482,31 @@ void main() {
final Map<Type, Generator> contextOverrides = <Type, Generator>{FileSystem: () => fs}; final Map<Type, Generator> contextOverrides = <Type, Generator>{FileSystem: () => fs};
testUsingContext('returns one file if only one is listed', () async { testUsingContext('returns one file if only one is listed', () {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart'); fs.file('a.d').writeAsStringSync('snapshot.d: /foo/a.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>['/foo/a.dart'])); expect(readDepfile('a.d'), unorderedEquals(<String>['/foo/a.dart']));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('returns multiple files', () async { testUsingContext('returns multiple files', () {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart /foo/b.dart'); fs.file('a.d').writeAsStringSync('snapshot.d: /foo/a.dart /foo/b.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[ expect(readDepfile('a.d'), unorderedEquals(<String>[
'/foo/a.dart', '/foo/a.dart',
'/foo/b.dart', '/foo/b.dart',
])); ]));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('trims extra spaces between files', () async { testUsingContext('trims extra spaces between files', () {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart /foo/b.dart /foo/c.dart'); fs.file('a.d').writeAsStringSync('snapshot.d: /foo/a.dart /foo/b.dart /foo/c.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[ expect(readDepfile('a.d'), unorderedEquals(<String>[
'/foo/a.dart', '/foo/a.dart',
'/foo/b.dart', '/foo/b.dart',
'/foo/c.dart', '/foo/c.dart',
])); ]));
}, overrides: contextOverrides); }, overrides: contextOverrides);
testUsingContext('returns files with spaces and backslashes', () async { testUsingContext('returns files with spaces and backslashes', () {
await fs.file('a.d').writeAsString(r'snapshot.d: /foo/a\ a.dart /foo/b\\b.dart /foo/c\\ c.dart'); fs.file('a.d').writeAsStringSync(r'snapshot.d: /foo/a\ a.dart /foo/b\\b.dart /foo/c\\ c.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[ expect(readDepfile('a.d'), unorderedEquals(<String>[
r'/foo/a a.dart', r'/foo/a a.dart',
r'/foo/b\b.dart', r'/foo/b\b.dart',
r'/foo/c\ c.dart', r'/foo/c\ c.dart',
......
...@@ -434,12 +434,12 @@ Could not build the precompiled application for the device.''', ...@@ -434,12 +434,12 @@ Could not build the precompiled application for the device.''',
when(project.xcodeProjectInfoFile).thenReturn(pbxprojFile); when(project.xcodeProjectInfoFile).thenReturn(pbxprojFile);
when(project.hostAppBundleName).thenReturn('UnitTestRunner.app'); when(project.hostAppBundleName).thenReturn('UnitTestRunner.app');
when(pbxprojFile.readAsLines()) when(pbxprojFile.readAsLinesSync())
.thenAnswer((_) => Future<List<String>>.value(flutterAssetPbxProjLines)); .thenAnswer((_) => flutterAssetPbxProjLines);
when(pbxprojFile.exists()) when(pbxprojFile.existsSync())
.thenAnswer((_) => Future<bool>.value(true)); .thenAnswer((_) => true);
bool result = await upgradePbxProjWithFlutterAssets(project); bool result = upgradePbxProjWithFlutterAssets(project);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, testLogger.statusText,
...@@ -447,9 +447,9 @@ Could not build the precompiled application for the device.''', ...@@ -447,9 +447,9 @@ Could not build the precompiled application for the device.''',
); );
testLogger.clear(); testLogger.clear();
when(pbxprojFile.readAsLines()) when(pbxprojFile.readAsLinesSync())
.thenAnswer((_) => Future<List<String>>.value(appFlxPbxProjLines)); .thenAnswer((_) => appFlxPbxProjLines);
result = await upgradePbxProjWithFlutterAssets(project); result = upgradePbxProjWithFlutterAssets(project);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, testLogger.statusText,
...@@ -457,9 +457,9 @@ Could not build the precompiled application for the device.''', ...@@ -457,9 +457,9 @@ Could not build the precompiled application for the device.''',
); );
testLogger.clear(); testLogger.clear();
when(pbxprojFile.readAsLines()) when(pbxprojFile.readAsLinesSync())
.thenAnswer((_) => Future<List<String>>.value(cleanPbxProjLines)); .thenAnswer((_) => cleanPbxProjLines);
result = await upgradePbxProjWithFlutterAssets(project); result = upgradePbxProjWithFlutterAssets(project);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, testLogger.statusText,
......
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