// 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.Linq; using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Services; internal class CompileCommand : ICommandLineCommand { public CompileCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable sources, IDictionary preprocessorVariables) { this.PreprocessorVariables = preprocessorVariables; this.ServiceProvider = serviceProvider; this.ExtensionManager = extensions; this.SourceFiles = sources; } private IServiceProvider ServiceProvider { get; } private IExtensionManager ExtensionManager { get; } public IEnumerable IncludeSearchPaths { get; } private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } public int Execute() { foreach (var sourceFile in this.SourceFiles) { var preprocessContext = this.ServiceProvider.GetService(); preprocessContext.Messaging = Messaging.Instance; preprocessContext.Extensions = this.ExtensionManager.Create(); preprocessContext.Platform = Platform.X86; // TODO: set this correctly preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List(); preprocessContext.SourceFile = sourceFile.SourcePath; preprocessContext.Variables = new Dictionary(this.PreprocessorVariables); var preprocessor = new Preprocessor(); var document = preprocessor.Process(preprocessContext); var compileContext = this.ServiceProvider.GetService(); compileContext.Messaging = Messaging.Instance; compileContext.CompilationId = Guid.NewGuid().ToString("N"); compileContext.Extensions = this.ExtensionManager.Create(); compileContext.OutputPath = sourceFile.OutputPath; compileContext.Platform = Platform.X86; // TODO: set this correctly compileContext.Source = document; var compiler = new Compiler(); var intermediate = compiler.Compile(compileContext); intermediate.Save(sourceFile.OutputPath); } return 0; } } }