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_start = open_pos.target + open_var.len;
|
||||||
const key = result.items[key_start..];
|
const key = result.items[key_start..];
|
||||||
if (key.len == 0) {
|
const value = values.get(key) orelse
|
||||||
return error.MissingKey;
|
if (key.len == 0)
|
||||||
}
|
.undef
|
||||||
const value = values.get(key) orelse return error.MissingValue;
|
else
|
||||||
|
return error.MissingValue;
|
||||||
|
|
||||||
result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);
|
result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);
|
||||||
switch (value) {
|
switch (value) {
|
||||||
.undef, .defined => {},
|
.undef, .defined => {},
|
||||||
|
|
@ -952,8 +954,8 @@ test "expand_variables_cmake simple cases" {
|
||||||
// line with misc content is preserved
|
// line with misc content is preserved
|
||||||
try testReplaceVariablesCMake(allocator, "no substitution", "no substitution", values);
|
try testReplaceVariablesCMake(allocator, "no substitution", "no substitution", values);
|
||||||
|
|
||||||
// empty ${} wrapper leads to an error
|
// empty ${} wrapper is removed
|
||||||
try std.testing.expectError(error.MissingKey, testReplaceVariablesCMake(allocator, "${}", "", values));
|
try testReplaceVariablesCMake(allocator, "${}", "", values);
|
||||||
|
|
||||||
// empty @ sigils are preserved
|
// empty @ sigils are preserved
|
||||||
try testReplaceVariablesCMake(allocator, "@", "@", values);
|
try testReplaceVariablesCMake(allocator, "@", "@", values);
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,9 @@
|
||||||
// test10
|
// test10
|
||||||
// @noval@@stringval@@trueval@@zeroval@
|
// @noval@@stringval@@trueval@@zeroval@
|
||||||
|
|
||||||
|
// empty key, removed
|
||||||
|
// ${}
|
||||||
|
|
||||||
// no substition
|
// no substition
|
||||||
// ${noval}
|
// ${noval}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,9 @@
|
||||||
// test10
|
// test10
|
||||||
// test10
|
// test10
|
||||||
|
|
||||||
|
// empty key, removed
|
||||||
|
//
|
||||||
|
|
||||||
// no substition
|
// no substition
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue