Ensure named bindpaths are not found in unnamed bindpaths
Fixes wixtoolset/issues#6200
Rob Mensching committed
Jul 17, 2020 at 15:22 UTC
6b21265e139513c1a242d8677b154fcc0e1dc7ef
6 files changed
+68
-62
src/WixToolset.Core/Bind/FileResolver.cs
+34
-28
@@ -115,13 +115,14 @@ namespace WixToolset.Core.Bind
115
}
116
else // not a rooted path so let's try applying all the different source resolution options.
117
{
118
- string bindName = null;
118
+ var bindName = String.Empty;
119
var path = source;
120
- string pathWithoutSourceDir = null;
120
+ var pathWithoutSourceDir = String.Empty;
121
122
if (source.StartsWith(BindPathOpenString, StringComparison.Ordinal))
123
{
124
- int closeParen = source.IndexOf(')', BindPathOpenString.Length);
124
+ var closeParen = source.IndexOf(')', BindPathOpenString.Length);
125
+
126
if (-1 != closeParen)
127
{
128
bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length);
@@ -138,43 +139,48 @@ namespace WixToolset.Core.Bind
139
140
foreach (var bindPath in bindPaths)
141
{
141
- if (!String.IsNullOrEmpty(bindName) && !String.IsNullOrEmpty(bindPath.Name))
142
+ if (String.IsNullOrEmpty(bindName))
143
{
143
- if (String.Equals(bindName, bindPath.Name, StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(resolved))
144
+ if (String.IsNullOrEmpty(bindPath.Name))
145
{
145
- var filePath = Path.Combine(bindPath.Path, path);
146
-
147
- checkedPaths.Add(filePath);
148
- if (CheckFileExists(filePath))
146
+ if (!String.IsNullOrEmpty(pathWithoutSourceDir))
147
{
150
- resolved = filePath;
148
+ var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir);
149
+
150
+ checkedPaths.Add(filePath);
151
+ if (CheckFileExists(filePath))
152
+ {
153
+ resolved = filePath;
154
+ }
155
}
152
- }
153
- }
154
- else
155
- {
156
- if (!String.IsNullOrEmpty(pathWithoutSourceDir))
157
- {
158
- var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir);
156
160
- checkedPaths.Add(filePath);
161
- if (CheckFileExists(filePath))
157
+ if (String.IsNullOrEmpty(resolved))
158
{
163
- resolved = filePath;
159
+ var filePath = Path.Combine(bindPath.Path, path);
160
+
161
+ checkedPaths.Add(filePath);
162
+ if (CheckFileExists(filePath))
163
+ {
164
+ resolved = filePath;
165
+ }
166
}
167
}
168
+ }
169
+ else if (bindName.Equals(bindPath.Name, StringComparison.OrdinalIgnoreCase))
170
+ {
171
+ var filePath = Path.Combine(bindPath.Path, path);
172
167
- if (String.IsNullOrEmpty(resolved))
173
+ checkedPaths.Add(filePath);
174
+ if (CheckFileExists(filePath))
175
{
169
- var filePath = Path.Combine(bindPath.Path, path);
170
-
171
- checkedPaths.Add(filePath);
172
- if (CheckFileExists(filePath))
173
- {
174
- resolved = filePath;
175
- }
176
+ resolved = filePath;
177
}
178
}
179
+
180
+ if (!String.IsNullOrEmpty(resolved))
181
+ {
182
+ break;
183
+ }
184
}
185
}
186
src/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs
+31
-1
@@ -13,7 +13,7 @@ namespace WixToolsetTest.CoreIntegration
13
[Fact]
14
public void CanBuildWithDefaultValue()
15
{
16
- var folder = TestData.Get(@"TestData\BindVariables");
16
+ var folder = TestData.Get(@"TestData", "BindVariables");
17
18
using (var fs = new DisposableFileSystem())
19
{
@@ -34,5 +34,35 @@ namespace WixToolsetTest.CoreIntegration
34
result.AssertSuccess();
35
}
36
}
37
+
38
+ [Fact]
39
+ public void CannotBuildWixlibWithBinariesFromMissingNamedBindPaths()
40
+ {
41
+ var folder = TestData.Get(@"TestData", "WixlibWithBinaries");
42
+
43
+ using (var fs = new DisposableFileSystem())
44
+ {
45
+ var baseFolder = fs.GetFolder();
46
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
47
+ var wixlibPath = Path.Combine(intermediateFolder, @"test.wixlib");
48
+
49
+ var result = WixRunner.Execute(new[]
50
+ {
51
+ "build",
52
+ Path.Combine(folder, "PackageComponents.wxs"),
53
+ "-bf",
54
+ "-bindpath", Path.Combine(folder, "data"),
55
+ // Use names that aren't excluded in default .gitignores.
56
+ "-bindpath", $"AlphaBits={Path.Combine(folder, "data", "alpha")}",
57
+ "-bindpath", $"PowerBits={Path.Combine(folder, "data", "powerpc")}",
58
+ "-bindpath", $"{Path.Combine(folder, "data", "alpha")}",
59
+ "-bindpath", $"{Path.Combine(folder, "data", "powerpc")}",
60
+ "-intermediateFolder", intermediateFolder,
61
+ "-o", wixlibPath,
62
+ });
63
+
64
+ Assert.Equal(103, result.ExitCode);
65
+ }
66
+ }
67
}
68
}
src/test/WixToolsetTest.CoreIntegration/TestData/WixlibWithBinaries/data/alpha/foo.dll
+1
-1
@@ -1 +1 @@
1
-This is test.txt.
\ No newline at end of file
1
+This is alpha\foo.dll.
src/test/WixToolsetTest.CoreIntegration/TestData/WixlibWithBinaries/data/mips/foo.dll
+1
-1
@@ -1 +1 @@
1
-This is test.txt.
\ No newline at end of file
1
+This is mips\foo.dll.
src/test/WixToolsetTest.CoreIntegration/TestData/WixlibWithBinaries/data/powerpc/foo.dll
+1
-1
@@ -1 +1 @@
1
-This is test.txt.
\ No newline at end of file
1
+This is powerpc\foo.dll.
src/test/WixToolsetTest.CoreIntegration/WixlibFixture.cs
-30
@@ -88,36 +88,6 @@ namespace WixToolsetTest.CoreIntegration
88
}
89
}
90
91
- [Fact(Skip = "Test demonstrates failure")]
92
- public void CantBuildWixlibWithBinariesFromMissingNamedBindPaths()
93
- {
94
- var folder = TestData.Get(@"TestData\WixlibWithBinaries");
95
-
96
- using (var fs = new DisposableFileSystem())
97
- {
98
- var baseFolder = fs.GetFolder();
99
- var intermediateFolder = Path.Combine(baseFolder, "obj");
100
- var wixlibPath = Path.Combine(intermediateFolder, @"test.wixlib");
101
-
102
- var result = WixRunner.Execute(new[]
103
- {
104
- "build",
105
- Path.Combine(folder, "PackageComponents.wxs"),
106
- "-bf",
107
- "-bindpath", Path.Combine(folder, "data"),
108
- // Use names that aren't excluded in default .gitignores.
109
- "-bindpath", $"AlphaBits={Path.Combine(folder, "data", "alpha")}",
110
- "-bindpath", $"PowerBits={Path.Combine(folder, "data", "powerpc")}",
111
- "-bindpath", $"{Path.Combine(folder, "data", "alpha")}",
112
- "-bindpath", $"{Path.Combine(folder, "data", "powerpc")}",
113
- "-intermediateFolder", intermediateFolder,
114
- "-o", wixlibPath,
115
- });
116
-
117
- Assert.InRange(result.ExitCode, 2, int.MaxValue);
118
- }
119
- }
120
-
91
[Fact]
92
public void CanBuildSingleFileUsingWixlib()
93
{