aboutsummaryrefslogtreecommitdiff
path: root/std/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-12 16:03:20 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-12 16:03:20 -0500
commit2b9302107fdd4adbbcfc2735afd7f2e4cd4c6769 (patch)
tree2066ea0666b9f3c3794e2eb40b84a9b31e96283b /std/build.zig
parentcd5fd653d7dd738d4c67b304e9cb17fb211f0163 (diff)
downloadzig-2b9302107fdd4adbbcfc2735afd7f2e4cd4c6769.tar.gz
zig-2b9302107fdd4adbbcfc2735afd7f2e4cd4c6769.zip
self-hosted: cleanup build looking for llvm-config
Diffstat (limited to 'std/build.zig')
-rw-r--r--std/build.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/std/build.zig b/std/build.zig
index 532eca1cc9..63d635de70 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -671,6 +671,63 @@ pub const Builder = struct {
};
}
}
+
+ pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
+ if (self.env_map.get("PATH")) |PATH| {
+ for (names) |name| {
+ if (os.path.isAbsolute(name)) {
+ return name;
+ }
+ var it = mem.split(PATH, []u8{os.path.delimiter});
+ while (it.next()) |path| {
+ const full_path = %return os.path.join(self.allocator, path, name);
+ if (os.path.real(self.allocator, full_path)) |real_path| {
+ return real_path;
+ } else |_| {
+ continue;
+ }
+ }
+ }
+ }
+ for (names) |name| {
+ if (os.path.isAbsolute(name)) {
+ return name;
+ }
+ for (paths) |path| {
+ const full_path = %return os.path.join(self.allocator, path, name);
+ if (os.path.real(self.allocator, full_path)) |real_path| {
+ return real_path;
+ } else |_| {
+ continue;
+ }
+ }
+ }
+ return error.FileNotFound;
+ }
+
+ pub fn exec(self: &Builder, argv: []const []const u8) -> []u8 {
+ const max_output_size = 100 * 1024;
+ const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) %% |err| {
+ std.debug.panic("Unable to spawn {}: {}", argv[0], @errorName(err));
+ };
+ switch (result.term) {
+ os.ChildProcess.Term.Exited => |code| {
+ if (code != 0) {
+ warn("The following command exited with error code {}:\n", code);
+ printCmd(null, argv);
+ warn("stderr:{}\n", result.stderr);
+ std.debug.panic("command failed");
+ }
+ return result.stdout;
+ },
+ else => {
+ warn("The following command terminated unexpectedly:\n");
+ printCmd(null, argv);
+ warn("stderr:{}\n", result.stderr);
+ std.debug.panic("command failed");
+ },
+ }
+ }
};
const Version = struct {