From 41622a07f82c57cf3d80393b0b6914f5ccb76e33 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 1 Jan 2019 00:26:30 -0800 Subject: Load .wixlib intermediates with single creator Using a single creator ensures definitions are shared and consistent across the entire build. --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 31 ++-- .../TupleDefinitionCreator.cs | 7 +- .../ComplexExampleExtension/OtherComponents.wxs | 12 ++ .../ComplexExampleExtension/Package.en-us.wxl | 11 ++ .../TestData/ComplexExampleExtension/Package.wxs | 26 ++++ .../ComplexExampleExtension/PackageComponents.wxs | 12 ++ .../ComplexExampleExtension/data/example.txt | 1 + .../ComplexExampleExtension/data/other.txt | 1 + .../WixToolsetTest.CoreIntegration.csproj | 6 + .../WixlibFixture.cs | 173 +++++++++++++++++++++ 10 files changed, 259 insertions(+), 21 deletions(-) create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/OtherComponents.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.en-us.wxl create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/PackageComponents.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/example.txt create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/other.txt create mode 100644 src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 87a3cd30..f754c876 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -331,27 +331,20 @@ namespace WixToolset.Core.CommandLine private IEnumerable LoadLibraries(IEnumerable libraryFiles, ITupleDefinitionCreator creator) { - var libraries = new List(); - - foreach (var libraryFile in libraryFiles) + try { - try - { - var library = Intermediate.Load(libraryFile, creator); - - libraries.Add(library); - } - catch (WixCorruptFileException e) - { - this.Messaging.Write(e.Error); - } - catch (WixUnexpectedFileFormatException e) - { - this.Messaging.Write(e.Error); - } + return Intermediate.Load(libraryFiles, creator); + } + catch (WixCorruptFileException e) + { + this.Messaging.Write(e.Error); + } + catch (WixUnexpectedFileFormatException e) + { + this.Messaging.Write(e.Error); } - return libraries; + return Array.Empty(); } private IEnumerable LoadLocalizationFiles(IEnumerable locFiles, IDictionary preprocessorVariables) @@ -437,7 +430,7 @@ namespace WixToolset.Core.CommandLine public string OutputsFile { get; private set; } public string BuiltOutputsFile { get; private set; } - + public CommandLine(IMessaging messaging) { this.Messaging = messaging; diff --git a/src/WixToolset.Core/ExtensibilityServices/TupleDefinitionCreator.cs b/src/WixToolset.Core/ExtensibilityServices/TupleDefinitionCreator.cs index b442da2b..e223e3a4 100644 --- a/src/WixToolset.Core/ExtensibilityServices/TupleDefinitionCreator.cs +++ b/src/WixToolset.Core/ExtensibilityServices/TupleDefinitionCreator.cs @@ -1,4 +1,4 @@ -// 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. +// 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.ExtensibilityServices { @@ -23,7 +23,10 @@ namespace WixToolset.Core.ExtensibilityServices public void AddCustomTupleDefinition(IntermediateTupleDefinition definition) { - this.CustomDefinitionByName.Add(definition.Name, definition); + if (!this.CustomDefinitionByName.TryGetValue(definition.Name, out var existing) || definition.Revision > existing.Revision) + { + this.CustomDefinitionByName[definition.Name] = definition; + } } public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/OtherComponents.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/OtherComponents.wxs new file mode 100644 index 00000000..15a9a0ce --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/OtherComponents.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.en-us.wxl b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.en-us.wxl new file mode 100644 index 00000000..38c12ac1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/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/ComplexExampleExtension/Package.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.wxs new file mode 100644 index 00000000..0e8e9795 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/Package.wxs @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/PackageComponents.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/PackageComponents.wxs new file mode 100644 index 00000000..7f17b538 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/PackageComponents.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/example.txt b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/example.txt new file mode 100644 index 00000000..1b4ffe8a --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/example.txt @@ -0,0 +1 @@ +This is example.txt. \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/other.txt b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/other.txt new file mode 100644 index 00000000..8c874ae7 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ComplexExampleExtension/data/other.txt @@ -0,0 +1 @@ +This is other.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 2a20fcff..53c5ceea 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj @@ -38,6 +38,12 @@ + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs b/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs new file mode 100644 index 00000000..532f158d --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs @@ -0,0 +1,173 @@ +// 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 WixToolsetTest.CoreIntegration +{ + using System; + using System.IO; + using System.Linq; + using Example.Extension; + using WixBuildTools.TestSupport; + using WixToolset.Core.TestPackage; + using WixToolset.Data; + using WixToolset.Data.Tuples; + using Xunit; + + public class WixlibFixture + { + [Fact] + public void CanBuildSingleFileUsingWixlib() + { + var folder = TestData.Get(@"TestData\SingleFile"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackageComponents.wxs"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"test.wixlib") + }); + + result.AssertSuccess(); + + result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Package.wxs"), + "-loc", Path.Combine(folder, "Package.en-us.wxl"), + "-lib", Path.Combine(intermediateFolder, @"test.wixlib"), + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(baseFolder, @"bin\test.msi") + }); + + result.AssertSuccess(); + + var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"obj\test.wir")); + var section = intermediate.Sections.Single(); + + var wixFile = section.Tuples.OfType().Single(); + Assert.Equal(Path.Combine(folder, @"data\test.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); + Assert.Equal(@"test.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); + } + } + + [Fact] + public void CanBuildWithExtensionUsingWixlib() + { + var folder = TestData.Get(@"TestData\ExampleExtension"); + var extensionPath = Path.GetFullPath(new Uri(typeof(ExampleExtensionFactory).Assembly.CodeBase).LocalPath); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackageComponents.wxs"), + "-ext", extensionPath, + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"test.wixlib") + }); + + result.AssertSuccess(); + + result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Package.wxs"), + "-loc", Path.Combine(folder, "Package.en-us.wxl"), + "-lib", Path.Combine(intermediateFolder, @"test.wixlib"), + "-ext", extensionPath, + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"bin\test.msi") + }); + + result.AssertSuccess(); + + var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"test.wir")); + var section = intermediate.Sections.Single(); + + var wixFile = section.Tuples.OfType().Single(); + Assert.Equal(Path.Combine(folder, @"data\example.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); + Assert.Equal(@"example.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); + + var example = section.Tuples.Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).Single(); + Assert.Equal("Foo", example.Id.Id); + Assert.Equal("Foo", example[0].AsString()); + Assert.Equal("Bar", example[1].AsString()); + } + } + + [Fact] + public void CanBuildWithExtensionUsingMultipleWixlibs() + { + var folder = TestData.Get(@"TestData\ComplexExampleExtension"); + var extensionPath = Path.GetFullPath(new Uri(typeof(ExampleExtensionFactory).Assembly.CodeBase).LocalPath); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackageComponents.wxs"), + "-ext", extensionPath, + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"components.wixlib") + }); + + result.AssertSuccess(); + + result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "OtherComponents.wxs"), + "-ext", extensionPath, + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"other.wixlib") + }); + + result.AssertSuccess(); + + result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Package.wxs"), + "-loc", Path.Combine(folder, "Package.en-us.wxl"), + "-lib", Path.Combine(intermediateFolder, @"components.wixlib"), + "-lib", Path.Combine(intermediateFolder, @"other.wixlib"), + "-ext", extensionPath, + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(intermediateFolder, @"bin\test.msi") + }); + + result.AssertSuccess(); + + var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"test.wir")); + var section = intermediate.Sections.Single(); + + var wixFiles = section.Tuples.OfType().OrderBy(t => Path.GetFileName(t.Source.Path)).ToArray(); + Assert.Equal(Path.Combine(folder, @"data\example.txt"), wixFiles[0][WixFileTupleFields.Source].AsPath().Path); + Assert.Equal(@"example.txt", wixFiles[0][WixFileTupleFields.Source].PreviousValue.AsPath().Path); + Assert.Equal(Path.Combine(folder, @"data\other.txt"), wixFiles[1][WixFileTupleFields.Source].AsPath().Path); + Assert.Equal(@"other.txt", wixFiles[1][WixFileTupleFields.Source].PreviousValue.AsPath().Path); + + var examples = section.Tuples.Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).ToArray(); + Assert.Equal(new[] { "Foo", "Other" }, examples.Select(t => t.Id.Id).ToArray()); + Assert.Equal(new[] { "Foo", "Other" }, examples.Select(t => t.AsString(0)).ToArray()); + Assert.Equal(new[] { "Bar", "Value" }, examples.Select(t => t[1].AsString()).ToArray()); + } + } + } +} -- cgit v1.2.3-55-g6feb