Commit d631ebe5 authored by Devon Carew's avatar Devon Carew

fix a regex in the ios logs command

fixed sub-process stdout parsing; added todos
parent b89935e5
...@@ -21,26 +21,20 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, { ...@@ -21,26 +21,20 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, {
cmd.sublist(1), cmd.sublist(1),
workingDirectory: workingDirectory workingDirectory: workingDirectory
); );
process.stdout.transform(UTF8.decoder).listen((String data) { process.stdout
List<String> dataLines = data.trimRight().split('\n'); .transform(UTF8.decoder)
if (filter != null) { .transform(const LineSplitter())
// TODO(ianh): This doesn't handle IO buffering (where the data might be split half-way through a line) .where((String line) => filter == null ? true : filter.hasMatch(line))
dataLines = dataLines.where((String s) => filter.hasMatch(s)).toList(); .listen((String line) {
} printStatus('$prefix$line');
if (dataLines.length > 0) { });
printStatus('$prefix${dataLines.join('\n$prefix')}'); process.stderr
} .transform(UTF8.decoder)
}); .transform(const LineSplitter())
process.stderr.transform(UTF8.decoder).listen((String data) { .where((String line) => filter == null ? true : filter.hasMatch(line))
List<String> dataLines = data.trimRight().split('\n'); .listen((String line) {
if (filter != null) { printError('$prefix$line');
// TODO(ianh): This doesn't handle IO buffering (where the data might be split half-way through a line) });
dataLines = dataLines.where((String s) => filter.hasMatch(s));
}
if (dataLines.length > 0) {
printError('$prefix${dataLines.join('\n$prefix')}');
}
});
return await process.exitCode; return await process.exitCode;
} }
......
...@@ -137,7 +137,7 @@ Future<int> startApp( ...@@ -137,7 +137,7 @@ Future<int> startApp(
if (clearLogs != null) if (clearLogs != null)
platformArgs['clear-logs'] = clearLogs; platformArgs['clear-logs'] = clearLogs;
printStatus('Starting $mainPath on ${device.name}...'); printStatus('Starting ${_getDisplayPath(mainPath)} on ${device.name}...');
bool result = await device.startApp( bool result = await device.startApp(
package, package,
...@@ -149,7 +149,7 @@ Future<int> startApp( ...@@ -149,7 +149,7 @@ Future<int> startApp(
); );
if (!result) { if (!result) {
printError('Could not start \'${package.name}\' on \'${device.id}\''); printError('Error starting application on ${device.name}.');
} else { } else {
startedSomething = true; startedSomething = true;
} }
...@@ -165,3 +165,12 @@ Future<int> startApp( ...@@ -165,3 +165,12 @@ Future<int> startApp(
return startedSomething ? 0 : 2; return startedSomething ? 0 : 2;
} }
/// Return a relative path if [fullPath] is contained by the cwd, else return an
/// absolute path.
String _getDisplayPath(String fullPath) {
String cwd = Directory.current.path + Platform.pathSeparator;
if (fullPath.startsWith(cwd))
return fullPath.substring(cwd.length);
return fullPath;
}
...@@ -131,7 +131,7 @@ class IOSDevice extends Device { ...@@ -131,7 +131,7 @@ class IOSDevice extends Device {
if (Platform.isMacOS) { if (Platform.isMacOS) {
printError('$command not found. $macInstructions'); printError('$command not found. $macInstructions');
} else { } else {
printError('Cannot control iOS devices or simulators. $command is not available on your platform.'); printError('Cannot control iOS devices or simulators. $command is not available on your platform.');
} }
} }
return command; return command;
...@@ -261,7 +261,7 @@ class IOSDevice extends Device { ...@@ -261,7 +261,7 @@ class IOSDevice extends Device {
return 2; return 2;
} }
return await runCommandAndStreamOutput([loggerPath], return await runCommandAndStreamOutput([loggerPath],
prefix: 'iOS: ', filter: new RegExp('FlutterRunner')); prefix: 'iOS: ', filter: new RegExp(r'(FlutterRunner|flutter.runner.Runner)'));
} }
} }
...@@ -315,8 +315,8 @@ class IOSSimulator extends Device { ...@@ -315,8 +315,8 @@ class IOSSimulator extends Device {
'which is not supposed to happen.'); 'which is not supposed to happen.');
for (Match match in matches) { for (Match match in matches) {
if (match.groupCount > 0) { if (match.groupCount > 0) {
// TODO: We're killing simulator devices inside an accessor method; // TODO(devoncarew): We're killing simulator devices inside an accessor
// we probably shouldn't be changing state here. // method; we probably shouldn't be changing state here.
printError('Killing simulator ${match.group(1)}'); printError('Killing simulator ${match.group(1)}');
runSync([xcrunPath, 'simctl', 'shutdown', match.group(2)]); runSync([xcrunPath, 'simctl', 'shutdown', match.group(2)]);
} }
...@@ -518,12 +518,21 @@ class IOSSimulator extends Device { ...@@ -518,12 +518,21 @@ class IOSSimulator extends Device {
String logFilePath = path.join( String logFilePath = path.join(
homeDirectory, 'Library', 'Logs', 'CoreSimulator', simulatorDeviceID, 'system.log' homeDirectory, 'Library', 'Logs', 'CoreSimulator', simulatorDeviceID, 'system.log'
); );
if (clear) if (clear)
runSync(['rm', logFilePath]); runSync(['rm', logFilePath]);
// TODO(devoncarew): The log message prefix could be shortened or removed.
// Jan 29 01:31:44 devoncarew-macbookpro3 SpringBoard[96648]:
// TODO(devoncarew): This truncates multi-line messages like:
// Jan 29 01:31:43 devoncarew-macbookpro3 CoreSimulatorBridge[96656]: Requesting... {
// environment = {
// };
// }
return await runCommandAndStreamOutput( return await runCommandAndStreamOutput(
['tail', '-f', logFilePath], ['tail', '-f', logFilePath],
prefix: 'iOS sim: ', prefix: 'iOS: ',
filter: new RegExp(r'.*SkyShell.*') filter: new RegExp(r'(FlutterRunner|flutter.runner.Runner)')
); );
} }
} }
......
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