Declare locals as final where not reassigned (dev) (#8574)
This commit is contained in:
@@ -33,14 +33,14 @@ Future<Null> main(List<String> rawArgs) async {
|
||||
|
||||
if (!args.wasParsed('task')) {
|
||||
if (args.wasParsed('stage')) {
|
||||
String stageName = args['stage'];
|
||||
List<ManifestTask> tasks = loadTaskManifest().tasks;
|
||||
final String stageName = args['stage'];
|
||||
final List<ManifestTask> tasks = loadTaskManifest().tasks;
|
||||
for (ManifestTask task in tasks) {
|
||||
if (task.stage == stageName)
|
||||
_taskNames.add(task.name);
|
||||
}
|
||||
} else if (args.wasParsed('all')) {
|
||||
List<ManifestTask> tasks = loadTaskManifest().tasks;
|
||||
final List<ManifestTask> tasks = loadTaskManifest().tasks;
|
||||
for (ManifestTask task in tasks) {
|
||||
_taskNames.add(task.name);
|
||||
}
|
||||
@@ -53,11 +53,11 @@ Future<Null> main(List<String> rawArgs) async {
|
||||
return null;
|
||||
}
|
||||
|
||||
bool silent = args['silent'];
|
||||
final bool silent = args['silent'];
|
||||
|
||||
for (String taskName in _taskNames) {
|
||||
section('Running task "$taskName"');
|
||||
Map<String, dynamic> result = await runTask(taskName, silent: silent);
|
||||
final Map<String, dynamic> result = await runTask(taskName, silent: silent);
|
||||
|
||||
if (!result['success'])
|
||||
exitCode = 1;
|
||||
@@ -82,8 +82,8 @@ final ArgParser _argParser = new ArgParser()
|
||||
'This option may be repeated to specify multiple tasks.',
|
||||
callback: (List<String> value) {
|
||||
for (String nameOrPath in value) {
|
||||
List<String> fragments = path.split(nameOrPath);
|
||||
bool isDartFile = fragments.last.endsWith('.dart');
|
||||
final List<String> fragments = path.split(nameOrPath);
|
||||
final bool isDartFile = fragments.last.endsWith('.dart');
|
||||
|
||||
if (fragments.length == 1 && !isDartFile) {
|
||||
// Not a path
|
||||
|
||||
@@ -9,9 +9,9 @@ import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
String revision = await getCurrentFlutterRepoCommit();
|
||||
DateTime revisionTimestamp = await getFlutterRepoCommitTimestamp(revision);
|
||||
String dartSdkVersion = await getDartVersion();
|
||||
final String revision = await getCurrentFlutterRepoCommit();
|
||||
final DateTime revisionTimestamp = await getFlutterRepoCommitTimestamp(revision);
|
||||
final String dartSdkVersion = await getDartVersion();
|
||||
await task(createAnalyzerCliTest(
|
||||
sdk: dartSdkVersion,
|
||||
commit: revision,
|
||||
|
||||
@@ -9,9 +9,9 @@ import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
String revision = await getCurrentFlutterRepoCommit();
|
||||
DateTime revisionTimestamp = await getFlutterRepoCommitTimestamp(revision);
|
||||
String dartSdkVersion = await getDartVersion();
|
||||
final String revision = await getCurrentFlutterRepoCommit();
|
||||
final DateTime revisionTimestamp = await getFlutterRepoCommitTimestamp(revision);
|
||||
final String dartSdkVersion = await getDartVersion();
|
||||
await task(createAnalyzerServerTest(
|
||||
sdk: dartSdkVersion,
|
||||
commit: revision,
|
||||
|
||||
@@ -12,11 +12,11 @@ import 'package:flutter_devicelab/framework/utils.dart';
|
||||
|
||||
void main() {
|
||||
task(() async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
Directory appDir =
|
||||
final Directory appDir =
|
||||
dir(path.join(flutterDirectory.path, 'examples/flutter_gallery'));
|
||||
File benchmarkFile = file(path.join(appDir.path, 'hot_benchmark.json'));
|
||||
final File benchmarkFile = file(path.join(appDir.path, 'hot_benchmark.json'));
|
||||
rm(benchmarkFile);
|
||||
await inDirectory(appDir, () async {
|
||||
return await flutter('run',
|
||||
|
||||
@@ -39,7 +39,7 @@ const String _kBenchmarkKey = 'technical_debt_in_dollars';
|
||||
|
||||
Future<Null> main() async {
|
||||
await task(() async {
|
||||
Process git = await startProcess(
|
||||
final Process git = await startProcess(
|
||||
'git',
|
||||
<String>['ls-files', '--full-name', flutterDirectory.path],
|
||||
workingDirectory: flutterDirectory.path,
|
||||
@@ -47,7 +47,7 @@ Future<Null> main() async {
|
||||
double total = 0.0;
|
||||
await for (String entry in git.stdout.transform(UTF8.decoder).transform(const LineSplitter()))
|
||||
total += await findCostsForFile(new File(path.join(flutterDirectory.path, entry)));
|
||||
int gitExitCode = await git.exitCode;
|
||||
final int gitExitCode = await git.exitCode;
|
||||
if (gitExitCode != 0)
|
||||
throw new Exception('git exit with unexpected error code $gitExitCode');
|
||||
return new TaskResult.success(
|
||||
|
||||
@@ -118,7 +118,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
/// [workingDevice].
|
||||
@override
|
||||
Future<Null> chooseWorkingDevice() async {
|
||||
List<Device> allDevices = (await discoverDevices())
|
||||
final List<Device> allDevices = (await discoverDevices())
|
||||
.map((String id) => new AndroidDevice(deviceId: id))
|
||||
.toList();
|
||||
|
||||
@@ -131,9 +131,9 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<List<String>> discoverDevices() async {
|
||||
List<String> output = (await eval(adbPath, <String>['devices', '-l'], canFail: false))
|
||||
final List<String> output = (await eval(adbPath, <String>['devices', '-l'], canFail: false))
|
||||
.trim().split('\n');
|
||||
List<String> results = <String>[];
|
||||
final List<String> results = <String>[];
|
||||
for (String line in output) {
|
||||
// Skip lines like: * daemon started successfully *
|
||||
if (line.startsWith('* daemon '))
|
||||
@@ -143,10 +143,10 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
continue;
|
||||
|
||||
if (_kDeviceRegex.hasMatch(line)) {
|
||||
Match match = _kDeviceRegex.firstMatch(line);
|
||||
final Match match = _kDeviceRegex.firstMatch(line);
|
||||
|
||||
String deviceID = match[1];
|
||||
String deviceState = match[2];
|
||||
final String deviceID = match[1];
|
||||
final String deviceState = match[2];
|
||||
|
||||
if (!const <String>['unauthorized', 'offline'].contains(deviceState)) {
|
||||
results.add(deviceID);
|
||||
@@ -161,10 +161,10 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<Map<String, HealthCheckResult>> checkDevices() async {
|
||||
Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
for (String deviceId in await discoverDevices()) {
|
||||
try {
|
||||
AndroidDevice device = new AndroidDevice(deviceId: deviceId);
|
||||
final AndroidDevice device = new AndroidDevice(deviceId: deviceId);
|
||||
// Just a smoke test that we can read wakefulness state
|
||||
// TODO(yjbanov): check battery level
|
||||
await device._getWakefulness();
|
||||
@@ -240,8 +240,8 @@ class AndroidDevice implements Device {
|
||||
///
|
||||
/// See: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/PowerManagerInternal.java
|
||||
Future<String> _getWakefulness() async {
|
||||
String powerInfo = await shellEval('dumpsys', <String>['power']);
|
||||
String wakefulness = grep('mWakefulness=', from: powerInfo).single.split('=')[1].trim();
|
||||
final String powerInfo = await shellEval('dumpsys', <String>['power']);
|
||||
final String wakefulness = grep('mWakefulness=', from: powerInfo).single.split('=')[1].trim();
|
||||
return wakefulness;
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ class AndroidDevice implements Device {
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
|
||||
String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
|
||||
Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
|
||||
final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
|
||||
final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
|
||||
return <String, dynamic>{
|
||||
'total_kb': int.parse(match.group(1)),
|
||||
};
|
||||
@@ -295,7 +295,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
/// [workingDevice].
|
||||
@override
|
||||
Future<Null> chooseWorkingDevice() async {
|
||||
List<IosDevice> allDevices = (await discoverDevices())
|
||||
final List<IosDevice> allDevices = (await discoverDevices())
|
||||
.map((String id) => new IosDevice(deviceId: id))
|
||||
.toList();
|
||||
|
||||
@@ -309,7 +309,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
@override
|
||||
Future<List<String>> discoverDevices() async {
|
||||
// TODO: use the -k UniqueDeviceID option, which requires much less parsing.
|
||||
List<String> iosDeviceIds = grep('UniqueDeviceID', from: await eval('ideviceinfo', <String>[]))
|
||||
final List<String> iosDeviceIds = grep('UniqueDeviceID', from: await eval('ideviceinfo', <String>[]))
|
||||
.map((String line) => line.split(' ').last).toList();
|
||||
|
||||
if (iosDeviceIds.isEmpty)
|
||||
@@ -320,7 +320,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<Map<String, HealthCheckResult>> checkDevices() async {
|
||||
Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
for (String deviceId in await discoverDevices()) {
|
||||
// TODO: do a more meaningful connectivity check than just recording the ID
|
||||
results['ios-device-$deviceId'] = new HealthCheckResult.success();
|
||||
@@ -376,13 +376,13 @@ class IosDevice implements Device {
|
||||
|
||||
/// Path to the `adb` executable.
|
||||
String get adbPath {
|
||||
String androidHome = Platform.environment['ANDROID_HOME'];
|
||||
final String androidHome = Platform.environment['ANDROID_HOME'];
|
||||
|
||||
if (androidHome == null)
|
||||
throw 'ANDROID_HOME environment variable missing. This variable must '
|
||||
'point to the Android SDK directory containing platform-tools.';
|
||||
|
||||
File adbPath = file(path.join(androidHome, 'platform-tools/adb'));
|
||||
final File adbPath = file(path.join(androidHome, 'platform-tools/adb'));
|
||||
|
||||
if (!adbPath.existsSync()) throw 'adb not found at: $adbPath';
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Future<num> runBenchmark(Benchmark benchmark, {
|
||||
}) async {
|
||||
await benchmark.init();
|
||||
|
||||
List<num> allRuns = <num>[];
|
||||
final List<num> allRuns = <num>[];
|
||||
|
||||
num minValue;
|
||||
|
||||
@@ -46,7 +46,7 @@ Future<num> runBenchmark(Benchmark benchmark, {
|
||||
print('');
|
||||
|
||||
try {
|
||||
num result = await benchmark.run();
|
||||
final num result = await benchmark.run();
|
||||
allRuns.add(result);
|
||||
|
||||
if (minValue == null || result < minValue) {
|
||||
|
||||
@@ -43,7 +43,7 @@ Future<TaskResult> task(TaskFunction task) {
|
||||
print('${rec.level.name}: ${rec.time}: ${rec.message}');
|
||||
});
|
||||
|
||||
_TaskRunner runner = new _TaskRunner(task);
|
||||
final _TaskRunner runner = new _TaskRunner(task);
|
||||
runner.keepVmAliveUntilTaskRunRequested();
|
||||
return runner.whenDone;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class _TaskRunner {
|
||||
_TaskRunner(this.task) {
|
||||
registerExtension('ext.cocoonRunTask',
|
||||
(String method, Map<String, String> parameters) async {
|
||||
TaskResult result = await run();
|
||||
final TaskResult result = await run();
|
||||
return new ServiceExtensionResponse.result(JSON.encode(result.toJson()));
|
||||
});
|
||||
registerExtension('ext.cocoonRunnerReady',
|
||||
@@ -78,7 +78,7 @@ class _TaskRunner {
|
||||
Future<TaskResult> run() async {
|
||||
try {
|
||||
_taskStarted = true;
|
||||
TaskResult result = await _performTask().timeout(taskTimeout);
|
||||
final TaskResult result = await _performTask().timeout(taskTimeout);
|
||||
_completer.complete(result);
|
||||
return result;
|
||||
} on TimeoutException catch (_) {
|
||||
@@ -117,11 +117,11 @@ class _TaskRunner {
|
||||
}
|
||||
|
||||
Future<TaskResult> _performTask() {
|
||||
Completer<TaskResult> completer = new Completer<TaskResult>();
|
||||
final Completer<TaskResult> completer = new Completer<TaskResult>();
|
||||
Chain.capture(() async {
|
||||
completer.complete(await task());
|
||||
}, onError: (dynamic taskError, Chain taskErrorStack) {
|
||||
String message = 'Task failed: $taskError';
|
||||
final String message = 'Task failed: $taskError';
|
||||
stderr
|
||||
..writeln(message)
|
||||
..writeln('\nStack trace:')
|
||||
@@ -210,7 +210,7 @@ class TaskResult {
|
||||
/// "reason": failure reason string valid only for unsuccessful results
|
||||
/// }
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> json = <String, dynamic>{
|
||||
final Map<String, dynamic> json = <String, dynamic>{
|
||||
'success': succeeded,
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'utils.dart';
|
||||
|
||||
/// Loads manifest data from `manifest.yaml` file or from [yaml], if present.
|
||||
Manifest loadTaskManifest([ String yaml ]) {
|
||||
dynamic manifestYaml = yaml == null
|
||||
final dynamic manifestYaml = yaml == null
|
||||
? loadYaml(file('manifest.yaml').readAsStringSync())
|
||||
: loadYamlNode(yaml);
|
||||
|
||||
@@ -33,7 +33,7 @@ class ManifestTask {
|
||||
@required this.stage,
|
||||
@required this.requiredAgentCapabilities,
|
||||
}) {
|
||||
String taskName = 'task "$name"';
|
||||
final String taskName = 'task "$name"';
|
||||
_checkIsNotBlank(name, 'Task name', taskName);
|
||||
_checkIsNotBlank(description, 'Task description', taskName);
|
||||
_checkIsNotBlank(stage, 'Task stage', taskName);
|
||||
@@ -84,7 +84,7 @@ ManifestTask _validateAndParseTask(dynamic taskName, dynamic taskYaml) {
|
||||
'required_agent_capabilities',
|
||||
]);
|
||||
|
||||
List<String> capabilities = _validateAndParseCapabilities(taskName, taskYaml['required_agent_capabilities']);
|
||||
final List<String> capabilities = _validateAndParseCapabilities(taskName, taskYaml['required_agent_capabilities']);
|
||||
return new ManifestTask._(
|
||||
name: taskName,
|
||||
description: taskYaml['description'],
|
||||
@@ -96,7 +96,7 @@ ManifestTask _validateAndParseTask(dynamic taskName, dynamic taskYaml) {
|
||||
List<String> _validateAndParseCapabilities(String taskName, dynamic capabilitiesYaml) {
|
||||
_checkType(capabilitiesYaml is List, capabilitiesYaml, 'required_agent_capabilities', 'list');
|
||||
for (int i = 0; i < capabilitiesYaml.length; i++) {
|
||||
dynamic capability = capabilitiesYaml[i];
|
||||
final dynamic capability = capabilitiesYaml[i];
|
||||
_checkType(capability is String, capability, 'required_agent_capabilities[$i]', 'string');
|
||||
}
|
||||
return capabilitiesYaml;
|
||||
|
||||
@@ -23,13 +23,13 @@ const Duration taskTimeoutWithGracePeriod = const Duration(minutes: 11);
|
||||
/// Running the task in [silent] mode will suppress standard output from task
|
||||
/// processes and only print standard errors.
|
||||
Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) async {
|
||||
String taskExecutable = 'bin/tasks/$taskName.dart';
|
||||
final String taskExecutable = 'bin/tasks/$taskName.dart';
|
||||
|
||||
if (!file(taskExecutable).existsSync())
|
||||
throw 'Executable Dart file not found: $taskExecutable';
|
||||
|
||||
int vmServicePort = await findAvailablePort();
|
||||
Process runner = await startProcess(dartBin, <String>[
|
||||
final int vmServicePort = await findAvailablePort();
|
||||
final Process runner = await startProcess(dartBin, <String>[
|
||||
'--enable-vm-service=$vmServicePort',
|
||||
'--no-pause-isolates-on-exit',
|
||||
taskExecutable,
|
||||
@@ -41,7 +41,7 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
runnerFinished = true;
|
||||
});
|
||||
|
||||
StreamSubscription<String> stdoutSub = runner.stdout
|
||||
final StreamSubscription<String> stdoutSub = runner.stdout
|
||||
.transform(const Utf8Decoder())
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
@@ -50,7 +50,7 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
}
|
||||
});
|
||||
|
||||
StreamSubscription<String> stderrSub = runner.stderr
|
||||
final StreamSubscription<String> stderrSub = runner.stderr
|
||||
.transform(const Utf8Decoder())
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
@@ -59,9 +59,9 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
|
||||
String waitingFor = 'connection';
|
||||
try {
|
||||
VMIsolateRef isolate = await _connectToRunnerIsolate(vmServicePort);
|
||||
final VMIsolateRef isolate = await _connectToRunnerIsolate(vmServicePort);
|
||||
waitingFor = 'task completion';
|
||||
Map<String, dynamic> taskResult =
|
||||
final Map<String, dynamic> taskResult =
|
||||
await isolate.invokeExtension('ext.cocoonRunTask').timeout(taskTimeoutWithGracePeriod);
|
||||
waitingFor = 'task process to exit';
|
||||
await runner.exitCode.timeout(const Duration(seconds: 1));
|
||||
@@ -81,8 +81,8 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
}
|
||||
|
||||
Future<VMIsolateRef> _connectToRunnerIsolate(int vmServicePort) async {
|
||||
String url = 'ws://localhost:$vmServicePort/ws';
|
||||
DateTime started = new DateTime.now();
|
||||
final String url = 'ws://localhost:$vmServicePort/ws';
|
||||
final DateTime started = new DateTime.now();
|
||||
|
||||
// TODO(yjbanov): due to lack of imagination at the moment the handshake with
|
||||
// the task process is very rudimentary and requires this small
|
||||
@@ -97,10 +97,10 @@ Future<VMIsolateRef> _connectToRunnerIsolate(int vmServicePort) async {
|
||||
await (await WebSocket.connect(url)).close();
|
||||
|
||||
// Look up the isolate.
|
||||
VMServiceClient client = new VMServiceClient.connect(url);
|
||||
VM vm = await client.getVM();
|
||||
VMIsolateRef isolate = vm.isolates.single;
|
||||
String response = await isolate.invokeExtension('ext.cocoonRunnerReady');
|
||||
final VMServiceClient client = new VMServiceClient.connect(url);
|
||||
final VM vm = await client.getVM();
|
||||
final VMIsolateRef isolate = vm.isolates.single;
|
||||
final String response = await isolate.invokeExtension('ext.cocoonRunnerReady');
|
||||
if (response != 'ready') throw 'not ready yet';
|
||||
return isolate;
|
||||
} catch (error) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class HealthCheckResult {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
StringBuffer buf = new StringBuffer(succeeded ? 'succeeded' : 'failed');
|
||||
final StringBuffer buf = new StringBuffer(succeeded ? 'succeeded' : 'failed');
|
||||
if (details != null && details.trim().isNotEmpty) {
|
||||
buf.writeln();
|
||||
// Indent details by 4 spaces
|
||||
@@ -89,7 +89,7 @@ Directory dir(String path) => new Directory(path);
|
||||
File file(String path) => new File(path);
|
||||
|
||||
void copy(File sourceFile, Directory targetDirectory, {String name}) {
|
||||
File target = file(
|
||||
final File target = file(
|
||||
path.join(targetDirectory.path, name ?? path.basename(sourceFile.path)));
|
||||
target.writeAsBytesSync(sourceFile.readAsBytesSync());
|
||||
}
|
||||
@@ -118,7 +118,7 @@ void section(String title) {
|
||||
|
||||
Future<String> getDartVersion() async {
|
||||
// The Dart VM returns the version text to stderr.
|
||||
ProcessResult result = Process.runSync(dartBin, <String>['--version']);
|
||||
final ProcessResult result = Process.runSync(dartBin, <String>['--version']);
|
||||
String version = result.stderr.trim();
|
||||
|
||||
// Convert:
|
||||
@@ -146,13 +146,13 @@ Future<String> getCurrentFlutterRepoCommit() {
|
||||
Future<DateTime> getFlutterRepoCommitTimestamp(String commit) {
|
||||
// git show -s --format=%at 4b546df7f0b3858aaaa56c4079e5be1ba91fbb65
|
||||
return inDirectory(flutterDirectory, () async {
|
||||
String unixTimestamp = await eval('git', <String>[
|
||||
final String unixTimestamp = await eval('git', <String>[
|
||||
'show',
|
||||
'-s',
|
||||
'--format=%at',
|
||||
commit,
|
||||
]);
|
||||
int secondsSinceEpoch = int.parse(unixTimestamp);
|
||||
final int secondsSinceEpoch = int.parse(unixTimestamp);
|
||||
return new DateTime.fromMillisecondsSinceEpoch(secondsSinceEpoch * 1000);
|
||||
});
|
||||
}
|
||||
@@ -163,17 +163,17 @@ Future<Process> startProcess(
|
||||
Map<String, String> environment,
|
||||
String workingDirectory,
|
||||
}) async {
|
||||
String command = '$executable ${arguments?.join(" ") ?? ""}';
|
||||
final String command = '$executable ${arguments?.join(" ") ?? ""}';
|
||||
print('Executing: $command');
|
||||
environment ??= <String, String>{};
|
||||
environment['BOT'] = 'true';
|
||||
Process process = await Process.start(
|
||||
final Process process = await Process.start(
|
||||
executable,
|
||||
arguments,
|
||||
environment: environment,
|
||||
workingDirectory: workingDirectory ?? cwd,
|
||||
);
|
||||
ProcessInfo processInfo = new ProcessInfo(command, process);
|
||||
final ProcessInfo processInfo = new ProcessInfo(command, process);
|
||||
_runningProcesses.add(processInfo);
|
||||
|
||||
process.exitCode.whenComplete(() {
|
||||
@@ -207,7 +207,7 @@ Future<int> exec(
|
||||
Map<String, String> environment,
|
||||
bool canFail: false,
|
||||
}) async {
|
||||
Process process = await startProcess(executable, arguments, environment: environment);
|
||||
final Process process = await startProcess(executable, arguments, environment: environment);
|
||||
|
||||
process.stdout
|
||||
.transform(UTF8.decoder)
|
||||
@@ -218,7 +218,7 @@ Future<int> exec(
|
||||
.transform(const LineSplitter())
|
||||
.listen(stderr.writeln);
|
||||
|
||||
int exitCode = await process.exitCode;
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable failed with exit code $exitCode.');
|
||||
@@ -235,12 +235,12 @@ Future<String> eval(
|
||||
Map<String, String> environment,
|
||||
bool canFail: false,
|
||||
}) async {
|
||||
Process process = await startProcess(executable, arguments, environment: environment);
|
||||
final Process process = await startProcess(executable, arguments, environment: environment);
|
||||
process.stderr.listen((List<int> data) {
|
||||
stderr.add(data);
|
||||
});
|
||||
String output = await UTF8.decodeStream(process.stdout);
|
||||
int exitCode = await process.exitCode;
|
||||
final String output = await UTF8.decodeStream(process.stdout);
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable failed with exit code $exitCode.');
|
||||
@@ -253,7 +253,7 @@ Future<int> flutter(String command, {
|
||||
bool canFail: false,
|
||||
Map<String, String> environment,
|
||||
}) {
|
||||
List<String> args = <String>[command]..addAll(options);
|
||||
final List<String> args = <String>[command]..addAll(options);
|
||||
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ Future<String> evalFlutter(String command, {
|
||||
bool canFail: false,
|
||||
Map<String, String> environment,
|
||||
}) {
|
||||
List<String> args = <String>[command]..addAll(options);
|
||||
final List<String> args = <String>[command]..addAll(options);
|
||||
return eval(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ String get dartBin =>
|
||||
Future<int> dart(List<String> args) => exec(dartBin, args);
|
||||
|
||||
Future<dynamic> inDirectory(dynamic directory, Future<dynamic> action()) async {
|
||||
String previousCwd = cwd;
|
||||
final String previousCwd = cwd;
|
||||
try {
|
||||
cd(directory);
|
||||
return await action();
|
||||
@@ -303,7 +303,7 @@ void cd(dynamic directory) {
|
||||
Directory get flutterDirectory => dir('../..').absolute;
|
||||
|
||||
String requireEnvVar(String name) {
|
||||
String value = Platform.environment[name];
|
||||
final String value = Platform.environment[name];
|
||||
|
||||
if (value == null) fail('$name environment variable is missing. Quitting.');
|
||||
|
||||
@@ -313,7 +313,7 @@ String requireEnvVar(String name) {
|
||||
T requireConfigProperty<T>(Map<String, dynamic> map, String propertyName) {
|
||||
if (!map.containsKey(propertyName))
|
||||
fail('Configuration property not found: $propertyName');
|
||||
T result = map[propertyName];
|
||||
final T result = map[propertyName];
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ Iterable<String> grep(Pattern pattern, {@required String from}) {
|
||||
///
|
||||
/// }
|
||||
Future<Null> runAndCaptureAsyncStacks(Future<Null> callback()) {
|
||||
Completer<Null> completer = new Completer<Null>();
|
||||
final Completer<Null> completer = new Completer<Null>();
|
||||
Chain.capture(() async {
|
||||
await callback();
|
||||
completer.complete();
|
||||
@@ -441,7 +441,7 @@ Future<int> findAvailablePort() async {
|
||||
int port = 20000;
|
||||
while (true) {
|
||||
try {
|
||||
ServerSocket socket =
|
||||
final ServerSocket socket =
|
||||
await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, port);
|
||||
await socket.close();
|
||||
return port;
|
||||
|
||||
@@ -18,10 +18,10 @@ TaskFunction createGalleryTransitionTest() {
|
||||
class GalleryTransitionTest {
|
||||
|
||||
Future<TaskResult> call() async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
String deviceId = device.deviceId;
|
||||
Directory galleryDirectory =
|
||||
final String deviceId = device.deviceId;
|
||||
final Directory galleryDirectory =
|
||||
dir('${flutterDirectory.path}/examples/flutter_gallery');
|
||||
await inDirectory(galleryDirectory, () async {
|
||||
await flutter('packages', options: <String>['get']);
|
||||
@@ -43,17 +43,17 @@ class GalleryTransitionTest {
|
||||
|
||||
// Route paths contains slashes, which Firebase doesn't accept in keys, so we
|
||||
// remove them.
|
||||
Map<String, List<int>> original = JSON.decode(file(
|
||||
final Map<String, List<int>> original = JSON.decode(file(
|
||||
'${galleryDirectory.path}/build/transition_durations.timeline.json')
|
||||
.readAsStringSync());
|
||||
Map<String, List<int>> transitions = new Map<String, List<int>>.fromIterable(
|
||||
final Map<String, List<int>> transitions = new Map<String, List<int>>.fromIterable(
|
||||
original.keys,
|
||||
key: (String key) => key.replaceAll('/', ''),
|
||||
value: (String key) => original[key]);
|
||||
|
||||
Map<String, dynamic> summary = JSON.decode(file('${galleryDirectory.path}/build/transitions.timeline_summary.json').readAsStringSync());
|
||||
final Map<String, dynamic> summary = JSON.decode(file('${galleryDirectory.path}/build/transitions.timeline_summary.json').readAsStringSync());
|
||||
|
||||
Map<String, dynamic> data = <String, dynamic>{
|
||||
final Map<String, dynamic> data = <String, dynamic>{
|
||||
'transitions': transitions,
|
||||
'missed_transition_count': _countMissedTransitions(transitions),
|
||||
};
|
||||
@@ -75,7 +75,7 @@ int _countMissedTransitions(Map<String, List<int>> transitions) {
|
||||
const int _kTransitionBudget = 100000; // µs
|
||||
int count = 0;
|
||||
transitions.forEach((String demoName, List<int> durations) {
|
||||
int longestDuration = durations.reduce(math.max);
|
||||
final int longestDuration = durations.reduce(math.max);
|
||||
if (longestDuration > _kTransitionBudget) {
|
||||
print('$demoName missed transition time budget ($longestDuration µs > $_kTransitionBudget µs)');
|
||||
count++;
|
||||
|
||||
@@ -16,13 +16,13 @@ import 'package:flutter_devicelab/framework/utils.dart';
|
||||
/// `dev/benchmarks/microbenchmarks` reports results to the dashboard.
|
||||
TaskFunction createMicrobenchmarkTask() {
|
||||
return () async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
|
||||
Future<Map<String, double>> _runMicrobench(String benchmarkPath) async {
|
||||
print('Running $benchmarkPath');
|
||||
Directory appDir = dir(path.join(flutterDirectory.path, 'dev/benchmarks/microbenchmarks'));
|
||||
Process flutterProcess = await inDirectory(appDir, () async {
|
||||
final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/benchmarks/microbenchmarks'));
|
||||
final Process flutterProcess = await inDirectory(appDir, () async {
|
||||
return await _startFlutter(
|
||||
options: <String>[
|
||||
'--profile', // --release doesn't work on iOS due to code signing issues
|
||||
@@ -37,7 +37,7 @@ TaskFunction createMicrobenchmarkTask() {
|
||||
return await _readJsonResults(flutterProcess);
|
||||
}
|
||||
|
||||
Map<String, double> allResults = <String, double>{};
|
||||
final Map<String, double> allResults = <String, double>{};
|
||||
allResults.addAll(await _runMicrobench('lib/stocks/layout_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/stocks/build_bench.dart'));
|
||||
allResults.addAll(await _runMicrobench('lib/gestures/velocity_tracker_bench.dart'));
|
||||
@@ -53,7 +53,7 @@ Future<Process> _startFlutter({
|
||||
bool canFail: false,
|
||||
Map<String, String> environment,
|
||||
}) {
|
||||
List<String> args = <String>['run']..addAll(options);
|
||||
final List<String> args = <String>['run']..addAll(options);
|
||||
return startProcess(path.join(flutterDirectory.path, 'bin', 'flutter'), args, environment: environment);
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ Future<Map<String, double>> _readJsonResults(Process process) {
|
||||
const String jsonStart = '================ RESULTS ================';
|
||||
const String jsonEnd = '================ FORMATTED ==============';
|
||||
bool jsonStarted = false;
|
||||
StringBuffer jsonBuf = new StringBuffer();
|
||||
Completer<Map<String, double>> completer = new Completer<Map<String, double>>();
|
||||
final StringBuffer jsonBuf = new StringBuffer();
|
||||
final Completer<Map<String, double>> completer = new Completer<Map<String, double>>();
|
||||
StreamSubscription<String> stdoutSub;
|
||||
|
||||
int prefixLength = 0;
|
||||
|
||||
@@ -77,7 +77,7 @@ class StartupTest {
|
||||
|
||||
Future<TaskResult> call() async {
|
||||
return await inDirectory(testDirectory, () async {
|
||||
String deviceId = (await devices.workingDevice).deviceId;
|
||||
final String deviceId = (await devices.workingDevice).deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
|
||||
@@ -91,7 +91,7 @@ class StartupTest {
|
||||
'-d',
|
||||
deviceId,
|
||||
]).timeout(_startupTimeout);
|
||||
Map<String, dynamic> data = JSON.decode(file('$testDirectory/build/start_up_info.json').readAsStringSync());
|
||||
final Map<String, dynamic> data = JSON.decode(file('$testDirectory/build/start_up_info.json').readAsStringSync());
|
||||
return new TaskResult.success(data, benchmarkScoreKeys: <String>[
|
||||
'timeToFirstFrameMicros',
|
||||
]);
|
||||
@@ -111,9 +111,9 @@ class PerfTest {
|
||||
|
||||
Future<TaskResult> call() {
|
||||
return inDirectory(testDirectory, () async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
String deviceId = device.deviceId;
|
||||
final String deviceId = device.deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
|
||||
@@ -130,7 +130,7 @@ class PerfTest {
|
||||
'-d',
|
||||
deviceId,
|
||||
]);
|
||||
Map<String, dynamic> data = JSON.decode(file('$testDirectory/build/$timelineFileName.timeline_summary.json').readAsStringSync());
|
||||
final Map<String, dynamic> data = JSON.decode(file('$testDirectory/build/$timelineFileName.timeline_summary.json').readAsStringSync());
|
||||
|
||||
if (data['frame_count'] < 5) {
|
||||
return new TaskResult.failure(
|
||||
@@ -159,12 +159,12 @@ class BuildTest {
|
||||
|
||||
Future<TaskResult> call() async {
|
||||
return await inDirectory(testDirectory, () async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
Stopwatch watch = new Stopwatch()..start();
|
||||
String buildLog = await evalFlutter('build', options: <String>[
|
||||
final Stopwatch watch = new Stopwatch()..start();
|
||||
final String buildLog = await evalFlutter('build', options: <String>[
|
||||
'aot',
|
||||
'-v',
|
||||
'--profile',
|
||||
@@ -173,9 +173,9 @@ class BuildTest {
|
||||
]);
|
||||
watch.stop();
|
||||
|
||||
RegExp metricExpression = new RegExp(r'([a-zA-Z]+)\(CodeSize\)\: (\d+)');
|
||||
final RegExp metricExpression = new RegExp(r'([a-zA-Z]+)\(CodeSize\)\: (\d+)');
|
||||
|
||||
Map<String, dynamic> data = new Map<String, dynamic>.fromIterable(
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>.fromIterable(
|
||||
metricExpression.allMatches(buildLog),
|
||||
key: (Match m) => _sdkNameToMetricName(m.group(1)),
|
||||
value: (Match m) => int.parse(m.group(2)),
|
||||
@@ -216,9 +216,9 @@ class MemoryTest {
|
||||
|
||||
Future<TaskResult> call() {
|
||||
return inDirectory(testDirectory, () async {
|
||||
Device device = await devices.workingDevice;
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
String deviceId = device.deviceId;
|
||||
final String deviceId = device.deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
|
||||
@@ -226,9 +226,9 @@ class MemoryTest {
|
||||
await flutter('build', options: <String>['ios', '--profile']);
|
||||
}
|
||||
|
||||
int observatoryPort = await findAvailablePort();
|
||||
final int observatoryPort = await findAvailablePort();
|
||||
|
||||
List<String> runOptions = <String>[
|
||||
final List<String> runOptions = <String>[
|
||||
'-v',
|
||||
'--profile',
|
||||
'--trace-startup', // wait for the first frame to render
|
||||
@@ -241,9 +241,9 @@ class MemoryTest {
|
||||
runOptions.addAll(<String>['-t', testTarget]);
|
||||
await flutter('run', options: runOptions);
|
||||
|
||||
Map<String, dynamic> startData = await device.getMemoryStats(packageName);
|
||||
final Map<String, dynamic> startData = await device.getMemoryStats(packageName);
|
||||
|
||||
Map<String, dynamic> data = <String, dynamic>{
|
||||
final Map<String, dynamic> data = <String, dynamic>{
|
||||
'start_total_kb': startData['total_kb'],
|
||||
};
|
||||
|
||||
@@ -257,7 +257,7 @@ class MemoryTest {
|
||||
'--use-existing-app=http://localhost:$observatoryPort',
|
||||
]);
|
||||
|
||||
Map<String, dynamic> endData = await device.getMemoryStats(packageName);
|
||||
final Map<String, dynamic> endData = await device.getMemoryStats(packageName);
|
||||
data['end_total_kb'] = endData['total_kb'];
|
||||
data['diff_total_kb'] = endData['total_kb'] - startData['total_kb'];
|
||||
}
|
||||
@@ -283,9 +283,9 @@ class AndroidBackButtonMemoryTest {
|
||||
throw 'This test is only supported on Android';
|
||||
}
|
||||
|
||||
AndroidDevice device = await devices.workingDevice;
|
||||
final AndroidDevice device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
String deviceId = device.deviceId;
|
||||
final String deviceId = device.deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
await flutter('run', options: <String>[
|
||||
@@ -296,9 +296,9 @@ class AndroidBackButtonMemoryTest {
|
||||
deviceId,
|
||||
]);
|
||||
|
||||
Map<String, dynamic> startData = await device.getMemoryStats(packageName);
|
||||
final Map<String, dynamic> startData = await device.getMemoryStats(packageName);
|
||||
|
||||
Map<String, dynamic> data = <String, dynamic>{
|
||||
final Map<String, dynamic> data = <String, dynamic>{
|
||||
'start_total_kb': startData['total_kb'],
|
||||
};
|
||||
|
||||
@@ -306,14 +306,14 @@ class AndroidBackButtonMemoryTest {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
await device.shellExec('input', <String>['keyevent', 'KEYCODE_BACK']);
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 1000));
|
||||
String output = await device.shellEval('am', <String>['start', '-n', 'io.flutter.examples.gallery/io.flutter.app.FlutterActivity']);
|
||||
final String output = await device.shellEval('am', <String>['start', '-n', 'io.flutter.examples.gallery/io.flutter.app.FlutterActivity']);
|
||||
print(output);
|
||||
if (output.contains('Error'))
|
||||
return new TaskResult.failure('unable to launch activity');
|
||||
await new Future<Null>.delayed(const Duration(milliseconds: 1000));
|
||||
}
|
||||
|
||||
Map<String, dynamic> endData = await device.getMemoryStats(packageName);
|
||||
final Map<String, dynamic> endData = await device.getMemoryStats(packageName);
|
||||
data['end_total_kb'] = endData['total_kb'];
|
||||
data['diff_total_kb'] = endData['total_kb'] - startData['total_kb'];
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import '../framework/utils.dart';
|
||||
TaskFunction createBasicMaterialAppSizeTest() {
|
||||
return () async {
|
||||
const String sampleAppName = 'sample_flutter_app';
|
||||
Directory sampleDir = dir('${Directory.systemTemp.path}/$sampleAppName');
|
||||
final Directory sampleDir = dir('${Directory.systemTemp.path}/$sampleAppName');
|
||||
|
||||
if (await sampleDir.exists())
|
||||
rmTree(sampleDir);
|
||||
|
||||
@@ -129,7 +129,7 @@ class CommandArgs {
|
||||
if (other.runtimeType != CommandArgs)
|
||||
return false;
|
||||
|
||||
CommandArgs otherCmd = other;
|
||||
final CommandArgs otherCmd = other;
|
||||
return otherCmd.command == this.command &&
|
||||
const ListEquality<String>().equals(otherCmd.arguments, this.arguments) &&
|
||||
const MapEquality<String, String>().equals(otherCmd.environment, this.environment);
|
||||
@@ -188,7 +188,7 @@ class FakeDevice extends AndroidDevice {
|
||||
arguments: arguments,
|
||||
environment: environment,
|
||||
));
|
||||
dynamic exitError = exitErrorFactory();
|
||||
final dynamic exitError = exitErrorFactory();
|
||||
if (exitError != null)
|
||||
throw exitError;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import 'package:flutter_devicelab/framework/manifest.dart';
|
||||
void main() {
|
||||
group('production manifest', () {
|
||||
test('must be valid', () {
|
||||
Manifest manifest = loadTaskManifest();
|
||||
final Manifest manifest = loadTaskManifest();
|
||||
expect(manifest.tasks, isNotEmpty);
|
||||
|
||||
ManifestTask task = manifest.tasks.firstWhere((ManifestTask task) => task.name == 'flutter_gallery__start_up');
|
||||
final ManifestTask task = manifest.tasks.firstWhere((ManifestTask task) => task.name == 'flutter_gallery__start_up');
|
||||
expect(task.description, 'Measures the startup time of the Flutter Gallery app on Android.\n');
|
||||
expect(task.stage, 'devicelab');
|
||||
expect(task.requiredAgentCapabilities, <String>['has-android-device']);
|
||||
|
||||
@@ -10,11 +10,11 @@ import 'package:test/test.dart';
|
||||
void main() {
|
||||
group('run.dart script', () {
|
||||
Future<int> runScript(List<String> testNames) async {
|
||||
List<String> options = <String>['bin/run.dart'];
|
||||
final List<String> options = <String>['bin/run.dart'];
|
||||
for (String testName in testNames) {
|
||||
options..addAll(<String>['-t', testName]);
|
||||
}
|
||||
ProcessResult scriptProcess = Process.runSync(
|
||||
final ProcessResult scriptProcess = Process.runSync(
|
||||
'../../bin/cache/dart-sdk/bin/dart',
|
||||
options,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user