Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ExportPlugin to add export messages; use in C# export plugin #90555

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/classes/EditorExportPlatform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@
</description>
</method>
</methods>
<constants>
<constant name="EXPORT_MESSAGE_NONE" value="0" enum="ExportMessageType">
Invalid message type used as the default value when no type is specified.
</constant>
<constant name="EXPORT_MESSAGE_INFO" value="1" enum="ExportMessageType">
Message type for informational messages that have no effect on the export.
</constant>
<constant name="EXPORT_MESSAGE_WARNING" value="2" enum="ExportMessageType">
Message type for warning messages that should be addressed but still allow to complete the export.
</constant>
<constant name="EXPORT_MESSAGE_ERROR" value="3" enum="ExportMessageType">
Message type for error messages that must be addressed and fail the export.
</constant>
</constants>
</class>
9 changes: 9 additions & 0 deletions doc/classes/EditorExportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@
[b]Note:[/b] This is useful only for macOS exports.
</description>
</method>
<method name="add_message" qualifiers="const">
<return type="void" />
<param index="0" name="type" type="int" enum="EditorExportPlatform.ExportMessageType" />
<param index="1" name="category" type="String" />
<param index="2" name="message" type="String" />
<description>
Adds a message to the export log that will be displayed when exporting ends.
</description>
</method>
<method name="add_shared_object">
<return type="void" />
<param index="0" name="path" type="String" />
Expand Down
7 changes: 6 additions & 1 deletion editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions editor/export/editor_export_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,6 @@ class EditorExportPlatform : public RefCounted {
EditorExportPlatform();
};

VARIANT_ENUM_CAST(EditorExportPlatform::ExportMessageType);

#endif // EDITOR_EXPORT_PLATFORM_H
5 changes: 5 additions & 0 deletions editor/export/editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Ref<EditorExportPreset> 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<uint8_t> &p_file, bool p_remap) {
ExtraFile ef;
ef.data = p_file;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions editor/export/editor_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class EditorExportPlugin : public RefCounted {
void set_export_preset(const Ref<EditorExportPreset> &p_preset);
Ref<EditorExportPreset> 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<uint8_t> &p_file, bool p_remap);
void add_shared_object(const String &p_path, const Vector<String> &tags, const String &p_target = String());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,6 @@ private static bool PublishProjectBlocking(BuildInfo buildInfo)
success = Publish(buildInfo);
}

if (!success)
{
ShowBuildErrorDialog("Failed to publish .NET project");
}

return success;
}

Expand Down
37 changes: 13 additions & 24 deletions modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.");
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<string> features, [NotNullWhen(true)] out string? platform)
Expand Down
Loading