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(...@@ -537,7 +537,7 @@ fn replace_variables(
537 switch (value) {537 switch (value) {
538 .boolean => |b| {538 .boolean => |b| {
539 const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline });539 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
542 allocator.free(content_buf);542 allocator.free(content_buf);
543 content_buf = buf;543 content_buf = buf;
...@@ -546,14 +546,14 @@ fn replace_variables(...@@ -546,14 +546,14 @@ fn replace_variables(
546 const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline });546 const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline });
547 const isNegative = i < 0;547 const isNegative = i < 0;
548 const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1;548 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
551 allocator.free(content_buf);551 allocator.free(content_buf);
552 content_buf = buf;552 content_buf = buf;
553 },553 },
554 .string, .ident => |x| {554 .string, .ident => |x| {
555 const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline });555 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
558 allocator.free(content_buf);558 allocator.free(content_buf);
559 content_buf = buf;559 content_buf = buf;
...@@ -561,7 +561,7 @@ fn replace_variables(...@@ -561,7 +561,7 @@ fn replace_variables(
561561
562 else => {562 else => {
563 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline });563 const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline });
564 last_index = start_index + 1;564 last_index = prefix_index;
565565
566 allocator.free(content_buf);566 allocator.free(content_buf);
567 content_buf = buf;567 content_buf = buf;
test/standalone/cmakedefine/config.h.cmake+53-1
...@@ -49,12 +49,24 @@...@@ -49,12 +49,24 @@
49// no substition49// no substition
50// @noval@50// @noval@
5151
52// no substition
53// @noval@@noval@
54
55// no substition
56// @noval@.@noval@
57
52// 158// 1
53// @trueval@59// @trueval@
5460
55// 061// 0
56// @falseval@62// @falseval@
5763
64// 10
65// @trueval@@falseval@
66
67// 0.1
68// @falseval@.@trueval@
69
58// 070// 0
59// @zeroval@71// @zeroval@
6072
...@@ -64,21 +76,47 @@...@@ -64,21 +76,47 @@
64// 1076// 10
65// @tenval@77// @tenval@
6678
79// 01
80// @zeroval@@oneval@
81
82// 0.10
83// @zeroval@.@tenval@
84
67// test85// test
68// @stringval@86// @stringval@
6987
88// testtest
89// @stringval@@stringval@
90
91// test.test
92// @stringval@.@stringval@
93
94// test10
95// @noval@@stringval@@trueval@@zeroval@
7096
71// ${} substition97// ${} substition
7298
73// removal99// no substition
74// ${noval}100// ${noval}
75101
102// no substition
103// ${noval}${noval}
104
105// no substition
106// ${noval}.${noval}
107
76// 1108// 1
77// ${trueval}109// ${trueval}
78110
79// 0111// 0
80// ${falseval}112// ${falseval}
81113
114// 10
115// ${trueval}${falseval}
116
117// 0.1
118// ${falseval}.${trueval}
119
82// 0120// 0
83// ${zeroval}121// ${zeroval}
84122
...@@ -88,6 +126,20 @@...@@ -88,6 +126,20 @@
88// 10126// 10
89// ${tenval}127// ${tenval}
90128
129// 01
130// ${zeroval}${oneval}
131
132// 0.10
133// ${zeroval}.${tenval}
134
91// test135// test
92// ${stringval}136// ${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 @@...@@ -49,12 +49,24 @@
49// no substition49// no substition
50// 50//
5151
52// no substition
53//
54
55// no substition
56// .
57
52// 158// 1
53// 159// 1
5460
55// 061// 0
56// 062// 0
5763
64// 10
65// 10
66
67// 0.1
68// 0.1
69
58// 070// 0
59// 071// 0
6072
...@@ -64,21 +76,47 @@...@@ -64,21 +76,47 @@
64// 1076// 10
65// 1077// 10
6678
79// 01
80// 01
81
82// 0.10
83// 0.10
84
67// test85// test
68// test86// test
6987
88// testtest
89// testtest
90
91// test.test
92// test.test
93
94// test10
95// test10
7096
71// substition97// substition
7298
73// removal99// no substition
74// 100//
75101
102// no substition
103//
104
105// no substition
106// .
107
76// 1108// 1
77// 1109// 1
78110
79// 0111// 0
80// 0112// 0
81113
114// 10
115// 10
116
117// 0.1
118// 0.1
119
82// 0120// 0
83// 0121// 0
84122
...@@ -88,6 +126,20 @@...@@ -88,6 +126,20 @@
88// 10126// 10
89// 10127// 10
90128
129// 01
130// 01
131
132// 0.10
133// 0.10
134
91// test135// test
92// test136// test
93137
138// testtest
139// testtest
140
141// test.test
142// test.test
143
144// test10
145// test10