Exemplo n.º 1
0
        public override bool Execute()
        {
            var currentSdk = IPhoneSdks.GetSdk(TargetFrameworkIdentifier);
            IPhoneSdkVersion version;
            string           sdk_path;

            if (IsWatchFramework)
            {
                if (!IPhoneSdkVersion.TryParse(SdkVersion, out version))
                {
                    Log.LogError("Failed to parse SdkVersion '{0}'.", SdkVersion);
                    return(false);
                }

                version  = currentSdk.GetClosestInstalledSdk(version, false);
                sdk_path = currentSdk.GetSdkPath(version, SdkIsSimulator);
            }
            else
            {
                if (AppleSdkSettings.XcodeVersion.Major >= 10)
                {
                    Log.LogError("Xcode 10 does not support watchOS 1 apps. Either upgrade to watchOS 2 apps, or use an older version of Xcode.");
                    return(false);
                }
                if (!(AppleSdkSettings.XcodeVersion.Major > 6 || (AppleSdkSettings.XcodeVersion.Major == 6 && AppleSdkSettings.XcodeVersion.Minor >= 2)))
                {
                    Log.LogError("An installation of Xcode >= 6.2 is required to build WatchKit applications.");
                    return(false);
                }

                if (!IPhoneSdkVersion.TryParse(SdkVersion, out version))
                {
                    Log.LogError("Failed to parse SdkVersion '{0}'.", SdkVersion);
                    return(false);
                }

                if (version < IPhoneSdkVersion.V8_2)
                {
                    Log.LogError("iOS {0} does not support WatchKit.", version);
                    return(false);
                }

                version  = currentSdk.GetClosestInstalledSdk(version, false);
                sdk_path = currentSdk.GetSdkPath(version, SdkIsSimulator);
            }

            NativeWatchApp = Path.Combine(sdk_path, "Library", "Application Support", "WatchKit", "WK");
            if (File.Exists(NativeWatchApp))
            {
                return(true);
            }

            Log.LogError("Failed to locate the WatchKit launcher in the Xcode app bundle.");

            return(false);
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            var currentSdk = IPhoneSdks.GetSdk(TargetFrameworkMoniker);
            IPhoneSdkVersion version;
            string           sdk_path;

            if (IsWatchFramework)
            {
                if (!IPhoneSdkVersion.TryParse(SdkVersion, out version))
                {
                    Log.LogError(MSBStrings.E0066, SdkVersion);
                    return(false);
                }

                version  = currentSdk.GetClosestInstalledSdk(version, false);
                sdk_path = currentSdk.GetSdkPath(version, SdkIsSimulator);
            }
            else
            {
                if (AppleSdkSettings.XcodeVersion.Major >= 10)
                {
                    Log.LogError(MSBStrings.E0067);
                    return(false);
                }
                if (!(AppleSdkSettings.XcodeVersion.Major > 6 || (AppleSdkSettings.XcodeVersion.Major == 6 && AppleSdkSettings.XcodeVersion.Minor >= 2)))
                {
                    Log.LogError(MSBStrings.E0068);
                    return(false);
                }

                if (!IPhoneSdkVersion.TryParse(SdkVersion, out version))
                {
                    Log.LogError(MSBStrings.E0066, SdkVersion);
                    return(false);
                }

                if (version < IPhoneSdkVersion.V8_2)
                {
                    Log.LogError(MSBStrings.E0069, version);
                    return(false);
                }

                version  = currentSdk.GetClosestInstalledSdk(version, false);
                sdk_path = currentSdk.GetSdkPath(version, SdkIsSimulator);
            }

            NativeWatchApp = Path.Combine(sdk_path, "Library", "Application Support", "WatchKit", "WK");
            if (File.Exists(NativeWatchApp))
            {
                return(true);
            }

            Log.LogError(MSBStrings.E0070);

            return(false);
        }
Exemplo n.º 3
0
        public override bool Execute()
        {
            AppleSdkSettings.CheckChanged();
            IPhoneSdks.Reload();

            TargetArchitecture architectures;

            if (string.IsNullOrEmpty(TargetArchitectures) || !Enum.TryParse(TargetArchitectures, out architectures))
            {
                architectures = TargetArchitecture.Default;
            }

            SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;

            IsXcode8 = AppleSdkSettings.XcodeVersion.Major >= 8;

            if (EnsureAppleSdkRoot())
            {
                switch (Framework)
                {
                case PlatformFramework.iOS:
                    EnsureiOSSdkPath();
                    break;

                case PlatformFramework.TVOS:
                    EnsureTVOSSdkPath();
                    break;

                case PlatformFramework.WatchOS:
                    EnsureWatchSdkPath();
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Invalid framework: {0}", Framework));
                }
            }
            EnsureXamarinSdkRoot();

            Log.LogTaskName("DetectSdkLocations");
            Log.LogTaskProperty("TargetFrameworkIdentifier", TargetFrameworkIdentifier);
            Log.LogTaskProperty("TargetArchitectures", TargetArchitectures);
            Log.LogTaskProperty("SdkVersion", SdkVersion);
            Log.LogTaskProperty("XamarinSdkRoot", XamarinSdkRoot);
            Log.LogTaskProperty("SdkRoot", SdkRoot);
            Log.LogTaskProperty("SdkDevPath", SdkDevPath);
            Log.LogTaskProperty("SdkUsrPath", SdkUsrPath);
            Log.LogTaskProperty("SdkPlatform", SdkPlatform);
            Log.LogTaskProperty("SdkIsSimulator", SdkIsSimulator);

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 4
0
        static IBTool CreateIBToolTask(ApplePlatform framework, string projectDir, string intermediateOutputPath)
        {
            var    interfaceDefinitions = new List <ITaskItem> ();
            var    sdk     = IPhoneSdks.GetSdk(framework);
            var    version = IPhoneSdkVersion.GetDefault(sdk, false);
            var    root    = sdk.GetSdkPath(version, false);
            var    usr     = Path.Combine(sdk.DeveloperRoot, "usr");
            var    bin     = Path.Combine(usr, "bin");
            string platform;

            switch (framework)
            {
            case ApplePlatform.WatchOS:
                platform = "WatchOS";
                break;

            case ApplePlatform.TVOS:
                platform = "AppleTVOS";
                break;

            default:
                platform = "iPhoneOS";
                break;
            }

            foreach (var item in Directory.EnumerateFiles(projectDir, "*.storyboard", SearchOption.AllDirectories))
            {
                interfaceDefinitions.Add(new TaskItem(item));
            }

            foreach (var item in Directory.EnumerateFiles(projectDir, "*.xib", SearchOption.AllDirectories))
            {
                interfaceDefinitions.Add(new TaskItem(item));
            }

            return(new IBTool {
                AppManifest = new TaskItem(Path.Combine(projectDir, "Info.plist")),
                InterfaceDefinitions = interfaceDefinitions.ToArray(),
                IntermediateOutputPath = intermediateOutputPath,
                BuildEngine = new TestEngine(),
                MinimumOSVersion = PDictionary.FromFile(Path.Combine(projectDir, "Info.plist")).GetMinimumOSVersion(),
                ResourcePrefix = "Resources",
                ProjectDir = projectDir,
                SdkDevPath = Configuration.xcode_root,
                SdkPlatform = platform,
                SdkVersion = version.ToString(),
                SdkUsrPath = usr,
                SdkBinPath = bin,
                SdkRoot = root,
            });
        }
Exemplo n.º 5
0
        public override bool Execute()
        {
            AppleSdkSettings.Init();
            IPhoneSdks.Reload();

            TargetArchitecture architectures;

            if (string.IsNullOrEmpty(TargetArchitectures) || !Enum.TryParse(TargetArchitectures, out architectures))
            {
                architectures = TargetArchitecture.Default;
            }

            SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;

            return(base.Execute());
        }
Exemplo n.º 6
0
        public override bool Execute()
        {
            AppleSdkSettings.Init();
            IPhoneSdks.Reload();

            TargetArchitecture architectures;

            if (string.IsNullOrEmpty(TargetArchitectures) || !Enum.TryParse(TargetArchitectures, out architectures))
            {
                architectures = TargetArchitecture.Default;
            }

            SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;

            IsXcode8 = AppleSdkSettings.XcodeVersion.Major >= 8;

            if (EnsureAppleSdkRoot())
            {
                switch (Framework)
                {
                case ApplePlatform.iOS:
                    EnsureiOSSdkPath();
                    break;

                case ApplePlatform.TVOS:
                    EnsureTVOSSdkPath();
                    break;

                case ApplePlatform.WatchOS:
                    EnsureWatchSdkPath();
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Invalid framework: {0}", Framework));
                }
            }
            EnsureXamarinSdkRoot();

            return(!Log.HasLoggedErrors);
        }
        bool Compile(PDictionary plist)
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                Log.LogError(null, null, null, null, 0, 0, 0, 0, "The {0} SDK for '{1}' is not installed.", Framework, sdkVersion);
                return(false);
            }

            supportedDevices = plist.GetUIDeviceFamily();

            if (!IsWatchApp)
            {
                var version = IPhoneSdks.MonoTouch.ExtendedVersion;
                // This key is our supported way of determining if an app
                // was built with Xamarin, so it needs to be present in all apps.

                var dict = new PDictionary();
                dict.Add("Version", new PString(string.Format("{0} ({1}: {2})", version.Version, version.Branch, version.Hash)));
                plist.Add("com.xamarin.ios", dict);
            }

            var sdkSettings = currentSDK.GetSdkSettings(sdkVersion, SdkIsSimulator);
            var dtSettings  = currentSDK.GetDTSettings();

            SetValue(plist, ManifestKeys.BuildMachineOSBuild, dtSettings.BuildMachineOSBuild);
            plist.SetIfNotPresent(ManifestKeys.CFBundleDevelopmentRegion, "en");

            plist.SetIfNotPresent(ManifestKeys.CFBundleExecutable, AssemblyName);
            if (IsIOS)
            {
                var executable = plist.GetCFBundleExecutable();
                if (executable.EndsWith(".app", StringComparison.Ordinal))
                {
                    LogAppManifestError("The executable (CFBundleExecutable) name ({0}) cannot end with '.app', because iOS may fail to launch the app.", executable);
                }
            }

            if (IsIOS)
            {
                if (minimumOSVersion < IPhoneSdkVersion.V5_0 && plist.GetUIMainStoryboardFile(true) != null)
                {
                    LogAppManifestError("Applications using a storyboard as the Main Interface must have a deployment target greater than 5.0");
                }

                if (!plist.ContainsKey(ManifestKeys.CFBundleName))
                {
                    plist [ManifestKeys.CFBundleName] = plist.ContainsKey(ManifestKeys.CFBundleDisplayName) ? plist.GetString(ManifestKeys.CFBundleDisplayName).Clone() : new PString(AppBundleName);
                }
            }
            else
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleName, AppBundleName);
            }

            plist.SetIfNotPresent(ManifestKeys.CFBundleIdentifier, BundleIdentifier);
            plist.SetIfNotPresent(ManifestKeys.CFBundleInfoDictionaryVersion, "6.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundlePackageType, IsAppExtension ? "XPC!" : "APPL");
            if (!string.IsNullOrEmpty(ResourceRules))
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleResourceSpecification, Path.GetFileName(ResourceRules));
            }
            plist.SetIfNotPresent(ManifestKeys.CFBundleSignature, "????");
            if (!plist.ContainsKey(ManifestKeys.CFBundleSupportedPlatforms))
            {
                plist[ManifestKeys.CFBundleSupportedPlatforms] = new PArray {
                    SdkPlatform
                }
            }
            ;
            plist.SetIfNotPresent(ManifestKeys.CFBundleVersion, "1.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundleShortVersionString, plist.GetCFBundleVersion());

            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTCompiler", sdkSettings.DTCompiler);
                SetValue(plist, "DTPlatformBuild", dtSettings.DTPlatformBuild);
                SetValue(plist, "DTSDKBuild", sdkSettings.DTSDKBuild);
            }

            plist.SetIfNotPresent("DTPlatformName", SdkPlatform.ToLowerInvariant());
            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTPlatformVersion", dtSettings.DTPlatformVersion);
            }

            var sdkName = sdkSettings.CanonicalName;

            // older sdksettings didn't have a canonicalname for sim
            if (SdkIsSimulator && string.IsNullOrEmpty(sdkName))
            {
                var deviceSdkSettings = currentSDK.GetSdkSettings(sdkVersion, false);
                sdkName = deviceSdkSettings.AlternateSDK;
            }
            SetValue(plist, "DTSDKName", sdkName);

            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTXcode", AppleSdkSettings.DTXcode);
                SetValue(plist, "DTXcodeBuild", dtSettings.DTXcodeBuild);
            }

            SetDeviceFamily(plist);

            plist.SetIfNotPresent(ManifestKeys.MinimumOSVersion, minimumOSVersion.ToString());

            if (IsWatchExtension && Debug)
            {
                SetAppTransportSecurity(plist);
            }

            // Remove any Xamarin Studio specific keys
            plist.Remove(ManifestKeys.XSLaunchImageAssets);
            plist.Remove(ManifestKeys.XSAppIconAssets);

            // Merge with any partial plists generated by the Asset Catalog compiler...
            MergePartialPlistTemplates(plist);

            if (IsIOS)
            {
                Validation(plist);
            }

            CompiledAppManifest = new TaskItem(Path.Combine(AppBundleDir, "Info.plist"));
            plist.Save(CompiledAppManifest.ItemSpec, true, true);

            return(!Log.HasLoggedErrors);
        }

        void SetDeviceFamily(PDictionary plist)
        {
            switch (Framework)
            {
            case PlatformFramework.iOS:
                SetIOSDeviceFamily(plist);
                break;

            case PlatformFramework.WatchOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                break;

            case PlatformFramework.TVOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.TV);
                break;
            }
        }

        void SetIOSDeviceFamily(PDictionary plist)
        {
            if (IsWatchApp)
            {
                if (SdkIsSimulator)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone | IPhoneDeviceType.Watch);
                }
                else
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                }
            }
            else
            {
                if (!IsAppExtension)
                {
                    plist.SetIfNotPresent(ManifestKeys.LSRequiresIPhoneOS, true);
                }

                if (minimumOSVersion >= IPhoneSdkVersion.V3_2 && supportedDevices == IPhoneDeviceType.NotSet)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone);
                }
            }
        }

        void SetAppTransportSecurity(PDictionary plist)
        {
            // Debugging over http has a couple of gotchas:
            // * We can't use https, because that requires a valid server certificate,
            //   which we can't ensure.
            //   It would also require a hostname for the mac, which it might not have either.
            // * NSAppTransportSecurity/NSExceptionDomains does not allow exceptions based
            //   on IP address (only hostname).
            // * Which means the only way to make sure watchOS allows connections from
            //   the app on device to the mac is to disable App Transport Security altogether.
            // Good news: watchOS 3 will apparently not apply ATS when connecting
            // directly to IP addresses, which means we won't have to do this at all
            // (sometime in the future).

            PDictionary ats;

            if (!plist.TryGetValue(ManifestKeys.NSAppTransportSecurity, out ats))
            {
                plist.Add(ManifestKeys.NSAppTransportSecurity, ats = new PDictionary());
            }

            if (ats.GetBoolean(ManifestKeys.NSAllowsArbitraryLoads))
            {
                Log.LogMessage(MessageImportance.Low, "All http loads are already allowed.");
            }
            else
            {
                Log.LogMessage(MessageImportance.Low, "Allowed arbitrary HTTP loads to support debugging.");
                ats.SetBooleanOrRemove(ManifestKeys.NSAllowsArbitraryLoads, true);
            }
        }

        void Validation(PDictionary plist)
        {
            var supportsIPhone = (supportedDevices & IPhoneDeviceType.IPhone) != 0 ||
                                 supportedDevices == IPhoneDeviceType.NotSet;
            var supportsIPad = (supportedDevices & IPhoneDeviceType.IPad) != 0;

            // Validation...
            if (!IsAppExtension && sdkVersion >= IPhoneSdkVersion.V3_2)
            {
                IPhoneOrientation orientation;

                if (supportsIPhone)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(false);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPhone orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPhone orientations are not matched pairs");
                    }
                }

                if (supportsIPad)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(true);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPad orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPad orientations are not matched pairs");
                    }
                }
            }
        }
    }
        bool Compile(PDictionary plist)
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                Log.LogError(null, null, null, null, 0, 0, 0, 0, "The {0} SDK for '{1}' is not installed.", Framework, sdkVersion);
                return(false);
            }

            supportedDevices = plist.GetUIDeviceFamily();

            if (!IsWatchApp)
            {
                var version = IPhoneSdks.MonoTouch.ExtendedVersion;
                // This key is our supported way of determining if an app
                // was built with Xamarin, so it needs to be present in all apps.

                var dict = new PDictionary();
                dict.Add("Version", new PString(string.Format("{0} ({1}: {2})", version.Version, version.Branch, version.Hash)));
                plist.Add("com.xamarin.ios", dict);
            }

            var sdkSettings = currentSDK.GetSdkSettings(sdkVersion, SdkIsSimulator);
            var dtSettings  = currentSDK.GetDTSettings();

            SetValue(plist, ManifestKeys.BuildMachineOSBuild, dtSettings.BuildMachineOSBuild);
            // We have an issue here, this is for consideration by the platform:
            // CFLocaleCopyCurrent(), used in the mono code to get the current locale (locale.c line 421), will return the value of the application's CFBundleDevelopmentRegion Info.plist key if all of the following conditions are true:
            //
            // * CFBundleDevelopmentRegion is present in the Info.plist
            // * The CFBundleDevelopmentRegion language is in the list of preferred languages on the iOS device, but isn't the first one
            // * There are no localized resources (i.e. no .lproj directory) in the app for the first preferred locale
            //
            // This differs from iOS 10 where the presence of the CFBundleDevelopmentRegion key had no effect. Commenting this line out, ensures that CurrentCulture is correct and behaves like the iOS 10 version.
            // plist.SetIfNotPresent (ManifestKeys.CFBundleDevelopmentRegion, "en");

            plist.SetIfNotPresent(ManifestKeys.CFBundleExecutable, AssemblyName);
            if (IsIOS)
            {
                var executable = plist.GetCFBundleExecutable();
                if (executable.EndsWith(".app", StringComparison.Ordinal))
                {
                    LogAppManifestError("The executable (CFBundleExecutable) name ({0}) cannot end with '.app', because iOS may fail to launch the app.", executable);
                }
            }

            if (IsIOS)
            {
                if (minimumOSVersion < IPhoneSdkVersion.V5_0 && plist.GetUIMainStoryboardFile(true) != null)
                {
                    LogAppManifestError("Applications using a storyboard as the Main Interface must have a deployment target greater than 5.0");
                }

                if (!plist.ContainsKey(ManifestKeys.CFBundleName))
                {
                    plist [ManifestKeys.CFBundleName] = plist.ContainsKey(ManifestKeys.CFBundleDisplayName) ? plist.GetString(ManifestKeys.CFBundleDisplayName).Clone() : new PString(AppBundleName);
                }
            }
            else
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleName, AppBundleName);
            }

            plist.SetIfNotPresent(ManifestKeys.CFBundleIdentifier, BundleIdentifier);
            plist.SetIfNotPresent(ManifestKeys.CFBundleInfoDictionaryVersion, "6.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundlePackageType, IsAppExtension ? "XPC!" : "APPL");
            if (!string.IsNullOrEmpty(ResourceRules))
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleResourceSpecification, Path.GetFileName(ResourceRules));
            }
            plist.SetIfNotPresent(ManifestKeys.CFBundleSignature, "????");
            if (!plist.ContainsKey(ManifestKeys.CFBundleSupportedPlatforms))
            {
                plist[ManifestKeys.CFBundleSupportedPlatforms] = new PArray {
                    SdkPlatform
                }
            }
            ;
            plist.SetIfNotPresent(ManifestKeys.CFBundleVersion, "1.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundleShortVersionString, plist.GetCFBundleVersion());

            string dtCompiler        = null;
            string dtPlatformBuild   = null;
            string dtSDKBuild        = null;
            string dtPlatformName    = null;
            string dtPlatformVersion = null;
            string dtXcode           = null;
            string dtXcodeBuild      = null;

            if (!SdkIsSimulator)
            {
                dtCompiler      = sdkSettings.DTCompiler;
                dtPlatformBuild = dtSettings.DTPlatformBuild;
                dtSDKBuild      = sdkSettings.DTSDKBuild;
            }

            dtPlatformName = SdkPlatform.ToLowerInvariant();
            if (!SdkIsSimulator)
            {
                dtPlatformVersion = dtSettings.DTPlatformVersion;
            }

            var dtSDKName = sdkSettings.CanonicalName;

            // older sdksettings didn't have a canonicalname for sim
            if (SdkIsSimulator && string.IsNullOrEmpty(dtSDKName))
            {
                var deviceSdkSettings = currentSDK.GetSdkSettings(sdkVersion, false);
                dtSDKName = deviceSdkSettings.AlternateSDK;
            }

            if (!SdkIsSimulator)
            {
                dtXcode      = AppleSdkSettings.DTXcode;
                dtXcodeBuild = dtSettings.DTXcodeBuild;
            }

            if (UseFakeWatchOS4_3Sdk)
            {
                // This is a workaround for https://github.com/xamarin/xamarin-macios/issues/4810
                if (Framework == PlatformFramework.WatchOS)
                {
                    if (dtPlatformBuild != null)
                    {
                        dtPlatformBuild = "15T212";
                    }
                    if (dtPlatformVersion != null)
                    {
                        dtPlatformVersion = "4.3";
                    }
                    if (dtSDKBuild != null)
                    {
                        dtSDKBuild = "15T212";
                    }
                    if (dtSDKName != null)
                    {
                        dtSDKName = "watchos4.3";
                    }
                    if (dtXcode != null)
                    {
                        dtXcode = "0940";
                    }
                    if (dtXcodeBuild != null)
                    {
                        dtXcodeBuild = "9F1027a";
                    }
                }
                else
                {
                    Log.LogWarning("Can only fake the watchOS 4.3 SDK when building for watchOS.");
                }
            }

            SetValueIfNotNull(plist, "DTCompiler", dtCompiler);
            SetValueIfNotNull(plist, "DTPlatformBuild", dtPlatformBuild);
            SetValueIfNotNull(plist, "DTSDKBuild", dtSDKBuild);
            plist.SetIfNotPresent("DTPlatformName", dtPlatformName);
            SetValueIfNotNull(plist, "DTPlatformVersion", dtPlatformVersion);
            SetValue(plist, "DTSDKName", dtSDKName);
            SetValueIfNotNull(plist, "DTXcode", dtXcode);
            SetValueIfNotNull(plist, "DTXcodeBuild", dtXcodeBuild);

            SetDeviceFamily(plist);

            plist.SetIfNotPresent(ManifestKeys.MinimumOSVersion, minimumOSVersion.ToString());

            if (IsWatchExtension)
            {
                // Note: Only watchOS1 Extensions target Xamarin.iOS
                if (Framework == PlatformFramework.iOS)
                {
                    PObject value;

                    if (!plist.TryGetValue(ManifestKeys.UIRequiredDeviceCapabilities, out value))
                    {
                        var capabilities = new PArray();
                        capabilities.Add(new PString("watch-companion"));

                        plist.Add(ManifestKeys.UIRequiredDeviceCapabilities, capabilities);
                    }
                    else if (value is PDictionary)
                    {
                        var capabilities = (PDictionary)value;

                        if (!capabilities.ContainsKey("watch-companion"))
                        {
                            capabilities.Add("watch-companion", new PBoolean(true));
                        }
                    }
                    else
                    {
                        var  capabilities = (PArray)value;
                        bool exists       = false;

                        foreach (var capability in capabilities.OfType <PString> ())
                        {
                            if (capability.Value != "watch-companion")
                            {
                                continue;
                            }

                            exists = true;
                            break;
                        }

                        if (!exists)
                        {
                            capabilities.Add(new PString("watch-companion"));
                        }
                    }
                }

                if (Debug)
                {
                    SetAppTransportSecurity(plist);
                }
            }

            // Remove any Xamarin Studio specific keys
            plist.Remove(ManifestKeys.XSLaunchImageAssets);
            plist.Remove(ManifestKeys.XSAppIconAssets);

            // Merge with any partial plists generated by the Asset Catalog compiler...
            MergePartialPlistTemplates(plist);

            SetRequiredArchitectures(plist);

            if (IsIOS)
            {
                Validation(plist);
            }

            CompiledAppManifest = new TaskItem(Path.Combine(AppBundleDir, "Info.plist"));
            plist.Save(CompiledAppManifest.ItemSpec, true, true);

            return(!Log.HasLoggedErrors);
        }

        void SetValueIfNotNull(PDictionary dict, string key, string value)
        {
            if (value == null)
            {
                return;
            }
            SetValue(dict, key, value);
        }

        void SetRequiredArchitectures(PDictionary plist)
        {
            PObject capabilities;

            if (plist.TryGetValue(ManifestKeys.UIRequiredDeviceCapabilities, out capabilities))
            {
                if (capabilities is PArray)
                {
                    var architectureValues = new HashSet <string> (new[] { "armv6", "armv7", "arm64" });
                    var array = (PArray)capabilities;

                    // Remove any architecture values
                    for (int i = 0; i < array.Count; i++)
                    {
                        var value = array[i] as PString;

                        if (value == null || !architectureValues.Contains(value.Value))
                        {
                            continue;
                        }

                        array.RemoveAt(i);
                    }

                    // If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
                    switch (architectures)
                    {
                    case TargetArchitecture.ARM64:
                        array.Add(new PString("arm64"));
                        break;

                    case TargetArchitecture.ARMv7:
                        array.Add(new PString("armv7"));
                        break;
                    }
                }
                else if (capabilities is PDictionary)
                {
                    var dict = (PDictionary)capabilities;

                    switch (architectures)
                    {
                    case TargetArchitecture.ARM64:
                        dict["arm64"] = new PBoolean(true);
                        dict.Remove("armv6");
                        dict.Remove("armv7");
                        break;

                    case TargetArchitecture.ARMv7:
                        dict["armv7"] = new PBoolean(true);
                        dict.Remove("armv6");
                        dict.Remove("arm64");
                        break;

                    default:
                        dict.Remove("armv6");
                        dict.Remove("armv7");
                        dict.Remove("arm64");
                        break;
                    }
                }
            }
            else
            {
                var array = new PArray();

                // If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
                switch (architectures)
                {
                case TargetArchitecture.ARM64:
                    array.Add(new PString("arm64"));
                    break;

                case TargetArchitecture.ARMv7:
                    array.Add(new PString("armv7"));
                    break;
                }

                if (array.Count > 0)
                {
                    plist.Add(ManifestKeys.UIRequiredDeviceCapabilities, array);
                }
            }
        }

        void SetDeviceFamily(PDictionary plist)
        {
            switch (Framework)
            {
            case PlatformFramework.iOS:
                SetIOSDeviceFamily(plist);
                break;

            case PlatformFramework.WatchOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                break;

            case PlatformFramework.TVOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.TV);
                break;
            }
        }

        void SetIOSDeviceFamily(PDictionary plist)
        {
            if (IsWatchApp)
            {
                if (SdkIsSimulator)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone | IPhoneDeviceType.Watch);
                }
                else
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                }
            }
            else
            {
                if (!IsAppExtension)
                {
                    plist.SetIfNotPresent(ManifestKeys.LSRequiresIPhoneOS, true);
                }

                if (minimumOSVersion >= IPhoneSdkVersion.V3_2 && supportedDevices == IPhoneDeviceType.NotSet)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone);
                }
            }
        }

        void SetAppTransportSecurity(PDictionary plist)
        {
            // Debugging over http has a couple of gotchas:
            // * We can't use https, because that requires a valid server certificate,
            //   which we can't ensure.
            //   It would also require a hostname for the mac, which it might not have either.
            // * NSAppTransportSecurity/NSExceptionDomains does not allow exceptions based
            //   on IP address (only hostname).
            // * Which means the only way to make sure watchOS allows connections from
            //   the app on device to the mac is to disable App Transport Security altogether.
            // Good news: watchOS 3 will apparently not apply ATS when connecting
            // directly to IP addresses, which means we won't have to do this at all
            // (sometime in the future).

            PDictionary ats;

            if (!plist.TryGetValue(ManifestKeys.NSAppTransportSecurity, out ats))
            {
                plist.Add(ManifestKeys.NSAppTransportSecurity, ats = new PDictionary());
            }

            if (ats.GetBoolean(ManifestKeys.NSAllowsArbitraryLoads))
            {
                Log.LogMessage(MessageImportance.Low, "All http loads are already allowed.");
            }
            else
            {
                Log.LogMessage(MessageImportance.Low, "Allowed arbitrary HTTP loads to support debugging.");
                ats.SetBooleanOrRemove(ManifestKeys.NSAllowsArbitraryLoads, true);
            }
        }

        void Validation(PDictionary plist)
        {
            var supportsIPhone = (supportedDevices & IPhoneDeviceType.IPhone) != 0 ||
                                 supportedDevices == IPhoneDeviceType.NotSet;
            var supportsIPad = (supportedDevices & IPhoneDeviceType.IPad) != 0;

            // Validation...
            if (!IsAppExtension && sdkVersion >= IPhoneSdkVersion.V3_2)
            {
                IPhoneOrientation orientation;

                if (supportsIPhone)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(false);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPhone orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPhone orientations are not matched pairs");
                    }
                }

                if (supportsIPad)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(true);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPad orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPad orientations are not matched pairs");
                    }
                }
            }
        }
    }
        void EnsureiOSSdkPath()
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);
            IPhoneSdkVersion requestedSdkVersion;

            if (string.IsNullOrEmpty(SdkVersion))
            {
                requestedSdkVersion = IPhoneSdkVersion.UseDefault;
            }
            else if (!IPhoneSdkVersion.TryParse(SdkVersion, out requestedSdkVersion))
            {
                Log.LogError("Could not parse the SDK version '{0}'", SdkVersion);
                return;
            }

            var sdkVersion = requestedSdkVersion.ResolveIfDefault(currentSDK, SdkIsSimulator);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                sdkVersion = currentSDK.GetClosestInstalledSdk(sdkVersion, SdkIsSimulator);

                if (sdkVersion.IsUseDefault || !currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
                {
                    if (requestedSdkVersion.IsUseDefault)
                    {
                        Log.LogError("The Apple iOS SDK is not installed.");
                    }
                    else
                    {
                        Log.LogError("The iOS SDK version '{0}' is not installed, and no newer version was found.", requestedSdkVersion.ToString());
                    }
                    return;
                }
                Log.LogWarning("The iOS SDK version '{0}' is not installed. Using newer version '{1}' instead'.", requestedSdkVersion, sdkVersion);
            }

            SdkVersion = sdkVersion.ToString();

            var platformDir = currentSDK.GetPlatformPath(SdkIsSimulator);

            if (string.IsNullOrEmpty(platformDir) || !Directory.Exists(platformDir))
            {
                Log.LogError("Could not locate the iOS platform directory at path '{0}'", platformDir);
            }

            SdkRoot = currentSDK.GetSdkPath(sdkVersion, SdkIsSimulator);
            if (string.IsNullOrEmpty(SdkRoot) || !Directory.Exists(SdkRoot))
            {
                Log.LogError("Could not locate the iOS '{0}' SDK at path '{1}'", SdkVersion, SdkRoot);
            }

            // Note: Developer/Platforms/iPhoneOS.platform/Developer/usr is a physical directory, but
            // Developer/Platforms/iPhoneSimulator.platform/Developer/bin has always been a symlink
            // to Developer/bin and starting with Xcode 7 Beta 2, the usr symlink no longer exists.
            SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(platformDir, "Developer", "usr"));
            if (string.IsNullOrEmpty(SdkUsrPath))
            {
                SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(currentSDK.DeveloperRoot, "usr"));
                if (string.IsNullOrEmpty(SdkUsrPath))
                {
                    Log.LogError("Could not locate the iOS '{0}' SDK usr path at '{1}'", SdkVersion, SdkRoot);
                }
            }

            SdkBinPath = DirExists("SDK bin directory", Path.Combine(SdkUsrPath, "bin"));
            if (string.IsNullOrEmpty(SdkBinPath))
            {
                Log.LogError("Could not locate SDK bin directory");
            }

            SdkPlatform = SdkIsSimulator ? "iPhoneSimulator" : "iPhoneOS";
        }
        void EnsureWatchSdkPath()
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);
            IPhoneSdkVersion requestedSdkVersion;

            if (string.IsNullOrEmpty(SdkVersion))
            {
                requestedSdkVersion = IPhoneSdkVersion.UseDefault;
            }
            else if (!IPhoneSdkVersion.TryParse(SdkVersion, out requestedSdkVersion))
            {
                Log.LogError("Could not parse the SDK version '{0}'", SdkVersion);
                return;
            }

            var sdkVersion = requestedSdkVersion.ResolveIfDefault(currentSDK, SdkIsSimulator);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                sdkVersion = currentSDK.GetClosestInstalledSdk(sdkVersion, SdkIsSimulator);

                if (sdkVersion.IsUseDefault || !currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
                {
                    if (requestedSdkVersion.IsUseDefault)
                    {
                        Log.LogError("The Apple Watch SDK is not installed.");
                    }
                    else
                    {
                        Log.LogError("The Watch SDK version '{0}' is not installed, and no newer version was found.", requestedSdkVersion.ToString());
                    }
                    return;
                }
                Log.LogWarning("The Watch SDK version '{0}' is not installed. Using newer version '{1}' instead'.", requestedSdkVersion, sdkVersion);
            }

            SdkVersion = sdkVersion.ToString();

            var platformDir = currentSDK.GetPlatformPath(SdkIsSimulator);

            if (string.IsNullOrEmpty(platformDir) || !Directory.Exists(platformDir))
            {
                Log.LogError("Could not locate the WatchOS platform directory at path '{0}'", platformDir);
            }

            SdkRoot = currentSDK.GetSdkPath(sdkVersion, SdkIsSimulator);
            if (string.IsNullOrEmpty(SdkRoot) || !Directory.Exists(SdkRoot))
            {
                Log.LogError("Could not locate the WatchOS '{0}' SDK at path '{1}'", SdkVersion, SdkRoot);
            }

            SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(currentSDK.DeveloperRoot, "usr"));
            if (string.IsNullOrEmpty(SdkUsrPath))
            {
                Log.LogError("Could not locate the WatchOS '{0}' SDK usr path at '{1}'", SdkVersion, SdkRoot);
            }

            SdkBinPath = DirExists("SDK bin directory", Path.Combine(SdkUsrPath, "bin"));
            if (string.IsNullOrEmpty(SdkBinPath))
            {
                Log.LogError("Could not locate SDK bin directory");
            }

            SdkPlatform = SdkIsSimulator ? "WatchSimulator" : "WatchOS";
        }
Exemplo n.º 11
0
        bool Compile(PDictionary plist)
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                Log.LogError(null, null, null, null, 0, 0, 0, 0, "The {0} SDK for '{1}' is not installed.", Framework, sdkVersion);
                return(false);
            }

            supportedDevices = plist.GetUIDeviceFamily();

            if (!IsWatchApp)
            {
                var version = IPhoneSdks.MonoTouch.ExtendedVersion;
                // This key is our supported way of determining if an app
                // was built with Xamarin, so it needs to be present in all apps.

                var dict = new PDictionary();
                dict.Add("Version", new PString(string.Format("{0} ({1}: {2})", version.Version, version.Branch, version.Hash)));
                plist.Add("com.xamarin.ios", dict);
            }

            var sdkSettings = currentSDK.GetSdkSettings(sdkVersion, SdkIsSimulator);
            var dtSettings  = currentSDK.GetDTSettings();

            SetValue(plist, ManifestKeys.BuildMachineOSBuild, dtSettings.BuildMachineOSBuild);
            plist.SetIfNotPresent(ManifestKeys.CFBundleDevelopmentRegion, "en");

            plist.SetIfNotPresent(ManifestKeys.CFBundleExecutable, AssemblyName);
            if (IsIOS)
            {
                var executable = plist.GetCFBundleExecutable();
                if (executable.EndsWith(".app", StringComparison.Ordinal))
                {
                    LogAppManifestError("The executable (CFBundleExecutable) name ({0}) cannot end with '.app', because iOS may fail to launch the app.", executable);
                }
            }

            if (IsIOS)
            {
                if (minimumOSVersion < IPhoneSdkVersion.V5_0 && plist.GetUIMainStoryboardFile(true) != null)
                {
                    LogAppManifestError("Applications using a storyboard as the Main Interface must have a deployment target greater than 5.0");
                }

                if (!plist.ContainsKey(ManifestKeys.CFBundleName))
                {
                    plist [ManifestKeys.CFBundleName] = plist.ContainsKey(ManifestKeys.CFBundleDisplayName) ? plist.GetString(ManifestKeys.CFBundleDisplayName).Clone() : new PString(AppBundleName);
                }
            }
            else
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleName, AppBundleName);
            }

            plist.SetIfNotPresent(ManifestKeys.CFBundleIdentifier, BundleIdentifier);
            plist.SetIfNotPresent(ManifestKeys.CFBundleInfoDictionaryVersion, "6.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundlePackageType, IsAppExtension ? "XPC!" : "APPL");
            if (!string.IsNullOrEmpty(ResourceRules))
            {
                plist.SetIfNotPresent(ManifestKeys.CFBundleResourceSpecification, Path.GetFileName(ResourceRules));
            }
            plist.SetIfNotPresent(ManifestKeys.CFBundleSignature, "????");
            if (!plist.ContainsKey(ManifestKeys.CFBundleSupportedPlatforms))
            {
                plist[ManifestKeys.CFBundleSupportedPlatforms] = new PArray {
                    SdkPlatform
                }
            }
            ;
            plist.SetIfNotPresent(ManifestKeys.CFBundleVersion, "1.0");
            plist.SetIfNotPresent(ManifestKeys.CFBundleShortVersionString, plist.GetCFBundleVersion());

            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTCompiler", sdkSettings.DTCompiler);
                SetValue(plist, "DTPlatformBuild", dtSettings.DTPlatformBuild);
                SetValue(plist, "DTSDKBuild", sdkSettings.DTSDKBuild);
            }

            plist.SetIfNotPresent("DTPlatformName", SdkPlatform.ToLowerInvariant());
            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTPlatformVersion", dtSettings.DTPlatformVersion);
            }

            var sdkName = sdkSettings.CanonicalName;

            // older sdksettings didn't have a canonicalname for sim
            if (SdkIsSimulator && string.IsNullOrEmpty(sdkName))
            {
                var deviceSdkSettings = currentSDK.GetSdkSettings(sdkVersion, false);
                sdkName = deviceSdkSettings.AlternateSDK;
            }
            SetValue(plist, "DTSDKName", sdkName);

            if (!SdkIsSimulator)
            {
                SetValue(plist, "DTXcode", AppleSdkSettings.DTXcode);
                SetValue(plist, "DTXcodeBuild", dtSettings.DTXcodeBuild);
            }

            SetDeviceFamily(plist);

            plist.SetIfNotPresent(ManifestKeys.MinimumOSVersion, minimumOSVersion.ToString());

            // Remove any Xamarin Studio specific keys
            plist.Remove(ManifestKeys.XSLaunchImageAssets);
            plist.Remove(ManifestKeys.XSAppIconAssets);

            // Merge with any partial plists generated by the Asset Catalog compiler...
            MergePartialPlistTemplates(plist);

            if (IsIOS)
            {
                Validation(plist);
            }

            CompiledAppManifest = new TaskItem(Path.Combine(AppBundleDir, "Info.plist"));
            plist.Save(CompiledAppManifest.ItemSpec, true, true);

            return(!Log.HasLoggedErrors);
        }

        void SetDeviceFamily(PDictionary plist)
        {
            switch (Framework)
            {
            case PlatformFramework.iOS:
                SetIOSDeviceFamily(plist);
                break;

            case PlatformFramework.WatchOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                break;

            case PlatformFramework.TVOS:
                plist.SetUIDeviceFamily(IPhoneDeviceType.TV);
                break;
            }
        }

        void SetIOSDeviceFamily(PDictionary plist)
        {
            if (IsWatchApp)
            {
                if (SdkIsSimulator)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone | IPhoneDeviceType.Watch);
                }
                else
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.Watch);
                }
            }
            else
            {
                if (!IsAppExtension)
                {
                    plist.SetIfNotPresent(ManifestKeys.LSRequiresIPhoneOS, true);
                }

                if (minimumOSVersion >= IPhoneSdkVersion.V3_2 && supportedDevices == IPhoneDeviceType.NotSet)
                {
                    plist.SetUIDeviceFamily(IPhoneDeviceType.IPhone);
                }
            }
        }

        void Validation(PDictionary plist)
        {
            var supportsIPhone = (supportedDevices & IPhoneDeviceType.IPhone) != 0 ||
                                 supportedDevices == IPhoneDeviceType.NotSet;
            var supportsIPad = (supportedDevices & IPhoneDeviceType.IPad) != 0;

            // Validation...
            if (!IsAppExtension && sdkVersion >= IPhoneSdkVersion.V3_2)
            {
                IPhoneOrientation orientation;

                if (supportsIPhone)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(false);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPhone orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPhone orientations are not matched pairs");
                    }
                }

                if (supportsIPad)
                {
                    orientation = plist.GetUISupportedInterfaceOrientations(true);
                    if (orientation == IPhoneOrientation.None)
                    {
                        LogAppManifestWarning("Supported iPad orientations have not been set");
                    }
                    else if (!orientation.IsValidPair())
                    {
                        LogAppManifestWarning("Supported iPad orientations are not matched pairs");
                    }
                }
            }
        }
    }
Exemplo n.º 12
0
        void EnsureiOSSdkPath()
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);
            IPhoneSdkVersion requestedSdkVersion;

            if (string.IsNullOrEmpty(SdkVersion))
            {
                requestedSdkVersion = IPhoneSdkVersion.UseDefault;
            }
            else if (!IPhoneSdkVersion.TryParse(SdkVersion, out requestedSdkVersion))
            {
                Log.LogError(MSBStrings.E0025, SdkVersion);
                return;
            }

            var sdkVersion = requestedSdkVersion.ResolveIfDefault(currentSDK, SdkIsSimulator);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                sdkVersion = currentSDK.GetClosestInstalledSdk(sdkVersion, SdkIsSimulator);

                if (sdkVersion.IsUseDefault || !currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
                {
                    if (requestedSdkVersion.IsUseDefault)
                    {
                        Log.LogError(MSBStrings.E0038);
                    }
                    else
                    {
                        Log.LogError(MSBStrings.E0039, requestedSdkVersion.ToString());
                    }
                    return;
                }
                Log.LogWarning(MSBStrings.E0040, requestedSdkVersion, sdkVersion);
            }

            SdkVersion = sdkVersion.ToString();

            var platformDir = currentSDK.GetPlatformPath(SdkIsSimulator);

            if (string.IsNullOrEmpty(platformDir) || !Directory.Exists(platformDir))
            {
                Log.LogError(MSBStrings.E0041, platformDir);
            }

            SdkRoot = currentSDK.GetSdkPath(sdkVersion, SdkIsSimulator);
            if (string.IsNullOrEmpty(SdkRoot) || !Directory.Exists(SdkRoot))
            {
                Log.LogError(MSBStrings.E0042, SdkVersion, SdkRoot);
            }
            // Note: Developer/Platforms/iPhoneOS.platform/Developer/usr is a physical directory, but
            // Developer/Platforms/iPhoneSimulator.platform/Developer/bin has always been a symlink
            // to Developer/bin and starting with Xcode 7 Beta 2, the usr symlink no longer exists.
            // In Xcode 10 beta 1 Developer/Platforms/iPhoneOS.platform/Developer/usr reappeared,
            // but since it seems incomplete don't even check for it.
            if (AppleSdkSettings.XcodeVersion.Major < 10)
            {
                SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(platformDir, "Developer", "usr"));
            }

            if (string.IsNullOrEmpty(SdkUsrPath))
            {
                SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(currentSDK.DeveloperRoot, "usr"));
                if (string.IsNullOrEmpty(SdkUsrPath))
                {
                    Log.LogError(MSBStrings.E0043, SdkVersion, SdkRoot);
                }
            }

            SdkBinPath = DirExists("SDK bin directory", Path.Combine(SdkUsrPath, "bin"));
            if (string.IsNullOrEmpty(SdkBinPath))
            {
                Log.LogError(MSBStrings.E0032);
            }

            SdkPlatform = SdkIsSimulator ? "iPhoneSimulator" : "iPhoneOS";
        }
Exemplo n.º 13
0
        void EnsureWatchSdkPath()
        {
            var currentSDK = IPhoneSdks.GetSdk(Framework);
            IPhoneSdkVersion requestedSdkVersion;

            if (string.IsNullOrEmpty(SdkVersion))
            {
                requestedSdkVersion = IPhoneSdkVersion.UseDefault;
            }
            else if (!IPhoneSdkVersion.TryParse(SdkVersion, out requestedSdkVersion))
            {
                Log.LogError(MSBStrings.E0025, SdkVersion);
                return;
            }

            var sdkVersion = requestedSdkVersion.ResolveIfDefault(currentSDK, SdkIsSimulator);

            if (!currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
            {
                sdkVersion = currentSDK.GetClosestInstalledSdk(sdkVersion, SdkIsSimulator);

                if (sdkVersion.IsUseDefault || !currentSDK.SdkIsInstalled(sdkVersion, SdkIsSimulator))
                {
                    if (requestedSdkVersion.IsUseDefault)
                    {
                        Log.LogError(MSBStrings.E0026);
                    }
                    else
                    {
                        Log.LogError(MSBStrings.E0033, requestedSdkVersion.ToString());
                    }
                    return;
                }
                Log.LogWarning(MSBStrings.W0034, requestedSdkVersion, sdkVersion);
            }

            SdkVersion = sdkVersion.ToString();

            var platformDir = currentSDK.GetPlatformPath(SdkIsSimulator);

            if (string.IsNullOrEmpty(platformDir) || !Directory.Exists(platformDir))
            {
                Log.LogError(MSBStrings.E0035, platformDir);
            }

            SdkRoot = currentSDK.GetSdkPath(sdkVersion, SdkIsSimulator);
            if (string.IsNullOrEmpty(SdkRoot) || !Directory.Exists(SdkRoot))
            {
                Log.LogError(MSBStrings.E0036, SdkVersion, SdkRoot);
            }

            SdkUsrPath = DirExists("SDK Usr directory", Path.Combine(currentSDK.DeveloperRoot, "usr"));
            if (string.IsNullOrEmpty(SdkUsrPath))
            {
                Log.LogError(MSBStrings.E0037, SdkVersion, SdkRoot);
            }

            SdkBinPath = DirExists("SDK bin directory", Path.Combine(SdkUsrPath, "bin"));
            if (string.IsNullOrEmpty(SdkBinPath))
            {
                Log.LogError(MSBStrings.E0032);
            }

            SdkPlatform = SdkIsSimulator ? "WatchSimulator" : "WatchOS";
        }