diff options
author | Bob Arnson <bob@firegiant.com> | 2020-03-18 21:45:53 -0400 |
---|---|---|
committer | Bob Arnson <bob@firegiant.com> | 2020-03-18 21:50:00 -0400 |
commit | c5df86a7caaa1cbff9adde6396925383ba9a2e4e (patch) | |
tree | a082d0a8eaa759a3ba78cfedb0d89a1ebfac8a8e | |
parent | f1ddeb81aa8c709582fc11a5711b39da596f4f22 (diff) | |
download | wix-c5df86a7caaa1cbff9adde6396925383ba9a2e4e.tar.gz wix-c5df86a7caaa1cbff9adde6396925383ba9a2e4e.tar.bz2 wix-c5df86a7caaa1cbff9adde6396925383ba9a2e4e.zip |
Allow unresolved variables during resolution.
-rw-r--r-- | src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | 4 | ||||
-rw-r--r-- | src/WixToolset.Core/ResolveContext.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/Resolver.cs | 1 | ||||
-rw-r--r-- | src/WixToolset.Core/VariableResolver.cs | 9 | ||||
-rw-r--r-- | src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs | 7 |
5 files changed, 13 insertions, 10 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs index 5db878a1..3e680a98 100644 --- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | |||
@@ -32,6 +32,8 @@ namespace WixToolset.Core.Bind | |||
32 | 32 | ||
33 | public bool SupportDelayedResolution { private get; set; } | 33 | public bool SupportDelayedResolution { private get; set; } |
34 | 34 | ||
35 | public bool AllowUnresolvedVariables { private get; set; } | ||
36 | |||
35 | public IEnumerable<DelayedField> DelayedFields { get; private set; } | 37 | public IEnumerable<DelayedField> DelayedFields { get; private set; } |
36 | 38 | ||
37 | public void Execute() | 39 | public void Execute() |
@@ -62,7 +64,7 @@ namespace WixToolset.Core.Bind | |||
62 | var original = field.AsString(); | 64 | var original = field.AsString(); |
63 | if (!String.IsNullOrEmpty(original)) | 65 | if (!String.IsNullOrEmpty(original)) |
64 | { | 66 | { |
65 | var resolution = this.VariableResolver.ResolveVariables(tuple.SourceLineNumbers, original); | 67 | var resolution = this.VariableResolver.ResolveVariables(tuple.SourceLineNumbers, original, !this.AllowUnresolvedVariables); |
66 | if (resolution.UpdatedValue) | 68 | if (resolution.UpdatedValue) |
67 | { | 69 | { |
68 | field.Set(resolution.Value); | 70 | field.Set(resolution.Value); |
diff --git a/src/WixToolset.Core/ResolveContext.cs b/src/WixToolset.Core/ResolveContext.cs index 1801f820..1694d6e5 100644 --- a/src/WixToolset.Core/ResolveContext.cs +++ b/src/WixToolset.Core/ResolveContext.cs | |||
@@ -33,5 +33,7 @@ namespace WixToolset.Core | |||
33 | public IEnumerable<Localization> Localizations { get; set; } | 33 | public IEnumerable<Localization> Localizations { get; set; } |
34 | 34 | ||
35 | public IVariableResolver VariableResolver { get; set; } | 35 | public IVariableResolver VariableResolver { get; set; } |
36 | |||
37 | public bool AllowUnresolvedVariables { get; set; } | ||
36 | } | 38 | } |
37 | } | 39 | } |
diff --git a/src/WixToolset.Core/Resolver.cs b/src/WixToolset.Core/Resolver.cs index 54bde848..6913ce98 100644 --- a/src/WixToolset.Core/Resolver.cs +++ b/src/WixToolset.Core/Resolver.cs | |||
@@ -87,6 +87,7 @@ namespace WixToolset.Core | |||
87 | command.IntermediateFolder = context.IntermediateFolder; | 87 | command.IntermediateFolder = context.IntermediateFolder; |
88 | command.Intermediate = context.IntermediateRepresentation; | 88 | command.Intermediate = context.IntermediateRepresentation; |
89 | command.SupportDelayedResolution = true; | 89 | command.SupportDelayedResolution = true; |
90 | command.AllowUnresolvedVariables = context.AllowUnresolvedVariables; | ||
90 | command.Execute(); | 91 | command.Execute(); |
91 | 92 | ||
92 | delayedFields = command.DelayedFields; | 93 | delayedFields = command.DelayedFields; |
diff --git a/src/WixToolset.Core/VariableResolver.cs b/src/WixToolset.Core/VariableResolver.cs index b1a5defc..8cddfaa5 100644 --- a/src/WixToolset.Core/VariableResolver.cs +++ b/src/WixToolset.Core/VariableResolver.cs | |||
@@ -77,14 +77,7 @@ namespace WixToolset.Core | |||
77 | return this.localizedControls.TryGetValue(key, out localizedControl); | 77 | return this.localizedControls.TryGetValue(key, out localizedControl); |
78 | } | 78 | } |
79 | 79 | ||
80 | /// <summary> | 80 | public IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool errorOnUnknown) |
81 | /// Resolve the wix variables in a value. | ||
82 | /// </summary> | ||
83 | /// <param name="sourceLineNumbers">The source line information for the value.</param> | ||
84 | /// <param name="value">The value to resolve.</param> | ||
85 | /// <param name="errorOnUnknown">true if unknown variables should throw errors.</param> | ||
86 | /// <returns>The resolved value.</returns> | ||
87 | internal IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool errorOnUnknown) | ||
88 | { | 81 | { |
89 | var matches = Common.WixVariableRegex.Matches(value); | 82 | var matches = Common.WixVariableRegex.Matches(value); |
90 | 83 | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs b/src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs index abf1bd43..3443896b 100644 --- a/src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs | |||
@@ -50,7 +50,12 @@ namespace WixToolsetTest.CoreIntegration | |||
50 | Assert.False(result.UpdatedValue); | 50 | Assert.False(result.UpdatedValue); |
51 | Assert.True(result.DelayedResolve); | 51 | Assert.True(result.DelayedResolve); |
52 | 52 | ||
53 | Assert.Throws<WixException>(() => variableResolver.ResolveVariables(null, "Welcome to !(loc.UnknownLocalizationVariable)")); | 53 | var withUnknownLocString = "Welcome to !(loc.UnknownLocalizationVariable)"; |
54 | Assert.Throws<WixException>(() => variableResolver.ResolveVariables(null, withUnknownLocString)); | ||
55 | |||
56 | result = variableResolver.ResolveVariables(null, withUnknownLocString, errorOnUnknown: false); | ||
57 | Assert.Equal(withUnknownLocString, result.Value); | ||
58 | Assert.False(result.UpdatedValue); | ||
54 | 59 | ||
55 | result = variableResolver.ResolveVariables(null, "Welcome to !!(loc.UnknownLocalizationVariable)"); | 60 | result = variableResolver.ResolveVariables(null, "Welcome to !!(loc.UnknownLocalizationVariable)"); |
56 | Assert.Equal("Welcome to !(loc.UnknownLocalizationVariable)", result.Value); | 61 | Assert.Equal("Welcome to !(loc.UnknownLocalizationVariable)", result.Value); |