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.
Rob Mensching committed
Aug 7, 2022 at 11:51 UTC
11f6b34b97809da414d6368155e70125b582565f
15 files changed
+115
-15
src/api/wix/WixToolset.Extensibility/Data/ICommandLineContext.cs
+12
-1
@@ -5,13 +5,24 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using WixToolset.Extensibility.Services;
7
8
-#pragma warning disable 1591 // TODO: add documentation
8
+ /// <summary>
9
+ /// Command-line context.
10
+ /// </summary>
11
public interface ICommandLineContext
12
{
13
+ /// <summary>
14
+ /// Service provider.
15
+ /// </summary>
16
IServiceProvider ServiceProvider { get; }
17
18
+ /// <summary>
19
+ /// Extension manager.
20
+ /// </summary>
21
IExtensionManager ExtensionManager { get; set; }
22
23
+ /// <summary>
24
+ /// Command-line arguments.
25
+ /// </summary>
26
ICommandLineArguments Arguments { get; set; }
27
}
28
}
src/api/wix/WixToolset.Extensibility/Data/ICompileContext.cs
+10
@@ -28,6 +28,16 @@ namespace WixToolset.Extensibility.Data
28
/// </summary>
29
IReadOnlyCollection<ICompilerExtension> Extensions { get; set; }
30
31
+ /// <summary>
32
+ /// Intermediate folder.
33
+ /// </summary>
34
+ string IntermediateFolder { get; set; }
35
+
36
+ /// <summary>
37
+ /// Output path.
38
+ /// </summary>
39
+ string OutputPath { get; set; }
40
+
41
/// <summary>
42
/// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements.
43
/// </summary>
src/api/wix/WixToolset.Extensibility/Data/ILayoutContext.cs
+5
@@ -36,6 +36,11 @@ namespace WixToolset.Extensibility.Data
36
/// </summary>
37
string IntermediateFolder { get; set; }
38
39
+ /// <summary>
40
+ /// Output path.
41
+ /// </summary>
42
+ string OutputPath { get; set; }
43
+
44
/// <summary>
45
/// File to capture list of content, built output and copied output files.
46
/// </summary>
src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs
+10
@@ -42,11 +42,21 @@ namespace WixToolset.Extensibility.Data
42
/// </summary>
43
IReadOnlyCollection<Localization> Localizations { get; set; }
44
45
+ /// <summary>
46
+ /// Intermediate folder.
47
+ /// </summary>
48
+ string IntermediateFolder { get; set; }
49
+
50
/// <summary>
51
/// Collection of intermediates to include in the library.
52
/// </summary>
53
IReadOnlyCollection<Intermediate> Intermediates { get; set; }
54
55
+ /// <summary>
56
+ /// Output path.
57
+ /// </summary>
58
+ string OutputPath { get; set; }
59
+
60
/// <summary>
61
/// Cancellation token.
62
/// </summary>
src/api/wix/WixToolset.Extensibility/Data/ILinkContext.cs
+10
@@ -32,11 +32,21 @@ namespace WixToolset.Extensibility.Data
32
/// </summary>
33
OutputType ExpectedOutputType { get; set; }
34
35
+ /// <summary>
36
+ /// Intermediate folder.
37
+ /// </summary>
38
+ string IntermediateFolder { get; set; }
39
+
40
/// <summary>
41
/// Collection of intermediates to link.
42
/// </summary>
43
IReadOnlyCollection<Intermediate> Intermediates { get; set; }
44
45
+ /// <summary>
46
+ /// Output path.
47
+ /// </summary>
48
+ string OutputPath { get; set; }
49
+
50
/// <summary>
51
/// Symbol definition creator used to load extension data.
52
/// </summary>
src/api/wix/WixToolset.Extensibility/Data/IPreprocessContext.cs
+10
@@ -27,6 +27,16 @@ namespace WixToolset.Extensibility.Data
27
/// </summary>
28
IReadOnlyCollection<string> IncludeSearchPaths { get; set; }
29
30
+ /// <summary>
31
+ /// Intermediate folder.
32
+ /// </summary>
33
+ string IntermediateFolder { get; set; }
34
+
35
+ /// <summary>
36
+ /// Output path.
37
+ /// </summary>
38
+ string OutputPath { get; set; }
39
+
40
/// <summary>
41
/// Gets the platform which the compiler will use when defaulting 64-bit attributes and elements.
42
/// </summary>
src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs
+5
@@ -57,6 +57,11 @@ namespace WixToolset.Extensibility.Data
57
/// </summary>
58
bool AllowUnresolvedVariables { get; set; }
59
60
+ /// <summary>
61
+ /// Output path.
62
+ /// </summary>
63
+ string OutputPath { get; set; }
64
+
65
/// <summary>
66
/// Cancellation token.
67
/// </summary>
src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
+31
-14
@@ -49,6 +49,8 @@ namespace WixToolset.Core.CommandLine
49
50
private string IntermediateFolder { get; set; }
51
52
+ private string OutputPath { get; set; }
53
+
54
private Platform Platform { get; set; }
55
56
private CompressionLevel? DefaultCompressionLevel { get; set; }
@@ -79,6 +81,8 @@ namespace WixToolset.Core.CommandLine
81
82
var inputsOutputs = this.commandLine.CalculateInputsAndOutputs(creator);
83
84
+ this.OutputPath = inputsOutputs.OutputPath;
85
+
86
if (this.Messaging.EncounteredError)
87
{
88
return Task.FromResult(this.Messaging.LastErrorNumber);
@@ -117,7 +121,9 @@ namespace WixToolset.Core.CommandLine
121
if (String.IsNullOrEmpty(outputExtension) || ".wix" == outputExtension)
122
{
123
var entrySectionType = wixipl.Sections.Single().Type;
124
+
125
inputsOutputs.OutputPath = Path.ChangeExtension(inputsOutputs.OutputPath, DefaultExtensionForSectionType(entrySectionType));
126
+ this.OutputPath = inputsOutputs.OutputPath;
127
}
128
129
if (inputsOutputs.OutputType == OutputType.IntermediatePostLink)
@@ -158,6 +164,8 @@ namespace WixToolset.Core.CommandLine
164
165
var context = this.ServiceProvider.GetService<ICompileContext>();
166
context.Extensions = this.ExtensionManager.GetServices<ICompilerExtension>();
167
+ context.IntermediateFolder = this.IntermediateFolder;
168
+ context.OutputPath = this.OutputPath;
169
context.Platform = this.Platform;
170
context.Source = document;
171
context.CancellationToken = cancellationToken;
@@ -198,7 +206,9 @@ namespace WixToolset.Core.CommandLine
206
context.BindPaths = bindPaths;
207
context.Extensions = this.ExtensionManager.GetServices<ILibrarianExtension>();
208
context.Localizations = localizations;
209
+ context.IntermediateFolder = this.IntermediateFolder;
210
context.Intermediates = intermediates.Concat(libraries).ToList();
211
+ context.OutputPath = this.OutputPath;
212
context.CancellationToken = cancellationToken;
213
214
try
@@ -210,7 +220,7 @@ namespace WixToolset.Core.CommandLine
220
{
221
result.Library.Save(outputPath);
222
213
- this.LayoutFiles(this.IntermediateFolder, result.TrackedFiles, null, cancellationToken);
223
+ this.LayoutFiles(result.TrackedFiles, null, cancellationToken);
224
}
225
}
226
catch (WixException e)
@@ -232,7 +242,9 @@ namespace WixToolset.Core.CommandLine
242
context.Extensions = this.ExtensionManager.GetServices<ILinkerExtension>();
243
context.ExtensionData = this.ExtensionManager.GetServices<IExtensionData>();
244
context.ExpectedOutputType = inputsOutputs.OutputType;
245
+ context.IntermediateFolder = this.IntermediateFolder;
246
context.Intermediates = intermediates.Concat(libraries).ToList();
247
+ context.OutputPath = this.OutputPath;
248
context.SymbolDefinitionCreator = creator;
249
context.CancellationToken = cancellationToken;
250
@@ -242,12 +254,6 @@ namespace WixToolset.Core.CommandLine
254
255
private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> localizations, IReadOnlyCollection<string> filterCultures, string cabCachePath, IReadOnlyCollection<IBindPath> bindPaths, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken)
256
{
245
- var intermediateFolder = this.IntermediateFolder;
246
- if (String.IsNullOrEmpty(intermediateFolder))
247
- {
248
- intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
249
- }
250
-
257
IResolveResult resolveResult;
258
{
259
var context = this.ServiceProvider.GetService<IResolveContext>();
@@ -255,9 +261,10 @@ namespace WixToolset.Core.CommandLine
261
context.Extensions = this.ExtensionManager.GetServices<IResolverExtension>();
262
context.ExtensionData = this.ExtensionManager.GetServices<IExtensionData>();
263
context.FilterCultures = filterCultures;
258
- context.IntermediateFolder = intermediateFolder;
264
+ context.IntermediateFolder = this.IntermediateFolder;
265
context.IntermediateRepresentation = output;
266
context.Localizations = localizations;
267
+ context.OutputPath = inputsOutputs.OutputPath;
268
context.CancellationToken = cancellationToken;
269
270
var resolver = this.ServiceProvider.GetService<IResolver>();
@@ -284,9 +291,9 @@ namespace WixToolset.Core.CommandLine
291
context.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles;
292
context.Extensions = this.ExtensionManager.GetServices<IBinderExtension>();
293
context.FileSystemExtensions = this.ExtensionManager.GetServices<IFileSystemExtension>();
287
- context.IntermediateFolder = intermediateFolder;
294
+ context.IntermediateFolder = this.IntermediateFolder;
295
context.IntermediateRepresentation = resolveResult.IntermediateRepresentation;
289
- context.OutputPath = inputsOutputs.OutputPath;
296
+ context.OutputPath = this.OutputPath;
297
context.PdbType = inputsOutputs.PdbType;
298
context.PdbPath = inputsOutputs.PdbPath;
299
context.CancellationToken = cancellationToken;
@@ -300,7 +307,7 @@ namespace WixToolset.Core.CommandLine
307
return;
308
}
309
303
- this.LayoutFiles(intermediateFolder, bindResult.TrackedFiles, bindResult.FileTransfers, cancellationToken);
310
+ this.LayoutFiles(bindResult.TrackedFiles, bindResult.FileTransfers, cancellationToken);
311
}
312
finally
313
{
@@ -308,13 +315,14 @@ namespace WixToolset.Core.CommandLine
315
}
316
}
317
311
- private void LayoutFiles(string intermediateFolder, IReadOnlyCollection<ITrackedFile> trackedFiles, IReadOnlyCollection<IFileTransfer> fileTransfers, CancellationToken cancellationToken)
318
+ private void LayoutFiles(IReadOnlyCollection<ITrackedFile> trackedFiles, IReadOnlyCollection<IFileTransfer> fileTransfers, CancellationToken cancellationToken)
319
{
320
var context = this.ServiceProvider.GetService<ILayoutContext>();
321
context.Extensions = this.ExtensionManager.GetServices<ILayoutExtension>();
322
context.TrackedFiles = trackedFiles;
323
context.FileTransfers = fileTransfers;
317
- context.IntermediateFolder = intermediateFolder;
324
+ context.IntermediateFolder = this.IntermediateFolder;
325
+ context.OutputPath = this.OutputPath;
326
context.TrackingFile = this.TrackingFile;
327
context.ResetAcls = this.commandLine.ResetAcls;
328
context.CancellationToken = cancellationToken;
@@ -368,6 +376,8 @@ namespace WixToolset.Core.CommandLine
376
context.Extensions = this.ExtensionManager.GetServices<IPreprocessorExtension>();
377
context.Platform = this.Platform;
378
context.IncludeSearchPaths = includeSearchPaths;
379
+ context.IntermediateFolder = this.IntermediateFolder;
380
+ context.OutputPath = this.OutputPath;
381
context.SourcePath = sourcePath;
382
context.Variables = preprocessorVariables;
383
context.CancellationToken = cancellationToken;
@@ -614,7 +624,14 @@ namespace WixToolset.Core.CommandLine
624
625
public string CalculateIntermedateFolder()
626
{
617
- return String.IsNullOrEmpty(this.IntermediateFolder) ? Path.GetTempPath() : this.IntermediateFolder;
627
+ var intermediateFolder = this.IntermediateFolder;
628
+
629
+ if (String.IsNullOrEmpty(intermediateFolder))
630
+ {
631
+ intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
632
+ }
633
+
634
+ return intermediateFolder;
635
}
636
637
public OutputType CalculateOutputType()
src/wix/WixToolset.Core/CompileContext.cs
+4
@@ -23,6 +23,10 @@ namespace WixToolset.Core
23
24
public IReadOnlyCollection<ICompilerExtension> Extensions { get; set; }
25
26
+ public string IntermediateFolder { get; set; }
27
+
28
+ public string OutputPath { get; set; }
29
+
30
public Platform Platform { get; set; }
31
32
public bool IsCurrentPlatform64Bit => this.Platform == Platform.ARM64 || this.Platform == Platform.X64;
src/wix/WixToolset.Core/LayoutContext.cs
+2
@@ -31,6 +31,8 @@ namespace WixToolset.Core
31
32
public bool ResetAcls { get; set; }
33
34
+ public string OutputPath { get; set; }
35
+
36
public CancellationToken CancellationToken { get; set; }
37
}
38
}
src/wix/WixToolset.Core/LibraryContext.cs
+4
@@ -31,8 +31,12 @@ namespace WixToolset.Core
31
32
public IReadOnlyCollection<Localization> Localizations { get; set; }
33
34
+ public string IntermediateFolder { get; set; }
35
+
36
public IReadOnlyCollection<Intermediate> Intermediates { get; set; }
37
38
+ public string OutputPath { get; set; }
39
+
40
public CancellationToken CancellationToken { get; set; }
41
}
42
}
src/wix/WixToolset.Core/LinkContext.cs
+4
@@ -24,8 +24,12 @@ namespace WixToolset.Core
24
25
public OutputType ExpectedOutputType { get; set; }
26
27
+ public string IntermediateFolder { get; set; }
28
+
29
public IReadOnlyCollection<Intermediate> Intermediates { get; set; }
30
31
+ public string OutputPath { get; set; }
32
+
33
public ISymbolDefinitionCreator SymbolDefinitionCreator { get; set; }
34
35
public CancellationToken CancellationToken { get; set; }
src/wix/WixToolset.Core/PreprocessContext.cs
+4
@@ -24,6 +24,10 @@ namespace WixToolset.Core
24
25
public IReadOnlyCollection<string> IncludeSearchPaths { get; set; }
26
27
+ public string IntermediateFolder { get; set; }
28
+
29
+ public string OutputPath { get; set; }
30
+
31
public string SourcePath { get; set; }
32
33
public IDictionary<string, string> Variables { get; set; }
src/wix/WixToolset.Core/ResolveContext.cs
+2
@@ -37,6 +37,8 @@ namespace WixToolset.Core
37
38
public bool AllowUnresolvedVariables { get; set; }
39
40
+ public string OutputPath { get; set; }
41
+
42
public CancellationToken CancellationToken { get; set; }
43
}
44
}
src/wix/test/WixToolsetTest.CoreIntegration/LinkerFixture.cs
+2
@@ -32,7 +32,9 @@ namespace WixToolsetTest.CoreIntegration
32
var context = serviceProvider.GetService<ILinkContext>();
33
context.Extensions = Array.Empty<WixToolset.Extensibility.ILinkerExtension>();
34
context.ExtensionData = Array.Empty<WixToolset.Extensibility.IExtensionData>();
35
+ context.IntermediateFolder = Path.GetTempPath();
36
context.Intermediates = new[] { intermediate1, intermediate2 };
37
+ context.OutputPath = Path.Combine(context.IntermediateFolder, "test.msi");
38
context.SymbolDefinitionCreator = creator;
39
40
var linker = serviceProvider.GetService<ILinker>();