mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Do not throw when trying to discover a fuchsia device and the sshConfig is invalid (#52858)
* Do not throw when trying to discover a fuchsia device and the sshConfig is invalid
This commit is contained in:
parent
6c2a29dd37
commit
53dc8db0e8
@ -423,11 +423,18 @@ class FuchsiaDevice extends Device {
|
||||
TargetPlatform _targetPlatform;
|
||||
|
||||
Future<TargetPlatform> _queryTargetPlatform() async {
|
||||
const TargetPlatform defaultTargetPlatform = TargetPlatform.fuchsia_arm64;
|
||||
if (!globals.fuchsiaArtifacts.hasSshConfig) {
|
||||
globals.printTrace('Could not determine Fuchsia target platform because '
|
||||
'Fuchsia ssh configuration is missing.\n'
|
||||
'Defaulting to arm64.');
|
||||
return defaultTargetPlatform;
|
||||
}
|
||||
final RunResult result = await shell('uname -m');
|
||||
if (result.exitCode != 0) {
|
||||
globals.printError('Could not determine Fuchsia target platform type:\n$result\n'
|
||||
'Defaulting to arm64.');
|
||||
return TargetPlatform.fuchsia_arm64;
|
||||
return defaultTargetPlatform;
|
||||
}
|
||||
final String machine = result.stdout.trim();
|
||||
switch (machine) {
|
||||
@ -438,7 +445,7 @@ class FuchsiaDevice extends Device {
|
||||
default:
|
||||
globals.printError('Unknown Fuchsia target platform "$machine". '
|
||||
'Defaulting to arm64.');
|
||||
return TargetPlatform.fuchsia_arm64;
|
||||
return defaultTargetPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,16 +487,22 @@ class FuchsiaDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<String> get sdkNameAndVersion async {
|
||||
const String defaultName = 'Fuchsia';
|
||||
if (!globals.fuchsiaArtifacts.hasSshConfig) {
|
||||
globals.printTrace('Could not determine Fuchsia sdk name or version '
|
||||
'because Fuchsia ssh configuration is missing.');
|
||||
return defaultName;
|
||||
}
|
||||
const String versionPath = '/pkgfs/packages/build-info/0/data/version';
|
||||
final RunResult catResult = await shell('cat $versionPath');
|
||||
if (catResult.exitCode != 0) {
|
||||
globals.printTrace('Failed to cat $versionPath: ${catResult.stderr}');
|
||||
return 'Fuchsia';
|
||||
return defaultName;
|
||||
}
|
||||
final String version = catResult.stdout.trim();
|
||||
if (version.isEmpty) {
|
||||
globals.printTrace('$versionPath was empty');
|
||||
return 'Fuchsia';
|
||||
return defaultName;
|
||||
}
|
||||
return 'Fuchsia $version';
|
||||
}
|
||||
|
||||
@ -156,4 +156,7 @@ class FuchsiaArtifacts {
|
||||
|
||||
/// The pm tool.
|
||||
final File pm;
|
||||
|
||||
/// Returns true if the [sshConfig] file is not null and exists.
|
||||
bool get hasSshConfig => sshConfig != null && sshConfig.existsSync();
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ void main() {
|
||||
setUp(() {
|
||||
memoryFileSystem = MemoryFileSystem();
|
||||
sshConfig = MockFile();
|
||||
when(sshConfig.existsSync()).thenReturn(true);
|
||||
when(sshConfig.absolute).thenReturn(sshConfig);
|
||||
});
|
||||
|
||||
@ -115,6 +116,15 @@ void main() {
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('targetPlatform does not throw when sshConfig is missing', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('123');
|
||||
expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64);
|
||||
}, overrides: <Type, Generator>{
|
||||
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: null),
|
||||
FuchsiaSdk: () => MockFuchsiaSdk(),
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
});
|
||||
|
||||
testUsingContext('targetPlatform arm64 works', () async {
|
||||
when(globals.processManager.run(any)).thenAnswer((Invocation _) async {
|
||||
return ProcessResult(1, 0, 'aarch64', '');
|
||||
@ -888,6 +898,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
sshConfig = MockFile();
|
||||
when(sshConfig.existsSync()).thenReturn(true);
|
||||
when(sshConfig.absolute).thenReturn(sshConfig);
|
||||
|
||||
mockSuccessProcessManager = MockProcessManager();
|
||||
@ -915,6 +926,15 @@ void main() {
|
||||
when<String>(emptyStdoutProcessResult.stderr as String).thenReturn('');
|
||||
});
|
||||
|
||||
testUsingContext('does not throw on non-existant ssh config', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('123');
|
||||
expect(await device.sdkNameAndVersion, equals('Fuchsia'));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockSuccessProcessManager,
|
||||
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: null),
|
||||
FuchsiaSdk: () => MockFuchsiaSdk(),
|
||||
});
|
||||
|
||||
testUsingContext('returns what we get from the device on success', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('123');
|
||||
expect(await device.sdkNameAndVersion, equals('Fuchsia version'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user