authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-02-10 02:23:31+11:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-02-11 20:50:57+02:00
logca0528209fc2a70fc52013b36439a093db0ac6e2
treee90601c72f09959f5f08035579bf2e1c2dd76c43
parentd976b4e4a56e4ac6b45a3d9ae9766e57bf04f82b

zig build: add -l, --list-steps option to build_runner.zig


1 files changed, 22 insertions(+), 8 deletions(-)

lib/build_runner.zig+22-8
......@@ -93,6 +93,8 @@ pub fn main() !void {
9393 std.debug.print("Expected argument after {s}\n\n", .{arg});
9494 return usageAndErr(builder, false, stderr_stream);
9595 };
96 } else if (mem.eql(u8, arg, "-l") or mem.eql(u8, arg, "--list-steps")) {
97 return steps(builder, false, stdout_stream);
9698 } else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
9799 dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
98100 std.debug.print("Expected argument after {s}\n\n", .{arg});
......@@ -232,20 +234,13 @@ pub fn main() !void {
232234 };
233235}
234236
235fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !void {
237fn steps(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !void {
236238 // run the build script to collect the options
237239 if (!already_ran_build) {
238240 builder.resolveInstallPrefix(null, .{});
239241 try builder.runBuild(root);
240242 }
241243
242 try out_stream.print(
243 \\Usage: {s} build [steps] [options]
244 \\
245 \\Steps:
246 \\
247 , .{builder.zig_exe});
248
249244 const allocator = builder.allocator;
250245 for (builder.top_level_steps.items) |top_level_step| {
251246 const name = if (&top_level_step.step == builder.default_step)
......@@ -254,6 +249,23 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
254249 top_level_step.step.name;
255250 try out_stream.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
256251 }
252}
253
254fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !void {
255 // run the build script to collect the options
256 if (!already_ran_build) {
257 builder.resolveInstallPrefix(null, .{});
258 try builder.runBuild(root);
259 }
260
261 try out_stream.print(
262 \\
263 \\Usage: {s} build [steps] [options]
264 \\
265 \\Steps:
266 \\
267 , .{builder.zig_exe});
268 try steps(builder, true, out_stream);
257269
258270 try out_stream.writeAll(
259271 \\
......@@ -284,6 +296,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
284296 \\ Windows programs on Linux hosts. (default: no)
285297 \\
286298 \\ -h, --help Print this help and exit
299 \\ -l, --list-steps Print available steps
287300 \\ --verbose Print commands before executing them
288301 \\ --color [auto|off|on] Enable or disable colored error messages
289302 \\ --prominent-compile-errors Output compile errors formatted for a human to read
......@@ -292,6 +305,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
292305 \\
293306 );
294307
308 const allocator = builder.allocator;
295309 if (builder.available_options_list.items.len == 0) {
296310 try out_stream.print(" (none)\n", .{});
297311 } else {