aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-03-25 22:03:40 -0700
committerRob Mensching <rob@firegiant.com>2021-03-25 22:08:36 -0700
commitf4242573301899109186cdff6694a289ee27d794 (patch)
tree826cf3f244efad344d9bd0202f38fd826ed8701a /src
parent3dc92067f57e3803d4e1bac6d055e2a23f797414 (diff)
downloadwix-f4242573301899109186cdff6694a289ee27d794.tar.gz
wix-f4242573301899109186cdff6694a289ee27d794.tar.bz2
wix-f4242573301899109186cdff6694a289ee27d794.zip
Re-resolve binary .wixlibs with defaulted embedded files
Fixes wixtoolset/issues#6376
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Core/Bind/ResolveFieldsCommand.cs165
-rw-r--r--src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs2
2 files changed, 92 insertions, 75 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
index 629e5f28..2738ac6c 100644
--- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
@@ -82,8 +82,6 @@ namespace WixToolset.Core.Bind
82 } 82 }
83 } 83 }
84 84
85 var isDefault = true;
86
87 // Check to make sure we're in a scenario where we can handle variable resolution. 85 // Check to make sure we're in a scenario where we can handle variable resolution.
88 if (null != delayedFields) 86 if (null != delayedFields)
89 { 87 {
@@ -103,8 +101,6 @@ namespace WixToolset.Core.Bind
103 { 101 {
104 delayedFields.Add(new DelayedField(symbol, field)); 102 delayedFields.Add(new DelayedField(symbol, field));
105 } 103 }
106
107 isDefault = resolution.IsDefault;
108 } 104 }
109 } 105 }
110 } 106 }
@@ -118,76 +114,7 @@ namespace WixToolset.Core.Bind
118 // Resolve file paths 114 // Resolve file paths
119 if (fieldType == IntermediateFieldType.Path) 115 if (fieldType == IntermediateFieldType.Path)
120 { 116 {
121 var objectField = field.AsPath(); 117 this.ResolvePathField(fileResolver, symbol, field);
122
123#if TODO_PATCHING
124 // Skip file resolution if the file is to be deleted.
125 if (RowOperation.Delete == symbol.Operation)
126 {
127 continue;
128 }
129#endif
130
131 // File is embedded and path to it was not modified above.
132 if (isDefault && objectField.Embed)
133 {
134 var extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileToExtract(objectField.BaseUri, objectField.Path, this.IntermediateFolder);
135
136 // Set the path to the embedded file once where it will be extracted.
137 field.Set(extractPath);
138 }
139 else if (null != objectField.Path) // non-compressed file (or localized value)
140 {
141 try
142 {
143 if (!this.BuildingPatch) // Normal binding for non-Patch scenario such as link (light.exe)
144 {
145#if TODO_PATCHING
146 // keep a copy of the un-resolved data for future replay. This will be saved into wixpdb file
147 if (null == objectField.UnresolvedData)
148 {
149 objectField.UnresolvedData = (string)objectField.Data;
150 }
151#endif
152
153 // resolve the path to the file
154 var value = fileResolver.ResolveFile(objectField.Path, symbol.Definition, symbol.SourceLineNumbers, BindStage.Normal);
155 field.Set(value);
156 }
157 else if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) // Normal binding for Patch Scenario (normal patch, no re-basing logic)
158 {
159 // resolve the path to the file
160 var value = fileResolver.ResolveFile(objectField.Path, symbol.Definition, symbol.SourceLineNumbers, BindStage.Normal);
161 field.Set(value);
162 }
163#if TODO_PATCHING
164 else // Re-base binding path scenario caused by pyro.exe -bt -bu
165 {
166 // by default, use the resolved Data for file lookup
167 string filePathToResolve = (string)objectField.Data;
168
169 // if -bu is used in pyro command, this condition holds true and the tool
170 // will use pre-resolved source for new wixpdb file
171 if (fileResolver.RebaseUpdated)
172 {
173 // try to use the unResolved Source if it exists.
174 // New version of wixpdb file keeps a copy of pre-resolved Source. i.e. !(bindpath.test)\foo.dll
175 // Old version of winpdb file does not contain this attribute and the value is null.
176 if (null != objectField.UnresolvedData)
177 {
178 filePathToResolve = objectField.UnresolvedData;
179 }
180 }
181
182 objectField.Data = fileResolver.ResolveFile(filePathToResolve, symbol.Definition.Name, symbol.SourceLineNumbers, BindStage.Updated);
183 }
184#endif
185 }
186 catch (WixException e)
187 {
188 this.Messaging.Write(e.Error);
189 }
190 }
191 118
192#if TODO_PATCHING 119#if TODO_PATCHING
193 if (null != objectField.PreviousData) 120 if (null != objectField.PreviousData)
@@ -255,5 +182,95 @@ namespace WixToolset.Core.Bind
255 182
256 this.DelayedFields = delayedFields; 183 this.DelayedFields = delayedFields;
257 } 184 }
185
186 private void ResolvePathField(FileResolver fileResolver, IntermediateSymbol symbol, IntermediateField field)
187 {
188 var fieldValue = field.AsPath();
189 var originalFieldPath = fieldValue.Path;
190
191#if TODO_PATCHING
192 // Skip file resolution if the file is to be deleted.
193 if (RowOperation.Delete == symbol.Operation)
194 {
195 continue;
196 }
197#endif
198
199 // If the file is embedded and if the previous value has a bind variable in the path
200 // which gets modified by resolving the previous value again then switch to that newly
201 // resolved path instead of using the embedded file.
202 if (fieldValue.Embed && field.PreviousValue != null)
203 {
204 var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, field.PreviousValue.AsString(), errorOnUnknown: false);
205
206 if (resolution.UpdatedValue && !resolution.IsDefault)
207 {
208 fieldValue = new IntermediateFieldPathValue { Path = resolution.Value };
209 }
210 }
211
212 // If we're still using the embedded file.
213 if (fieldValue.Embed)
214 {
215 // Set the path to the embedded file once where it will be extracted.
216 var extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileToExtract(fieldValue.BaseUri, fieldValue.Path, this.IntermediateFolder);
217
218 field.Set(extractPath);
219 }
220 else if (fieldValue.Path != null)
221 {
222 try
223 {
224 var resolvedPath = fieldValue.Path;
225
226 if (!this.BuildingPatch) // Normal binding for non-Patch scenario such as link (light.exe)
227 {
228#if TODO_PATCHING
229 // keep a copy of the un-resolved data for future replay. This will be saved into wixpdb file
230 if (null == objectField.UnresolvedData)
231 {
232 objectField.UnresolvedData = (string)objectField.Data;
233 }
234#endif
235 resolvedPath = fileResolver.ResolveFile(fieldValue.Path, symbol.Definition, symbol.SourceLineNumbers, BindStage.Normal);
236 }
237 else if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) // Normal binding for Patch Scenario (normal patch, no re-basing logic)
238 {
239 resolvedPath = fileResolver.ResolveFile(fieldValue.Path, symbol.Definition, symbol.SourceLineNumbers, BindStage.Normal);
240 }
241#if TODO_PATCHING
242 else // Re-base binding path scenario caused by pyro.exe -bt -bu
243 {
244 // by default, use the resolved Data for file lookup
245 string filePathToResolve = (string)objectField.Data;
246
247 // if -bu is used in pyro command, this condition holds true and the tool
248 // will use pre-resolved source for new wixpdb file
249 if (fileResolver.RebaseUpdated)
250 {
251 // try to use the unResolved Source if it exists.
252 // New version of wixpdb file keeps a copy of pre-resolved Source. i.e. !(bindpath.test)\foo.dll
253 // Old version of winpdb file does not contain this attribute and the value is null.
254 if (null != objectField.UnresolvedData)
255 {
256 filePathToResolve = objectField.UnresolvedData;
257 }
258 }
259
260 objectField.Data = fileResolver.ResolveFile(filePathToResolve, symbol.Definition.Name, symbol.SourceLineNumbers, BindStage.Updated);
261 }
262#endif
263
264 if (!String.Equals(originalFieldPath, resolvedPath, StringComparison.OrdinalIgnoreCase))
265 {
266 field.Set(resolvedPath);
267 }
268 }
269 catch (WixException e)
270 {
271 this.Messaging.Write(e.Error);
272 }
273 }
274 }
258 } 275 }
259} 276}
diff --git a/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs b/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs
index 52460843..d7296cfe 100644
--- a/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs
+++ b/src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs
@@ -144,7 +144,7 @@ namespace WixToolsetTest.CoreIntegration
144 } 144 }
145 } 145 }
146 146
147 [Fact(Skip = "https://github.com/wixtoolset/issues/issues/6376")] 147 [Fact]
148 public void CanOverridePathWixVariable() 148 public void CanOverridePathWixVariable()
149 { 149 {
150 var folder = TestData.Get(@"TestData\WixVariableOverride"); 150 var folder = TestData.Get(@"TestData\WixVariableOverride");