zig build system: fix cleanup on error, report spawn error

This commit is contained in:
Andrew Kelley 2017-04-04 06:47:42 -04:00
parent 00efbfa054
commit 9c803af044
2 changed files with 7 additions and 6 deletions

View File

@ -150,9 +150,10 @@ pub const Builder = struct {
}
// TODO issue #301
var child = %return os.ChildProcess.spawn(self.zig_exe, zig_args.toSliceConst(), &env_map,
StdIo.Ignore, StdIo.Inherit, StdIo.Inherit, self.allocator);
const term = %return child.wait();
var child = os.ChildProcess.spawn(self.zig_exe, zig_args.toSliceConst(), &env_map,
StdIo.Ignore, StdIo.Inherit, StdIo.Inherit, self.allocator)
%% |err| debug.panic("Unable to spawn zig compiler: {}\n", @errorName(err));
const term = %%child.wait();
const exe_result = switch (term) {
Term.Clean => |code| {
if (code != 0) {

View File

@ -215,8 +215,8 @@ pub fn posixExecve(path: []const u8, argv: []const []const u8, env_map: &const B
const argv_buf = %return allocator.alloc(?&const u8, argv.len + 2);
mem.set(?&const u8, argv_buf, null);
defer {
for (argv_buf) |arg, i| {
const arg_buf = if (const ptr ?= arg) ptr[0...argv[i].len + 1] else break;
for (argv_buf) |arg| {
const arg_buf = if (const ptr ?= arg) ptr[0...cstr.len(ptr)] else break;
allocator.free(arg_buf);
}
allocator.free(argv_buf);
@ -242,7 +242,7 @@ pub fn posixExecve(path: []const u8, argv: []const []const u8, env_map: &const B
const envp_buf = %return allocator.alloc(?&const u8, envp_count + 1);
mem.set(?&const u8, envp_buf, null);
defer {
for (envp_buf) |env, i| {
for (envp_buf) |env| {
const env_buf = if (const ptr ?= env) ptr[0...cstr.len(ptr)] else break;
allocator.free(env_buf);
}