Ejemplo n.º 1
0
        public void FindMSBuildSDKsPath(string dotNetCorePath)
        {
            if (string.IsNullOrEmpty(dotNetCorePath))
            {
                return;
            }

            string rootDirectory = Path.GetDirectoryName(dotNetCorePath);

            sdkRootPath = Path.Combine(rootDirectory, "sdk");

            if (!Directory.Exists(sdkRootPath))
            {
                return;
            }

            SdkVersions = GetInstalledSdkVersions(sdkRootPath)
                          .OrderByDescending(version => version)
                          .ToArray();
            if (!SdkVersions.Any())
            {
                return;
            }

            DotNetCoreVersion latestVersion = SdkVersions.FirstOrDefault();

            SdksParentDirectory = Path.Combine(sdkRootPath, latestVersion.OriginalString);
            if (SdksParentDirectory == null)
            {
                return;
            }

            msbuildSDKsPath = Path.Combine(SdksParentDirectory, "Sdks");
            Exist           = true;
        }
Ejemplo n.º 2
0
        public void FindMSBuildSDKsPath()
        {
            var dotNetCorePath = new DotNetCorePath();

            if (dotNetCorePath.IsMissing)
            {
                return;
            }

            string rootDirectory = Path.GetDirectoryName(dotNetCorePath.FileName);
            string sdkRootPath   = Path.Combine(rootDirectory, "sdk");

            if (!Directory.Exists(sdkRootPath))
            {
                return;
            }

            SdkVersions = GetInstalledSdkVersions(sdkRootPath)
                          .OrderByDescending(version => version)
                          .ToArray();
            if (!SdkVersions.Any())
            {
                return;
            }

            DotNetCoreVersion latestVersion = SdkVersions.FirstOrDefault();

            SdksParentDirectory = Path.Combine(sdkRootPath, latestVersion.OriginalString);
            if (SdksParentDirectory == null)
            {
                return;
            }

            msbuildSDKsPath = Path.Combine(SdksParentDirectory, "Sdks");

            MSBuildProjectService.RegisterProjectImportSearchPath("MSBuildSDKsPath", MSBuildSDKsPath);
        }
Ejemplo n.º 3
0
        public void InitializeCommon()
        {
            Namespaces.Initialize();
            SelectRegistrar();

            if (RequiresXcodeHeaders && SdkVersion < SdkVersions.GetVersion(Platform))
            {
                throw ErrorHelper.CreateError(91, "This version of {0} requires the {1} {2} SDK (shipped with Xcode {3}). Either upgrade Xcode to get the required header files or {4} (to try to avoid the new APIs).", ProductName, PlatformName, SdkVersions.GetVersion(Platform), SdkVersions.Xcode, Error91LinkerSuggestion);
            }

            if (DeploymentTarget != null)
            {
                if (DeploymentTarget < Xamarin.SdkVersions.GetMinVersion(Platform))
                {
                    throw new PlatformException(73, true, "{4} {0} does not support a deployment target of {1} for {3} (the minimum is {2}). Please select a newer deployment target in your project's Info.plist.", Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetMinVersion(Platform), PlatformName, ProductName);
                }
                if (DeploymentTarget > Xamarin.SdkVersions.GetVersion(Platform))
                {
                    throw new PlatformException(74, true, "{4} {0} does not support a deployment target of {1} for {3} (the maximum is {2}). Please select an older deployment target in your project's Info.plist or upgrade to a newer version of {4}.", Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetVersion(Platform), PlatformName, ProductName);
                }
            }

            if (Platform == ApplePlatform.WatchOS && EnableCoopGC.HasValue && !EnableCoopGC.Value)
            {
                throw ErrorHelper.CreateError(88, "The GC must be in cooperative mode for watchOS apps. Please remove the --coop:false argument to mtouch.");
            }

            if (!EnableCoopGC.HasValue)
            {
                EnableCoopGC = Platform == ApplePlatform.WatchOS;
            }

            if (EnableCoopGC.Value)
            {
                switch (MarshalObjectiveCExceptions)
                {
                case MarshalObjectiveCExceptionMode.UnwindManagedCode:
                case MarshalObjectiveCExceptionMode.Disable:
                    throw ErrorHelper.CreateError(89, "The option '{0}' cannot take the value '{1}' when cooperative mode is enabled for the GC.", "--marshal-objectivec-exceptions", MarshalObjectiveCExceptions.ToString().ToLowerInvariant());
                }
                switch (MarshalManagedExceptions)
                {
                case MarshalManagedExceptionMode.UnwindNativeCode:
                case MarshalManagedExceptionMode.Disable:
                    throw ErrorHelper.CreateError(89, "The option '{0}' cannot take the value '{1}' when cooperative mode is enabled for the GC.", "--marshal-managed-exceptions", MarshalManagedExceptions.ToString().ToLowerInvariant());
                }
            }


            bool isSimulatorOrDesktopDebug = EnableDebug;

#if MTOUCH
            isSimulatorOrDesktopDebug &= IsSimulatorBuild;
#endif

            if (MarshalObjectiveCExceptions == MarshalObjectiveCExceptionMode.Default)
            {
                if (EnableCoopGC.Value)
                {
                    MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.ThrowManagedException;
                }
                else
                {
                    MarshalObjectiveCExceptions = isSimulatorOrDesktopDebug ? MarshalObjectiveCExceptionMode.UnwindManagedCode : MarshalObjectiveCExceptionMode.Disable;
                }
            }

            if (MarshalManagedExceptions == MarshalManagedExceptionMode.Default)
            {
                if (EnableCoopGC.Value)
                {
                    MarshalManagedExceptions = MarshalManagedExceptionMode.ThrowObjectiveCException;
                }
                else
                {
                    MarshalManagedExceptions = isSimulatorOrDesktopDebug ? MarshalManagedExceptionMode.UnwindNativeCode : MarshalManagedExceptionMode.Disable;
                }
                IsDefaultMarshalManagedExceptionMode = true;
            }

            if (SymbolMode == SymbolMode.Default)
            {
#if MONOTOUCH
                SymbolMode = EnableBitCode ? SymbolMode.Code : SymbolMode.Linker;
#else
                SymbolMode = SymbolMode.Linker;
#endif
            }

#if MONOTOUCH
            if (EnableBitCode && SymbolMode != SymbolMode.Code)
            {
                // This is a warning because:
                // * The user will get a linker error anyway if they do this.
                // * I see it as quite unlikely that anybody will in fact try this (it must be manually set in the additional mtouch arguments).
                // * I find it more probable that Apple will remove the -u restriction, in which case someone might actually want to try this, and if it's a warning, we won't prevent it.
                ErrorHelper.Warning(115, "It is recommended to reference dynamic symbols using code (--dynamic-symbol-mode=code) when bitcode is enabled.");
            }
#endif

            Optimizations.Initialize(this);
        }
Ejemplo n.º 4
0
        //https://docs.microsoft.com/en-us/dotnet/core/tools/global-json
        public void ResolveSDK(string workingDir = "", bool forceLookUpGlobalJson = false)
        {
            if (!SdkVersions.Any())
            {
                return;
            }

            DotNetCoreVersion targetVersion = null;

            if (forceLookUpGlobalJson)
            {
                GlobalJsonPath = LookUpGlobalJson(workingDir);
            }
            var specificVersion = ReadGlobalJson();

            //if !global.json, returns latest
            if (string.IsNullOrEmpty(specificVersion))
            {
                msbuildSDKsPath = GetSdksParentDirectory(GetLatestSdk());
                Exist           = true;
                return;
            }

            DotNetCoreVersion requiredVersion;

            DotNetCoreVersion.TryParse(specificVersion, out requiredVersion);

            if (requiredVersion == null)
            {
                msbuildSDKsPath         = string.Empty;
                IsUnsupportedSdkVersion = true;
                Exist = false;
                return;
            }

            //if global.json exists and matches returns it
            targetVersion = SdkVersions.FirstOrDefault(x => x.OriginalString.IndexOf(specificVersion, StringComparison.InvariantCulture) == 0);
            if (targetVersion == null)
            {
                //if global.json exists and !matches then:
                if (requiredVersion >= DotNetCoreVersion.Parse("2.1"))
                {
                    targetVersion = SdkVersions.Where(version => version.Major == requiredVersion.Major &&
                                                      version.Minor == requiredVersion.Minor)
                                    .OrderByDescending(version => version.Patch).FirstOrDefault(x => {
                        return((x.Patch / 100 == requiredVersion.Patch / 100) &&
                               (x.Patch % 100 >= requiredVersion.Patch % 100));
                    });
                }
                else
                {
                    targetVersion = SdkVersions.Where(version => version.Major == requiredVersion.Major && version.Minor == requiredVersion.Minor)
                                    .OrderByDescending(version => version.Patch).FirstOrDefault();
                }

                if (targetVersion == null)
                {
                    msbuildSDKsPath         = string.Empty;
                    IsUnsupportedSdkVersion = true;
                    Exist = false;
                    return;
                }
            }

            msbuildSDKsPath         = GetSdksParentDirectory(targetVersion);
            Exist                   = true;
            IsUnsupportedSdkVersion = false;
        }
Ejemplo n.º 5
0
 internal DotNetCoreVersion GetLatestSdk() => SdkVersions.OrderByDescending(v => v).FirstOrDefault();
Ejemplo n.º 6
0
        public void InitializeCommon()
        {
            SelectRegistrar();
            SelectMonoNative();

            RuntimeOptions = RuntimeOptions.Create(this, HttpMessageHandler, TlsProvider);

            if (RequiresXcodeHeaders && SdkVersion < SdkVersions.GetVersion(this))
            {
                switch (Platform)
                {
                case ApplePlatform.iOS:
                case ApplePlatform.TVOS:
                case ApplePlatform.WatchOS:
                    throw ErrorHelper.CreateError(180, Errors.MX0180, ProductName, PlatformName, SdkVersions.GetVersion(this), SdkVersions.Xcode);

                case ApplePlatform.MacOSX:
                    throw ErrorHelper.CreateError(179, Errors.MX0179, ProductName, PlatformName, SdkVersions.GetVersion(this), SdkVersions.Xcode);

                default:
                    // Default to the iOS error message, it's better than showing MX0071 (unknown platform), which would be completely unrelated
                    goto case ApplePlatform.iOS;
                }
            }

            if (DeploymentTarget != null)
            {
                if (DeploymentTarget < Xamarin.SdkVersions.GetMinVersion(this))
                {
                    throw new ProductException(73, true, Errors.MT0073, Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetMinVersion(this), PlatformName, ProductName);
                }
                if (DeploymentTarget > Xamarin.SdkVersions.GetVersion(this))
                {
                    throw new ProductException(74, true, Errors.MX0074, Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetVersion(this), PlatformName, ProductName);
                }
            }

            if (Platform == ApplePlatform.WatchOS && EnableCoopGC.HasValue && !EnableCoopGC.Value)
            {
                throw ErrorHelper.CreateError(88, Errors.MT0088);
            }

            if (!EnableCoopGC.HasValue)
            {
                EnableCoopGC = Platform == ApplePlatform.WatchOS;
            }

            SetObjectiveCExceptionMode();
            SetManagedExceptionMode();

            if (SymbolMode == SymbolMode.Default)
            {
#if MONOTOUCH
                SymbolMode = EnableBitCode ? SymbolMode.Code : SymbolMode.Linker;
#else
                SymbolMode = SymbolMode.Linker;
#endif
            }

#if MONOTOUCH
            if (EnableBitCode && SymbolMode != SymbolMode.Code)
            {
                // This is a warning because:
                // * The user will get a linker error anyway if they do this.
                // * I see it as quite unlikely that anybody will in fact try this (it must be manually set in the additional mtouch arguments).
                // * I find it more probable that Apple will remove the -u restriction, in which case someone might actually want to try this, and if it's a warning, we won't prevent it.
                ErrorHelper.Warning(115, Errors.MT0115);
            }
#endif

            if (!DebugTrack.HasValue)
            {
                DebugTrack = false;
            }
            else if (DebugTrack.Value && !EnableDebug)
            {
                ErrorHelper.Warning(32, Errors.MT0032);
            }

            if (!package_managed_debug_symbols.HasValue)
            {
                package_managed_debug_symbols = EnableDebug;
            }
            else if (package_managed_debug_symbols.Value && IsLLVM)
            {
                ErrorHelper.Warning(3007, Errors.MX3007);
            }

            Optimizations.Initialize(this, out var messages);
            ErrorHelper.Show(messages);
            if (Driver.Verbosity > 3)
            {
                Driver.Log(4, $"Enabled optimizations: {Optimizations}");
            }
        }
Ejemplo n.º 7
0
        public void InitializeCommon()
        {
            Namespaces.Initialize();
            SelectRegistrar();
            foreach (var target in Targets)
            {
                target.SelectMonoNative();
            }

            if (RequiresXcodeHeaders && SdkVersion < SdkVersions.GetVersion(Platform))
            {
                throw ErrorHelper.CreateError(91, Errors.MX0091, ProductName, PlatformName, SdkVersions.GetVersion(Platform), SdkVersions.Xcode, Error91LinkerSuggestion);
            }

            if (DeploymentTarget != null)
            {
                if (DeploymentTarget < Xamarin.SdkVersions.GetMinVersion(Platform))
                {
                    throw new PlatformException(73, true, Errors.MT0073, Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetMinVersion(Platform), PlatformName, ProductName);
                }
                if (DeploymentTarget > Xamarin.SdkVersions.GetVersion(Platform))
                {
                    throw new PlatformException(74, true, Errors.MX0074, Constants.Version, DeploymentTarget, Xamarin.SdkVersions.GetVersion(Platform), PlatformName, ProductName);
                }
            }

            if (Platform == ApplePlatform.WatchOS && EnableCoopGC.HasValue && !EnableCoopGC.Value)
            {
                throw ErrorHelper.CreateError(88, Errors.MT0088);
            }

            if (!EnableCoopGC.HasValue)
            {
                EnableCoopGC = Platform == ApplePlatform.WatchOS;
            }

            if (EnableCoopGC.Value)
            {
                switch (MarshalObjectiveCExceptions)
                {
                case MarshalObjectiveCExceptionMode.UnwindManagedCode:
                case MarshalObjectiveCExceptionMode.Disable:
                    throw ErrorHelper.CreateError(89, Errors.MT0089, "--marshal-objectivec-exceptions", MarshalObjectiveCExceptions.ToString().ToLowerInvariant());
                }
                switch (MarshalManagedExceptions)
                {
                case MarshalManagedExceptionMode.UnwindNativeCode:
                case MarshalManagedExceptionMode.Disable:
                    throw ErrorHelper.CreateError(89, Errors.MT0089, "--marshal-managed-exceptions", MarshalManagedExceptions.ToString().ToLowerInvariant());
                }
            }


            bool isSimulatorOrDesktopDebug = EnableDebug;

#if MTOUCH
            isSimulatorOrDesktopDebug &= IsSimulatorBuild;
#endif

            if (MarshalObjectiveCExceptions == MarshalObjectiveCExceptionMode.Default)
            {
                if (EnableCoopGC.Value || (Platform == ApplePlatform.MacOSX && EnableDebug))
                {
                    MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.ThrowManagedException;
                }
                else
                {
                    MarshalObjectiveCExceptions = isSimulatorOrDesktopDebug ? MarshalObjectiveCExceptionMode.UnwindManagedCode : MarshalObjectiveCExceptionMode.Disable;
                }
            }

            if (MarshalManagedExceptions == MarshalManagedExceptionMode.Default)
            {
                if (EnableCoopGC.Value)
                {
                    MarshalManagedExceptions = MarshalManagedExceptionMode.ThrowObjectiveCException;
                }
                else
                {
                    MarshalManagedExceptions = isSimulatorOrDesktopDebug ? MarshalManagedExceptionMode.UnwindNativeCode : MarshalManagedExceptionMode.Disable;
                }
                IsDefaultMarshalManagedExceptionMode = true;
            }

            if (SymbolMode == SymbolMode.Default)
            {
#if MONOTOUCH
                SymbolMode = EnableBitCode ? SymbolMode.Code : SymbolMode.Linker;
#else
                SymbolMode = SymbolMode.Linker;
#endif
            }

#if MONOTOUCH
            if (EnableBitCode && SymbolMode != SymbolMode.Code)
            {
                // This is a warning because:
                // * The user will get a linker error anyway if they do this.
                // * I see it as quite unlikely that anybody will in fact try this (it must be manually set in the additional mtouch arguments).
                // * I find it more probable that Apple will remove the -u restriction, in which case someone might actually want to try this, and if it's a warning, we won't prevent it.
                ErrorHelper.Warning(115, Errors.MT0115);
            }
#endif

            Optimizations.Initialize(this);
        }