public bool ShouldParseSampleForSpecificDevice(VendorSampleID sampleID) { if (_ParseAll) { return(true); } return(_IDsToParse.Contains(sampleID)); }
public void Run(string[] args) { string SDKdir = null; string specificSampleName = null; RunMode mode = RunMode.Invalid; foreach (var arg in args) { string singlePrefix = "/single:"; if (arg.StartsWith(singlePrefix, StringComparison.InvariantCultureIgnoreCase)) { mode = RunMode.SingleSample; specificSampleName = arg.Substring(singlePrefix.Length); } else if (arg.StartsWith("/")) { mode = Enum.GetValues(typeof(RunMode)).OfType <RunMode>().First(v => v.ToString().ToLower() == arg.Substring(1).ToLower()); } else { SDKdir = arg; } } if (SDKdir == null || mode == RunMode.Invalid) { Console.WriteLine($"Usage: {Path.GetFileName(Assembly.GetEntryAssembly().Location)} <mode> <SW package directory>"); Console.WriteLine($"Modes:"); Console.WriteLine($" /incremental - Only retest/rebuild previously failed samples."); Console.WriteLine($" This doesn't update the BSP archive."); Console.WriteLine($" /release - Reuse cached definitions, retest all samples. Update BSP."); Console.WriteLine($" /cleanRelease - Reparse/retest all samples. Update BSP."); Console.WriteLine($" /updateErrors - Re-categorize errors based on KnownProblems.xml"); Console.WriteLine($" /single:<name> - Run all phases of just one sample."); Console.WriteLine($"Press any key to continue..."); Console.ReadKey(); Environment.ExitCode = 1; return; } if (mode == RunMode.Incremental) { Console.WriteLine("*********************** WARNING ************************"); Console.WriteLine("* Vendor sample parser is running in incremental mode. *"); Console.WriteLine("* Only retested samples will be saved to BSP! *"); Console.WriteLine("* Re-run in /release mode to build a releasable BSP. *"); Console.WriteLine("********************************************************"); } if (mode == RunMode.UpdateErrors) { foreach (var rec in _Report.Records) { } XmlTools.SaveObject(_Report, ReportFile); return; } string archiveName = string.Format("{0}-{1}.vgdbxbsp", BSP.BSP.PackageID.Split('.').Last(), BSP.BSP.PackageVersion); string archiveFilePath = Path.Combine(BSPDirectory, archiveName); if (File.Exists(archiveFilePath)) { File.Delete(archiveFilePath); } string sampleListFile = Path.Combine(CacheDirectory, "Samples.xml"); var sampleDir = BuildOrLoadSampleDirectoryAndUpdateReportForFailedSamples(sampleListFile, SDKdir, mode, specificSampleName); Dictionary <VendorSampleID, string> encounteredIDs = new Dictionary <VendorSampleID, string>(); foreach (var vs in sampleDir.Samples) { var id = new VendorSampleID(vs); if (encounteredIDs.TryGetValue(id, out var dir)) { throw new Exception("Duplicate sample for " + id); } encounteredIDs[new VendorSampleID(vs)] = vs.Path; var rec = _Report.ProvideEntryForSample(new VendorSampleID(vs)); if (rec.LastSucceededPass < VendorSamplePass.InitialParse) { rec.LastSucceededPass = VendorSamplePass.InitialParse; } } //We cache unadjusted sample definitions to allow tweaking the adjusting code without the need to reparse everything. Console.WriteLine("Adjusting sample properties..."); foreach (var vs in sampleDir.Samples) { AdjustVendorSampleProperties(vs); if (vs.Path == null) { throw new Exception("Missing sample path for " + vs.UserFriendlyName); } } VendorSample[] pass1Queue, insertionQueue; switch (mode) { case RunMode.Incremental: pass1Queue = insertionQueue = sampleDir.Samples.Where(s => _Report.ShouldBuildIncrementally(new VendorSampleID(s), VendorSamplePass.InPlaceBuild)).ToArray(); break; case RunMode.Release: insertionQueue = sampleDir.Samples; if (sampleDir.Samples.FirstOrDefault(s => s.AllDependencies != null) == null) { pass1Queue = sampleDir.Samples; } else { pass1Queue = new VendorSample[0]; } break; case RunMode.CleanRelease: pass1Queue = insertionQueue = sampleDir.Samples; break; case RunMode.SingleSample: pass1Queue = insertionQueue = sampleDir.Samples.Where(s => new VendorSampleID(s).ToString() == specificSampleName).ToArray(); if (pass1Queue.Length == 0) { throw new Exception("No samples match " + specificSampleName); } break; default: throw new Exception("Invalid run mode"); } if (pass1Queue.Length > 0) { //Test the raw VendorSamples in-place and store AllDependencies TestVendorSamplesAndUpdateReportAndDependencies(pass1Queue, null, VendorSamplePass.InPlaceBuild, vs => _Report.HasSampleFailed(new VendorSampleID(vs)), validationFlags: BSPValidationFlags.ResolveNameCollisions); foreach (var vs in pass1Queue) { if (vs.Path == null) { throw new Exception("Missing sample path for " + vs.UserFriendlyName); } } sampleDir.ToolchainDirectory = ToolchainDirectory; sampleDir.BSPDirectory = Path.GetFullPath(BSPDirectory); XmlTools.SaveObject(sampleDir, sampleListFile); } //Insert the samples into the generated BSP var relocator = CreateRelocator(sampleDir); var copiedFiles = relocator.InsertVendorSamplesIntoBSP(sampleDir, insertionQueue, BSPDirectory); var bsp = XmlTools.LoadObject <BoardSupportPackage>(Path.Combine(BSPDirectory, LoadedBSP.PackageFileName)); bsp.VendorSampleDirectoryPath = VendorSampleDirectoryName; bsp.VendorSampleCatalogName = VendorSampleCatalogName; XmlTools.SaveObject(bsp, Path.Combine(BSPDirectory, LoadedBSP.PackageFileName)); if (mode != RunMode.Incremental && mode != RunMode.SingleSample) { Console.WriteLine("Creating new BSP archive..."); string statFile = Path.ChangeExtension(archiveName, ".xml"); TarPacker.PackDirectoryToTGZ(BSPDirectory, archiveFilePath, fn => Path.GetExtension(fn).ToLower() != ".vgdbxbsp" && Path.GetFileName(fn) != statFile); } var vendorSampleListInBSP = Path.Combine(BSPDirectory, VendorSampleDirectoryName, "VendorSamples.xml"); // Finally verify that everything builds var expandedSamples = XmlTools.LoadObject <VendorSampleDirectory>(vendorSampleListInBSP); expandedSamples.Path = Path.GetFullPath(Path.Combine(BSPDirectory, VendorSampleDirectoryName)); var finalStats = TestVendorSamplesAndUpdateReportAndDependencies(expandedSamples.Samples, expandedSamples.Path, VendorSamplePass.RelocatedBuild); XmlTools.SaveObject(_Report, ReportFile); if (mode == RunMode.Incremental || mode == RunMode.SingleSample) { Console.WriteLine($"Deleting incomplete {vendorSampleListInBSP}...\n***Re-run in /release mode to produce a valid BSP."); File.Delete(vendorSampleListInBSP); //Incremental mode only places the samples that are currently built. } if (finalStats.Failed == 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"All {finalStats.Total} tests passed during final pass."); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{finalStats.Failed} out of {finalStats.Total} tests failed during final pass."); } Console.ResetColor(); Console.WriteLine("============================================="); Console.WriteLine($"Overall statistics for v{BSP.BSP.PackageVersion}:"); List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >(); fields.Add(new KeyValuePair <string, string>("Total samples discovered:", sampleDir.Samples.Length.ToString())); int unparsableSamples = _Report.Records.Count(r => r.LastSucceededPass == VendorSamplePass.None); int failedAtFirstBuild = _Report.Records.Count(r => r.LastSucceededPass == VendorSamplePass.InitialParse && r.BuildFailedExplicitly); int failedAtSecondBuild = _Report.Records.Count(r => r.LastSucceededPass == VendorSamplePass.InPlaceBuild && r.BuildFailedExplicitly); fields.Add(new KeyValuePair <string, string>("Failed during initial parse attempt:", $"{unparsableSamples}/{sampleDir.Samples.Length} ({unparsableSamples * 100.0 / sampleDir.Samples.Length:f1}%)")); fields.Add(new KeyValuePair <string, string>("Failed during in-place build:", $"{failedAtFirstBuild}/{sampleDir.Samples.Length} ({failedAtFirstBuild * 100.0 / sampleDir.Samples.Length:f1}%)")); fields.Add(new KeyValuePair <string, string>("Failed during relocated build:", $"{failedAtSecondBuild}/{sampleDir.Samples.Length} ({failedAtSecondBuild * 100.0 / sampleDir.Samples.Length:f1}%)")); if (mode != RunMode.Incremental) { fields.Add(new KeyValuePair <string, string>("Inserted into BSP:", expandedSamples.Samples.Length.ToString())); } OutputKeyValueList(fields); if (finalStats.Failed > 0 && mode != RunMode.Incremental) { throw new Exception("Some of the vendor samples have failed the final test. Fix this before releasing the BSP."); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }