From 11f6b34b97809da414d6368155e70125b582565f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 7 Aug 2022 11:51:01 -0700 Subject: Add intermediate folder and output path to all contexts Extensions sometimes need to generate files and lay them out relative to the final output path. Provide that context to all extensions so they can use the correct intermediate folder and output path. --- .../Data/ICommandLineContext.cs | 13 ++++++- .../Data/ICompileContext.cs | 10 +++++ .../Data/ILayoutContext.cs | 5 +++ .../Data/ILibraryContext.cs | 10 +++++ .../WixToolset.Extensibility/Data/ILinkContext.cs | 10 +++++ .../Data/IPreprocessContext.cs | 10 +++++ .../Data/IResolveContext.cs | 5 +++ .../WixToolset.Core/CommandLine/BuildCommand.cs | 45 +++++++++++++++------- src/wix/WixToolset.Core/CompileContext.cs | 4 ++ src/wix/WixToolset.Core/LayoutContext.cs | 2 + src/wix/WixToolset.Core/LibraryContext.cs | 4 ++ src/wix/WixToolset.Core/LinkContext.cs | 4 ++ src/wix/WixToolset.Core/PreprocessContext.cs | 4 ++ src/wix/WixToolset.Core/ResolveContext.cs | 2 + .../LinkerFixture.cs | 2 + 15 files changed, 115 insertions(+), 15 deletions(-) diff --git a/src/api/wix/WixToolset.Extensibility/Data/ICommandLineContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ICommandLineContext.cs index d8c9469e..595fc996 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ICommandLineContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ICommandLineContext.cs @@ -5,13 +5,24 @@ namespace WixToolset.Extensibility.Data using System; using WixToolset.Extensibility.Services; -#pragma warning disable 1591 // TODO: add documentation + /// + /// Command-line context. + /// public interface ICommandLineContext { + /// + /// Service provider. + /// IServiceProvider ServiceProvider { get; } + /// + /// Extension manager. + /// IExtensionManager ExtensionManager { get; set; } + /// + /// Command-line arguments. + /// ICommandLineArguments Arguments { get; set; } } } diff --git a/src/api/wix/WixToolset.Extensibility/Data/ICompileContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ICompileContext.cs index 2ee8f2a1..7006fde8 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ICompileContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ICompileContext.cs @@ -28,6 +28,16 @@ namespace WixToolset.Extensibility.Data /// IReadOnlyCollection Extensions { get; set; } + /// + /// Intermediate folder. + /// + string IntermediateFolder { get; set; } + + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/ILayoutContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ILayoutContext.cs index 981ed38e..8ff26365 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ILayoutContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ILayoutContext.cs @@ -36,6 +36,11 @@ namespace WixToolset.Extensibility.Data /// string IntermediateFolder { get; set; } + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// File to capture list of content, built output and copied output files. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs index 208b6f73..f3c4db6e 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs @@ -42,11 +42,21 @@ namespace WixToolset.Extensibility.Data /// IReadOnlyCollection Localizations { get; set; } + /// + /// Intermediate folder. + /// + string IntermediateFolder { get; set; } + /// /// Collection of intermediates to include in the library. /// IReadOnlyCollection Intermediates { get; set; } + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// Cancellation token. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs index d56866f7..8556d9eb 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs @@ -32,11 +32,21 @@ namespace WixToolset.Extensibility.Data /// OutputType ExpectedOutputType { get; set; } + /// + /// Intermediate folder. + /// + string IntermediateFolder { get; set; } + /// /// Collection of intermediates to link. /// IReadOnlyCollection Intermediates { get; set; } + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// Symbol definition creator used to load extension data. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/IPreprocessContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IPreprocessContext.cs index 69057c33..39e56f7c 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/IPreprocessContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/IPreprocessContext.cs @@ -27,6 +27,16 @@ namespace WixToolset.Extensibility.Data /// IReadOnlyCollection IncludeSearchPaths { get; set; } + /// + /// Intermediate folder. + /// + string IntermediateFolder { get; set; } + + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// Gets the platform which the compiler will use when defaulting 64-bit attributes and elements. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs index 63159ccb..bec689ba 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs @@ -57,6 +57,11 @@ namespace WixToolset.Extensibility.Data /// bool AllowUnresolvedVariables { get; set; } + /// + /// Output path. + /// + string OutputPath { get; set; } + /// /// Cancellation token. /// diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index f291fa8c..e63c727c 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -49,6 +49,8 @@ namespace WixToolset.Core.CommandLine private string IntermediateFolder { get; set; } + private string OutputPath { get; set; } + private Platform Platform { get; set; } private CompressionLevel? DefaultCompressionLevel { get; set; } @@ -79,6 +81,8 @@ namespace WixToolset.Core.CommandLine var inputsOutputs = this.commandLine.CalculateInputsAndOutputs(creator); + this.OutputPath = inputsOutputs.OutputPath; + if (this.Messaging.EncounteredError) { return Task.FromResult(this.Messaging.LastErrorNumber); @@ -117,7 +121,9 @@ namespace WixToolset.Core.CommandLine if (String.IsNullOrEmpty(outputExtension) || ".wix" == outputExtension) { var entrySectionType = wixipl.Sections.Single().Type; + inputsOutputs.OutputPath = Path.ChangeExtension(inputsOutputs.OutputPath, DefaultExtensionForSectionType(entrySectionType)); + this.OutputPath = inputsOutputs.OutputPath; } if (inputsOutputs.OutputType == OutputType.IntermediatePostLink) @@ -158,6 +164,8 @@ namespace WixToolset.Core.CommandLine var context = this.ServiceProvider.GetService(); context.Extensions = this.ExtensionManager.GetServices(); + context.IntermediateFolder = this.IntermediateFolder; + context.OutputPath = this.OutputPath; context.Platform = this.Platform; context.Source = document; context.CancellationToken = cancellationToken; @@ -198,7 +206,9 @@ namespace WixToolset.Core.CommandLine context.BindPaths = bindPaths; context.Extensions = this.ExtensionManager.GetServices(); context.Localizations = localizations; + context.IntermediateFolder = this.IntermediateFolder; context.Intermediates = intermediates.Concat(libraries).ToList(); + context.OutputPath = this.OutputPath; context.CancellationToken = cancellationToken; try @@ -210,7 +220,7 @@ namespace WixToolset.Core.CommandLine { result.Library.Save(outputPath); - this.LayoutFiles(this.IntermediateFolder, result.TrackedFiles, null, cancellationToken); + this.LayoutFiles(result.TrackedFiles, null, cancellationToken); } } catch (WixException e) @@ -232,7 +242,9 @@ namespace WixToolset.Core.CommandLine context.Extensions = this.ExtensionManager.GetServices(); context.ExtensionData = this.ExtensionManager.GetServices(); context.ExpectedOutputType = inputsOutputs.OutputType; + context.IntermediateFolder = this.IntermediateFolder; context.Intermediates = intermediates.Concat(libraries).ToList(); + context.OutputPath = this.OutputPath; context.SymbolDefinitionCreator = creator; context.CancellationToken = cancellationToken; @@ -242,12 +254,6 @@ namespace WixToolset.Core.CommandLine private void BindPhase(Intermediate output, IReadOnlyCollection localizations, IReadOnlyCollection filterCultures, string cabCachePath, IReadOnlyCollection bindPaths, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken) { - var intermediateFolder = this.IntermediateFolder; - if (String.IsNullOrEmpty(intermediateFolder)) - { - intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - IResolveResult resolveResult; { var context = this.ServiceProvider.GetService(); @@ -255,9 +261,10 @@ namespace WixToolset.Core.CommandLine context.Extensions = this.ExtensionManager.GetServices(); context.ExtensionData = this.ExtensionManager.GetServices(); context.FilterCultures = filterCultures; - context.IntermediateFolder = intermediateFolder; + context.IntermediateFolder = this.IntermediateFolder; context.IntermediateRepresentation = output; context.Localizations = localizations; + context.OutputPath = inputsOutputs.OutputPath; context.CancellationToken = cancellationToken; var resolver = this.ServiceProvider.GetService(); @@ -284,9 +291,9 @@ namespace WixToolset.Core.CommandLine context.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; context.Extensions = this.ExtensionManager.GetServices(); context.FileSystemExtensions = this.ExtensionManager.GetServices(); - context.IntermediateFolder = intermediateFolder; + context.IntermediateFolder = this.IntermediateFolder; context.IntermediateRepresentation = resolveResult.IntermediateRepresentation; - context.OutputPath = inputsOutputs.OutputPath; + context.OutputPath = this.OutputPath; context.PdbType = inputsOutputs.PdbType; context.PdbPath = inputsOutputs.PdbPath; context.CancellationToken = cancellationToken; @@ -300,7 +307,7 @@ namespace WixToolset.Core.CommandLine return; } - this.LayoutFiles(intermediateFolder, bindResult.TrackedFiles, bindResult.FileTransfers, cancellationToken); + this.LayoutFiles(bindResult.TrackedFiles, bindResult.FileTransfers, cancellationToken); } finally { @@ -308,13 +315,14 @@ namespace WixToolset.Core.CommandLine } } - private void LayoutFiles(string intermediateFolder, IReadOnlyCollection trackedFiles, IReadOnlyCollection fileTransfers, CancellationToken cancellationToken) + private void LayoutFiles(IReadOnlyCollection trackedFiles, IReadOnlyCollection fileTransfers, CancellationToken cancellationToken) { var context = this.ServiceProvider.GetService(); context.Extensions = this.ExtensionManager.GetServices(); context.TrackedFiles = trackedFiles; context.FileTransfers = fileTransfers; - context.IntermediateFolder = intermediateFolder; + context.IntermediateFolder = this.IntermediateFolder; + context.OutputPath = this.OutputPath; context.TrackingFile = this.TrackingFile; context.ResetAcls = this.commandLine.ResetAcls; context.CancellationToken = cancellationToken; @@ -368,6 +376,8 @@ namespace WixToolset.Core.CommandLine context.Extensions = this.ExtensionManager.GetServices(); context.Platform = this.Platform; context.IncludeSearchPaths = includeSearchPaths; + context.IntermediateFolder = this.IntermediateFolder; + context.OutputPath = this.OutputPath; context.SourcePath = sourcePath; context.Variables = preprocessorVariables; context.CancellationToken = cancellationToken; @@ -614,7 +624,14 @@ namespace WixToolset.Core.CommandLine public string CalculateIntermedateFolder() { - return String.IsNullOrEmpty(this.IntermediateFolder) ? Path.GetTempPath() : this.IntermediateFolder; + var intermediateFolder = this.IntermediateFolder; + + if (String.IsNullOrEmpty(intermediateFolder)) + { + intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + } + + return intermediateFolder; } public OutputType CalculateOutputType() diff --git a/src/wix/WixToolset.Core/CompileContext.cs b/src/wix/WixToolset.Core/CompileContext.cs index d84d7aac..f0c99a51 100644 --- a/src/wix/WixToolset.Core/CompileContext.cs +++ b/src/wix/WixToolset.Core/CompileContext.cs @@ -23,6 +23,10 @@ namespace WixToolset.Core public IReadOnlyCollection Extensions { get; set; } + public string IntermediateFolder { get; set; } + + public string OutputPath { get; set; } + public Platform Platform { get; set; } public bool IsCurrentPlatform64Bit => this.Platform == Platform.ARM64 || this.Platform == Platform.X64; diff --git a/src/wix/WixToolset.Core/LayoutContext.cs b/src/wix/WixToolset.Core/LayoutContext.cs index 3def3006..a5a8ea28 100644 --- a/src/wix/WixToolset.Core/LayoutContext.cs +++ b/src/wix/WixToolset.Core/LayoutContext.cs @@ -31,6 +31,8 @@ namespace WixToolset.Core public bool ResetAcls { get; set; } + public string OutputPath { get; set; } + public CancellationToken CancellationToken { get; set; } } } diff --git a/src/wix/WixToolset.Core/LibraryContext.cs b/src/wix/WixToolset.Core/LibraryContext.cs index e701cadf..a463844e 100644 --- a/src/wix/WixToolset.Core/LibraryContext.cs +++ b/src/wix/WixToolset.Core/LibraryContext.cs @@ -31,8 +31,12 @@ namespace WixToolset.Core public IReadOnlyCollection Localizations { get; set; } + public string IntermediateFolder { get; set; } + public IReadOnlyCollection Intermediates { get; set; } + public string OutputPath { get; set; } + public CancellationToken CancellationToken { get; set; } } } diff --git a/src/wix/WixToolset.Core/LinkContext.cs b/src/wix/WixToolset.Core/LinkContext.cs index b99bb9c4..10223171 100644 --- a/src/wix/WixToolset.Core/LinkContext.cs +++ b/src/wix/WixToolset.Core/LinkContext.cs @@ -24,8 +24,12 @@ namespace WixToolset.Core public OutputType ExpectedOutputType { get; set; } + public string IntermediateFolder { get; set; } + public IReadOnlyCollection Intermediates { get; set; } + public string OutputPath { get; set; } + public ISymbolDefinitionCreator SymbolDefinitionCreator { get; set; } public CancellationToken CancellationToken { get; set; } diff --git a/src/wix/WixToolset.Core/PreprocessContext.cs b/src/wix/WixToolset.Core/PreprocessContext.cs index 986045ff..1b31e150 100644 --- a/src/wix/WixToolset.Core/PreprocessContext.cs +++ b/src/wix/WixToolset.Core/PreprocessContext.cs @@ -24,6 +24,10 @@ namespace WixToolset.Core public IReadOnlyCollection IncludeSearchPaths { get; set; } + public string IntermediateFolder { get; set; } + + public string OutputPath { get; set; } + public string SourcePath { get; set; } public IDictionary Variables { get; set; } diff --git a/src/wix/WixToolset.Core/ResolveContext.cs b/src/wix/WixToolset.Core/ResolveContext.cs index 638c8079..a56ce4c9 100644 --- a/src/wix/WixToolset.Core/ResolveContext.cs +++ b/src/wix/WixToolset.Core/ResolveContext.cs @@ -37,6 +37,8 @@ namespace WixToolset.Core public bool AllowUnresolvedVariables { get; set; } + public string OutputPath { get; set; } + public CancellationToken CancellationToken { get; set; } } } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs index 2b3adfb4..c3f16722 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs @@ -32,7 +32,9 @@ namespace WixToolsetTest.CoreIntegration var context = serviceProvider.GetService(); context.Extensions = Array.Empty(); context.ExtensionData = Array.Empty(); + context.IntermediateFolder = Path.GetTempPath(); context.Intermediates = new[] { intermediate1, intermediate2 }; + context.OutputPath = Path.Combine(context.IntermediateFolder, "test.msi"); context.SymbolDefinitionCreator = creator; var linker = serviceProvider.GetService(); -- cgit v1.2.3-55-g6feb