private static bool FindBestSharedCookedBuild(ref string FinalCookedBuildPath, string ProjectFullPath, UnrealTargetPlatform TargetPlatform, string CookPlatform, string SharedCookedBuildCL)
    {
        string BuildRoot    = CommandUtils.P4Enabled ? CommandUtils.P4Env.Branch.Replace("/", "+") : "";
        int    CurrentCLInt = CommandUtils.P4Enabled ? CommandUtils.P4Env.Changelist : 0;

        BuildVersion Version;

        if (BuildVersion.TryRead(BuildVersion.GetDefaultFileName(), out Version))
        {
            CurrentCLInt = Version.Changelist;
            BuildRoot    = Version.BranchName;
        }
        System.GC.Collect();
        string CurrentCL = CurrentCLInt.ToString();


        FileReference ProjectFileRef = new FileReference(ProjectFullPath);
        // get network location
        ConfigHierarchy Hierarchy = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirectoryReference.FromFile(ProjectFileRef), TargetPlatform);
        List <string>   CookedBuildPaths;

        if (Hierarchy.GetArray("SharedCookedBuildSettings", "SharedCookedBuildPath", out CookedBuildPaths) == false)
        {
            CommandUtils.LogInformation("Unable to copy shared cooked build: SharedCookedBuildPath not set in Engine.ini SharedCookedBuildSettings");
            return(false);
        }

        const string MetaDataFilename = "\\Metadata\\DevelopmentAssetRegistry.bin";


        if (SharedCookedBuildCL == "usesyncedbuild")
        {
            foreach (string CookedBuildPath in CookedBuildPaths)
            {
                if (CurrentCL == "" && FinalCookedBuildPath.Contains("[CL]"))
                {
                    CommandUtils.LogInformation("Unable to copy shared cooked build: Unable to determine CL number from P4 or UGS, and is required by SharedCookedBuildPath");
                    return(false);
                }

                if (CurrentCL == "" && FinalCookedBuildPath.Contains("[BRANCHNAME]"))
                {
                    CommandUtils.LogInformation("Unable to copy shared cooked build: Unable to determine BRANCHNAME number from P4 or UGS, and is required by SharedCookedBuildPath");
                    return(false);
                }


                FinalCookedBuildPath = FinalCookedBuildPath.Replace("[CL]", CurrentCL.ToString());
                FinalCookedBuildPath = FinalCookedBuildPath.Replace("[BRANCHNAME]", BuildRoot);
                FinalCookedBuildPath = FinalCookedBuildPath.Replace("[PLATFORM]", CookPlatform);

                // make sure that the directory and metadata file exist.  otherwise this build might not be finished yet and we should skip it
                if (Directory.Exists(FinalCookedBuildPath))
                {
                    if (File.Exists(FinalCookedBuildPath + MetaDataFilename))
                    {
                        return(true);
                    }
                }
            }
        }
        else if (SharedCookedBuildCL == "userecentbuild")
        {
            // build our CookedBUildPath into a regex which we can execute on the directories and extract info from



            string BestBuild    = null;
            int    BestCLNumber = 0;

            // find all the recent builds which are valid
            foreach (string CookedBuildPath in CookedBuildPaths)
            {
                int IndexOfFirstParam = CookedBuildPath.IndexOf("[");
                int CustomFolderStart = CookedBuildPath.LastIndexOf("\\", IndexOfFirstParam);

                string CookedBuildDirectory = CookedBuildPath.Substring(0, CustomFolderStart);

                string BuildNameWildcard = CookedBuildPath.Substring(CustomFolderStart);


                BuildNameWildcard += MetaDataFilename;

                FileFilter BuildSearch = new FileFilter();

                // we know the platform and the branch name;
                string BuildRule = BuildNameWildcard;
                BuildRule = BuildRule.Replace("[BRANCHNAME]", BuildRoot);
                BuildRule = BuildRule.Replace("[PLATFORM]", CookPlatform);

                string IncludeRule = BuildRule.Replace("[CL]", "*");
                string ForgetRule  = BuildRule.Replace("[CL]", "*-PF-*");                // get rid of any preflights from the list... they don't count because who knows what they did...

                BuildSearch.AddRule(IncludeRule);
                BuildSearch.AddRule(ForgetRule, FileFilterType.Exclude);

                List <FileReference> ValidBuilds = BuildSearch.ApplyToDirectory(new DirectoryReference(CookedBuildDirectory), false);

                // figure out what the CL is
                string BuildNameRegex = String.Format(".*{0}", CookedBuildPath.Substring(CustomFolderStart));
                BuildNameRegex = BuildNameRegex.Replace("\\", "\\\\");
                BuildNameRegex = BuildNameRegex.Replace("[BRANCHNAME]", BuildRoot);
                BuildNameRegex = BuildNameRegex.Replace("+", "\\+");
                BuildNameRegex = BuildNameRegex.Replace("[PLATFORM]", CookPlatform);
                BuildNameRegex = BuildNameRegex.Replace("[CL]", "(?<CL>.*)");

                Regex ExtractCL = new Regex(BuildNameRegex);

                foreach (FileReference ValidBuild in ValidBuilds)
                {
                    string BuildPath = ValidBuild.FullName.Replace(MetaDataFilename, "");

                    Match CLMatch = ExtractCL.Match(BuildPath);
                    if (CLMatch != null)
                    {
                        string CLNumber    = CLMatch.Result("${CL}");
                        int    CLNumberInt = int.Parse(CLNumber);
                        if (CLNumberInt <= CurrentCLInt)
                        {
                            if (CLNumberInt > BestCLNumber)
                            {
                                BestCLNumber = CLNumberInt;
                                BestBuild    = BuildPath;
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(BestBuild))
            {
                return(false);
            }

            FinalCookedBuildPath = BestBuild;
            return(true);
        }


        return(false);
    }
Exemple #2
0
    static void CopySharedCookedBuildForTarget(ProjectParams Params, TargetPlatformDescriptor TargetPlatform, string CookPlatform)
    {
        string ProjectPath = Params.RawProjectPath.FullName;
        var    LocalPath   = CombinePaths(GetDirectoryName(ProjectPath), "Saved", "SharedIterativeBuild", CookPlatform);

        // get network location
        ConfigHierarchy Hierarchy = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirectoryReference.FromFile(Params.RawProjectPath), TargetPlatform.Type);
        string          CookedBuildPath;

        if (Hierarchy.GetString("SharedCookedBuildSettings", "SharedCookedBuildPath", out CookedBuildPath) == false)
        {
            Log("Unable to copy shared cooked build: SharedCookedBuildPath not set in Engine.ini SharedCookedBuildSettings");
            return;
        }

        string BuildRoot = P4Enabled ? P4Env.BuildRootP4.Replace("/", "+") : "";
        int    RecentCL  = P4Enabled ? P4Env.Changelist : 0;

        BuildVersion Version;

        if (BuildVersion.TryRead(out Version))
        {
            RecentCL  = Version.Changelist;
            BuildRoot = Version.BranchName;
        }

        // check to see if we have already synced this build ;)
        var    SyncedBuildFile = CombinePaths(LocalPath, "SyncedBuild.txt");
        string BuildCL         = "Invalid";

        if (File.Exists(SyncedBuildFile))
        {
            BuildCL = File.ReadAllText(SyncedBuildFile);
        }

        if (RecentCL == 0 && CookedBuildPath.Contains("[CL]"))
        {
            Log("Unable to copy shared cooked build: Unable to determine CL number from P4 or UGS, and is required by SharedCookedBuildPath");
            return;
        }

        if (RecentCL == 0 && CookedBuildPath.Contains("[BRANCHNAME]"))
        {
            Log("Unable to copy shared cooked build: Unable to determine BRANCHNAME number from P4 or UGS, and is required by SharedCookedBuildPath");
            return;
        }


        CookedBuildPath = CookedBuildPath.Replace("[CL]", RecentCL.ToString());
        CookedBuildPath = CookedBuildPath.Replace("[BRANCHNAME]", BuildRoot);
        CookedBuildPath = CookedBuildPath.Replace("[PLATFORM]", CookPlatform);

        if (Directory.Exists(CookedBuildPath) == false)
        {
            Log("Unable to copy shared cooked build: Unable to find shared build at location {0} check SharedCookedBuildPath in Engine.ini SharedCookedBuildSettings is correct", CookedBuildPath);
            return;
        }

        Log("Attempting download of latest shared build CL {0} from location {1}", RecentCL, CookedBuildPath);

        if (BuildCL == RecentCL.ToString())
        {
            Log("Already downloaded latest shared build at CL {0}", RecentCL);
            return;
        }
        // delete all the stuff
        Log("Deleting previous shared build because it was out of date");
        CommandUtils.DeleteDirectory(LocalPath);
        Directory.CreateDirectory(LocalPath);


        // find all the files in the staged directory
        string CookedBuildStagedDirectory = Path.GetFullPath(Path.Combine(CookedBuildPath, "Staged"));
        string LocalBuildStagedDirectory  = Path.GetFullPath(Path.Combine(LocalPath, "Staged"));

        if (Directory.Exists(CookedBuildStagedDirectory))
        {
            foreach (string FileName in Directory.EnumerateFiles(CookedBuildStagedDirectory, "*.*", SearchOption.AllDirectories))
            {
                string SourceFileName = Path.GetFullPath(FileName);
                string DestFileName   = SourceFileName.Replace(CookedBuildStagedDirectory, LocalBuildStagedDirectory);
                Directory.CreateDirectory(Path.GetDirectoryName(DestFileName));
                File.Copy(SourceFileName, DestFileName);
            }
        }


        string CookedBuildCookedDirectory = Path.Combine(CookedBuildPath, "Cooked");

        CookedBuildCookedDirectory = Path.GetFullPath(CookedBuildCookedDirectory);
        string LocalBuildCookedDirectory = Path.Combine(LocalPath, "Cooked");

        LocalBuildCookedDirectory = Path.GetFullPath(LocalBuildCookedDirectory);
        if (Directory.Exists(CookedBuildCookedDirectory))
        {
            foreach (string FileName in Directory.EnumerateFiles(CookedBuildCookedDirectory, "*.*", SearchOption.AllDirectories))
            {
                string SourceFileName = Path.GetFullPath(FileName);
                string DestFileName   = SourceFileName.Replace(CookedBuildCookedDirectory, LocalBuildCookedDirectory);
                Directory.CreateDirectory(Path.GetDirectoryName(DestFileName));
                File.Copy(SourceFileName, DestFileName);
            }
        }
        File.WriteAllText(SyncedBuildFile, RecentCL.ToString());
        return;
    }