Commit 31dc3c47 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Try all possible Android SDK locations before giving up (#8730)

Fixes #8618
parent 3d5d63a8
......@@ -87,8 +87,9 @@ class AndroidSdk {
return new AndroidSdk(fs.path.join(androidHomeDir, 'sdk'));
}
File aaptBin = os.which('aapt'); // in build-tools/$version/aapt
if (aaptBin != null) {
// in build-tools/$version/aapt
final List<File> aaptBins = os.whichAll('aapt');
for (File aaptBin in aaptBins) {
// Make sure we're using the aapt from the SDK.
aaptBin = fs.file(aaptBin.resolveSymbolicLinksSync());
final String dir = aaptBin.parent.parent.parent.path;
......@@ -96,8 +97,9 @@ class AndroidSdk {
return new AndroidSdk(dir);
}
File adbBin = os.which('adb'); // in platform-tools/adb
if (adbBin != null) {
// in platform-tools/adb
final List<File> adbBins = os.whichAll('adb');
for (File adbBin in adbBins) {
// Make sure we're using the adb from the SDK.
adbBin = fs.file(adbBin.resolveSymbolicLinksSync());
final String dir = adbBin.parent.parent.path;
......
......@@ -5,7 +5,6 @@
import 'dart:async';
import 'package:archive/archive.dart';
import 'context.dart';
import 'file_system.dart';
import 'io.dart';
......@@ -34,6 +33,28 @@ abstract class OperatingSystemUtils {
/// if `which` was not able to locate the binary.
File which(String execName);
/// Return a list of all paths to `execName` found on the system. Uses the
/// PATH environment variable.
List<File> whichAll(String execName) {
final List<File> result = <File>[];
final String pathEnvironmentVariable = platform.environment['PATH'];
for (final String pathComponent in _splitPath(pathEnvironmentVariable)) {
final String pathToExecName = fs.path.join(pathComponent, execName);
if (processManager.canRun(pathToExecName)) {
result.add(fs.file(pathToExecName));
}
}
return result;
}
List<String> _splitPath(String pathEnvironmentVariable) {
final String delimiter = platform.isWindows ? ';' : ':';
if (pathEnvironmentVariable == null) {
return <String>[];
}
return pathEnvironmentVariable.split(delimiter);
}
/// Return the File representing a new pipe.
File makePipe(String path);
......
......@@ -151,7 +151,10 @@ class MockSimControl extends Mock implements SimControl {
}
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {
@override
List<File> whichAll(String execName) => <File>[];
}
class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils {}
......
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