diff options
8 files changed, 113 insertions, 4 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index b460e48f..16c98c83 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs | |||
@@ -6,6 +6,7 @@ namespace WixToolset.Core.CommandLine | |||
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.IO; | 7 | using System.IO; |
8 | using System.Linq; | 8 | using System.Linq; |
9 | using System.Xml.Linq; | ||
9 | using WixToolset.Data; | 10 | using WixToolset.Data; |
10 | using WixToolset.Extensibility.Data; | 11 | using WixToolset.Extensibility.Data; |
11 | using WixToolset.Extensibility.Services; | 12 | using WixToolset.Extensibility.Services; |
@@ -173,7 +174,16 @@ namespace WixToolset.Core.CommandLine | |||
173 | preprocessor.Platform = Platform.X86; // TODO: set this correctly | 174 | preprocessor.Platform = Platform.X86; // TODO: set this correctly |
174 | preprocessor.SourcePath = sourceFile.SourcePath; | 175 | preprocessor.SourcePath = sourceFile.SourcePath; |
175 | preprocessor.Variables = this.PreprocessorVariables; | 176 | preprocessor.Variables = this.PreprocessorVariables; |
176 | var document = preprocessor.Execute(); | 177 | |
178 | XDocument document = null; | ||
179 | try | ||
180 | { | ||
181 | document = preprocessor.Execute(); | ||
182 | } | ||
183 | catch (WixException e) | ||
184 | { | ||
185 | this.Messaging.Write(e.Error); | ||
186 | } | ||
177 | 187 | ||
178 | if (this.Messaging.EncounteredError) | 188 | if (this.Messaging.EncounteredError) |
179 | { | 189 | { |
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index 6bd0f25a..ec1ce602 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs | |||
@@ -4,26 +4,31 @@ namespace WixToolset.Core.CommandLine | |||
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.Xml.Linq; | ||
7 | using WixToolset.Data; | 8 | using WixToolset.Data; |
8 | using WixToolset.Extensibility.Data; | 9 | using WixToolset.Extensibility.Data; |
10 | using WixToolset.Extensibility.Services; | ||
9 | 11 | ||
10 | internal class CompileCommand : ICommandLineCommand | 12 | internal class CompileCommand : ICommandLineCommand |
11 | { | 13 | { |
12 | public CompileCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables) | 14 | public CompileCommand(IServiceProvider serviceProvider, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables) |
13 | { | 15 | { |
14 | this.PreprocessorVariables = preprocessorVariables; | ||
15 | this.ServiceProvider = serviceProvider; | 16 | this.ServiceProvider = serviceProvider; |
17 | this.Messaging = serviceProvider.GetService<IMessaging>(); | ||
16 | this.SourceFiles = sources; | 18 | this.SourceFiles = sources; |
19 | this.PreprocessorVariables = preprocessorVariables; | ||
17 | } | 20 | } |
18 | 21 | ||
19 | private IServiceProvider ServiceProvider { get; } | 22 | private IServiceProvider ServiceProvider { get; } |
20 | 23 | ||
21 | public IEnumerable<string> IncludeSearchPaths { get; } | 24 | public IMessaging Messaging { get; } |
22 | 25 | ||
23 | private IEnumerable<SourceFile> SourceFiles { get; } | 26 | private IEnumerable<SourceFile> SourceFiles { get; } |
24 | 27 | ||
25 | private IDictionary<string, string> PreprocessorVariables { get; } | 28 | private IDictionary<string, string> PreprocessorVariables { get; } |
26 | 29 | ||
30 | public IEnumerable<string> IncludeSearchPaths { get; } | ||
31 | |||
27 | public int Execute() | 32 | public int Execute() |
28 | { | 33 | { |
29 | foreach (var sourceFile in this.SourceFiles) | 34 | foreach (var sourceFile in this.SourceFiles) |
@@ -33,7 +38,21 @@ namespace WixToolset.Core.CommandLine | |||
33 | preprocessor.Platform = Platform.X86; // TODO: set this correctly | 38 | preprocessor.Platform = Platform.X86; // TODO: set this correctly |
34 | preprocessor.SourcePath = sourceFile.SourcePath; | 39 | preprocessor.SourcePath = sourceFile.SourcePath; |
35 | preprocessor.Variables = new Dictionary<string, string>(this.PreprocessorVariables); | 40 | preprocessor.Variables = new Dictionary<string, string>(this.PreprocessorVariables); |
36 | var document = preprocessor.Execute(); | 41 | |
42 | XDocument document = null; | ||
43 | try | ||
44 | { | ||
45 | document = preprocessor.Execute(); | ||
46 | } | ||
47 | catch (WixException e) | ||
48 | { | ||
49 | this.Messaging.Write(e.Error); | ||
50 | } | ||
51 | |||
52 | if (this.Messaging.EncounteredError) | ||
53 | { | ||
54 | continue; | ||
55 | } | ||
37 | 56 | ||
38 | var compiler = new Compiler(this.ServiceProvider); | 57 | var compiler = new Compiler(this.ServiceProvider); |
39 | compiler.OutputPath = sourceFile.OutputPath; | 58 | compiler.OutputPath = sourceFile.OutputPath; |
diff --git a/src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs b/src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs index 9c60c902..ebc713ed 100644 --- a/src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs | |||
@@ -63,6 +63,32 @@ namespace WixToolsetTest.CoreIntegration | |||
63 | Assert.Equal(0, result); | 63 | Assert.Equal(0, result); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | |||
67 | [Fact] | ||
68 | public void NonterminatedPreprocessorInstructionShowsSourceLineNumber() | ||
69 | { | ||
70 | var folder = TestData.Get(@"TestData\BadIf"); | ||
71 | |||
72 | using (var fs = new DisposableFileSystem()) | ||
73 | { | ||
74 | var baseFolder = fs.GetFolder(); | ||
75 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
76 | |||
77 | var result = WixRunner.Execute(new[] | ||
78 | { | ||
79 | "build", | ||
80 | Path.Combine(folder, "Package.wxs"), | ||
81 | Path.Combine(folder, "PackageComponents.wxs"), | ||
82 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), | ||
83 | "-bindpath", Path.Combine(folder, "data"), | ||
84 | "-intermediateFolder", intermediateFolder, | ||
85 | "-o", Path.Combine(baseFolder, @"bin\test.msi") | ||
86 | }, out var messages); | ||
87 | |||
88 | Assert.Equal(147, result); | ||
89 | Assert.StartsWith("Found a <?if?>", messages.Single().ToString()); | ||
90 | } | ||
91 | } | ||
66 | } | 92 | } |
67 | } | 93 | } |
68 | 94 | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.en-us.wxl b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.en-us.wxl new file mode 100644 index 00000000..38c12ac1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.en-us.wxl | |||
@@ -0,0 +1,11 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | |||
3 | <!-- | ||
4 | This file contains the declaration of all the localizable strings. | ||
5 | --> | ||
6 | <WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US"> | ||
7 | |||
8 | <String Id="DowngradeError">A newer version of [ProductName] is already installed.</String> | ||
9 | <String Id="FeatureTitle">MsiPackage</String> | ||
10 | |||
11 | </WixLocalization> | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.wxs new file mode 100644 index 00000000..73577ce5 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/Package.wxs | |||
@@ -0,0 +1,26 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
3 | <Product Id="*" Name="MsiPackage" Language="1033" Version="1.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"> | ||
4 | <Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" /> | ||
5 | |||
6 | <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" /> | ||
7 | <MediaTemplate /> | ||
8 | |||
9 | <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)"> | ||
10 | <ComponentGroupRef Id="ProductComponents.x86" /> | ||
11 | <!-- <?if x64 == $(sys.BUILDARCH) ?> --> | ||
12 | <!-- <?if arm==$(sys.BUILDARCH) ?> --> | ||
13 | <?if $(sys.BUILDARCH) = "x64" ?> | ||
14 | <ComponentGroupRef Id="ProductComponents.x64" /> | ||
15 | <ComponentGroupRef Id="ProductComponents.arm" /> | ||
16 | </Feature> | ||
17 | </Product> | ||
18 | |||
19 | <Fragment> | ||
20 | <Directory Id="TARGETDIR" Name="SourceDir"> | ||
21 | <Directory Id="ProgramFilesFolder"> | ||
22 | <Directory Id="INSTALLFOLDER" Name="MsiPackage" /> | ||
23 | </Directory> | ||
24 | </Directory> | ||
25 | </Fragment> | ||
26 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/PackageComponents.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/PackageComponents.wxs new file mode 100644 index 00000000..2a75e3d7 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/PackageComponents.wxs | |||
@@ -0,0 +1,12 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
3 | <?foreach ComponentPlatform in x86;x64;arm ?> | ||
4 | <Fragment> | ||
5 | <ComponentGroup Id="ProductComponents.$(var.ComponentPlatform)" Directory="INSTALLFOLDER"> | ||
6 | <Component> | ||
7 | <File Name="$(var.ComponentPlatform).dll" Source="test.txt" /> | ||
8 | </Component> | ||
9 | </ComponentGroup> | ||
10 | </Fragment> | ||
11 | <?endforeach?> | ||
12 | </Wix> | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/data/test.txt b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/data/test.txt new file mode 100644 index 00000000..cd0db0e1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadIf/data/test.txt | |||
@@ -0,0 +1 @@ | |||
This is test.txt. \ No newline at end of file | |||
diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index 7c4578d9..38b7dc81 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj | |||
@@ -28,6 +28,10 @@ | |||
28 | <Content Include="TestData\ForEach\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | 28 | <Content Include="TestData\ForEach\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> |
29 | <Content Include="TestData\ForEach\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | 29 | <Content Include="TestData\ForEach\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> |
30 | <Content Include="TestData\ForEach\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> | 30 | <Content Include="TestData\ForEach\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> |
31 | <Content Include="TestData\BadIf\data\test.txt" CopyToOutputDirectory="PreserveNewest" /> | ||
32 | <Content Include="TestData\BadIf\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | ||
33 | <Content Include="TestData\BadIf\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
34 | <Content Include="TestData\BadIf\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
31 | <Content Include="TestData\SingleFile\data\test.txt" CopyToOutputDirectory="PreserveNewest" /> | 35 | <Content Include="TestData\SingleFile\data\test.txt" CopyToOutputDirectory="PreserveNewest" /> |
32 | <Content Include="TestData\SingleFile\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | 36 | <Content Include="TestData\SingleFile\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> |
33 | <Content Include="TestData\SingleFile\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | 37 | <Content Include="TestData\SingleFile\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> |