From f2e5bdc263b8f6def149c918c332bd0d66fb6c1f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 6 Dec 2022 14:10:10 -0800 Subject: Remove DirectoryRef to TARGETDIR Fixes 7061 --- src/wix/WixToolset.Converters/WixConverter.cs | 37 ++++++++++ .../WixToolsetTest.Converters/ConverterFixture.cs | 6 +- .../WixToolsetTest.Converters/DirectoryFixture.cs | 78 ++++++++++++++++++++++ 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 private static readonly XName OldRequiresElementName = WixDependencyNamespace + "Requires"; private static readonly XName OldRequiresRefElementName = WixDependencyNamespace + "RequiresRef"; private static readonly XName DirectoryElementName = WixNamespace + "Directory"; + private static readonly XName DirectoryRefElementName = WixNamespace + "DirectoryRef"; private static readonly XName EmbeddedChainerElementName = WixNamespace + "EmbeddedChainer"; private static readonly XName ErrorElementName = WixNamespace + "Error"; private static readonly XName FeatureElementName = WixNamespace + "Feature"; @@ -288,6 +289,7 @@ namespace WixToolset.Converters { WixConverter.CustomTableElementName, this.ConvertCustomTableElement }, { WixConverter.DataElementName, this.ConvertDataElement }, { WixConverter.DirectoryElementName, this.ConvertDirectoryElement }, + { WixConverter.DirectoryRefElementName, this.ConvertDirectoryRefElement }, { WixConverter.FeatureElementName, this.ConvertFeatureElement }, { WixConverter.FileElementName, this.ConvertFileElement }, { WixConverter.FragmentElementName, this.ConvertFragmentElement }, @@ -1129,6 +1131,36 @@ namespace WixToolset.Converters } } + private void ConvertDirectoryRefElement(XElement element) + { + var id = element.Attribute("Id")?.Value; + + if (id == "TARGETDIR" && + this.OnInformation(ConverterTestType.TargetDirRefDeprecated, element, "The TARGETDIR directory should not longer be explicitly referenced. Remove the DirectoryRef element with Id attribute 'TARGETDIR'.")) + { + var parentElement = element.Parent; + + element.Remove(); + + if (parentElement.FirstNode is XText text && String.IsNullOrWhiteSpace(text.Value)) + { + parentElement.FirstNode.Remove(); + } + + foreach (var child in element.Nodes()) + { + parentElement.Add(child); + } + + element.RemoveAll(); + + if (parentElement.FirstNode is XText textAgain && String.IsNullOrWhiteSpace(textAgain.Value)) + { + parentElement.FirstNode.Remove(); + } + } + } + private void ConvertFeatureElement(XElement element) { var xAbsent = element.Attribute("Absent"); @@ -3144,6 +3176,11 @@ namespace WixToolset.Converters /// 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. /// CustomActionIdsIncludePlatformSuffix, + + /// + /// The TARGETDIR directory should not longer be explicitly referenced. + /// + TargetDirRefDeprecated, } } } 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 "", " ", " ", - " ", " ", - " ", - " ", + " ", "", }; @@ -298,9 +296,9 @@ namespace WixToolsetTest.Converters var actual = UnformattedDocumentLines(document); - Assert.Equal(2, errors); WixAssert.CompareLineByLine(expected, actual); Assert.Equal(Wix4Namespace, document.Root.GetDefaultNamespace()); + Assert.Equal(3, errors); } [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 var converter = new WixConverter(messaging, 2, null, null); var errors = converter.ConvertDocument(document); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); Assert.Equal(3, errors); + } + + [Fact] + public void RemoveTargetDirRef() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); var actualLines = UnformattedDocumentLines(document); WixAssert.CompareLineByLine(expected, actualLines); + Assert.Equal(3, errors); } [Fact] @@ -83,10 +123,48 @@ namespace WixToolsetTest.Converters var converter = new WixConverter(messaging, 2, null, null); var errors = converter.ConvertDocument(document); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); Assert.Equal(4, errors); + } + + [Fact] + public void RemoveTargetDirRefAndFixStandardDirectory() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); var actualLines = UnformattedDocumentLines(document); WixAssert.CompareLineByLine(expected, actualLines); + Assert.Equal(4, errors); } } } -- cgit v1.2.3-55-g6feb