From d3d3649a68cb1fa589fdd987a6690dbd5d671f0d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 17 Sep 2017 15:35:20 -0700 Subject: Initial code commit --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 100 ++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/WixToolset.Core/CommandLine/BuildCommand.cs (limited to 'src/WixToolset.Core/CommandLine/BuildCommand.cs') 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 @@ +// 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. + +namespace WixToolset.Core +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using WixToolset.Data; + + internal class BuildCommand : ICommand + { + public BuildCommand(IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, string outputPath, IEnumerable cultures, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) + { + this.LocFiles = locFiles; + this.PreprocessorVariables = preprocessorVariables; + this.SourceFiles = sources; + this.OutputPath = outputPath; + + this.Cultures = cultures; + this.ContentsFile = contentsFile; + this.OutputsFile = outputsFile; + this.BuiltOutputsFile = builtOutputsFile; + this.WixProjectFile = wixProjectFile; + } + + public IEnumerable LocFiles { get; } + + private IEnumerable SourceFiles { get; } + + private IDictionary PreprocessorVariables { get; } + + private string OutputPath { get; } + + public IEnumerable Cultures { get; } + + public string ContentsFile { get; } + + public string OutputsFile { get; } + + public string BuiltOutputsFile { get; } + + public string WixProjectFile { get; } + + public int Execute() + { + var intermediates = CompilePhase(); + + var sections = intermediates.SelectMany(i => i.Sections).ToList(); + + var linker = new Linker(); + + var output = linker.Link(sections, OutputType.Product); + + var localizer = new Localizer(); + + var binder = new Binder(); + binder.TempFilesLocation = Path.GetTempPath(); + binder.WixVariableResolver = new WixVariableResolver(); + binder.WixVariableResolver.Localizer = localizer; + binder.AddExtension(new BinderFileManager()); + binder.SuppressValidation = true; + + binder.ContentsFile = this.ContentsFile; + binder.OutputsFile = this.OutputsFile; + binder.BuiltOutputsFile = this.BuiltOutputsFile; + binder.WixprojectFile = this.WixProjectFile; + + foreach (var loc in this.LocFiles) + { + var localization = Localizer.ParseLocalizationFile(loc, linker.TableDefinitions); + binder.WixVariableResolver.Localizer.AddLocalization(localization); + } + + binder.Bind(output, this.OutputPath); + + return 0; + } + + private IEnumerable CompilePhase() + { + var intermediates = new List(); + + var preprocessor = new Preprocessor(); + + var compiler = new Compiler(); + + foreach (var sourceFile in this.SourceFiles) + { + var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); + + var intermediate = compiler.Compile(document); + + intermediates.Add(intermediate); + } + + return intermediates; + } + } +} -- cgit v1.2.3-55-g6feb