From e4ec2d10c67542589e10e1eaf569157284171159 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 17 Apr 2017 03:20:56 -0400 Subject: [PATCH] zig build system: implement custom command step --- std/build.zig | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/std/build.zig b/std/build.zig index ae62efdf83..f4bf93c558 100644 --- a/std/build.zig +++ b/std/build.zig @@ -397,6 +397,10 @@ pub const Builder = struct { } fn spawnChild(self: &Builder, exe_path: []const u8, args: []const []const u8) { + return self.spawnChildEnvMap(&self.env_map, exe_path, args); + } + + fn spawnChildEnvMap(self: &Builder, env_map: &const BufMap, exe_path: []const u8, args: []const []const u8) { if (self.verbose) { %%io.stderr.printf("{}", exe_path); for (args) |arg| { @@ -405,7 +409,7 @@ pub const Builder = struct { %%io.stderr.printf("\n"); } - var child = os.ChildProcess.spawn(exe_path, args, &self.env_map, + var child = os.ChildProcess.spawn(exe_path, args, env_map, StdIo.Ignore, StdIo.Inherit, StdIo.Inherit, self.allocator) %% |err| debug.panic("Unable to spawn {}: {}\n", exe_path, @errorName(err)); @@ -905,17 +909,19 @@ const CExecutable = struct { const CommandStep = struct { step: Step, - path: []const u8, + builder: &Builder, + exe_path: []const u8, args: []const []const u8, cwd: []const u8, env_map: &const BufMap, pub fn init(builder: &Builder, cwd: []const u8, env_map: &const BufMap, - path: []const u8, args: []const []const u8) -> CommandStep + exe_path: []const u8, args: []const []const u8) -> CommandStep { CommandStep { - .step = Step.init(path, builder.allocator, make), - .path = path, + .builder = builder, + .step = Step.init(exe_path, builder.allocator, make), + .exe_path = exe_path, .args = args, .cwd = cwd, .env_map = env_map, @@ -927,7 +933,8 @@ const CommandStep = struct { //const self = @fieldParentPtr(CExecutable, "step", step); const self = @ptrcast(&CommandStep, step); - %%io.stderr.printf("TODO: exec command\n"); + // TODO set cwd + self.builder.spawnChildEnvMap(self.env_map, self.exe_path, self.args); } };