aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine/BuildCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-09-17 15:35:20 -0700
committerRob Mensching <rob@firegiant.com>2017-09-17 16:00:11 -0700
commitd3d3649a68cb1fa589fdd987a6690dbd5d671f0d (patch)
tree44fe37ee352b7e3a355cc1e08b1d7d5988c14cc0 /src/WixToolset.Core/CommandLine/BuildCommand.cs
parenta62610d23d6feb98be3b1e529a4e81b19d77d9d8 (diff)
downloadwix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.gz
wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.bz2
wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.zip
Initial code commit
Diffstat (limited to 'src/WixToolset.Core/CommandLine/BuildCommand.cs')
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
new file mode 100644
index 00000000..ffb48305
--- /dev/null
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -0,0 +1,100 @@
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.Core
4{
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9 using WixToolset.Data;
10
11 internal class BuildCommand : ICommand
12 {
13 public BuildCommand(IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, string outputPath, IEnumerable<string> cultures, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile)
14 {
15 this.LocFiles = locFiles;
16 this.PreprocessorVariables = preprocessorVariables;
17 this.SourceFiles = sources;
18 this.OutputPath = outputPath;
19
20 this.Cultures = cultures;
21 this.ContentsFile = contentsFile;
22 this.OutputsFile = outputsFile;
23 this.BuiltOutputsFile = builtOutputsFile;
24 this.WixProjectFile = wixProjectFile;
25 }
26
27 public IEnumerable<string> LocFiles { get; }
28
29 private IEnumerable<SourceFile> SourceFiles { get; }
30
31 private IDictionary<string, string> PreprocessorVariables { get; }
32
33 private string OutputPath { get; }
34
35 public IEnumerable<string> Cultures { get; }
36
37 public string ContentsFile { get; }
38
39 public string OutputsFile { get; }
40
41 public string BuiltOutputsFile { get; }
42
43 public string WixProjectFile { get; }
44
45 public int Execute()
46 {
47 var intermediates = CompilePhase();
48
49 var sections = intermediates.SelectMany(i => i.Sections).ToList();
50
51 var linker = new Linker();
52
53 var output = linker.Link(sections, OutputType.Product);
54
55 var localizer = new Localizer();
56
57 var binder = new Binder();
58 binder.TempFilesLocation = Path.GetTempPath();
59 binder.WixVariableResolver = new WixVariableResolver();
60 binder.WixVariableResolver.Localizer = localizer;
61 binder.AddExtension(new BinderFileManager());
62 binder.SuppressValidation = true;
63
64 binder.ContentsFile = this.ContentsFile;
65 binder.OutputsFile = this.OutputsFile;
66 binder.BuiltOutputsFile = this.BuiltOutputsFile;
67 binder.WixprojectFile = this.WixProjectFile;
68
69 foreach (var loc in this.LocFiles)
70 {
71 var localization = Localizer.ParseLocalizationFile(loc, linker.TableDefinitions);
72 binder.WixVariableResolver.Localizer.AddLocalization(localization);
73 }
74
75 binder.Bind(output, this.OutputPath);
76
77 return 0;
78 }
79
80 private IEnumerable<Intermediate> CompilePhase()
81 {
82 var intermediates = new List<Intermediate>();
83
84 var preprocessor = new Preprocessor();
85
86 var compiler = new Compiler();
87
88 foreach (var sourceFile in this.SourceFiles)
89 {
90 var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables);
91
92 var intermediate = compiler.Compile(document);
93
94 intermediates.Add(intermediate);
95 }
96
97 return intermediates;
98 }
99 }
100}