diff options
| author | Rob Mensching <rob@firegiant.com> | 2020-06-12 12:46:48 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2020-06-13 09:22:27 -0700 |
| commit | 86b7ea7a411813e03a2b238ca5c24fcebc947209 (patch) | |
| tree | 722bdc9463a6773df4242725ec340975e6c28641 /src/WixToolset.Core.WindowsInstaller | |
| parent | 404e5661ee971b9b2544185c3a28b24fafc06185 (diff) | |
| download | wix-86b7ea7a411813e03a2b238ca5c24fcebc947209.tar.gz wix-86b7ea7a411813e03a2b238ca5c24fcebc947209.tar.bz2 wix-86b7ea7a411813e03a2b238ca5c24fcebc947209.zip | |
Move validate guids to a command and execute it earlier
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs | 49 | ||||
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs | 63 |
2 files changed, 68 insertions, 44 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 65e4bf13..e0dd2b96 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs | |||
| @@ -319,6 +319,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 319 | command.Execute(); | 319 | command.Execute(); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | { | ||
| 323 | var command = new ValidateComponentGuidsCommand(this.Messaging, section); | ||
| 324 | command.Execute(); | ||
| 325 | } | ||
| 326 | |||
| 322 | // Add missing CreateFolder tuples to null-keypath components. | 327 | // Add missing CreateFolder tuples to null-keypath components. |
| 323 | { | 328 | { |
| 324 | var command = new AddCreateFoldersCommand(section); | 329 | var command = new AddCreateFoldersCommand(section); |
| @@ -407,8 +412,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 407 | } | 412 | } |
| 408 | #endif | 413 | #endif |
| 409 | 414 | ||
| 410 | this.ValidateComponentGuids(output); | ||
| 411 | |||
| 412 | // Stop processing if an error previously occurred. | 415 | // Stop processing if an error previously occurred. |
| 413 | if (this.Messaging.EncounteredError) | 416 | if (this.Messaging.EncounteredError) |
| 414 | { | 417 | { |
| @@ -579,48 +582,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 579 | return wixout; | 582 | return wixout; |
| 580 | } | 583 | } |
| 581 | 584 | ||
| 582 | /// <summary> | ||
| 583 | /// Validate that there are no duplicate GUIDs in the output. | ||
| 584 | /// </summary> | ||
| 585 | /// <remarks> | ||
| 586 | /// Duplicate GUIDs without conditions are an error condition; with conditions, it's a | ||
| 587 | /// warning, as the conditions might be mutually exclusive. | ||
| 588 | /// </remarks> | ||
| 589 | private void ValidateComponentGuids(WindowsInstallerData output) | ||
| 590 | { | ||
| 591 | if (output.TryGetTable("Component", out var componentTable)) | ||
| 592 | { | ||
| 593 | var componentGuidConditions = new Dictionary<string, bool>(componentTable.Rows.Count); | ||
| 594 | |||
| 595 | foreach (Data.WindowsInstaller.Rows.ComponentRow row in componentTable.Rows) | ||
| 596 | { | ||
| 597 | // We don't care about unmanaged components and if there's a * GUID remaining, | ||
| 598 | // there's already an error that prevented it from being replaced with a real GUID. | ||
| 599 | if (!String.IsNullOrEmpty(row.Guid) && "*" != row.Guid) | ||
| 600 | { | ||
| 601 | var thisComponentHasCondition = !String.IsNullOrEmpty(row.Condition); | ||
| 602 | var allComponentsHaveConditions = thisComponentHasCondition; | ||
| 603 | |||
| 604 | if (componentGuidConditions.ContainsKey(row.Guid)) | ||
| 605 | { | ||
| 606 | allComponentsHaveConditions = thisComponentHasCondition && componentGuidConditions[row.Guid]; | ||
| 607 | |||
| 608 | if (allComponentsHaveConditions) | ||
| 609 | { | ||
| 610 | this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(row.SourceLineNumbers, row.Component, row.Guid)); | ||
| 611 | } | ||
| 612 | else | ||
| 613 | { | ||
| 614 | this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(row.SourceLineNumbers, row.Component, row.Guid)); | ||
| 615 | } | ||
| 616 | } | ||
| 617 | |||
| 618 | componentGuidConditions[row.Guid] = allComponentsHaveConditions; | ||
| 619 | } | ||
| 620 | } | ||
| 621 | } | ||
| 622 | } | ||
| 623 | |||
| 624 | private string ResolveMedia(MediaTuple media, string mediaLayoutDirectory, string layoutDirectory) | 585 | private string ResolveMedia(MediaTuple media, string mediaLayoutDirectory, string layoutDirectory) |
| 625 | { | 586 | { |
| 626 | string layout = null; | 587 | string layout = null; |
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs new file mode 100644 index 00000000..020a83fc --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.WindowsInstaller.Bind | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Linq; | ||
| 8 | using WixToolset.Data; | ||
| 9 | using WixToolset.Data.Tuples; | ||
| 10 | using WixToolset.Extensibility.Services; | ||
| 11 | |||
| 12 | /// <summary> | ||
| 13 | /// Validate that there are no duplicate GUIDs in the output. | ||
| 14 | /// </summary> | ||
| 15 | /// <remarks> | ||
| 16 | /// Duplicate GUIDs without conditions are an error condition; with conditions, it's a | ||
| 17 | /// warning, as the conditions might be mutually exclusive. | ||
| 18 | /// </remarks> | ||
| 19 | internal class ValidateComponentGuidsCommand | ||
| 20 | { | ||
| 21 | internal ValidateComponentGuidsCommand(IMessaging messaging, IntermediateSection section) | ||
| 22 | { | ||
| 23 | this.Messaging = messaging; | ||
| 24 | this.Section = section; | ||
| 25 | } | ||
| 26 | |||
| 27 | private IMessaging Messaging { get; } | ||
| 28 | |||
| 29 | private IntermediateSection Section { get; } | ||
| 30 | |||
| 31 | public void Execute() | ||
| 32 | { | ||
| 33 | var componentGuidConditions = new Dictionary<string, bool>(); | ||
| 34 | |||
| 35 | foreach (var componentTuple in this.Section.Tuples.OfType<ComponentTuple>()) | ||
| 36 | { | ||
| 37 | // We don't care about unmanaged components and if there's a * GUID remaining, | ||
| 38 | // there's already an error that prevented it from being replaced with a real GUID. | ||
| 39 | if (!String.IsNullOrEmpty(componentTuple.ComponentId) && "*" != componentTuple.ComponentId) | ||
| 40 | { | ||
| 41 | var thisComponentHasCondition = !String.IsNullOrEmpty(componentTuple.Condition); | ||
| 42 | var allComponentsHaveConditions = thisComponentHasCondition; | ||
| 43 | |||
| 44 | if (componentGuidConditions.TryGetValue(componentTuple.ComponentId, out var alreadyCheckedCondition)) | ||
| 45 | { | ||
| 46 | allComponentsHaveConditions = thisComponentHasCondition && alreadyCheckedCondition; | ||
| 47 | |||
| 48 | if (allComponentsHaveConditions) | ||
| 49 | { | ||
| 50 | this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId)); | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId)); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | componentGuidConditions[componentTuple.ComponentId] = allComponentsHaveConditions; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
