diff options
author | Bob Arnson <bob@firegiant.com> | 2020-02-06 22:04:55 -0500 |
---|---|---|
committer | Bob Arnson <bob@firegiant.com> | 2020-02-07 22:00:52 -0500 |
commit | 57559c253fe8ec6f9c66662d11fbcabccc3ba057 (patch) | |
tree | 60c7b4da6bbb6fe0090498e60fdfbcb769a1af0b /src | |
parent | 9feb0090d2cdd0979bea90ba9aa13dc541f47054 (diff) | |
download | wix-57559c253fe8ec6f9c66662d11fbcabccc3ba057.tar.gz wix-57559c253fe8ec6f9c66662d11fbcabccc3ba057.tar.bz2 wix-57559c253fe8ec6f9c66662d11fbcabccc3ba057.zip |
Add CreateFolder tuples for null-keypath components in the backend instead of the compiler.
Diffstat (limited to 'src')
9 files changed, 126 insertions, 17 deletions
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 @@ | |||
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.Collections.Generic; | ||
6 | using System.Linq; | ||
7 | using WixToolset.Data; | ||
8 | using WixToolset.Data.Tuples; | ||
9 | |||
10 | /// <summary> | ||
11 | /// Add CreateFolder tuples, if not already present, for null-keypath components. | ||
12 | /// </summary> | ||
13 | internal class AddCreateFoldersCommand | ||
14 | { | ||
15 | internal AddCreateFoldersCommand(IntermediateSection section) | ||
16 | { | ||
17 | this.Section = section; | ||
18 | } | ||
19 | |||
20 | private IntermediateSection Section { get; } | ||
21 | |||
22 | public void Execute() | ||
23 | { | ||
24 | var createFolderTuplesByComponentRef = new HashSet<string>(this.Section.Tuples.OfType<CreateFolderTuple>().Select(t => t.ComponentRef)); | ||
25 | foreach (var componentTuple in this.Section.Tuples.OfType<ComponentTuple>().Where(t => t.KeyPathType == ComponentKeyPathType.Directory).ToList()) | ||
26 | { | ||
27 | if (!createFolderTuplesByComponentRef.Contains(componentTuple.Id.Id)) | ||
28 | { | ||
29 | var createFolderTuple = new CreateFolderTuple(componentTuple.SourceLineNumbers) | ||
30 | { | ||
31 | DirectoryRef = componentTuple.DirectoryRef, | ||
32 | ComponentRef = componentTuple.Id.Id, | ||
33 | }; | ||
34 | |||
35 | this.Section.Tuples.Add(createFolderTuple); | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | } \ 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 | |||
338 | command.Execute(); | 338 | command.Execute(); |
339 | } | 339 | } |
340 | 340 | ||
341 | // Add missing CreateFolder tuples to null-keypath components. | ||
342 | { | ||
343 | var command = new AddCreateFoldersCommand(section); | ||
344 | command.Execute(); | ||
345 | } | ||
346 | |||
341 | // stop processing if an error previously occurred | 347 | // stop processing if an error previously occurred |
342 | if (this.Messaging.EncounteredError) | 348 | if (this.Messaging.EncounteredError) |
343 | { | 349 | { |
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 | |||
2126 | var id = new Identifier(AccessModifier.Private, componentIdPlaceholderWixVariable); | 2126 | var id = new Identifier(AccessModifier.Private, componentIdPlaceholderWixVariable); |
2127 | var keyFound = false; | 2127 | var keyFound = false; |
2128 | string keyPath = null; | 2128 | string keyPath = null; |
2129 | var shouldAddCreateFolder = false; | ||
2130 | 2129 | ||
2131 | var keyPathType = ComponentKeyPathType.Directory; | 2130 | var keyPathType = ComponentKeyPathType.Directory; |
2132 | var location = ComponentLocation.LocalOnly; | 2131 | var location = ComponentLocation.LocalOnly; |
@@ -2181,7 +2180,6 @@ namespace WixToolset.Core | |||
2181 | { | 2180 | { |
2182 | keyFound = true; | 2181 | keyFound = true; |
2183 | keyPath = null; | 2182 | keyPath = null; |
2184 | shouldAddCreateFolder = true; | ||
2185 | } | 2183 | } |
2186 | break; | 2184 | break; |
2187 | case "Location": | 2185 | case "Location": |
@@ -2343,10 +2341,6 @@ namespace WixToolset.Core | |||
2343 | break; | 2341 | break; |
2344 | case "CreateFolder": | 2342 | case "CreateFolder": |
2345 | var createdFolder = this.ParseCreateFolderElement(child, id.Id, directoryId, win64); | 2343 | var createdFolder = this.ParseCreateFolderElement(child, id.Id, directoryId, win64); |
2346 | if (directoryId == createdFolder) | ||
2347 | { | ||
2348 | shouldAddCreateFolder = false; | ||
2349 | } | ||
2350 | break; | 2344 | break; |
2351 | case "Environment": | 2345 | case "Environment": |
2352 | this.ParseEnvironmentElement(child, id.Id); | 2346 | this.ParseEnvironmentElement(child, id.Id); |
@@ -2479,17 +2473,6 @@ namespace WixToolset.Core | |||
2479 | } | 2473 | } |
2480 | } | 2474 | } |
2481 | 2475 | ||
2482 | if (shouldAddCreateFolder) | ||
2483 | { | ||
2484 | var tuple = new CreateFolderTuple(sourceLineNumbers) | ||
2485 | { | ||
2486 | DirectoryRef = directoryId, | ||
2487 | ComponentRef = id.Id | ||
2488 | }; | ||
2489 | |||
2490 | this.Core.AddTuple(tuple); | ||
2491 | } | ||
2492 | |||
2493 | // check for conditions that exclude this component from using generated guids | 2476 | // check for conditions that exclude this component from using generated guids |
2494 | var isGeneratableGuidOk = "*" == guid; | 2477 | var isGeneratableGuidOk = "*" == guid; |
2495 | if (isGeneratableGuidOk) | 2478 | 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 | |||
@@ -253,6 +253,39 @@ namespace WixToolsetTest.CoreIntegration | |||
253 | } | 253 | } |
254 | 254 | ||
255 | [Fact] | 255 | [Fact] |
256 | public void PopulatesCreateFolderTableForNullKeypathComponents() | ||
257 | { | ||
258 | var folder = TestData.Get(@"TestData\Components"); | ||
259 | |||
260 | using (var fs = new DisposableFileSystem()) | ||
261 | { | ||
262 | var baseFolder = fs.GetFolder(); | ||
263 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
264 | var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); | ||
265 | |||
266 | var result = WixRunner.Execute(new[] | ||
267 | { | ||
268 | "build", | ||
269 | Path.Combine(folder, "Package.wxs"), | ||
270 | Path.Combine(folder, "PackageComponents.wxs"), | ||
271 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), | ||
272 | "-bindpath", Path.Combine(folder, "data"), | ||
273 | "-intermediateFolder", intermediateFolder, | ||
274 | "-o", msiPath | ||
275 | }); | ||
276 | |||
277 | result.AssertSuccess(); | ||
278 | |||
279 | Assert.True(File.Exists(msiPath)); | ||
280 | var results = Query.QueryDatabase(msiPath, new[] { "CreateFolder" }); | ||
281 | Assert.Equal(new[] | ||
282 | { | ||
283 | "CreateFolder:INSTALLFOLDER\tNullKeypathComponent", | ||
284 | }, results); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | [Fact] | ||
256 | public void PopulatesCustomActionTable() | 289 | public void PopulatesCustomActionTable() |
257 | { | 290 | { |
258 | var folder = TestData.Get(@"TestData"); | 291 | var folder = TestData.Get(@"TestData"); |
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 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | |||
3 | <!-- | ||
4 | This file contains the declaration of all the localizable strings. | ||
5 | --> | ||
6 | <WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US"> | ||
7 | |||
8 | <String Id="DowngradeError">A newer version of [ProductName] is already installed.</String> | ||
9 | <String Id="FeatureTitle">MsiPackage</String> | ||
10 | |||
11 | </WixLocalization> | ||
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 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
3 | <Product Id="*" Name="MsiPackage" Codepage="1252" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"> | ||
4 | <Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" /> | ||
5 | |||
6 | <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" /> | ||
7 | <MediaTemplate /> | ||
8 | |||
9 | <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)"> | ||
10 | <ComponentGroupRef Id="ProductComponents" /> | ||
11 | </Feature> | ||
12 | </Product> | ||
13 | |||
14 | <Fragment> | ||
15 | <Directory Id="TARGETDIR" Name="SourceDir"> | ||
16 | <Directory Id="ProgramFilesFolder"> | ||
17 | <Directory Id="INSTALLFOLDER" Name="MsiPackage" /> | ||
18 | </Directory> | ||
19 | </Directory> | ||
20 | </Fragment> | ||
21 | </Wix> | ||
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 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
3 | <Fragment> | ||
4 | <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> | ||
5 | <Component Id="NullKeypathComponent" Guid="{C493379B-D655-4331-8F03-B618C70EA779}" KeyPath="yes"> | ||
6 | <File Source="test.txt" /> | ||
7 | </Component> | ||
8 | </ComponentGroup> | ||
9 | </Fragment> | ||
10 | </Wix> | ||
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 @@ | |||
156 | <Content Include="TestData\ProgId\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | 156 | <Content Include="TestData\ProgId\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> |
157 | <Content Include="TestData\ProgId\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | 157 | <Content Include="TestData\ProgId\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> |
158 | <Content Include="TestData\ProgId\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> | 158 | <Content Include="TestData\ProgId\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> |
159 | <Content Include="TestData\Components\data\test.txt" CopyToOutputDirectory="PreserveNewest" /> | ||
160 | <Content Include="TestData\Components\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | ||
161 | <Content Include="TestData\Components\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
162 | <Content Include="TestData\Components\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
159 | </ItemGroup> | 163 | </ItemGroup> |
160 | 164 | ||
161 | <ItemGroup> | 165 | <ItemGroup> |