Implement -arch switch
Fixes wixtoolset/issues#5863
Rob Mensching committed
Oct 3, 2018 at 14:30 UTC
be612cbcea4e74196445940c41b42acb6ffa5ebd
4 files changed
+61
-10
src/WixToolset.Core/CommandLine/BuildCommand.cs
+6
-3
@@ -13,7 +13,7 @@ namespace WixToolset.Core.CommandLine
13
14
internal class BuildCommand : ICommandLineCommand
15
{
16
- public BuildCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, IEnumerable<string> filterCultures, string outputPath, OutputType outputType, string cabCachePath, bool bindFiles, IEnumerable<BindPath> bindPaths, IEnumerable<string> includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile)
16
+ public BuildCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, IEnumerable<string> filterCultures, string outputPath, OutputType outputType, Platform platform, string cabCachePath, bool bindFiles, IEnumerable<BindPath> bindPaths, IEnumerable<string> includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile)
17
{
18
this.ServiceProvider = serviceProvider;
19
this.Messaging = serviceProvider.GetService<IMessaging>();
@@ -25,6 +25,7 @@ namespace WixToolset.Core.CommandLine
25
this.SourceFiles = sources;
26
this.OutputPath = outputPath;
27
this.OutputType = outputType;
28
+ this.Platform = platform;
29
30
this.CabCachePath = cabCachePath;
31
this.BindFiles = bindFiles;
@@ -59,6 +60,8 @@ namespace WixToolset.Core.CommandLine
60
61
private OutputType OutputType { get; }
62
63
+ private Platform Platform { get; }
64
+
65
public string CabCachePath { get; }
66
67
public bool BindFiles { get; }
@@ -171,7 +174,7 @@ namespace WixToolset.Core.CommandLine
174
{
175
var preprocessor = new Preprocessor(this.ServiceProvider);
176
preprocessor.IncludeSearchPaths = this.IncludeSearchPaths;
174
- preprocessor.Platform = Platform.X86; // TODO: set this correctly
177
+ preprocessor.Platform = this.Platform;
178
preprocessor.SourcePath = sourceFile.SourcePath;
179
preprocessor.Variables = this.PreprocessorVariables;
180
@@ -192,7 +195,7 @@ namespace WixToolset.Core.CommandLine
195
196
var compiler = new Compiler(this.ServiceProvider);
197
compiler.OutputPath = sourceFile.OutputPath;
195
- compiler.Platform = Platform.X86; // TODO: set this correctly
198
+ compiler.Platform = this.Platform;
199
compiler.SourceDocument = document;
200
var intermediate = compiler.Execute();
201
src/WixToolset.Core/CommandLine/CommandLineParser.cs
+18
-5
@@ -59,6 +59,7 @@ namespace WixToolset.Core.CommandLine
59
var outputFolder = String.Empty;
60
var outputFile = String.Empty;
61
var outputType = String.Empty;
62
+ var platformType = String.Empty;
63
var verbose = false;
64
var files = new List<string>();
65
var defines = new List<string>();
@@ -91,6 +92,11 @@ namespace WixToolset.Core.CommandLine
92
cmdline.ShowHelp = true;
93
return true;
94
95
+ case "arch":
96
+ case "platform":
97
+ platformType = parser.GetNextArgumentOrError(arg);
98
+ return true;
99
+
100
case "bindfiles":
101
bindFiles = true;
102
return true;
@@ -211,14 +217,16 @@ namespace WixToolset.Core.CommandLine
217
var bindPathList = this.GatherBindPaths(bindPaths);
218
var filterCultures = CalculateFilterCultures(cultures);
219
var type = CalculateOutputType(outputType, outputFile);
214
- return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile);
220
+ var platform = CalculatePlatform(platformType);
221
+ return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, platform, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile);
222
}
223
224
case Commands.Compile:
225
{
226
var sourceFiles = GatherSourceFiles(files, outputFolder);
220
- var variables = GatherPreprocessorVariables(defines);
221
- return new CompileCommand(this.ServiceProvider, sourceFiles, variables);
227
+ var variables = this.GatherPreprocessorVariables(defines);
228
+ var platform = CalculatePlatform(platformType);
229
+ return new CompileCommand(this.ServiceProvider, sourceFiles, variables, platform);
230
}
231
}
232
@@ -297,6 +305,11 @@ namespace WixToolset.Core.CommandLine
305
return OutputType.Unknown;
306
}
307
308
+ private static Platform CalculatePlatform(string platformType)
309
+ {
310
+ return Enum.TryParse(platformType, true, out Platform platform) ? platform : Platform.X86;
311
+ }
312
+
313
private ICommandLineParser Parse(ICommandLineContext context, Func<CommandLineParser, string, bool> parseCommand, Func<CommandLineParser, IParseCommandLine, string, bool> parseArgument)
314
{
315
var extensions = this.ExtensionManager.Create<IExtensionCommandLine>();
@@ -372,7 +385,7 @@ namespace WixToolset.Core.CommandLine
385
386
foreach (var pair in defineConstants)
387
{
375
- string[] value = pair.Split(new[] { '=' }, 2);
388
+ var value = pair.Split(new[] { '=' }, 2);
389
390
if (variables.ContainsKey(value[0]))
391
{
@@ -422,7 +435,7 @@ namespace WixToolset.Core.CommandLine
435
436
public static BindPath ParseBindPath(string bindPath)
437
{
425
- string[] namedPath = bindPath.Split(BindPathSplit, 2);
438
+ var namedPath = bindPath.Split(BindPathSplit, 2);
439
return (1 == namedPath.Length) ? new BindPath(namedPath[0]) : new BindPath(namedPath[0], namedPath[1]);
440
}
441
}
src/WixToolset.Core/CommandLine/CompileCommand.cs
+5
-2
@@ -11,12 +11,13 @@ namespace WixToolset.Core.CommandLine
11
12
internal class CompileCommand : ICommandLineCommand
13
{
14
- public CompileCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables)
14
+ public CompileCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, Platform platform)
15
{
16
this.ServiceProvider = serviceProvider;
17
this.Messaging = serviceProvider.GetService<IMessaging>();
18
this.SourceFiles = sources;
19
this.PreprocessorVariables = preprocessorVariables;
20
+ this.Platform = platform;
21
}
22
23
private IServiceProvider ServiceProvider { get; }
@@ -27,6 +28,8 @@ namespace WixToolset.Core.CommandLine
28
29
private IDictionary<string, string> PreprocessorVariables { get; }
30
31
+ private Platform Platform { get; }
32
+
33
public IEnumerable<string> IncludeSearchPaths { get; }
34
35
public int Execute()
@@ -56,7 +59,7 @@ namespace WixToolset.Core.CommandLine
59
60
var compiler = new Compiler(this.ServiceProvider);
61
compiler.OutputPath = sourceFile.OutputPath;
59
- compiler.Platform = Platform.X86; // TODO: set this correctly
62
+ compiler.Platform = this.Platform;
63
compiler.SourceDocument = document;
64
var intermediate = compiler.Execute();
65
src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
+32
@@ -448,6 +448,38 @@ namespace WixToolsetTest.CoreIntegration
448
}
449
}
450
451
+ [Fact]
452
+ public void CanBuild64bit()
453
+ {
454
+ var folder = TestData.Get(@"TestData\SingleFile");
455
+
456
+ using (var fs = new DisposableFileSystem())
457
+ {
458
+ var baseFolder = fs.GetFolder();
459
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
460
+
461
+ var result = WixRunner.Execute(new[]
462
+ {
463
+ "build",
464
+ Path.Combine(folder, "Package.wxs"),
465
+ Path.Combine(folder, "PackageComponents.wxs"),
466
+ "-loc", Path.Combine(folder, "Package.en-us.wxl"),
467
+ "-bindpath", Path.Combine(folder, "data"),
468
+ "-intermediateFolder", intermediateFolder,
469
+ "-arch", "x64",
470
+ "-o", Path.Combine(baseFolder, @"bin\test.msi")
471
+ });
472
+
473
+ result.AssertSuccess();
474
+
475
+ var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"test.wir"));
476
+ var section = intermediate.Sections.Single();
477
+
478
+ var platformSummary = section.Tuples.OfType<_SummaryInformationTuple>().Single(s => s.PropertyId == 7);
479
+ Assert.Equal("x64;1033", platformSummary.Value);
480
+ }
481
+ }
482
+
483
[Fact(Skip = "Not implemented yet.")]
484
public void CanBuildInstanceTransform()
485
{