From dbd55e8f360561ae802f24536b04e223830ade9c Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 12 Apr 2024 02:37:32 +0200 Subject: [PATCH 1/2] Expose `EditorExportPlatform::add_message` in `ExportPlugin` Allow export plugins to add messages to the preset's export platform. --- doc/classes/EditorExportPlatform.xml | 14 ++++++++++++++ doc/classes/EditorExportPlugin.xml | 9 +++++++++ editor/export/editor_export_platform.cpp | 7 ++++++- editor/export/editor_export_platform.h | 2 ++ editor/export/editor_export_plugin.cpp | 5 +++++ editor/export/editor_export_plugin.h | 2 ++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/classes/EditorExportPlatform.xml b/doc/classes/EditorExportPlatform.xml index 0e5de79b25da..540516d0c16f 100644 --- a/doc/classes/EditorExportPlatform.xml +++ b/doc/classes/EditorExportPlatform.xml @@ -18,4 +18,18 @@ + + + Invalid message type used as the default value when no type is specified. + + + Message type for informational messages that have no effect on the export. + + + Message type for warning messages that should be addressed but still allow to complete the export. + + + Message type for error messages that must be addressed and fail the export. + + diff --git a/doc/classes/EditorExportPlugin.xml b/doc/classes/EditorExportPlugin.xml index 436f471e5d36..c2ab0a6eee45 100644 --- a/doc/classes/EditorExportPlugin.xml +++ b/doc/classes/EditorExportPlugin.xml @@ -292,6 +292,15 @@ [b]Note:[/b] This is useful only for macOS exports. + + + + + + + Adds a message to the export log that will be displayed when exporting ends. + + diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 33fdd7418e60..9626a5c5de2b 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -71,7 +71,7 @@ bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err) p_log->add_text(" "); p_log->add_text(get_name()); p_log->add_text(" - "); - if (p_err == OK) { + if (p_err == OK && get_worst_message_type() < EditorExportPlatform::EXPORT_MESSAGE_ERROR) { if (get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_WARNING) { p_log->add_image(p_log->get_editor_theme_icon(SNAME("StatusWarning")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER); p_log->add_text(" "); @@ -2026,6 +2026,11 @@ Error EditorExportPlatform::ssh_push_to_remote(const String &p_host, const Strin void EditorExportPlatform::_bind_methods() { ClassDB::bind_method(D_METHOD("get_os_name"), &EditorExportPlatform::get_os_name); + + BIND_ENUM_CONSTANT(EXPORT_MESSAGE_NONE); + BIND_ENUM_CONSTANT(EXPORT_MESSAGE_INFO); + BIND_ENUM_CONSTANT(EXPORT_MESSAGE_WARNING); + BIND_ENUM_CONSTANT(EXPORT_MESSAGE_ERROR); } EditorExportPlatform::EditorExportPlatform() { diff --git a/editor/export/editor_export_platform.h b/editor/export/editor_export_platform.h index 26e1f86c8b86..21d6c77e8f50 100644 --- a/editor/export/editor_export_platform.h +++ b/editor/export/editor_export_platform.h @@ -256,4 +256,6 @@ class EditorExportPlatform : public RefCounted { EditorExportPlatform(); }; +VARIANT_ENUM_CAST(EditorExportPlatform::ExportMessageType); + #endif // EDITOR_EXPORT_PLATFORM_H diff --git a/editor/export/editor_export_plugin.cpp b/editor/export/editor_export_plugin.cpp index 5353eae6545b..ce6812b90525 100644 --- a/editor/export/editor_export_plugin.cpp +++ b/editor/export/editor_export_plugin.cpp @@ -48,6 +48,10 @@ Ref EditorExportPlugin::get_export_preset() const { return export_preset; } +void EditorExportPlugin::add_message(EditorExportPlatform::ExportMessageType p_type, const String &p_category, const String &p_message) const { + get_export_preset()->get_platform()->add_message(p_type, p_category, p_message); +} + void EditorExportPlugin::add_file(const String &p_path, const Vector &p_file, bool p_remap) { ExtraFile ef; ef.data = p_file; @@ -304,6 +308,7 @@ void EditorExportPlugin::skip() { } void EditorExportPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("add_message", "type", "category", "message"), &EditorExportPlugin::add_message); ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object); ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib); ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file); diff --git a/editor/export/editor_export_plugin.h b/editor/export/editor_export_plugin.h index a4e9917a81cb..9670e31f8f5f 100644 --- a/editor/export/editor_export_plugin.h +++ b/editor/export/editor_export_plugin.h @@ -92,6 +92,8 @@ class EditorExportPlugin : public RefCounted { void set_export_preset(const Ref &p_preset); Ref get_export_preset() const; + void add_message(EditorExportPlatform::ExportMessageType p_type, const String &p_category, const String &p_message) const; + void add_file(const String &p_path, const Vector &p_file, bool p_remap); void add_shared_object(const String &p_path, const Vector &tags, const String &p_target = String()); From c69851b89983aee288c575d1242604ee80cf33de Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 12 Apr 2024 02:40:29 +0200 Subject: [PATCH 2/2] Use `EditorExportPlugin::add_message` in C# export plugin Integrates .NET error messages with the export log dialog. --- .../GodotTools/Build/BuildManager.cs | 5 --- .../GodotTools/Export/ExportPlugin.cs | 37 +++++++------------ 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs index ebb26773613d..d7877fa5fcd7 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs @@ -265,11 +265,6 @@ private static bool PublishProjectBlocking(BuildInfo buildInfo) success = Publish(buildInfo); } - if (!success) - { - ShowBuildErrorDialog("Failed to publish .NET project"); - } - return success; } diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs index d3720dcb727e..7caae8c971dd 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs @@ -75,7 +75,16 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool }; } - private string? _maybeLastExportError; + private void AddExceptionMessage(Exception exception) + { + string? exceptionMessage = exception.Message; + if (string.IsNullOrEmpty(exceptionMessage)) + { + exceptionMessage = $"Exception thrown: {exception.GetType().Name}"; + } + + AddMessage(EditorExportPlatform.ExportMessageType.Error, "Export .NET Project", exceptionMessage); + } // With this method we can override how a file is exported in the PCK public override void _ExportFile(string path, string type, string[] features) @@ -92,8 +101,8 @@ public override void _ExportFile(string path, string type, string[] features) if (!ProjectContainsDotNet()) { - _maybeLastExportError = $"This project contains C# files but no solution file was found at the following path: {GodotSharpDirs.ProjectSlnPath}\n" + - "A solution file is required for projects with C# files. Please ensure that the solution file exists in the specified location and try again."; + AddMessage(EditorExportPlatform.ExportMessageType.Error, "Export .NET Project", $"This project contains C# files but no solution file was found at the following path: {GodotSharpDirs.ProjectSlnPath}\n" + + "A solution file is required for projects with C# files. Please ensure that the solution file exists in the specified location and try again."); throw new InvalidOperationException($"{path} is a C# file but no solution file exists."); } @@ -124,16 +133,7 @@ public override void _ExportBegin(string[] features, bool isDebug, string path, } catch (Exception e) { - _maybeLastExportError = e.Message; - - // 'maybeLastExportError' cannot be null or empty if there was an error, so we - // must consider the possibility of exceptions being thrown without a message. - if (string.IsNullOrEmpty(_maybeLastExportError)) - _maybeLastExportError = $"Exception thrown: {e.GetType().Name}"; - - GD.PushError($"Failed to export project: {_maybeLastExportError}"); - Console.Error.WriteLine(e); - // TODO: Do something on error once _ExportBegin supports failing. + AddExceptionMessage(e); } } @@ -446,17 +446,6 @@ public override void _ExportEnd() Directory.Delete(folder, recursive: true); } _tempFolders.Clear(); - - // TODO: The following is just a workaround until the export plugins can be made to abort with errors - - // We check for empty as well, because it's set to empty after hot-reloading - if (!string.IsNullOrEmpty(_maybeLastExportError)) - { - string lastExportError = _maybeLastExportError; - _maybeLastExportError = null; - - GodotSharpEditor.Instance.ShowErrorDialog(lastExportError, "Failed to export C# project"); - } } private static bool DeterminePlatformFromFeatures(IEnumerable features, [NotNullWhen(true)] out string? platform)