forked from firka/flutter
[flutter_tools] cache adb path (#76650)
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user