Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds build number of ios device in flutter devices command #84512

Merged
merged 15 commits into from Jun 23, 2021
7 changes: 5 additions & 2 deletions packages/flutter_tools/lib/src/macos/xcdevice.dart
Expand Up @@ -373,14 +373,17 @@ class XCDevice {
// "13.3 (17C54)"
final RegExp operatingSystemRegex = RegExp(r'(.*) \(.*\)$');
final String operatingSystemVersion = deviceProperties['operatingSystemVersion'] as String;
return operatingSystemRegex.firstMatch(operatingSystemVersion.trim())?.group(1);
if(operatingSystemRegex.hasMatch(operatingSystemVersion.trim())) {
return operatingSystemRegex.firstMatch(operatingSystemVersion.trim())?.group(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a condition to check here if the regex had a match , because it was returning null for 10.1 . i think it should return 10.1.

}
return operatingSystemVersion;
}
return null;
}

static String _buildVersion(Map<String, dynamic> deviceProperties) {
if (deviceProperties.containsKey('operatingSystemVersion')) {
//Parse out the build version
// Parse out the build version, for example 17C54 from "13.3 (17C54)".
final RegExp buildVersionRegex = RegExp(r'\(.*\)$');
final String operatingSystemVersion = deviceProperties['operatingSystemVersion'] as String;
return buildVersionRegex.firstMatch(operatingSystemVersion)?.group(0)?.replaceAll(RegExp('[()]'), '');
Expand Down
53 changes: 53 additions & 0 deletions packages/flutter_tools/test/general.shard/macos/xcode_test.dart
Expand Up @@ -627,6 +627,59 @@ void main() {
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});

testUsingContext('Sdk Version is parsed correctly',() async {
const String devicesOutput = '''
[
{
"simulator" : false,
"operatingSystemVersion" : "13.3 (17C54)",
"interface" : "usb",
"available" : true,
"platform" : "com.apple.platform.iphoneos",
"modelCode" : "iPhone8,1",
"identifier" : "00008027-00192736010F802E",
"architecture" : "arm64",
"modelName" : "iPhone 6s",
"name" : "An iPhone (Space Gray)"
},
{
"simulator" : false,
"operatingSystemVersion" : "10.1",
"interface" : "usb",
"available" : true,
"platform" : "com.apple.platform.iphoneos",
"modelCode" : "iPad11,4",
"identifier" : "234234234234234234345445687594e089dede3c44",
"architecture" : "arm64",
"modelName" : "iPad Air 3rd Gen",
"name" : "A networked iPad"
},
{
"simulator" : false,
"interface" : "usb",
"available" : true,
"platform" : "com.apple.platform.iphoneos",
"modelCode" : "iPad11,4",
"identifier" : "f577a7903cc54959be2e34bc4f7f80b7009efcf4",
"architecture" : "BOGUS",
"modelName" : "iPad Air 3rd Gen",
"name" : "iPad 2"
}
]
''';
fakeProcessManager.addCommand(const FakeCommand(
command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
stdout: devicesOutput,
));

final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
expect(await devices[0].sdkNameAndVersion,'iOS 13.3 17C54');
expect(await devices[1].sdkNameAndVersion,'iOS 10.1');
expect(await devices[2].sdkNameAndVersion,'iOS null');
balvinderz marked this conversation as resolved.
Show resolved Hide resolved
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
});
});

group('diagnostics', () {
Expand Down