Skip to content

Commit 34607df

Browse files
committed
tar: remove output
Replaced with writer.
1 parent 7ac8d0a commit 34607df

File tree

5 files changed

+2
-339
lines changed

5 files changed

+2
-339
lines changed

lib/compiler/std-docs.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
207207
// Since this command is JIT compiled, the builtin module available in
208208
// this source file corresponds to the user's host system.
209209
const builtin_zig = @embedFile("builtin");
210-
archiver.prefix = "builtin";
211210
var stream = std.io.fixedBufferStream(builtin_zig);
211+
archiver.prefix = "builtin";
212212
try archiver.addFile("builtin.zig", builtin_zig.len, stream.reader(), .{});
213213
}
214214

lib/std/tar.zig

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const std = @import("std");
1919
const assert = std.debug.assert;
2020
const testing = std.testing;
2121

22-
pub const output = @import("tar/output.zig");
2322
pub const writer = @import("tar/writer.zig").writer;
2423

2524
/// Provide this to receive detailed error messages.

lib/std/tar/output.zig

-232
This file was deleted.

lib/std/tar/writer.zig

-104
Original file line numberDiff line numberDiff line change
@@ -520,107 +520,3 @@ pub fn main() !void {
520520
}
521521
try cmp.finish();
522522
}
523-
524-
test "sourcesTar" {
525-
const gpa = testing.allocator;
526-
var lib_dir = try std.fs.cwd().openDir("/home/ianic/Code/zig/lib", .{});
527-
var out_dir = try std.fs.cwd().openDir("/home/ianic/Code/tmp", .{});
528-
529-
// previous version
530-
{
531-
var out_file = try out_dir.createFile("sources.tar", .{});
532-
defer out_file.close();
533-
var w = out_file.writer();
534-
535-
var std_dir = try lib_dir.openDir("std", .{ .iterate = true });
536-
defer std_dir.close();
537-
538-
var walker = try std_dir.walk(gpa);
539-
defer walker.deinit();
540-
541-
while (try walker.next()) |entry| {
542-
switch (entry.kind) {
543-
.file => {
544-
if (!std.mem.endsWith(u8, entry.basename, ".zig"))
545-
continue;
546-
if (std.mem.endsWith(u8, entry.basename, "test.zig"))
547-
continue;
548-
},
549-
else => continue,
550-
}
551-
552-
var file = try std_dir.openFile(entry.path, .{});
553-
defer file.close();
554-
555-
const stat = try file.stat();
556-
const padding = p: {
557-
const remainder = stat.size % 512;
558-
break :p if (remainder > 0) 512 - remainder else 0;
559-
};
560-
561-
var file_header = std.tar.output.Header.init();
562-
file_header.typeflag = .regular;
563-
try file_header.setPath("std", entry.path);
564-
try file_header.setSize(stat.size);
565-
try file_header.updateChecksum();
566-
try w.writeAll(std.mem.asBytes(&file_header));
567-
try w.any().writeFile(file);
568-
try w.writeByteNTimes(0, padding);
569-
}
570-
571-
{
572-
// Since this command is JIT compiled, the builtin module available in
573-
// this source file corresponds to the user's host system.
574-
const builtin_zig = @embedFile("builtin");
575-
576-
var file_header = std.tar.output.Header.init();
577-
file_header.typeflag = .regular;
578-
try file_header.setPath("builtin", "builtin.zig");
579-
try file_header.setSize(builtin_zig.len);
580-
try file_header.updateChecksum();
581-
try w.writeAll(std.mem.asBytes(&file_header));
582-
try w.writeAll(builtin_zig);
583-
const padding = p: {
584-
const remainder = builtin_zig.len % 512;
585-
break :p if (remainder > 0) 512 - remainder else 0;
586-
};
587-
try w.writeByteNTimes(0, padding);
588-
}
589-
}
590-
591-
// this version
592-
{
593-
var out_file = try out_dir.createFile("sources_new.tar", .{});
594-
defer out_file.close();
595-
var w = writer(out_file.writer());
596-
try w.setRoot("std");
597-
598-
var std_dir = try lib_dir.openDir("std", .{ .iterate = true });
599-
defer std_dir.close();
600-
601-
var walker = try std_dir.walk(gpa);
602-
defer walker.deinit();
603-
604-
while (try walker.next()) |entry| {
605-
switch (entry.kind) {
606-
.file => {
607-
if (!std.mem.endsWith(u8, entry.basename, ".zig"))
608-
continue;
609-
if (std.mem.endsWith(u8, entry.basename, "test.zig"))
610-
continue;
611-
},
612-
else => continue,
613-
}
614-
try w.addEntry(entry);
615-
}
616-
617-
{
618-
w.prefix = "builtin";
619-
// Since this command is JIT compiled, the builtin module available in
620-
// this source file corresponds to the user's host system.
621-
const builtin_zig = @embedFile("builtin");
622-
var stm = std.io.fixedBufferStream(builtin_zig);
623-
try w.addFile("builtin.zig", builtin_zig.len, stm.reader(), .{});
624-
}
625-
}
626-
}

src/Compilation.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3762,6 +3762,7 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.
37623762
defer walker.deinit();
37633763

37643764
var archiver = std.tar.writer(tar_file.writer());
3765+
archiver.prefix = module.fully_qualified_name;
37653766

37663767
while (try walker.next()) |entry| {
37673768
switch (entry.kind) {
@@ -3772,7 +3773,6 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.
37723773
},
37733774
else => continue,
37743775
}
3775-
archiver.prefix = module.fully_qualified_name;
37763776
archiver.addEntry(entry) catch |err| {
37773777
return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive '{}{s}': {s}", .{
37783778
root, entry.path, @errorName(err),

0 commit comments

Comments
 (0)