diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
| commit | 2bb37beda887d120a0ddabf874ad25357101faa1 (patch) | |
| tree | c35e97b03274b86cfc9ff7fd2caeee211165a140 /src/WixToolset.Core/CommandLine | |
| parent | df7413aeed3aea3425dff20ae0c8b1be3a3ab525 (diff) | |
| download | wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.gz wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.bz2 wix-2bb37beda887d120a0ddabf874ad25357101faa1.zip | |
Update to WiX Intermediate Representation
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
| -rw-r--r-- | src/WixToolset.Core/CommandLine/BuildCommand.cs | 92 | ||||
| -rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLine.cs | 2 | ||||
| -rw-r--r-- | src/WixToolset.Core/CommandLine/CompileCommand.cs | 27 |
3 files changed, 72 insertions, 49 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 4a1fc1ed..54bf688d 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs | |||
| @@ -7,7 +7,7 @@ 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.Data.Tuples; |
| 11 | using WixToolset.Extensibility; | 11 | using WixToolset.Extensibility; |
| 12 | using WixToolset.Extensibility.Services; | 12 | using WixToolset.Extensibility.Services; |
| 13 | 13 | ||
| @@ -79,21 +79,19 @@ namespace WixToolset.Core | |||
| 79 | return 1; | 79 | return 1; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | var tableDefinitions = new TableDefinitionCollection(WindowsInstallerStandard.GetTableDefinitions()); | ||
| 83 | |||
| 84 | if (this.OutputType == OutputType.Library) | 82 | if (this.OutputType == OutputType.Library) |
| 85 | { | 83 | { |
| 86 | var library = this.LibraryPhase(intermediates, tableDefinitions); | 84 | var library = this.LibraryPhase(intermediates); |
| 87 | 85 | ||
| 88 | library?.Save(this.OutputPath); | 86 | library?.Save(this.OutputPath); |
| 89 | } | 87 | } |
| 90 | else | 88 | else |
| 91 | { | 89 | { |
| 92 | var output = this.LinkPhase(intermediates, tableDefinitions); | 90 | var output = this.LinkPhase(intermediates); |
| 93 | 91 | ||
| 94 | if (!Messaging.Instance.EncounteredError) | 92 | if (!Messaging.Instance.EncounteredError) |
| 95 | { | 93 | { |
| 96 | this.BindPhase(output, tableDefinitions); | 94 | this.BindPhase(output); |
| 97 | } | 95 | } |
| 98 | } | 96 | } |
| 99 | 97 | ||
| @@ -104,15 +102,26 @@ namespace WixToolset.Core | |||
| 104 | { | 102 | { |
| 105 | var intermediates = new List<Intermediate>(); | 103 | var intermediates = new List<Intermediate>(); |
| 106 | 104 | ||
| 107 | var preprocessor = new Preprocessor(); | ||
| 108 | |||
| 109 | var compiler = new Compiler(); | ||
| 110 | 105 | ||
| 111 | foreach (var sourceFile in this.SourceFiles) | 106 | foreach (var sourceFile in this.SourceFiles) |
| 112 | { | 107 | { |
| 108 | //var preprocessContext = this.ServiceProvider.GetService<IPreprocessContext>(); | ||
| 109 | //preprocessContext.SourcePath = sourceFile.SourcePath; | ||
| 110 | //preprocessContext.Variables = this.PreprocessorVariables; | ||
| 111 | |||
| 112 | var preprocessor = new Preprocessor(); | ||
| 113 | var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); | 113 | var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); |
| 114 | 114 | ||
| 115 | var intermediate = compiler.Compile(document); | 115 | var compileContext = this.ServiceProvider.GetService<ICompileContext>(); |
| 116 | compileContext.Messaging = Messaging.Instance; | ||
| 117 | compileContext.CompilationId = Guid.NewGuid().ToString("N"); | ||
| 118 | compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>(); | ||
| 119 | compileContext.OutputPath = sourceFile.OutputPath; | ||
| 120 | compileContext.Platform = Platform.X86; // TODO: set this correctly | ||
| 121 | compileContext.Source = document; | ||
| 122 | |||
| 123 | var compiler = new Compiler(); | ||
| 124 | var intermediate = compiler.Compile(compileContext); | ||
| 116 | 125 | ||
| 117 | intermediates.Add(intermediate); | 126 | intermediates.Add(intermediate); |
| 118 | } | 127 | } |
| @@ -120,9 +129,9 @@ namespace WixToolset.Core | |||
| 120 | return intermediates; | 129 | return intermediates; |
| 121 | } | 130 | } |
| 122 | 131 | ||
| 123 | private Library LibraryPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions) | 132 | private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates) |
| 124 | { | 133 | { |
| 125 | var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList(); | 134 | var localizations = this.LoadLocalizationFiles().ToList(); |
| 126 | 135 | ||
| 127 | // If there was an error adding localization files, then bail. | 136 | // If there was an error adding localization files, then bail. |
| 128 | if (Messaging.Instance.EncounteredError) | 137 | if (Messaging.Instance.EncounteredError) |
| @@ -137,35 +146,34 @@ namespace WixToolset.Core | |||
| 137 | context.BindPaths = this.BindPaths; | 146 | context.BindPaths = this.BindPaths; |
| 138 | context.Extensions = this.ExtensionManager.Create<ILibrarianExtension>(); | 147 | context.Extensions = this.ExtensionManager.Create<ILibrarianExtension>(); |
| 139 | context.Localizations = localizations; | 148 | context.Localizations = localizations; |
| 140 | context.Sections = intermediates.SelectMany(i => i.Sections).ToList(); | 149 | context.LibraryId = Guid.NewGuid().ToString("N"); |
| 150 | context.Intermediates = intermediates; | ||
| 141 | context.WixVariableResolver = resolver; | 151 | context.WixVariableResolver = resolver; |
| 142 | 152 | ||
| 143 | var librarian = new Librarian(context); | 153 | var librarian = new Librarian(); |
| 144 | 154 | return librarian.Combine(context); | |
| 145 | return librarian.Combine(); | ||
| 146 | } | 155 | } |
| 147 | 156 | ||
| 148 | private Output LinkPhase(IEnumerable<Intermediate> intermediates, TableDefinitionCollection tableDefinitions) | 157 | private Intermediate LinkPhase(IEnumerable<Intermediate> intermediates) |
| 149 | { | 158 | { |
| 150 | var sections = intermediates.SelectMany(i => i.Sections).ToList(); | 159 | var creator = this.ServiceProvider.GetService<ITupleDefinitionCreator>(); |
| 151 | |||
| 152 | sections.AddRange(this.SectionsFromLibraries(tableDefinitions)); | ||
| 153 | 160 | ||
| 154 | var linker = new Linker(); | 161 | var libraries = this.LoadLibraries(creator); |
| 155 | |||
| 156 | foreach (var data in this.ExtensionManager.Create<IExtensionData>()) | ||
| 157 | { | ||
| 158 | linker.AddExtensionData(data); | ||
| 159 | } | ||
| 160 | 162 | ||
| 161 | var output = linker.Link(sections, this.OutputType); | 163 | var context = this.ServiceProvider.GetService<ILinkContext>(); |
| 164 | context.Messaging = Messaging.Instance; | ||
| 165 | context.Extensions = this.ExtensionManager.Create<ILinkerExtension>(); | ||
| 166 | context.Intermediates = intermediates.Union(libraries).ToList(); | ||
| 167 | context.ExpectedOutputType = this.OutputType; | ||
| 162 | 168 | ||
| 169 | var linker = new Linker(); | ||
| 170 | var output = linker.Link(context); | ||
| 163 | return output; | 171 | return output; |
| 164 | } | 172 | } |
| 165 | 173 | ||
| 166 | private void BindPhase(Output output, TableDefinitionCollection tableDefinitions) | 174 | private void BindPhase(Intermediate output) |
| 167 | { | 175 | { |
| 168 | var localizations = this.LoadLocalizationFiles(tableDefinitions).ToList(); | 176 | var localizations = this.LoadLocalizationFiles().ToList(); |
| 169 | 177 | ||
| 170 | var localizer = new Localizer(localizations); | 178 | var localizer = new Localizer(localizations); |
| 171 | 179 | ||
| @@ -199,13 +207,13 @@ namespace WixToolset.Core | |||
| 199 | context.BuiltOutputsFile = this.BuiltOutputsFile; | 207 | context.BuiltOutputsFile = this.BuiltOutputsFile; |
| 200 | context.WixprojectFile = this.WixProjectFile; | 208 | context.WixprojectFile = this.WixProjectFile; |
| 201 | 209 | ||
| 202 | var binder = new Binder(context); | 210 | var binder = new Binder(); |
| 203 | binder.Bind(); | 211 | binder.Bind(context); |
| 204 | } | 212 | } |
| 205 | 213 | ||
| 206 | private IEnumerable<Section> SectionsFromLibraries(TableDefinitionCollection tableDefinitions) | 214 | private IEnumerable<Intermediate> LoadLibraries(ITupleDefinitionCreator creator) |
| 207 | { | 215 | { |
| 208 | var sections = new List<Section>(); | 216 | var libraries = new List<Intermediate>(); |
| 209 | 217 | ||
| 210 | if (this.LibraryFiles != null) | 218 | if (this.LibraryFiles != null) |
| 211 | { | 219 | { |
| @@ -213,9 +221,9 @@ namespace WixToolset.Core | |||
| 213 | { | 221 | { |
| 214 | try | 222 | try |
| 215 | { | 223 | { |
| 216 | var library = Library.Load(libraryFile, tableDefinitions, false); | 224 | var library = Intermediate.Load(libraryFile, creator); |
| 217 | 225 | ||
| 218 | sections.AddRange(library.Sections); | 226 | libraries.Add(library); |
| 219 | } | 227 | } |
| 220 | catch (WixCorruptFileException e) | 228 | catch (WixCorruptFileException e) |
| 221 | { | 229 | { |
| @@ -228,28 +236,28 @@ namespace WixToolset.Core | |||
| 228 | } | 236 | } |
| 229 | } | 237 | } |
| 230 | 238 | ||
| 231 | return sections; | 239 | return libraries; |
| 232 | } | 240 | } |
| 233 | 241 | ||
| 234 | private IEnumerable<Localization> LoadLocalizationFiles(TableDefinitionCollection tableDefinitions) | 242 | private IEnumerable<Localization> LoadLocalizationFiles() |
| 235 | { | 243 | { |
| 236 | foreach (var loc in this.LocFiles) | 244 | foreach (var loc in this.LocFiles) |
| 237 | { | 245 | { |
| 238 | var localization = Localizer.ParseLocalizationFile(loc, tableDefinitions); | 246 | var localization = Localizer.ParseLocalizationFile(loc); |
| 239 | 247 | ||
| 240 | yield return localization; | 248 | yield return localization; |
| 241 | } | 249 | } |
| 242 | } | 250 | } |
| 243 | 251 | ||
| 244 | private static WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Output output) | 252 | private static WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Intermediate output) |
| 245 | { | 253 | { |
| 246 | var resolver = new WixVariableResolver(localizer); | 254 | var resolver = new WixVariableResolver(localizer); |
| 247 | 255 | ||
| 248 | // Gather all the wix variables. | 256 | // Gather all the wix variables. |
| 249 | Table wixVariableTable = output?.Tables["WixVariable"]; | 257 | var wixVariables = output?.Sections.SelectMany(s => s.Tuples).OfType<WixVariableTuple>(); |
| 250 | if (null != wixVariableTable) | 258 | if (wixVariables != null) |
| 251 | { | 259 | { |
| 252 | foreach (WixVariableRow wixVariableRow in wixVariableTable.Rows) | 260 | foreach (var wixVariableRow in wixVariables) |
| 253 | { | 261 | { |
| 254 | resolver.AddVariable(wixVariableRow); | 262 | resolver.AddVariable(wixVariableRow); |
| 255 | } | 263 | } |
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index b0594348..c6fe11b7 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs | |||
| @@ -218,7 +218,7 @@ namespace WixToolset.Core | |||
| 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(sourceFiles, variables); | 221 | return new CompileCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index 855e7c6a..58ba9d29 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs | |||
| @@ -2,32 +2,47 @@ | |||
| 2 | 2 | ||
| 3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core |
| 4 | { | 4 | { |
| 5 | using System; | ||
| 5 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
| 7 | using WixToolset.Data; | ||
| 8 | using WixToolset.Extensibility; | ||
| 6 | using WixToolset.Extensibility.Services; | 9 | using WixToolset.Extensibility.Services; |
| 7 | 10 | ||
| 8 | internal class CompileCommand : ICommandLineCommand | 11 | internal class CompileCommand : ICommandLineCommand |
| 9 | { | 12 | { |
| 10 | public CompileCommand(IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables) | 13 | public CompileCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables) |
| 11 | { | 14 | { |
| 12 | this.PreprocessorVariables = preprocessorVariables; | 15 | this.PreprocessorVariables = preprocessorVariables; |
| 16 | this.ServiceProvider = serviceProvider; | ||
| 17 | this.ExtensionManager = extensions; | ||
| 13 | this.SourceFiles = sources; | 18 | this.SourceFiles = sources; |
| 14 | } | 19 | } |
| 15 | 20 | ||
| 21 | private IServiceProvider ServiceProvider { get; } | ||
| 22 | |||
| 23 | private IExtensionManager ExtensionManager { get; } | ||
| 24 | |||
| 16 | private IEnumerable<SourceFile> SourceFiles { get; } | 25 | private IEnumerable<SourceFile> SourceFiles { get; } |
| 17 | 26 | ||
| 18 | private IDictionary<string, string> PreprocessorVariables { get; } | 27 | private IDictionary<string, string> PreprocessorVariables { get; } |
| 19 | 28 | ||
| 20 | public int Execute() | 29 | public int Execute() |
| 21 | { | 30 | { |
| 22 | var preprocessor = new Preprocessor(); | ||
| 23 | |||
| 24 | var compiler = new Compiler(); | ||
| 25 | |||
| 26 | foreach (var sourceFile in this.SourceFiles) | 31 | foreach (var sourceFile in this.SourceFiles) |
| 27 | { | 32 | { |
| 33 | var preprocessor = new Preprocessor(); | ||
| 28 | var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); | 34 | var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); |
| 29 | 35 | ||
| 30 | var intermediate = compiler.Compile(document); | 36 | var compileContext = this.ServiceProvider.GetService<ICompileContext>(); |
| 37 | compileContext.Messaging = Messaging.Instance; | ||
| 38 | compileContext.CompilationId = Guid.NewGuid().ToString("N"); | ||
| 39 | compileContext.Extensions = this.ExtensionManager.Create<ICompilerExtension>(); | ||
| 40 | compileContext.OutputPath = sourceFile.OutputPath; | ||
| 41 | compileContext.Platform = Platform.X86; // TODO: set this correctly | ||
| 42 | compileContext.Source = document; | ||
| 43 | |||
| 44 | var compiler = new Compiler(); | ||
| 45 | var intermediate = compiler.Compile(compileContext); | ||
| 31 | 46 | ||
| 32 | intermediate.Save(sourceFile.OutputPath); | 47 | intermediate.Save(sourceFile.OutputPath); |
| 33 | } | 48 | } |
