// 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; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; internal class CompileCommand : ICommandLineCommand { public CompileCommand(IServiceProvider serviceProvider) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.ExtensionManager = serviceProvider.GetService(); } public CompileCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, Platform platform) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.ExtensionManager = serviceProvider.GetService(); this.SourceFiles = sources; this.PreprocessorVariables = preprocessorVariables; this.Platform = platform; } private IServiceProvider ServiceProvider { get; } public IMessaging Messaging { get; } public IExtensionManager ExtensionManager { get; } private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } private Platform Platform { get; } public IEnumerable IncludeSearchPaths { get; } public bool ShowLogo => throw new NotImplementedException(); public bool StopParsing => throw new NotImplementedException(); public bool TryParseArgument(ICommandLineParser parseHelper, string argument) { throw new NotImplementedException(); } public int Execute() { foreach (var sourceFile in this.SourceFiles) { var context = this.ServiceProvider.GetService(); context.Extensions = this.ExtensionManager.GetServices(); context.Platform = this.Platform; context.IncludeSearchPaths = this.IncludeSearchPaths; context.SourcePath = sourceFile.SourcePath; context.Variables = this.PreprocessorVariables; IPreprocessResult result = null; try { var preprocessor = this.ServiceProvider.GetService(); result = preprocessor.Preprocess(context); } catch (WixException e) { this.Messaging.Write(e.Error); } if (this.Messaging.EncounteredError) { continue; } var compileContext = this.ServiceProvider.GetService(); compileContext.Extensions = this.ExtensionManager.GetServices(); compileContext.OutputPath = sourceFile.OutputPath; compileContext.Platform = this.Platform; compileContext.Source = result?.Document; var compiler = this.ServiceProvider.GetService(); var intermediate = compiler.Compile(compileContext); intermediate.Save(sourceFile.OutputPath); } return 0; } } }