authorgravatar for aidenhaledev@gmail.comMrDmitry <aidenhaledev@gmail.com> 2024-06-08 00:21:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-08 15:18:56-04:00
log84d15808731978637a1093a96c385a92949dff0d
tree110912206cf25433a1e90dde6f9a43aeb4c213bb
parent0884a434117dee3458eea8890b2e47e432844ac3

Report error on missing values for addConfigHeader


9 files changed, 15 insertions(+), 36 deletions(-)

lib/std/Build/Step/ConfigHeader.zig+15-12
...@@ -568,7 +568,7 @@ fn expand_variables_cmake(...@@ -568,7 +568,7 @@ fn expand_variables_cmake(
568 }568 }
569569
570 const key = contents[curr + 1 .. close_pos];570 const key = contents[curr + 1 .. close_pos];
571 const value = values.get(key) orelse .undef;571 const value = values.get(key) orelse return error.MissingValue;
572 const missing = contents[source_offset..curr];572 const missing = contents[source_offset..curr];
573 try result.appendSlice(missing);573 try result.appendSlice(missing);
574 switch (value) {574 switch (value) {
...@@ -623,7 +623,10 @@ fn expand_variables_cmake(...@@ -623,7 +623,10 @@ fn expand_variables_cmake(
623623
624 const key_start = open_pos.target + open_var.len;624 const key_start = open_pos.target + open_var.len;
625 const key = result.items[key_start..];625 const key = result.items[key_start..];
626 const value = values.get(key) orelse .undef;626 if (key.len == 0) {
627 return error.MissingKey;
628 }
629 const value = values.get(key) orelse return error.MissingValue;
627 result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);630 result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);
628 switch (value) {631 switch (value) {
629 .undef, .defined => {},632 .undef, .defined => {},
...@@ -693,8 +696,8 @@ test "expand_variables_cmake simple cases" {...@@ -693,8 +696,8 @@ test "expand_variables_cmake simple cases" {
693 // line with misc content is preserved696 // line with misc content is preserved
694 try testReplaceVariables(allocator, "no substitution", "no substitution", values);697 try testReplaceVariables(allocator, "no substitution", "no substitution", values);
695698
696 // empty ${} wrapper is removed699 // empty ${} wrapper leads to an error
697 try testReplaceVariables(allocator, "${}", "", values);700 try std.testing.expectError(error.MissingKey, testReplaceVariables(allocator, "${}", "", values));
698701
699 // empty @ sigils are preserved702 // empty @ sigils are preserved
700 try testReplaceVariables(allocator, "@", "@", values);703 try testReplaceVariables(allocator, "@", "@", values);
...@@ -757,9 +760,9 @@ test "expand_variables_cmake simple cases" {...@@ -757,9 +760,9 @@ test "expand_variables_cmake simple cases" {
757 try testReplaceVariables(allocator, "undef@", "undef@", values);760 try testReplaceVariables(allocator, "undef@", "undef@", values);
758 try testReplaceVariables(allocator, "undef}", "undef}", values);761 try testReplaceVariables(allocator, "undef}", "undef}", values);
759762
760 // unknown key is removed763 // unknown key leads to an error
761 try testReplaceVariables(allocator, "@bad@", "", values);764 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "@bad@", "", values));
762 try testReplaceVariables(allocator, "${bad}", "", values);765 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "${bad}", "", values));
763}766}
764767
765test "expand_variables_cmake edge cases" {768test "expand_variables_cmake edge cases" {
...@@ -804,17 +807,17 @@ test "expand_variables_cmake edge cases" {...@@ -804,17 +807,17 @@ test "expand_variables_cmake edge cases" {
804 try testReplaceVariables(allocator, "@dollar@{@string@}", "${text}", values);807 try testReplaceVariables(allocator, "@dollar@{@string@}", "${text}", values);
805808
806 // when expanded variables contain invalid characters, they prevent further expansion809 // when expanded variables contain invalid characters, they prevent further expansion
807 try testReplaceVariables(allocator, "${${string_var}}", "", values);810 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "${${string_var}}", "", values));
808 try testReplaceVariables(allocator, "${@string_var@}", "", values);811 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "${@string_var@}", "", values));
809812
810 // nested expanded variables are expanded from the inside out813 // nested expanded variables are expanded from the inside out
811 try testReplaceVariables(allocator, "${string${underscore}proxy}", "string", values);814 try testReplaceVariables(allocator, "${string${underscore}proxy}", "string", values);
812 try testReplaceVariables(allocator, "${string@underscore@proxy}", "string", values);815 try testReplaceVariables(allocator, "${string@underscore@proxy}", "string", values);
813816
814 // nested vars are only expanded when ${} is closed817 // nested vars are only expanded when ${} is closed
815 try testReplaceVariables(allocator, "@nest@underscore@proxy@", "underscore", values);818 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "@nest@underscore@proxy@", "", values));
816 try testReplaceVariables(allocator, "${nest${underscore}proxy}", "nest_underscore_proxy", values);819 try testReplaceVariables(allocator, "${nest${underscore}proxy}", "nest_underscore_proxy", values);
817 try testReplaceVariables(allocator, "@nest@@nest_underscore@underscore@proxy@@proxy@", "underscore", values);820 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "@nest@@nest_underscore@underscore@proxy@@proxy@", "", values));
818 try testReplaceVariables(allocator, "${nest${${nest_underscore${underscore}proxy}}proxy}", "nest_underscore_proxy", values);821 try testReplaceVariables(allocator, "${nest${${nest_underscore${underscore}proxy}}proxy}", "nest_underscore_proxy", values);
819822
820 // invalid characters lead to an error823 // invalid characters lead to an error
...@@ -840,5 +843,5 @@ test "expand_variables_cmake escaped characters" {...@@ -840,5 +843,5 @@ test "expand_variables_cmake escaped characters" {
840 try testReplaceVariables(allocator, "$\\{string}", "$\\{string}", values);843 try testReplaceVariables(allocator, "$\\{string}", "$\\{string}", values);
841844
842 // backslash is skipped when checking for invalid characters, yet it mangles the key845 // backslash is skipped when checking for invalid characters, yet it mangles the key
843 try testReplaceVariables(allocator, "${string\\}", "", values);846 try std.testing.expectError(error.MissingValue, testReplaceVariables(allocator, "${string\\}", "", values));
844}847}
test/standalone/cmakedefine/config.h.in-2
...@@ -94,8 +94,6 @@...@@ -94,8 +94,6 @@
94// test1094// test10
95// @noval@@stringval@@trueval@@zeroval@95// @noval@@stringval@@trueval@@zeroval@
9696
97// ${} substition
98
99// no substition97// no substition
100// ${noval}98// ${noval}
10199
test/standalone/cmakedefine/expected_config.h-2
...@@ -94,8 +94,6 @@...@@ -94,8 +94,6 @@
94// test1094// test10
95// test1095// test10
9696
97// substition
98
99// no substition97// no substition
100// 98//
10199
test/standalone/cmakedefine/expected_sigil.h-1
...@@ -1,4 +1,3 @@...@@ -1,4 +1,3 @@
1#define VAR
2#define AT @1#define AT @
3#define ATAT @@2#define ATAT @@
4#define ATATAT @@@3#define ATATAT @@@
test/standalone/cmakedefine/expected_stack.h-4
...@@ -1,7 +1,3 @@...@@ -1,7 +1,3 @@
1#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY1#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY
2#define UNDERSCORE UNDERSCORE
32
4#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY3#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY
5#define UNDERSCORE UNDERSCORE
6
7#define (empty)
test/standalone/cmakedefine/expected_wrapper.h-5
...@@ -25,11 +25,6 @@...@@ -25,11 +25,6 @@
25#define @STRING@25#define @STRING@
26#define @STRING@26#define @STRING@
2727
28// becomes `empty`
29#define
30#define
31
32#define \@STRING_VAR\@28#define \@STRING_VAR\@
33#define \${STRING}29#define \${STRING}
34#define $\{STRING_VAR}30#define $\{STRING_VAR}
35#define
test/standalone/cmakedefine/sigil.h.in-1
...@@ -1,4 +1,3 @@...@@ -1,4 +1,3 @@
1#define VAR ${}
2#define AT @1#define AT @
3#define ATAT @@2#define ATAT @@
4#define ATATAT @@@3#define ATATAT @@@
test/standalone/cmakedefine/stack.h.in-4
...@@ -1,7 +1,3 @@...@@ -1,7 +1,3 @@
1#define NEST_UNDERSCORE_PROXY ${NEST${UNDERSCORE}PROXY}1#define NEST_UNDERSCORE_PROXY ${NEST${UNDERSCORE}PROXY}
2#define UNDERSCORE @NEST@UNDERSCORE@PROXY@
32
4#define NEST_UNDERSCORE_PROXY ${NEST${${NEST_UNDERSCORE${UNDERSCORE}PROXY}}PROXY}3#define NEST_UNDERSCORE_PROXY ${NEST${${NEST_UNDERSCORE${UNDERSCORE}PROXY}}PROXY}
5#define UNDERSCORE @NEST@@NEST_UNDERSCORE@UNDERSCORE@PROXY@@PROXY@
6
7#define (empty) ${NEST${${AT}UNDERSCORE${AT}}PROXY}
test/standalone/cmakedefine/wrapper.h.in-5
...@@ -25,11 +25,6 @@...@@ -25,11 +25,6 @@
25#define ${STRING_AT}25#define ${STRING_AT}
26#define @STRING_AT@26#define @STRING_AT@
2727
28// becomes `empty`
29#define ${${STRING_VAR}}
30#define ${@STRING_VAR@}
31
32#define \@STRING_VAR\@28#define \@STRING_VAR\@
33#define \${STRING_VAR}29#define \${STRING_VAR}
34#define $\{STRING_VAR}30#define $\{STRING_VAR}
35#define ${STRING_VAR\}