aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2023-01-15 20:29:17 -0600
committerSean Hall <r.sean.hall@gmail.com>2023-01-15 22:03:31 -0600
commitf4329d17538c14569ab7058c1c378aa5b2297b2c (patch)
treecfd3621d068f082d254dd6f6b2ce08f85ca85971 /src/tools
parentfb8903d9a185a020d54d2bb001f4331caf7c3825 (diff)
downloadwix-f4329d17538c14569ab7058c1c378aa5b2297b2c.tar.gz
wix-f4329d17538c14569ab7058c1c378aa5b2297b2c.tar.bz2
wix-f4329d17538c14569ab7058c1c378aa5b2297b2c.zip
Implement SourceDir substitution for Payloads.
7160
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/heat/UtilFinalizeHarvesterMutator.cs35
-rw-r--r--src/tools/test/WixToolsetTest.Heat/DirectoryToPayloadGroupFixture.cs80
2 files changed, 115 insertions, 0 deletions
diff --git a/src/tools/heat/UtilFinalizeHarvesterMutator.cs b/src/tools/heat/UtilFinalizeHarvesterMutator.cs
index 61bb8731..d41d6e1e 100644
--- a/src/tools/heat/UtilFinalizeHarvesterMutator.cs
+++ b/src/tools/heat/UtilFinalizeHarvesterMutator.cs
@@ -25,6 +25,7 @@ namespace WixToolset.Harvesters
25 private Hashtable filePaths; 25 private Hashtable filePaths;
26 private ArrayList files; 26 private ArrayList files;
27 private ArrayList registryValues; 27 private ArrayList registryValues;
28 private List<Wix.Payload> payloads;
28 private bool suppressCOMElements; 29 private bool suppressCOMElements;
29 private bool suppressVB6COMElements; 30 private bool suppressVB6COMElements;
30 private string preprocessorVariable; 31 private string preprocessorVariable;
@@ -40,6 +41,7 @@ namespace WixToolset.Harvesters
40 this.filePaths = new Hashtable(); 41 this.filePaths = new Hashtable();
41 this.files = new ArrayList(); 42 this.files = new ArrayList();
42 this.registryValues = new ArrayList(); 43 this.registryValues = new ArrayList();
44 this.payloads = new List<Wix.Payload>();
43 } 45 }
44 46
45 /// <summary> 47 /// <summary>
@@ -93,6 +95,7 @@ namespace WixToolset.Harvesters
93 this.filePaths.Clear(); 95 this.filePaths.Clear();
94 this.files.Clear(); 96 this.files.Clear();
95 this.registryValues.Clear(); 97 this.registryValues.Clear();
98 this.payloads.Clear();
96 99
97 // index elements in this wix document 100 // index elements in this wix document
98 this.IndexElement(wix); 101 this.IndexElement(wix);
@@ -100,6 +103,7 @@ namespace WixToolset.Harvesters
100 this.MutateDirectories(); 103 this.MutateDirectories();
101 this.MutateFiles(); 104 this.MutateFiles();
102 this.MutateRegistryValues(); 105 this.MutateRegistryValues();
106 this.MutatePayloads();
103 107
104 // must occur after all the registry values have been formatted 108 // must occur after all the registry values have been formatted
105 this.MutateComponents(); 109 this.MutateComponents();
@@ -131,6 +135,10 @@ namespace WixToolset.Harvesters
131 { 135 {
132 this.registryValues.Add(element); 136 this.registryValues.Add(element);
133 } 137 }
138 else if (element is Wix.Payload payloadElement)
139 {
140 this.payloads.Add(payloadElement);
141 }
134 142
135 // index the child elements 143 // index the child elements
136 if (element is Wix.IParentElement) 144 if (element is Wix.IParentElement)
@@ -1006,6 +1014,33 @@ namespace WixToolset.Harvesters
1006 } 1014 }
1007 1015
1008 /// <summary> 1016 /// <summary>
1017 /// Mutate the payloads.
1018 /// </summary>
1019 private void MutatePayloads()
1020 {
1021 string sourceDirSubstitution = this.preprocessorVariable;
1022 if (sourceDirSubstitution == null)
1023 {
1024 return;
1025 }
1026
1027 string prefix = "$(";
1028 if (sourceDirSubstitution.StartsWith("wix.", StringComparison.Ordinal))
1029 {
1030 prefix = "!(";
1031 }
1032 sourceDirSubstitution = String.Concat(prefix, sourceDirSubstitution, ")");
1033
1034 foreach (var payload in this.payloads)
1035 {
1036 if (payload.SourceFile != null && payload.SourceFile.StartsWith("SourceDir\\", StringComparison.Ordinal))
1037 {
1038 payload.SourceFile = payload.SourceFile.Substring(9).Insert(0, sourceDirSubstitution);
1039 }
1040 }
1041 }
1042
1043 /// <summary>
1009 /// Mutate an individual registry string, according to a collection of replacement items. 1044 /// Mutate an individual registry string, according to a collection of replacement items.
1010 /// </summary> 1045 /// </summary>
1011 /// <param name="value">The string to mutate.</param> 1046 /// <param name="value">The string to mutate.</param>
diff --git a/src/tools/test/WixToolsetTest.Heat/DirectoryToPayloadGroupFixture.cs b/src/tools/test/WixToolsetTest.Heat/DirectoryToPayloadGroupFixture.cs
new file mode 100644
index 00000000..c9b8ee30
--- /dev/null
+++ b/src/tools/test/WixToolsetTest.Heat/DirectoryToPayloadGroupFixture.cs
@@ -0,0 +1,80 @@
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 WixToolsetTest.Heat
4{
5 using System;
6 using System.IO;
7 using System.Linq;
8 using WixInternal.TestSupport;
9 using Xunit;
10
11 public class DirectoryToPayloadGroupFixture
12 {
13 [Fact]
14 public void CanHarvestSimpleDirectory()
15 {
16 var folder = TestData.Get("TestData", "SingleFile");
17
18 using (var fs = new DisposableFileSystem())
19 {
20 var outputPath = Path.Combine(fs.GetFolder(), "out.wxs");
21
22 var args = new[]
23 {
24 "dir", folder,
25 "-generate", "payloadgroup",
26 "-o", outputPath
27 };
28
29 var result = HeatRunner.Execute(args);
30 result.AssertSuccess();
31
32 var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray();
33 WixAssert.CompareLineByLine(new[]
34 {
35 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
36 " <Fragment>",
37 " <PayloadGroup Id='TARGETDIR'>",
38 " <Payload SourceFile='SourceDir\\a.txt' />",
39 " </PayloadGroup>",
40 " </Fragment>",
41 "</Wix>",
42 }, wxs);
43 }
44 }
45
46 [Fact]
47 public void CanHarvestSimpleDirectoryWithSourceDirSubstitution()
48 {
49 var folder = TestData.Get("TestData", "SingleFile");
50
51 using (var fs = new DisposableFileSystem())
52 {
53 var outputPath = Path.Combine(fs.GetFolder(), "out.wxs");
54
55 var args = new[]
56 {
57 "dir", folder,
58 "-generate", "payloadgroup",
59 "-var", "var.RootDir",
60 "-o", outputPath
61 };
62
63 var result = HeatRunner.Execute(args);
64 result.AssertSuccess();
65
66 var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray();
67 WixAssert.CompareLineByLine(new[]
68 {
69 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
70 " <Fragment>",
71 " <PayloadGroup Id='TARGETDIR'>",
72 " <Payload SourceFile='$(var.RootDir)\\a.txt' />",
73 " </PayloadGroup>",
74 " </Fragment>",
75 "</Wix>",
76 }, wxs);
77 }
78 }
79 }
80}