Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ pub fn build(b: *std.Build) !void {
{
const unzip = b.addExecutable(.{
.name = "unzip",
.root_source_file = b.path("unzip.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("unzip.zig"),
.target = target,
.optimize = optimize,
}),
});
const install = b.addInstallArtifact(unzip, .{});
unzip_step.dependOn(&install.step);
Expand All @@ -47,18 +49,22 @@ pub fn build(b: *std.Build) !void {
{
const zip = b.addExecutable(.{
.name = "zip",
.root_source_file = b.path("zip.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("zip.zig"),
.target = target,
.optimize = optimize,
}),
});
const install = b.addInstallArtifact(zip, .{});
zip_step.dependOn(&install.step);
}

const host_zip_exe = b.addExecutable(.{
.name = "zip",
.root_source_file = b.path("zip.zig"),
.target = b.graph.host,
.root_module = b.createModule(.{
.root_source_file = b.path("zip.zig"),
.target = b.graph.host,
}),
});

const ci_step = b.step("ci", "The build/test step to run on the CI");
Expand All @@ -72,15 +78,17 @@ pub fn build(b: *std.Build) !void {
fn addZigupExe(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const win32exelink_mod: ?*std.Build.Module = blk: {
if (target.result.os.tag == .windows) {
const exe = b.addExecutable(.{
.name = "win32exelink",
.root_source_file = b.path("win32exelink.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("win32exelink.zig"),
.target = target,
.optimize = optimize,
}),
});
break :blk b.createModule(.{
.root_source_file = exe.getEmittedBin(),
Expand All @@ -91,10 +99,12 @@ fn addZigupExe(

const exe = b.addExecutable(.{
.name = "zigup",
.root_source_file = b.path("zigup.zig"),
.target = target,
.optimize = optimize,
.strip = true,
.root_module = b.createModule(.{
.root_source_file = b.path("zigup.zig"),
.target = target,
.optimize = optimize,
.strip = true,
}),
});

if (target.result.os.tag == .windows) {
Expand Down Expand Up @@ -214,8 +224,10 @@ fn addTests(
) void {
const runtest_exe = b.addExecutable(.{
.name = "runtest",
.root_source_file = b.path("runtest.zig"),
.target = target,
.root_module = b.createModule(.{
.root_source_file = b.path("runtest.zig"),
.target = target,
}),
});
const tests: Tests = .{
.b = b,
Expand All @@ -235,6 +247,11 @@ fn addTests(
.argv = &.{"--help"},
.check = .{ .expect_stderr_match = "Usage" },
});
tests.addWithClean(.{
.name = "test-usage-help-command",
.argv = &.{"help"},
.check = .{ .expect_stderr_match = "Usage" },
});

tests.addWithClean(.{
.name = "test-fetch-index",
Expand Down
2 changes: 1 addition & 1 deletion fixdeletetree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn deleteTree(dir: std.fs.Dir, sub_path: []const u8) !void {
switch (err) {
error.FileBusy => {
std.log.warn("path '{s}' is busy (attempt {}), will retry", .{ sub_path, attempt });
std.time.sleep(std.time.ns_per_ms * 100); // sleep for 100 ms
std.Thread.sleep(std.time.ns_per_ms * 100); // sleep for 100 ms
},
else => |e| return e,
}
Expand Down
57 changes: 36 additions & 21 deletions runtest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn main() !void {
try std.fs.cwd().makeDir(appdata);
var file = try std.fs.cwd().createFile(install_dir_setting_path, .{});
defer file.close();
try file.writer().writeAll(install_dir);
try file.writeAll(install_dir);
} else {
var shared_sibling_state: SharedSiblingState = .{};
try copyEnvDir(
Expand All @@ -85,7 +85,7 @@ pub fn main() !void {
std.debug.assert(std.mem.eql(u8, install_dir_parsed.cache_o, input_install_dir_parsed.cache_o));
var file = try std.fs.cwd().createFile(install_dir_setting_path, .{});
defer file.close();
try file.writer().writeAll(install_dir);
try file.writeAll(install_dir);
},
.bad => {
// the install dir must have been customized, keep it
Expand Down Expand Up @@ -114,42 +114,42 @@ pub fn main() !void {
defer arena.free(fake_zig);
var file = try std.fs.cwd().createFile(fake_zig, .{});
defer file.close();
try file.writer().writeAll("a fake executable");
try file.writeAll("a fake executable");
} else {
std.log.err("unknown setup option '{s}'", .{setup_option});
std.process.exit(0xff);
}

var argv = std.ArrayList([]const u8).init(arena);
try argv.append(zigup_exe);
try argv.append("--appdata");
try argv.append(appdata);
try argv.append("--path-link");
try argv.append(path_link);
try argv.appendSlice(zigup_args);
var argv: std.ArrayList([]const u8) = .empty;
try argv.append(arena, zigup_exe);
try argv.append(arena, "--appdata");
try argv.append(arena, appdata);
try argv.append(arena, "--path-link");
try argv.append(arena, path_link);
try argv.appendSlice(arena, zigup_args);

if (true) {
try std.io.getStdErr().writer().writeAll("runtest exec: ");
try std.fs.File.stderr().deprecatedWriter().writeAll("runtest exec: ");
for (argv.items) |arg| {
try std.io.getStdErr().writer().print(" {s}", .{arg});
try std.fs.File.stderr().deprecatedWriter().print(" {s}", .{arg});
}
try std.io.getStdErr().writer().writeAll("\n");
try std.fs.File.stderr().deprecatedWriter().writeAll("\n");
}

var child = std.process.Child.init(argv.items, arena);

if (add_path) {
var env_map = try std.process.getEnvMap(arena);
// make sure the directory with our path-link comes first in PATH
var new_path = std.ArrayList(u8).init(arena);
var new_path: std.ArrayList(u8) = .empty;
if (maybe_second_bin_dir) |second_bin_dir| {
try new_path.appendSlice(second_bin_dir);
try new_path.append(std.fs.path.delimiter);
try new_path.appendSlice(arena, second_bin_dir);
try new_path.append(arena, std.fs.path.delimiter);
}
try new_path.appendSlice(out_env_dir);
try new_path.append(std.fs.path.delimiter);
try new_path.appendSlice(arena, out_env_dir);
try new_path.append(arena, std.fs.path.delimiter);
if (env_map.get("PATH")) |path| {
try new_path.appendSlice(path);
try new_path.appendSlice(arena, path);
}
try env_map.put("PATH", new_path.items);
child.env_map = &env_map;
Expand Down Expand Up @@ -293,14 +293,29 @@ fn copyEnvDir(
var out_target_buf: [std.fs.max_path_bytes]u8 = undefined;
const out_target = blk: {
if (std.fs.path.isAbsolute(in_target)) {
if (!std.mem.startsWith(u8, in_target, in_root)) std.debug.panic(
const maybe_absolute_in_root = if (std.fs.path.isAbsolute(in_root))
null
else
try std.fs.cwd().realpathAlloc(allocator, in_root);
defer if (maybe_absolute_in_root) |absolute_in_root| allocator.free(absolute_in_root);

var matched_in_root: ?[]const u8 = null;
if (std.mem.startsWith(u8, in_target, in_root)) {
matched_in_root = in_root;
} else if (maybe_absolute_in_root) |absolute_in_root| {
if (std.mem.startsWith(u8, in_target, absolute_in_root)) {
matched_in_root = absolute_in_root;
}
}

const prefix = matched_in_root orelse std.debug.panic(
"expected symlink target to start with '{s}' but got '{s}'",
.{ in_root, in_target },
);
break :blk try std.fmt.bufPrint(
&out_target_buf,
"{s}{s}",
.{ out_root, in_target[in_root.len..] },
.{ out_root, in_target[prefix.len..] },
);
}
break :blk in_target;
Expand Down
6 changes: 4 additions & 2 deletions unzip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
}

fn usage() noreturn {
std.io.getStdErr().writer().print("Usage: unzip [-d DIR] ZIP_FILE\n", .{}) catch |e| @panic(@errorName(e));
std.fs.File.stderr().deprecatedWriter().print("Usage: unzip [-d DIR] ZIP_FILE\n", .{}) catch |e| @panic(@errorName(e));
std.process.exit(1);
}

Expand Down Expand Up @@ -80,7 +80,9 @@ pub fn main() !void {
const zip_file = std.fs.cwd().openFile(zip_file_arg, .{}) catch |err|
fatal("open '{s}' failed: {s}", .{ zip_file_arg, @errorName(err) });
defer zip_file.close();
try std.zip.extract(out_dir, zip_file.seekableStream(), .{
var zip_reader_buffer: [4096]u8 = undefined;
var zip_reader = zip_file.reader(&zip_reader_buffer);
try std.zip.extract(out_dir, &zip_reader, .{
.allow_backslashes = true,
});
}
17 changes: 6 additions & 11 deletions win32exelink.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main() !u8 {

const args = try std.process.argsAlloc(global.arena);
if (args.len >= 2 and std.mem.eql(u8, args[1], "exelink")) {
try std.io.getStdOut().writer().writeAll(zig_exe);
try std.fs.File.stdout().deprecatedWriter().writeAll(zig_exe);
return 0;
}
args[0] = zig_exe;
Expand All @@ -59,7 +59,7 @@ pub fn main() !u8 {
};
}

fn consoleCtrlHandler(ctrl_type: u32) callconv(@import("std").os.windows.WINAPI) win32.BOOL {
fn consoleCtrlHandler(ctrl_type: u32) callconv(.winapi) win32.BOOL {
//
// NOTE: Do I need to synchronize this with the main thread?
//
Expand Down Expand Up @@ -94,16 +94,11 @@ const win32 = struct {
pub const CTRL_LOGOFF_EVENT = @as(u32, 5);
pub const CTRL_SHUTDOWN_EVENT = @as(u32, 6);
pub const GetLastError = std.os.windows.kernel32.GetLastError;
pub const PHANDLER_ROUTINE = switch (builtin.zig_backend) {
.stage1 => fn (
CtrlType: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL,
else => *const fn (
CtrlType: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL,
};
pub const PHANDLER_ROUTINE = *const fn (
CtrlType: u32,
) callconv(.winapi) BOOL;
pub extern "kernel32" fn SetConsoleCtrlHandler(
HandlerRoutine: ?PHANDLER_ROUTINE,
Add: BOOL,
) callconv(@import("std").os.windows.WINAPI) BOOL;
) callconv(.winapi) BOOL;
};
Loading
Loading