Support preprocessing .wxl files
Rob Mensching committed
Dec 31, 2017 at 00:43 UTC
84d1f05fee656c01938613bcc50bd8139006bbf6
2 files changed
+50
-24
src/WixToolset.Core/CommandLine/BuildCommand.cs
+37
-20
@@ -75,37 +75,48 @@ namespace WixToolset.Core.CommandLine
75
76
public int Execute()
77
{
78
- var intermediates = this.CompilePhase();
78
+ var wixobjs = this.CompilePhase();
79
80
if (this.Messaging.EncounteredError)
81
{
82
return this.Messaging.LastErrorNumber;
83
}
84
85
- if (!intermediates.Any())
85
+ if (!wixobjs.Any())
86
{
87
return 1;
88
}
89
90
- if (this.OutputType == OutputType.Library)
91
- {
92
- var library = this.LibraryPhase(intermediates);
90
+ var wxls = this.LoadLocalizationFiles();
91
94
- library?.Save(this.OutputPath);
92
+ if (this.Messaging.EncounteredError)
93
+ {
94
+ return this.Messaging.LastErrorNumber;
95
}
96
- else if (this.OutputType == OutputType.IntermediatePostLink)
96
+
97
+ if (this.OutputType == OutputType.Library)
98
{
98
- var output = this.LinkPhase(intermediates);
99
+ var wixlib = this.LibraryPhase(wixobjs, wxls);
100
100
- output?.Save(this.OutputPath);
101
+ if (!this.Messaging.EncounteredError)
102
+ {
103
+ wixlib.Save(this.OutputPath);
104
+ }
105
}
106
else
107
{
104
- var output = this.LinkPhase(intermediates);
108
+ var wixipl = this.LinkPhase(wixobjs);
109
110
if (!this.Messaging.EncounteredError)
111
{
108
- this.BindPhase(output);
112
+ if (this.OutputType == OutputType.IntermediatePostLink)
113
+ {
114
+ wixipl.Save(this.OutputPath);
115
+ }
116
+ else
117
+ {
118
+ this.BindPhase(wixipl, wxls);
119
+ }
120
}
121
}
122
@@ -147,10 +158,8 @@ namespace WixToolset.Core.CommandLine
158
return intermediates;
159
}
160
150
- private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates)
161
+ private Intermediate LibraryPhase(IEnumerable<Intermediate> intermediates, IEnumerable<Localization> localizations)
162
{
152
- var localizations = this.LoadLocalizationFiles().ToList();
153
-
163
// If there was an error loading localization files, then bail.
164
if (this.Messaging.EncounteredError)
165
{
@@ -184,12 +193,8 @@ namespace WixToolset.Core.CommandLine
193
return linker.Execute();
194
}
195
187
- private void BindPhase(Intermediate output)
196
+ private void BindPhase(Intermediate output, IEnumerable<Localization> localizations)
197
{
189
- var localizations = new List<Localization>(output.Localizations);
190
-
191
- localizations.AddRange(this.LoadLocalizationFiles());
192
-
198
// If there was an error loading localization files, then bail.
199
if (this.Messaging.EncounteredError)
200
{
@@ -288,7 +293,19 @@ namespace WixToolset.Core.CommandLine
293
{
294
foreach (var loc in this.LocFiles)
295
{
291
- var localization = Localizer.ParseLocalizationFile(this.Messaging, loc);
296
+ var preprocessor = new Preprocessor(this.ServiceProvider);
297
+ preprocessor.IncludeSearchPaths = this.IncludeSearchPaths;
298
+ preprocessor.Platform = Platform.X86; // TODO: set this correctly
299
+ preprocessor.SourcePath = loc;
300
+ preprocessor.Variables = this.PreprocessorVariables;
301
+ var document = preprocessor.Execute();
302
+
303
+ if (this.Messaging.EncounteredError)
304
+ {
305
+ continue;
306
+ }
307
+
308
+ var localization = Localizer.ParseLocalizationFile(this.Messaging, document);
309
310
yield return localization;
311
}
src/WixToolset.Core/Localizer.cs
+13
-4
@@ -22,13 +22,22 @@ namespace WixToolset.Core
22
/// <summary>
23
/// Loads a localization file from a path on disk.
24
/// </summary>
25
- /// <param name="path">Path to library file saved on disk.</param>
26
- /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param>
27
- /// <param name="suppressSchema">Suppress xml schema validation while loading.</param>
25
+ /// <param name="path">Path to localization file saved on disk.</param>
26
/// <returns>Returns the loaded localization file.</returns>
27
public static Localization ParseLocalizationFile(IMessaging messaging, string path)
28
{
31
- XElement root = XDocument.Load(path).Root;
29
+ var document = XDocument.Load(path);
30
+ return ParseLocalizationFile(messaging, document);
31
+ }
32
+
33
+ /// <summary>
34
+ /// Loads a localization file from memory.
35
+ /// </summary>
36
+ /// <param name="document">Document to parse as localization file.</param>
37
+ /// <returns>Returns the loaded localization file.</returns>
38
+ public static Localization ParseLocalizationFile(IMessaging messaging, XDocument document)
39
+ {
40
+ XElement root = document.Root;
41
Localization localization = null;
42
43
SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(root);