Skip to content

Commit ace4529

Browse files
committed
Merge pull request godotengine#96335 from raulsntos/dotnet/export-plugin
C#: Use export platform to determine the target OS and log errors
2 parents 6489013 + 4c14421 commit ace4529

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,6 @@ private static bool PublishProjectBlocking(BuildInfo buildInfo)
265265
success = Publish(buildInfo);
266266
}
267267

268-
if (!success)
269-
{
270-
ShowBuildErrorDialog("Failed to publish .NET project");
271-
}
272-
273268
return success;
274269
}
275270

modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,19 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool
7575
};
7676
}
7777

78-
private string? _maybeLastExportError;
78+
private void AddExceptionMessage(EditorExportPlatform platform, Exception exception)
79+
{
80+
string? exceptionMessage = exception.Message;
81+
if (string.IsNullOrEmpty(exceptionMessage))
82+
{
83+
exceptionMessage = $"Exception thrown: {exception.GetType().Name}";
84+
}
85+
86+
platform.AddMessage(EditorExportPlatform.ExportMessageType.Error, "Export .NET Project", exceptionMessage);
87+
88+
// We also print exceptions as we receive them to stderr.
89+
Console.Error.WriteLine(exception);
90+
}
7991

8092
// With this method we can override how a file is exported in the PCK
8193
public override void _ExportFile(string path, string type, string[] features)
@@ -92,8 +104,8 @@ public override void _ExportFile(string path, string type, string[] features)
92104

93105
if (!ProjectContainsDotNet())
94106
{
95-
_maybeLastExportError = $"This project contains C# files but no solution file was found at the following path: {GodotSharpDirs.ProjectSlnPath}\n" +
96-
"A solution file is required for projects with C# files. Please ensure that the solution file exists in the specified location and try again.";
107+
GetExportPlatform().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" +
108+
"A solution file is required for projects with C# files. Please ensure that the solution file exists in the specified location and try again.");
97109
throw new InvalidOperationException($"{path} is a C# file but no solution file exists.");
98110
}
99111

@@ -124,16 +136,7 @@ public override void _ExportBegin(string[] features, bool isDebug, string path,
124136
}
125137
catch (Exception e)
126138
{
127-
_maybeLastExportError = e.Message;
128-
129-
// 'maybeLastExportError' cannot be null or empty if there was an error, so we
130-
// must consider the possibility of exceptions being thrown without a message.
131-
if (string.IsNullOrEmpty(_maybeLastExportError))
132-
_maybeLastExportError = $"Exception thrown: {e.GetType().Name}";
133-
134-
GD.PushError($"Failed to export project: {_maybeLastExportError}");
135-
Console.Error.WriteLine(e);
136-
// TODO: Do something on error once _ExportBegin supports failing.
139+
AddExceptionMessage(GetExportPlatform(), e);
137140
}
138141
}
139142

@@ -144,7 +147,9 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
144147
if (!ProjectContainsDotNet())
145148
return;
146149

147-
if (!DeterminePlatformFromFeatures(features, out string? platform))
150+
string osName = GetExportPlatform().GetOsName();
151+
152+
if (!TryDeterminePlatformFromOSName(osName, out string? platform))
148153
throw new NotSupportedException("Target platform not supported.");
149154

150155
if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS, OS.Platforms.Android, OS.Platforms.iOS }
@@ -445,25 +450,22 @@ public override void _ExportEnd()
445450
Directory.Delete(folder, recursive: true);
446451
}
447452
_tempFolders.Clear();
448-
449-
// TODO: The following is just a workaround until the export plugins can be made to abort with errors
450-
451-
// We check for empty as well, because it's set to empty after hot-reloading
452-
if (!string.IsNullOrEmpty(_maybeLastExportError))
453-
{
454-
string lastExportError = _maybeLastExportError;
455-
_maybeLastExportError = null;
456-
457-
GodotSharpEditor.Instance.ShowErrorDialog(lastExportError, "Failed to export C# project");
458-
}
459453
}
460454

461-
private static bool DeterminePlatformFromFeatures(IEnumerable<string> features, [NotNullWhen(true)] out string? platform)
455+
/// <summary>
456+
/// Tries to determine the platform from the export preset's platform OS name.
457+
/// </summary>
458+
/// <param name="osName">Name of the export operating system.</param>
459+
/// <param name="platform">Platform name for the recognized supported platform.</param>
460+
/// <returns>
461+
/// <see langword="true"/> when the platform OS name is recognized as a supported platform,
462+
/// <see langword="false"/> otherwise.
463+
/// </returns>
464+
private static bool TryDeterminePlatformFromOSName(string osName, [NotNullWhen(true)] out string? platform)
462465
{
463-
foreach (var feature in features)
466+
if (OS.PlatformFeatureMap.TryGetValue(osName, out platform))
464467
{
465-
if (OS.PlatformFeatureMap.TryGetValue(feature, out platform))
466-
return true;
468+
return true;
467469
}
468470

469471
platform = null;

0 commit comments

Comments
 (0)