From 02e8fa7b914f332ccf7b27c0e00c20844d6c6512 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 4 Mar 2020 14:52:37 +0100 Subject: [PATCH] Adjust SDK validation to allow tools/bin and not allow usr/bin. Adjust SDK validation to find mtouch in a tools/bin directory (which is where mtouch resides when shipped in a nuget package), and not look in usr/bin (mtouch hasn't been there in a long, long time, and then it was very briefly). Simplify the validation logic to output mtouch's actual path instead of a value indicating the subdirectory where it was found. Additionally compute the bin directory to be mtouch's directory, and the lib directory a sibling of the bin directory. --- Xamarin.MacDev/MonoTouchSdk.cs | 42 ++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/Xamarin.MacDev/MonoTouchSdk.cs b/Xamarin.MacDev/MonoTouchSdk.cs index 339e72b..38d0241 100644 --- a/Xamarin.MacDev/MonoTouchSdk.cs +++ b/Xamarin.MacDev/MonoTouchSdk.cs @@ -72,7 +72,7 @@ public class MonoTouchSdk DateTime lastMTExeWrite = DateTime.MinValue; PDictionary versions; - bool hasUsrSubdir; + string mtouchPath; static MonoTouchSdk () { @@ -94,13 +94,15 @@ public MonoTouchSdk (string sdkDir) public string BinDir { get { - return Path.Combine (SdkDir, hasUsrSubdir ? "usr/bin" : "bin"); + // mtouch is in the bin dir + return Path.GetDirectoryName (mtouchPath); } } public string LibDir { get { - return Path.Combine (SdkDir, hasUsrSubdir ? "usr/lib" : "lib"); + // the lib dir is next to the bin dir + return Path.Combine (Path.GetDirectoryName (BinDir), "lib"); } } @@ -179,26 +181,24 @@ static PDictionary CreateDefaultVersionsPlist () void Init () { - string currentLocation = IsInstalled ? Path.Combine (BinDir, "mtouch") : null; + string currentLocation = IsInstalled ? mtouchPath : null; IsInstalled = false; versions = null; if (string.IsNullOrEmpty (SdkDir)) { foreach (var loc in DefaultLocations) { - if (IsInstalled = ValidateSdkLocation (loc, out hasUsrSubdir)) { + if (IsInstalled = ValidateSdkLocation (loc, out mtouchPath)) { SdkDir = loc; break; } } } else { - IsInstalled = ValidateSdkLocation (SdkDir, out hasUsrSubdir); + IsInstalled = ValidateSdkLocation (SdkDir, out mtouchPath); } - string mtouch = null; if (IsInstalled) { - mtouch = Path.Combine (BinDir, "mtouch"); - lastMTExeWrite = File.GetLastWriteTimeUtc (mtouch); + lastMTExeWrite = File.GetLastWriteTimeUtc (mtouchPath); Version = ReadVersion (); if (Version.CompareTo (requiredXI) >= 0) { @@ -235,7 +235,7 @@ void Init () AnalyticsService.ReportSdkVersion ("XS.Core.SDK.iOS.Version", string.Empty); } - if (Changed != null && currentLocation != mtouch) + if (Changed != null && currentLocation != mtouchPath) Changed (this, EventArgs.Empty); } @@ -256,23 +256,31 @@ IPhoneSdkVersion ReadVersion () public static bool ValidateSdkLocation (string sdkDir) { - bool hasUsrSubdir; - - return ValidateSdkLocation (sdkDir, out hasUsrSubdir); + return ValidateSdkLocation (sdkDir, out string _); } public static bool ValidateSdkLocation (string sdkDir, out bool hasUsrSubdir) { hasUsrSubdir = false; + return ValidateSdkLocation (sdkDir, out string _); + } + + public static bool ValidateSdkLocation (string sdkDir, out string mtouchPath) + { + mtouchPath = null; if (!File.Exists (Path.Combine (sdkDir, "Version"))) return false; - if (File.Exists (Path.Combine (sdkDir, "bin", "mtouch"))) + var path = Path.Combine (sdkDir, "bin", "mtouch"); + if (File.Exists (path)) { + mtouchPath = path; return true; + } - if (File.Exists (Path.Combine (sdkDir, "usr", "bin", "mtouch"))) { - hasUsrSubdir = true; + path = Path.Combine (sdkDir, "tools", "bin", "mtouch"); + if (File.Exists (path)) { + mtouchPath = path; return true; } @@ -367,7 +375,7 @@ public void CheckCaches () { if (IsInstalled) { try { - var lastWrite = File.GetLastWriteTimeUtc (Path.Combine (BinDir, "mtouch")); + var lastWrite = File.GetLastWriteTimeUtc (mtouchPath); if (lastWrite == lastMTExeWrite) return; } catch (IOException) {