authorgravatar for jay@jayschwa.netJay Petacat <jay@jayschwa.net> 2019-09-11 00:25:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-24 00:20:29-04:00
log0bdc85181cbe1954dac7e96c5ab4b2fe209b9098
tree88fbcfba5153d69568478b9d0e411e9783edd4e9
parent663e665843627cead40258a74ffddf4574fbb816

Create user-specified `output-dir`

Fixes #2637

2 files changed, 17 insertions(+), 2 deletions(-)

src/codegen.cpp+7-2
......@@ -10238,8 +10238,13 @@ void codegen_build_and_link(CodeGen *g) {
1023810238 Error err;
1023910239 assert(g->out_type != OutTypeUnknown);
1024010240
10241 if (!g->enable_cache && g->output_dir == nullptr) {
10242 g->output_dir = buf_create_from_str(".");
10241 if (!g->enable_cache) {
10242 if (g->output_dir == nullptr) {
10243 g->output_dir = buf_create_from_str(".");
10244 } else if ((err = os_make_path(g->output_dir))) {
10245 fprintf(stderr, "Unable to create output directory: %s\n", err_str(err));
10246 exit(1);
10247 }
1024310248 }
1024410249
1024510250 g->have_dynamic_link = detect_dynamic_link(g);
test/cli.zig+10
......@@ -34,6 +34,7 @@ pub fn main() !void {
3434 testZigInitLib,
3535 testZigInitExe,
3636 testGodboltApi,
37 testMissingOutputPath,
3738 };
3839 for (test_fns) |testFn| {
3940 try fs.deleteTree(a, dir_path);
......@@ -129,3 +130,12 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
129130 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
130131 testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
131132}
133
134fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
135 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });
136 const output_path = try fs.path.join(a, [_][]const u8{ "does", "not", "exist" });
137 const source_path = try fs.path.join(a, [_][]const u8{ "src", "main.zig" });
138 _ = try exec(dir_path, [_][]const u8{
139 zig_exe, "build-exe", source_path, "--output-dir", output_path
140 });
141}