Skip to content

Commit a0a11af

Browse files
authored
Adjust SDK validation to allow tools/bin and not allow usr/bin. (#71)
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.
1 parent e21e1aa commit a0a11af

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Xamarin.MacDev/MonoTouchSdk.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class MonoTouchSdk
7272

7373
DateTime lastMTExeWrite = DateTime.MinValue;
7474
PDictionary versions;
75-
bool hasUsrSubdir;
75+
string mtouchPath;
7676

7777
static MonoTouchSdk ()
7878
{
@@ -94,13 +94,15 @@ public MonoTouchSdk (string sdkDir)
9494

9595
public string BinDir {
9696
get {
97-
return Path.Combine (SdkDir, hasUsrSubdir ? "usr/bin" : "bin");
97+
// mtouch is in the bin dir
98+
return Path.GetDirectoryName (mtouchPath);
9899
}
99100
}
100101

101102
public string LibDir {
102103
get {
103-
return Path.Combine (SdkDir, hasUsrSubdir ? "usr/lib" : "lib");
104+
// the lib dir is next to the bin dir
105+
return Path.Combine (Path.GetDirectoryName (BinDir), "lib");
104106
}
105107
}
106108

@@ -179,26 +181,24 @@ static PDictionary CreateDefaultVersionsPlist ()
179181

180182
void Init ()
181183
{
182-
string currentLocation = IsInstalled ? Path.Combine (BinDir, "mtouch") : null;
184+
string currentLocation = IsInstalled ? mtouchPath : null;
183185

184186
IsInstalled = false;
185187
versions = null;
186188

187189
if (string.IsNullOrEmpty (SdkDir)) {
188190
foreach (var loc in DefaultLocations) {
189-
if (IsInstalled = ValidateSdkLocation (loc, out hasUsrSubdir)) {
191+
if (IsInstalled = ValidateSdkLocation (loc, out mtouchPath)) {
190192
SdkDir = loc;
191193
break;
192194
}
193195
}
194196
} else {
195-
IsInstalled = ValidateSdkLocation (SdkDir, out hasUsrSubdir);
197+
IsInstalled = ValidateSdkLocation (SdkDir, out mtouchPath);
196198
}
197199

198-
string mtouch = null;
199200
if (IsInstalled) {
200-
mtouch = Path.Combine (BinDir, "mtouch");
201-
lastMTExeWrite = File.GetLastWriteTimeUtc (mtouch);
201+
lastMTExeWrite = File.GetLastWriteTimeUtc (mtouchPath);
202202
Version = ReadVersion ();
203203

204204
if (Version.CompareTo (requiredXI) >= 0) {
@@ -235,7 +235,7 @@ void Init ()
235235
AnalyticsService.ReportSdkVersion ("XS.Core.SDK.iOS.Version", string.Empty);
236236
}
237237

238-
if (Changed != null && currentLocation != mtouch)
238+
if (Changed != null && currentLocation != mtouchPath)
239239
Changed (this, EventArgs.Empty);
240240
}
241241

@@ -256,23 +256,31 @@ IPhoneSdkVersion ReadVersion ()
256256

257257
public static bool ValidateSdkLocation (string sdkDir)
258258
{
259-
bool hasUsrSubdir;
260-
261-
return ValidateSdkLocation (sdkDir, out hasUsrSubdir);
259+
return ValidateSdkLocation (sdkDir, out string _);
262260
}
263261

264262
public static bool ValidateSdkLocation (string sdkDir, out bool hasUsrSubdir)
265263
{
266264
hasUsrSubdir = false;
265+
return ValidateSdkLocation (sdkDir, out string _);
266+
}
267+
268+
public static bool ValidateSdkLocation (string sdkDir, out string mtouchPath)
269+
{
270+
mtouchPath = null;
267271

268272
if (!File.Exists (Path.Combine (sdkDir, "Version")))
269273
return false;
270274

271-
if (File.Exists (Path.Combine (sdkDir, "bin", "mtouch")))
275+
var path = Path.Combine (sdkDir, "bin", "mtouch");
276+
if (File.Exists (path)) {
277+
mtouchPath = path;
272278
return true;
279+
}
273280

274-
if (File.Exists (Path.Combine (sdkDir, "usr", "bin", "mtouch"))) {
275-
hasUsrSubdir = true;
281+
path = Path.Combine (sdkDir, "tools", "bin", "mtouch");
282+
if (File.Exists (path)) {
283+
mtouchPath = path;
276284
return true;
277285
}
278286

@@ -367,7 +375,7 @@ public void CheckCaches ()
367375
{
368376
if (IsInstalled) {
369377
try {
370-
var lastWrite = File.GetLastWriteTimeUtc (Path.Combine (BinDir, "mtouch"));
378+
var lastWrite = File.GetLastWriteTimeUtc (mtouchPath);
371379
if (lastWrite == lastMTExeWrite)
372380
return;
373381
} catch (IOException) {

0 commit comments

Comments
 (0)