Skip to content

Commit

Permalink
Add 'uet internal engine-checkout' command (#45)
Browse files Browse the repository at this point in the history
* Add internal engine-checkout command for syncing engine to a specific directory

* Set GIT_LFS_FORCE_PROGRESS=1 so we always get LFS progress
  • Loading branch information
hach-que authored Nov 14, 2024
1 parent 4fe5c17 commit 98fa2ff
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async Task<int> ExecuteNodesInWorkspaceAsync(string targetWorkspacePath)
AdditionalFolderZips = Array.Empty<string>(),
WorkspaceDisambiguators = nodeNames,
ProjectFolderName = buildSpecification.ProjectFolderName,
IsEngineBuild = false,
BuildType = GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<IWorkspace> GetEngineWorkspace(
AdditionalFolderZips = buildEngineSpecification._gitConsoleZips!,
WorkspaceDisambiguators = new[] { workspaceSuffix },
ProjectFolderName = null,
IsEngineBuild = buildEngineSpecification.IsEngineBuild,
BuildType = buildEngineSpecification.IsEngineBuild ? GitWorkspaceDescriptorBuildType.Engine : GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = buildEngineSpecification._gitSharedWindowsCachePath,
MacSharedGitCachePath = buildEngineSpecification._gitSharedMacCachePath,
},
Expand Down
10 changes: 5 additions & 5 deletions UET/Redpoint.Uet.Workspace.Tests/PhysicalGitCheckoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ await physicalGit.PrepareGitWorkspaceAsync(
AdditionalFolderLayers = Array.Empty<string>(),
AdditionalFolderZips = Array.Empty<string>(),
ProjectFolderName = "GMF",
IsEngineBuild = false,
BuildType = Descriptors.GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
},
Expand Down Expand Up @@ -124,7 +124,7 @@ await physicalGit.PrepareGitWorkspaceAsync(
AdditionalFolderLayers = Array.Empty<string>(),
AdditionalFolderZips = Array.Empty<string>(),
ProjectFolderName = "GMF",
IsEngineBuild = false,
BuildType = Descriptors.GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
},
Expand All @@ -146,7 +146,7 @@ await physicalGit.PrepareGitWorkspaceAsync(
AdditionalFolderLayers = Array.Empty<string>(),
AdditionalFolderZips = Array.Empty<string>(),
ProjectFolderName = "GMF",
IsEngineBuild = false,
BuildType = Descriptors.GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
},
Expand Down Expand Up @@ -215,7 +215,7 @@ await physicalGit.PrepareGitWorkspaceAsync(
AdditionalFolderLayers = Array.Empty<string>(),
AdditionalFolderZips = Array.Empty<string>(),
ProjectFolderName = "UET",
IsEngineBuild = false,
BuildType = Descriptors.GitWorkspaceDescriptorBuildType.Generic,
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
},
Expand Down Expand Up @@ -268,7 +268,7 @@ await physicalGit.PrepareGitWorkspaceAsync(
AdditionalFolderLayers = Array.Empty<string>(),
AdditionalFolderZips = Array.Empty<string>(),
ProjectFolderName = null,
IsEngineBuild = true,
BuildType = Descriptors.GitWorkspaceDescriptorBuildType.Engine,
WindowsSharedGitCachePath = sharedReservation.ReservedPath,
MacSharedGitCachePath = sharedReservation.ReservedPath,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public record class GitWorkspaceDescriptor : IWorkspaceDescriptor
/// </summary>
public string? ProjectFolderName { get; set; }

/// <summary>
/// If set, this is a checkout of the engine itself, instead of a project or plugin.
/// </summary>
public bool IsEngineBuild { get; set; }
public GitWorkspaceDescriptorBuildType BuildType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Redpoint.Uet.Workspace.Descriptors
{
public enum GitWorkspaceDescriptorBuildType
{
/// <summary>
/// This is a project or plugin build.
/// </summary>
Generic,

/// <summary>
/// This is a checkout of the engine itself, instead of a project or plugin, from the Unreal Engine GitHub repository where we need to run GitDeps and potentially copy console files.
/// </summary>
Engine,

/// <summary>
/// This is a checkout of the engine itself, where all the engine files have been stored in a Git repository with LFS (and there's no external console folders or GitDeps to run). This is the case if you externally sync Perforce into a Git repository with LFS.
/// </summary>
EngineLfs,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,8 @@ public async Task PrepareGitWorkspaceAsync(
Git = git,
GitEnvs = gitEnvs,
FetchEnvironmentVariablesFactory = fetchEnvironmentVariablesFactory,
EnableLfsSupport = !descriptor.IsEngineBuild,
EnableSubmoduleSupport = !descriptor.IsEngineBuild,
EnableLfsSupport = descriptor.BuildType != GitWorkspaceDescriptorBuildType.Engine,
EnableSubmoduleSupport = descriptor.BuildType == GitWorkspaceDescriptorBuildType.Generic,
};

// Initialize the Git repository if needed.
Expand Down Expand Up @@ -1555,7 +1555,7 @@ await CheckoutTargetCommitAsync(
cancellationToken).ConfigureAwait(false);

// Clean all Source, Config, Resources and Content folders so that we don't have stale files accidentally included in build steps.
if (!descriptor.IsEngineBuild)
if (descriptor.BuildType == GitWorkspaceDescriptorBuildType.Generic)
{
await CleanBuildSensitiveDirectoriesForProjectsAndPluginsAsync(
repositoryPath,
Expand All @@ -1580,7 +1580,7 @@ await CheckoutSubmoduleAsync(
}
}

if (descriptor.IsEngineBuild)
if (descriptor.BuildType == GitWorkspaceDescriptorBuildType.Engine)
{
// Copy our additional folder layers on top.
await ExtractAdditionalLayersToEngineWorkspaceAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public GitTemporaryEnvVarsForFetch(string privateKey)
{
{ "GIT_SSH_COMMAND", $@"ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -i {identityPath}" },
{ "GIT_ASK_YESNO", "false" },
{ "GIT_LFS_FORCE_PROGRESS", "1" },
};
}

Expand Down
75 changes: 75 additions & 0 deletions UET/uet/Commands/Internal/EngineCheckout/EngineCheckoutCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace UET.Commands.Internal.EngineCheckout
{
using Microsoft.Extensions.Logging;
using Redpoint.Uet.Workspace;
using Redpoint.Uet.Workspace.Descriptors;
using Redpoint.Uet.Workspace.PhysicalGit;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;

internal sealed class EngineCheckoutCommand
{
internal sealed class Options
{
public Option<string> Path;
public Option<string> RepositoryUri;
public Option<string> Branch;

public Options()
{
Path = new Option<string>("--path");
RepositoryUri = new Option<string>("--uri");
Branch = new Option<string>("--branch");
}
}

public static Command CreateEngineCheckoutCommand()
{
var options = new Options();
var command = new Command("engine-checkout");
command.AddAllOptions(options);
command.AddCommonHandler<EngineCheckoutCommandInstance>(options);
return command;
}

private sealed class EngineCheckoutCommandInstance : ICommandInstance
{
private readonly ILogger<EngineCheckoutCommandInstance> _logger;
private readonly IPhysicalGitCheckout _physicalGitCheckout;
private readonly Options _options;

public EngineCheckoutCommandInstance(
ILogger<EngineCheckoutCommandInstance> logger,
IPhysicalGitCheckout physicalGitCheckout,
Options options)
{
_logger = logger;
_physicalGitCheckout = physicalGitCheckout;
_options = options;
}

public async Task<int> ExecuteAsync(InvocationContext context)
{
Directory.CreateDirectory(context.ParseResult.GetValueForOption(_options.Path)!);

await _physicalGitCheckout.PrepareGitWorkspaceAsync(
context.ParseResult.GetValueForOption(_options.Path)!,
new GitWorkspaceDescriptor
{
RepositoryUrl = context.ParseResult.GetValueForOption(_options.RepositoryUri)!,
RepositoryCommitOrRef = context.ParseResult.GetValueForOption(_options.Branch)!,
AdditionalFolderLayers = [],
AdditionalFolderZips = [],
WorkspaceDisambiguators = [],
WindowsSharedGitCachePath = null,
MacSharedGitCachePath = null,
ProjectFolderName = null,
BuildType = GitWorkspaceDescriptorBuildType.EngineLfs,
},
context.GetCancellationToken()).ConfigureAwait(false);
return 0;
}
}
}
}
2 changes: 2 additions & 0 deletions UET/uet/Commands/Internal/InternalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using UET.Commands.Internal.UploadToBackblazeB2;
using UET.Commands.Internal.WakeOnLan;
using UET.Commands.Internal.TestUba;
using UET.Commands.Internal.EngineCheckout;

internal sealed class InternalCommand
{
Expand Down Expand Up @@ -63,6 +64,7 @@ public static Command CreateInternalCommand(HashSet<Command> globalCommands)
TestUbaCommand.CreateTestUbaCommand(),
RemoteZfsServerCommand.CreateRemoteZfsServerCommand(),
RemoteZfsTestCommand.CreateRemoteZfsTestCommand(),
EngineCheckoutCommand.CreateEngineCheckoutCommand(),
};

var command = new Command("internal", "Internal commands used by UET when it needs to call back into itself.");
Expand Down

0 comments on commit 98fa2ff

Please sign in to comment.