authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-08 23:55:22-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-09 15:31:49-05:00
logae324985a67b1258c226a799f2680906686670f2
tree94051f04c9493466eb50fcd97354129bcfa10419
parent5e345ff0ee9eb70d7f5f7167227f6a1e8903f428
signature Commit is signed but in an unrecognized format.

clean up a TODO in self-hosted


1 files changed, 27 insertions(+), 71 deletions(-)

src-self-hosted/main.zig+27-71
......@@ -58,8 +58,7 @@ pub fn main() !void {
5858 stderr = &stderr_file.outStream().stream;
5959
6060 const args = try process.argsAlloc(allocator);
61 // TODO I'm getting unreachable code here, which shouldn't happen
62 //defer process.argsFree(allocator, args);
61 defer process.argsFree(allocator, args);
6362
6463 if (args.len <= 1) {
6564 try stderr.write("expected command argument\n\n");
......@@ -67,64 +66,33 @@ pub fn main() !void {
6766 process.exit(1);
6867 }
6968
70 const commands = [_]Command{
71 Command{
72 .name = "build-exe",
73 .exec = cmdBuildExe,
74 },
75 Command{
76 .name = "build-lib",
77 .exec = cmdBuildLib,
78 },
79 Command{
80 .name = "build-obj",
81 .exec = cmdBuildObj,
82 },
83 Command{
84 .name = "fmt",
85 .exec = cmdFmt,
86 },
87 Command{
88 .name = "libc",
89 .exec = cmdLibC,
90 },
91 Command{
92 .name = "targets",
93 .exec = cmdTargets,
94 },
95 Command{
96 .name = "version",
97 .exec = cmdVersion,
98 },
99 Command{
100 .name = "zen",
101 .exec = cmdZen,
102 },
103
104 // undocumented commands
105 Command{
106 .name = "help",
107 .exec = cmdHelp,
108 },
109 Command{
110 .name = "internal",
111 .exec = cmdInternal,
112 },
113 };
114
115 inline for (commands) |command| {
116 if (mem.eql(u8, command.name, args[1])) {
117 var frame = try allocator.create(@Frame(command.exec));
118 defer allocator.destroy(frame);
119 frame.* = async command.exec(allocator, args[2..]);
120 return await frame;
121 }
69 const cmd = args[1];
70 const cmd_args = args[2..];
71 if (mem.eql(u8, cmd, "build-exe")) {
72 return buildOutputType(allocator, cmd_args, .Exe);
73 } else if (mem.eql(u8, cmd, "build-lib")) {
74 return buildOutputType(allocator, cmd_args, .Lib);
75 } else if (mem.eql(u8, cmd, "build-obj")) {
76 return buildOutputType(allocator, cmd_args, .Obj);
77 } else if (mem.eql(u8, cmd, "fmt")) {
78 return cmdFmt(allocator, cmd_args);
79 } else if (mem.eql(u8, cmd, "libc")) {
80 return cmdLibC(allocator, cmd_args);
81 } else if (mem.eql(u8, cmd, "targets")) {
82 return cmdTargets(allocator, cmd_args);
83 } else if (mem.eql(u8, cmd, "version")) {
84 return cmdVersion(allocator, cmd_args);
85 } else if (mem.eql(u8, cmd, "zen")) {
86 return cmdZen(allocator, cmd_args);
87 } else if (mem.eql(u8, cmd, "help")) {
88 return cmdHelp(allocator, cmd_args);
89 } else if (mem.eql(u8, cmd, "internal")) {
90 return cmdInternal(allocator, cmd_args);
91 } else {
92 try stderr.print("unknown command: {}\n\n", .{args[1]});
93 try stderr.write(usage);
94 process.exit(1);
12295 }
123
124 try stderr.print("unknown command: {}\n\n", .{args[1]});
125 try stderr.write(usage);
126 process.argsFree(allocator, args);
127 process.exit(1);
12896}
12997
13098const usage_build_generic =
......@@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
555523 }
556524}
557525
558fn cmdBuildExe(allocator: *Allocator, args: []const []const u8) !void {
559 return buildOutputType(allocator, args, Compilation.Kind.Exe);
560}
561
562fn cmdBuildLib(allocator: *Allocator, args: []const []const u8) !void {
563 return buildOutputType(allocator, args, Compilation.Kind.Lib);
564}
565
566fn cmdBuildObj(allocator: *Allocator, args: []const []const u8) !void {
567 return buildOutputType(allocator, args, Compilation.Kind.Obj);
568}
569
570526pub const usage_fmt =
571527 \\usage: zig fmt [file]...
572528 \\