aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-19 12:25:40 -0800
committerRob Mensching <rob@firegiant.com>2017-12-19 12:25:40 -0800
commit155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 (patch)
tree59d1f151bfde8068b6014b05b5c8cfea3402c974 /src/WixToolset.Core/CommandLine
parent6f1665ed759b31bd095f186f9239232c653597cd (diff)
downloadwix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.tar.gz
wix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.tar.bz2
wix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.zip
Integrate simplified message handling
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs59
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs26
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineContext.cs3
-rw-r--r--src/WixToolset.Core/CommandLine/CompileCommand.cs9
4 files changed, 54 insertions, 43 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index 7a63b869..43b75f33 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -13,9 +13,10 @@ namespace WixToolset.Core
13 13
14 internal class BuildCommand : ICommandLineCommand 14 internal class BuildCommand : ICommandLineCommand
15 { 15 {
16 public BuildCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) 16 public BuildCommand(IServiceProvider serviceProvider, IMessaging messaging, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile)
17 { 17 {
18 this.ServiceProvider = serviceProvider; 18 this.ServiceProvider = serviceProvider;
19 this.Messaging = messaging;
19 this.ExtensionManager = extensions; 20 this.ExtensionManager = extensions;
20 this.LocFiles = locFiles; 21 this.LocFiles = locFiles;
21 this.LibraryFiles = libraryFiles; 22 this.LibraryFiles = libraryFiles;
@@ -38,6 +39,8 @@ namespace WixToolset.Core
38 39
39 public IServiceProvider ServiceProvider { get; } 40 public IServiceProvider ServiceProvider { get; }
40 41
42 public IMessaging Messaging { get; }
43
41 public IExtensionManager ExtensionManager { get; } 44 public IExtensionManager ExtensionManager { get; }
42 45
43 public IEnumerable<string> IncludeSearchPaths { get; } 46 public IEnumerable<string> IncludeSearchPaths { get; }
@@ -91,13 +94,13 @@ namespace WixToolset.Core
91 { 94 {
92 var output = this.LinkPhase(intermediates); 95 var output = this.LinkPhase(intermediates);
93 96
94 if (!Messaging.Instance.EncounteredError) 97 if (!this.Messaging.EncounteredError)
95 { 98 {
96 this.BindPhase(output); 99 this.BindPhase(output);
97 } 100 }
98 } 101 }
99 102
100 return Messaging.Instance.LastErrorNumber; 103 return this.Messaging.LastErrorNumber;
101 } 104 }
102 105
103 private IEnumerable<Intermediate> CompilePhase() 106 private IEnumerable<Intermediate> CompilePhase()
@@ -107,7 +110,7 @@ namespace WixToolset.Core
107 foreach (var sourceFile in this.SourceFiles) 110 foreach (var sourceFile in this.SourceFiles)
108 { 111 {
109 var preprocessContext = this.ServiceProvider.GetService<IPreprocessContext>(); 112 var preprocessContext = this.ServiceProvider.GetService<IPreprocessContext>();
110 preprocessContext.Messaging = Messaging.Instance; 113 preprocessContext.Messaging = this.Messaging;
111 preprocessContext.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>(); 114 preprocessContext.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>();
112 preprocessContext.Platform = Platform.X86; // TODO: set this correctly 115 preprocessContext.Platform = Platform.X86; // TODO: set this correctly
113 preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List<string>(); 116 preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List<string>();
@@ -117,18 +120,24 @@ namespace WixToolset.Core
117 var preprocessor = new Preprocessor(); 120 var preprocessor = new Preprocessor();
118 var document = preprocessor.Process(preprocessContext); 121 var document = preprocessor.Process(preprocessContext);
119 122
120 var compileContext = this.ServiceProvider.GetService<ICompileContext>(); 123 if (!this.Messaging.EncounteredError)
121 compileContext.Messaging = Messaging.Instance; 124 {
122 compileContext.CompilationId = Guid.NewGuid().ToString("N"); 125 var compileContext = this.ServiceProvider.GetService<ICompileContext>();
123 compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>(); 126 compileContext.Messaging = this.Messaging;
124 compileContext.OutputPath = sourceFile.OutputPath; 127 compileContext.CompilationId = Guid.NewGuid().ToString("N");
125 compileContext.Platform = Platform.X86; // TODO: set this correctly 128 compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>();
126 compileContext.Source = document; 129 compileContext.OutputPath = sourceFile.OutputPath;
127 130 compileContext.Platform = Platform.X86; // TODO: set this correctly
128 var compiler = new Compiler(); 131 compileContext.Source = document;
129 var intermediate = compiler.Compile(compileContext); 132
130 133 var compiler = new Compiler();
131 intermediates.Add(intermediate); 134 var intermediate = compiler.Compile(compileContext);
135
136 if (!this.Messaging.EncounteredError)
137 {
138 intermediates.Add(intermediate);
139 }
140 }
132 } 141 }
133 142
134 return intermediates; 143 return intermediates;
@@ -139,7 +148,7 @@ namespace WixToolset.Core
139 var localizations = this.LoadLocalizationFiles().ToList(); 148 var localizations = this.LoadLocalizationFiles().ToList();
140 149
141 // If there was an error adding localization files, then bail. 150 // If there was an error adding localization files, then bail.
142 if (Messaging.Instance.EncounteredError) 151 if (this.Messaging.EncounteredError)
143 { 152 {
144 return null; 153 return null;
145 } 154 }
@@ -166,7 +175,7 @@ namespace WixToolset.Core
166 var libraries = this.LoadLibraries(creator); 175 var libraries = this.LoadLibraries(creator);
167 176
168 var context = this.ServiceProvider.GetService<ILinkContext>(); 177 var context = this.ServiceProvider.GetService<ILinkContext>();
169 context.Messaging = Messaging.Instance; 178 context.Messaging = this.Messaging;
170 context.Extensions = this.ExtensionManager.Create<ILinkerExtension>(); 179 context.Extensions = this.ExtensionManager.Create<ILinkerExtension>();
171 context.ExtensionData = this.ExtensionManager.Create<IExtensionData>(); 180 context.ExtensionData = this.ExtensionManager.Create<IExtensionData>();
172 context.ExpectedOutputType = this.OutputType; 181 context.ExpectedOutputType = this.OutputType;
@@ -182,7 +191,7 @@ namespace WixToolset.Core
182 { 191 {
183 var localizations = this.LoadLocalizationFiles().ToList(); 192 var localizations = this.LoadLocalizationFiles().ToList();
184 193
185 var localizer = new Localizer(localizations); 194 var localizer = new Localizer(this.Messaging, localizations);
186 195
187 var resolver = CreateWixResolverWithVariables(localizer, output); 196 var resolver = CreateWixResolverWithVariables(localizer, output);
188 197
@@ -193,7 +202,7 @@ namespace WixToolset.Core
193 } 202 }
194 203
195 var context = this.ServiceProvider.GetService<IBindContext>(); 204 var context = this.ServiceProvider.GetService<IBindContext>();
196 context.Messaging = Messaging.Instance; 205 context.Messaging = this.Messaging;
197 context.ExtensionManager = this.ExtensionManager; 206 context.ExtensionManager = this.ExtensionManager;
198 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>(); 207 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>();
199 //context.CabbingThreadCount = this.CabbingThreadCount; 208 //context.CabbingThreadCount = this.CabbingThreadCount;
@@ -234,11 +243,11 @@ namespace WixToolset.Core
234 } 243 }
235 catch (WixCorruptFileException e) 244 catch (WixCorruptFileException e)
236 { 245 {
237 Messaging.Instance.OnMessage(e.Error); 246 this.Messaging.Write(e.Error);
238 } 247 }
239 catch (WixUnexpectedFileFormatException e) 248 catch (WixUnexpectedFileFormatException e)
240 { 249 {
241 Messaging.Instance.OnMessage(e.Error); 250 this.Messaging.Write(e.Error);
242 } 251 }
243 } 252 }
244 } 253 }
@@ -250,15 +259,15 @@ namespace WixToolset.Core
250 { 259 {
251 foreach (var loc in this.LocFiles) 260 foreach (var loc in this.LocFiles)
252 { 261 {
253 var localization = Localizer.ParseLocalizationFile(loc); 262 var localization = Localizer.ParseLocalizationFile(this.Messaging, loc);
254 263
255 yield return localization; 264 yield return localization;
256 } 265 }
257 } 266 }
258 267
259 private static WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Intermediate output) 268 private WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Intermediate output)
260 { 269 {
261 var resolver = new WixVariableResolver(localizer); 270 var resolver = new WixVariableResolver(this.Messaging, localizer);
262 271
263 // Gather all the wix variables. 272 // Gather all the wix variables.
264 var wixVariables = output?.Sections.SelectMany(s => s.Tuples).OfType<WixVariableTuple>(); 273 var wixVariables = output?.Sections.SelectMany(s => s.Tuples).OfType<WixVariableTuple>();
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 9bedca9a..9db1b2f9 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -24,12 +24,10 @@ namespace WixToolset.Core
24 24
25 internal class CommandLine : ICommandLine, IParseCommandLine 25 internal class CommandLine : ICommandLine, IParseCommandLine
26 { 26 {
27 public CommandLine()
28 {
29 }
30
31 private IServiceProvider ServiceProvider { get; set; } 27 private IServiceProvider ServiceProvider { get; set; }
32 28
29 private IMessaging Messaging { get; set; }
30
33 public static string ExpectedArgument { get; } = "expected argument"; 31 public static string ExpectedArgument { get; } = "expected argument";
34 32
35 public string ActiveCommand { get; private set; } 33 public string ActiveCommand { get; private set; }
@@ -48,6 +46,8 @@ namespace WixToolset.Core
48 { 46 {
49 this.ServiceProvider = context.ServiceProvider; 47 this.ServiceProvider = context.ServiceProvider;
50 48
49 this.Messaging = context.Messaging ?? this.ServiceProvider.GetService<IMessaging>();
50
51 this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>(); 51 this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>();
52 52
53 var args = context.ParsedArguments ?? Array.Empty<string>(); 53 var args = context.ParsedArguments ?? Array.Empty<string>();
@@ -186,7 +186,7 @@ namespace WixToolset.Core
186 } 186 }
187 }); 187 });
188 188
189 Messaging.Instance.ShowVerboseMessages = verbose; 189 this.Messaging.ShowVerboseMessages = verbose;
190 190
191 if (showVersion) 191 if (showVersion)
192 { 192 {
@@ -208,17 +208,17 @@ namespace WixToolset.Core
208 case Commands.Build: 208 case Commands.Build:
209 { 209 {
210 var sourceFiles = GatherSourceFiles(files, outputFolder); 210 var sourceFiles = GatherSourceFiles(files, outputFolder);
211 var variables = GatherPreprocessorVariables(defines); 211 var variables = this.GatherPreprocessorVariables(defines);
212 var bindPathList = GatherBindPaths(bindPaths); 212 var bindPathList = this.GatherBindPaths(bindPaths);
213 var type = CalculateOutputType(outputType, outputFile); 213 var type = CalculateOutputType(outputType, outputFile);
214 return new BuildCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); 214 return new BuildCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile);
215 } 215 }
216 216
217 case Commands.Compile: 217 case Commands.Compile:
218 { 218 {
219 var sourceFiles = GatherSourceFiles(files, outputFolder); 219 var sourceFiles = GatherSourceFiles(files, outputFolder);
220 var variables = GatherPreprocessorVariables(defines); 220 var variables = GatherPreprocessorVariables(defines);
221 return new CompileCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables); 221 return new CompileCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables);
222 } 222 }
223 } 223 }
224 224
@@ -305,7 +305,7 @@ namespace WixToolset.Core
305 return files; 305 return files;
306 } 306 }
307 307
308 private static IDictionary<string, string> GatherPreprocessorVariables(IEnumerable<string> defineConstants) 308 private IDictionary<string, string> GatherPreprocessorVariables(IEnumerable<string> defineConstants)
309 { 309 {
310 var variables = new Dictionary<string, string>(); 310 var variables = new Dictionary<string, string>();
311 311
@@ -315,7 +315,7 @@ namespace WixToolset.Core
315 315
316 if (variables.ContainsKey(value[0])) 316 if (variables.ContainsKey(value[0]))
317 { 317 {
318 Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], variables[value[0]])); 318 this.Messaging.Write(ErrorMessages.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], variables[value[0]]));
319 continue; 319 continue;
320 } 320 }
321 321
@@ -325,7 +325,7 @@ namespace WixToolset.Core
325 return variables; 325 return variables;
326 } 326 }
327 327
328 private static IEnumerable<BindPath> GatherBindPaths(IEnumerable<string> bindPaths) 328 private IEnumerable<BindPath> GatherBindPaths(IEnumerable<string> bindPaths)
329 { 329 {
330 var result = new List<BindPath>(); 330 var result = new List<BindPath>();
331 331
@@ -339,7 +339,7 @@ namespace WixToolset.Core
339 } 339 }
340 else if (File.Exists(bp.Path)) 340 else if (File.Exists(bp.Path))
341 { 341 {
342 Messaging.Instance.OnMessage(WixErrors.ExpectedDirectoryGotFile("-bindpath", bp.Path)); 342 this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path));
343 } 343 }
344 } 344 }
345 345
diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
index 96c149be..cbb9af53 100644
--- a/src/WixToolset.Core/CommandLine/CommandLineContext.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
@@ -3,7 +3,6 @@
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using WixToolset.Data;
7 using WixToolset.Extensibility.Services; 6 using WixToolset.Extensibility.Services;
8 7
9 internal class CommandLineContext : ICommandLineContext 8 internal class CommandLineContext : ICommandLineContext
@@ -15,7 +14,7 @@ namespace WixToolset.Core
15 14
16 public IServiceProvider ServiceProvider { get; } 15 public IServiceProvider ServiceProvider { get; }
17 16
18 public Messaging Messaging { get; set; } 17 public IMessaging Messaging { get; set; }
19 18
20 public IExtensionManager ExtensionManager { get; set; } 19 public IExtensionManager ExtensionManager { get; set; }
21 20
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs
index e7fcdd4d..856dd29f 100644
--- a/src/WixToolset.Core/CommandLine/CompileCommand.cs
+++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs
@@ -11,16 +11,19 @@ namespace WixToolset.Core
11 11
12 internal class CompileCommand : ICommandLineCommand 12 internal class CompileCommand : ICommandLineCommand
13 { 13 {
14 public CompileCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables) 14 public CompileCommand(IServiceProvider serviceProvider, IMessaging messaging, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables)
15 { 15 {
16 this.PreprocessorVariables = preprocessorVariables; 16 this.PreprocessorVariables = preprocessorVariables;
17 this.ServiceProvider = serviceProvider; 17 this.ServiceProvider = serviceProvider;
18 this.Messaging = messaging;
18 this.ExtensionManager = extensions; 19 this.ExtensionManager = extensions;
19 this.SourceFiles = sources; 20 this.SourceFiles = sources;
20 } 21 }
21 22
22 private IServiceProvider ServiceProvider { get; } 23 private IServiceProvider ServiceProvider { get; }
23 24
25 private IMessaging Messaging { get; }
26
24 private IExtensionManager ExtensionManager { get; } 27 private IExtensionManager ExtensionManager { get; }
25 28
26 public IEnumerable<string> IncludeSearchPaths { get; } 29 public IEnumerable<string> IncludeSearchPaths { get; }
@@ -34,7 +37,7 @@ namespace WixToolset.Core
34 foreach (var sourceFile in this.SourceFiles) 37 foreach (var sourceFile in this.SourceFiles)
35 { 38 {
36 var preprocessContext = this.ServiceProvider.GetService<IPreprocessContext>(); 39 var preprocessContext = this.ServiceProvider.GetService<IPreprocessContext>();
37 preprocessContext.Messaging = Messaging.Instance; 40 preprocessContext.Messaging = this.Messaging;
38 preprocessContext.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>(); 41 preprocessContext.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>();
39 preprocessContext.Platform = Platform.X86; // TODO: set this correctly 42 preprocessContext.Platform = Platform.X86; // TODO: set this correctly
40 preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List<string>(); 43 preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List<string>();
@@ -45,7 +48,7 @@ namespace WixToolset.Core
45 var document = preprocessor.Process(preprocessContext); 48 var document = preprocessor.Process(preprocessContext);
46 49
47 var compileContext = this.ServiceProvider.GetService<ICompileContext>(); 50 var compileContext = this.ServiceProvider.GetService<ICompileContext>();
48 compileContext.Messaging = Messaging.Instance; 51 compileContext.Messaging = this.Messaging;
49 compileContext.CompilationId = Guid.NewGuid().ToString("N"); 52 compileContext.CompilationId = Guid.NewGuid().ToString("N");
50 compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>(); 53 compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>();
51 compileContext.OutputPath = sourceFile.OutputPath; 54 compileContext.OutputPath = sourceFile.OutputPath;