[flutter_tools] cache adb path (#76650)

This commit is contained in:
Jonah Williams
2021-02-23 17:26:02 -08:00
committed by GitHub
parent ed70d190db
commit bbaced6d12
2 changed files with 23 additions and 1 deletions

View File

@@ -167,7 +167,8 @@ class AndroidSdk {
AndroidSdkVersion get latestVersion => _latestVersion;
String get adbPath => getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb');
String get adbPath => _adbPath ??= getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb');
String _adbPath;
String get emulatorPath => getEmulatorPath();

View File

@@ -83,6 +83,27 @@ void main() {
Config: () => config,
});
testUsingContext('Caches adb location after first access', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
final File adbFile = fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe')
)..createSync(recursive: true);
expect(sdk.adbPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe'));
adbFile.deleteSync(recursive: true);
expect(sdk.adbPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
Config: () => config,
});
testUsingContext('returns sdkmanager.bat path under cmdline tools for windows', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);