setcap and sudo args
This commit is contained in:
parent
4946963af3
commit
fe4f09d546
20
build.zig
20
build.zig
@ -10,7 +10,8 @@ pub fn build(b: *std.Build) void {
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const sudo = b.option([]const u8, "sudo", "sudo command") orelse null;
|
||||
const setcap = b.option(bool, "setcap", "run setcap before executing the test binary") orelse false;
|
||||
const sudo = b.option([]const u8, "sudo", "sudo command for setcap command") orelse null;
|
||||
|
||||
// This declares intent for the executable to be installed into the
|
||||
// standard location when the user invokes the "install" step (the default
|
||||
@ -46,15 +47,20 @@ pub fn build(b: *std.Build) void {
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const set_cap = b.addSystemCommand(if (sudo) |cmd|
|
||||
const run_unit_tests = b.addRunArtifact(unit_tests);
|
||||
|
||||
if (setcap and sudo == null) {
|
||||
std.log.warn("non-null setcap and no sudo command probably won't work. Add sudo.", .{});
|
||||
}
|
||||
|
||||
if (setcap) {
|
||||
const set_cap_cmd = b.addSystemCommand(if (sudo) |cmd|
|
||||
&.{ cmd, "setcap", "cap_net_admin=+ep" }
|
||||
else
|
||||
&.{ "setcap", "cap_net_admin=+ep" });
|
||||
set_cap.addArtifactArg(unit_tests);
|
||||
|
||||
const run_unit_tests = b.addRunArtifact(unit_tests);
|
||||
|
||||
run_unit_tests.step.dependOn(&set_cap.step);
|
||||
set_cap_cmd.addArtifactArg(unit_tests);
|
||||
run_unit_tests.step.dependOn(&set_cap_cmd.step);
|
||||
}
|
||||
|
||||
// Similar to creating the run step earlier, this exposes a `test` step to
|
||||
// the `zig build --help` menu, providing a way for the user to request
|
||||
|
Loading…
Reference in New Issue
Block a user