aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-12-06 14:10:10 -0800
committerRob Mensching <rob@firegiant.com>2022-12-06 17:29:07 -0800
commitf2e5bdc263b8f6def149c918c332bd0d66fb6c1f (patch)
tree486e397a44eb0d2bb9fb6245dbf96b4e581848c6 /src
parentc4c37a053b20eb61d36afde02ef7a82198711e56 (diff)
downloadwix-f2e5bdc263b8f6def149c918c332bd0d66fb6c1f.tar.gz
wix-f2e5bdc263b8f6def149c918c332bd0d66fb6c1f.tar.bz2
wix-f2e5bdc263b8f6def149c918c332bd0d66fb6c1f.zip
Remove DirectoryRef to TARGETDIR
Fixes 7061
Diffstat (limited to 'src')
-rw-r--r--src/wix/WixToolset.Converters/WixConverter.cs37
-rw-r--r--src/wix/test/WixToolsetTest.Converters/ConverterFixture.cs6
-rw-r--r--src/wix/test/WixToolsetTest.Converters/DirectoryFixture.cs78
3 files changed, 117 insertions, 4 deletions
diff --git a/src/wix/WixToolset.Converters/WixConverter.cs b/src/wix/WixToolset.Converters/WixConverter.cs
index 4e20ff14..59bbb7c4 100644
--- a/src/wix/WixToolset.Converters/WixConverter.cs
+++ b/src/wix/WixToolset.Converters/WixConverter.cs
@@ -92,6 +92,7 @@ namespace WixToolset.Converters
92 private static readonly XName OldRequiresElementName = WixDependencyNamespace + "Requires"; 92 private static readonly XName OldRequiresElementName = WixDependencyNamespace + "Requires";
93 private static readonly XName OldRequiresRefElementName = WixDependencyNamespace + "RequiresRef"; 93 private static readonly XName OldRequiresRefElementName = WixDependencyNamespace + "RequiresRef";
94 private static readonly XName DirectoryElementName = WixNamespace + "Directory"; 94 private static readonly XName DirectoryElementName = WixNamespace + "Directory";
95 private static readonly XName DirectoryRefElementName = WixNamespace + "DirectoryRef";
95 private static readonly XName EmbeddedChainerElementName = WixNamespace + "EmbeddedChainer"; 96 private static readonly XName EmbeddedChainerElementName = WixNamespace + "EmbeddedChainer";
96 private static readonly XName ErrorElementName = WixNamespace + "Error"; 97 private static readonly XName ErrorElementName = WixNamespace + "Error";
97 private static readonly XName FeatureElementName = WixNamespace + "Feature"; 98 private static readonly XName FeatureElementName = WixNamespace + "Feature";
@@ -288,6 +289,7 @@ namespace WixToolset.Converters
288 { WixConverter.CustomTableElementName, this.ConvertCustomTableElement }, 289 { WixConverter.CustomTableElementName, this.ConvertCustomTableElement },
289 { WixConverter.DataElementName, this.ConvertDataElement }, 290 { WixConverter.DataElementName, this.ConvertDataElement },
290 { WixConverter.DirectoryElementName, this.ConvertDirectoryElement }, 291 { WixConverter.DirectoryElementName, this.ConvertDirectoryElement },
292 { WixConverter.DirectoryRefElementName, this.ConvertDirectoryRefElement },
291 { WixConverter.FeatureElementName, this.ConvertFeatureElement }, 293 { WixConverter.FeatureElementName, this.ConvertFeatureElement },
292 { WixConverter.FileElementName, this.ConvertFileElement }, 294 { WixConverter.FileElementName, this.ConvertFileElement },
293 { WixConverter.FragmentElementName, this.ConvertFragmentElement }, 295 { WixConverter.FragmentElementName, this.ConvertFragmentElement },
@@ -1129,6 +1131,36 @@ namespace WixToolset.Converters
1129 } 1131 }
1130 } 1132 }
1131 1133
1134 private void ConvertDirectoryRefElement(XElement element)
1135 {
1136 var id = element.Attribute("Id")?.Value;
1137
1138 if (id == "TARGETDIR" &&
1139 this.OnInformation(ConverterTestType.TargetDirRefDeprecated, element, "The TARGETDIR directory should not longer be explicitly referenced. Remove the DirectoryRef element with Id attribute 'TARGETDIR'."))
1140 {
1141 var parentElement = element.Parent;
1142
1143 element.Remove();
1144
1145 if (parentElement.FirstNode is XText text && String.IsNullOrWhiteSpace(text.Value))
1146 {
1147 parentElement.FirstNode.Remove();
1148 }
1149
1150 foreach (var child in element.Nodes())
1151 {
1152 parentElement.Add(child);
1153 }
1154
1155 element.RemoveAll();
1156
1157 if (parentElement.FirstNode is XText textAgain && String.IsNullOrWhiteSpace(textAgain.Value))
1158 {
1159 parentElement.FirstNode.Remove();
1160 }
1161 }
1162 }
1163
1132 private void ConvertFeatureElement(XElement element) 1164 private void ConvertFeatureElement(XElement element)
1133 { 1165 {
1134 var xAbsent = element.Attribute("Absent"); 1166 var xAbsent = element.Attribute("Absent");
@@ -3144,6 +3176,11 @@ namespace WixToolset.Converters
3144 /// Custom action ids have changed in WiX v4 extensions. Because WiX v4 has platform-specific custom actions, the platform is applied as a suffix: _X86, _X64, _A64 (Arm64). When manually rescheduling custom actions, you must use the new custom action id, with platform suffix. 3176 /// Custom action ids have changed in WiX v4 extensions. Because WiX v4 has platform-specific custom actions, the platform is applied as a suffix: _X86, _X64, _A64 (Arm64). When manually rescheduling custom actions, you must use the new custom action id, with platform suffix.
3145 /// </summary> 3177 /// </summary>
3146 CustomActionIdsIncludePlatformSuffix, 3178 CustomActionIdsIncludePlatformSuffix,
3179
3180 /// <summary>
3181 /// The TARGETDIR directory should not longer be explicitly referenced.
3182 /// </summary>
3183 TargetDirRefDeprecated,
3147 } 3184 }
3148 } 3185 }
3149} 3186}
diff --git a/src/wix/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/wix/test/WixToolsetTest.Converters/ConverterFixture.cs
index 375b6608..f580e516 100644
--- a/src/wix/test/WixToolsetTest.Converters/ConverterFixture.cs
+++ b/src/wix/test/WixToolsetTest.Converters/ConverterFixture.cs
@@ -282,10 +282,8 @@ namespace WixToolsetTest.Converters
282 "<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", 282 "<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
283 " <?define Version = 1.2.3 ?>", 283 " <?define Version = 1.2.3 ?>",
284 " <Fragment>", 284 " <Fragment>",
285 " <DirectoryRef Id=\"TARGETDIR\">",
286 " <Directory Id=\"ANOTHERDIR\" Name=\"Another\" />", 285 " <Directory Id=\"ANOTHERDIR\" Name=\"Another\" />",
287 " </DirectoryRef>", 286 " </Fragment>",
288 " </Fragment>",
289 "</Include>", 287 "</Include>",
290 }; 288 };
291 289
@@ -298,9 +296,9 @@ namespace WixToolsetTest.Converters
298 296
299 var actual = UnformattedDocumentLines(document); 297 var actual = UnformattedDocumentLines(document);
300 298
301 Assert.Equal(2, errors);
302 WixAssert.CompareLineByLine(expected, actual); 299 WixAssert.CompareLineByLine(expected, actual);
303 Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); 300 Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace());
301 Assert.Equal(3, errors);
304 } 302 }
305 303
306 [Fact] 304 [Fact]
diff --git a/src/wix/test/WixToolsetTest.Converters/DirectoryFixture.cs b/src/wix/test/WixToolsetTest.Converters/DirectoryFixture.cs
index 063554db..6f233509 100644
--- a/src/wix/test/WixToolsetTest.Converters/DirectoryFixture.cs
+++ b/src/wix/test/WixToolsetTest.Converters/DirectoryFixture.cs
@@ -45,10 +45,50 @@ namespace WixToolsetTest.Converters
45 var converter = new WixConverter(messaging, 2, null, null); 45 var converter = new WixConverter(messaging, 2, null, null);
46 46
47 var errors = converter.ConvertDocument(document); 47 var errors = converter.ConvertDocument(document);
48
49 var actualLines = UnformattedDocumentLines(document);
50 WixAssert.CompareLineByLine(expected, actualLines);
48 Assert.Equal(3, errors); 51 Assert.Equal(3, errors);
52 }
53
54 [Fact]
55 public void RemoveTargetDirRef()
56 {
57 var parse = String.Join(Environment.NewLine,
58 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
59 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
60 " <Fragment>",
61 " <DirectoryRef Id='TARGETDIR'>",
62 " <!-- Comment -->",
63 " <Directory Id='RootFolder' Name='Root'>",
64 " <Directory Id='ChildFolder' Name='Child' />",
65 " </Directory>",
66 " </DirectoryRef>",
67 " </Fragment>",
68 "</Wix>");
69
70 var expected = new[]
71 {
72 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
73 " <Fragment>",
74 " <!-- Comment -->",
75 " <Directory Id=\"RootFolder\" Name=\"Root\">",
76 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
77 " </Directory>",
78 " </Fragment>",
79 "</Wix>"
80 };
81
82 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
83
84 var messaging = new MockMessaging();
85 var converter = new WixConverter(messaging, 2, null, null);
86
87 var errors = converter.ConvertDocument(document);
49 88
50 var actualLines = UnformattedDocumentLines(document); 89 var actualLines = UnformattedDocumentLines(document);
51 WixAssert.CompareLineByLine(expected, actualLines); 90 WixAssert.CompareLineByLine(expected, actualLines);
91 Assert.Equal(3, errors);
52 } 92 }
53 93
54 [Fact] 94 [Fact]
@@ -83,10 +123,48 @@ namespace WixToolsetTest.Converters
83 var converter = new WixConverter(messaging, 2, null, null); 123 var converter = new WixConverter(messaging, 2, null, null);
84 124
85 var errors = converter.ConvertDocument(document); 125 var errors = converter.ConvertDocument(document);
126
127 var actualLines = UnformattedDocumentLines(document);
128 WixAssert.CompareLineByLine(expected, actualLines);
86 Assert.Equal(4, errors); 129 Assert.Equal(4, errors);
130 }
131
132 [Fact]
133 public void RemoveTargetDirRefAndFixStandardDirectory()
134 {
135 var parse = String.Join(Environment.NewLine,
136 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
137 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
138 " <Fragment>",
139 " <DirectoryRef Id='TARGETDIR'>",
140 " <Directory Id='ProgramFilesFolder' Name='PFiles'>",
141 " <Directory Id='ChildFolder' Name='Child' />",
142 " </Directory>",
143 " </DirectoryRef>",
144 " </Fragment>",
145 "</Wix>");
146
147 var expected = new[]
148 {
149 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
150 " <Fragment>",
151 " <StandardDirectory Id=\"ProgramFilesFolder\">",
152 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
153 " </StandardDirectory>",
154 " </Fragment>",
155 "</Wix>"
156 };
157
158 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
159
160 var messaging = new MockMessaging();
161 var converter = new WixConverter(messaging, 2, null, null);
162
163 var errors = converter.ConvertDocument(document);
87 164
88 var actualLines = UnformattedDocumentLines(document); 165 var actualLines = UnformattedDocumentLines(document);
89 WixAssert.CompareLineByLine(expected, actualLines); 166 WixAssert.CompareLineByLine(expected, actualLines);
167 Assert.Equal(4, errors);
90 } 168 }
91 } 169 }
92} 170}