aboutsummaryrefslogtreecommitdiff
path: root/std/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-04-20 02:26:36 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-04-20 02:26:36 -0400
commit8654bc18104d64c7a7f9f80bdba75ed4e0c005fa (patch)
tree398f7b9d18988b61ad12db21aa72e21da3aec4d4 /std/build.zig
parent1ff73a8e69a09b3bc993cffb755cc2ca98c7040b (diff)
downloadzig-8654bc18104d64c7a7f9f80bdba75ed4e0c005fa.tar.gz
zig-8654bc18104d64c7a7f9f80bdba75ed4e0c005fa.zip
delete test_artifacts directory when tests complete
* add std.os.deleteTree * add std.os.deleteDir * add std.os.page_size * add std.os API for iterating over directories * refactor duplication in build.zig * update documentation on how to run tests
Diffstat (limited to 'std/build.zig')
-rw-r--r--std/build.zig36
1 files changed, 34 insertions, 2 deletions
diff --git a/std/build.zig b/std/build.zig
index 20fb4cad5c..d22d6b660a 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -195,6 +195,12 @@ pub const Builder = struct {
return log_step;
}
+ pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep {
+ const remove_dir_step = %%self.allocator.create(RemoveDirStep);
+ *remove_dir_step = RemoveDirStep.init(self, dir_path);
+ return remove_dir_step;
+ }
+
pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version {
Version {
.major = major,
@@ -1548,10 +1554,12 @@ pub const WriteFileStep = struct {
const full_path = self.builder.pathFromRoot(self.file_path);
const full_path_dir = %%os.path.dirname(self.builder.allocator, full_path);
os.makePath(self.builder.allocator, full_path_dir) %% |err| {
- debug.panic("unable to make path {}: {}\n", full_path_dir, @errorName(err));
+ %%io.stderr.printf("unable to make path {}: {}\n", full_path_dir, @errorName(err));
+ return err;
};
io.writeFile(full_path, self.data, self.builder.allocator) %% |err| {
- debug.panic("unable to write {}: {}\n", full_path, @errorName(err));
+ %%io.stderr.printf("unable to write {}: {}\n", full_path, @errorName(err));
+ return err;
};
}
};
@@ -1576,6 +1584,30 @@ pub const LogStep = struct {
}
};
+pub const RemoveDirStep = struct {
+ step: Step,
+ builder: &Builder,
+ dir_path: []const u8,
+
+ pub fn init(builder: &Builder, dir_path: []const u8) -> RemoveDirStep {
+ return RemoveDirStep {
+ .builder = builder,
+ .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
+ .dir_path = dir_path,
+ };
+ }
+
+ fn make(step: &Step) -> %void {
+ const self = @fieldParentPtr(RemoveDirStep, "step", step);
+
+ const full_path = self.builder.pathFromRoot(self.dir_path);
+ os.deleteTree(self.builder.allocator, full_path) %% |err| {
+ %%io.stderr.printf("Unable to remove {}: {}\n", full_path, @errorName(err));
+ return err;
+ };
+ }
+};
+
pub const Step = struct {
name: []const u8,
makeFn: fn(self: &Step) -> %void,