Skip to content

Commit

Permalink
Adjust SDK validation to allow tools/bin and not allow usr/bin. (#71)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rolfbjarne authored Mar 5, 2020
1 parent e21e1aa commit a0a11af
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions Xamarin.MacDev/MonoTouchSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MonoTouchSdk

DateTime lastMTExeWrite = DateTime.MinValue;
PDictionary versions;
bool hasUsrSubdir;
string mtouchPath;

static MonoTouchSdk ()
{
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a0a11af

Please sign in to comment.