예제 #1
0
    public override void ExecuteBuild()
    {
        bool bAutoCreateChangelist = true;

        if (ParseParam("SkipCreateChangelist"))
        {
            bAutoCreateChangelist = false;
        }

        bool bAutoSubmit = bAutoCreateChangelist;

        if (ParseParam("SkipSubmit"))
        {
            bAutoSubmit = false;
        }

        // if we don't pass anything, we'll just merge by default
        string RobomergeCommand = ParseParamValue("Robomerge", "").ToLower();

        if (!string.IsNullOrEmpty(RobomergeCommand))
        {
            // for merge default action, add flag to make sure buildmachine commit isn't skipped
            if (RobomergeCommand == "merge")
            {
                RobomergeCommand = "#robomerge[all] #DisregardExcludedAuthors";
            }
            // otherwise add hashtags
            else if (RobomergeCommand == "ignore")
            {
                RobomergeCommand = "#robomerge #ignore";
            }
            else if (RobomergeCommand == "null")
            {
                RobomergeCommand = "#robomerge #null";
            }
            // otherwise the submit will likely fail.
            else
            {
                throw new AutomationException("Invalid Robomerge param passed in {0}.  Must be \"merge\", \"null\", or \"ignore\"", RobomergeCommand);
            }
        }

        SetupBuildEnvironment();

        TargetPlatform Platform = GetTargetPlatform();

        TargetLib TargetLib = GetTargetLib();

        List <string> TargetConfigurations = GetTargetConfigurations();

        if (Platform.SeparateProjectPerConfig)
        {
            foreach (string TargetConfiguration in TargetConfigurations)
            {
                Platform.SetupTargetLib(TargetLib, TargetConfiguration);
            }
        }
        else
        {
            Platform.SetupTargetLib(TargetLib, null);
        }

        HashSet <FileReference> FilesToReconcile = new HashSet <FileReference>();

        foreach (string TargetConfiguration in TargetConfigurations)
        {
            foreach (FileReference FileToDelete in Platform.EnumerateOutputFiles(TargetLib, TargetConfiguration).Distinct())
            {
                FilesToReconcile.Add(FileToDelete);

                // Also clean the output files
                InternalUtils.SafeDeleteFile(FileToDelete.FullName);
            }
        }

        foreach (string TargetConfiguration in TargetConfigurations)
        {
            Platform.BuildTargetLib(TargetLib, TargetConfiguration);
        }

        Platform.CleanupTargetLib(TargetLib, null);

        const int InvalidChangeList = -1;
        int       P4ChangeList      = InvalidChangeList;

        if (bAutoCreateChangelist)
        {
            string LibDeploymentDesc = TargetLib.Name + " " + Platform.FriendlyName;

            var Builder = new StringBuilder();
            Builder.AppendFormat("BuildCMakeLib.Automation: Deploying {0} libs.{1}", LibDeploymentDesc, Environment.NewLine);
            Builder.AppendLine("#rb none");
            Builder.AppendLine("#lockdown Nick.Penwarden");
            Builder.AppendLine("#tests none");
            Builder.AppendLine("#jira none");
            Builder.AppendLine("#okforgithub ignore");
            if (!string.IsNullOrEmpty(RobomergeCommand))
            {
                Builder.AppendLine(RobomergeCommand);
            }

            P4ChangeList = P4.CreateChange(P4Env.Client, Builder.ToString());
        }

        if (P4ChangeList != InvalidChangeList)
        {
            foreach (FileReference FileToReconcile in FilesToReconcile)
            {
                P4.Reconcile(P4ChangeList, FileToReconcile.FullName);
            }

            if (bAutoSubmit)
            {
                if (!P4.TryDeleteEmptyChange(P4ChangeList))
                {
                    LogInformation("Submitting changelist " + P4ChangeList.ToString());
                    int SubmittedChangeList = InvalidChangeList;
                    P4.Submit(P4ChangeList, out SubmittedChangeList);
                }
                else
                {
                    LogInformation("Nothing to submit!");
                }
            }
        }
    }