Commit 42ca357604

Jan200101 <sentrycraft123@gmail.com>
2023-06-26 08:23:05
std.Build: omit newline from last line
1 parent d5ebe3e
Changed files (1)
lib
std
Build
lib/std/Build/Step/ConfigHeader.zig
@@ -303,10 +303,7 @@ fn render_cmake(
     var line_index: u32 = 0;
     var line_it = std.mem.splitScalar(u8, contents, '\n');
     while (line_it.next()) |raw_line| : (line_index += 1) {
-        // if we reached the end of the buffer there is nothing worth doing anymore
-        if (line_it.index == line_it.buffer.len) {
-            continue;
-        }
+        const last_line = line_it.index == line_it.buffer.len;
 
         const first_pass = replace_variables(allocator, raw_line, values, "@", "@") catch @panic("Failed to substitute");
         const line = replace_variables(allocator, first_pass, values, "${", "}") catch @panic("Failed to substitute");
@@ -316,7 +313,9 @@ fn render_cmake(
 
         if (!std.mem.startsWith(u8, line, "#")) {
             try output.appendSlice(line);
-            try output.appendSlice("\n");
+            if (!last_line) {
+                try output.appendSlice("\n");
+            }
             continue;
         }
         var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
@@ -325,7 +324,9 @@ fn render_cmake(
             !std.mem.eql(u8, cmakedefine, "cmakedefine01"))
         {
             try output.appendSlice(line);
-            try output.appendSlice("\n");
+            if (!last_line) {
+                try output.appendSlice("\n");
+            }
             continue;
         }