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.cs142
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs22
2 files changed, 88 insertions, 76 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index afb9e829..32da5bcf 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -7,13 +7,14 @@ namespace WixToolset.Core
7 using System.IO; 7 using System.IO;
8 using System.Linq; 8 using System.Linq;
9 using WixToolset.Data; 9 using WixToolset.Data;
10 using WixToolset.Data.Rows;
10 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
11 12
12 internal class BuildCommand : ICommandLineCommand 13 internal class BuildCommand : ICommandLineCommand
13 { 14 {
14 public BuildCommand(ExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) 15 public BuildCommand(ExtensionManager 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)
15 { 16 {
16 this.Extensions = extensions; 17 this.ExtensionManager = extensions;
17 this.LocFiles = locFiles; 18 this.LocFiles = locFiles;
18 this.LibraryFiles = libraryFiles; 19 this.LibraryFiles = libraryFiles;
19 this.PreprocessorVariables = preprocessorVariables; 20 this.PreprocessorVariables = preprocessorVariables;
@@ -21,6 +22,7 @@ namespace WixToolset.Core
21 this.OutputPath = outputPath; 22 this.OutputPath = outputPath;
22 this.OutputType = outputType; 23 this.OutputType = outputType;
23 24
25 this.CabCachePath = cabCachePath;
24 this.Cultures = cultures; 26 this.Cultures = cultures;
25 this.BindFiles = bindFiles; 27 this.BindFiles = bindFiles;
26 this.BindPaths = bindPaths; 28 this.BindPaths = bindPaths;
@@ -32,7 +34,7 @@ namespace WixToolset.Core
32 this.WixProjectFile = wixProjectFile; 34 this.WixProjectFile = wixProjectFile;
33 } 35 }
34 36
35 public ExtensionManager Extensions { get; } 37 public ExtensionManager ExtensionManager { get; }
36 38
37 public IEnumerable<string> LocFiles { get; } 39 public IEnumerable<string> LocFiles { get; }
38 40
@@ -46,6 +48,8 @@ namespace WixToolset.Core
46 48
47 private OutputType OutputType { get; } 49 private OutputType OutputType { get; }
48 50
51 public string CabCachePath { get; }
52
49 public IEnumerable<string> Cultures { get; } 53 public IEnumerable<string> Cultures { get; }
50 54
51 public bool BindFiles { get; } 55 public bool BindFiles { get; }
@@ -70,7 +74,9 @@ namespace WixToolset.Core
70 74
71 if (this.OutputType == OutputType.Library) 75 if (this.OutputType == OutputType.Library)
72 { 76 {
73 this.LibraryPhase(intermediates, tableDefinitions); 77 var library = this.LibraryPhase(intermediates, tableDefinitions);
78
79 library?.Save(this.OutputPath);
74 } 80 }
75 else 81 else
76 { 82 {
@@ -105,51 +111,40 @@ namespace WixToolset.Core
105 return intermediates; 111 return intermediates;
106 } 112 }
107 113
108 private void LibraryPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions) 114 private Library LibraryPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions)
109 { 115 {
110 var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList(); 116 var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList();
111 117
112 // If there was an error adding localization files, then bail. 118 // If there was an error adding localization files, then bail.
113 if (Messaging.Instance.EncounteredError) 119 if (Messaging.Instance.EncounteredError)
114 { 120 {
115 return; 121 return null;
116 } 122 }
117 123
118 var sections = intermediates.SelectMany(i => i.Sections).ToList(); 124 var resolver = CreateWixResolverWithVariables(null, null);
119
120 LibraryBinaryFileResolver resolver = null;
121
122 if (this.BindFiles)
123 {
124 resolver = new LibraryBinaryFileResolver();
125 resolver.FileManagers = new List<IBinderFileManager> { new BinderFileManager() }; ;
126 resolver.VariableResolver = new WixVariableResolver();
127
128 BinderFileManagerCore core = new BinderFileManagerCore();
129 core.AddBindPaths(this.BindPaths, BindStage.Normal);
130
131 foreach (var fileManager in resolver.FileManagers)
132 {
133 fileManager.Core = core;
134 }
135 }
136 125
137 var librarian = new Librarian(); 126 var context = new LibraryContext();
127 context.BindFiles = this.BindFiles;
128 context.BindPaths = this.BindPaths;
129 context.Extensions = this.ExtensionManager.Create<ILibrarianExtension>();
130 context.Localizations = localizations;
131 context.Sections = intermediates.SelectMany(i => i.Sections).ToList();
132 context.WixVariableResolver = resolver;
138 133
139 var library = librarian.Combine(sections, localizations, resolver); 134 var librarian = new Librarian(context);
140 135
141 library?.Save(this.OutputPath); 136 return librarian.Combine();
142 } 137 }
143 138
144 private Output LinkPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions) 139 private Output LinkPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions)
145 { 140 {
146 var sections = intermediates.SelectMany(i => i.Sections).ToList(); 141 var sections = intermediates.SelectMany(i => i.Sections).ToList();
147 142
148 sections.AddRange(SectionsFromLibraries(tableDefinitions)); 143 sections.AddRange(this.SectionsFromLibraries(tableDefinitions));
149 144
150 var linker = new Linker(); 145 var linker = new Linker();
151 146
152 foreach (var data in this.Extensions.Create<IExtensionData>()) 147 foreach (var data in this.ExtensionManager.Create<IExtensionData>())
153 { 148 {
154 linker.AddExtensionData(data); 149 linker.AddExtensionData(data);
155 } 150 }
@@ -159,6 +154,40 @@ namespace WixToolset.Core
159 return output; 154 return output;
160 } 155 }
161 156
157 private void BindPhase(Output output, TableDefinitionCollection tableDefinitions)
158 {
159 var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList();
160
161 var localizer = new Localizer(localizations);
162
163 var resolver = CreateWixResolverWithVariables(localizer, output);
164
165 var context = new BindContext();
166 context.Messaging = Messaging.Instance;
167 context.ExtensionManager = this.ExtensionManager;
168 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>();
169 //context.CabbingThreadCount = this.CabbingThreadCount;
170 context.CabCachePath = this.CabCachePath;
171 context.Codepage = localizer.Codepage;
172 //context.DefaultCompressionLevel = this.DefaultCompressionLevel;
173 //context.Ices = this.Ices;
174 context.IntermediateFolder = this.IntermediateFolder;
175 context.IntermediateRepresentation = output;
176 context.OutputPath = this.OutputPath;
177 context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb");
178 //context.SuppressIces = this.SuppressIces;
179 context.SuppressValidation = true;
180 //context.SuppressValidation = this.SuppressValidation;
181 context.WixVariableResolver = resolver;
182 context.ContentsFile = this.ContentsFile;
183 context.OutputsFile = this.OutputsFile;
184 context.BuiltOutputsFile = this.BuiltOutputsFile;
185 context.WixprojectFile = this.WixProjectFile;
186
187 var binder = new Binder(context);
188 binder.Bind();
189 }
190
162 private IEnumerable<Section> SectionsFromLibraries(TableDefinitionCollection tableDefinitions) 191 private IEnumerable<Section> SectionsFromLibraries(TableDefinitionCollection tableDefinitions)
163 { 192 {
164 var sections = new List<Section>(); 193 var sections = new List<Section>();
@@ -187,34 +216,6 @@ namespace WixToolset.Core
187 return sections; 216 return sections;
188 } 217 }
189 218
190 private void BindPhase(Output output, TableDefinitionCollection tableDefinitions)
191 {
192 var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList();
193
194 var localizer = new Localizer(localizations);
195
196 var resolver = new WixVariableResolver(localizer);
197
198 var binder = new Binder();
199 binder.TempFilesLocation = this.IntermediateFolder;
200 binder.WixVariableResolver = resolver;
201 binder.SuppressValidation = true;
202
203 binder.ContentsFile = this.ContentsFile;
204 binder.OutputsFile = this.OutputsFile;
205 binder.BuiltOutputsFile = this.BuiltOutputsFile;
206 binder.WixprojectFile = this.WixProjectFile;
207
208 if (this.BindPaths != null)
209 {
210 binder.BindPaths.AddRange(this.BindPaths);
211 }
212
213 binder.AddExtension(new BinderFileManager());
214
215 binder.Bind(output, this.OutputPath);
216 }
217
218 private IEnumerable<Localization> LoadLocalizationFiles(TableDefinitionCollection tableDefinitions) 219 private IEnumerable<Localization> LoadLocalizationFiles(TableDefinitionCollection tableDefinitions)
219 { 220 {
220 foreach (var loc in this.LocFiles) 221 foreach (var loc in this.LocFiles)
@@ -225,30 +226,21 @@ namespace WixToolset.Core
225 } 226 }
226 } 227 }
227 228
228 /// <summary> 229 private static WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Output output)
229 /// File resolution mechanism to create binary library.
230 /// </summary>
231 private class LibraryBinaryFileResolver : ILibraryBinaryFileResolver
232 { 230 {
233 public IEnumerable<IBinderFileManager> FileManagers { get; set; } 231 var resolver = new WixVariableResolver(localizer);
234
235 public WixVariableResolver VariableResolver { get; set; }
236 232
237 public string Resolve(SourceLineNumber sourceLineNumber, string table, string path) 233 // Gather all the wix variables.
234 Table wixVariableTable = output?.Tables["WixVariable"];
235 if (null != wixVariableTable)
238 { 236 {
239 string resolvedPath = this.VariableResolver.ResolveVariables(sourceLineNumber, path, false); 237 foreach (WixVariableRow wixVariableRow in wixVariableTable.Rows)
240
241 foreach (IBinderFileManager fileManager in this.FileManagers)
242 { 238 {
243 string finalPath = fileManager.ResolveFile(resolvedPath, table, sourceLineNumber, BindStage.Normal); 239 resolver.AddVariable(wixVariableRow);
244 if (!String.IsNullOrEmpty(finalPath))
245 {
246 return finalPath;
247 }
248 } 240 }
249
250 return null;
251 } 241 }
242
243 return resolver;
252 } 244 }
253 } 245 }
254} 246}
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index a3a6831c..2f203ecb 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -6,6 +6,7 @@ namespace WixToolset.Core
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Linq; 8 using System.Linq;
9 using System.Reflection;
9 using System.Text; 10 using System.Text;
10 using System.Text.RegularExpressions; 11 using System.Text.RegularExpressions;
11 using WixToolset.Data; 12 using WixToolset.Data;
@@ -71,6 +72,7 @@ namespace WixToolset.Core
71 72
72 var intermediateFolder = String.Empty; 73 var intermediateFolder = String.Empty;
73 74
75 var cabCachePath = String.Empty;
74 var cultures = new List<string>(); 76 var cultures = new List<string>();
75 var contentsFile = String.Empty; 77 var contentsFile = String.Empty;
76 var outputsFile = String.Empty; 78 var outputsFile = String.Empty;
@@ -98,6 +100,10 @@ namespace WixToolset.Core
98 cmdline.GetNextArgumentOrError(bindPaths); 100 cmdline.GetNextArgumentOrError(bindPaths);
99 return true; 101 return true;
100 102
103 case "cc":
104 cmdline.GetNextArgumentOrError(ref cabCachePath);
105 return true;
106
101 case "cultures": 107 case "cultures":
102 cmdline.GetNextArgumentOrError(cultures); 108 cmdline.GetNextArgumentOrError(cultures);
103 return true; 109 return true;
@@ -190,12 +196,14 @@ namespace WixToolset.Core
190 { 196 {
191 case Commands.Build: 197 case Commands.Build:
192 { 198 {
199 LoadStandardBackends(cli.ExtensionManager);
200
193 var sourceFiles = GatherSourceFiles(files, outputFolder); 201 var sourceFiles = GatherSourceFiles(files, outputFolder);
194 var variables = GatherPreprocessorVariables(defines); 202 var variables = GatherPreprocessorVariables(defines);
195 var bindPathList = GatherBindPaths(bindPaths); 203 var bindPathList = GatherBindPaths(bindPaths);
196 var extensions = cli.ExtensionManager; 204 var extensions = cli.ExtensionManager;
197 var type = CalculateOutputType(outputType, outputFile); 205 var type = CalculateOutputType(outputType, outputFile);
198 return new BuildCommand(extensions, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); 206 return new BuildCommand(extensions, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile);
199 } 207 }
200 208
201 case Commands.Compile: 209 case Commands.Compile:
@@ -209,6 +217,18 @@ namespace WixToolset.Core
209 return null; 217 return null;
210 } 218 }
211 219
220 private static void LoadStandardBackends(ExtensionManager extensionManager)
221 {
222 var folder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
223
224 foreach (var backendAssemblyName in new[] { "WixToolset.Core.Burn.dll", "WixToolset.Core.WindowsInstaller.dll" })
225 {
226 var path = Path.Combine(folder, backendAssemblyName);
227
228 extensionManager.Load(path);
229 }
230 }
231
212 private static OutputType CalculateOutputType(string outputType, string outputFile) 232 private static OutputType CalculateOutputType(string outputType, string outputFile)
213 { 233 {
214 if (String.IsNullOrEmpty(outputType)) 234 if (String.IsNullOrEmpty(outputType))