diff options
Diffstat (limited to 'src/WixToolset.Core/CommandLine/BuildCommand.cs')
-rw-r--r-- | src/WixToolset.Core/CommandLine/BuildCommand.cs | 142 |
1 files changed, 67 insertions, 75 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 | } |