diff --git a/Xamarin.MacDev/AppleSdk.cs b/Xamarin.MacDev/AppleSdk.cs index 702cf91..f2d0812 100644 --- a/Xamarin.MacDev/AppleSdk.cs +++ b/Xamarin.MacDev/AppleSdk.cs @@ -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; } @@ -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)) @@ -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 @@ -171,6 +181,11 @@ public IPhoneSdkVersion GetClosestInstalledSdk (IPhoneSdkVersion v, bool sim) return IPhoneSdkVersion.UseDefault; } + IList IAppleSdk.GetInstalledSdkVersions (bool isSimulator) + { + return GetInstalledSdkVersions (isSimulator).Cast ().ToArray (); + } + public IList GetInstalledSdkVersions (bool sim) { return sim ? InstalledSimVersions : InstalledSdkVersions; @@ -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 (value, out version); + } } } diff --git a/Xamarin.MacDev/IAppleSdk.cs b/Xamarin.MacDev/IAppleSdk.cs new file mode 100644 index 0000000..ef6dbde --- /dev/null +++ b/Xamarin.MacDev/IAppleSdk.cs @@ -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 GetInstalledSdkVersions (bool isSimulator); + } +} diff --git a/Xamarin.MacDev/IAppleSdkVersion.cs b/Xamarin.MacDev/IAppleSdkVersion.cs new file mode 100644 index 0000000..93a4b81 --- /dev/null +++ b/Xamarin.MacDev/IAppleSdkVersion.cs @@ -0,0 +1,49 @@ +using System; +namespace Xamarin.MacDev { + public interface IAppleSdkVersion : IEquatable { + 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 (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 (string s, out IAppleSdkVersion result) where T : IAppleSdkVersion, new() + { + var rv = TryParse (s, out T tmp); + result = tmp; + return rv; + } + } +} diff --git a/Xamarin.MacDev/IPhoneSdkVersion.cs b/Xamarin.MacDev/IPhoneSdkVersion.cs index ee6ced7..5973598 100644 --- a/Xamarin.MacDev/IPhoneSdkVersion.cs +++ b/Xamarin.MacDev/IPhoneSdkVersion.cs @@ -29,7 +29,7 @@ namespace Xamarin.MacDev { - public struct IPhoneSdkVersion : IComparable, IEquatable + public struct IPhoneSdkVersion : IComparable, IEquatable, IAppleSdkVersion { int[] version; @@ -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 ('.'); @@ -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 (s, out result); } public int[] Version { get { return version; } } @@ -145,6 +133,11 @@ public override bool Equals (object obj) return false; } + bool IEquatable.Equals (IAppleSdkVersion other) + { + return Equals ((object) other); + } + public override int GetHashCode () { unchecked { @@ -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) { diff --git a/Xamarin.MacDev/MacOSXSdk.cs b/Xamarin.MacDev/MacOSXSdk.cs index 54d1fd7..ed85fc0 100644 --- a/Xamarin.MacDev/MacOSXSdk.cs +++ b/Xamarin.MacDev/MacOSXSdk.cs @@ -30,7 +30,7 @@ namespace Xamarin.MacDev { - public class MacOSXSdk + public class MacOSXSdk : IAppleSdk { List knownOSVersions = new List { MacOSXSdkVersion.V10_7, @@ -133,6 +133,11 @@ public string GetPlatformPath () { return DesktopPlatform; } + + string IAppleSdk.GetPlatformPath (bool isSimulator) + { + return GetPlatformPath (); + } public string GetSdkPath (MacOSXSdkVersion version) { @@ -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) { @@ -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 @@ -241,11 +261,21 @@ public MacOSXSdkVersion GetClosestInstalledSdk (MacOSXSdkVersion v) return MacOSXSdkVersion.UseDefault; } + IList IAppleSdk.GetInstalledSdkVersions (bool isSimulator) + { + return GetInstalledSdkVersions ().Cast ().ToArray (); + } + public IList GetInstalledSdkVersions () { return InstalledSdkVersions; } + bool IAppleSdk.TryParseSdkVersion (string value, out IAppleSdkVersion version) + { + return IAppleSdkVersion_Extensions.TryParse (value, out version); + } + public class DTSettings { public string DTXcodeBuild { get; set; } diff --git a/Xamarin.MacDev/MacOSXSdkVersion.cs b/Xamarin.MacDev/MacOSXSdkVersion.cs index f1a0fed..25002df 100644 --- a/Xamarin.MacDev/MacOSXSdkVersion.cs +++ b/Xamarin.MacDev/MacOSXSdkVersion.cs @@ -27,7 +27,7 @@ namespace Xamarin.MacDev { - public struct MacOSXSdkVersion : IComparable, IEquatable + public struct MacOSXSdkVersion : IComparable, IEquatable, IAppleSdkVersion { int[] version; @@ -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) @@ -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 (s, out result); } public int[] Version { get { return version; } } @@ -124,6 +117,11 @@ public override bool Equals (object obj) return false; } + bool IEquatable.Equals (IAppleSdkVersion other) + { + return Equals ((object) other); + } + public override int GetHashCode () { unchecked { @@ -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 ();