mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
File arguments added to `std.Build.Step.Run` with e.g. `addFileArg` are not necessarily passed as absolute paths. It used to be the case that they were as a consequence of an unnecessary path conversion done by the frontend, but this no longer happens, at least not always, so these tests were sometimes failing when run locally. Therefore, the standalone tests must handle cwd-relative CLI paths correctly.
18 lines
812 B
Zig
18 lines
812 B
Zig
const std = @import("std");
|
|
|
|
pub fn main() anyerror!void {
|
|
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
|
defer if (gpa.deinit() == .leak) @panic("found memory leaks");
|
|
const allocator = gpa.allocator();
|
|
|
|
var it = try std.process.argsWithAllocator(allocator);
|
|
defer it.deinit();
|
|
_ = it.next() orelse unreachable; // skip binary name
|
|
const exe_path = it.next() orelse unreachable;
|
|
const symlink_path = it.next() orelse unreachable;
|
|
|
|
// If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
|
|
const exe_rel_path = try std.fs.path.relative(allocator, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
|
|
defer allocator.free(exe_rel_path);
|
|
try std.fs.cwd().symLink(exe_rel_path, symlink_path, .{});
|
|
}
|