Skip to content

Commit f263397

Browse files
committed
building plugins for distribution for vanilla engine versions is working now
1 parent 0fb1229 commit f263397

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

src/Nuke.Unreal/Plugins/UnrealPlugin.cs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ namespace Nuke.Unreal.Plugins;
3737
/// <param name="UPluginAssociateEngineVersion">
3838
/// When set to true, distributing sources of plugins will write engine version to UPlugin file.
3939
/// </param>
40+
/// <param name="UPluginIsInstalled">
41+
/// Mark plugin as Installed when distributing. Default is true
42+
/// </param>
43+
/// <param name="UPluginConfig">
44+
/// Modify plugin descriptor for the distributed plugin after all other configuration is done.
45+
/// </param>
4046
public record class PluginDistributionOptions(
4147
RelativePath? OutputSubfolder = null,
4248
AbsolutePath? OutputOverride = null,
4349
bool GenerateFilterPluginIni = true,
44-
bool UPluginAssociateEngineVersion = true
50+
bool UPluginAssociateEngineVersion = true,
51+
bool UPluginIsInstalled = true,
52+
Func<PluginDescriptor, PluginDescriptor>? UPluginConfig = null
4553
);
4654

4755
/// <summary>
@@ -327,21 +335,21 @@ private IEnumerable<AbsolutePath> GetDefaultExplicitPluginFiles(UnrealBuild buil
327335
private void AddDefaultExplicitPluginFiles(UnrealBuild build)
328336
=> AddExplicitPluginFiles(GetDefaultExplicitPluginFiles(build));
329337

330-
private bool InjectBinaryPlumbing(out PluginDescriptor result)
338+
private bool InjectBinaryPlumbing(PluginDescriptor descriptor, out PluginDescriptor result)
331339
{
332340
var plumbingRootRelative = (RelativePath) "Source" / "ThirdParty" / "BinaryPlumbing";
333341
var plumbingRoot = Folder / plumbingRootRelative;
334342
if (!plumbingRoot.DirectoryExists())
335343
{
336-
result = Descriptor;
344+
result = descriptor;
337345
return false;
338346
}
339347

340348
Log.Information("{0} seemingly requires binary plumbing", Name);
341349
Log.Debug("Because {0} exists", plumbingRoot);
342350

343-
result = Descriptor with {
344-
PreBuildSteps = Descriptor.PreBuildSteps?.ToDictionary() ?? []
351+
result = descriptor with {
352+
PreBuildSteps = descriptor.PreBuildSteps?.ToDictionary() ?? []
345353
};
346354
result.PreBuildSteps.EnsureDevelopmentPlatforms();
347355

@@ -427,15 +435,29 @@ private bool InjectBinaryPlumbing(out PluginDescriptor result)
427435

428436
var outUPlugin = outFolder / PluginPath.Name;
429437

438+
var descriptor = Descriptor with {};
439+
430440
if (!pretend && options.UPluginAssociateEngineVersion)
431441
{
432-
Descriptor = Descriptor with { EngineVersion = Unreal.Version(build).VersionMinor };
433-
Unreal.WriteJson(Descriptor, outUPlugin);
442+
descriptor = descriptor with { EngineVersion = Unreal.Version(build).VersionMinor };
443+
Unreal.WriteJson(descriptor, outUPlugin);
434444
}
435445

436-
if (!pretend && InjectBinaryPlumbing(out var newDescriptor))
446+
if (!pretend && InjectBinaryPlumbing(descriptor, out descriptor))
447+
{
448+
Unreal.WriteJson(descriptor, outUPlugin);
449+
}
450+
451+
if (!pretend && options.UPluginIsInstalled)
452+
{
453+
descriptor = descriptor with { Installed = true };
454+
Unreal.WriteJson(descriptor, outUPlugin);
455+
}
456+
457+
if (!pretend && options.UPluginConfig != null)
437458
{
438-
Unreal.WriteJson(newDescriptor, outUPlugin);
459+
descriptor = options.UPluginConfig(descriptor);
460+
Unreal.WriteJson(descriptor, outUPlugin);
439461
}
440462

441463
return (result.WithFilesExpanded(), outFolder);
@@ -567,6 +589,7 @@ public AbsolutePath BuildPlugin(
567589
hostProjectDir.CreateDirectory();
568590
var hostPluginDir = hostProjectDir / "Plugins" / Name;
569591
var hostProject = new ProjectDescriptor(
592+
EngineAssociation: build.ProjectDescriptor.EngineAssociation,
570593
Plugins: [
571594
new (Name: Name, Enabled: true),
572595
..
@@ -579,15 +602,18 @@ public AbsolutePath BuildPlugin(
579602
Unreal.WriteJson(hostProject, hostProjectDir / "HostProject.uproject");
580603
sourceFolder.Copy(hostPluginDir);
581604

582-
var shortPluginDir = hostPluginDir.Shorten();
605+
var shortHostProjectDir = hostProjectDir.Shorten();
606+
var shortPluginDir = shortHostProjectDir / "Plugins" / Name;
583607
try
584608
{
585609
UbtConfig Common(UbtConfig _) => _
586-
.Plugin(shortPluginDir / PluginPath.Name)
587-
.NoUBTMakefiles()
610+
.Project(shortHostProjectDir / "HostProject.uproject")
611+
// .Plugin(shortPluginDir / PluginPath.Name) // this just breaks plugin distribution
612+
// .NoUBTMakefiles()
588613
.NoHotReload()
589614
.Apply(ubtConfig)
590-
.Apply(build.UbtGlobal);
615+
.Apply(build.UbtGlobal)
616+
;
591617

592618
foreach(var platform in platforms)
593619
{

0 commit comments

Comments
 (0)