From eff9d4204880535f821827e5aece5068402358f6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 6 Dec 2023 19:48:54 -0800 Subject: Introducing the WiX Standard Library Completes 7914 --- src/api/wix/WixToolset.Data/Intermediate.cs | 4 +- src/api/wix/WixToolset.Data/IntermediateSection.cs | 4 +- .../WindowsInstaller/WindowsInstallerStandard.cs | 115 +++++++++------- src/api/wix/WixToolset.Data/WixStandardLibrary.cs | 152 +++++++++++++++++++++ .../WixStandardLibraryIdentifiers.cs | 20 +++ .../WixToolset.Extensibility/Data/ILinkContext.cs | 10 ++ src/ext/UI/wixlib/WixUI_Minimal.wxs | 1 - .../CreateWindowsInstallerDataFromIRCommand.cs | 6 +- .../Decompile/Decompiler.cs | 4 +- .../WixToolset.Core/CommandLine/BuildCommand.cs | 9 ++ src/wix/WixToolset.Core/Compiler.cs | 2 +- src/wix/WixToolset.Core/Compiler_Module.cs | 2 + src/wix/WixToolset.Core/Compiler_Package.cs | 2 + .../Link/AddRequiredStandardDirectories.cs | 130 ------------------ src/wix/WixToolset.Core/LinkContext.cs | 4 + src/wix/WixToolset.Core/Linker.cs | 86 ++---------- .../LinkerFixture.cs | 1 + .../TestData/Variables/Package.wxs | 7 +- 18 files changed, 292 insertions(+), 267 deletions(-) create mode 100644 src/api/wix/WixToolset.Data/WixStandardLibrary.cs create mode 100644 src/api/wix/WixToolset.Data/WixStandardLibraryIdentifiers.cs delete mode 100644 src/wix/WixToolset.Core/Link/AddRequiredStandardDirectories.cs diff --git a/src/api/wix/WixToolset.Data/Intermediate.cs b/src/api/wix/WixToolset.Data/Intermediate.cs index 64f9810d..977f894a 100644 --- a/src/api/wix/WixToolset.Data/Intermediate.cs +++ b/src/api/wix/WixToolset.Data/Intermediate.cs @@ -215,9 +215,11 @@ namespace WixToolset.Data /// Updates the intermediate level to the specified level. /// /// Intermediate level. - public void UpdateLevel(string level) + public Intermediate UpdateLevel(string level) { this.Level = String.IsNullOrEmpty(this.Level) ? level : String.Concat(this.Level, ";", level); + + return this; } /// diff --git a/src/api/wix/WixToolset.Data/IntermediateSection.cs b/src/api/wix/WixToolset.Data/IntermediateSection.cs index b9157875..16d63a4c 100644 --- a/src/api/wix/WixToolset.Data/IntermediateSection.cs +++ b/src/api/wix/WixToolset.Data/IntermediateSection.cs @@ -70,9 +70,11 @@ namespace WixToolset.Data /// Assigns the section to a library. /// /// Identifier of the library. - public void AssignToLibrary(string libraryId) + public IntermediateSection AssignToLibrary(string libraryId) { this.LibraryId = libraryId; + + return this; } /// diff --git a/src/api/wix/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs b/src/api/wix/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs index 17267cf7..971a0416 100644 --- a/src/api/wix/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs +++ b/src/api/wix/WixToolset.Data/WindowsInstaller/WindowsInstallerStandard.cs @@ -11,7 +11,6 @@ namespace WixToolset.Data.WindowsInstaller { private static readonly Dictionary standardActionsById; private static readonly HashSet standardActionNames; - private static readonly Dictionary standardDirectoriesById; /// /// References: @@ -208,6 +207,41 @@ namespace WixToolset.Data.WindowsInstaller "WindowsVolume", }; + private static readonly Dictionary standardDirectoryNamesById = new Dictionary + { + ["TARGETDIR"] = "SourceDir", + ["AdminToolsFolder"] = "Admin", + ["AppDataFolder"] = "AppData", + ["CommonAppDataFolder"] = "CommApp", + ["CommonFilesFolder"] = "CFiles", + ["CommonFiles64Folder"] = "CFiles64", + ["CommonFiles6432Folder"] = ".", + ["DesktopFolder"] = "Desktop", + ["FavoritesFolder"] = "Favs", + ["FontsFolder"] = "Fonts", + ["LocalAppDataFolder"] = "LocalApp", + ["MyPicturesFolder"] = "Pictures", + ["NetHoodFolder"] = "NetHood", + ["PersonalFolder"] = "Personal", + ["PrintHoodFolder"] = "Printers", + ["ProgramFilesFolder"] = "PFiles", + ["ProgramFiles64Folder"] = "PFiles64", + ["ProgramFiles6432Folder"] = ".", + ["ProgramMenuFolder"] = "PMenu", + ["RecentFolder"] = "Recent", + ["SendToFolder"] = "SendTo", + ["StartMenuFolder"] = "StrtMenu", + ["StartupFolder"] = "StartUp", + ["SystemFolder"] = "System", + ["System16Folder"] = "System16", + ["System64Folder"] = "System64", + ["System6432Folder"] = ".", + ["TempFolder"] = "Temp", + ["TemplateFolder"] = "Template", + ["WindowsFolder"] = "Windows", + }; + + static WindowsInstallerStandard() { var standardActions = new[] @@ -332,43 +366,8 @@ namespace WixToolset.Data.WindowsInstaller new WixActionSymbol(null, new Identifier(AccessModifier.Virtual, "InstallExecuteSequence/InstallFinalize")) { Action="InstallFinalize", Sequence=6600, SequenceTable=SequenceTable.InstallExecuteSequence }, }; - var standardDirectories = new[] - { - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "TARGETDIR")) { Name = "SourceDir" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "AdminToolsFolder")) { Name = "Admin" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "AppDataFolder")) { Name = "AppData" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "CommonAppDataFolder")) { Name = "CommApp" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "CommonFilesFolder")) { Name = "CFiles" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "CommonFiles64Folder")) { Name = "CFiles64" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "CommonFiles6432Folder")) { Name = "." }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "DesktopFolder")) { Name = "Desktop" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "FavoritesFolder")) { Name = "Favs" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "FontsFolder")) { Name = "Fonts" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "LocalAppDataFolder")) { Name = "LocalApp" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "MyPicturesFolder")) { Name = "Pictures" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "NetHoodFolder")) { Name = "NetHood" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "PersonalFolder")) { Name = "Personal" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "PrintHoodFolder")) { Name = "Printers" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "ProgramFilesFolder")) { Name = "PFiles" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "ProgramFiles64Folder")) { Name = "PFiles64" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "ProgramFiles6432Folder")) { Name = "." }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "ProgramMenuFolder")) { Name = "PMenu" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "RecentFolder")) { Name = "Recent" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "SendToFolder")) { Name = "SendTo" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "StartMenuFolder")) { Name = "StrtMenu" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "StartupFolder")) { Name = "StartUp" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "SystemFolder")) { Name = "System" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "System16Folder")) { Name = "System16" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "System64Folder")) { Name = "System64" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "System6432Folder")) { Name = "." }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "TempFolder")) { Name = "Temp" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "TemplateFolder")) { Name = "Template" }, - new DirectorySymbol(null, new Identifier(AccessModifier.Virtual, "WindowsFolder")) { Name = "Windows" }, - }; - standardActionNames = new HashSet(standardActions.Select(a => a.Action)); standardActionsById = standardActions.ToDictionary(a => a.Id.Id); - standardDirectoriesById = standardDirectories.ToDictionary(d => d.Id.Id); } /// @@ -376,17 +375,26 @@ namespace WixToolset.Data.WindowsInstaller /// /// Name of the action. /// true if the action is standard, false otherwise. - public static bool IsStandardAction(string actionName) => standardActionNames.Contains(actionName); + public static bool IsStandardAction(string actionName) + { + return standardActionNames.Contains(actionName); + } /// /// Standard actions. /// - public static IReadOnlyCollection StandardActions() => standardActionsById.Values; + public static IReadOnlyCollection StandardActions() + { + return standardActionsById.Values; + } /// - /// Standard directories. + /// Standard directory identifiers. /// - public static IReadOnlyCollection StandardDirectories() => standardDirectoriesById.Values; + public static IReadOnlyCollection StandardDirectoryIds() + { + return standardDirectoryNamesById.Keys; + } /// /// Gets the platform specific directory id for a directory. Most directories are not platform @@ -418,28 +426,43 @@ namespace WixToolset.Data.WindowsInstaller /// /// Name of the directory. /// true if the directory is standard, false otherwise. - public static bool IsStandardDirectory(string directoryId) => standardDirectoriesById.ContainsKey(directoryId); + public static bool IsStandardDirectory(string directoryId) + { + return standardDirectoryNamesById.ContainsKey(directoryId); + } /// /// Find out if a property is a standard property. /// /// Name of the property. /// true if a property is standard, false otherwise. - public static bool IsStandardProperty(string propertyName) => standardProperties.Contains(propertyName); + public static bool IsStandardProperty(string propertyName) + { + return standardProperties.Contains(propertyName); + } /// /// Try to get standard action by id. /// - public static bool TryGetStandardAction(string id, out WixActionSymbol standardAction) => standardActionsById.TryGetValue(id, out standardAction); + public static bool TryGetStandardAction(string id, out WixActionSymbol standardAction) + { + return standardActionsById.TryGetValue(id, out standardAction); + } /// /// Try to get standard action by sequence and action name. /// - public static bool TryGetStandardAction(string sequenceName, string actioname, out WixActionSymbol standardAction) => standardActionsById.TryGetValue(String.Concat(sequenceName, "/", actioname), out standardAction); + public static bool TryGetStandardAction(string sequenceName, string actioname, out WixActionSymbol standardAction) + { + return standardActionsById.TryGetValue(String.Concat(sequenceName, "/", actioname), out standardAction); + } /// - /// Try to get standard directory symbol by id. + /// Try to get standard directory name by id. /// - public static bool TryGetStandardDirectory(string directoryId, out DirectorySymbol symbol) => standardDirectoriesById.TryGetValue(directoryId, out symbol); + public static bool TryGetStandardDirectoryName(string directoryId, out string name) + { + return standardDirectoryNamesById.TryGetValue(directoryId, out name); + } } } diff --git a/src/api/wix/WixToolset.Data/WixStandardLibrary.cs b/src/api/wix/WixToolset.Data/WixStandardLibrary.cs new file mode 100644 index 00000000..c5c9d8d4 --- /dev/null +++ b/src/api/wix/WixToolset.Data/WixStandardLibrary.cs @@ -0,0 +1,152 @@ +// 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.Data +{ + using System; + using System.Collections.Generic; + using System.Linq; + using WixToolset.Data.Bind; + using WixToolset.Data.Symbols; + using WixToolset.Data.WindowsInstaller; + + /// + /// WiX Standard Library implementation. + /// + public static class WixStandardLibrary + { + private const string WixStandardLibraryId = "wixstd"; + + /// + /// Build the wixstd.wixlib Intermediate. + /// + /// Target platform for the wixstd.wixlib + /// Intermediate containing the wixstd.wixlib. + public static Intermediate Build(Platform platform) + { + var localizations = YieldLocalizations(); + + var sections = YieldSections(platform); + + return new Intermediate(WixStandardLibraryId, IntermediateLevels.Combined, sections, localizations.ToDictionary(l => l.Culture, StringComparer.OrdinalIgnoreCase)); + } + + private static IEnumerable YieldLocalizations() + { + var strings = new BindVariable[0]; + + var localizedControls = new LocalizedControl[0]; + + yield return new Localization(LocalizationLocation.Library, null, null, String.Empty, strings.ToDictionary(s => s.Id), localizedControls.ToDictionary(l => l.GetKey())); + } + + private static IEnumerable YieldSections(Platform platform) + { + var sourceLineNumber = new SourceLineNumber("wixstd.wixlib"); + + // Actions. + foreach (var actionSymbol in WindowsInstallerStandard.StandardActions()) + { + var symbol = new WixActionSymbol(sourceLineNumber, new Identifier(actionSymbol.Id.Access, actionSymbol.Id.Id)) + { + Action = actionSymbol.Action, + SequenceTable = actionSymbol.SequenceTable, + Sequence = actionSymbol.Sequence, + Condition = actionSymbol.Condition, + }; + + var section = CreateSectionAroundSymbol(symbol); + + yield return section; + } + + // Directories. + foreach (var id in WindowsInstallerStandard.StandardDirectoryIds()) + { + var symbol = new DirectorySymbol(sourceLineNumber, new Identifier(AccessModifier.Virtual, id)) + { + ParentDirectoryRef = GetStandardDirectoryParent(id, platform), + Name = WindowsInstallerStandard.TryGetStandardDirectoryName(id, out var name) ? name : throw new InvalidOperationException("Standard directories must have a default name") + }; + + var section = CreateSectionAroundSymbol(symbol); + + // Add a reference for the more complicated parent directory references. + if (symbol.ParentDirectoryRef != null && symbol.ParentDirectoryRef != "TARGEDIR") + { + section.AddSymbol(new WixSimpleReferenceSymbol(sourceLineNumber) + { + Table = "Directory", + PrimaryKeys = symbol.ParentDirectoryRef + }); + } + + yield return section; + } + + // Package References. + { + var section = CreateSection(WixStandardLibraryIdentifiers.WixStandardPackageReferences); + + section.AddSymbol(new WixFragmentSymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardLibraryIdentifiers.WixStandardPackageReferences))); + + section.AddSymbol(new WixSimpleReferenceSymbol(sourceLineNumber) + { + Table = SymbolDefinitions.Directory.Name, + PrimaryKeys = "TARGETDIR" + }); + + yield return section; + } + + // Module References. + { + var section = CreateSection(WixStandardLibraryIdentifiers.WixStandardModuleReferences); + + section.AddSymbol(new WixFragmentSymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardLibraryIdentifiers.WixStandardModuleReferences))); + + section.AddSymbol(new WixSimpleReferenceSymbol(sourceLineNumber) + { + Table = SymbolDefinitions.Directory.Name, + PrimaryKeys = "TARGETDIR" + }); + + yield return section; + } + } + + private static IntermediateSection CreateSection(string sectionId) + { + return new IntermediateSection(sectionId, SectionType.Fragment, WixStandardLibraryId).AssignToLibrary(WixStandardLibraryId); + } + + private static IntermediateSection CreateSectionAroundSymbol(IntermediateSymbol symbol) + { + var section = CreateSection(symbol.Id.Id); + + section.AddSymbol(symbol); + + return section; + } + + private static string GetStandardDirectoryParent(string directoryId, Platform platform) + { + switch (directoryId) + { + case "TARGETDIR": + return null; + + case "CommonFiles6432Folder": + return platform == Platform.X86 ? "CommonFilesFolder" : "CommonFiles64Folder"; + + case "ProgramFiles6432Folder": + return platform == Platform.X86 ? "ProgramFilesFolder" : "ProgramFiles64Folder"; + + case "System6432Folder": + return platform == Platform.X86 ? "SystemFolder" : "System64Folder"; + + default: + return "TARGETDIR"; + } + } + } +} diff --git a/src/api/wix/WixToolset.Data/WixStandardLibraryIdentifiers.cs b/src/api/wix/WixToolset.Data/WixStandardLibraryIdentifiers.cs new file mode 100644 index 00000000..8c4ac08e --- /dev/null +++ b/src/api/wix/WixToolset.Data/WixStandardLibraryIdentifiers.cs @@ -0,0 +1,20 @@ +// 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.Data +{ + /// + /// Well-known identifier names from the wixstd.wixlib. + /// + public static class WixStandardLibraryIdentifiers + { + /// + /// WiX Standard references for packages. + /// + public static readonly string WixStandardPackageReferences = "WixStandardPackageReferences"; + + /// + /// WiX Standard references for modules. + /// + public static readonly string WixStandardModuleReferences = "WixStandardModuleReferences"; + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs index 8556d9eb..402d78fe 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs @@ -47,6 +47,16 @@ namespace WixToolset.Extensibility.Data /// string OutputPath { get; set; } + /// + /// Gets or sets the platform for the output. + /// + Platform Platform { get; set; } + + /// + /// Gets or sets whether to skip the standard wixlib. + /// + bool SkipStdWixlib { get; set; } + /// /// Symbol definition creator used to load extension data. /// diff --git a/src/ext/UI/wixlib/WixUI_Minimal.wxs b/src/ext/UI/wixlib/WixUI_Minimal.wxs index e6f3437a..80a011e6 100644 --- a/src/ext/UI/wixlib/WixUI_Minimal.wxs +++ b/src/ext/UI/wixlib/WixUI_Minimal.wxs @@ -59,7 +59,6 @@ Patch dialog sequence: - diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs index 234cad4a..5c2c40d1 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs @@ -550,11 +550,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else { - foreach (var standardDirectory in WindowsInstallerStandard.StandardDirectories()) + foreach (var standardDirectoryId in WindowsInstallerStandard.StandardDirectoryIds()) { - if (directoryId.StartsWith(standardDirectory.Id.Id, StringComparison.Ordinal)) + if (directoryId.StartsWith(standardDirectoryId, StringComparison.Ordinal)) { - this.Messaging.Write(WarningMessages.StandardDirectoryConflictInMergeModule(symbol.SourceLineNumbers, directoryId, standardDirectory.Id.Id)); + this.Messaging.Write(WarningMessages.StandardDirectoryConflictInMergeModule(symbol.SourceLineNumbers, directoryId, standardDirectoryId)); } } } diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs b/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs index 9701f958..71e1b22b 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs @@ -2280,10 +2280,10 @@ namespace WixToolset.Core.WindowsInstaller.Decompile xDirectory = xDirectory.Parent; } - if (xDirectory?.Name.LocalName == "StandardDirectory" && WindowsInstallerStandard.TryGetStandardDirectory(xDirectory.Attribute("Id").Value, out var standardDirectory)) + if (xDirectory?.Name.LocalName == "StandardDirectory" && WindowsInstallerStandard.TryGetStandardDirectoryName(xDirectory.Attribute("Id").Value, out var standardDirectoryName)) { sourcePath.Insert(0, Path.DirectorySeparatorChar); - sourcePath.Insert(0, standardDirectory.Name); + sourcePath.Insert(0, standardDirectoryName); } return sourcePath.ToString(); diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index 2ad18073..b0cd174a 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -61,6 +61,7 @@ namespace WixToolset.Core.CommandLine new CommandLineHelpSwitch("-loc", "Localization file to use in the build. By default, .wxl files are recognized as localization."), new CommandLineHelpSwitch("-lib", "Library file to use in the build. By default, .wixlib files are recognized as libraries."), new CommandLineHelpSwitch("-src", "Source file to use in the build. By default, .wxs files are recognized as source code."), + new CommandLineHelpSwitch("-nostdlib", "Skip use of WiX standard wixlib."), new CommandLineHelpSwitch("-out", "-o", "Path to output the build to."), new CommandLineHelpSwitch("-outputtype", "Explicitly set the output type if it cannot be determined from the output."), new CommandLineHelpSwitch("-pdb", "Optional path to output .wixpdb. Default will write .wixpdb beside output path."), @@ -278,6 +279,8 @@ namespace WixToolset.Core.CommandLine context.IntermediateFolder = this.IntermediateFolder; context.Intermediates = intermediates.Concat(libraries).ToList(); context.OutputPath = this.OutputPath; + context.Platform = this.Platform; + context.SkipStdWixlib = this.commandLine.SkipStdWixlib; context.SymbolDefinitionCreator = creator; context.CancellationToken = cancellationToken; @@ -530,6 +533,8 @@ namespace WixToolset.Core.CommandLine public string TrackingFile { get; private set; } + public bool SkipStdWixlib { get; set; } + public bool ResetAcls { get; set; } public CommandLine(IServiceProvider serviceProvider, IMessaging messaging) @@ -685,6 +690,10 @@ namespace WixToolset.Core.CommandLine parser.GetNextArgumentAsFilePathOrError(arg, "source code", this.SourceFilePaths); return true; + case "nostdlib": + this.SkipStdWixlib = true; + return true; + case "o": case "out": this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg, "output file"); diff --git a/src/wix/WixToolset.Core/Compiler.cs b/src/wix/WixToolset.Core/Compiler.cs index 73fd494d..6a01b0ef 100644 --- a/src/wix/WixToolset.Core/Compiler.cs +++ b/src/wix/WixToolset.Core/Compiler.cs @@ -7129,7 +7129,7 @@ namespace WixToolset.Core } else if (!WindowsInstallerStandard.IsStandardDirectory(id)) { - this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "Id", id, String.Join(", \"", WindowsInstallerStandard.StandardDirectories().Select(d => d.Id.Id)))); + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "Id", id, String.Join(", \"", WindowsInstallerStandard.StandardDirectoryIds()))); } foreach (var child in node.Elements()) diff --git a/src/wix/WixToolset.Core/Compiler_Module.cs b/src/wix/WixToolset.Core/Compiler_Module.cs index 0a547ad7..092f3473 100644 --- a/src/wix/WixToolset.Core/Compiler_Module.cs +++ b/src/wix/WixToolset.Core/Compiler_Module.cs @@ -285,6 +285,8 @@ namespace WixToolset.Core } this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, this.activeLanguage); + + this.Core.CreateSimpleReference(sourceLineNumbers, SymbolDefinitions.WixFragment, WixStandardLibraryIdentifiers.WixStandardModuleReferences); } } finally diff --git a/src/wix/WixToolset.Core/Compiler_Package.cs b/src/wix/WixToolset.Core/Compiler_Package.cs index bfc59c75..02ed9092 100644 --- a/src/wix/WixToolset.Core/Compiler_Package.cs +++ b/src/wix/WixToolset.Core/Compiler_Package.cs @@ -423,6 +423,8 @@ namespace WixToolset.Core SymbolPaths = symbols, }); } + + this.Core.CreateSimpleReference(sourceLineNumbers, SymbolDefinitions.WixFragment, WixStandardLibraryIdentifiers.WixStandardPackageReferences); } } finally diff --git a/src/wix/WixToolset.Core/Link/AddRequiredStandardDirectories.cs b/src/wix/WixToolset.Core/Link/AddRequiredStandardDirectories.cs deleted file mode 100644 index 38493648..00000000 --- a/src/wix/WixToolset.Core/Link/AddRequiredStandardDirectories.cs +++ /dev/null @@ -1,130 +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; - using System.Collections.Generic; - using System.Linq; - using WixToolset.Data; - using WixToolset.Data.Symbols; - using WixToolset.Data.WindowsInstaller; - - /// - /// Add referenced standard directory symbols, if not already present. - /// - internal class AddRequiredStandardDirectories - { - public AddRequiredStandardDirectories(IntermediateSection section, List references) - { - this.Section = section; - this.References = references; - } - - private IntermediateSection Section { get; } - - private List References { get; } - - public void Execute() - { - var platform = this.GetPlatformFromSection(); - - var directories = this.Section.Symbols.OfType().ToList(); - var directoryIds = new SortedSet(directories.Select(d => d.Id.Id)); - - // Ensure any standard directory references symbols are added. - foreach (var directoryReference in this.References.Where(r => r.Table == "Directory")) - { - this.EnsureStandardDirectoryAdded(directoryIds, directoryReference.PrimaryKeys, directoryReference.SourceLineNumbers, platform); - } - - foreach (var directory in directories) - { - var parentDirectoryId = directory.ParentDirectoryRef; - - if (String.IsNullOrEmpty(parentDirectoryId)) - { - parentDirectoryId = this.GetStandardDirectoryParent(directory.Id.Id, platform); - - directory.ParentDirectoryRef = parentDirectoryId; - - //if (directory.Id.Id != "TARGETDIR") - //{ - // directory.ParentDirectoryRef = "TARGETDIR"; - //} - } - - if (!String.IsNullOrEmpty(parentDirectoryId)) - { - this.EnsureStandardDirectoryAdded(directoryIds, parentDirectoryId, directory.SourceLineNumbers, platform); - } - } - - if (!directoryIds.Contains("TARGETDIR") && WindowsInstallerStandard.TryGetStandardDirectory("TARGETDIR", out var targetDir)) - { - directoryIds.Add(targetDir.Id.Id); - this.Section.AddSymbol(targetDir); - } - } - - private void EnsureStandardDirectoryAdded(ISet directoryIds, string directoryId, SourceLineNumber sourceLineNumbers, Platform platform) - { - if (!directoryIds.Contains(directoryId) && WindowsInstallerStandard.TryGetStandardDirectory(directoryId, out var standardDirectory)) - { - var parentDirectoryId = this.GetStandardDirectoryParent(directoryId, platform); - - var directory = new DirectorySymbol(sourceLineNumbers, standardDirectory.Id) - { - Name = standardDirectory.Name, - ParentDirectoryRef = parentDirectoryId, - }; - - directoryIds.Add(directory.Id.Id); - this.Section.AddSymbol(directory); - - if (!String.IsNullOrEmpty(parentDirectoryId)) - { - this.EnsureStandardDirectoryAdded(directoryIds, parentDirectoryId, sourceLineNumbers, platform); - } - } - } - - private string GetStandardDirectoryParent(string directoryId, Platform platform) - { - switch (directoryId) - { - case "TARGETDIR": - return null; - - case "CommonFiles6432Folder": - case "ProgramFiles6432Folder": - case "System6432Folder": - return WindowsInstallerStandard.GetPlatformSpecificDirectoryId(directoryId, platform); - - default: - return "TARGETDIR"; - } - } - - private Platform GetPlatformFromSection() - { - var symbol = this.Section.Symbols.OfType().First(p => p.PropertyId == SummaryInformationType.PlatformAndLanguage); - - var value = symbol.Value; - var separatorIndex = value.IndexOf(';'); - var platformValue = separatorIndex > 0 ? value.Substring(0, separatorIndex) : value; - - switch (platformValue) - { - case "x64": - return Platform.X64; - - case "Arm64": - return Platform.ARM64; - - case "Intel": - default: - return Platform.X86; - } - } - } -} diff --git a/src/wix/WixToolset.Core/LinkContext.cs b/src/wix/WixToolset.Core/LinkContext.cs index 10223171..dd004817 100644 --- a/src/wix/WixToolset.Core/LinkContext.cs +++ b/src/wix/WixToolset.Core/LinkContext.cs @@ -30,6 +30,10 @@ namespace WixToolset.Core public string OutputPath { get; set; } + public Platform Platform { get; set; } + + public bool SkipStdWixlib { get; set; } + public ISymbolDefinitionCreator SymbolDefinitionCreator { get; set; } public CancellationToken CancellationToken { get; set; } diff --git a/src/wix/WixToolset.Core/Linker.cs b/src/wix/WixToolset.Core/Linker.cs index 85333da4..0cef88d2 100644 --- a/src/wix/WixToolset.Core/Linker.cs +++ b/src/wix/WixToolset.Core/Linker.cs @@ -11,7 +11,6 @@ namespace WixToolset.Core using WixToolset.Core.Link; using WixToolset.Data; using WixToolset.Data.Symbols; - using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -98,8 +97,13 @@ namespace WixToolset.Core } } - // TODO: Replace this with "std.wixlib" - this.LoadStandardSymbols(sections); + // Load the standard wixlib. + if (!this.Context.SkipStdWixlib) + { + var stdlib = WixStandardLibrary.Build(this.Context.Platform); + + sections.AddRange(stdlib.Sections); + } var multipleFeatureComponents = new Hashtable(); @@ -122,9 +126,6 @@ namespace WixToolset.Core } } - ////// Add the missing standard action and directory symbols. - ////this.LoadStandardSymbols(find.SymbolsByName); - // Resolve the symbol 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.SymbolsByName); @@ -187,7 +188,6 @@ namespace WixToolset.Core // Create a new section to hold the linked content. Start with the entry section's // metadata. var resolvedSection = new IntermediateSection(find.EntrySection.Id, find.EntrySection.Type); - var references = new List(); var identicalDirectoryIds = new HashSet(StringComparer.Ordinal); foreach (var section in sections) @@ -263,13 +263,9 @@ namespace WixToolset.Core } break; - case SymbolDefinitionType.WixComplexReference: - copySymbol = false; - break; - case SymbolDefinitionType.WixSimpleReference: + case SymbolDefinitionType.WixComplexReference: copySymbol = false; - references.Add(symbol as WixSimpleReferenceSymbol); break; case SymbolDefinitionType.WixVariable: @@ -310,12 +306,6 @@ namespace WixToolset.Core var command = new FlattenAndProcessBundleTablesCommand(resolvedSection, this.Messaging); command.Execute(); } - else if (resolvedSection.Type == SectionType.Package || resolvedSection.Type == SectionType.Module) - { - // Packages and modules get standard directories add. - var command = new AddRequiredStandardDirectories(resolvedSection, references); - command.Execute(); - } if (this.Messaging.EncounteredError) { @@ -364,66 +354,6 @@ namespace WixToolset.Core } } - /// - /// Load the standard action and directory symbols. - /// - /// Collection of symbols. - //private void LoadStandardSymbols(IDictionary symbolsByName) - //{ - // foreach (var actionSymbol in WindowsInstallerStandard.StandardActions()) - // { - // var symbolWithSection = new SymbolWithSection(null, actionSymbol); - // var fullName = symbolWithSection.GetFullName(); - - // // If the action's symbol has not already been defined (i.e. overriden by the user), add it now. - // if (!symbolsByName.ContainsKey(fullName)) - // { - // symbolsByName.Add(fullName, symbolWithSection); - // } - // } - - // foreach (var directorySymbol in WindowsInstallerStandard.StandardDirectories()) - // { - // var symbolWithSection = new SymbolWithSection(null, directorySymbol); - // var fullName = symbolWithSection.GetFullName(); - - // // If the directory's symbol has not already been defined (i.e. overriden by the user), add it now. - // if (!symbolsByName.ContainsKey(fullName)) - // { - // symbolsByName.Add(fullName, symbolWithSection); - // } - // } - //} - - private void LoadStandardSymbols(List sections) - { - foreach (var actionSymbol in WindowsInstallerStandard.StandardActions()) - { - var section = new IntermediateSection(actionSymbol.Id.Id, SectionType.Fragment); - section.AddSymbol(new WixActionSymbol(null, new Identifier(actionSymbol.Id.Access, actionSymbol.Id.Id)) - { - Action = actionSymbol.Action, - SequenceTable = actionSymbol.SequenceTable, - Sequence = actionSymbol.Sequence, - Condition = actionSymbol.Condition, - }); - - sections.Add(section); - } - - foreach (var directorySymbol in WindowsInstallerStandard.StandardDirectories()) - { - var section = new IntermediateSection(directorySymbol.Id.Id, SectionType.Fragment); - section.AddSymbol(new DirectorySymbol(null, new Identifier(directorySymbol.Id.Access, directorySymbol.Id.Id)) - { - Name = directorySymbol.Name - }); - - sections.Add(section); - } - } - - /// /// Process the complex references. /// diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs index 3667a2f2..e42c7810 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs @@ -35,6 +35,7 @@ namespace WixToolsetTest.CoreIntegration context.IntermediateFolder = Path.GetTempPath(); context.Intermediates = new[] { intermediate1, intermediate2 }; context.OutputPath = Path.Combine(context.IntermediateFolder, "test.msi"); + context.Platform = Platform.X64; context.SymbolDefinitionCreator = creator; var linker = serviceProvider.GetService(); diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.wxs index 7de55810..bcbdb00f 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.wxs @@ -1,4 +1,4 @@ - + @@ -12,7 +12,6 @@ - @@ -22,8 +21,8 @@ - - + + -- cgit v1.2.3-55-g6feb