コード例 #1
0
        // NOTE: This will be replaced with C# source generators in 4.0
        public static string GenerateExportedGameScriptMetadata(bool isDebug)
        {
            string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");

            CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);
            return(scriptsMetadataPath);
        }
コード例 #2
0
        // NOTE: This will be replaced with C# source generators in 4.0
        public static void GenerateEditorScriptMetadata()
        {
            string editorScriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, "scripts_metadata.editor");
            string playerScriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, "scripts_metadata.editor_player");

            CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, editorScriptsMetadataPath);

            if (!File.Exists(editorScriptsMetadataPath))
            {
                return;
            }

            try
            {
                File.Copy(editorScriptsMetadataPath, playerScriptsMetadataPath);
            }
            catch (IOException e)
            {
                throw new IOException("Failed to copy scripts metadata file.", innerException: e);
            }
        }
コード例 #3
0
        private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return;
            }

            string platform = DeterminePlatformFromFeatures(features);

            if (platform == null)
            {
                throw new NotSupportedException("Target platform not supported");
            }

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

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

            string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");

            CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);

            AddFile(scriptsMetadataPath, scriptsMetadataPath);

            // Turn export features into defines
            var godotDefines = features;

            if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines))
            {
                throw new Exception("Failed to build project");
            }

            // Add dependency assemblies

            var assemblies = new Godot.Collections.Dictionary <string, string>();

            string projectDllName    = GodotSharpEditor.ProjectAssemblyName;
            string projectDllSrcDir  = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
            string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");

            assemblies[projectDllName] = projectDllSrcPath;

            if (platform == OS.Platforms.Android)
            {
                string godotAndroidExtProfileDir = GetBclProfileDir("godot_android_ext");
                string monoAndroidAssemblyPath   = Path.Combine(godotAndroidExtProfileDir, "Mono.Android.dll");

                if (!File.Exists(monoAndroidAssemblyPath))
                {
                    throw new FileNotFoundException("Assembly not found: 'Mono.Android'", monoAndroidAssemblyPath);
                }

                assemblies["Mono.Android"] = monoAndroidAssemblyPath;
            }

            string bclDir = DeterminePlatformBclDir(platform);

            var initialAssemblies = assemblies.Duplicate();

            internal_GetExportedAssemblyDependencies(initialAssemblies, buildConfig, bclDir, assemblies);

            AddI18NAssemblies(assemblies, bclDir);

            string outputDataDir = null;

            if (PlatformHasTemplateDir(platform))
            {
                outputDataDir = ExportDataDirectory(features, platform, isDebug, outputDir);
            }

            string apiConfig        = isDebug ? "Debug" : "Release";
            string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig);

            bool assembliesInsidePck = (bool)ProjectSettings.GetSetting("mono/export/export_assemblies_inside_pck") || outputDataDir == null;

            if (!assembliesInsidePck)
            {
                string outputDataGameAssembliesDir = Path.Combine(outputDataDir, "Assemblies");
                if (!Directory.Exists(outputDataGameAssembliesDir))
                {
                    Directory.CreateDirectory(outputDataGameAssembliesDir);
                }
            }

            foreach (var assembly in assemblies)
            {
                void AddToAssembliesDir(string fileSrcPath)
                {
                    if (assembliesInsidePck)
                    {
                        string fileDstPath = Path.Combine(resAssembliesDir, fileSrcPath.GetFile());
                        AddFile(fileSrcPath, fileDstPath);
                    }
                    else
                    {
                        Debug.Assert(outputDataDir != null);
                        string fileDstPath = Path.Combine(outputDataDir, "Assemblies", fileSrcPath.GetFile());
                        File.Copy(fileSrcPath, fileDstPath);
                    }
                }

                string assemblySrcPath = assembly.Value;

                string assemblyPathWithoutExtension = Path.ChangeExtension(assemblySrcPath, null);
                string pdbSrcPath = assemblyPathWithoutExtension + ".pdb";

                AddToAssembliesDir(assemblySrcPath);

                if (File.Exists(pdbSrcPath))
                {
                    AddToAssembliesDir(pdbSrcPath);
                }
            }

            // AOT compilation
            bool aotEnabled = platform == OS.Platforms.iOS || (bool)ProjectSettings.GetSetting("mono/export/aot/enabled");

            if (aotEnabled)
            {
                string aotToolchainPath = null;

                if (platform == OS.Platforms.Android)
                {
                    aotToolchainPath = (string)ProjectSettings.GetSetting("mono/export/aot/android_toolchain_path");
                }

                if (aotToolchainPath == string.Empty)
                {
                    aotToolchainPath = null; // Don't risk it being used as current working dir
                }
                // TODO: LLVM settings are hard-coded and disabled for now
                var aotOpts = new AotOptions
                {
                    EnableLLVM            = false,
                    LLVMOnly              = false,
                    LLVMPath              = "",
                    LLVMOutputPath        = "",
                    FullAot               = platform == OS.Platforms.iOS || (bool)(ProjectSettings.GetSetting("mono/export/aot/full_aot") ?? false),
                    UseInterpreter        = (bool)ProjectSettings.GetSetting("mono/export/aot/use_interpreter"),
                    ExtraAotOptions       = (string[])ProjectSettings.GetSetting("mono/export/aot/extra_aot_options") ?? new string[] { },
                    ExtraOptimizerOptions = (string[])ProjectSettings.GetSetting("mono/export/aot/extra_optimizer_options") ?? new string[] { },
                    ToolchainPath         = aotToolchainPath
                };

                AotBuilder.CompileAssemblies(this, aotOpts, features, platform, isDebug, bclDir, outputDir, outputDataDir, assemblies);
            }
        }
コード例 #4
0
ファイル: ExportPlugin.cs プロジェクト: TsFreddie/godot-rg
        private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return;
            }

            string platform = DeterminePlatformFromFeatures(features);

            if (platform == null)
            {
                throw new NotSupportedException("Target platform not supported");
            }

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

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

            string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");

            CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);

            AddFile(scriptsMetadataPath, scriptsMetadataPath);

            // Turn export features into defines
            var godotDefines = features;

            if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines))
            {
                throw new Exception("Failed to build project");
            }

            // Add dependency assemblies

            var dependencies = new Godot.Collections.Dictionary <string, string>();

            var projectDllName = (string)ProjectSettings.GetSetting("application/config/name");

            if (projectDllName.Empty())
            {
                projectDllName = "UnnamedProject";
            }

            string projectDllSrcDir  = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
            string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");

            dependencies[projectDllName] = projectDllSrcPath;

            if (platform == OS.Platforms.Android)
            {
                string godotAndroidExtProfileDir = GetBclProfileDir("godot_android_ext");
                string monoAndroidAssemblyPath   = Path.Combine(godotAndroidExtProfileDir, "Mono.Android.dll");

                if (!File.Exists(monoAndroidAssemblyPath))
                {
                    throw new FileNotFoundException("Assembly not found: 'Mono.Android'", monoAndroidAssemblyPath);
                }

                dependencies["Mono.Android"] = monoAndroidAssemblyPath;
            }

            var initialDependencies = dependencies.Duplicate();

            internal_GetExportedAssemblyDependencies(initialDependencies, buildConfig, DeterminePlatformBclDir(platform), dependencies);

            AddI18NAssemblies(dependencies, platform);

            string outputDataDir = null;

            if (PlatformHasTemplateDir(platform))
            {
                outputDataDir = ExportDataDirectory(features, platform, isDebug, outputDir);
            }

            string apiConfig        = isDebug ? "Debug" : "Release";
            string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig);

            bool assembliesInsidePck = (bool)ProjectSettings.GetSetting("mono/export/export_assemblies_inside_pck") || outputDataDir == null;

            if (!assembliesInsidePck)
            {
                string outputDataGameAssembliesDir = Path.Combine(outputDataDir, "Assemblies");
                if (!Directory.Exists(outputDataGameAssembliesDir))
                {
                    Directory.CreateDirectory(outputDataGameAssembliesDir);
                }
            }

            foreach (var dependency in dependencies)
            {
                string dependSrcPath = dependency.Value;

                if (assembliesInsidePck)
                {
                    string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile());
                    AddFile(dependSrcPath, dependDstPath);
                }
                else
                {
                    string dependDstPath = Path.Combine(outputDataDir, "Assemblies", dependSrcPath.GetFile());
                    File.Copy(dependSrcPath, dependDstPath);
                }
            }

            // AOT

            if ((bool)ProjectSettings.GetSetting("mono/export/aot/enabled"))
            {
                AotCompileDependencies(features, platform, isDebug, outputDir, outputDataDir, dependencies);
            }
        }
コード例 #5
0
        private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
        {
            if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
            {
                return;
            }

            string platform = DeterminePlatformFromFeatures(features);

            if (platform == null)
            {
                throw new NotSupportedException("Target platform not supported");
            }

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

            string buildConfig = isDebug ? "Debug" : "Release";

            string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");

            CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);

            AddFile(scriptsMetadataPath, scriptsMetadataPath);

            // Turn export features into defines
            var godotDefines = features;

            if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines))
            {
                throw new Exception("Failed to build project");
            }

            // Add dependency assemblies

            var dependencies = new Godot.Collections.Dictionary <string, string>();

            var projectDllName = (string)ProjectSettings.GetSetting("application/config/name");

            if (projectDllName.Empty())
            {
                projectDllName = "UnnamedProject";
            }

            string projectDllSrcDir  = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
            string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");

            dependencies[projectDllName] = projectDllSrcPath;

            {
                string platformBclDir = DeterminePlatformBclDir(platform);

                internal_GetExportedAssemblyDependencies(projectDllName, projectDllSrcPath, buildConfig, platformBclDir, dependencies);
            }

            string apiConfig        = isDebug ? "Debug" : "Release";
            string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig);

            foreach (var dependency in dependencies)
            {
                string dependSrcPath = dependency.Value;
                string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile());
                AddFile(dependSrcPath, dependDstPath);
            }

            // Mono specific export template extras (data dir)
            string outputDataDir = null;

            if (PlatformHasTemplateDir(platform))
            {
                outputDataDir = ExportDataDirectory(features, platform, isDebug, outputDir);
            }

            // AOT

            if ((bool)ProjectSettings.GetSetting("mono/export/aot/enabled"))
            {
                AotCompileDependencies(features, platform, isDebug, outputDir, outputDataDir, dependencies);
            }
        }