// 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.CommandLine { using System; using System.Collections.Generic; using System.Xml.Linq; using WixToolset.Data; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; internal class CompileCommand : ICommandLineCommand { public CompileCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.SourceFiles = sources; this.PreprocessorVariables = preprocessorVariables; } private IServiceProvider ServiceProvider { get; } public IMessaging Messaging { get; } private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } public IEnumerable IncludeSearchPaths { get; } public int Execute() { foreach (var sourceFile in this.SourceFiles) { var preprocessor = new Preprocessor(this.ServiceProvider); preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; preprocessor.Platform = Platform.X86; // TODO: set this correctly preprocessor.SourcePath = sourceFile.SourcePath; preprocessor.Variables = new Dictionary(this.PreprocessorVariables); XDocument document = null; try { document = preprocessor.Execute(); } catch (WixException e) { this.Messaging.Write(e.Error); } if (this.Messaging.EncounteredError) { continue; } var compiler = new Compiler(this.ServiceProvider); compiler.OutputPath = sourceFile.OutputPath; compiler.Platform = Platform.X86; // TODO: set this correctly compiler.SourceDocument = document; var intermediate = compiler.Execute(); intermediate.Save(sourceFile.OutputPath); } return 0; } } }