authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 03:20:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 06:47:20-04:00
loge4ec2d10c67542589e10e1eaf569157284171159
treecec0f0c5d5d14601f6dd48251b856b5ab305bcd2
parent47336abae3992ef343bd9cb6099b89bad1dfb634

zig build system: implement custom command step


1 files changed, 13 insertions(+), 6 deletions(-)

std/build.zig+13-6
...@@ -397,6 +397,10 @@ pub const Builder = struct {...@@ -397,6 +397,10 @@ pub const Builder = struct {
397 }397 }
398398
399 fn spawnChild(self: &Builder, exe_path: []const u8, args: []const []const u8) {399 fn spawnChild(self: &Builder, exe_path: []const u8, args: []const []const u8) {
400 return self.spawnChildEnvMap(&self.env_map, exe_path, args);
401 }
402
403 fn spawnChildEnvMap(self: &Builder, env_map: &const BufMap, exe_path: []const u8, args: []const []const u8) {
400 if (self.verbose) {404 if (self.verbose) {
401 %%io.stderr.printf("{}", exe_path);405 %%io.stderr.printf("{}", exe_path);
402 for (args) |arg| {406 for (args) |arg| {
...@@ -405,7 +409,7 @@ pub const Builder = struct {...@@ -405,7 +409,7 @@ pub const Builder = struct {
405 %%io.stderr.printf("\n");409 %%io.stderr.printf("\n");
406 }410 }
407411
408 var child = os.ChildProcess.spawn(exe_path, args, &self.env_map,412 var child = os.ChildProcess.spawn(exe_path, args, env_map,
409 StdIo.Ignore, StdIo.Inherit, StdIo.Inherit, self.allocator)413 StdIo.Ignore, StdIo.Inherit, StdIo.Inherit, self.allocator)
410 %% |err| debug.panic("Unable to spawn {}: {}\n", exe_path, @errorName(err));414 %% |err| debug.panic("Unable to spawn {}: {}\n", exe_path, @errorName(err));
411415
...@@ -905,17 +909,19 @@ const CExecutable = struct {...@@ -905,17 +909,19 @@ const CExecutable = struct {
905909
906const CommandStep = struct {910const CommandStep = struct {
907 step: Step,911 step: Step,
908 path: []const u8,912 builder: &Builder,
913 exe_path: []const u8,
909 args: []const []const u8,914 args: []const []const u8,
910 cwd: []const u8,915 cwd: []const u8,
911 env_map: &const BufMap,916 env_map: &const BufMap,
912917
913 pub fn init(builder: &Builder, cwd: []const u8, env_map: &const BufMap,918 pub fn init(builder: &Builder, cwd: []const u8, env_map: &const BufMap,
914 path: []const u8, args: []const []const u8) -> CommandStep919 exe_path: []const u8, args: []const []const u8) -> CommandStep
915 {920 {
916 CommandStep {921 CommandStep {
917 .step = Step.init(path, builder.allocator, make),922 .builder = builder,
918 .path = path,923 .step = Step.init(exe_path, builder.allocator, make),
924 .exe_path = exe_path,
919 .args = args,925 .args = args,
920 .cwd = cwd,926 .cwd = cwd,
921 .env_map = env_map,927 .env_map = env_map,
...@@ -927,7 +933,8 @@ const CommandStep = struct {...@@ -927,7 +933,8 @@ const CommandStep = struct {
927 //const self = @fieldParentPtr(CExecutable, "step", step);933 //const self = @fieldParentPtr(CExecutable, "step", step);
928 const self = @ptrcast(&CommandStep, step);934 const self = @ptrcast(&CommandStep, step);
929935
930 %%io.stderr.printf("TODO: exec command\n");936 // TODO set cwd
937 self.builder.spawnChildEnvMap(self.env_map, self.exe_path, self.args);
931 }938 }
932};939};
933940