public void RunBatch(string batcFileName, string cmdArgs, string workingDir, bool isQuietMode, int waitTime, NewMessage userMessage) { if (userMessage.Cancelled) { return; } if (cmdArgs == null) { cmdArgs = ""; } cmdArgs += " 2>&1 | " + LibraryBuilderConfig.GetLogProcessPath() + " " + userMessage.UniqueKey + " >> " + GetBuildLogfile(); using (Process buildProcess = new Process()) { buildProcess.StartInfo.FileName = batcFileName; buildProcess.StartInfo.Arguments = cmdArgs; buildProcess.StartInfo.WorkingDirectory = workingDir; buildProcess.StartInfo.CreateNoWindow = false; buildProcess.StartInfo.UseShellExecute = false; buildProcess.Start(); userMessage.MonitorCancell(buildProcess.Id); buildProcess.WaitForExit(waitTime); buildProcess.Close(); } }
public static bool CanBuildOnPath(string sourcePath, string buildPath, ref string errorMsg) { bool returnValue = true; if (LibraryManifest.IsNetworkPath(buildPath)) { returnValue = false; errorMsg = "Builds are not allowed on VMS product paths; "; errorMsg += "please select a different path and try again."; } else { if (sourcePath.ToLower() != buildPath.ToLower()) { LibraryManifest libManifest = new LibraryManifest(sourcePath); string buildLibName = (LibraryManifest.IsNetworkPath(sourcePath))? "NETWORK_" : "LOCAL_"; buildLibName += libManifest.GetBranchOrTrunkName() + "_BUILD"; //Abort if the path is a registered path of a non-build lib VmsLibrary[] libList = LibraryBuilderConfig.GetLibrariesWithElementValue(LibraryElementNames.libraryPath, buildPath); if (libList != null) { bool canUsePath = false; foreach (VmsLibrary currLib in libList) { if (currLib.Name.ToLower() == buildLibName.ToLower()) { canUsePath = true; } } if (false == canUsePath) { returnValue = false; errorMsg = "A local library already exists on the selected build path; "; errorMsg += "please select a different path and try again."; } } } } return(returnValue); }
private void ValidateLibrary(NewMessage userMsg, bool isQuietMode) { string buildTimeEntry = DateTime.Now + " - Starting Validate."; buildTimes.Add(buildTimeEntry); Console.WriteLine(buildTimeEntry); string buildPath = pbDataSet.GetBuildProperty("BuildPath"); string sourcePath = pbDataSet.GetBuildProperty("SourcePath"); // save build configuration file string buildDefinitionFile = ProductBuildDataSet.GetBuildConfigurationFilename(buildPath); string tempFile = ProductBuildDataSet.GetBuildConfigurationFilename(Path.GetTempPath()); if (File.Exists(tempFile)) { File.SetAttributes(tempFile, FileAttributes.Normal); File.Delete(tempFile); } string tempBuildDefinitionDirectory = Path.Combine(Path.GetPathRoot(tempFile), Path.GetDirectoryName(tempFile)); if (!Directory.Exists(tempBuildDefinitionDirectory)) { Directory.CreateDirectory(tempBuildDefinitionDirectory); } File.Move(buildDefinitionFile, tempFile); // copy build definition file into buildpath string buildDefinitionDirectory = Path.Combine(Path.GetPathRoot(buildDefinitionFile), Path.GetDirectoryName(buildDefinitionFile)); if (Directory.Exists(buildDefinitionDirectory)) { Directory.Delete(buildDefinitionDirectory, true); } Directory.CreateDirectory(buildDefinitionDirectory); File.Move(tempFile, buildDefinitionFile); string errorMsg = null; if (false == CanBuildOnPath(sourcePath, buildPath, ref errorMsg)) { throw new Exception(errorMsg); } string buildLibName; string createDate; if (LibraryManifest.IsNetworkPath(sourcePath)) { buildLibName = "NETWORK_" + libraryManifest.GetBranchOrTrunkName() + "_BUILD"; createDate = new DateTime(DatabaseInterface.GetCurrentServerTime()).ToString(); } else { buildLibName = "LOCAL_" + libraryManifest.GetBranchOrTrunkName() + "_BUILD"; createDate = libraryManifest.GetDate(); } // Attempt to run LB three times. Try the first time in quiet mode. // Disable "quiet mode" on a retry, hoping to get information // useful to determine the source of problem. string quietModeArg = "/q"; int lbExitCode = 0; int attemptCount = 0; string validateBatchFilePath = buildPath + "\\validate.bat"; while (true) { string validateCmd = LibraryBuilderConfig.GetLbCommandLinePath() + " /c " + quietModeArg + " /nocopy /src:" + sourcePath + " /path:" + buildPath; validateCmd += " /name:" + buildLibName + " /date:\"" + createDate + "\""; //create bat file in buildPath and save StreamWriter cmdWriter = new StreamWriter(validateBatchFilePath, false); cmdWriter.WriteLine(validateCmd); cmdWriter.WriteLine("@set LB__EXIT__CODE=%ERRORLEVEL%"); cmdWriter.WriteLine("@echo Library validation: LB exited with code: %LB__EXIT__CODE%"); cmdWriter.WriteLine("@exit %LB__EXIT__CODE%"); cmdWriter.Close(); lbExitCode = RunBatchWithInternalOutputHandling(validateBatchFilePath, null, buildPath, isQuietMode, (1 * 60 * 60 * 1000), userMsg); Console.WriteLine("LB exited with code: " + lbExitCode); if (lbExitCode != 0 && ++attemptCount < 3) { Console.WriteLine("LB failed - retrying..."); quietModeArg = ""; continue; } break; } File.Delete(validateBatchFilePath); if (lbExitCode != 0) { Console.WriteLine("Unable to validate library, terminating build..."); throw new Exception("Unable to validate library. Please see build log for details."); } // refresh LibraryInfo file with current datetime LibraryManifest lif = new LibraryManifest( pbDataSet.GetBuildProperty("ProductName"), pbDataSet.GetBuildProperty("ProductVersion"), pbDataSet.GetBuildProperty("ProductPlatform"), pbDataSet.GetBuildProperty("BranchOrTrunkName"), pbDataSet.GetBuildProperty("ProductDirectory"), pbDataSet.GetBuildProperty("LibraryDate")); lif.SaveToPath(pbDataSet.GetBuildProperty("BuildPath")); buildTimeEntry = DateTime.Now + " - Validate Complete."; if (pbDataSet.IsPartialBuild()) { string binCopyCmd = Path.Combine(pbDataSet.GetBuildProperty("PBToolsPath"), "CopyBinaries.bat"); string copyArgs = " " + sourcePath + " " + buildPath; RunBatch(binCopyCmd, copyArgs, buildPath, isQuietMode, (1 * 60 * 60 * 1000), userMsg); } buildTimes.Add(buildTimeEntry); Console.WriteLine(buildTimeEntry); }