authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-21 12:45:21-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-21 12:45:21-08:00
logac2930332104cf1d1f51edca922b502ef3bd3f89
tree06ffbc7c3921a3c6d14cb83fde246620b67075ae
parentbf7ebfa67af78da3ad40869cc61aecb594f9fc74
parente72f1d5ae70b78046c27d0b7fc12ee4b69380b2a
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #18634 from MrDmitry/bug/ConfigHeader_cmake_neighbors

std.Build.Step.ConfigHeader (cmake): fix offset calculation for multiple substitutions on a single line

3 files changed, 110 insertions(+), 6 deletions(-)

lib/std/Build/Step/ConfigHeader.zig+4-4
......@@ -537,7 +537,7 @@ fn replace_variables(
537537 switch (value) {
538538 .boolean => |b| {
539539 const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline });
540 last_index = start_index + 1;
540 last_index = prefix_index + 1;
541541
542542 allocator.free(content_buf);
543543 content_buf = buf;
......@@ -546,14 +546,14 @@ fn replace_variables(
546546 const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline });
547547 const isNegative = i < 0;
548548 const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1;
549 last_index = start_index + @intFromBool(isNegative) + digits + 1;
549 last_index = prefix_index + @intFromBool(isNegative) + digits;
550550
551551 allocator.free(content_buf);
552552 content_buf = buf;
553553 },
554554 .string, .ident => |x| {
555555 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline });
556 last_index = start_index + x.len + 1;
556 last_index = prefix_index + x.len;
557557
558558 allocator.free(content_buf);
559559 content_buf = buf;
......@@ -561,7 +561,7 @@ fn replace_variables(
561561
562562 else => {
563563 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline });
564 last_index = start_index + 1;
564 last_index = prefix_index;
565565
566566 allocator.free(content_buf);
567567 content_buf = buf;
test/standalone/cmakedefine/config.h.cmake+53-1
......@@ -49,12 +49,24 @@
4949// no substition
5050// @noval@
5151
52// no substition
53// @noval@@noval@
54
55// no substition
56// @noval@.@noval@
57
5258// 1
5359// @trueval@
5460
5561// 0
5662// @falseval@
5763
64// 10
65// @trueval@@falseval@
66
67// 0.1
68// @falseval@.@trueval@
69
5870// 0
5971// @zeroval@
6072
......@@ -64,21 +76,47 @@
6476// 10
6577// @tenval@
6678
79// 01
80// @zeroval@@oneval@
81
82// 0.10
83// @zeroval@.@tenval@
84
6785// test
6886// @stringval@
6987
88// testtest
89// @stringval@@stringval@
90
91// test.test
92// @stringval@.@stringval@
93
94// test10
95// @noval@@stringval@@trueval@@zeroval@
7096
7197// ${} substition
7298
73// removal
99// no substition
74100// ${noval}
75101
102// no substition
103// ${noval}${noval}
104
105// no substition
106// ${noval}.${noval}
107
76108// 1
77109// ${trueval}
78110
79111// 0
80112// ${falseval}
81113
114// 10
115// ${trueval}${falseval}
116
117// 0.1
118// ${falseval}.${trueval}
119
82120// 0
83121// ${zeroval}
84122
......@@ -88,6 +126,20 @@
88126// 10
89127// ${tenval}
90128
129// 01
130// ${zeroval}${oneval}
131
132// 0.10
133// ${zeroval}.${tenval}
134
91135// test
92136// ${stringval}
93137
138// testtest
139// ${stringval}${stringval}
140
141// test.test
142// ${stringval}.${stringval}
143
144// test10
145// ${noval}${stringval}${trueval}${zeroval}
test/standalone/cmakedefine/expected.h+53-1
......@@ -49,12 +49,24 @@
4949// no substition
5050//
5151
52// no substition
53//
54
55// no substition
56// .
57
5258// 1
5359// 1
5460
5561// 0
5662// 0
5763
64// 10
65// 10
66
67// 0.1
68// 0.1
69
5870// 0
5971// 0
6072
......@@ -64,21 +76,47 @@
6476// 10
6577// 10
6678
79// 01
80// 01
81
82// 0.10
83// 0.10
84
6785// test
6886// test
6987
88// testtest
89// testtest
90
91// test.test
92// test.test
93
94// test10
95// test10
7096
7197// substition
7298
73// removal
99// no substition
74100//
75101
102// no substition
103//
104
105// no substition
106// .
107
76108// 1
77109// 1
78110
79111// 0
80112// 0
81113
114// 10
115// 10
116
117// 0.1
118// 0.1
119
82120// 0
83121// 0
84122
......@@ -88,6 +126,20 @@
88126// 10
89127// 10
90128
129// 01
130// 01
131
132// 0.10
133// 0.10
134
91135// test
92136// test
93137
138// testtest
139// testtest
140
141// test.test
142// test.test
143
144// test10
145// test10