aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs')
-rw-r--r--src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs b/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs
new file mode 100644
index 00000000..39c3a5c2
--- /dev/null
+++ b/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs
@@ -0,0 +1,49 @@
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
3namespace WixToolset.Link
4{
5 using System.Collections.Generic;
6 using System.Linq;
7 using WixToolset.Data;
8
9 public class ReportConflictingSymbolsCommand : ICommand
10 {
11 private IEnumerable<Symbol> possibleConflicts;
12 private IEnumerable<Section> resolvedSections;
13
14 public ReportConflictingSymbolsCommand(IEnumerable<Symbol> possibleConflicts, IEnumerable<Section> resolvedSections)
15 {
16 this.possibleConflicts = possibleConflicts;
17 this.resolvedSections = resolvedSections;
18 }
19
20 public void Execute()
21 {
22 // Do a quick check if there are any possibly conflicting symbols that don't come from tables that allow
23 // overriding. Hopefully the symbols with possible conflicts list is usually very short list (empty should
24 // be the most common). If we find any matches, we'll do a more costly check to see if the possible conflicting
25 // symbols are in sections we actually referenced. From the resulting set, show an error for each duplicate
26 // (aka: conflicting) symbol. This should catch any rows with colliding primary keys (since symbols are based
27 // on the primary keys of rows).
28 List<Symbol> illegalDuplicates = possibleConflicts.Where(s => "WixAction" != s.Row.Table.Name && "WixVariable" != s.Row.Table.Name).ToList();
29 if (0 < illegalDuplicates.Count)
30 {
31 HashSet<Section> referencedSections = new HashSet<Section>(resolvedSections);
32 foreach (Symbol referencedDuplicateSymbol in illegalDuplicates.Where(s => referencedSections.Contains(s.Section)))
33 {
34 List<Symbol> actuallyReferencedDuplicateSymbols = referencedDuplicateSymbol.PossiblyConflictingSymbols.Where(s => referencedSections.Contains(s.Section)).ToList();
35
36 if (actuallyReferencedDuplicateSymbols.Any())
37 {
38 Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol(referencedDuplicateSymbol.Row.SourceLineNumbers, referencedDuplicateSymbol.Name));
39
40 foreach (Symbol duplicate in actuallyReferencedDuplicateSymbols)
41 {
42 Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol2(duplicate.Row.SourceLineNumbers));
43 }
44 }
45 }
46 }
47 }
48 }
49}