Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Xamarin.MacDev/AppleSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Xamarin.MacDev
{
public abstract class AppleSdk
public abstract class AppleSdk : IAppleSdk
{
public string DeveloperRoot { get; protected set; }
public string VersionPlist { get; protected set; }
Expand Down Expand Up @@ -90,6 +90,11 @@ string GetSdkPlistFilename (string version, bool sim)
return Path.Combine (GetSdkPath (version, sim), "SDKSettings.plist");
}

bool IAppleSdk.SdkIsInstalled (IAppleSdkVersion version, bool isSimulator)
{
return SdkIsInstalled ((IPhoneSdkVersion) version, isSimulator);
}

public bool SdkIsInstalled (IPhoneSdkVersion version, bool sim)
{
foreach (var v in (sim? InstalledSimVersions : InstalledSdkVersions))
Expand Down Expand Up @@ -161,6 +166,11 @@ public AppleDTSettings GetDTSettings ()
});
}

IAppleSdkVersion IAppleSdk.GetClosestInstalledSdk (IAppleSdkVersion version, bool isSimulator)
{
return GetClosestInstalledSdk ((IPhoneSdkVersion) version, isSimulator);
}

public IPhoneSdkVersion GetClosestInstalledSdk (IPhoneSdkVersion v, bool sim)
{
//sorted low to high, so get first that's >= requested version
Expand All @@ -171,6 +181,11 @@ public IPhoneSdkVersion GetClosestInstalledSdk (IPhoneSdkVersion v, bool sim)
return IPhoneSdkVersion.UseDefault;
}

IList<IAppleSdkVersion> IAppleSdk.GetInstalledSdkVersions (bool isSimulator)
{
return GetInstalledSdkVersions (isSimulator).Cast<IAppleSdkVersion> ().ToArray ();
}

public IList<IPhoneSdkVersion> GetInstalledSdkVersions (bool sim)
{
return sim ? InstalledSimVersions : InstalledSdkVersions;
Expand Down Expand Up @@ -227,5 +242,10 @@ protected static string GrabRootString (string file, string key)

return null;
}

bool IAppleSdk.TryParseSdkVersion (string value, out IAppleSdkVersion version)
{
return IAppleSdkVersion_Extensions.TryParse<IPhoneSdkVersion> (value, out version);
}
}
}
15 changes: 15 additions & 0 deletions Xamarin.MacDev/IAppleSdk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;

namespace Xamarin.MacDev {
public interface IAppleSdk {
bool IsInstalled { get; }
string DeveloperRoot { get; }
string GetPlatformPath (bool isSimulator);
string GetSdkPath (string version, bool isSimulator);
bool SdkIsInstalled (IAppleSdkVersion version, bool isSimulator);
bool TryParseSdkVersion (string value, out IAppleSdkVersion version);
IAppleSdkVersion GetClosestInstalledSdk (IAppleSdkVersion version, bool isSimulator);
IList<IAppleSdkVersion> GetInstalledSdkVersions (bool isSimulator);
}
}
49 changes: 49 additions & 0 deletions Xamarin.MacDev/IAppleSdkVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
namespace Xamarin.MacDev {
public interface IAppleSdkVersion : IEquatable<IAppleSdkVersion> {
bool IsUseDefault { get; }
void SetVersion (int [] version);
IAppleSdkVersion GetUseDefault ();
}

public static class IAppleSdkVersion_Extensions {
public static IAppleSdkVersion ResolveIfDefault (this IAppleSdkVersion @this, IAppleSdk sdk, bool sim)
{
return @this.IsUseDefault ? @this.GetDefault (sdk, sim) : @this;
}

public static IAppleSdkVersion GetDefault (this IAppleSdkVersion @this, IAppleSdk sdk, bool sim)
{
var v = sdk.GetInstalledSdkVersions (sim);
return v.Count > 0 ? v [v.Count - 1] : @this.GetUseDefault ();
}

public static bool TryParse<T> (string s, out T result) where T : IAppleSdkVersion, new()
{
result = new T ();
if (s == null)
return false;

var vstr = s.Split ('.');
var vint = new int [vstr.Length];

for (int j = 0; j < vstr.Length; j++) {
int component;
if (!int.TryParse (vstr [j], out component))
return false;

vint [j] = component;
}

result.SetVersion (vint);
return true;
}

public static bool TryParse<T> (string s, out IAppleSdkVersion result) where T : IAppleSdkVersion, new()
{
var rv = TryParse<T> (s, out T tmp);
result = tmp;
return rv;
}
}
}
36 changes: 17 additions & 19 deletions Xamarin.MacDev/IPhoneSdkVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace Xamarin.MacDev
{
public struct IPhoneSdkVersion : IComparable<IPhoneSdkVersion>, IEquatable<IPhoneSdkVersion>
public struct IPhoneSdkVersion : IComparable<IPhoneSdkVersion>, IEquatable<IPhoneSdkVersion>, IAppleSdkVersion
{
int[] version;

Expand Down Expand Up @@ -57,6 +57,11 @@ public IPhoneSdkVersion (params int[] version)
this.version = version;
}

void IAppleSdkVersion.SetVersion (int[] version)
{
this.version = version;
}

public static IPhoneSdkVersion Parse (string s)
{
var vstr = s.Split ('.');
Expand All @@ -70,24 +75,7 @@ public static IPhoneSdkVersion Parse (string s)

public static bool TryParse (string s, out IPhoneSdkVersion result)
{
result = new IPhoneSdkVersion ();

if (s == null)
return false;

var vstr = s.Split ('.');
var vint = new int[vstr.Length];

for (int j = 0; j < vstr.Length; j++) {
int component;
if (!int.TryParse (vstr[j], out component))
return false;

vint[j] = component;
}

result.version = vint;
return true;
return IAppleSdkVersion_Extensions.TryParse<IPhoneSdkVersion> (s, out result);
}

public int[] Version { get { return version; } }
Expand Down Expand Up @@ -145,6 +133,11 @@ public override bool Equals (object obj)
return false;
}

bool IEquatable<IAppleSdkVersion>.Equals (IAppleSdkVersion other)
{
return Equals ((object) other);
}

public override int GetHashCode ()
{
unchecked {
Expand Down Expand Up @@ -190,6 +183,11 @@ public bool IsUseDefault {
get { return version == null || version.Length == 0; }
}

IAppleSdkVersion IAppleSdkVersion.GetUseDefault ()
{
return UseDefault;
}

#if !WINDOWS
public IPhoneSdkVersion ResolveIfDefault (AppleSdk sdk, bool sim)
{
Expand Down
36 changes: 33 additions & 3 deletions Xamarin.MacDev/MacOSXSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Xamarin.MacDev
{
public class MacOSXSdk
public class MacOSXSdk : IAppleSdk
{
List<MacOSXSdkVersion> knownOSVersions = new List<MacOSXSdkVersion> {
MacOSXSdkVersion.V10_7,
Expand Down Expand Up @@ -133,6 +133,11 @@ public string GetPlatformPath ()
{
return DesktopPlatform;
}

string IAppleSdk.GetPlatformPath (bool isSimulator)
{
return GetPlatformPath ();
}

public string GetSdkPath (MacOSXSdkVersion version)
{
Expand All @@ -143,12 +148,22 @@ public string GetSdkPath (string version)
{
return Path.Combine (SdkDeveloperRoot, "SDKs", "MacOSX" + version + ".sdk");
}


string IAppleSdk.GetSdkPath (string version, bool isSimulator)
{
return GetSdkPath (version);
}

string GetSdkPlistFilename (string version)
{
return Path.Combine (GetSdkPath (version), "SDKSettings.plist");
}


bool IAppleSdk.SdkIsInstalled (IAppleSdkVersion version, bool isSimulator)
{
return SdkIsInstalled ((MacOSXSdkVersion) version);
}

public bool SdkIsInstalled (MacOSXSdkVersion version)
{
foreach (var v in InstalledSdkVersions) {
Expand Down Expand Up @@ -231,6 +246,11 @@ static string GrabRootString (string file, string key)
return null;
}

IAppleSdkVersion IAppleSdk.GetClosestInstalledSdk (IAppleSdkVersion version, bool isSimulator)
{
return GetClosestInstalledSdk ((MacOSXSdkVersion) version);
}

public MacOSXSdkVersion GetClosestInstalledSdk (MacOSXSdkVersion v)
{
// sorted low to high, so get first that's >= requested version
Expand All @@ -241,11 +261,21 @@ public MacOSXSdkVersion GetClosestInstalledSdk (MacOSXSdkVersion v)
return MacOSXSdkVersion.UseDefault;
}

IList<IAppleSdkVersion> IAppleSdk.GetInstalledSdkVersions (bool isSimulator)
{
return GetInstalledSdkVersions ().Cast<IAppleSdkVersion> ().ToArray ();
}

public IList<MacOSXSdkVersion> GetInstalledSdkVersions ()
{
return InstalledSdkVersions;
}

bool IAppleSdk.TryParseSdkVersion (string value, out IAppleSdkVersion version)
{
return IAppleSdkVersion_Extensions.TryParse<MacOSXSdkVersion> (value, out version);
}

public class DTSettings
{
public string DTXcodeBuild { get; set; }
Expand Down
36 changes: 22 additions & 14 deletions Xamarin.MacDev/MacOSXSdkVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Xamarin.MacDev
{
public struct MacOSXSdkVersion : IComparable<MacOSXSdkVersion>, IEquatable<MacOSXSdkVersion>
public struct MacOSXSdkVersion : IComparable<MacOSXSdkVersion>, IEquatable<MacOSXSdkVersion>, IAppleSdkVersion
{
int[] version;

Expand All @@ -38,6 +38,11 @@ public MacOSXSdkVersion (params int[] version)
this.version = version;
}

void IAppleSdkVersion.SetVersion (int [] version)
{
this.version = version;
}

public MacOSXSdkVersion (Version version)
{
if (version == null)
Expand All @@ -56,19 +61,7 @@ public static MacOSXSdkVersion Parse (string s)

public static bool TryParse (string s, out MacOSXSdkVersion result)
{
result = new MacOSXSdkVersion ();
if (s == null)
return false;
var vstr = s.Split ('.');
var vint = new int[vstr.Length];
for (int j = 0; j < vstr.Length; j++) {
int component;
if (!int.TryParse (vstr[j], out component))
return false;
vint[j] = component;
}
result.version = vint;
return true;
return IAppleSdkVersion_Extensions.TryParse<MacOSXSdkVersion> (s, out result);
}

public int[] Version { get { return version; } }
Expand Down Expand Up @@ -124,6 +117,11 @@ public override bool Equals (object obj)
return false;
}

bool IEquatable<IAppleSdkVersion>.Equals (IAppleSdkVersion other)
{
return Equals ((object) other);
}

public override int GetHashCode ()
{
unchecked {
Expand Down Expand Up @@ -171,6 +169,16 @@ public bool IsUseDefault {
}
}

IAppleSdkVersion IAppleSdkVersion.GetUseDefault ()
{
return UseDefault;
}

public static MacOSXSdkVersion GetDefault (IAppleSdk sdk)
{
return GetDefault ((MacOSXSdk) sdk);
}

public static MacOSXSdkVersion GetDefault (MacOSXSdk sdk)
{
var v = sdk.GetInstalledSdkVersions ();
Expand Down