aboutsummaryrefslogtreecommitdiff
path: root/std/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-23 20:21:57 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-23 22:14:35 -0500
commite0a1466bd842f23983bb4a175bd16b005001a3f9 (patch)
tree2e1504f8e526a4b7783cd390a9e54f427045ca92 /std/build.zig
parent2031989d981f05dca9d2b0da0bfcfb67f0333dac (diff)
downloadzig-e0a1466bd842f23983bb4a175bd16b005001a3f9.tar.gz
zig-e0a1466bd842f23983bb4a175bd16b005001a3f9.zip
build: add --search-prefix option
Diffstat (limited to 'std/build.zig')
-rw-r--r--std/build.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/std/build.zig b/std/build.zig
index 0a23a77f80..3a2079db15 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -47,6 +47,7 @@ pub const Builder = struct {
env_map: BufMap,
top_level_steps: ArrayList(&TopLevelStep),
prefix: []const u8,
+ search_prefixes: ArrayList([]const u8),
lib_dir: []const u8,
exe_dir: []const u8,
installed_files: ArrayList([]const u8),
@@ -114,6 +115,7 @@ pub const Builder = struct {
.default_step = undefined,
.env_map = %%os.getEnvMap(allocator),
.prefix = undefined,
+ .search_prefixes = ArrayList([]const u8).init(allocator),
.lib_dir = undefined,
.exe_dir = undefined,
.installed_files = ArrayList([]const u8).init(allocator),
@@ -671,7 +673,22 @@ pub const Builder = struct {
}
pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
+ // TODO report error for ambiguous situations
const exe_extension = (Target { .Native = {}}).exeFileExt();
+ for (self.search_prefixes.toSliceConst()) |search_prefix| {
+ for (names) |name| {
+ if (os.path.isAbsolute(name)) {
+ return name;
+ }
+ const full_path = %return os.path.join(self.allocator, search_prefix, "bin",
+ self.fmt("{}{}", name, exe_extension));
+ if (os.path.real(self.allocator, full_path)) |real_path| {
+ return real_path;
+ } else |_| {
+ continue;
+ }
+ }
+ }
if (self.env_map.get("PATH")) |PATH| {
for (names) |name| {
if (os.path.isAbsolute(name)) {
@@ -727,6 +744,10 @@ pub const Builder = struct {
},
}
}
+
+ pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {
+ %%self.search_prefixes.append(search_prefix);
+ }
};
const Version = struct {