예제 #1
0
        private static void ExportDataDirectory(IEnumerable <string> features, bool debug, string path)
        {
            var featureSet = new HashSet <string>(features);

            if (!PlatformHasTemplateDir(featureSet))
            {
                return;
            }

            string templateDirName = "data.mono";

            if (featureSet.Contains("Windows"))
            {
                templateDirName += ".windows";
                templateDirName += featureSet.Contains("64") ? ".64" : ".32";
            }
            else if (featureSet.Contains("X11"))
            {
                templateDirName += ".x11";
                templateDirName += featureSet.Contains("64") ? ".64" : ".32";
            }
            else
            {
                throw new NotSupportedException("Target platform not supported");
            }

            templateDirName += debug ? ".release_debug" : ".release";

            string templateDirPath = Path.Combine(Internal.FullTemplatesDir, templateDirName);

            if (!Directory.Exists(templateDirPath))
            {
                throw new FileNotFoundException("Data template directory not found");
            }

            string outputDir = new FileInfo(path).Directory?.FullName ??
                               throw new FileNotFoundException("Base directory not found");

            string outputDataDir = Path.Combine(outputDir, DataDirName);

            if (Directory.Exists(outputDataDir))
            {
                Directory.Delete(outputDataDir, recursive: true); // Clean first
            }
            Directory.CreateDirectory(outputDataDir);

            foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
            }

            foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
            {
                File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
            }
        }
예제 #2
0
        private static string ExportDataDirectory(string[] features, string platform, bool isDebug, string outputDir)
        {
            string target = isDebug ? "release_debug" : "release";

            // NOTE: Bits is ok for now as all platforms with a data directory only have one or two architectures.
            // However, this may change in the future if we add arm linux or windows desktop templates.
            string bits = features.Contains("64") ? "64" : "32";

            string TemplateDirName() => $"data.mono.{platform}.{bits}.{target}";

            string templateDirPath        = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());
            bool   validTemplatePathFound = true;

            if (!Directory.Exists(templateDirPath))
            {
                validTemplatePathFound = false;

                if (isDebug)
                {
                    target                 = "debug"; // Support both 'release_debug' and 'debug' for the template data directory name
                    templateDirPath        = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());
                    validTemplatePathFound = true;

                    if (!Directory.Exists(templateDirPath))
                    {
                        validTemplatePathFound = false;
                    }
                }
            }

            if (!validTemplatePathFound)
            {
                throw new FileNotFoundException("Data template directory not found", templateDirPath);
            }

            string outputDataDir = Path.Combine(outputDir, DetermineDataDirNameForProject());

            if (Directory.Exists(outputDataDir))
            {
                Directory.Delete(outputDataDir, recursive: true); // Clean first
            }
            Directory.CreateDirectory(outputDataDir);

            foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
            }

            foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
            {
                File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
            }

            return(outputDataDir);
        }
예제 #3
0
        private static string ExportDataDirectory(string[] features, string platform, bool isDebug, string outputDir)
        {
            string target = isDebug ? "release_debug" : "release";

            // NOTE: Bits is ok for now as all platforms with a data directory have it, but that may change in the future.
            string bits = features.Contains("64") ? "64" : "32";

            string TemplateDirName() => $"data.mono.{platform}.{bits}.{target}";

            string templateDirPath = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());

            if (!Directory.Exists(templateDirPath))
            {
                templateDirPath = null;

                if (isDebug)
                {
                    target          = "debug"; // Support both 'release_debug' and 'debug' for the template data directory name
                    templateDirPath = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());

                    if (!Directory.Exists(templateDirPath))
                    {
                        templateDirPath = null;
                    }
                }
            }

            if (templateDirPath == null)
            {
                throw new FileNotFoundException("Data template directory not found");
            }

            string outputDataDir = Path.Combine(outputDir, DataDirName);

            if (Directory.Exists(outputDataDir))
            {
                Directory.Delete(outputDataDir, recursive: true); // Clean first
            }
            Directory.CreateDirectory(outputDataDir);

            foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
            }

            foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
            {
                File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
            }

            return(outputDataDir);
        }
예제 #4
0
        public override void _ExportEnd()
        {
            base._ExportEnd();

            string aotTempDir = Path.Combine(Path.GetTempPath(), $"godot-aot-{Process.GetCurrentProcess().Id}");

            if (Directory.Exists(aotTempDir))
                Directory.Delete(aotTempDir, recursive: true);

            // TODO: Just a workaround until the export plugins can be made to abort with errors
            if (!string.IsNullOrEmpty(maybeLastExportError)) // Check empty as well, because it's set to empty after hot-reloading
            {
                string lastExportError = maybeLastExportError;
                maybeLastExportError = null;

                GodotSharpEditor.Instance.ShowErrorDialog(lastExportError, "Failed to export C# project");
            }
        }
예제 #5
0
        private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
        {
            _ = flags; // Unused

            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return;
            }

            if (!DeterminePlatformFromFeatures(features, out string platform))
            {
                throw new NotSupportedException("Target platform not supported");
            }

            if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS }
                .Contains(platform))
            {
                throw new NotImplementedException("Target platform not yet implemented");
            }

            string outputDir = new FileInfo(path).Directory?.FullName ??
                               throw new FileNotFoundException("Output base directory not found");

            string buildConfig = isDebug ? "ExportDebug" : "ExportRelease";

            // TODO: This works for now, as we only implemented support for x86 family desktop so far, but it needs to be fixed
            string arch = features.Contains("64") ? "x86_64" : "x86";

            string ridOS             = DetermineRuntimeIdentifierOS(platform);
            string ridArch           = DetermineRuntimeIdentifierArch(arch);
            string runtimeIdentifier = $"{ridOS}-{ridArch}";

            // Create temporary publish output directory

            string publishOutputTempDir = Path.Combine(Path.GetTempPath(), "godot-publish-dotnet",
                                                       $"{Process.GetCurrentProcess().Id}-{buildConfig}-{runtimeIdentifier}");

            if (!Directory.Exists(publishOutputTempDir))
            {
                Directory.CreateDirectory(publishOutputTempDir);
            }

            // Execute dotnet publish

            if (!BuildManager.PublishProjectBlocking(buildConfig, platform,
                                                     runtimeIdentifier, publishOutputTempDir))
            {
                throw new Exception("Failed to build project");
            }

            string soExt = ridOS switch
            {
                OS.DotNetOS.Win or OS.DotNetOS.Win10 => "dll",
                   OS.DotNetOS.OSX or OS.DotNetOS.iOS => "dylib",
                   _ => "so"
            };

            if (!File.Exists(Path.Combine(publishOutputTempDir, $"{GodotSharpDirs.ProjectAssemblyName}.dll"))
                // NativeAOT shared library output
                && !File.Exists(Path.Combine(publishOutputTempDir, $"{GodotSharpDirs.ProjectAssemblyName}.{soExt}")))
            {
                throw new NotSupportedException(
                          "Publish succeeded but project assembly not found in the output directory");
            }

            // Copy all files from the dotnet publish output directory to
            // a data directory next to the Godot output executable.

            string outputDataDir = Path.Combine(outputDir, DetermineDataDirNameForProject());

            if (Directory.Exists(outputDataDir))
            {
                Directory.Delete(outputDataDir, recursive: true); // Clean first
            }
            Directory.CreateDirectory(outputDataDir);

            foreach (string dir in Directory.GetDirectories(publishOutputTempDir, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(publishOutputTempDir.Length + 1)));
            }

            foreach (string file in Directory.GetFiles(publishOutputTempDir, "*", SearchOption.AllDirectories))
            {
                File.Copy(file, Path.Combine(outputDataDir, file.Substring(publishOutputTempDir.Length + 1)));
            }
        }