Esempio n. 1
0
        private static string FindBuildEngineOnUnix(string name)
        {
            string ret = OS.PathWhich(name);

            if (!ret.Empty())
            {
                return(ret);
            }

            string retFallback = OS.PathWhich($"{name}.exe");

            if (!retFallback.Empty())
            {
                return(retFallback);
            }

            foreach (string hintDir in MsBuildHintDirs)
            {
                string hintPath = Path.Combine(hintDir, name);

                if (File.Exists(hintPath))
                {
                    return(hintPath);
                }
            }

            return(string.Empty);
        }
Esempio n. 2
0
        public static RiderInfo[] GetAllRiderPaths()
        {
            try
            {
                if (OS.IsWindows)
                {
                    return(CollectRiderInfosWindows());
                }
                if (OS.IsOSX)
                {
                    return(CollectRiderInfosMac());
                }
                if (OS.IsUnixLike())
                {
                    return(CollectAllRiderPathsLinux());
                }
                throw new Exception("Unexpected OS.");
            }
            catch (Exception e)
            {
                GD.PushWarning(e.Message);
            }

            return(new RiderInfo[0]);
        }
Esempio n. 3
0
        private static string GetToolboxBaseDir()
        {
            if (OS.IsWindows)
            {
                var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                return(GetToolboxRiderRootPath(localAppData));
            }

            if (OS.IsOSX)
            {
                var home = Environment.GetEnvironmentVariable("HOME");
                if (string.IsNullOrEmpty(home))
                {
                    return(string.Empty);
                }
                var localAppData = Path.Combine(home, @"Library/Application Support");
                return(GetToolboxRiderRootPath(localAppData));
            }

            if (OS.IsUnixLike())
            {
                var home = Environment.GetEnvironmentVariable("HOME");
                if (string.IsNullOrEmpty(home))
                {
                    return(string.Empty);
                }
                var localAppData = Path.Combine(home, @".local/share");
                return(GetToolboxRiderRootPath(localAppData));
            }

            return(string.Empty);
        }
Esempio n. 4
0
        private static string GetToolboxBaseDir()
        {
            if (OS.IsWindows)
            {
                var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                return(Path.Combine(localAppData, @"JetBrains\Toolbox\apps\Rider"));
            }

            if (OS.IsOSX)
            {
                var home = Environment.GetEnvironmentVariable("HOME");
                if (!string.IsNullOrEmpty(home))
                {
                    return(Path.Combine(home, @"Library/Application Support/JetBrains/Toolbox/apps/Rider"));
                }
            }

            if (OS.IsUnixLike())
            {
                var home = Environment.GetEnvironmentVariable("HOME");
                if (!string.IsNullOrEmpty(home))
                {
                    return(Path.Combine(home, @".local/share/JetBrains/Toolbox/apps/Rider"));
                }
            }

            throw new Exception("Unexpected OS.");
        }
Esempio n. 5
0
        public static string FindDotNetExe()
        {
            // In the future, this method may do more than just search in PATH. We could look in
            // known locations or use Godot's linked nethost to search from the hostfxr location.

            return(OS.PathWhich("dotnet"));
        }
Esempio n. 6
0
 private static string GetRelativePathToBuildTxt()
 {
     if (OS.IsWindows || OS.IsUnixLike())
     {
         return("../../build.txt");
     }
     if (OS.IsOSX)
     {
         return("Contents/Resources/build.txt");
     }
     throw new Exception("Unknown OS.");
 }
Esempio n. 7
0
        public static void Initialize()
        {
            // Build tool settings
            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();

            BuildTool msbuildDefault;

            if (OS.IsWindows)
            {
                if (RiderPathManager.IsExternalEditorSetToRider(editorSettings))
                {
                    msbuildDefault = BuildTool.JetBrainsMsBuild;
                }
                else
                {
                    msbuildDefault = !string.IsNullOrEmpty(OS.PathWhich("dotnet")) ? BuildTool.DotnetCli : BuildTool.MsBuildVs;
                }
            }
            else
            {
                msbuildDefault = !string.IsNullOrEmpty(OS.PathWhich("dotnet")) ? BuildTool.DotnetCli : BuildTool.MsBuildMono;
            }

            EditorDef("mono/builds/build_tool", msbuildDefault);

            string hintString;

            if (OS.IsWindows)
            {
                hintString = $"{PropNameMSBuildMono}:{(int)BuildTool.MsBuildMono}," +
                             $"{PropNameMSBuildVs}:{(int)BuildTool.MsBuildVs}," +
                             $"{PropNameMSBuildJetBrains}:{(int)BuildTool.JetBrainsMsBuild}," +
                             $"{PropNameDotnetCli}:{(int)BuildTool.DotnetCli}";
            }
            else
            {
                hintString = $"{PropNameMSBuildMono}:{(int)BuildTool.MsBuildMono}," +
                             $"{PropNameDotnetCli}:{(int)BuildTool.DotnetCli}";
            }

            editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
            {
                ["type"]        = Godot.Variant.Type.Int,
                ["name"]        = "mono/builds/build_tool",
                ["hint"]        = Godot.PropertyHint.Enum,
                ["hint_string"] = hintString
            });
        }
Esempio n. 8
0
        public static string FindMsBuild()
        {
            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildManager.BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            if (OS.IsWindows)
            {
                switch (buildTool)
                {
                case BuildManager.BuildTool.MsBuildVs:
                {
                    if (_msbuildToolsPath.Empty() || !File.Exists(_msbuildToolsPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildToolsPath = FindMsBuildToolsPathOnWindows();

                        if (_msbuildToolsPath.Empty())
                        {
                            throw new FileNotFoundException($"Cannot find executable for '{BuildManager.PropNameMsbuildVs}'.");
                        }
                    }

                    if (!_msbuildToolsPath.EndsWith("\\"))
                    {
                        _msbuildToolsPath += "\\";
                    }

                    return(Path.Combine(_msbuildToolsPath, "MSBuild.exe"));
                }

                case BuildManager.BuildTool.MsBuildMono:
                {
                    string msbuildPath = Path.Combine(Internal.MonoWindowsInstallRoot, "bin", "msbuild.bat");

                    if (!File.Exists(msbuildPath))
                    {
                        throw new FileNotFoundException($"Cannot find executable for '{BuildManager.PropNameMsbuildMono}'. Tried with path: {msbuildPath}");
                    }

                    return(msbuildPath);
                }

                case BuildManager.BuildTool.JetBrainsMsBuild:
                    var editorPath = (string)editorSettings.GetSetting(RiderPathManager.EditorPathSettingName);
                    if (!File.Exists(editorPath))
                    {
                        throw new FileNotFoundException($"Cannot find Rider executable. Tried with path: {editorPath}");
                    }
                    var riderDir = new FileInfo(editorPath).Directory.Parent;
                    return(Path.Combine(riderDir.FullName, @"tools\MSBuild\Current\Bin\MSBuild.exe"));

                default:
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            if (OS.IsUnixLike())
            {
                if (buildTool == BuildManager.BuildTool.MsBuildMono)
                {
                    if (_msbuildUnixPath.Empty() || !File.Exists(_msbuildUnixPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildUnixPath = FindBuildEngineOnUnix("msbuild");
                    }

                    if (_msbuildUnixPath.Empty())
                    {
                        throw new FileNotFoundException($"Cannot find binary for '{BuildManager.PropNameMsbuildMono}'");
                    }

                    return(_msbuildUnixPath);
                }
                else
                {
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            throw new PlatformNotSupportedException();
        }
Esempio n. 9
0
        public static (string, BuildTool) FindMsBuild()
        {
            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            if (OS.IsWindows)
            {
                switch (buildTool)
                {
                case BuildTool.DotnetCli:
                {
                    string dotnetCliPath = OS.PathWhich("dotnet");
                    if (!string.IsNullOrEmpty(dotnetCliPath))
                    {
                        return(dotnetCliPath, BuildTool.DotnetCli);
                    }
                    GD.PushError("Cannot find dotnet CLI executable. Fallback to MSBuild from Visual Studio.");
                    goto case BuildTool.MsBuildVs;
                }

                case BuildTool.MsBuildVs:
                {
                    if (string.IsNullOrEmpty(_msbuildToolsPath) || !File.Exists(_msbuildToolsPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildToolsPath = FindMsBuildToolsPathOnWindows();

                        if (string.IsNullOrEmpty(_msbuildToolsPath))
                        {
                            throw new FileNotFoundException($"Cannot find executable for '{BuildManager.PropNameMSBuildVs}'.");
                        }
                    }

                    if (!_msbuildToolsPath.EndsWith("\\"))
                    {
                        _msbuildToolsPath += "\\";
                    }

                    return(Path.Combine(_msbuildToolsPath, "MSBuild.exe"), BuildTool.MsBuildVs);
                }

                case BuildTool.MsBuildMono:
                {
                    string msbuildPath = Path.Combine(Internal.MonoWindowsInstallRoot, "bin", "msbuild.bat");

                    if (!File.Exists(msbuildPath))
                    {
                        throw new FileNotFoundException($"Cannot find executable for '{BuildManager.PropNameMSBuildMono}'. Tried with path: {msbuildPath}");
                    }

                    return(msbuildPath, BuildTool.MsBuildMono);
                }

                case BuildTool.JetBrainsMsBuild:
                {
                    var editorPath = (string)editorSettings.GetSetting(RiderPathManager.EditorPathSettingName);

                    if (!File.Exists(editorPath))
                    {
                        throw new FileNotFoundException($"Cannot find Rider executable. Tried with path: {editorPath}");
                    }

                    var riderDir = new FileInfo(editorPath).Directory?.Parent;

                    string msbuildPath = Path.Combine(riderDir.FullName, @"tools\MSBuild\Current\Bin\MSBuild.exe");

                    if (!File.Exists(msbuildPath))
                    {
                        throw new FileNotFoundException($"Cannot find executable for '{BuildManager.PropNameMSBuildJetBrains}'. Tried with path: {msbuildPath}");
                    }

                    return(msbuildPath, BuildTool.JetBrainsMsBuild);
                }

                default:
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            if (OS.IsUnixLike)
            {
                switch (buildTool)
                {
                case BuildTool.DotnetCli:
                {
                    string dotnetCliPath = OS.PathWhich("dotnet");
                    if (!string.IsNullOrEmpty(dotnetCliPath))
                    {
                        return(dotnetCliPath, BuildTool.DotnetCli);
                    }
                    GD.PushError("Cannot find dotnet CLI executable. Fallback to MSBuild from Mono.");
                    goto case BuildTool.MsBuildMono;
                }

                case BuildTool.MsBuildMono:
                {
                    if (string.IsNullOrEmpty(_msbuildUnixPath) || !File.Exists(_msbuildUnixPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildUnixPath = FindBuildEngineOnUnix("msbuild");
                    }

                    if (string.IsNullOrEmpty(_msbuildUnixPath))
                    {
                        throw new FileNotFoundException($"Cannot find binary for '{BuildManager.PropNameMSBuildMono}'");
                    }

                    return(_msbuildUnixPath, BuildTool.MsBuildMono);
                }

                default:
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            throw new PlatformNotSupportedException();
        }
Esempio n. 10
0
        private static string FindMsBuildToolsPathOnWindows()
        {
            if (!OS.IsWindows())
            {
                throw new PlatformNotSupportedException();
            }

            // Try to find 15.0 with vswhere

            string vsWherePath = Environment.GetEnvironmentVariable(Internal.GodotIs32Bits() ? "ProgramFiles" : "ProgramFiles(x86)");

            vsWherePath += "\\Microsoft Visual Studio\\Installer\\vswhere.exe";

            var vsWhereArgs = new[] { "-latest", "-products", "*", "-requires", "Microsoft.Component.MSBuild" };

            var outputArray = new Godot.Collections.Array <string>();
            int exitCode    = Godot.OS.Execute(vsWherePath, vsWhereArgs,
                                               blocking: true, output: (Godot.Collections.Array)outputArray);

            if (exitCode != 0)
            {
                return(string.Empty);
            }

            if (outputArray.Count == 0)
            {
                return(string.Empty);
            }

            var lines = outputArray[0].Split('\n');

            foreach (string line in lines)
            {
                int sepIdx = line.IndexOf(':');

                if (sepIdx <= 0)
                {
                    continue;
                }

                string key = line.Substring(0, sepIdx); // No need to trim

                if (key != "installationPath")
                {
                    continue;
                }

                string value = line.Substring(sepIdx + 1).StripEdges();

                if (value.Empty())
                {
                    throw new FormatException("installationPath value is empty");
                }

                if (!value.EndsWith("\\"))
                {
                    value += "\\";
                }

                // Since VS2019, the directory is simply named "Current"
                string msbuildDir = Path.Combine(value, "MSBuild\\Current\\Bin");

                if (Directory.Exists(msbuildDir))
                {
                    return(msbuildDir);
                }

                // Directory name "15.0" is used in VS 2017
                return(Path.Combine(value, "MSBuild\\15.0\\Bin"));
            }

            return(string.Empty);
        }
Esempio n. 11
0
        public static string FindMsBuild()
        {
            var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
            var buildTool      = (GodotSharpBuilds.BuildTool)editorSettings.GetSetting("mono/builds/build_tool");

            if (OS.IsWindows())
            {
                switch (buildTool)
                {
                case GodotSharpBuilds.BuildTool.MsBuildVs:
                {
                    if (_msbuildToolsPath.Empty() || !File.Exists(_msbuildToolsPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildToolsPath = FindMsBuildToolsPathOnWindows();

                        if (_msbuildToolsPath.Empty())
                        {
                            throw new FileNotFoundException($"Cannot find executable for '{GodotSharpBuilds.PropNameMsbuildVs}'. Tried with path: {_msbuildToolsPath}");
                        }
                    }

                    if (!_msbuildToolsPath.EndsWith("\\"))
                    {
                        _msbuildToolsPath += "\\";
                    }

                    return(Path.Combine(_msbuildToolsPath, "MSBuild.exe"));
                }

                case GodotSharpBuilds.BuildTool.MsBuildMono:
                {
                    string msbuildPath = Path.Combine(Internal.MonoWindowsInstallRoot, "bin", "msbuild.bat");

                    if (!File.Exists(msbuildPath))
                    {
                        throw new FileNotFoundException($"Cannot find executable for '{GodotSharpBuilds.PropNameMsbuildMono}'. Tried with path: {msbuildPath}");
                    }

                    return(msbuildPath);
                }

                default:
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            if (OS.IsUnix())
            {
                if (buildTool == GodotSharpBuilds.BuildTool.MsBuildMono)
                {
                    if (_msbuildUnixPath.Empty() || !File.Exists(_msbuildUnixPath))
                    {
                        // Try to search it again if it wasn't found last time or if it was removed from its location
                        _msbuildUnixPath = FindBuildEngineOnUnix("msbuild");
                    }

                    if (_msbuildUnixPath.Empty())
                    {
                        throw new FileNotFoundException($"Cannot find binary for '{GodotSharpBuilds.PropNameMsbuildMono}'");
                    }

                    return(_msbuildUnixPath);
                }
                else
                {
                    throw new IndexOutOfRangeException("Invalid build tool in editor settings");
                }
            }

            throw new PlatformNotSupportedException();
        }