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:
Jan200101 2025-06-01 20:48:44 +02:00
parent 0386730777
commit 9d6750935e
No known key found for this signature in database
GPG key ID: 5B71B1D78B882E05
3 changed files with 14 additions and 6 deletions

View file

@ -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);

View file

@ -94,6 +94,9 @@
// test10
// @noval@@stringval@@trueval@@zeroval@
// empty key, removed
// ${}
// no substition
// ${noval}

View file

@ -94,6 +94,9 @@
// test10
// test10
// empty key, removed
//
// no substition
//