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 {...@@ -58,8 +58,7 @@ pub fn main() !void {
58 stderr = &stderr_file.outStream().stream;58 stderr = &stderr_file.outStream().stream;
5959
60 const args = try process.argsAlloc(allocator);60 const args = try process.argsAlloc(allocator);
61 // TODO I'm getting unreachable code here, which shouldn't happen61 defer process.argsFree(allocator, args);
62 //defer process.argsFree(allocator, args);
6362
64 if (args.len <= 1) {63 if (args.len <= 1) {
65 try stderr.write("expected command argument\n\n");64 try stderr.write("expected command argument\n\n");
...@@ -67,64 +66,33 @@ pub fn main() !void {...@@ -67,64 +66,33 @@ pub fn main() !void {
67 process.exit(1);66 process.exit(1);
68 }67 }
6968
70 const commands = [_]Command{69 const cmd = args[1];
71 Command{70 const cmd_args = args[2..];
72 .name = "build-exe",71 if (mem.eql(u8, cmd, "build-exe")) {
73 .exec = cmdBuildExe,72 return buildOutputType(allocator, cmd_args, .Exe);
74 },73 } else if (mem.eql(u8, cmd, "build-lib")) {
75 Command{74 return buildOutputType(allocator, cmd_args, .Lib);
76 .name = "build-lib",75 } else if (mem.eql(u8, cmd, "build-obj")) {
77 .exec = cmdBuildLib,76 return buildOutputType(allocator, cmd_args, .Obj);
78 },77 } else if (mem.eql(u8, cmd, "fmt")) {
79 Command{78 return cmdFmt(allocator, cmd_args);
80 .name = "build-obj",79 } else if (mem.eql(u8, cmd, "libc")) {
81 .exec = cmdBuildObj,80 return cmdLibC(allocator, cmd_args);
82 },81 } else if (mem.eql(u8, cmd, "targets")) {
83 Command{82 return cmdTargets(allocator, cmd_args);
84 .name = "fmt",83 } else if (mem.eql(u8, cmd, "version")) {
85 .exec = cmdFmt,84 return cmdVersion(allocator, cmd_args);
86 },85 } else if (mem.eql(u8, cmd, "zen")) {
87 Command{86 return cmdZen(allocator, cmd_args);
88 .name = "libc",87 } else if (mem.eql(u8, cmd, "help")) {
89 .exec = cmdLibC,88 return cmdHelp(allocator, cmd_args);
90 },89 } else if (mem.eql(u8, cmd, "internal")) {
91 Command{90 return cmdInternal(allocator, cmd_args);
92 .name = "targets",91 } else {
93 .exec = cmdTargets,92 try stderr.print("unknown command: {}\n\n", .{args[1]});
94 },93 try stderr.write(usage);
95 Command{94 process.exit(1);
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 }
122 }95 }
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);
128}96}
12997
130const usage_build_generic =98const usage_build_generic =
...@@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {...@@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
555 }523 }
556}524}
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
570pub const usage_fmt =526pub const usage_fmt =
571 \\usage: zig fmt [file]...527 \\usage: zig fmt [file]...
572 \\528 \\