2018-04-12 03:23:58 -07:00
|
|
|
// Introspection and determination of system libraries needed by zig.
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
const mem = std.mem;
|
|
|
|
const os = std.os;
|
|
|
|
|
|
|
|
const warn = std.debug.warn;
|
|
|
|
|
|
|
|
/// Caller must free result
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
|
2018-11-29 08:51:31 -08:00
|
|
|
const test_zig_dir = try os.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
|
2018-04-12 03:23:58 -07:00
|
|
|
errdefer allocator.free(test_zig_dir);
|
|
|
|
|
2018-11-29 08:51:31 -08:00
|
|
|
const test_index_file = try os.path.join(allocator, [][]const u8{ test_zig_dir, "std", "index.zig" });
|
2018-04-12 03:23:58 -07:00
|
|
|
defer allocator.free(test_index_file);
|
|
|
|
|
2018-08-21 13:07:28 -07:00
|
|
|
var file = try os.File.openRead(test_index_file);
|
2018-04-12 03:23:58 -07:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
return test_zig_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Caller must free result
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
|
2018-08-21 17:28:37 -07:00
|
|
|
const self_exe_path = try os.selfExeDirPathAlloc(allocator);
|
2018-04-12 03:23:58 -07:00
|
|
|
defer allocator.free(self_exe_path);
|
|
|
|
|
|
|
|
var cur_path: []const u8 = self_exe_path;
|
|
|
|
while (true) {
|
2018-06-14 13:15:32 -07:00
|
|
|
const test_dir = os.path.dirname(cur_path) orelse ".";
|
2018-04-12 03:23:58 -07:00
|
|
|
|
|
|
|
if (mem.eql(u8, test_dir, cur_path)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return testZigInstallPrefix(allocator, test_dir) catch |err| {
|
|
|
|
cur_path = test_dir;
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return error.FileNotFound;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
|
2018-04-12 08:00:11 -07:00
|
|
|
return findZigLibDir(allocator) catch |err| {
|
|
|
|
warn(
|
|
|
|
\\Unable to find zig lib directory: {}.
|
|
|
|
\\Reinstall Zig or use --zig-install-prefix.
|
|
|
|
\\
|
2018-05-26 15:16:39 -07:00
|
|
|
, @errorName(err));
|
2018-04-12 08:00:11 -07:00
|
|
|
|
|
|
|
return error.ZigLibDirNotFound;
|
|
|
|
};
|
2018-04-12 03:23:58 -07:00
|
|
|
}
|
2018-07-10 17:18:43 -07:00
|
|
|
|
|
|
|
/// Caller must free result
|
|
|
|
pub fn resolveZigCacheDir(allocator: *mem.Allocator) ![]u8 {
|
|
|
|
return std.mem.dupe(allocator, u8, "zig-cache");
|
|
|
|
}
|