Editgrated latest SyncProject script from FN as part of UE-78832, UE-78826, and resolved issues with omitted / dangerous arguments.

Project arg is now optional and will simply sync the engine.
Passing -CL=0 will now require the -force argument before syncing files out of the workspace.
Fixed issue with deep samples (e.g AREnvProbe) not being discovered by FindProjectFileFromName
Added NativeProjects.ClearCache option for the case when syncing a project from P4 that isn't yet on disk

Fixed issue with P4.FileExistsInDepot returning true if passed a path that isn't in the users client view. Relates to UE-78832 but not the entire fix
Fixed issue with BuildEditor not working without a project arg.
Fixed issue building projects that don't have source

[CODEREVIEW] ben.marsh
#jira UE-78832, UE-78826
#rb na

#ROBOMERGE-OWNER: ben.marsh
#ROBOMERGE-AUTHOR: andrew.grant
#ROBOMERGE-SOURCE: CL 8008332 in //UE4/Release-4.23/... via CL 8008726
#ROBOMERGE-BOT: BUILD (Main -> Dev-Build) (v399-8035122)

[CL 8048144 by andrew grant in Dev-Build branch]
This commit is contained in:
andrew grant
2019-08-14 23:01:07 -04:00
5 changed files with 191 additions and 106 deletions

View File

@@ -3059,6 +3059,7 @@ namespace AutomationTool
string Output;
if(!LogP4Output(out Output, CommandLine, AllowSpew: false) || !Output.Contains("headRev"))
{
return false;
}

View File

@@ -653,33 +653,69 @@ namespace AutomationTool
/// <returns></returns>
public static FileReference FindProjectFileFromName(string GameName)
{
// if they passed in a path then easy.
if (File.Exists(GameName))
{
return new FileReference(GameName);
}
// Start with the gamename regardless of what they passed in
GameName = Path.GetFileNameWithoutExtension(GameName);
// Turn Foo into Foo.uproject
string ProjectFile = GameName;
// Look for GameName.uproject
if (string.IsNullOrEmpty(Path.GetExtension(ProjectFile)))
{
// if project was specified but had no extension then just add it.
ProjectFile = Path.ChangeExtension(GameName, ".uproject");
}
// easy!
// Turn Foo.uproject into Foo/Foo.uproject
ProjectFile = Path.Combine(GameName, ProjectFile);
GameName = Path.GetFileNameWithoutExtension(GameName);
// check for sibling to engine
if (File.Exists(ProjectFile))
{
return new FileReference(ProjectFile);
}
// check for sibling to engine
string SiblingPath = Path.Combine(Environment.CurrentDirectory, GameName, ProjectFile);
if (File.Exists(SiblingPath))
{
return new FileReference(SiblingPath);
}
// check projectfiles paths.
// Search NativeProjects (sibling folders).
IEnumerable<FileReference> Projects = NativeProjects.EnumerateProjectFiles();
FileReference ProjectPath = Projects.Where(R => string.Equals(R.GetFileName(), ProjectFile, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (ProjectPath == null)
{
// read .uprojectdirs
List<string> SearchPaths = new List<string>();
SearchPaths.Add("");
string ProjectDirsFile = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.uprojectdirs").FirstOrDefault();
if (ProjectDirsFile != null)
{
foreach (string FilePath in File.ReadAllLines(ProjectDirsFile))
{
string Trimmed = FilePath.Trim();
if (!Trimmed.StartsWith("./", StringComparison.OrdinalIgnoreCase) &&
!Trimmed.StartsWith(";", StringComparison.OrdinalIgnoreCase) &&
Trimmed.IndexOfAny(Path.GetInvalidPathChars()) < 0)
{
SearchPaths.Add(Trimmed);
}
}
string ResolvedFile = SearchPaths.Select(P => Path.Combine(P, ProjectFile))
.Where(P => File.Exists(P))
.FirstOrDefault();
if (ResolvedFile != null)
{
ProjectPath = new FileReference(ResolvedFile);
}
}
}
// either valid or we're out of ideas...
return ProjectPath;

View File

@@ -44,8 +44,6 @@ namespace AutomationTool
public override ExitCode Execute()
{
FileReference ProjectFile = null;
string[] Arguments = this.Params;
ProjectName = ParseParamValue("project", ProjectName);
@@ -95,11 +93,9 @@ namespace AutomationTool
return ExitCode.Error_Arguments;
}
if (String.IsNullOrEmpty(ProjectName))
{
Log.TraceWarning("No project specified, will build vanilla UE4 binaries");
}
else
FileReference ProjectFile = null;
if (!string.IsNullOrEmpty(ProjectName))
{
ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);
@@ -110,30 +106,46 @@ namespace AutomationTool
string SourceDirectoryName = Path.Combine(ProjectFile.Directory.FullName, "Source");
IEnumerable<string> TargetScripts = Directory.EnumerateFiles(SourceDirectoryName, "*.Target.cs");
if (Directory.Exists(SourceDirectoryName))
{
IEnumerable<string> TargetScripts = Directory.EnumerateFiles(SourceDirectoryName, "*.Target.cs");
foreach (string TargetName in TargetList)
{
string TargetScript = TargetScripts.Where(S => S.IndexOf(TargetName, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
if (TargetScript == null && (
TargetName.Equals("Client", StringComparison.OrdinalIgnoreCase) ||
TargetName.Equals("Game", StringComparison.OrdinalIgnoreCase)
)
)
{
// if there's no ProjectGame.Target.cs or ProjectClient.Target.cs then
// fallback to Project.Target.cs
TargetScript = TargetScripts.Where(S => S.IndexOf(ProjectName + ".", StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
}
if (TargetScript == null)
{
throw new AutomationException("No Target.cs file for target {0} in project {1}", TargetName, ProjectName);
}
string FullName = Path.GetFileName(TargetScript);
TargetNames[TargetName] = Regex.Replace(FullName, ".Target.cs", "", RegexOptions.IgnoreCase);
}
}
}
else
{
Log.TraceWarning("No project specified, will build vanilla UE4 binaries");
}
// Handle content-only projects or when no project was specified
if (TargetNames.Keys.Count == 0)
{
foreach (string TargetName in TargetList)
{
string TargetScript = TargetScripts.Where(S => S.IndexOf(TargetName, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
if (TargetScript == null && (
TargetName.Equals("Client", StringComparison.OrdinalIgnoreCase) ||
TargetName.Equals("Game", StringComparison.OrdinalIgnoreCase)
)
)
{
// if there's no ProjectGame.Target.cs or ProjectClient.Target.cs then
// fallback to Project.Target.cs
TargetScript = TargetScripts.Where(S => S.IndexOf(ProjectName + ".", StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
}
if (TargetScript == null)
{
throw new AutomationException("No Target.cs file for target {0} in project {1}", TargetName, ProjectName);
}
string FullName = Path.GetFileName(TargetScript);
TargetNames[TargetName] = Regex.Replace(FullName, ".Target.cs", "", RegexOptions.IgnoreCase);
TargetNames[TargetName] = string.Format("UE4{0}", TargetName);
}
}

View File

@@ -12,17 +12,18 @@ using System.Text.RegularExpressions;
[Help("Syncs and builds all the binaries required for a project")]
[Help("project=<FortniteGame>", "Project to sync. Will search current path and paths in ueprojectdirs. If omitted will sync projectdirs")]
[Help("threads=N", "How many threads to use when syncing. Default=2. When >1 all output happens first")]
[Help("cl=< 12345 >", "Changelist to sync to. If omitted will sync to latest CL of the workspace path")]
[Help("cl=<12345>", "Changelist to sync to. If omitted will sync to latest CL of the workspace path. 0 Will Remove files!")]
[Help("clean", "Clean old files before building")]
[Help("build", "Build after syncing")]
[Help("open", "Open project editor after syncing")]
[Help("generate", "Generate project files after syncing")]
[Help("force", "force sync files (files opened for edit will be untouched)")]
[Help("preview", "Shows commands that will be executed but performs no operations")]
[Help("projectonly", "Only shync the project")]
[Help("maxwait=n", "Maximum wait time for a file. Defaults to 0 (disabled).")]
[Help("projectonly", "Only sync the project")]
[Help("paths", "Only sync this path. Can be comma-separated list.")]
[Help("retries=n", "Number of retries for a timed out file. Defaults to 3")]
[Help("unversioned", "Do not set an engine version after syncing")]
[Help("path", "Only sync files that match this path. Can be comma-separated list.")]
[RequireP4]
[DoesNotNeedP4CL]
class SyncProject : BuildCommand
@@ -38,23 +39,31 @@ class SyncProject : BuildCommand
"Engine/Source/Programs/DotNETCommon/MetaData.cs"
};
// Parse the project filename (as a local path)
string ProjectArg = ParseParamValue("Project", null);
// Parse the changelist to sync to. -1 will sync to head.
int CL = ParseParamInt("CL", -1);
int Threads = ParseParamInt("threads", 2);
bool ForceSync = ParseParam("force");
bool PreviewOnly = ParseParam("preview");
bool ProjectOnly = ParseParam("projectonly");
int MaxWait = ParseParamInt("maxwait", 0);
int Retries = ParseParamInt("retries", 3);
bool Unversioned = ParseParam("unversioned");
bool BuildProject = ParseParam("build");
bool OpenProject = ParseParam("open");
bool GenerateProject = ParseParam("generate");
string PathArg = ParseParamValue("paths", "");
if (CL == 0)
IEnumerable<string> ExplicitPaths = PathArg.Split(new char[] { ',',';' }, StringSplitOptions.RemoveEmptyEntries).Select(S => S.Trim());
if (CL == 0 && !ForceSync)
{
throw new AutomationException("If specified CL must be a number. Omit -CL for latest.");
throw new AutomationException("If using 0 CL to remove files -force must also be specified (and you may also want -projectonly)");
}
else if (CL == -1)
{
@@ -70,19 +79,21 @@ class SyncProject : BuildCommand
CL = Records.First().CL;
}
// Parse the project filename (as a local path)
string ProjectName = ParseParamValue("Project", null);
bool EngineOnly = string.IsNullOrEmpty(ProjectArg);
// this will be the path to the project in P4, if one is specified
// Will be the full local path to the project file once resolved
FileReference ProjectFile = null;
// Will be the full workspace path to the project in P4 (if a project was specified)
string P4ProjectPath = null;
if (!string.IsNullOrEmpty(ProjectName))
{
// We want to find the Perforce path to the project so we can sync this even if it doesn't
// exist locally
// Will be the full workspace path to the engine in P4 (If projectonly wasn't specified);
string P4EnginePath = null;
// First try to find a local file that exists
FileReference ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);
// If we're syncing a project find where it is in P4
if (!EngineOnly)
{
ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectArg);
if (ProjectFile != null)
{
@@ -92,38 +103,26 @@ class SyncProject : BuildCommand
}
else
{
// Couldn't be find locally, so try to find where it is in P4 by checking workspace root and uproject dirs
// ok, check P4...
string RelativePath = ProjectName;
// if they provided a name and not a path then find the file (requires that it's synced).
string RelativePath = ProjectArg;
// Change EngineTest into EngineTest.uproject
if (Path.GetExtension(RelativePath).Length == 0)
{
RelativePath = Path.ChangeExtension(RelativePath, "uproject");
}
// Change EngineTest.uproject into EngineTest/EngineTest.uproject
if (!RelativePath.Contains(Path.DirectorySeparatorChar) && !RelativePath.Contains(Path.AltDirectorySeparatorChar))
{
RelativePath = CommandUtils.CombinePaths(PathSeparator.Slash, Path.GetFileNameWithoutExtension(RelativePath), RelativePath);
}
// the calls to P4.FileExists will outout text regardless of spew setting so tell
// people why the are going to see these...
Log.TraceInformation("{0} not on disk. Searching P4 for {1}", ProjectName, RelativePath);
Log.TraceInformation("{0} not on disk. Searching P4 for {1}", ProjectArg, RelativePath);
List<string> SearchPaths = new List<string>();
// Search workspace root
SearchPaths.Add("");
// now check uproject dirs
string ProjectDirsFile = Directory.EnumerateFiles(CommandUtils.CombinePaths(CmdEnv.LocalRoot), "*.uprojectdirs").FirstOrDefault();
if (ProjectDirsFile != null)
{
// read the project dirs file, removing anything invalid and the cur-path entry
// we add ourselves
foreach (string FilePath in File.ReadAllLines(ProjectDirsFile))
{
string Trimmed = FilePath.Trim();
@@ -136,7 +135,7 @@ class SyncProject : BuildCommand
}
}
// now check P4
// Get the root of the branch containing the selected file
foreach (string SearchPath in SearchPaths)
{
string P4Path = CommandUtils.CombinePaths(PathSeparator.Slash, P4Env.ClientRoot, SearchPath, RelativePath);
@@ -149,42 +148,51 @@ class SyncProject : BuildCommand
break;
}
}
if (string.IsNullOrEmpty(P4ProjectPath))
{
throw new AutomationException("Could not find project file for {0} locally or in P4. Provide a full path or check the subdirectory is listed in UE4Games.uprojectdirs", ProjectName);
}
}
if (string.IsNullOrEmpty(P4ProjectPath))
{
throw new AutomationException("Could not find project file for {0} locally or in P4. Provide a full path or check the subdirectory is listed in UE4Games.uprojectdirs", ProjectArg);
}
Log.TraceVerbose("Resolved {0} to P4 Path {1}", ProjectArg, P4ProjectPath);
}
// Build the list of paths that need syncing
List<string> SyncPaths = new List<string>();
// See if the engine is in P4 too by checking the p4 location of a local file
string LocalEngineFile = CommandUtils.CombinePaths(CmdEnv.LocalRoot, "Engine", "Source", "UE4Editor.target.cs");
P4WhereRecord EngineRecord = P4.Where(LocalEngineFile, AllowSpew: false).FirstOrDefault(x => x.DepotFile != null && !x.bUnmap);
string P4EngineLocation = null;
// add engine files if they exist
if (!ProjectOnly && P4.FileExistsInDepot(EngineRecord.DepotFile))
//
if (ExplicitPaths.Any())
{
P4EngineLocation = EngineRecord.DepotFile.Replace("Engine/Source/UE4Editor.target.cs", "");
SyncPaths.Add(CommandUtils.CombinePaths(PathSeparator.Slash, P4EngineLocation + "*"));
SyncPaths.Add(CommandUtils.CombinePaths(PathSeparator.Slash, P4EngineLocation, "Engine", "..."));
// Add all explicit paths as <root>/Path/...
ExplicitPaths.ToList().ForEach(P => SyncPaths.Add(CommandUtils.CombinePaths(PathSeparator.Slash, P4Env.ClientRoot, P, "...")));
}
// add project file if any
if (!string.IsNullOrEmpty(P4ProjectPath))
else
{
string P4ProjectDir = Regex.Replace(P4ProjectPath, @"[^/]+\.uproject", "...", RegexOptions.IgnoreCase);
SyncPaths.Add(P4ProjectDir);
}
// See if the engine is in P4 too by checking the p4 location of a local file
string LocalEngineFile = CommandUtils.CombinePaths(CmdEnv.LocalRoot, "Engine", "Source", "UE4Editor.target.cs");
P4WhereRecord EngineRecord = P4.Where(LocalEngineFile, AllowSpew: false).FirstOrDefault(x => x.DepotFile != null && !x.bUnmap);
if (!ProjectOnly && P4.FileExistsInDepot(EngineRecord.DepotFile))
{
P4EnginePath = EngineRecord.DepotFile.Replace("Engine/Source/UE4Editor.target.cs", "");
SyncPaths.Add(CommandUtils.CombinePaths(PathSeparator.Slash, P4EnginePath + "*"));
SyncPaths.Add(CommandUtils.CombinePaths(PathSeparator.Slash, P4EnginePath, "Engine", "..."));
}
if (!string.IsNullOrEmpty(P4ProjectPath))
{
string P4ProjectDir = Regex.Replace(P4ProjectPath, @"[^/]+\.uproject", "...", RegexOptions.IgnoreCase);
SyncPaths.Add(P4ProjectDir);
}
}
// Force these files as they can be overwritten by tools
if (!PreviewOnly && !string.IsNullOrEmpty(P4EngineLocation))
if (!PreviewOnly && !string.IsNullOrEmpty(P4EnginePath) && !ProjectOnly)
{
IEnumerable<string> ForceSyncList = ForceSyncFiles.Select(F => CommandUtils.CombinePaths(PathSeparator.Slash, P4EngineLocation, F));
IEnumerable<string> ForceSyncList = ForceSyncFiles.Select(F => CommandUtils.CombinePaths(PathSeparator.Slash, P4EnginePath, F));
foreach (var F in ForceSyncList)
{
@@ -193,7 +201,7 @@ class SyncProject : BuildCommand
string SyncCommand = string.Format("-f {0}@{1}", F, CL);
// sync with retries
P4.Sync(SyncCommand, true, false, Retries, MaxWait);
P4.Sync(SyncCommand, true, false, Retries);
}
}
@@ -217,7 +225,7 @@ class SyncProject : BuildCommand
if (!PreviewOnly)
{
// sync with retries
P4.Sync(SyncCommand, true, false, Retries, MaxWait);
P4.Sync(SyncCommand, true, false, Retries);
}
else
{
@@ -225,30 +233,44 @@ class SyncProject : BuildCommand
}
}
// P4 utils don't return errors :(
ExitCode ExitStatus = ExitCode.Success;
if (!PreviewOnly)
// Sync is complete so do the actions
if (!PreviewOnly && CL > 0)
{
// Get a reference to the project file
FileReference ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);
// Argument to pass to the editor (could be null with no project).
string ProjectArgForEditor = "";
if (!string.IsNullOrEmpty(ProjectArg))
{
// If we synced the project from P4 we couldn't resolve this earlier
if (ProjectFile == null)
{
NativeProjects.ClearCache();
ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectArg);
}
ProjectArgForEditor = ProjectFile.FullName;
}
if (GenerateProject)
{
// generate project files.
Log.TraceVerbose("Generating project files for {0}", ProjectArgForEditor);
if (BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Win64 ||
BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Win32)
{
CommandUtils.Run("GenerateProjectFiles.bat", ProjectFile.FullName);
CommandUtils.Run("GenerateProjectFiles.bat", ProjectArgForEditor);
}
else
{
CommandUtils.Run("GenerateProjectFiles.sh", ProjectFile.FullName);
CommandUtils.Run("GenerateProjectFiles.sh", ProjectArgForEditor);
}
}
UE4Build Build = new UE4Build(this);
if (!Unversioned)
if (!Unversioned && !ProjectOnly)
{
Build.UpdateVersionFiles(ActuallyUpdateVersionFiles: true, ChangelistNumberOverride: CL, IsPromotedOverride: false);
}
@@ -256,16 +278,20 @@ class SyncProject : BuildCommand
// Build everything
if (BuildProject && ExitStatus == ExitCode.Success)
{
Log.TraceVerbose("Building Editor for {0}", ProjectArgForEditor);
BuildEditor BuildCmd = new BuildEditor();
BuildCmd.Clean = ParseParam("clean");
BuildCmd.ProjectName = ProjectName;
BuildCmd.ProjectName = ProjectArgForEditor;
ExitStatus = BuildCmd.Execute();
}
if (OpenProject && ExitStatus == ExitCode.Success)
{
Log.TraceVerbose("Opening Editor for {0}", ProjectArgForEditor);
OpenEditor OpenCmd = new OpenEditor();
OpenCmd.ProjectName = ProjectName;
OpenCmd.ProjectName = ProjectArgForEditor;
ExitStatus = OpenCmd.Execute();
}

View File

@@ -35,6 +35,16 @@ namespace UnrealBuildTool
/// </summary>
static Dictionary<string, FileReference> CachedTargetNameToProjectFile;
/// <summary>
/// Clear our cached properties. Generally only needed if your script has modified local files...
/// </summary>
public static void ClearCache()
{
CachedBaseDirectories = null;
CachedProjectFiles = null;
CachedTargetNameToProjectFile = null;
}
/// <summary>
/// Retrieve the list of base directories for native projects
/// </summary>