diff options
Diffstat (limited to 'modules/mono/editor')
17 files changed, 148 insertions, 368 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ApiSolutionGenerator.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ApiSolutionGenerator.cs deleted file mode 100644 index bfae2afc13..0000000000 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ApiSolutionGenerator.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace GodotTools.ProjectEditor -{ - public static class ApiSolutionGenerator - { - public static void GenerateApiSolution(string solutionDir, - string coreProjDir, IEnumerable<string> coreCompileItems, - string editorProjDir, IEnumerable<string> editorCompileItems) - { - var solution = new DotNetSolution(ApiAssemblyNames.SolutionName); - - solution.DirectoryPath = solutionDir; - - // GodotSharp project - - const string coreApiAssemblyName = ApiAssemblyNames.Core; - - string coreGuid = ProjectGenerator.GenCoreApiProject(coreProjDir, coreCompileItems); - - var coreProjInfo = new DotNetSolution.ProjectInfo - { - Guid = coreGuid, - PathRelativeToSolution = Path.Combine(coreApiAssemblyName, $"{coreApiAssemblyName}.csproj") - }; - coreProjInfo.Configs.Add("Debug"); - coreProjInfo.Configs.Add("Release"); - - solution.AddNewProject(coreApiAssemblyName, coreProjInfo); - - // GodotSharpEditor project - - const string editorApiAssemblyName = ApiAssemblyNames.Editor; - - string editorGuid = ProjectGenerator.GenEditorApiProject(editorProjDir, - $"../{coreApiAssemblyName}/{coreApiAssemblyName}.csproj", editorCompileItems); - - var editorProjInfo = new DotNetSolution.ProjectInfo(); - editorProjInfo.Guid = editorGuid; - editorProjInfo.PathRelativeToSolution = Path.Combine(editorApiAssemblyName, $"{editorApiAssemblyName}.csproj"); - editorProjInfo.Configs.Add("Debug"); - editorProjInfo.Configs.Add("Release"); - - solution.AddNewProject(editorApiAssemblyName, editorProjInfo); - - // Save solution - - solution.Save(); - } - } -} diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj index ab3a5d1aea..ae727e8789 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/GodotTools.ProjectEditor.csproj @@ -32,18 +32,11 @@ <Reference Include="System" /> <Reference Include="Microsoft.Build" /> <Reference Include="DotNet.Glob, Version=2.1.1.0, Culture=neutral, PublicKeyToken=b68cc888b4f632d1, processorArchitecture=MSIL"> - <!-- - When building Godot with 'mono_glue=no' SCons will build this project alone instead of the - entire solution. $(SolutionDir) is not defined in that case, so we need to workaround that. - We make SCons restore the NuGet packages in the project directory instead in this case. - --> - <HintPath Condition=" '$(SolutionDir)' != '' And Exists('$(SolutionDir)\packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll') ">$(SolutionDir)\packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll</HintPath> - <HintPath Condition=" '$(SolutionDir)' == '' Or !Exists('$(SolutionDir)\packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll') ">$(ProjectDir)\packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll</HintPath> + <HintPath>packages\DotNet.Glob.2.1.1\lib\net45\DotNet.Glob.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> <Compile Include="ApiAssembliesInfo.cs" /> - <Compile Include="ApiSolutionGenerator.cs" /> <Compile Include="DotNetSolution.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="IdentifierUtils.cs" /> diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs index b40d985d51..82627de01a 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs @@ -2,6 +2,7 @@ using GodotTools.Core; using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using Microsoft.Build.Construction; namespace GodotTools.ProjectEditor @@ -10,68 +11,13 @@ namespace GodotTools.ProjectEditor { private const string CoreApiProjectName = "GodotSharp"; private const string EditorApiProjectName = "GodotSharpEditor"; - private const string CoreApiProjectGuid = "{AEBF0036-DA76-4341-B651-A3F2856AB2FA}"; - private const string EditorApiProjectGuid = "{8FBEC238-D944-4074-8548-B3B524305905}"; - - public static string GenCoreApiProject(string dir, IEnumerable<string> compileItems) - { - string path = Path.Combine(dir, CoreApiProjectName + ".csproj"); - - ProjectPropertyGroupElement mainGroup; - var root = CreateLibraryProject(CoreApiProjectName, out mainGroup); - - mainGroup.AddProperty("DocumentationFile", Path.Combine("$(OutputPath)", "$(AssemblyName).xml")); - mainGroup.SetProperty("RootNamespace", "Godot"); - mainGroup.SetProperty("ProjectGuid", CoreApiProjectGuid); - mainGroup.SetProperty("BaseIntermediateOutputPath", "obj"); - - GenAssemblyInfoFile(root, dir, CoreApiProjectName, - new[] { "[assembly: InternalsVisibleTo(\"" + EditorApiProjectName + "\")]" }, - new[] { "System.Runtime.CompilerServices" }); - - foreach (var item in compileItems) - { - root.AddItem("Compile", item.RelativeToPath(dir).Replace("/", "\\")); - } - - root.Save(path); - - return CoreApiProjectGuid; - } - - public static string GenEditorApiProject(string dir, string coreApiProjPath, IEnumerable<string> compileItems) - { - string path = Path.Combine(dir, EditorApiProjectName + ".csproj"); - - ProjectPropertyGroupElement mainGroup; - var root = CreateLibraryProject(EditorApiProjectName, out mainGroup); - - mainGroup.AddProperty("DocumentationFile", Path.Combine("$(OutputPath)", "$(AssemblyName).xml")); - mainGroup.SetProperty("RootNamespace", "Godot"); - mainGroup.SetProperty("ProjectGuid", EditorApiProjectGuid); - mainGroup.SetProperty("BaseIntermediateOutputPath", "obj"); - - GenAssemblyInfoFile(root, dir, EditorApiProjectName); - - foreach (var item in compileItems) - { - root.AddItem("Compile", item.RelativeToPath(dir).Replace("/", "\\")); - } - - var coreApiRef = root.AddItem("ProjectReference", coreApiProjPath.Replace("/", "\\")); - coreApiRef.AddMetadata("Private", "False"); - - root.Save(path); - - return EditorApiProjectGuid; - } public static string GenGameProject(string dir, string name, IEnumerable<string> compileItems) { string path = Path.Combine(dir, name + ".csproj"); ProjectPropertyGroupElement mainGroup; - var root = CreateLibraryProject(name, out mainGroup); + var root = CreateLibraryProject(name, "Tools", out mainGroup); mainGroup.SetProperty("OutputPath", Path.Combine(".mono", "temp", "bin", "$(Configuration)")); mainGroup.SetProperty("BaseIntermediateOutputPath", Path.Combine(".mono", "temp", "obj")); @@ -110,7 +56,7 @@ namespace GodotTools.ProjectEditor return root.GetGuid().ToString().ToUpper(); } - public static void GenAssemblyInfoFile(ProjectRootElement root, string dir, string name, string[] assemblyLines = null, string[] usingDirectives = null) + private static void GenAssemblyInfoFile(ProjectRootElement root, string dir, string name, string[] assemblyLines = null, string[] usingDirectives = null) { string propertiesDir = Path.Combine(dir, "Properties"); if (!Directory.Exists(propertiesDir)) @@ -138,7 +84,7 @@ namespace GodotTools.ProjectEditor root.AddItem("Compile", assemblyInfoFile.RelativeToPath(dir).Replace("/", "\\")); } - public static ProjectRootElement CreateLibraryProject(string name, out ProjectPropertyGroupElement mainGroup) + public static ProjectRootElement CreateLibraryProject(string name, string defaultConfig, out ProjectPropertyGroupElement mainGroup) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name)); @@ -147,7 +93,7 @@ namespace GodotTools.ProjectEditor root.DefaultTargets = "Build"; mainGroup = root.AddPropertyGroup(); - mainGroup.AddProperty("Configuration", "Debug").Condition = " '$(Configuration)' == '' "; + mainGroup.AddProperty("Configuration", defaultConfig).Condition = " '$(Configuration)' == '' "; mainGroup.AddProperty("Platform", "AnyCPU").Condition = " '$(Platform)' == '' "; mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}"); mainGroup.AddProperty("OutputType", "Library"); @@ -155,6 +101,7 @@ namespace GodotTools.ProjectEditor mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true)); mainGroup.AddProperty("AssemblyName", name); mainGroup.AddProperty("TargetFrameworkVersion", "v4.5"); + mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString()); var debugGroup = root.AddPropertyGroup(); debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "; @@ -184,16 +131,6 @@ namespace GodotTools.ProjectEditor return root; } - private static void AddItems(ProjectRootElement elem, string groupName, params string[] items) - { - var group = elem.AddItemGroup(); - - foreach (var item in items) - { - group.AddItem(groupName, item); - } - } - private const string AssemblyInfoTemplate = @"using System.Reflection;{0} diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj index dbd774a66a..618527f916 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj +++ b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj @@ -9,6 +9,7 @@ <AssemblyName>GodotTools</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <GodotSourceRootPath>$(SolutionDir)/../../../../</GodotSourceRootPath> + <DataDirToolsOutputPath>$(GodotSourceRootPath)/bin/GodotSharp/Tools</DataDirToolsOutputPath> <GodotApiConfiguration>Debug</GodotApiConfiguration> <LangVersion>7</LangVersion> </PropertyGroup> @@ -34,7 +35,6 @@ <HintPath>..\packages\JetBrains.Annotations.2019.1.3\lib\net20\JetBrains.Annotations.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="Mono.Posix" /> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <Private>True</Private> @@ -42,9 +42,11 @@ <Reference Include="System" /> <Reference Include="GodotSharp"> <HintPath>$(GodotSourceRootPath)/bin/GodotSharp/Api/$(GodotApiConfiguration)/GodotSharp.dll</HintPath> + <Private>False</Private> </Reference> <Reference Include="GodotSharpEditor"> <HintPath>$(GodotSourceRootPath)/bin/GodotSharp/Api/$(GodotApiConfiguration)/GodotSharpEditor.dll</HintPath> + <Private>False</Private> </Reference> </ItemGroup> <ItemGroup> @@ -57,7 +59,6 @@ <Compile Include="Ides\MonoDevelop\Instance.cs" /> <Compile Include="Ides\Rider\RiderPathLocator.cs" /> <Compile Include="Ides\Rider\RiderPathManager.cs" /> - <Compile Include="Internals\BindingsGenerator.cs" /> <Compile Include="Internals\EditorProgress.cs" /> <Compile Include="Internals\GodotSharpDirs.cs" /> <Compile Include="Internals\Internal.cs" /> @@ -100,8 +101,21 @@ <ItemGroup> <None Include="packages.config" /> </ItemGroup> - <ItemGroup> - <Content Include="Ides\Rider\.editorconfig" /> - </ItemGroup> + <Target Name="CopyToDataDir" AfterTargets="Build"> + <ItemGroup> + <GodotToolsCopy Include="$(OutputPath)\GodotTools*.dll" /> + <GodotToolsCopy Include="$(OutputPath)\Newtonsoft.Json.dll" /> + <GodotToolsCopy Include="$(OutputPath)\DotNet.Glob.dll" /> + </ItemGroup> + <ItemGroup Condition=" '$(Configuration)' == 'Debug' "> + <GodotToolsCopy Include="$(OutputPath)\GodotTools*.pdb" /> + </ItemGroup> + <Copy SourceFiles="@(GodotToolsCopy)" DestinationFolder="$(DataDirToolsOutputPath)" ContinueOnError="false" /> + </Target> + <Target Name="BuildAlwaysCopyToDataDir"> + <!-- Custom target run by SCons to make sure the CopyToDataDir target is always executed, without having to use DisableFastUpToDateCheck --> + <CallTarget Targets="Build" /> + <CallTarget Targets="CopyToDataDir" /> + </Target> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs index b752535dcb..9038333d38 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs @@ -89,18 +89,20 @@ namespace GodotTools.Ides.Rider { var installInfos = new List<RiderInfo>(); // "/Applications/*Rider*.app" + // should be combined with "Contents/MacOS/rider" var folder = new DirectoryInfo("/Applications"); if (folder.Exists) { installInfos.AddRange(folder.GetDirectories("*Rider*.app") - .Select(a => new RiderInfo(a.FullName, false)) + .Select(a => new RiderInfo(Path.Combine(a.FullName, "Contents/MacOS/rider"), false)) .ToList()); } // /Users/user/Library/Application Support/JetBrains/Toolbox/apps/Rider/ch-1/181.3870.267/Rider EAP.app + // should be combined with "Contents/MacOS/rider" var toolboxRiderRootPath = GetToolboxBaseDir(); var paths = CollectPathsFromToolbox(toolboxRiderRootPath, "", "Rider*.app", true) - .Select(a => new RiderInfo(a, true)); + .Select(a => new RiderInfo(Path.Combine(a, "Contents/MacOS/rider"), true)); installInfos.AddRange(paths); return installInfos.ToArray(); diff --git a/modules/mono/editor/GodotTools/GodotTools/Internals/BindingsGenerator.cs b/modules/mono/editor/GodotTools/GodotTools/Internals/BindingsGenerator.cs deleted file mode 100644 index 1daa5e138e..0000000000 --- a/modules/mono/editor/GodotTools/GodotTools/Internals/BindingsGenerator.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace GodotTools.Internals -{ - public class BindingsGenerator : IDisposable - { - class BindingsGeneratorSafeHandle : SafeHandle - { - public BindingsGeneratorSafeHandle(IntPtr handle) : base(IntPtr.Zero, true) - { - this.handle = handle; - } - - public override bool IsInvalid => handle == IntPtr.Zero; - - protected override bool ReleaseHandle() - { - internal_Dtor(handle); - return true; - } - } - - private BindingsGeneratorSafeHandle safeHandle; - private bool disposed = false; - - public bool LogPrintEnabled - { - get => internal_LogPrintEnabled(GetPtr()); - set => internal_SetLogPrintEnabled(GetPtr(), value); - } - - public static uint Version => internal_Version(); - public static uint CsGlueVersion => internal_CsGlueVersion(); - - public Godot.Error GenerateCsApi(string outputDir) => internal_GenerateCsApi(GetPtr(), outputDir); - - internal IntPtr GetPtr() - { - if (disposed) - throw new ObjectDisposedException(GetType().FullName); - - return safeHandle.DangerousGetHandle(); - } - - public void Dispose() - { - if (disposed) - return; - - if (safeHandle != null && !safeHandle.IsInvalid) - { - safeHandle.Dispose(); - safeHandle = null; - } - - disposed = true; - } - - public BindingsGenerator() - { - safeHandle = new BindingsGeneratorSafeHandle(internal_Ctor()); - } - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern IntPtr internal_Ctor(); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern void internal_Dtor(IntPtr handle); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern bool internal_LogPrintEnabled(IntPtr handle); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern void internal_SetLogPrintEnabled(IntPtr handle, bool enabled); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern Godot.Error internal_GenerateCsApi(IntPtr handle, string outputDir); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern uint internal_Version(); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern uint internal_CsGlueVersion(); - } -} diff --git a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs index 5a867b7f8b..279e67b3eb 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs @@ -5,7 +5,6 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using Mono.Unix.Native; namespace GodotTools.Utils { @@ -15,6 +14,9 @@ namespace GodotTools.Utils [MethodImpl(MethodImplOptions.InternalCall)] static extern string GetPlatformName(); + [MethodImpl(MethodImplOptions.InternalCall)] + static extern bool UnixFileHasExecutableAccess(string filePath); + public static class Names { public const string Windows = "Windows"; @@ -105,7 +107,7 @@ namespace GodotTools.Utils searchDirs.AddRange(pathDirs); string nameExt = Path.GetExtension(name); - bool hasPathExt = string.IsNullOrEmpty(nameExt) || windowsExts.Contains(nameExt, StringComparer.OrdinalIgnoreCase); + bool hasPathExt = !string.IsNullOrEmpty(nameExt) && windowsExts.Contains(nameExt, StringComparer.OrdinalIgnoreCase); searchDirs.Add(System.IO.Directory.GetCurrentDirectory()); // last in the list @@ -131,7 +133,7 @@ namespace GodotTools.Utils searchDirs.Add(System.IO.Directory.GetCurrentDirectory()); // last in the list return searchDirs.Select(dir => Path.Combine(dir, name)) - .FirstOrDefault(path => File.Exists(path) && Syscall.access(path, AccessModes.X_OK) == 0); + .FirstOrDefault(path => File.Exists(path) && UnixFileHasExecutableAccess(path)); } public static void RunProcess(string command, IEnumerable<string> arguments) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 2252f7676d..9beadb1778 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -40,7 +40,6 @@ #include "core/os/os.h" #include "core/ucaps.h" -#include "../glue/cs_compressed.gen.h" #include "../glue/cs_glue_version.gen.h" #include "../godotsharp_defs.h" #include "../mono_gd/gd_mono_marshal.h" @@ -874,7 +873,7 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) { p_output.append("\n#pragma warning restore CS1591\n"); } -Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vector<String> &r_compile_items) { +Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir) { ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); @@ -887,22 +886,24 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect } da->change_dir(p_proj_dir); - da->make_dir("Core"); - da->make_dir("ObjectType"); + da->make_dir("Generated"); + da->make_dir("Generated/GodotObjects"); - String core_dir = path::join(p_proj_dir, "Core"); - String obj_type_dir = path::join(p_proj_dir, "ObjectType"); + String base_gen_dir = path::join(p_proj_dir, "Generated"); + String godot_objects_gen_dir = path::join(base_gen_dir, "GodotObjects"); + + Vector<String> compile_items; // Generate source file for global scope constants and enums { StringBuilder constants_source; _generate_global_constants(constants_source); - String output_file = path::join(core_dir, BINDINGS_GLOBAL_SCOPE_CLASS "_constants.cs"); + String output_file = path::join(base_gen_dir, BINDINGS_GLOBAL_SCOPE_CLASS "_constants.cs"); Error save_err = _save_file(output_file, constants_source); if (save_err != OK) return save_err; - r_compile_items.push_back(output_file); + compile_items.push_back(output_file); } for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) { @@ -911,7 +912,7 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect if (itype.api_type == ClassDB::API_EDITOR) continue; - String output_file = path::join(obj_type_dir, itype.proxy_name + ".cs"); + String output_file = path::join(godot_objects_gen_dir, itype.proxy_name + ".cs"); Error err = _generate_cs_type(itype, output_file); if (err == ERR_SKIP) @@ -920,39 +921,11 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect if (err != OK) return err; - r_compile_items.push_back(output_file); + compile_items.push_back(output_file); } // Generate sources from compressed files - Map<String, GodotCsCompressedFile> compressed_files; - get_compressed_files(compressed_files); - - for (Map<String, GodotCsCompressedFile>::Element *E = compressed_files.front(); E; E = E->next()) { - const String &file_name = E->key(); - const GodotCsCompressedFile &file_data = E->value(); - - String output_file = path::join(core_dir, file_name); - - Vector<uint8_t> data; - data.resize(file_data.uncompressed_size); - Compression::decompress(data.ptrw(), file_data.uncompressed_size, file_data.data, file_data.compressed_size, Compression::MODE_DEFLATE); - - String output_dir = output_file.get_base_dir(); - - if (!DirAccess::exists(output_dir)) { - Error err = da->make_dir_recursive(ProjectSettings::get_singleton()->globalize_path(output_dir)); - ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); - } - - FileAccessRef file = FileAccess::open(output_file, FileAccess::WRITE); - ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE); - file->store_buffer(data.ptr(), data.size()); - file->close(); - - r_compile_items.push_back(output_file); - } - StringBuilder cs_icalls_content; cs_icalls_content.append("using System;\n" @@ -986,18 +959,36 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir, Vect cs_icalls_content.append(INDENT1 CLOSE_BLOCK CLOSE_BLOCK); - String internal_methods_file = path::join(core_dir, BINDINGS_CLASS_NATIVECALLS ".cs"); + String internal_methods_file = path::join(base_gen_dir, BINDINGS_CLASS_NATIVECALLS ".cs"); Error err = _save_file(internal_methods_file, cs_icalls_content); if (err != OK) return err; - r_compile_items.push_back(internal_methods_file); + compile_items.push_back(internal_methods_file); + + StringBuilder includes_props_content; + includes_props_content.append("<Project>\n" + " <ItemGroup>\n"); + + for (int i = 0; i < compile_items.size(); i++) { + String include = path::relative_to(compile_items[i], p_proj_dir).replace("/", "\\"); + includes_props_content.append(" <Compile Include=\"" + include + "\" />\n"); + } + + includes_props_content.append(" </ItemGroup>\n" + "</Project>\n"); + + String includes_props_file = path::join(base_gen_dir, "GeneratedIncludes.props"); + + err = _save_file(includes_props_file, includes_props_content); + if (err != OK) + return err; return OK; } -Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Vector<String> &r_compile_items) { +Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir) { ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); @@ -1010,11 +1001,13 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve } da->change_dir(p_proj_dir); - da->make_dir("Core"); - da->make_dir("ObjectType"); + da->make_dir("Generated"); + da->make_dir("Generated/GodotObjects"); - String core_dir = path::join(p_proj_dir, "Core"); - String obj_type_dir = path::join(p_proj_dir, "ObjectType"); + String base_gen_dir = path::join(p_proj_dir, "Generated"); + String godot_objects_gen_dir = path::join(base_gen_dir, "GodotObjects"); + + Vector<String> compile_items; for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) { const TypeInterface &itype = E.get(); @@ -1022,7 +1015,7 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve if (itype.api_type != ClassDB::API_EDITOR) continue; - String output_file = path::join(obj_type_dir, itype.proxy_name + ".cs"); + String output_file = path::join(godot_objects_gen_dir, itype.proxy_name + ".cs"); Error err = _generate_cs_type(itype, output_file); if (err == ERR_SKIP) @@ -1031,7 +1024,7 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve if (err != OK) return err; - r_compile_items.push_back(output_file); + compile_items.push_back(output_file); } StringBuilder cs_icalls_content; @@ -1068,13 +1061,31 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir, Ve cs_icalls_content.append(INDENT1 CLOSE_BLOCK CLOSE_BLOCK); - String internal_methods_file = path::join(core_dir, BINDINGS_CLASS_NATIVECALLS_EDITOR ".cs"); + String internal_methods_file = path::join(base_gen_dir, BINDINGS_CLASS_NATIVECALLS_EDITOR ".cs"); Error err = _save_file(internal_methods_file, cs_icalls_content); if (err != OK) return err; - r_compile_items.push_back(internal_methods_file); + compile_items.push_back(internal_methods_file); + + StringBuilder includes_props_content; + includes_props_content.append("<Project>\n" + " <ItemGroup>\n"); + + for (int i = 0; i < compile_items.size(); i++) { + String include = path::relative_to(compile_items[i], p_proj_dir).replace("/", "\\"); + includes_props_content.append(" <Compile Include=\"" + include + "\" />\n"); + } + + includes_props_content.append(" </ItemGroup>\n" + "</Project>\n"); + + String includes_props_file = path::join(base_gen_dir, "GeneratedIncludes.props"); + + err = _save_file(includes_props_file, includes_props_content); + if (err != OK) + return err; return OK; } @@ -1098,9 +1109,8 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // Generate GodotSharp source files String core_proj_dir = output_dir.plus_file(CORE_API_ASSEMBLY_NAME); - Vector<String> core_compile_items; - proj_err = generate_cs_core_project(core_proj_dir, core_compile_items); + proj_err = generate_cs_core_project(core_proj_dir); if (proj_err != OK) { ERR_PRINT("Generation of the Core API C# project failed."); return proj_err; @@ -1109,22 +1119,14 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // Generate GodotSharpEditor source files String editor_proj_dir = output_dir.plus_file(EDITOR_API_ASSEMBLY_NAME); - Vector<String> editor_compile_items; - proj_err = generate_cs_editor_project(editor_proj_dir, editor_compile_items); + proj_err = generate_cs_editor_project(editor_proj_dir); if (proj_err != OK) { ERR_PRINT("Generation of the Editor API C# project failed."); return proj_err; } - // Generate solution - - if (!CSharpProject::generate_api_solution(output_dir, - core_proj_dir, core_compile_items, editor_proj_dir, editor_compile_items)) { - return ERR_CANT_CREATE; - } - - _log("The solution for the Godot API was generated successfully\n"); + _log("The Godot API sources were successfully generated\n"); return OK; } @@ -1600,7 +1602,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf // Apparently the name attribute must not include the @ String param_tag_name = iarg.name.begins_with("@") ? iarg.name.substr(1, iarg.name.length()) : iarg.name; - default_args_doc.append(INDENT2 "/// <param name=\"" + param_tag_name + "\">If the parameter is null, then the default value is " + def_arg + "</param>\n"); + default_args_doc.append(MEMBER_BEGIN "/// <param name=\"" + param_tag_name + "\">If the parameter is null, then the default value is " + def_arg + "</param>"); } else { icall_params += arg_type->cs_in.empty() ? iarg.name : sformat(arg_type->cs_in, iarg.name); } @@ -1619,7 +1621,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf String xml_summary = bbcode_to_xml(fix_doc_description(p_imethod.method_doc->description), &p_itype); Vector<String> summary_lines = xml_summary.length() ? xml_summary.split("\n") : Vector<String>(); - if (summary_lines.size() || default_args_doc.get_string_length()) { + if (summary_lines.size()) { p_output.append(MEMBER_BEGIN "/// <summary>\n"); for (int i = 0; i < summary_lines.size(); i++) { @@ -1628,11 +1630,14 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf p_output.append("\n"); } - p_output.append(default_args_doc.as_string()); p_output.append(INDENT2 "/// </summary>"); } } + if (default_args_doc.get_string_length()) { + p_output.append(default_args_doc.as_string()); + } + if (!p_imethod.is_internal) { p_output.append(MEMBER_BEGIN "[GodotMethod(\""); p_output.append(p_imethod.name); @@ -2064,9 +2069,11 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte p_output.append(p_imethod.arguments.size() ? C_LOCAL_PTRCALL_ARGS ".ptr()" : "NULL"); p_output.append(", total_length, vcall_error);\n"); - // See the comment on the C_LOCAL_VARARG_RET declaration - if (return_type->cname != name_cache.type_Variant) { - p_output.append("\t" C_LOCAL_RET " = " C_LOCAL_VARARG_RET ";\n"); + if (!ret_void) { + // See the comment on the C_LOCAL_VARARG_RET declaration + if (return_type->cname != name_cache.type_Variant) { + p_output.append("\t" C_LOCAL_RET " = " C_LOCAL_VARARG_RET ";\n"); + } } } else { p_output.append("\t" CS_PARAM_METHODBIND "->ptrcall(" CS_PARAM_INSTANCE ", "); @@ -3170,7 +3177,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) if (bindings_generator.generate_glue(glue_dir_path) != OK) ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C++ glue."); - if (bindings_generator.generate_cs_api(glue_dir_path.plus_file("Managed/Generated")) != OK) + if (bindings_generator.generate_cs_api(glue_dir_path.plus_file(API_SOLUTION_NAME)) != OK) ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C# API."); } diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index 07918a2d03..d3a8937313 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -635,8 +635,8 @@ class BindingsGenerator { void _initialize(); public: - Error generate_cs_core_project(const String &p_proj_dir, Vector<String> &r_compile_files); - Error generate_cs_editor_project(const String &p_proj_dir, Vector<String> &r_compile_items); + Error generate_cs_core_project(const String &p_proj_dir); + Error generate_cs_editor_project(const String &p_proj_dir); Error generate_cs_api(const String &p_output_dir); Error generate_glue(const String &p_output_dir); diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp index 748447005f..872f45ba91 100644 --- a/modules/mono/editor/csharp_project.cpp +++ b/modules/mono/editor/csharp_project.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -44,54 +44,6 @@ namespace CSharpProject { -bool generate_api_solution_impl(const String &p_solution_dir, const String &p_core_proj_dir, const Vector<String> &p_core_compile_items, - const String &p_editor_proj_dir, const Vector<String> &p_editor_compile_items, - GDMonoAssembly *p_tools_project_editor_assembly) { - - GDMonoClass *klass = p_tools_project_editor_assembly->get_class("GodotTools.ProjectEditor", "ApiSolutionGenerator"); - - Variant solution_dir = p_solution_dir; - Variant core_proj_dir = p_core_proj_dir; - Variant core_compile_items = p_core_compile_items; - Variant editor_proj_dir = p_editor_proj_dir; - Variant editor_compile_items = p_editor_compile_items; - const Variant *args[5] = { &solution_dir, &core_proj_dir, &core_compile_items, &editor_proj_dir, &editor_compile_items }; - MonoException *exc = NULL; - klass->get_method("GenerateApiSolution", 5)->invoke(NULL, args, &exc); - - if (exc) { - GDMonoUtils::debug_print_unhandled_exception(exc); - ERR_FAIL_V(false); - } - - return true; -} - -bool generate_api_solution(const String &p_solution_dir, const String &p_core_proj_dir, const Vector<String> &p_core_compile_items, - const String &p_editor_proj_dir, const Vector<String> &p_editor_compile_items) { - - if (GDMono::get_singleton()->get_tools_project_editor_assembly()) { - return generate_api_solution_impl(p_solution_dir, p_core_proj_dir, p_core_compile_items, - p_editor_proj_dir, p_editor_compile_items, - GDMono::get_singleton()->get_tools_project_editor_assembly()); - } else { - MonoDomain *temp_domain = GDMonoUtils::create_domain("GodotEngine.Domain.ApiSolutionGeneration"); - CRASH_COND(temp_domain == NULL); - _GDMONO_SCOPE_EXIT_DOMAIN_UNLOAD_(temp_domain); - - _GDMONO_SCOPE_DOMAIN_(temp_domain); - - GDMonoAssembly *tools_project_editor_asm = NULL; - - bool assembly_loaded = GDMono::get_singleton()->load_assembly(TOOLS_PROJECT_EDITOR_ASM_NAME, &tools_project_editor_asm); - ERR_FAIL_COND_V_MSG(!assembly_loaded, false, "Failed to load assembly: '" TOOLS_PROJECT_EDITOR_ASM_NAME "'."); - - return generate_api_solution_impl(p_solution_dir, p_core_proj_dir, p_core_compile_items, - p_editor_proj_dir, p_editor_compile_items, - tools_project_editor_asm); - } -} - void add_item(const String &p_project_path, const String &p_item_type, const String &p_include) { if (!GLOBAL_DEF("mono/project/auto_update_project", true)) diff --git a/modules/mono/editor/csharp_project.h b/modules/mono/editor/csharp_project.h index b42762cea2..515b8d3d62 100644 --- a/modules/mono/editor/csharp_project.h +++ b/modules/mono/editor/csharp_project.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -35,9 +35,6 @@ namespace CSharpProject { -bool generate_api_solution(const String &p_solution_dir, const String &p_core_proj_dir, const Vector<String> &p_core_compile_items, - const String &p_editor_proj_dir, const Vector<String> &p_editor_compile_items); - void add_item(const String &p_project_path, const String &p_item_type, const String &p_include); } // namespace CSharpProject diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index 443b4ba841..cfc869cd39 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,9 +30,14 @@ #include "editor_internal_calls.h" +#ifdef UNIX_ENABLED +#include <unistd.h> // access +#endif + #include "core/os/os.h" #include "core/version.h" #include "editor/editor_node.h" +#include "editor/editor_scale.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/script_editor_debugger.h" #include "main/main.h" @@ -370,6 +375,15 @@ MonoString *godot_icall_Utils_OS_GetPlatformName() { return GDMonoMarshal::mono_string_from_godot(os_name); } +MonoBoolean godot_icall_Utils_OS_UnixFileHasExecutableAccess(MonoString *p_file_path) { +#ifdef UNIX_ENABLED + String file_path = GDMonoMarshal::mono_string_to_godot(p_file_path); + return access(file_path.utf8().get_data(), X_OK) == 0; +#else + ERR_FAIL_V(false); +#endif +} + void register_editor_internal_calls() { // GodotSharpDirs @@ -442,4 +456,5 @@ void register_editor_internal_calls() { // Utils.OS mono_add_internal_call("GodotTools.Utils.OS::GetPlatformName", (void *)godot_icall_Utils_OS_GetPlatformName); + mono_add_internal_call("GodotTools.Utils.OS::UnixFileHasExecutableAccess", (void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess); } diff --git a/modules/mono/editor/editor_internal_calls.h b/modules/mono/editor/editor_internal_calls.h index 1682da66e5..ef4e639161 100644 --- a/modules/mono/editor/editor_internal_calls.h +++ b/modules/mono/editor/editor_internal_calls.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/editor/godotsharp_export.cpp b/modules/mono/editor/godotsharp_export.cpp index e02bd3be58..ce0b6ad0e6 100644 --- a/modules/mono/editor/godotsharp_export.cpp +++ b/modules/mono/editor/godotsharp_export.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/editor/godotsharp_export.h b/modules/mono/editor/godotsharp_export.h index 8eb5a4d9dc..36138f81b7 100644 --- a/modules/mono/editor/godotsharp_export.h +++ b/modules/mono/editor/godotsharp_export.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index 1c3a583601..c400479b89 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/editor/script_class_parser.h b/modules/mono/editor/script_class_parser.h index 39003336ac..a76a3a50a9 100644 --- a/modules/mono/editor/script_class_parser.h +++ b/modules/mono/editor/script_class_parser.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |