Use ProcessManager for Xcode tool invocations (#10955)

1. Run all Xcode tool invocations through ProcessManager, which allows
us to mock out failures, etc. for tests.

2. Add said tests.
This commit is contained in:
Chris Bracken
2017-06-23 18:50:27 -07:00
committed by GitHub
parent bbea0c3d1a
commit 2ebb9e5dc6
2 changed files with 103 additions and 6 deletions

View File

@@ -86,7 +86,7 @@ class Xcode {
String get xcodeSelectPath {
if (_xcodeSelectPath == null) {
try {
_xcodeSelectPath = runSync(<String>['/usr/bin/xcode-select', '--print-path'])?.trim();
_xcodeSelectPath = processManager.runSync(<String>['/usr/bin/xcode-select', '--print-path']).stdout.trim();
} on ProcessException {
// Ignore: return null below.
}
@@ -125,7 +125,7 @@ class Xcode {
String get xcodeVersionText {
if (_xcodeVersionText == null) {
try {
_xcodeVersionText = runSync(<String>['/usr/bin/xcodebuild', '-version']).replaceAll('\n', ', ');
_xcodeVersionText = processManager.runSync(<String>['/usr/bin/xcodebuild', '-version']).stdout.replaceAll('\n', ', ');
} on ProcessException {
// Ignore: return null below.
}
@@ -155,10 +155,15 @@ class Xcode {
}
Future<String> getAvailableDevices() async {
final RunResult result = await runAsync(<String>['/usr/bin/instruments', '-s', 'devices']);
if (result.exitCode != 0)
try {
final ProcessResult result = await processManager.run(
<String>['/usr/bin/instruments', '-s', 'devices']);
if (result.exitCode != 0)
throw new ToolExit('/usr/bin/instruments returned an error:\n${result.stderr}');
return result.stdout;
} on ProcessException {
throw new ToolExit('Failed to invoke /usr/bin/instruments. Is Xcode installed?');
return result.stdout;
}
}
}