diff --git a/packages/flutter_tools/lib/src/macos/xcode.dart b/packages/flutter_tools/lib/src/macos/xcode.dart index 5e8f0f135de..291bd58065e 100644 --- a/packages/flutter_tools/lib/src/macos/xcode.dart +++ b/packages/flutter_tools/lib/src/macos/xcode.dart @@ -169,10 +169,9 @@ class Xcode { assert(sdk != null); final RunResult runResult = await _processUtils.run( ['xcrun', '--sdk', getNameForSdk(sdk), '--show-sdk-path'], - throwOnError: true, ); if (runResult.exitCode != 0) { - throwToolExit('Could not find iPhone SDK location: ${runResult.stderr}'); + throwToolExit('Could not find SDK location: ${runResult.stderr}'); } return runResult.stdout.trim(); } diff --git a/packages/flutter_tools/test/general.shard/macos/xcode_test.dart b/packages/flutter_tools/test/general.shard/macos/xcode_test.dart index 4b4282ae03c..0515800f59b 100644 --- a/packages/flutter_tools/test/general.shard/macos/xcode_test.dart +++ b/packages/flutter_tools/test/general.shard/macos/xcode_test.dart @@ -178,6 +178,32 @@ void main() { expect(getNameForSdk(SdkType.iPhoneSimulator), 'iphonesimulator'); expect(getNameForSdk(SdkType.macOS), 'macosx'); }); + + group('SDK location', () { + const String sdkroot = 'Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk'; + + testWithoutContext('--show-sdk-path iphoneos', () async { + when(processManager.run(['xcrun', '--sdk', 'iphoneos', '--show-sdk-path'])).thenAnswer((_) => + Future.value(ProcessResult(1, 0, sdkroot, ''))); + + expect(await xcode.sdkLocation(SdkType.iPhone), sdkroot); + }); + + testWithoutContext('--show-sdk-path macosx', () async { + when(processManager.run(['xcrun', '--sdk', 'macosx', '--show-sdk-path'])).thenAnswer((_) => + Future.value(ProcessResult(1, 0, sdkroot, ''))); + + expect(await xcode.sdkLocation(SdkType.macOS), sdkroot); + }); + + testWithoutContext('--show-sdk-path fails', () async { + when(processManager.run(['xcrun', '--sdk', 'iphoneos', '--show-sdk-path'])).thenAnswer((_) => + Future.value(ProcessResult(1, 1, '', 'xcrun: error:'))); + + expect(() async => await xcode.sdkLocation(SdkType.iPhone), + throwsToolExit(message: 'Could not find SDK location')); + }); + }); }); group('xcdevice', () {