예제 #1
0
    public override void ExecuteBuild()
    {
        SetupStaticBuildEnvironment();

        bool bBuildSolutions = true;

        if (ParseParam("SkipBuildSolutions"))
        {
            bBuildSolutions = false;
        }

        bool bBuildLibraries = true;

        if (ParseParam("SkipBuild"))
        {
            bBuildLibraries = false;
        }

        bool bAutoCreateChangelist = true;

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

        bool bAutoSubmit = false;         // 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);
            }
        }

        // get the platforms we want to build for
        List <TargetPlatformData> TargetPlatforms = GetTargetPlatforms();

        // get the platforms we want to build for
        List <WindowsCompiler> TargetWindowsCompilers = GetTargetWindowsCompilers();

        // get the configurations we want to build for
        List <string> TargetConfigurations = GetTargetConfigurations();

        if (bBuildSolutions)
        {
            // build target lib for all platforms
            foreach (TargetPlatformData TargetData in TargetPlatforms)
            {
                if (!PlatformSupportsTargetLib(TargetData))
                {
                    continue;
                }

                SetupBuildForTargetLibAndPlatform(TargetData, TargetConfigurations, TargetWindowsCompilers, false);
            }
        }

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

        if (bBuildLibraries)
        {
            // build target lib for all platforms
            foreach (TargetPlatformData TargetData in TargetPlatforms)
            {
                if (!PlatformSupportsTargetLib(TargetData))
                {
                    continue;
                }

                HashSet <FileReference> FilesToDelete = new HashSet <FileReference>();
                foreach (string TargetConfiguration in TargetConfigurations)
                {
                    // Delete output files before building them
                    if (TargetData.Platform == UnrealTargetPlatform.Win64)
                    {
                        foreach (WindowsCompiler TargetCompiler in TargetWindowsCompilers)
                        {
                            FindOutputFiles(FilesToDelete, TargetData, TargetConfiguration, TargetCompiler);
                        }
                    }
                    else
                    {
                        FindOutputFiles(FilesToDelete, TargetData, TargetConfiguration);
                    }
                }
                foreach (FileReference FileToDelete in FilesToDelete)
                {
                    FilesToReconcile.Add(FileToDelete);
                    InternalUtils.SafeDeleteFile(FileToDelete.ToString());
                }

                BuildTargetLibForPlatform(TargetData, TargetConfigurations, TargetWindowsCompilers);

                if (DoesPlatformUseMSBuild(TargetData))
                {
                    foreach (WindowsCompiler TargetWindowsCompiler in TargetWindowsCompilers)
                    {
                        CopyLibsToFinalDestination(TargetData, TargetConfigurations, TargetWindowsCompiler);
                    }
                }
                else
                {
                    CopyLibsToFinalDestination(TargetData, TargetConfigurations);
                }
            }
        }

        int P4ChangeList = InvalidChangeList;

        if (bAutoCreateChangelist)
        {
            string RobomergeLine = string.Empty;
            if (!string.IsNullOrEmpty(RobomergeCommand))
            {
                RobomergeLine = Environment.NewLine + RobomergeCommand;
            }
            P4ChangeList = P4.CreateChange(P4Env.Client, "BuildHlslcc.Automation: Deploying hlslcc libs." + Environment.NewLine + "#rb none" + Environment.NewLine + "#lockdown Nick.Penwarden" + Environment.NewLine + "#tests none" + Environment.NewLine + "#jira none" + Environment.NewLine + "#okforgithub ignore" + RobomergeLine);
        }

        if (P4ChangeList != InvalidChangeList)
        {
            foreach (string TargetConfiguration in TargetConfigurations)
            {
                //Add any new files that p4 is not yet tracking.
                foreach (TargetPlatformData TargetData in TargetPlatforms)
                {
                    if (!PlatformSupportsTargetLib(TargetData))
                    {
                        continue;
                    }

                    if (TargetData.Platform == UnrealTargetPlatform.Win64)
                    {
                        foreach (WindowsCompiler TargetCompiler in TargetWindowsCompilers)
                        {
                            FindOutputFiles(FilesToReconcile, TargetData, TargetConfiguration, TargetCompiler);
                        }
                    }
                    else
                    {
                        FindOutputFiles(FilesToReconcile, TargetData, TargetConfiguration);
                    }
                }
            }

            foreach (FileReference FileToReconcile in FilesToReconcile)
            {
                P4.Reconcile(P4ChangeList, FileToReconcile.ToString());
            }
        }

        if (bAutoSubmit && (P4ChangeList != InvalidChangeList))
        {
            if (!P4.TryDeleteEmptyChange(P4ChangeList))
            {
                LogInformation("Submitting changelist " + P4ChangeList.ToString());
                int SubmittedChangeList = InvalidChangeList;
                P4.Submit(P4ChangeList, out SubmittedChangeList);
            }
            else
            {
                LogInformation("Nothing to submit!");
            }
        }
    }
예제 #2
0
        private void UpdateOpenHAB()
        {
            ResetSummary();

            string OpenHABUpdateFileWithPath;

            if (MainForm.UpdateTypeValue == 1)
            {
                UpdateDownloadComplete = false;

                Uri       UpdateFileURI;
                string    OpenHABUpdateFile;
                WebClient OpenHABDownload = new WebClient();

                WriteLog("Downloading OpenHAB update" + Environment.NewLine, true);

                Uri.TryCreate(MainForm.UpdateURL.Text.Trim(), UriKind.Absolute, out UpdateFileURI);
                OpenHABUpdateFile = Path.GetFileName(UpdateFileURI.LocalPath);

                OpenHABUpdateFileWithPath = new Uri(MainForm.UpdatePath.Text.Trim() + "\\" + OpenHABUpdateFile.Trim()).LocalPath;

                if (File.Exists(OpenHABUpdateFileWithPath))
                {
                    File.Delete(OpenHABUpdateFileWithPath);
                }

                OpenHABDownload.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
                OpenHABDownload.DownloadFileCompleted   += new AsyncCompletedEventHandler(DownloadFileCompletedCallback);

                try
                {
                    OpenHABDownload.DownloadFileAsync(new System.Uri(MainForm.UpdateURL.Text.Trim()), OpenHABUpdateFileWithPath.Trim());

                    while (!UpdateDownloadComplete)
                    {
                        Application.DoEvents();
                    }
                }
                catch (Exception DownloadException)
                {
                    WriteLog("An error occured while downloading OpenHAB update (" + DownloadException.Message + ")" + Environment.NewLine, true, true);

                    return;
                }

                TotalNumberOfItems = 0;
                CurrentItemNumber  = 0;
                bwrPerformUpdate.ReportProgress(0);
            }
            else
            {
                OpenHABUpdateFileWithPath = MainForm.UpdateFile.Text.Trim();
            }

            if (!StopOpenHABService())
            {
                return;
            }

            ZipArchive ZipFileToExtract = null;

            try
            {
                ZipFileToExtract = ZipFile.Open(OpenHABUpdateFileWithPath.Trim(), ZipArchiveMode.Read);
            }
            catch (Exception UpdateException)
            {
                WriteLog("Cannot update OpenHAB using update file: " + OpenHABUpdateFileWithPath.Trim() + " (" + UpdateException.Message + ")" + Environment.NewLine, true, true);

                return;
            }

            foreach (ZipArchiveEntry ZipEntryToCount in ZipFileToExtract.Entries)
            {
                if (!string.IsNullOrEmpty(ZipEntryToCount.FullName))
                {
                    TotalNumberOfItems++;
                }
            }

            if (MainForm.BeforeUpdatingValue == 2)
            {
                CreateFullBackup();
            }
            else if (MainForm.BeforeUpdatingValue == 3)
            {
                CreateConfigurationBackup();
            }

            WriteLog("Updating OpenHAB using update file: " + OpenHABUpdateFileWithPath.Trim() + Environment.NewLine, true);

            var FilesToDelete = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "DeleteList.dat");

            foreach (var FileToDelete in FilesToDelete)
            {
                bool IsFolder = false;

                if ((!FileToDelete.ToString().Trim().Contains("*")) && (!FileToDelete.ToString().Trim().Contains("?")) && (Directory.Exists(new Uri(MainForm.OpenHABPath.Text.Trim() + "\\" + FileToDelete.ToString().Trim()).LocalPath)))
                {
                    if (File.GetAttributes(new Uri(MainForm.OpenHABPath.Text.Trim() + "\\" + FileToDelete.ToString().Trim()).LocalPath).HasFlag(FileAttributes.Directory))
                    {
                        IsFolder = true;
                    }
                }

                if (IsFolder)
                {
                    try
                    {
                        Directory.Delete(new Uri(MainForm.OpenHABPath.Text.Trim() + "\\" + FileToDelete.ToString().Trim()).LocalPath, true);

                        SummaryFoldersDeleteSucceeded++;

                        WriteLog("Deleting folder: " + new Uri(MainForm.OpenHABPath.Text.Trim() + "\\" + FileToDelete.ToString().Trim()).LocalPath);
                    }
                    catch (Exception DeleteException)
                    {
                        SummaryFoldersDeleteFailed++;

                        WriteLog("Cannot delete folder: " + new Uri(MainForm.OpenHABPath.Text.Trim() + "\\" + FileToDelete.ToString().Trim()).LocalPath + " (" + DeleteException.Message + ")", false, true);
                    }
                }
                else
                {
                    foreach (var SingleFile in Directory.GetFiles(new Uri(MainForm.OpenHABPath.Text.Trim() + "\\").LocalPath, FileToDelete))
                    {
                        try
                        {
                            File.Delete(SingleFile.ToString().Trim());

                            SummaryFilesDeleteSucceeded++;

                            WriteLog("Deleting file: " + SingleFile.ToString().Trim());
                        }
                        catch (Exception DeleteException)
                        {
                            SummaryFilesDeleteFailed++;

                            WriteLog("Cannot delete file: " + SingleFile.ToString().Trim() + " (" + DeleteException.Message + ")", false, true);
                        }
                    }
                }
            }

            foreach (ZipArchiveEntry ZipEntryToExtract in ZipFileToExtract.Entries)
            {
                CurrentItemNumber++;

                if (String.IsNullOrEmpty(ZipEntryToExtract.Name))
                {
                    if (!Directory.Exists(new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Substring(0, new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Length - ZipEntryToExtract.Name.Length)))
                    {
                        try
                        {
                            Directory.CreateDirectory(new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Substring(0, new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Length - ZipEntryToExtract.Name.Length));

                            bwrPerformUpdate.ReportProgress(CurrentItemNumber * 100 / TotalNumberOfItems);

                            SummaryFoldersCreateSucceeded++;

                            WriteLog("Creating folder: " + new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Substring(0, new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Length - ZipEntryToExtract.Name.Length));
                        }
                        catch (Exception UpdateException)
                        {
                            SummaryFoldersCreateFailed++;

                            WriteLog("Cannot create folder: " + new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Substring(0, new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath.Length - ZipEntryToExtract.Name.Length) + " (" + UpdateException.Message + ")", false, true);
                        }
                    }
                }
                else
                {
                    try
                    {
                        ZipEntryToExtract.ExtractToFile(new Uri(Path.Combine(MainForm.OpenHABPath.Text.Trim(), ZipEntryToExtract.FullName)).LocalPath, false);

                        bwrPerformUpdate.ReportProgress(CurrentItemNumber * 100 / TotalNumberOfItems);

                        SummaryFilesExtractSucceeded++;

                        WriteLog("Extracting file: " + ZipEntryToExtract.FullName);
                    }
                    catch (Exception UpdateException)
                    {
                        bwrPerformUpdate.ReportProgress(CurrentItemNumber * 100 / TotalNumberOfItems);

                        SummaryFilesExtractSkipped++;

                        WriteLog("Skipping file extraction: " + ZipEntryToExtract.FullName + " (" + UpdateException.Message.ToString() + ")");
                    }
                }
            }

            ZipFileToExtract.Dispose();

            WriteSummary("Update summary");

            WriteLog(Environment.NewLine + "Update complete" + Environment.NewLine, true);
        }