mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Build.Step.ConfigHeader: handle empty keys more permissively
${} is never used in a cmake config header but still needs to be
substituted
instead of erroring because of an empty key simply omit the value
This commit is contained in:
parent
0386730777
commit
9d6750935e
3 changed files with 14 additions and 6 deletions
|
|
@ -748,10 +748,12 @@ fn expand_variables_cmake(
|
|||
|
||||
const key_start = open_pos.target + open_var.len;
|
||||
const key = result.items[key_start..];
|
||||
if (key.len == 0) {
|
||||
return error.MissingKey;
|
||||
}
|
||||
const value = values.get(key) orelse return error.MissingValue;
|
||||
const value = values.get(key) orelse
|
||||
if (key.len == 0)
|
||||
.undef
|
||||
else
|
||||
return error.MissingValue;
|
||||
|
||||
result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);
|
||||
switch (value) {
|
||||
.undef, .defined => {},
|
||||
|
|
@ -952,8 +954,8 @@ test "expand_variables_cmake simple cases" {
|
|||
// line with misc content is preserved
|
||||
try testReplaceVariablesCMake(allocator, "no substitution", "no substitution", values);
|
||||
|
||||
// empty ${} wrapper leads to an error
|
||||
try std.testing.expectError(error.MissingKey, testReplaceVariablesCMake(allocator, "${}", "", values));
|
||||
// empty ${} wrapper is removed
|
||||
try testReplaceVariablesCMake(allocator, "${}", "", values);
|
||||
|
||||
// empty @ sigils are preserved
|
||||
try testReplaceVariablesCMake(allocator, "@", "@", values);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,9 @@
|
|||
// test10
|
||||
// @noval@@stringval@@trueval@@zeroval@
|
||||
|
||||
// empty key, removed
|
||||
// ${}
|
||||
|
||||
// no substition
|
||||
// ${noval}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,9 @@
|
|||
// test10
|
||||
// test10
|
||||
|
||||
// empty key, removed
|
||||
//
|
||||
|
||||
// no substition
|
||||
//
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue