From 4dacca2d463524fbdcb1a916a1c328bf60e88478 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 14 Aug 2023 22:56:19 -0700 Subject: [PATCH] introduce verbosity --- build.zig | 4 +++- codegen/src/main.zig | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 627dfae..5174f0d 100644 --- a/build.zig +++ b/build.zig @@ -82,7 +82,7 @@ pub fn build(b: *Builder) !void { .root_source_file = .{ .path = "codegen/src/main.zig" }, // We need this generated for the host, not the real target // .target = target, - .optimize = .ReleaseSafe, + .optimize = if (b.verbose) .Debug else .ReleaseSafe, }); cg_exe.addModule("smithy", smithy_dep.module("smithy")); var cg_cmd = b.addRunArtifact(cg_exe); @@ -90,6 +90,8 @@ pub fn build(b: *Builder) !void { cg_cmd.addDirectoryArg(std.Build.FileSource.relative("codegen/models")); cg_cmd.addArg("--output"); cg_cmd.addDirectoryArg(std.Build.FileSource.relative("src/models")); + if (b.verbose) + cg_cmd.addArg("--verbose"); // TODO: this should use zig_exe from std.Build // codegen should store a hash in a comment diff --git a/codegen/src/main.zig b/codegen/src/main.zig index bc258d6..210c5db 100644 --- a/codegen/src/main.zig +++ b/codegen/src/main.zig @@ -3,6 +3,8 @@ const smithy = @import("smithy"); const snake = @import("snake.zig"); const json_zig = @embedFile("json.zig"); +var verbose = false; + pub fn main() anyerror!void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); @@ -20,7 +22,7 @@ pub fn main() anyerror!void { if (std.mem.eql(u8, "--help", arg) or std.mem.eql(u8, "-h", arg)) { - try stdout.print("usage: {s} [--models dir] [--output dir] [file...]\n\n", .{args[0]}); + try stdout.print("usage: {s} [--verbose] [--models dir] [--output dir] [file...]\n\n", .{args[0]}); try stdout.print(" --models specifies a directory with all model files (do not specify files if --models is used)\n", .{}); try stdout.print(" --output specifies an output directory, otherwise the current working directory will be used\n", .{}); std.process.exit(0); @@ -44,6 +46,11 @@ pub fn main() anyerror!void { skip_next = false; continue; } + if (std.mem.eql(u8, "--verbose", arg)) { + verbose = true; + continue; + } + if (std.mem.eql(u8, "--models", arg) or std.mem.eql(u8, "--output", arg)) { @@ -60,11 +67,7 @@ pub fn main() anyerror!void { defer cwd.close(); defer cwd.setAsCwd() catch unreachable; - try stdout.print("orig cwd: {any}\n", .{cwd}); try m.dir.setAsCwd(); - try stdout.print("cwd: {any}\n", .{m.dir}); - // TODO: this is throwing an error? - // _ = cwd; var mi = m.iterate(); while (try mi.next()) |e| { if ((e.kind == .file or e.kind == .sym_link) and @@ -96,7 +99,7 @@ fn processFile(file_name: []const u8, stdout: anytype, output_dir: std.fs.Dir, m _ = try writer.write("const std = @import(\"std\");\n"); _ = try writer.write("const serializeMap = @import(\"json.zig\").serializeMap;\n"); _ = try writer.write("const smithy = @import(\"smithy\");\n\n"); - std.log.info("Processing file: {s}", .{file_name}); + if (verbose) std.log.info("Processing file: {s}", .{file_name}); const service_names = generateServicesForFilePath(allocator, ";", file_name, writer) catch |err| { std.log.err("Error processing file: {s}", .{file_name}); return err;