diff options
author | Rob Mensching <rob@firegiant.com> | 2022-11-06 19:29:57 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-11-06 20:58:40 -0800 |
commit | d5673c535ea6ce81e87e891746ac14088aee0184 (patch) | |
tree | 0564df49b20f90a4a9f04e6c2e15e39ad24bfbe2 | |
parent | a4e1959094cdf2f868479dc62aeb2cb92def51b7 (diff) | |
download | wix-d5673c535ea6ce81e87e891746ac14088aee0184.tar.gz wix-d5673c535ea6ce81e87e891746ac14088aee0184.tar.bz2 wix-d5673c535ea6ce81e87e891746ac14088aee0184.zip |
Implement cab thread count
Closes 6978
3 files changed, 41 insertions, 16 deletions
diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index 1ed2ba79..bf215623 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | |||
@@ -83,17 +83,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
83 | 83 | ||
84 | public void Execute() | 84 | public void Execute() |
85 | { | 85 | { |
86 | // If the cabbing thread count wasn't provided, default the number of cabbing threads to the number of processors. | 86 | var calculatedCabbingThreadCount = this.CalculateCabbingThreadCount(); |
87 | if (this.CabbingThreadCount <= 0) | ||
88 | { | ||
89 | this.CabbingThreadCount = this.CalculateCabbingThreadCount(); | ||
90 | |||
91 | this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); | ||
92 | } | ||
93 | 87 | ||
94 | this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize); | 88 | this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize); |
95 | 89 | ||
96 | var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize); | 90 | var cabinetBuilder = new CabinetBuilder(this.Messaging, calculatedCabbingThreadCount, maximumCabinetSizeForLargeFileSplitting, maximumUncompressedMediaSize); |
97 | 91 | ||
98 | var hashesByFileId = this.Section.Symbols.OfType<MsiFileHashSymbol>().ToDictionary(s => s.Id.Id); | 92 | var hashesByFileId = this.Section.Symbols.OfType<MsiFileHashSymbol>().ToDictionary(s => s.Id.Id); |
99 | 93 | ||
@@ -130,16 +124,25 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
130 | 124 | ||
131 | private int CalculateCabbingThreadCount() | 125 | private int CalculateCabbingThreadCount() |
132 | { | 126 | { |
133 | var cabbingThreadCount = Environment.ProcessorCount; | 127 | var processorCount = Environment.ProcessorCount; |
134 | 128 | ||
135 | if (cabbingThreadCount <= 0) | 129 | // If the number of processors is invalid, default to a single processor. |
130 | if (processorCount == 0) | ||
136 | { | 131 | { |
137 | cabbingThreadCount = 1; // reset to 1 when the environment variable is invalid. | 132 | processorCount = 1; |
138 | 133 | ||
139 | this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), cabbingThreadCount.ToString())); | 134 | this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), processorCount.ToString())); |
140 | } | 135 | } |
141 | 136 | ||
142 | return cabbingThreadCount; | 137 | // If the cabbing thread count was provided, and it isn't more than double the number of processors, use it. |
138 | if (this.CabbingThreadCount > 0 && processorCount < this.CabbingThreadCount * 2) | ||
139 | { | ||
140 | processorCount = this.CabbingThreadCount; | ||
141 | } | ||
142 | |||
143 | this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(processorCount.ToString())); | ||
144 | |||
145 | return processorCount; | ||
143 | } | 146 | } |
144 | 147 | ||
145 | private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable<IFileFacade> fileFacades, Dictionary<string, MsiFileHashSymbol> hashesByFileId) | 148 | private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable<IFileFacade> fileFacades, Dictionary<string, MsiFileHashSymbol> hashesByFileId) |
diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index 4cc2227c..53c4f798 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs | |||
@@ -52,6 +52,7 @@ namespace WixToolset.Core.CommandLine | |||
52 | new CommandLineHelpSwitch("-bindpath:target", "-bt", "Bind path to search for target package's content files. Only used when building a patch."), | 52 | new CommandLineHelpSwitch("-bindpath:target", "-bt", "Bind path to search for target package's content files. Only used when building a patch."), |
53 | new CommandLineHelpSwitch("-bindpath:update", "-bu", "Bind path to search for update package's content files. Only used when building a patch."), | 53 | new CommandLineHelpSwitch("-bindpath:update", "-bu", "Bind path to search for update package's content files. Only used when building a patch."), |
54 | new CommandLineHelpSwitch("-cabcache", "-cc", "Set a folder to cache cabinets across builds."), | 54 | new CommandLineHelpSwitch("-cabcache", "-cc", "Set a folder to cache cabinets across builds."), |
55 | new CommandLineHelpSwitch("-cabthreads", "-ct", "Override the number of threads used to create cabinets."), | ||
55 | new CommandLineHelpSwitch("-culture", "Adds a culture to filter localization files."), | 56 | new CommandLineHelpSwitch("-culture", "Adds a culture to filter localization files."), |
56 | new CommandLineHelpSwitch("-define", "-d", "Sets a preprocessor variable."), | 57 | new CommandLineHelpSwitch("-define", "-d", "Sets a preprocessor variable."), |
57 | new CommandLineHelpSwitch("-defaultcompressionlevel", "-dcl", "Default compression level; see Compression levels below."), | 58 | new CommandLineHelpSwitch("-defaultcompressionlevel", "-dcl", "Default compression level; see Compression levels below."), |
@@ -147,7 +148,7 @@ namespace WixToolset.Core.CommandLine | |||
147 | { | 148 | { |
148 | using (new IntermediateFieldContext("wix.bind")) | 149 | using (new IntermediateFieldContext("wix.bind")) |
149 | { | 150 | { |
150 | this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.BindPaths, inputsOutputs, cancellationToken); | 151 | this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.CabbingThreadCount, this.commandLine.BindPaths, inputsOutputs, cancellationToken); |
151 | } | 152 | } |
152 | } | 153 | } |
153 | } | 154 | } |
@@ -265,7 +266,7 @@ namespace WixToolset.Core.CommandLine | |||
265 | return linker.Link(context); | 266 | return linker.Link(context); |
266 | } | 267 | } |
267 | 268 | ||
268 | private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> localizations, IReadOnlyCollection<string> filterCultures, string cabCachePath, IReadOnlyCollection<IBindPath> bindPaths, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken) | 269 | private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> localizations, IReadOnlyCollection<string> filterCultures, string cabCachePath, int cabbingThreadCount, IReadOnlyCollection<IBindPath> bindPaths, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken) |
269 | { | 270 | { |
270 | IResolveResult resolveResult; | 271 | IResolveResult resolveResult; |
271 | { | 272 | { |
@@ -295,7 +296,7 @@ namespace WixToolset.Core.CommandLine | |||
295 | { | 296 | { |
296 | var context = this.ServiceProvider.GetService<IBindContext>(); | 297 | var context = this.ServiceProvider.GetService<IBindContext>(); |
297 | context.BindPaths = bindPaths; | 298 | context.BindPaths = bindPaths; |
298 | //context.CabbingThreadCount = this.CabbingThreadCount; | 299 | context.CabbingThreadCount = cabbingThreadCount; |
299 | context.CabCachePath = cabCachePath; | 300 | context.CabCachePath = cabCachePath; |
300 | context.ResolvedCodepage = resolveResult.Codepage; | 301 | context.ResolvedCodepage = resolveResult.Codepage; |
301 | context.ResolvedSummaryInformationCodepage = resolveResult.SummaryInformationCodepage; | 302 | context.ResolvedSummaryInformationCodepage = resolveResult.SummaryInformationCodepage; |
@@ -467,6 +468,8 @@ namespace WixToolset.Core.CommandLine | |||
467 | 468 | ||
468 | public string CabCachePath { get; private set; } | 469 | public string CabCachePath { get; private set; } |
469 | 470 | ||
471 | public int CabbingThreadCount { get; private set; } | ||
472 | |||
470 | public List<string> Cultures { get; } = new List<string>(); | 473 | public List<string> Cultures { get; } = new List<string>(); |
471 | 474 | ||
472 | public List<string> Defines { get; } = new List<string>(); | 475 | public List<string> Defines { get; } = new List<string>(); |
@@ -566,6 +569,24 @@ namespace WixToolset.Core.CommandLine | |||
566 | this.CabCachePath = parser.GetNextArgumentOrError(arg); | 569 | this.CabCachePath = parser.GetNextArgumentOrError(arg); |
567 | return true; | 570 | return true; |
568 | 571 | ||
572 | case "ct": | ||
573 | case "cabthreads": | ||
574 | { | ||
575 | var value = parser.GetNextArgumentOrError(arg); | ||
576 | if (Int32.TryParse(value, out var cabbingThreads)) | ||
577 | { | ||
578 | this.CabbingThreadCount = cabbingThreads; | ||
579 | } | ||
580 | else if (!String.IsNullOrEmpty(value)) | ||
581 | { | ||
582 | var processorCount = Environment.ProcessorCount == 0 ? 1 : Environment.ProcessorCount; | ||
583 | var range = Enumerable.Range(1, processorCount * 2).Select(i => i.ToString()); | ||
584 | parser.ReportErrorArgument(arg, ErrorMessages.IllegalCommandLineArgumentValue(arg, value, range)); | ||
585 | } | ||
586 | |||
587 | return true; | ||
588 | } | ||
589 | |||
569 | case "culture": | 590 | case "culture": |
570 | parser.GetNextArgumentOrError(arg, this.Cultures); | 591 | parser.GetNextArgumentOrError(arg, this.Cultures); |
571 | return true; | 592 | return true; |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/CabFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/CabFixture.cs index da1d47df..690937d2 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/CabFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/CabFixture.cs | |||
@@ -28,6 +28,7 @@ namespace WixToolsetTest.CoreIntegration | |||
28 | "build", | 28 | "build", |
29 | Path.Combine(folder, "Package.wxs"), | 29 | Path.Combine(folder, "Package.wxs"), |
30 | Path.Combine(folder, "PackageComponents.wxs"), | 30 | Path.Combine(folder, "PackageComponents.wxs"), |
31 | "-ct", "1000000", | ||
31 | "-d", "MediaTemplateCompressionLevel", | 32 | "-d", "MediaTemplateCompressionLevel", |
32 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), | 33 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), |
33 | "-bindpath", Path.Combine(folder, "data"), | 34 | "-bindpath", Path.Combine(folder, "data"), |