Exemplo n.º 1
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                errorLevel = 3;
                Usage();
                return(errorLevel);
            }

            try {
                string    path = null;
                Hashtable commandLineProperties = new Hashtable();

                ProcessCommandLineArguments(args, ref path, commandLineProperties);

                LibraryManifest libraryInfo = new LibraryManifest(path);

                // default to Development profile
                string profileName            = "Development (Public)";
                string commandLineProfileName = (string)commandLineProperties["BuildProfileName"];
                profileName = (commandLineProfileName != null) ? commandLineProfileName : profileName;

                ProductBuildDataSet pbDataSet = ProductBuildDataSet.GetProductBuildDataSetWithoutComplist(
                    profileName,
                    libraryInfo.GetName(),
                    libraryInfo.GetVersion(),
                    libraryInfo.GetPlatform(),
                    libraryInfo.GetBranchOrTrunkName(),
                    libraryInfo.GetDirectory(),
                    path,
                    libraryInfo.GetDate());

                pbDataSet.ApplyCommandLineProperties(commandLineProperties);
                pbDataSet.LoadComplist();
                pbDataSet.FinalizeProperties();
                pbDataSet.WriteBuildConfigurationFile(pbDataSet.GetBuildConfigurationFilename());

                string           buildPath        = pbDataSet.GetBuildProperty("BuildPath");
                VmsProduct       currProduct      = new VmsProduct(libraryInfo.GetName(), libraryInfo.GetVersion(), libraryInfo.GetPlatform());
                VmsLibrary       currLibrary      = new VmsLibrary(currProduct, libraryInfo.GetBranchOrTrunkName());
                ControllerObject controllerObject = new ControllerObject();
                string           currentKey       = Util.GetServiceKey();
                bool             actionSucceeded  = false;
                string           errorMessage     = null;
                if (controllerObject.BuildLibrary(currLibrary, currentKey, buildPath, out errorMessage, false))
                {
                    NewMessage.ProcessMessages(currentKey, ref errorMessage, ref actionSucceeded, false, ref errorLevel);
                    if (actionSucceeded)
                    {
                        Console.WriteLine("    Successfully built " + currLibrary.ShortLibraryName);
                    }
                    else
                    {
                        Console.WriteLine("    Error building " + currLibrary.ShortLibraryName + ":" + errorMessage);
                    }
                }
                else
                {
                    Console.WriteLine("    Error building " + currLibrary.ShortLibraryName + ":" + errorMessage);
                }
            }
            catch (Exception e) {
                errorLevel = 3;
                Console.Error.WriteLine("An error occurred in ProductBuilder:");
                Console.Error.WriteLine(e.ToString());
                Usage();
            }
            return(errorLevel);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            int errlvl = 0;

            try {
                // Process Command-line Arguments
                string buildPath        = null;
                string buildUserProfile = null;
                string maxFileAge       = null;
                string exclusionFile    = null;
                string buildCfgFile     = null;

                if (args.Length < 1)
                {
                    Console.WriteLine();
                    Console.Error.WriteLine("Missing or Invalid Parameter.");
                    Usage();
                    errlvl = 2;
                    return(errlvl);
                }

                buildPath = args[0];
                foreach (string arg in args)
                {
                    if (arg.ToLower().StartsWith("/p:"))
                    {
                        buildUserProfile = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/a:"))
                    {
                        maxFileAge = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/e:"))
                    {
                        exclusionFile = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/f:"))
                    {
                        buildCfgFile = arg.Substring(3).Trim();
                    }
                }

                Console.WriteLine();
                Console.WriteLine("buildPath:        " + buildPath);
                Console.WriteLine("buildUserProfile: " + buildUserProfile);
                Console.WriteLine("maxFileAge:       " + maxFileAge);
                Console.WriteLine("exclusionFile:    " + exclusionFile);
                Console.WriteLine("buildCfgFile:     " + buildCfgFile);
                Console.WriteLine();

                //build dataset
                ProductBuildDataSet pbDataSet = null;
                if (buildCfgFile != null)
                {
                    pbDataSet = ProductBuildDataSet.ReadBuildConfigurationFile(buildCfgFile);
                }
                else
                {
                    LibraryManifest li = new LibraryManifest(buildPath);
                    if (buildUserProfile == null)
                    {
                        buildUserProfile = "Development";
                    }
                    pbDataSet = ProductBuildDataSet.GetProductBuildDataSetWithoutComplist(buildUserProfile,
                                                                                          li.GetName(),
                                                                                          li.GetVersion(),
                                                                                          li.GetPlatform(),
                                                                                          li.GetBranchOrTrunkName(),
                                                                                          li.GetDirectory(),
                                                                                          buildPath,
                                                                                          li.GetDate());
                    pbDataSet.LoadComplist();
                    pbDataSet.FinalizeProperties();
                }

                if (maxFileAge == null)
                {
                    maxFileAge = pbDataSet.GetBuildProperty("MaximumTargetAge");
                }
                //hack for backwards compatibility
                int colonIndex  = maxFileAge.IndexOf(':');
                int periodIndex = maxFileAge.IndexOf('.');
                if (periodIndex == -1 || colonIndex < periodIndex)
                {
                    maxFileAge = maxFileAge.Substring(0, colonIndex) + "." + maxFileAge.Substring(colonIndex + 1);
                }

                ArrayList checkedTargets   = pbDataSet.GetTargets(true);
                ArrayList uncheckedTargets = pbDataSet.GetTargets(false);

                if (exclusionFile != null)
                {
                    StringCollection excludedFiles = CollectionUtil.ReadValueFile(exclusionFile);
                    foreach (string excludedFile in excludedFiles)
                    {
                        foreach (string checkedTarget in checkedTargets)
                        {
                            if (excludedFile.ToLower() == checkedTarget.ToLower())
                            {
                                checkedTargets.Remove(checkedTarget);
                                uncheckedTargets.Add(checkedTarget);
                            }
                        }
                    }
                    uncheckedTargets.Sort();
                }

                //check the build
                Console.WriteLine();
                Console.WriteLine("Checking product , {0}, {1}, {2}, {3}",
                                  new object[] { pbDataSet.GetBuildProperty("ProductName"),
                                                 pbDataSet.GetBuildProperty("ProductVersion"),
                                                 pbDataSet.GetBuildProperty("ProductPlatform"),
                                                 pbDataSet.GetBuildProperty("BranchOrTrunkName"),
                                                 buildPath });
                Console.WriteLine("  in {0}", buildPath);
                Console.WriteLine();

                int  totalTargets     = checkedTargets.Count + uncheckedTargets.Count;
                int  foundTargets     = 0;
                int  duplicateTargets = 0;
                int  excludedTargets  = uncheckedTargets.Count;
                int  missingTargets   = 0;
                int  overAgeTargets   = 0;
                bool buildSucceeded   = true;

                string binPath = Path.Combine(buildPath, "bin");

                DateTime currentTime = DateTime.Now;
                DateTime checkTime   = currentTime - TimeSpan.Parse(maxFileAge);
                for (int targetIndex = 0; targetIndex < checkedTargets.Count; targetIndex++)
                {
                    string target = (string)checkedTargets[targetIndex];
                    if (targetIndex > 0 && target.ToLower() == ((string)checkedTargets[targetIndex - 1]).ToLower())
                    {
                        duplicateTargets++;
                        continue;
                    }
                    string targetFilename = Path.Combine(binPath, target);
                    if (!File.Exists(targetFilename))
                    {
                        buildSucceeded = false;
                        missingTargets++;
                        Console.WriteLine("{0,-32} Missing", target);
                        continue;
                    }
                    foundTargets++;
                    DateTime creationTime = File.GetLastWriteTime(targetFilename);
                    if (creationTime < checkTime)
                    {
                        buildSucceeded = false;
                        overAgeTargets++;
                        TimeSpan overAgeTime   = currentTime - creationTime;
                        string   overAgeString = "";
                        if (overAgeTime.Days > 0)
                        {
                            overAgeString += String.Format("{0,4}d", overAgeTime.Days);
                        }
                        if (overAgeTime.Hours > 0)
                        {
                            overAgeString += String.Format("{0:D2}h", overAgeTime.Hours);
                        }
                        overAgeString += String.Format("{0:D2}m", overAgeTime.Minutes);
                        Console.WriteLine("{0,-32} OverAge:{1}", target, overAgeString);
                    }
                }

                //results summary
                Console.WriteLine();
                Console.WriteLine("CheckBuild Statistics:");
                Console.WriteLine("Product           : {0}", pbDataSet.GetBuildProperty("ProductName"));
                Console.WriteLine("Version           : {0}", pbDataSet.GetBuildProperty("ProductVersion"));
                Console.WriteLine("Platform          : {0}", pbDataSet.GetBuildProperty("ProductPlatform"));
                Console.WriteLine("BranchOrTrunkName : {0}", pbDataSet.GetBuildProperty("BranchOrTrunkName"));
                Console.WriteLine("Target Dir        : {0}", buildPath);
                Console.WriteLine("Max File Age      : {0} (DD.HH:MM:SS)", maxFileAge);
                Console.WriteLine("Targets           : {0}", totalTargets);
                Console.WriteLine("Found             : {0}", foundTargets);
                Console.WriteLine("Duplicates        : {0}", duplicateTargets);
                Console.WriteLine("Excluded          : {0}", excludedTargets);
                Console.WriteLine("Missing           : {0}", missingTargets);
                Console.WriteLine("OverAge           : {0}", overAgeTargets);
                string successString = (buildSucceeded) ? "Successful Build." : "Build Failed!!!";
                Console.WriteLine("Results           : {0}", successString);

                errlvl = (buildSucceeded) ? 0 : 1;
            }
            catch (Exception e) {
                errlvl = 2;
                Console.Error.WriteLine("An error occurred in CheckBuild:");
                Console.Error.WriteLine(e.ToString());
                Usage();
            }

            return(errlvl);
        }