aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-06-02 19:45:25 +1000
committerSean Hall <r.sean.hall@gmail.com>2020-06-03 14:24:34 +1000
commita04ddca42b2070124c63a61c661e2b96a5bddac2 (patch)
treeb95095a7df475d32f3842542423d235accbdac70 /src
parent82a26a321bae36e38743f50f38887387a392ce24 (diff)
downloadwix-a04ddca42b2070124c63a61c661e2b96a5bddac2.tar.gz
wix-a04ddca42b2070124c63a61c661e2b96a5bddac2.tar.bz2
wix-a04ddca42b2070124c63a61c661e2b96a5bddac2.zip
Refactor the tasks so that the in-proc code is in partial classes.
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.BuildTasks/HeatTask.cs20
-rw-r--r--src/WixToolset.BuildTasks/HeatTask_InProc.cs27
-rw-r--r--src/WixToolset.BuildTasks/ToolsetTask.cs73
-rw-r--r--src/WixToolset.BuildTasks/ToolsetTask_InProc.cs71
-rw-r--r--src/WixToolset.BuildTasks/WixBuild.cs46
-rw-r--r--src/WixToolset.BuildTasks/WixBuild_InProc.cs53
6 files changed, 158 insertions, 132 deletions
diff --git a/src/WixToolset.BuildTasks/HeatTask.cs b/src/WixToolset.BuildTasks/HeatTask.cs
index 5feed26d..99cbae77 100644
--- a/src/WixToolset.BuildTasks/HeatTask.cs
+++ b/src/WixToolset.BuildTasks/HeatTask.cs
@@ -3,16 +3,12 @@
3namespace WixToolset.BuildTasks 3namespace WixToolset.BuildTasks
4{ 4{
5 using Microsoft.Build.Framework; 5 using Microsoft.Build.Framework;
6 using WixToolset.Extensibility;
7 using WixToolset.Extensibility.Data;
8 using WixToolset.Extensibility.Services;
9 using WixToolset.Harvesters;
10 6
11 /// <summary> 7 /// <summary>
12 /// A base MSBuild task to run the WiX harvester. 8 /// A base MSBuild task to run the WiX harvester.
13 /// Specific harvester tasks should extend this class. 9 /// Specific harvester tasks should extend this class.
14 /// </summary> 10 /// </summary>
15 public abstract class HeatTask : ToolsetTask 11 public abstract partial class HeatTask : ToolsetTask
16 { 12 {
17 private bool autogenerageGuids; 13 private bool autogenerageGuids;
18 private bool generateGuidsNow; 14 private bool generateGuidsNow;
@@ -59,7 +55,6 @@ namespace WixToolset.BuildTasks
59 set { this.transforms = value; } 55 set { this.transforms = value; }
60 } 56 }
61 57
62 protected sealed override string TaskShortName => "HEAT";
63 protected sealed override string ToolName => "heat.exe"; 58 protected sealed override string ToolName => "heat.exe";
64 59
65 /// <summary> 60 /// <summary>
@@ -72,19 +67,6 @@ namespace WixToolset.BuildTasks
72 get; 67 get;
73 } 68 }
74 69
75 protected sealed override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString)
76 {
77 var messaging = serviceProvider.GetService<IMessaging>();
78 messaging.SetListener(listener);
79
80 var arguments = serviceProvider.GetService<ICommandLineArguments>();
81 arguments.Populate(commandLineString);
82
83 var commandLine = HeatCommandLineFactory.CreateCommandLine(serviceProvider, true);
84 var command = commandLine.ParseStandardCommandLine(arguments);
85 return command?.Execute() ?? -1;
86 }
87
88 /// <summary> 70 /// <summary>
89 /// Builds a command line from options in this task. 71 /// Builds a command line from options in this task.
90 /// </summary> 72 /// </summary>
diff --git a/src/WixToolset.BuildTasks/HeatTask_InProc.cs b/src/WixToolset.BuildTasks/HeatTask_InProc.cs
new file mode 100644
index 00000000..8190d9e2
--- /dev/null
+++ b/src/WixToolset.BuildTasks/HeatTask_InProc.cs
@@ -0,0 +1,27 @@
1// 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.
2
3namespace WixToolset.BuildTasks
4{
5 using WixToolset.Extensibility;
6 using WixToolset.Extensibility.Data;
7 using WixToolset.Extensibility.Services;
8 using WixToolset.Harvesters;
9
10 public partial class HeatTask
11 {
12 protected sealed override string TaskShortName => "HEAT";
13
14 protected sealed override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString)
15 {
16 var messaging = serviceProvider.GetService<IMessaging>();
17 messaging.SetListener(listener);
18
19 var arguments = serviceProvider.GetService<ICommandLineArguments>();
20 arguments.Populate(commandLineString);
21
22 var commandLine = HeatCommandLineFactory.CreateCommandLine(serviceProvider, true);
23 var command = commandLine.ParseStandardCommandLine(arguments);
24 return command?.Execute() ?? -1;
25 }
26 }
27}
diff --git a/src/WixToolset.BuildTasks/ToolsetTask.cs b/src/WixToolset.BuildTasks/ToolsetTask.cs
index fe6812fc..4fd7af3f 100644
--- a/src/WixToolset.BuildTasks/ToolsetTask.cs
+++ b/src/WixToolset.BuildTasks/ToolsetTask.cs
@@ -4,15 +4,9 @@ namespace WixToolset.BuildTasks
4{ 4{
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using System.Runtime.InteropServices;
8 using Microsoft.Build.Framework;
9 using Microsoft.Build.Utilities; 7 using Microsoft.Build.Utilities;
10 using WixToolset.Core;
11 using WixToolset.Data;
12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
14 8
15 public abstract class ToolsetTask : ToolTask 9 public abstract partial class ToolsetTask : ToolTask
16 { 10 {
17 /// <summary> 11 /// <summary>
18 /// Gets or sets additional options that are appended the the tool command-line. 12 /// Gets or sets additional options that are appended the the tool command-line.
@@ -59,49 +53,6 @@ namespace WixToolset.BuildTasks
59 /// </summary> 53 /// </summary>
60 public bool VerboseOutput { get; set; } 54 public bool VerboseOutput { get; set; }
61 55
62 protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
63 {
64 if (this.RunAsSeparateProcess)
65 {
66 return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
67 }
68
69 return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}");
70 }
71
72 private int ExecuteInProc(string commandLineString)
73 {
74 this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}");
75
76 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
77 var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode);
78 int exitCode = -1;
79
80 try
81 {
82 exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString);
83 }
84 catch (WixException e)
85 {
86 listener.Write(e.Error);
87 }
88 catch (Exception e)
89 {
90 this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null);
91
92 if (e is NullReferenceException || e is SEHException)
93 {
94 throw;
95 }
96 }
97
98 if (exitCode == 0 && this.Log.HasLoggedErrors)
99 {
100 exitCode = -1;
101 }
102 return exitCode;
103 }
104
105 /// <summary> 56 /// <summary>
106 /// Get the path to the executable. 57 /// Get the path to the executable.
107 /// </summary> 58 /// </summary>
@@ -113,13 +64,12 @@ namespace WixToolset.BuildTasks
113 protected sealed override string GenerateFullPathToTool() 64 protected sealed override string GenerateFullPathToTool()
114 { 65 {
115 var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; 66 var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath;
116 if (this.RunAsSeparateProcess) 67 if (!this.RunAsSeparateProcess)
117 { 68 {
118 return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe); 69 // We need to return a path that exists, so if we're not actually going to run the tool then just return this dll path.
70 return thisDllPath;
119 } 71 }
120 72 return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe);
121 // We need to return a path that exists, so if we're not actually going to run the tool then just return this dll path.
122 return thisDllPath;
123 } 73 }
124 74
125 protected sealed override string GenerateResponseFileCommands() 75 protected sealed override string GenerateResponseFileCommands()
@@ -129,15 +79,6 @@ namespace WixToolset.BuildTasks
129 return commandLineBuilder.ToString(); 79 return commandLineBuilder.ToString();
130 } 80 }
131 81
132 protected sealed override void LogToolCommand(string message)
133 {
134 // Only log this if we're actually going to do it.
135 if (this.RunAsSeparateProcess)
136 {
137 base.LogToolCommand(message);
138 }
139 }
140
141 /// <summary> 82 /// <summary>
142 /// Builds a command line from options in this and derivative tasks. 83 /// Builds a command line from options in this and derivative tasks.
143 /// </summary> 84 /// </summary>
@@ -153,9 +94,5 @@ namespace WixToolset.BuildTasks
153 commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); 94 commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors);
154 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); 95 commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors);
155 } 96 }
156
157 protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString);
158
159 protected abstract string TaskShortName { get; }
160 } 97 }
161} 98}
diff --git a/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs
new file mode 100644
index 00000000..4b365b2a
--- /dev/null
+++ b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs
@@ -0,0 +1,71 @@
1// 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.
2
3namespace WixToolset.BuildTasks
4{
5 using System;
6 using System.Runtime.InteropServices;
7 using Microsoft.Build.Framework;
8 using WixToolset.Core;
9 using WixToolset.Data;
10 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services;
12
13 public partial class ToolsetTask
14 {
15 protected sealed override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
16 {
17 if (this.RunAsSeparateProcess)
18 {
19 return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
20 }
21
22 return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}");
23 }
24
25 private int ExecuteInProc(string commandLineString)
26 {
27 this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}");
28
29 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
30 var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode);
31 int exitCode = -1;
32
33 try
34 {
35 exitCode = this.ExecuteCore(serviceProvider, listener, commandLineString);
36 }
37 catch (WixException e)
38 {
39 listener.Write(e.Error);
40 }
41 catch (Exception e)
42 {
43 this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null);
44
45 if (e is NullReferenceException || e is SEHException)
46 {
47 throw;
48 }
49 }
50
51 if (exitCode == 0 && this.Log.HasLoggedErrors)
52 {
53 exitCode = -1;
54 }
55 return exitCode;
56 }
57
58 protected sealed override void LogToolCommand(string message)
59 {
60 // Only log this if we're actually going to do it.
61 if (this.RunAsSeparateProcess)
62 {
63 base.LogToolCommand(message);
64 }
65 }
66
67 protected abstract int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString);
68
69 protected abstract string TaskShortName { get; }
70 }
71}
diff --git a/src/WixToolset.BuildTasks/WixBuild.cs b/src/WixToolset.BuildTasks/WixBuild.cs
index c15bc2f7..b669c52b 100644
--- a/src/WixToolset.BuildTasks/WixBuild.cs
+++ b/src/WixToolset.BuildTasks/WixBuild.cs
@@ -5,15 +5,11 @@ namespace WixToolset.BuildTasks
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using Microsoft.Build.Framework; 7 using Microsoft.Build.Framework;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10 using WixToolset.Extensibility.Data;
11 using WixToolset.Extensibility.Services;
12 8
13 /// <summary> 9 /// <summary>
14 /// An MSBuild task to run the WiX compiler. 10 /// An MSBuild task to run the WiX compiler.
15 /// </summary> 11 /// </summary>
16 public sealed class WixBuild : ToolsetTask 12 public sealed partial class WixBuild : ToolsetTask
17 { 13 {
18 public string[] Cultures { get; set; } 14 public string[] Cultures { get; set; }
19 15
@@ -76,24 +72,8 @@ namespace WixToolset.BuildTasks
76 public string[] SuppressIces { get; set; } 72 public string[] SuppressIces { get; set; }
77 public string AdditionalCub { get; set; } 73 public string AdditionalCub { get; set; }
78 74
79 protected override string TaskShortName => "WIX";
80 protected override string ToolName => "wix.exe"; 75 protected override string ToolName => "wix.exe";
81 76
82 protected override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString)
83 {
84 var messaging = serviceProvider.GetService<IMessaging>();
85 messaging.SetListener(listener);
86
87 var arguments = serviceProvider.GetService<ICommandLineArguments>();
88 arguments.Populate(commandLineString);
89
90 var commandLine = serviceProvider.GetService<ICommandLine>();
91 commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions);
92 commandLine.Arguments = arguments;
93 var command = commandLine.ParseStandardCommandLine();
94 return command?.Execute() ?? -1;
95 }
96
97 protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) 77 protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
98 { 78 {
99 commandLineBuilder.AppendTextUnquoted("build"); 79 commandLineBuilder.AppendTextUnquoted("build");
@@ -126,30 +106,6 @@ namespace WixToolset.BuildTasks
126 commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " "); 106 commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
127 } 107 }
128 108
129 private IExtensionManager CreateExtensionManagerWithStandardBackends(IWixToolsetServiceProvider serviceProvider, IMessaging messaging, string[] extensions)
130 {
131 var extensionManager = serviceProvider.GetService<IExtensionManager>();
132
133 foreach (var type in new[] { typeof(WixToolset.Core.Burn.WixToolsetStandardBackend), typeof(WixToolset.Core.WindowsInstaller.WixToolsetStandardBackend) })
134 {
135 extensionManager.Add(type.Assembly);
136 }
137
138 foreach (var extension in extensions)
139 {
140 try
141 {
142 extensionManager.Load(extension);
143 }
144 catch (WixException e)
145 {
146 messaging.Write(e.Error);
147 }
148 }
149
150 return extensionManager;
151 }
152
153 private IEnumerable<string> CalculateBindPathStrings() 109 private IEnumerable<string> CalculateBindPathStrings()
154 { 110 {
155 if (null != this.BindInputPaths) 111 if (null != this.BindInputPaths)
diff --git a/src/WixToolset.BuildTasks/WixBuild_InProc.cs b/src/WixToolset.BuildTasks/WixBuild_InProc.cs
new file mode 100644
index 00000000..8e9f2fec
--- /dev/null
+++ b/src/WixToolset.BuildTasks/WixBuild_InProc.cs
@@ -0,0 +1,53 @@
1// 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.
2
3namespace WixToolset.BuildTasks
4{
5 using WixToolset.Data;
6 using WixToolset.Extensibility;
7 using WixToolset.Extensibility.Data;
8 using WixToolset.Extensibility.Services;
9
10 public partial class WixBuild
11 {
12 protected override string TaskShortName => "WIX";
13
14 protected override int ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener listener, string commandLineString)
15 {
16 var messaging = serviceProvider.GetService<IMessaging>();
17 messaging.SetListener(listener);
18
19 var arguments = serviceProvider.GetService<ICommandLineArguments>();
20 arguments.Populate(commandLineString);
21
22 var commandLine = serviceProvider.GetService<ICommandLine>();
23 commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions);
24 commandLine.Arguments = arguments;
25 var command = commandLine.ParseStandardCommandLine();
26 return command?.Execute() ?? -1;
27 }
28
29 private IExtensionManager CreateExtensionManagerWithStandardBackends(IWixToolsetServiceProvider serviceProvider, IMessaging messaging, string[] extensions)
30 {
31 var extensionManager = serviceProvider.GetService<IExtensionManager>();
32
33 foreach (var type in new[] { typeof(WixToolset.Core.Burn.WixToolsetStandardBackend), typeof(WixToolset.Core.WindowsInstaller.WixToolsetStandardBackend) })
34 {
35 extensionManager.Add(type.Assembly);
36 }
37
38 foreach (var extension in extensions)
39 {
40 try
41 {
42 extensionManager.Load(extension);
43 }
44 catch (WixException e)
45 {
46 messaging.Write(e.Error);
47 }
48 }
49
50 return extensionManager;
51 }
52 }
53}