@joebigelow / wix-1 / commits / c9c3ab27

Clean up variable resolution during Resolve.

Bob Arnson committed Jan 29, 2020 at 15:04 UTC c9c3ab2776252d3131fea561bd3f3fac8c045f5e
3 files changed +17 -22
src/WixToolset.Core/CommandLine/BuildCommand.cs
-1
@@ -284,7 +284,6 @@ namespace WixToolset.Core.CommandLine
284 context.IntermediateFolder = intermediateFolder;
285 context.IntermediateRepresentation = output;
286 context.Localizations = localizations;
287 - context.VariableResolver = this.ServiceProvider.GetService<IVariableResolver>();
287
288 var resolver = this.ServiceProvider.GetService<IResolver>();
289 resolveResult = resolver.Resolve(context);
src/WixToolset.Core/Resolver.cs
+17 -13
@@ -22,12 +22,16 @@ namespace WixToolset.Core
22 this.ServiceProvider = serviceProvider;
23
24 this.Messaging = serviceProvider.GetService<IMessaging>();
25 +
26 + this.VariableResolver = serviceProvider.GetService<IVariableResolver>();
27 }
28
29 private IServiceProvider ServiceProvider { get; }
30
31 private IMessaging Messaging { get; }
32
33 + private IVariableResolver VariableResolver { get; set; }
34 +
35 public IEnumerable<IBindPath> BindPaths { get; set; }
36
37 public string IntermediateFolder { get; set; }
@@ -40,7 +44,6 @@ namespace WixToolset.Core
44
45 public IResolveResult Resolve(IResolveContext context)
46 {
43 -
47 foreach (var extension in context.Extensions)
48 {
49 extension.PreResolve(context);
@@ -49,11 +52,11 @@ namespace WixToolset.Core
52 ResolveResult resolveResult = null;
53 try
54 {
52 - PopulateVariableResolver(context);
55 + var codepage = this.PopulateVariableResolver(context);
56
57 this.LocalizeUI(context);
58
56 - resolveResult = this.DoResolve(context);
59 + resolveResult = this.DoResolve(context, codepage);
60 }
61 finally
62 {
@@ -66,7 +69,7 @@ namespace WixToolset.Core
69 return resolveResult;
70 }
71
69 - private ResolveResult DoResolve(IResolveContext context)
72 + private ResolveResult DoResolve(IResolveContext context, int? codepage)
73 {
74 var buildingPatch = context.IntermediateRepresentation.Sections.Any(s => s.Type == SectionType.Patch);
75
@@ -77,7 +80,7 @@ namespace WixToolset.Core
80 var command = new ResolveFieldsCommand();
81 command.Messaging = this.Messaging;
82 command.BuildingPatch = buildingPatch;
80 - command.VariableResolver = context.VariableResolver;
83 + command.VariableResolver = this.VariableResolver;
84 command.BindPaths = context.BindPaths;
85 command.Extensions = context.Extensions;
86 command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles;
@@ -112,7 +115,7 @@ namespace WixToolset.Core
115
116 return new ResolveResult
117 {
115 - Codepage = context.VariableResolver.Codepage,
118 + Codepage = codepage.HasValue ? codepage.Value : -1,
119 ExpectedEmbeddedFiles = expectedEmbeddedFiles,
120 DelayedFields = delayedFields,
121 IntermediateRepresentation = context.IntermediateRepresentation
@@ -128,7 +131,7 @@ namespace WixToolset.Core
131 {
132 foreach (var tuple in section.Tuples.OfType<DialogTuple>())
133 {
131 - if (context.VariableResolver.TryGetLocalizedControl(tuple.Id.Id, null, out var localizedControl))
134 + if (this.VariableResolver.TryGetLocalizedControl(tuple.Id.Id, null, out var localizedControl))
135 {
136 if (CompilerConstants.IntegerNotSet != localizedControl.X)
137 {
@@ -163,7 +166,7 @@ namespace WixToolset.Core
166
167 foreach (var tuple in section.Tuples.OfType<ControlTuple>())
168 {
166 - if (context.VariableResolver.TryGetLocalizedControl(tuple.DialogRef, tuple.Control, out var localizedControl))
169 + if (this.VariableResolver.TryGetLocalizedControl(tuple.DialogRef, tuple.Control, out var localizedControl))
170 {
171 if (CompilerConstants.IntegerNotSet != localizedControl.X)
172 {
@@ -198,23 +201,24 @@ namespace WixToolset.Core
201 }
202 }
203
201 - private static void PopulateVariableResolver(IResolveContext context)
204 + private int? PopulateVariableResolver(IResolveContext context)
205 {
203 - var creator = context.ServiceProvider.GetService<ITupleDefinitionCreator>();
204 -
206 var localizations = FilterLocalizations(context);
207 + var codepage = localizations.FirstOrDefault()?.Codepage;
208
209 foreach (var localization in localizations)
210 {
209 - context.VariableResolver.AddLocalization(localization);
211 + this.VariableResolver.AddLocalization(localization);
212 }
213
214 // Gather all the wix variables.
215 var wixVariableTuples = context.IntermediateRepresentation.Sections.SelectMany(s => s.Tuples).OfType<WixVariableTuple>();
216 foreach (var tuple in wixVariableTuples)
217 {
216 - context.VariableResolver.AddVariable(tuple.SourceLineNumbers, tuple.Id.Id, tuple.Value, tuple.Overridable);
218 + this.VariableResolver.AddVariable(tuple.SourceLineNumbers, tuple.Id.Id, tuple.Value, tuple.Overridable);
219 }
220 +
221 + return codepage;
222 }
223
224 private static IEnumerable<Localization> FilterLocalizations(IResolveContext context)
src/WixToolset.Core/VariableResolver.cs
-8
@@ -29,24 +29,16 @@ namespace WixToolset.Core
29 this.locVariables = new Dictionary<string, BindVariable>();
30 this.wixVariables = new Dictionary<string, BindVariable>();
31 this.localizedControls = new Dictionary<string, LocalizedControl>();
32 - this.Codepage = -1;
32 }
33
34 private IServiceProvider ServiceProvider { get; }
35
36 private IMessaging Messaging { get; }
37
39 - public int Codepage { get; private set; }
40 -
38 public int VariableCount => this.wixVariables.Count;
39
40 public void AddLocalization(Localization localization)
41 {
45 - if (-1 == this.Codepage)
46 - {
47 - this.Codepage = localization.Codepage;
48 - }
49 -
42 foreach (var variable in localization.Variables)
43 {
44 if (!TryAddWixVariable(this.locVariables, variable))