authorgravatar for michaldrozd@protonmail.chfardragon <michaldrozd@protonmail.ch> 2026-06-04 18:54:43+00:00
committergravatar for michaldrozd@protonmail.chfardragon <michaldrozd@protonmail.ch> 2026-06-05 14:59:18+02:00
log6043fbb2b7f263c0bab308f46f4ef393fec4a678
treedd1806e6079eac5d8393c4cfbb0d742b4aaa9f9a
parentbe18e17ce528f5e4a0cda5f694c8ad13a6b38662

Fix unexpected trailing newline for autconf_undef


3 files changed, 4 insertions(+), 5 deletions(-)

lib/compiler/Maker/Step/ConfigHeader.zig+4-2
...@@ -177,16 +177,18 @@ fn renderAutoConfUndef(...@@ -177,16 +177,18 @@ fn renderAutoConfUndef(
177 var line_index: u32 = 0;177 var line_index: u32 = 0;
178 var line_it = std.mem.splitScalar(u8, contents, '\n');178 var line_it = std.mem.splitScalar(u8, contents, '\n');
179 while (line_it.next()) |line| : (line_index += 1) {179 while (line_it.next()) |line| : (line_index += 1) {
180 const last_line = line_it.index == line_it.buffer.len;
181
180 if (!std.mem.startsWith(u8, line, "#")) {182 if (!std.mem.startsWith(u8, line, "#")) {
181 try w.writeAll(line);183 try w.writeAll(line);
182 try w.writeByte('\n');184 if (!last_line) try w.writeByte('\n');
183 continue;185 continue;
184 }186 }
185 var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");187 var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
186 const undef = it.next().?;188 const undef = it.next().?;
187 if (!std.mem.eql(u8, undef, "undef")) {189 if (!std.mem.eql(u8, undef, "undef")) {
188 try w.writeAll(line);190 try w.writeAll(line);
189 try w.writeByte('\n');191 if (!last_line) try w.writeByte('\n');
190 continue;192 continue;
191 }193 }
192 const name = it.next().?;194 const name = it.next().?;
test/standalone/config_header/autoconf_undef/config.h-2
...@@ -30,5 +30,3 @@ int foo();...@@ -30,5 +30,3 @@ int foo();
30// non-#undef # lines pass through unchanged30// non-#undef # lines pass through unchanged
31#define KEPT_DEFINE value31#define KEPT_DEFINE value
32#include <kept.h>32#include <kept.h>
33// TODO: unexpected newline is being added here
34
test/standalone/config_header/autoconf_undef/config.h.in-1
...@@ -29,4 +29,3 @@ int foo();...@@ -29,4 +29,3 @@ int foo();
29// non-#undef # lines pass through unchanged29// non-#undef # lines pass through unchanged
30#define KEPT_DEFINE value30#define KEPT_DEFINE value
31#include <kept.h>31#include <kept.h>
32// TODO: unexpected newline is being added here