static void ValidateXcode(bool accept_any_xcode_version, bool warn_if_not_found) { if (sdk_root == null) { sdk_root = FindSystemXcode(); if (sdk_root == null) { // FindSystemXcode showed a warning in this case. In particular do not use 'string.IsNullOrEmpty' here, // because FindSystemXcode may return an empty string (with no warning printed) if the xcode-select command // succeeds, but returns nothing. sdk_root = null; } else if (!Directory.Exists(sdk_root)) { ErrorHelper.Warning(60, "Could not find the currently selected Xcode on the system. 'xcode-select --print-path' returned '{0}', but that directory does not exist.", sdk_root); sdk_root = null; } else { if (!accept_any_xcode_version) { ErrorHelper.Warning(61, "No Xcode.app specified (using --sdkroot), using the system Xcode as reported by 'xcode-select --print-path': {0}", sdk_root); } } if (sdk_root == null) { sdk_root = XcodeDefault; if (!Directory.Exists(sdk_root)) { if (warn_if_not_found) { // mmp: and now we give up, but don't throw like mtouch, because we don't want to change behavior (this sometimes worked it appears) ErrorHelper.Warning(56, "Cannot find Xcode in any of our default locations. Please install Xcode, or pass a custom path using --sdkroot=<path>."); return; // Can't validate the version below if we can't even find Xcode... } throw ErrorHelper.CreateError(56, "Cannot find Xcode in the default location (/Applications/Xcode.app). Please install Xcode, or pass a custom path using --sdkroot <path>."); } ErrorHelper.Warning(62, "No Xcode.app specified (using --sdkroot or 'xcode-select --print-path'), using the default Xcode instead: {0}", sdk_root); } } else if (!Directory.Exists(sdk_root)) { throw ErrorHelper.CreateError(55, "The Xcode path '{0}' does not exist.", sdk_root); } // Check what kind of path we got if (File.Exists(Path.Combine(sdk_root, "Contents", "MacOS", "Xcode"))) { // path to the Xcode.app developer_directory = Path.Combine(sdk_root, "Contents", "Developer"); } else if (File.Exists(Path.Combine(sdk_root, "..", "MacOS", "Xcode"))) { // path to Contents/Developer developer_directory = Path.GetFullPath(Path.Combine(sdk_root, "..", "..", "Contents", "Developer")); } else { throw ErrorHelper.CreateError(57, "Cannot determine the path to Xcode.app from the sdk root '{0}'. Please specify the full path to the Xcode.app bundle.", sdk_root); } var plist_path = Path.Combine(Path.GetDirectoryName(DeveloperDirectory), "version.plist"); if (File.Exists(plist_path)) { var plist = FromPList(plist_path); var version = plist.GetString("CFBundleShortVersionString"); xcode_version = new Version(version); xcode_product_version = plist.GetString("ProductBuildVersion"); } else { throw ErrorHelper.CreateError(58, "The Xcode.app '{0}' is invalid (the file '{1}' does not exist).", Path.GetDirectoryName(Path.GetDirectoryName(DeveloperDirectory)), plist_path); } if (!accept_any_xcode_version) { if (min_xcode_version != null && XcodeVersion < min_xcode_version) { throw ErrorHelper.CreateError(51, "{3} {0} requires Xcode {4} or later. The current Xcode version (found in {2}) is {1}.", Constants.Version, XcodeVersion.ToString(), sdk_root, PRODUCT, min_xcode_version); } if (XcodeVersion < SdkVersions.XcodeVersion) { ErrorHelper.Warning(79, "The recommended Xcode version for {4} {0} is Xcode {3} or later. The current Xcode version (found in {2}) is {1}.", Constants.Version, XcodeVersion.ToString(), sdk_root, SdkVersions.Xcode, PRODUCT); } } Driver.Log(1, "Using Xcode {0} ({2}) found in {1}", XcodeVersion, sdk_root, XcodeProductVersion); }
static void ValidateXcode(bool accept_any_xcode_version, bool warn_if_not_found) { if (sdk_root == null) { sdk_root = FindSystemXcode(); if (sdk_root == null) { // FindSystemXcode showed a warning in this case. In particular do not use 'string.IsNullOrEmpty' here, // because FindSystemXcode may return an empty string (with no warning printed) if the xcode-select command // succeeds, but returns nothing. sdk_root = null; } else if (!Directory.Exists(sdk_root)) { ErrorHelper.Warning(60, Errors.MX0060, sdk_root); sdk_root = null; } else { if (!accept_any_xcode_version) { ErrorHelper.Warning(61, Errors.MT0061, sdk_root); } } if (sdk_root == null) { sdk_root = XcodeDefault; if (!Directory.Exists(sdk_root)) { if (warn_if_not_found) { // mmp: and now we give up, but don't throw like mtouch, because we don't want to change behavior (this sometimes worked it appears) ErrorHelper.Warning(56, Errors.MX0056); return; // Can't validate the version below if we can't even find Xcode... } throw ErrorHelper.CreateError(56, Errors.MX0056); } ErrorHelper.Warning(62, Errors.MT0062, sdk_root); } } else if (!Directory.Exists(sdk_root)) { throw ErrorHelper.CreateError(55, Errors.MT0055, sdk_root); } // Check what kind of path we got if (File.Exists(Path.Combine(sdk_root, "Contents", "MacOS", "Xcode"))) { // path to the Xcode.app developer_directory = Path.Combine(sdk_root, "Contents", "Developer"); } else if (File.Exists(Path.Combine(sdk_root, "..", "MacOS", "Xcode"))) { // path to Contents/Developer developer_directory = Path.GetFullPath(Path.Combine(sdk_root, "..", "..", "Contents", "Developer")); } else { throw ErrorHelper.CreateError(57, Errors.MT0057, sdk_root); } var plist_path = Path.Combine(Path.GetDirectoryName(DeveloperDirectory), "version.plist"); if (File.Exists(plist_path)) { var plist = FromPList(plist_path); var version = plist.GetString("CFBundleShortVersionString"); xcode_version = new Version(version); xcode_product_version = plist.GetString("ProductBuildVersion"); } else { throw ErrorHelper.CreateError(58, Errors.MT0058, Path.GetDirectoryName(Path.GetDirectoryName(DeveloperDirectory)), plist_path); } if (!accept_any_xcode_version) { if (min_xcode_version != null && XcodeVersion < min_xcode_version) { throw ErrorHelper.CreateError(51, Errors.MT0051, Constants.Version, XcodeVersion.ToString(), sdk_root, PRODUCT, min_xcode_version); } if (XcodeVersion < SdkVersions.XcodeVersion) { ErrorHelper.Warning(79, Errors.MT0079, Constants.Version, XcodeVersion.ToString(), sdk_root, SdkVersions.Xcode, PRODUCT); } } Driver.Log(1, "Using Xcode {0} ({2}) found in {1}", XcodeVersion, sdk_root, XcodeProductVersion); }