From 57559c253fe8ec6f9c66662d11fbcabccc3ba057 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Thu, 6 Feb 2020 22:04:55 -0500 Subject: Add CreateFolder tuples for null-keypath components in the backend instead of the compiler. --- .../Bind/AddCreateFoldersCommand.cs | 40 ++++++++++++++++++++++ .../Bind/BindDatabaseCommand.cs | 6 ++++ src/WixToolset.Core/Compiler.cs | 17 --------- .../MsiQueryFixture.cs | 33 ++++++++++++++++++ .../TestData/Components/Package.en-us.wxl | 11 ++++++ .../TestData/Components/Package.wxs | 21 ++++++++++++ .../TestData/Components/PackageComponents.wxs | 10 ++++++ .../TestData/Components/data/test.txt | 1 + .../WixToolsetTest.CoreIntegration.csproj | 4 +++ 9 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.en-us.wxl create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Components/PackageComponents.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Components/data/test.txt (limited to 'src') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs new file mode 100644 index 00000000..6cc4153f --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs @@ -0,0 +1,40 @@ +// 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.WindowsInstaller.Bind +{ + using System.Collections.Generic; + using System.Linq; + using WixToolset.Data; + using WixToolset.Data.Tuples; + + /// + /// Add CreateFolder tuples, if not already present, for null-keypath components. + /// + internal class AddCreateFoldersCommand + { + internal AddCreateFoldersCommand(IntermediateSection section) + { + this.Section = section; + } + + private IntermediateSection Section { get; } + + public void Execute() + { + var createFolderTuplesByComponentRef = new HashSet(this.Section.Tuples.OfType().Select(t => t.ComponentRef)); + foreach (var componentTuple in this.Section.Tuples.OfType().Where(t => t.KeyPathType == ComponentKeyPathType.Directory).ToList()) + { + if (!createFolderTuplesByComponentRef.Contains(componentTuple.Id.Id)) + { + var createFolderTuple = new CreateFolderTuple(componentTuple.SourceLineNumbers) + { + DirectoryRef = componentTuple.DirectoryRef, + ComponentRef = componentTuple.Id.Id, + }; + + this.Section.Tuples.Add(createFolderTuple); + } + } + } + } +} \ No newline at end of file diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 34104ef5..1bcaf209 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -338,6 +338,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind command.Execute(); } + // Add missing CreateFolder tuples to null-keypath components. + { + var command = new AddCreateFoldersCommand(section); + command.Execute(); + } + // stop processing if an error previously occurred if (this.Messaging.EncounteredError) { diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index cee64911..6fd0f30b 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -2126,7 +2126,6 @@ namespace WixToolset.Core var id = new Identifier(AccessModifier.Private, componentIdPlaceholderWixVariable); var keyFound = false; string keyPath = null; - var shouldAddCreateFolder = false; var keyPathType = ComponentKeyPathType.Directory; var location = ComponentLocation.LocalOnly; @@ -2181,7 +2180,6 @@ namespace WixToolset.Core { keyFound = true; keyPath = null; - shouldAddCreateFolder = true; } break; case "Location": @@ -2343,10 +2341,6 @@ namespace WixToolset.Core break; case "CreateFolder": var createdFolder = this.ParseCreateFolderElement(child, id.Id, directoryId, win64); - if (directoryId == createdFolder) - { - shouldAddCreateFolder = false; - } break; case "Environment": this.ParseEnvironmentElement(child, id.Id); @@ -2479,17 +2473,6 @@ namespace WixToolset.Core } } - if (shouldAddCreateFolder) - { - var tuple = new CreateFolderTuple(sourceLineNumbers) - { - DirectoryRef = directoryId, - ComponentRef = id.Id - }; - - this.Core.AddTuple(tuple); - } - // check for conditions that exclude this component from using generated guids var isGeneratableGuidOk = "*" == guid; if (isGeneratableGuidOk) diff --git a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs index 38ef2e2e..6fd02d5f 100644 --- a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs @@ -252,6 +252,39 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void PopulatesCreateFolderTableForNullKeypathComponents() + { + var folder = TestData.Get(@"TestData\Components"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Package.wxs"), + Path.Combine(folder, "PackageComponents.wxs"), + "-loc", Path.Combine(folder, "Package.en-us.wxl"), + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(msiPath)); + var results = Query.QueryDatabase(msiPath, new[] { "CreateFolder" }); + Assert.Equal(new[] + { + "CreateFolder:INSTALLFOLDER\tNullKeypathComponent", + }, results); + } + } + [Fact] public void PopulatesCustomActionTable() { diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.en-us.wxl b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.en-us.wxl new file mode 100644 index 00000000..38c12ac1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.en-us.wxl @@ -0,0 +1,11 @@ + + + + + + A newer version of [ProductName] is already installed. + MsiPackage + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.wxs new file mode 100644 index 00000000..6da3dcbe --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/Package.wxs @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Components/PackageComponents.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/PackageComponents.wxs new file mode 100644 index 00000000..beaf70bf --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/PackageComponents.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Components/data/test.txt b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/data/test.txt new file mode 100644 index 00000000..cd0db0e1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Components/data/test.txt @@ -0,0 +1 @@ +This is test.txt. \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index b17a27ff..a64ff93d 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj @@ -156,6 +156,10 @@ + + + + -- cgit v1.2.3-55-g6feb