Skip to content

Commit

Permalink
Fix null reference exception when generating engine project files (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que authored Nov 11, 2024
1 parent 260f20c commit 5d83914
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions UET/uet/Commands/Generate/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -137,25 +138,40 @@ private static IEnumerable<DirectoryInfo> DiscoverAutomationProjectDirectories(D
}
}

private static bool IsGeneratingEngineFiles(EngineSpec engine, PathSpec[] paths, OptionResult? pathResult)
{
var isEngineSourceInThisDirectory =
engine.Type == EngineSpecType.Path &&
string.Equals(engine.Path, Environment.CurrentDirectory, StringComparison.OrdinalIgnoreCase) &&
!File.Exists(Path.Combine(engine.Path!, "Engine", "Build", "InstalledBuild.txt"));
if (isEngineSourceInThisDirectory)
{
return true;
}

var isNonSinglePath = paths.Length != 1;
if (isNonSinglePath)
{
return true;
}

return false;
}

public async Task<int> ExecuteAsync(InvocationContext context)
{
var engine = context.ParseResult.GetValueForOption(_options.Engine)!;
var paths = context.ParseResult.GetValueForOption(_options.Path) ?? Array.Empty<PathSpec>();
var paths = context.ParseResult.GetValueForOption(_options.Path) ?? [];
var open = context.ParseResult.GetValueForOption(_options.Open);
var automationPaths = context.ParseResult.GetValueForOption(_options.AutomationPath) ?? Array.Empty<DirectoryInfo>();
var automationPaths = context.ParseResult.GetValueForOption(_options.AutomationPath) ?? [];

// Compute how to invoke project generation.
string workingDirectory;
string outputFolder;
string outputFilenameWithoutExtension;
string scriptName;
var arguments = new List<string>();
if ((engine.Type == EngineSpecType.Path &&
string.Equals(engine.Path, Environment.CurrentDirectory, StringComparison.OrdinalIgnoreCase) &&
!File.Exists(Path.Combine(engine.Path!, "Engine", "Build", "InstalledBuild.txt"))) ||
paths.Length != 1 ||
((context.ParseResult.FindResultFor(_options.Path)?.Tokens?.Count ?? 0) == 0 &&
paths.First().Type != PathSpecType.UProject))
if (IsGeneratingEngineFiles(engine, paths, context.ParseResult.FindResultFor(_options.Path)))
{
// We want to generate project files for an engine.
var installedBuild = Path.Combine(engine.Path!, "Engine", "Build", "InstalledBuild.txt");
Expand Down Expand Up @@ -246,7 +262,7 @@ public async Task<int> ExecuteAsync(InvocationContext context)
uprojectDirs,
projectLines);
}
else
else if (paths.Length == 1)
{
arguments.Add($"-project={paths[0].UProjectPath}");
}
Expand Down

0 comments on commit 5d83914

Please sign in to comment.