Skip to content

Commit

Permalink
tar: remove output
Browse files Browse the repository at this point in the history
Replaced with writer.
  • Loading branch information
ianic committed Apr 12, 2024
1 parent 7ac8d0a commit 34607df
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 339 deletions.
2 changes: 1 addition & 1 deletion lib/compiler/std-docs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
// Since this command is JIT compiled, the builtin module available in
// this source file corresponds to the user's host system.
const builtin_zig = @embedFile("builtin");
archiver.prefix = "builtin";
var stream = std.io.fixedBufferStream(builtin_zig);
archiver.prefix = "builtin";
try archiver.addFile("builtin.zig", builtin_zig.len, stream.reader(), .{});
}

Expand Down
1 change: 0 additions & 1 deletion lib/std/tar.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const std = @import("std");
const assert = std.debug.assert;
const testing = std.testing;

pub const output = @import("tar/output.zig");
pub const writer = @import("tar/writer.zig").writer;

/// Provide this to receive detailed error messages.
Expand Down
232 changes: 0 additions & 232 deletions lib/std/tar/output.zig

This file was deleted.

104 changes: 0 additions & 104 deletions lib/std/tar/writer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -520,107 +520,3 @@ pub fn main() !void {
}
try cmp.finish();
}

test "sourcesTar" {
const gpa = testing.allocator;
var lib_dir = try std.fs.cwd().openDir("/home/ianic/Code/zig/lib", .{});
var out_dir = try std.fs.cwd().openDir("/home/ianic/Code/tmp", .{});

// previous version
{
var out_file = try out_dir.createFile("sources.tar", .{});
defer out_file.close();
var w = out_file.writer();

var std_dir = try lib_dir.openDir("std", .{ .iterate = true });
defer std_dir.close();

var walker = try std_dir.walk(gpa);
defer walker.deinit();

while (try walker.next()) |entry| {
switch (entry.kind) {
.file => {
if (!std.mem.endsWith(u8, entry.basename, ".zig"))
continue;
if (std.mem.endsWith(u8, entry.basename, "test.zig"))
continue;
},
else => continue,
}

var file = try std_dir.openFile(entry.path, .{});
defer file.close();

const stat = try file.stat();
const padding = p: {
const remainder = stat.size % 512;
break :p if (remainder > 0) 512 - remainder else 0;
};

var file_header = std.tar.output.Header.init();
file_header.typeflag = .regular;
try file_header.setPath("std", entry.path);
try file_header.setSize(stat.size);
try file_header.updateChecksum();
try w.writeAll(std.mem.asBytes(&file_header));
try w.any().writeFile(file);
try w.writeByteNTimes(0, padding);
}

{
// Since this command is JIT compiled, the builtin module available in
// this source file corresponds to the user's host system.
const builtin_zig = @embedFile("builtin");

var file_header = std.tar.output.Header.init();
file_header.typeflag = .regular;
try file_header.setPath("builtin", "builtin.zig");
try file_header.setSize(builtin_zig.len);
try file_header.updateChecksum();
try w.writeAll(std.mem.asBytes(&file_header));
try w.writeAll(builtin_zig);
const padding = p: {
const remainder = builtin_zig.len % 512;
break :p if (remainder > 0) 512 - remainder else 0;
};
try w.writeByteNTimes(0, padding);
}
}

// this version
{
var out_file = try out_dir.createFile("sources_new.tar", .{});
defer out_file.close();
var w = writer(out_file.writer());
try w.setRoot("std");

var std_dir = try lib_dir.openDir("std", .{ .iterate = true });
defer std_dir.close();

var walker = try std_dir.walk(gpa);
defer walker.deinit();

while (try walker.next()) |entry| {
switch (entry.kind) {
.file => {
if (!std.mem.endsWith(u8, entry.basename, ".zig"))
continue;
if (std.mem.endsWith(u8, entry.basename, "test.zig"))
continue;
},
else => continue,
}
try w.addEntry(entry);
}

{
w.prefix = "builtin";
// Since this command is JIT compiled, the builtin module available in
// this source file corresponds to the user's host system.
const builtin_zig = @embedFile("builtin");
var stm = std.io.fixedBufferStream(builtin_zig);
try w.addFile("builtin.zig", builtin_zig.len, stm.reader(), .{});
}
}
}
2 changes: 1 addition & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3762,6 +3762,7 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.
defer walker.deinit();

var archiver = std.tar.writer(tar_file.writer());
archiver.prefix = module.fully_qualified_name;

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

0 comments on commit 34607df

Please sign in to comment.