From 8968578d50858721317d410549a9f9b5c62bf1f7 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 24 Jun 2020 12:24:20 -0700 Subject: Integrate Symbol to TupleWithSection rename --- .../Link/FindEntrySectionAndLoadSymbolsCommand.cs | 20 ++--- .../Link/ReportConflictingSymbolsCommand.cs | 55 ------------ .../Link/ReportConflictingTuplesCommand.cs | 54 +++++++++++ .../Link/ResolveReferencesCommand.cs | 100 ++++++++++----------- src/WixToolset.Core/Linker.cs | 36 ++++---- 5 files changed, 132 insertions(+), 133 deletions(-) delete mode 100644 src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs create mode 100644 src/WixToolset.Core/Link/ReportConflictingTuplesCommand.cs (limited to 'src') diff --git a/src/WixToolset.Core/Link/FindEntrySectionAndLoadSymbolsCommand.cs b/src/WixToolset.Core/Link/FindEntrySectionAndLoadSymbolsCommand.cs index b9890a3b..31cbf0b8 100644 --- a/src/WixToolset.Core/Link/FindEntrySectionAndLoadSymbolsCommand.cs +++ b/src/WixToolset.Core/Link/FindEntrySectionAndLoadSymbolsCommand.cs @@ -31,17 +31,17 @@ namespace WixToolset.Core.Link /// /// Gets the collection of loaded symbols. /// - public IDictionary Symbols { get; private set; } + public IDictionary TuplesByName { get; private set; } /// /// Gets the collection of possibly conflicting symbols. /// - public IEnumerable PossiblyConflictingSymbols { get; private set; } + public IEnumerable PossibleConflicts { get; private set; } public void Execute() { - var symbols = new Dictionary(); - var possibleConflicts = new HashSet(); + var tuplesByName = new Dictionary(); + var possibleConflicts = new HashSet(); if (!Enum.TryParse(this.ExpectedOutputType.ToString(), out SectionType expectedEntrySectionType)) { @@ -74,11 +74,11 @@ namespace WixToolset.Core.Link // Load all the symbols from the section's tables that create symbols. foreach (var tuple in section.Tuples.Where(t => t.Id != null)) { - var symbol = new Symbol(section, tuple); + var symbol = new TupleWithSection(section, tuple); - if (!symbols.TryGetValue(symbol.Name, out var existingSymbol)) + if (!tuplesByName.TryGetValue(symbol.Name, out var existingSymbol)) { - symbols.Add(symbol.Name, symbol); + tuplesByName.Add(symbol.Name, symbol); } else // uh-oh, duplicate symbols. { @@ -86,7 +86,7 @@ namespace WixToolset.Core.Link // point to identical tuples. Identical directory tuples are redundant and will not cause // conflicts. if (AccessModifier.Private == existingSymbol.Access && AccessModifier.Private == symbol.Access && - TupleDefinitionType.Directory == existingSymbol.Row.Definition.Type && existingSymbol.Row.IsIdentical(symbol.Row)) + TupleDefinitionType.Directory == existingSymbol.Tuple.Definition.Type && existingSymbol.Tuple.IsIdentical(symbol.Tuple)) { // Ensure identical symbol's tuple is marked redundant to ensure (should the tuple be // referenced into the final output) it will not add duplicate primary keys during @@ -103,8 +103,8 @@ namespace WixToolset.Core.Link } } - this.Symbols = symbols; - this.PossiblyConflictingSymbols = possibleConflicts; + this.TuplesByName = tuplesByName; + this.PossibleConflicts = possibleConflicts; } } } diff --git a/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs b/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs deleted file mode 100644 index 8d818ad9..00000000 --- a/src/WixToolset.Core/Link/ReportConflictingSymbolsCommand.cs +++ /dev/null @@ -1,55 +0,0 @@ -// 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. - -namespace WixToolset.Core.Link -{ - using System.Collections.Generic; - using System.Linq; - using WixToolset.Data; - using WixToolset.Extensibility.Services; - - internal class ReportConflictingSymbolsCommand - { - public ReportConflictingSymbolsCommand(IMessaging messaging, IEnumerable possibleConflicts, IEnumerable resolvedSections) - { - this.Messaging = messaging; - this.PossibleConflicts = possibleConflicts; - this.ResolvedSections = resolvedSections; - } - - private IMessaging Messaging { get; } - - private IEnumerable PossibleConflicts { get; } - - private IEnumerable ResolvedSections { get; } - - public void Execute() - { - // Do a quick check if there are any possibly conflicting symbols that don't come from tables that allow - // overriding. Hopefully the symbols with possible conflicts list is usually very short list (empty should - // be the most common). If we find any matches, we'll do a more costly check to see if the possible conflicting - // symbols are in sections we actually referenced. From the resulting set, show an error for each duplicate - // (aka: conflicting) symbol. This should catch any rows with colliding primary keys (since symbols are based - // on the primary keys of rows). - var illegalDuplicates = this.PossibleConflicts.Where(s => s.Row.Definition.Type != TupleDefinitionType.WixAction && s.Row.Definition.Type != TupleDefinitionType.WixVariable).ToList(); - if (0 < illegalDuplicates.Count) - { - var referencedSections = new HashSet(this.ResolvedSections); - - foreach (Symbol referencedDuplicateSymbol in illegalDuplicates.Where(s => referencedSections.Contains(s.Section))) - { - List actuallyReferencedDuplicateSymbols = referencedDuplicateSymbol.PossiblyConflictingSymbols.Where(s => referencedSections.Contains(s.Section)).ToList(); - - if (actuallyReferencedDuplicateSymbols.Any()) - { - this.Messaging.Write(ErrorMessages.DuplicateSymbol(referencedDuplicateSymbol.Row.SourceLineNumbers, referencedDuplicateSymbol.Name)); - - foreach (Symbol duplicate in actuallyReferencedDuplicateSymbols) - { - this.Messaging.Write(ErrorMessages.DuplicateSymbol2(duplicate.Row.SourceLineNumbers)); - } - } - } - } - } - } -} diff --git a/src/WixToolset.Core/Link/ReportConflictingTuplesCommand.cs b/src/WixToolset.Core/Link/ReportConflictingTuplesCommand.cs new file mode 100644 index 00000000..ff01f573 --- /dev/null +++ b/src/WixToolset.Core/Link/ReportConflictingTuplesCommand.cs @@ -0,0 +1,54 @@ +// 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. + +namespace WixToolset.Core.Link +{ + using System.Collections.Generic; + using System.Linq; + using WixToolset.Data; + using WixToolset.Extensibility.Services; + + internal class ReportConflictingTuplesCommand + { + public ReportConflictingTuplesCommand(IMessaging messaging, IEnumerable possibleConflicts, IEnumerable resolvedSections) + { + this.Messaging = messaging; + this.PossibleConflicts = possibleConflicts; + this.ResolvedSections = resolvedSections; + } + + private IMessaging Messaging { get; } + + private IEnumerable PossibleConflicts { get; } + + private IEnumerable ResolvedSections { get; } + + public void Execute() + { + // Do a quick check if there are any possibly conflicting symbols that don't come from tables that allow + // overriding. Hopefully the tuples with possible conflicts list is usually very short list (empty should + // be the most common). If we find any matches, we'll do a more costly check to see if the possible conflicting + // tuples are in sections we actually referenced. From the resulting set, show an error for each duplicate + // (aka: conflicting) tuple. + var illegalDuplicates = this.PossibleConflicts.Where(s => s.Tuple.Definition.Type != TupleDefinitionType.WixAction && s.Tuple.Definition.Type != TupleDefinitionType.WixVariable).ToList(); + if (0 < illegalDuplicates.Count) + { + var referencedSections = new HashSet(this.ResolvedSections); + + foreach (var referencedDuplicate in illegalDuplicates.Where(s => referencedSections.Contains(s.Section))) + { + var actuallyReferencedDuplicates = referencedDuplicate.PossiblyConflicts.Where(s => referencedSections.Contains(s.Section)).ToList(); + + if (actuallyReferencedDuplicates.Any()) + { + this.Messaging.Write(ErrorMessages.DuplicateSymbol(referencedDuplicate.Tuple.SourceLineNumbers, referencedDuplicate.Name)); + + foreach (var duplicate in actuallyReferencedDuplicates) + { + this.Messaging.Write(ErrorMessages.DuplicateSymbol2(duplicate.Tuple.SourceLineNumbers)); + } + } + } + } + } + } +} diff --git a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs index 6dcd36d3..4ffb5443 100644 --- a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs +++ b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs @@ -15,19 +15,19 @@ namespace WixToolset.Core.Link internal class ResolveReferencesCommand { private readonly IntermediateSection entrySection; - private readonly IDictionary symbols; - private HashSet referencedSymbols; + private readonly IDictionary tuplesWithSections; + private HashSet referencedTuples; private HashSet resolvedSections; - public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary symbols) + public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary tuplesWithSections) { this.Messaging = messaging; this.entrySection = entrySection; - this.symbols = symbols; + this.tuplesWithSections = tuplesWithSections; this.BuildingMergeModule = (SectionType.Module == entrySection.Type); } - public IEnumerable ReferencedSymbols => this.referencedSymbols; + public IEnumerable ReferencedTupleWithSections => this.referencedTuples; public IEnumerable ResolvedSections => this.resolvedSections; @@ -41,7 +41,7 @@ namespace WixToolset.Core.Link public void Execute() { this.resolvedSections = new HashSet(); - this.referencedSymbols = new HashSet(); + this.referencedTuples = new HashSet(); this.RecursivelyResolveReferences(this.entrySection); } @@ -60,8 +60,8 @@ namespace WixToolset.Core.Link } // Process all of the references contained in this section using the collection of - // symbols provided. Then recursively call this method to process the - // located symbol's section. All in all this is a very simple depth-first + // tuples provided. Then recursively call this method to process the + // located tuple's section. All in all this is a very simple depth-first // search of the references per-section. foreach (var wixSimpleReferenceRow in section.Tuples.OfType()) { @@ -72,44 +72,44 @@ namespace WixToolset.Core.Link continue; } - if (!this.symbols.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var symbol)) + if (!this.tuplesWithSections.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var tupleWithSection)) { this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName)); } - else // see if the symbol (and any of its duplicates) are appropriately accessible. + else // see if the tuple (and any of its duplicates) are appropriately accessible. { - IList accessible = this.DetermineAccessibleSymbols(section, symbol); + var accessible = this.DetermineAccessibleTuples(section, tupleWithSection); if (!accessible.Any()) { - this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, symbol.Access)); + this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, tupleWithSection.Access)); } else if (1 == accessible.Count) { - var accessibleSymbol = accessible[0]; - this.referencedSymbols.Add(accessibleSymbol); + var accessibleTuple = accessible[0]; + this.referencedTuples.Add(accessibleTuple); - if (null != accessibleSymbol.Section) + if (null != accessibleTuple.Section) { - this.RecursivelyResolveReferences(accessibleSymbol.Section); + this.RecursivelyResolveReferences(accessibleTuple.Section); } } - else // display errors for the duplicate symbols. + else // display errors for the duplicate tuples. { - var accessibleSymbol = accessible[0]; + var accessibleTuple = accessible[0]; var referencingSourceLineNumber = wixSimpleReferenceRow.SourceLineNumbers?.ToString(); if (String.IsNullOrEmpty(referencingSourceLineNumber)) { - this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name)); + this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name)); } else { - this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name, referencingSourceLineNumber)); + this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name, referencingSourceLineNumber)); } - foreach (Symbol accessibleDuplicate in accessible.Skip(1)) + foreach (var accessibleDuplicate in accessible.Skip(1)) { - this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Row.SourceLineNumbers)); + this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Tuple.SourceLineNumbers)); } } } @@ -117,67 +117,67 @@ namespace WixToolset.Core.Link } /// - /// Determine if the symbol and any of its duplicates are accessbile by referencing section. + /// Determine if the tuple and any of its duplicates are accessbile by referencing section. /// - /// Section referencing the symbol. - /// Symbol being referenced. - /// List of symbols accessible by referencing section. - private IList DetermineAccessibleSymbols(IntermediateSection referencingSection, Symbol symbol) + /// Section referencing the tuple. + /// Tuple being referenced. + /// List of tuples accessible by referencing section. + private List DetermineAccessibleTuples(IntermediateSection referencingSection, TupleWithSection tupleWithSection) { - List symbols = new List(); + var accessibleTuples = new List(); - if (this.AccessibleSymbol(referencingSection, symbol)) + if (this.AccessibleTuple(referencingSection, tupleWithSection)) { - symbols.Add(symbol); + accessibleTuples.Add(tupleWithSection); } - foreach (Symbol dupe in symbol.PossiblyConflictingSymbols) + foreach (var dupe in tupleWithSection.PossiblyConflicts) { // don't count overridable WixActionTuples - WixActionTuple symbolAction = symbol.Row as WixActionTuple; - WixActionTuple dupeAction = dupe.Row as WixActionTuple; - if (symbolAction?.Overridable != dupeAction?.Overridable) + var tupleAction = tupleWithSection.Tuple as WixActionTuple; + var dupeAction = dupe.Tuple as WixActionTuple; + if (tupleAction?.Overridable != dupeAction?.Overridable) { continue; } - if (this.AccessibleSymbol(referencingSection, dupe)) + if (this.AccessibleTuple(referencingSection, dupe)) { - symbols.Add(dupe); + accessibleTuples.Add(dupe); } } - foreach (Symbol dupe in symbol.RedundantSymbols) + foreach (var dupe in tupleWithSection.Redundants) { - if (this.AccessibleSymbol(referencingSection, dupe)) + if (this.AccessibleTuple(referencingSection, dupe)) { - symbols.Add(dupe); + accessibleTuples.Add(dupe); } } - return symbols; + return accessibleTuples; } /// - /// Determine if a single symbol is accessible by the referencing section. + /// Determine if a single tuple is accessible by the referencing section. /// - /// Section referencing the symbol. - /// Symbol being referenced. - /// True if symbol is accessible. - private bool AccessibleSymbol(IntermediateSection referencingSection, Symbol symbol) + /// Section referencing the tuple. + /// Tuple being referenced. + /// True if tuple is accessible. + private bool AccessibleTuple(IntermediateSection referencingSection, TupleWithSection tupleWithSection) { - switch (symbol.Access) + switch (tupleWithSection.Access) { case AccessModifier.Public: return true; case AccessModifier.Internal: - return symbol.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != symbol.Section.LibraryId && symbol.Section.LibraryId.Equals(referencingSection.LibraryId)); + return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != tupleWithSection.Section.LibraryId && tupleWithSection.Section.LibraryId.Equals(referencingSection.LibraryId)); case AccessModifier.Protected: - return symbol.Section.CompilationId.Equals(referencingSection.CompilationId); + return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId); case AccessModifier.Private: - return referencingSection == symbol.Section; + return referencingSection == tupleWithSection.Section; default: - throw new ArgumentOutOfRangeException(nameof(symbol.Access)); + throw new ArgumentOutOfRangeException(nameof(tupleWithSection.Access)); } } } diff --git a/src/WixToolset.Core/Linker.cs b/src/WixToolset.Core/Linker.cs index cbdb46d0..862681bb 100644 --- a/src/WixToolset.Core/Linker.cs +++ b/src/WixToolset.Core/Linker.cs @@ -149,12 +149,12 @@ namespace WixToolset.Core throw new WixException(ErrorMessages.MissingEntrySection(this.Context.ExpectedOutputType.ToString())); } - // Add the missing standard action symbols. - this.LoadStandardActionSymbols(find.EntrySection, find.Symbols); + // Add the missing standard action tuples. + this.LoadStandardActions(find.EntrySection, find.TuplesByName); - // Resolve the symbol references to find the set of sections we care about for linking. + // Resolve the tuple references to find the set of sections we care about for linking. // Of course, we start with the entry section (that's how it got its name after all). - var resolve = new ResolveReferencesCommand(this.Messaging, find.EntrySection, find.Symbols); + var resolve = new ResolveReferencesCommand(this.Messaging, find.EntrySection, find.TuplesByName); resolve.Execute(); @@ -190,16 +190,16 @@ namespace WixToolset.Core } // Display an error message for Components that were not referenced by a Feature. - foreach (var symbol in resolve.ReferencedSymbols.Where(s => s.Row.Definition.Type == TupleDefinitionType.Component)) + foreach (var tupleWithSection in resolve.ReferencedTupleWithSections.Where(s => s.Tuple.Definition.Type == TupleDefinitionType.Component)) { - if (!referencedComponents.Contains(symbol.Name)) + if (!referencedComponents.Contains(tupleWithSection.Name)) { - this.Messaging.Write(ErrorMessages.OrphanedComponent(symbol.Row.SourceLineNumbers, symbol.Row.Id.Id)); + this.Messaging.Write(ErrorMessages.OrphanedComponent(tupleWithSection.Tuple.SourceLineNumbers, tupleWithSection.Tuple.Id.Id)); } } // Report duplicates that would ultimately end up being primary key collisions. - var reportDupes = new ReportConflictingSymbolsCommand(this.Messaging, find.PossiblyConflictingSymbols, resolve.ResolvedSections); + var reportDupes = new ReportConflictingTuplesCommand(this.Messaging, find.PossibleConflicts, resolve.ResolvedSections); reportDupes.Execute(); if (this.Messaging.EncounteredError) @@ -208,7 +208,7 @@ namespace WixToolset.Core } // resolve the feature to feature connects - this.ResolveFeatureToFeatureConnects(featuresToFeatures, find.Symbols); + this.ResolveFeatureToFeatureConnects(featuresToFeatures, find.TuplesByName); // Create the section to hold the linked content. var resolvedSection = new IntermediateSection(find.EntrySection.Id, find.EntrySection.Type, find.EntrySection.Codepage); @@ -734,17 +734,17 @@ namespace WixToolset.Core /// /// Load the standard action symbols. /// - /// Collection of symbols. - private void LoadStandardActionSymbols(IntermediateSection section, IDictionary symbols) + /// Collection of symbols. + private void LoadStandardActions(IntermediateSection section, IDictionary tuplesByName) { - foreach (var actionRow in WindowsInstallerStandard.StandardActions()) + foreach (var actionTuple in WindowsInstallerStandard.StandardActions()) { - var symbol = new Symbol(section, actionRow); + var tupleWithSection = new TupleWithSection(section, actionTuple); - // If the action's symbol has not already been defined (i.e. overriden by the user), add it now. - if (!symbols.ContainsKey(symbol.Name)) + // If the action's tuple has not already been defined (i.e. overriden by the user), add it now. + if (!tuplesByName.ContainsKey(tupleWithSection.Name)) { - symbols.Add(symbol.Name, symbol); + tuplesByName.Add(tupleWithSection.Name, tupleWithSection); } } } @@ -1242,7 +1242,7 @@ namespace WixToolset.Core /// /// Feature to feature complex references. /// All symbols loaded from the sections. - private void ResolveFeatureToFeatureConnects(ConnectToFeatureCollection featuresToFeatures, IDictionary allSymbols) + private void ResolveFeatureToFeatureConnects(ConnectToFeatureCollection featuresToFeatures, IDictionary allSymbols) { foreach (ConnectToFeature connection in featuresToFeatures) { @@ -1254,7 +1254,7 @@ namespace WixToolset.Core if (allSymbols.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var symbol)) { - var featureTuple = (FeatureTuple)symbol.Row; + var featureTuple = (FeatureTuple)symbol.Tuple; featureTuple.ParentFeatureRef = connection.PrimaryFeature; } } -- cgit v1.2.3-55-g6feb