aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs194
-rw-r--r--src/WixToolset.Core/CommandLine/CompileCommand.cs31
2 files changed, 137 insertions, 88 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index 76502bb0..6052d979 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -8,6 +8,7 @@ namespace WixToolset.Core.CommandLine
8 using System.Linq; 8 using System.Linq;
9 using System.Xml.Linq; 9 using System.Xml.Linq;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Data; 12 using WixToolset.Extensibility.Data;
12 using WixToolset.Extensibility.Services; 13 using WixToolset.Extensibility.Services;
13 14
@@ -172,16 +173,24 @@ namespace WixToolset.Core.CommandLine
172 173
173 foreach (var sourceFile in sourceFiles) 174 foreach (var sourceFile in sourceFiles)
174 { 175 {
175 var preprocessor = new Preprocessor(this.ServiceProvider); 176 var document = this.Preprocess(sourceFile.SourcePath);
176 preprocessor.IncludeSearchPaths = this.IncludeSearchPaths;
177 preprocessor.Platform = this.Platform;
178 preprocessor.SourcePath = sourceFile.SourcePath;
179 preprocessor.Variables = this.PreprocessorVariables;
180 177
181 XDocument document = null; 178 if (this.Messaging.EncounteredError)
179 {
180 continue;
181 }
182
183 var context = this.ServiceProvider.GetService<ICompileContext>();
184 context.Extensions = this.ExtensionManager.Create<ICompilerExtension>();
185 context.OutputPath = sourceFile.OutputPath;
186 context.Platform = this.Platform;
187 context.Source = document;
188
189 Intermediate intermediate = null;
182 try 190 try
183 { 191 {
184 document = preprocessor.Execute(); 192 var compiler = this.ServiceProvider.GetService<ICompiler>();
193 intermediate = compiler.Compile(context);
185 } 194 }
186 catch (WixException e) 195 catch (WixException e)
187 { 196 {
@@ -193,17 +202,6 @@ namespace WixToolset.Core.CommandLine
193 continue; 202 continue;
194 } 203 }
195 204
196 var compiler = new Compiler(this.ServiceProvider);
197 compiler.OutputPath = sourceFile.OutputPath;
198 compiler.Platform = this.Platform;
199 compiler.SourceDocument = document;
200 var intermediate = compiler.Execute();
201
202 if (this.Messaging.EncounteredError)
203 {
204 continue;
205 }
206
207 intermediates.Add(intermediate); 205 intermediates.Add(intermediate);
208 } 206 }
209 207
@@ -212,14 +210,27 @@ namespace WixToolset.Core.CommandLine
212 210
213 private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates, IEnumerable<Localization> localizations) 211 private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates, IEnumerable<Localization> localizations)
214 { 212 {
215 var librarian = new Librarian(this.ServiceProvider); 213 var context = this.ServiceProvider.GetService<ILibraryContext>();
216 librarian.BindFiles = this.BindFiles; 214 context.BindFiles = this.BindFiles;
217 librarian.BindPaths = this.BindPaths; 215 context.BindPaths = this.BindPaths;
218 librarian.Intermediates = intermediates; 216 context.Extensions = this.ExtensionManager.Create<ILibrarianExtension>();
219 librarian.Localizations = localizations; 217 context.Localizations = localizations;
220 return librarian.Execute(); 218 context.Intermediates = intermediates;
221 } 219
220 Intermediate library = null;
221 try
222 {
223 var librarian = this.ServiceProvider.GetService<ILibrarian>();
224 library = librarian.Combine(context);
225 }
226 catch (WixException e)
227 {
228 this.Messaging.Write(e.Error);
229 }
222 230
231 return library;
232 }
233
223 private Intermediate LinkPhase(IEnumerable<Intermediate> intermediates, ITupleDefinitionCreator creator) 234 private Intermediate LinkPhase(IEnumerable<Intermediate> intermediates, ITupleDefinitionCreator creator)
224 { 235 {
225 var libraries = this.LoadLibraries(creator); 236 var libraries = this.LoadLibraries(creator);
@@ -229,26 +240,39 @@ namespace WixToolset.Core.CommandLine
229 return null; 240 return null;
230 } 241 }
231 242
232 var linker = new Linker(this.ServiceProvider); 243 var context = this.ServiceProvider.GetService<ILinkContext>();
233 linker.OutputType = this.OutputType; 244 context.Extensions = this.ExtensionManager.Create<ILinkerExtension>();
234 linker.Intermediates = intermediates; 245 context.ExtensionData = this.ExtensionManager.Create<IExtensionData>();
235 linker.Libraries = libraries; 246 context.ExpectedOutputType = this.OutputType;
236 linker.TupleDefinitionCreator = creator; 247 context.Intermediates = intermediates.Concat(libraries).ToList();
237 return linker.Execute(); 248 context.TupleDefinitionCreator = creator;
249
250 var linker = this.ServiceProvider.GetService<ILinker>();
251 return linker.Link(context);
238 } 252 }
239 253
240 private void BindPhase(Intermediate output, IEnumerable<Localization> localizations) 254 private void BindPhase(Intermediate output, IEnumerable<Localization> localizations)
241 { 255 {
256 var intermediateFolder = this.IntermediateFolder;
257 if (String.IsNullOrEmpty(intermediateFolder))
258 {
259 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
260 }
261
242 ResolveResult resolveResult; 262 ResolveResult resolveResult;
243 { 263 {
244 var resolver = new Resolver(this.ServiceProvider); 264 var context = this.ServiceProvider.GetService<IResolveContext>();
245 resolver.BindPaths = this.BindPaths; 265 context.BindPaths = this.BindPaths;
246 resolver.FilterCultures = this.FilterCultures; 266 context.Extensions = this.ExtensionManager.Create<IResolverExtension>();
247 resolver.IntermediateFolder = this.IntermediateFolder; 267 context.ExtensionData = this.ExtensionManager.Create<IExtensionData>();
248 resolver.IntermediateRepresentation = output; 268 context.FilterCultures = this.FilterCultures;
249 resolver.Localizations = localizations; 269 context.IntermediateFolder = intermediateFolder;
250 270 context.IntermediateRepresentation = output;
251 resolveResult = resolver.Execute(); 271 context.Localizations = localizations;
272 context.VariableResolver = new WixVariableResolver(this.Messaging);
273
274 var resolver = this.ServiceProvider.GetService<IResolver>();
275 resolveResult = resolver.Resolve(context);
252 } 276 }
253 277
254 if (this.Messaging.EncounteredError) 278 if (this.Messaging.EncounteredError)
@@ -258,28 +282,24 @@ namespace WixToolset.Core.CommandLine
258 282
259 BindResult bindResult; 283 BindResult bindResult;
260 { 284 {
261 var intermediateFolder = this.IntermediateFolder; 285 var context = this.ServiceProvider.GetService<IBindContext>();
262 if (String.IsNullOrEmpty(intermediateFolder)) 286 //context.CabbingThreadCount = this.CabbingThreadCount;
263 { 287 context.CabCachePath = this.CabCachePath;
264 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); 288 context.Codepage = resolveResult.Codepage;
265 } 289 //context.DefaultCompressionLevel = this.DefaultCompressionLevel;
266 290 context.DelayedFields = resolveResult.DelayedFields;
267 var binder = new Binder(this.ServiceProvider); 291 context.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles;
268 //binder.CabbingThreadCount = this.CabbingThreadCount; 292 context.Extensions = this.ExtensionManager.Create<IBinderExtension>();
269 binder.CabCachePath = this.CabCachePath; 293 context.Ices = Array.Empty<string>(); // TODO: set this correctly
270 binder.Codepage = resolveResult.Codepage; 294 context.IntermediateFolder = intermediateFolder;
271 //binder.DefaultCompressionLevel = this.DefaultCompressionLevel; 295 context.IntermediateRepresentation = resolveResult.IntermediateRepresentation;
272 binder.DelayedFields = resolveResult.DelayedFields; 296 context.OutputPath = this.OutputPath;
273 binder.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; 297 context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb");
274 binder.Ices = Array.Empty<string>(); // TODO: set this correctly 298 context.SuppressIces = Array.Empty<string>(); // TODO: set this correctly
275 binder.IntermediateFolder = intermediateFolder; 299 context.SuppressValidation = true; // TODO: set this correctly
276 binder.IntermediateRepresentation = resolveResult.IntermediateRepresentation; 300
277 binder.OutputPath = this.OutputPath; 301 var binder = this.ServiceProvider.GetService<IBinder>();
278 binder.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); 302 bindResult = binder.Bind(context);
279 binder.SuppressIces = Array.Empty<string>(); // TODO: set this correctly
280 binder.SuppressValidation = true; // TODO: set this correctly
281
282 bindResult = binder.Execute();
283 } 303 }
284 304
285 if (this.Messaging.EncounteredError) 305 if (this.Messaging.EncounteredError)
@@ -288,16 +308,18 @@ namespace WixToolset.Core.CommandLine
288 } 308 }
289 309
290 { 310 {
291 var layout = new Layout(this.ServiceProvider); 311 var context = this.ServiceProvider.GetService<ILayoutContext>();
292 layout.TrackedFiles = bindResult.TrackedFiles; 312 context.Extensions = this.ExtensionManager.Create<ILayoutExtension>();
293 layout.FileTransfers = bindResult.FileTransfers; 313 context.TrackedFiles = bindResult.TrackedFiles;
294 layout.IntermediateFolder = this.IntermediateFolder; 314 context.FileTransfers = bindResult.FileTransfers;
295 layout.ContentsFile = this.ContentsFile; 315 context.IntermediateFolder = intermediateFolder;
296 layout.OutputsFile = this.OutputsFile; 316 context.ContentsFile = this.ContentsFile;
297 layout.BuiltOutputsFile = this.BuiltOutputsFile; 317 context.OutputsFile = this.OutputsFile;
298 layout.SuppressAclReset = false; // TODO: correctly set SuppressAclReset 318 context.BuiltOutputsFile = this.BuiltOutputsFile;
299 319 context.SuppressAclReset = false; // TODO: correctly set SuppressAclReset
300 layout.Execute(); 320
321 var layout = this.ServiceProvider.GetService<ILayoutCreator>();
322 layout.Layout(context);
301 } 323 }
302 } 324 }
303 325
@@ -335,12 +357,7 @@ namespace WixToolset.Core.CommandLine
335 357
336 foreach (var loc in this.LocFiles) 358 foreach (var loc in this.LocFiles)
337 { 359 {
338 var preprocessor = new Preprocessor(this.ServiceProvider); 360 var document = this.Preprocess(loc);
339 preprocessor.IncludeSearchPaths = this.IncludeSearchPaths;
340 preprocessor.Platform = Platform.X86; // TODO: set this correctly
341 preprocessor.SourcePath = loc;
342 preprocessor.Variables = this.PreprocessorVariables;
343 var document = preprocessor.Execute();
344 361
345 if (this.Messaging.EncounteredError) 362 if (this.Messaging.EncounteredError)
346 { 363 {
@@ -351,5 +368,28 @@ namespace WixToolset.Core.CommandLine
351 yield return localization; 368 yield return localization;
352 } 369 }
353 } 370 }
371
372 private XDocument Preprocess(string sourcePath)
373 {
374 var context = this.ServiceProvider.GetService<IPreprocessContext>();
375 context.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>();
376 context.Platform = this.Platform;
377 context.IncludeSearchPaths = this.IncludeSearchPaths;
378 context.SourcePath = sourcePath;
379 context.Variables = this.PreprocessorVariables;
380
381 XDocument document = null;
382 try
383 {
384 var preprocessor = this.ServiceProvider.GetService<IPreprocessor>();
385 document = preprocessor.Preprocess(context);
386 }
387 catch (WixException e)
388 {
389 this.Messaging.Write(e.Error);
390 }
391
392 return document;
393 }
354 } 394 }
355} 395}
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs
index 621571b1..4007c263 100644
--- a/src/WixToolset.Core/CommandLine/CompileCommand.cs
+++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs
@@ -6,6 +6,7 @@ namespace WixToolset.Core.CommandLine
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Xml.Linq; 7 using System.Xml.Linq;
8 using WixToolset.Data; 8 using WixToolset.Data;
9 using WixToolset.Extensibility;
9 using WixToolset.Extensibility.Data; 10 using WixToolset.Extensibility.Data;
10 using WixToolset.Extensibility.Services; 11 using WixToolset.Extensibility.Services;
11 12
@@ -15,6 +16,7 @@ namespace WixToolset.Core.CommandLine
15 { 16 {
16 this.ServiceProvider = serviceProvider; 17 this.ServiceProvider = serviceProvider;
17 this.Messaging = serviceProvider.GetService<IMessaging>(); 18 this.Messaging = serviceProvider.GetService<IMessaging>();
19 this.ExtensionManager = serviceProvider.GetService<IExtensionManager>();
18 this.SourceFiles = sources; 20 this.SourceFiles = sources;
19 this.PreprocessorVariables = preprocessorVariables; 21 this.PreprocessorVariables = preprocessorVariables;
20 this.Platform = platform; 22 this.Platform = platform;
@@ -24,6 +26,8 @@ namespace WixToolset.Core.CommandLine
24 26
25 public IMessaging Messaging { get; } 27 public IMessaging Messaging { get; }
26 28
29 public IExtensionManager ExtensionManager { get; }
30
27 private IEnumerable<SourceFile> SourceFiles { get; } 31 private IEnumerable<SourceFile> SourceFiles { get; }
28 32
29 private IDictionary<string, string> PreprocessorVariables { get; } 33 private IDictionary<string, string> PreprocessorVariables { get; }
@@ -36,16 +40,18 @@ namespace WixToolset.Core.CommandLine
36 { 40 {
37 foreach (var sourceFile in this.SourceFiles) 41 foreach (var sourceFile in this.SourceFiles)
38 { 42 {
39 var preprocessor = new Preprocessor(this.ServiceProvider); 43 var context = this.ServiceProvider.GetService<IPreprocessContext>();
40 preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; 44 context.Extensions = this.ExtensionManager.Create<IPreprocessorExtension>();
41 preprocessor.Platform = Platform.X86; // TODO: set this correctly 45 context.Platform = this.Platform;
42 preprocessor.SourcePath = sourceFile.SourcePath; 46 context.IncludeSearchPaths = this.IncludeSearchPaths;
43 preprocessor.Variables = new Dictionary<string, string>(this.PreprocessorVariables); 47 context.SourcePath = sourceFile.SourcePath;
48 context.Variables = this.PreprocessorVariables;
44 49
45 XDocument document = null; 50 XDocument document = null;
46 try 51 try
47 { 52 {
48 document = preprocessor.Execute(); 53 var preprocessor = this.ServiceProvider.GetService<IPreprocessor>();
54 document = preprocessor.Preprocess(context);
49 } 55 }
50 catch (WixException e) 56 catch (WixException e)
51 { 57 {
@@ -57,11 +63,14 @@ namespace WixToolset.Core.CommandLine
57 continue; 63 continue;
58 } 64 }
59 65
60 var compiler = new Compiler(this.ServiceProvider); 66 var compileContext = this.ServiceProvider.GetService<ICompileContext>();
61 compiler.OutputPath = sourceFile.OutputPath; 67 compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>();
62 compiler.Platform = this.Platform; 68 compileContext.OutputPath = sourceFile.OutputPath;
63 compiler.SourceDocument = document; 69 compileContext.Platform = this.Platform;
64 var intermediate = compiler.Execute(); 70 compileContext.Source = document;
71
72 var compiler = this.ServiceProvider.GetService<ICompiler>();
73 var intermediate = compiler.Compile(compileContext);
65 74
66 intermediate.Save(sourceFile.OutputPath); 75 intermediate.Save(sourceFile.OutputPath);
67 } 76 }