From be612cbcea4e74196445940c41b42acb6ffa5ebd Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 3 Oct 2018 14:30:58 -0700 Subject: Implement -arch switch Fixes wixtoolset/issues#5863 --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 9 ++++++--- .../CommandLine/CommandLineParser.cs | 23 +++++++++++++++++----- src/WixToolset.Core/CommandLine/CompileCommand.cs | 7 +++++-- 3 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 16c98c83..76502bb0 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -13,7 +13,7 @@ namespace WixToolset.Core.CommandLine internal class BuildCommand : ICommandLineCommand { - public BuildCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, IEnumerable filterCultures, string outputPath, OutputType outputType, string cabCachePath, bool bindFiles, IEnumerable bindPaths, IEnumerable includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile) + public BuildCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, IEnumerable filterCultures, string outputPath, OutputType outputType, Platform platform, string cabCachePath, bool bindFiles, IEnumerable bindPaths, IEnumerable includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); @@ -25,6 +25,7 @@ namespace WixToolset.Core.CommandLine this.SourceFiles = sources; this.OutputPath = outputPath; this.OutputType = outputType; + this.Platform = platform; this.CabCachePath = cabCachePath; this.BindFiles = bindFiles; @@ -59,6 +60,8 @@ namespace WixToolset.Core.CommandLine private OutputType OutputType { get; } + private Platform Platform { get; } + public string CabCachePath { get; } public bool BindFiles { get; } @@ -171,7 +174,7 @@ namespace WixToolset.Core.CommandLine { var preprocessor = new Preprocessor(this.ServiceProvider); preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; - preprocessor.Platform = Platform.X86; // TODO: set this correctly + preprocessor.Platform = this.Platform; preprocessor.SourcePath = sourceFile.SourcePath; preprocessor.Variables = this.PreprocessorVariables; @@ -192,7 +195,7 @@ namespace WixToolset.Core.CommandLine var compiler = new Compiler(this.ServiceProvider); compiler.OutputPath = sourceFile.OutputPath; - compiler.Platform = Platform.X86; // TODO: set this correctly + compiler.Platform = this.Platform; compiler.SourceDocument = document; var intermediate = compiler.Execute(); diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index b0ad6cad..d0484e45 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs @@ -59,6 +59,7 @@ namespace WixToolset.Core.CommandLine var outputFolder = String.Empty; var outputFile = String.Empty; var outputType = String.Empty; + var platformType = String.Empty; var verbose = false; var files = new List(); var defines = new List(); @@ -91,6 +92,11 @@ namespace WixToolset.Core.CommandLine cmdline.ShowHelp = true; return true; + case "arch": + case "platform": + platformType = parser.GetNextArgumentOrError(arg); + return true; + case "bindfiles": bindFiles = true; return true; @@ -211,14 +217,16 @@ namespace WixToolset.Core.CommandLine var bindPathList = this.GatherBindPaths(bindPaths); var filterCultures = CalculateFilterCultures(cultures); var type = CalculateOutputType(outputType, outputFile); - return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); + var platform = CalculatePlatform(platformType); + return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, platform, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); } case Commands.Compile: { var sourceFiles = GatherSourceFiles(files, outputFolder); - var variables = GatherPreprocessorVariables(defines); - return new CompileCommand(this.ServiceProvider, sourceFiles, variables); + var variables = this.GatherPreprocessorVariables(defines); + var platform = CalculatePlatform(platformType); + return new CompileCommand(this.ServiceProvider, sourceFiles, variables, platform); } } @@ -297,6 +305,11 @@ namespace WixToolset.Core.CommandLine return OutputType.Unknown; } + private static Platform CalculatePlatform(string platformType) + { + return Enum.TryParse(platformType, true, out Platform platform) ? platform : Platform.X86; + } + private ICommandLineParser Parse(ICommandLineContext context, Func parseCommand, Func parseArgument) { var extensions = this.ExtensionManager.Create(); @@ -372,7 +385,7 @@ namespace WixToolset.Core.CommandLine foreach (var pair in defineConstants) { - string[] value = pair.Split(new[] { '=' }, 2); + var value = pair.Split(new[] { '=' }, 2); if (variables.ContainsKey(value[0])) { @@ -422,7 +435,7 @@ namespace WixToolset.Core.CommandLine public static BindPath ParseBindPath(string bindPath) { - string[] namedPath = bindPath.Split(BindPathSplit, 2); + var namedPath = bindPath.Split(BindPathSplit, 2); return (1 == namedPath.Length) ? new BindPath(namedPath[0]) : new BindPath(namedPath[0], namedPath[1]); } } diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index ec1ce602..621571b1 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs @@ -11,12 +11,13 @@ namespace WixToolset.Core.CommandLine internal class CompileCommand : ICommandLineCommand { - public CompileCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables) + public CompileCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, Platform platform) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.SourceFiles = sources; this.PreprocessorVariables = preprocessorVariables; + this.Platform = platform; } private IServiceProvider ServiceProvider { get; } @@ -27,6 +28,8 @@ namespace WixToolset.Core.CommandLine private IDictionary PreprocessorVariables { get; } + private Platform Platform { get; } + public IEnumerable IncludeSearchPaths { get; } public int Execute() @@ -56,7 +59,7 @@ namespace WixToolset.Core.CommandLine var compiler = new Compiler(this.ServiceProvider); compiler.OutputPath = sourceFile.OutputPath; - compiler.Platform = Platform.X86; // TODO: set this correctly + compiler.Platform = this.Platform; compiler.SourceDocument = document; var intermediate = compiler.Execute(); -- cgit v1.2.3-55-g6feb