authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 01:05:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 01:05:42-05:00
log447a89cd4db37b3d184bc05a46bf330066e677ab
treef8637e63113ae977ccd0336c22786dbe954c0962
parentb21d44f26a9f2ee9b4d4248692aa5cc5fc78ade3
signaturelock-open Commit is signed but in an unrecognized format.

update self-hosted `zig targets` to print correct glibc availability


3 files changed, 64 insertions(+), 53 deletions(-)

lib/std/fs.zig+8-5
...@@ -663,11 +663,14 @@ pub const Dir = struct {...@@ -663,11 +663,14 @@ pub const Dir = struct {
663 return self.openFileW(&path_w, flags);663 return self.openFileW(&path_w, flags);
664 }664 }
665 const path_c = try os.toPosixPath(sub_path);665 const path_c = try os.toPosixPath(sub_path);
666 return self.openFileC(&path_c, flags);666 return self.openFileZ(&path_c, flags);
667 }667 }
668668
669 /// Deprecated; use `openFileZ`.
670 pub const openFileC = openFileZ;
671
669 /// Same as `openFile` but the path parameter is null-terminated.672 /// Same as `openFile` but the path parameter is null-terminated.
670 pub fn openFileC(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {673 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
671 if (builtin.os.tag == .windows) {674 if (builtin.os.tag == .windows) {
672 const path_w = try os.windows.cStrToPrefixedFileW(sub_path);675 const path_w = try os.windows.cStrToPrefixedFileW(sub_path);
673 return self.openFileW(&path_w, flags);676 return self.openFileW(&path_w, flags);
...@@ -753,9 +756,9 @@ pub const Dir = struct {...@@ -753,9 +756,9 @@ pub const Dir = struct {
753 return self.openFile(sub_path, .{});756 return self.openFile(sub_path, .{});
754 }757 }
755758
756 /// Deprecated; call `openFileC` directly.759 /// Deprecated; call `openFileZ` directly.
757 pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File {760 pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File {
758 return self.openFileC(sub_path, .{});761 return self.openFileZ(sub_path, .{});
759 }762 }
760763
761 /// Deprecated; call `openFileW` directly.764 /// Deprecated; call `openFileW` directly.
...@@ -1403,7 +1406,7 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O...@@ -1403,7 +1406,7 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
1403/// Same as `openFileAbsolute` but the path parameter is null-terminated.1406/// Same as `openFileAbsolute` but the path parameter is null-terminated.
1404pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {1407pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
1405 assert(path.isAbsoluteC(absolute_path_c));1408 assert(path.isAbsoluteC(absolute_path_c));
1406 return cwd().openFileC(absolute_path_c, flags);1409 return cwd().openFileZ(absolute_path_c, flags);
1407}1410}
14081411
1409/// Same as `openFileAbsolute` but the path parameter is WTF-16 encoded.1412/// Same as `openFileAbsolute` but the path parameter is WTF-16 encoded.
src-self-hosted/introspect.zig+21-2
...@@ -8,13 +8,32 @@ const warn = std.debug.warn;...@@ -8,13 +8,32 @@ const warn = std.debug.warn;
88
9/// Caller must free result9/// Caller must free result
10pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {10pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
11 const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib", "zig" });11 {
12 const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib", "zig" });
13 errdefer allocator.free(test_zig_dir);
14
15 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
16 defer allocator.free(test_index_file);
17
18 if (fs.cwd().openFile(test_index_file, .{})) |file| {
19 file.close();
20 return test_zig_dir;
21 } else |err| switch (err) {
22 error.FileNotFound => {
23 allocator.free(test_zig_dir);
24 },
25 else => |e| return e,
26 }
27 }
28
29 // Also try without "zig"
30 const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib" });
12 errdefer allocator.free(test_zig_dir);31 errdefer allocator.free(test_zig_dir);
1332
14 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });33 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
15 defer allocator.free(test_index_file);34 defer allocator.free(test_index_file);
1635
17 var file = try fs.cwd().openRead(test_index_file);36 const file = try fs.cwd().openFile(test_index_file, .{});
18 file.close();37 file.close();
1938
20 return test_zig_dir;39 return test_zig_dir;
src-self-hosted/print_targets.zig+35-46
...@@ -4,6 +4,9 @@ const io = std.io;...@@ -4,6 +4,9 @@ const io = std.io;
4const mem = std.mem;4const mem = std.mem;
5const Allocator = mem.Allocator;5const Allocator = mem.Allocator;
6const Target = std.Target;6const Target = std.Target;
7const assert = std.debug.assert;
8
9const introspect = @import("introspect.zig");
710
8// TODO this is hard-coded until self-hosted gains this information canonically11// TODO this is hard-coded until self-hosted gains this information canonically
9const available_libcs = [_][]const u8{12const available_libcs = [_][]const u8{
...@@ -55,57 +58,40 @@ const available_libcs = [_][]const u8{...@@ -55,57 +58,40 @@ const available_libcs = [_][]const u8{
55 "x86_64-windows-gnu",58 "x86_64-windows-gnu",
56};59};
5760
58// TODO this is hard-coded until self-hosted gains this information canonically
59const available_glibcs = [_][]const u8{
60 "2.0",
61 "2.1",
62 "2.1.1",
63 "2.1.2",
64 "2.1.3",
65 "2.2",
66 "2.2.1",
67 "2.2.2",
68 "2.2.3",
69 "2.2.4",
70 "2.2.5",
71 "2.2.6",
72 "2.3",
73 "2.3.2",
74 "2.3.3",
75 "2.3.4",
76 "2.4",
77 "2.5",
78 "2.6",
79 "2.7",
80 "2.8",
81 "2.9",
82 "2.10",
83 "2.11",
84 "2.12",
85 "2.13",
86 "2.14",
87 "2.15",
88 "2.16",
89 "2.17",
90 "2.18",
91 "2.19",
92 "2.22",
93 "2.23",
94 "2.24",
95 "2.25",
96 "2.26",
97 "2.27",
98 "2.28",
99 "2.29",
100 "2.30",
101};
102
103pub fn cmdTargets(61pub fn cmdTargets(
104 allocator: *Allocator,62 allocator: *Allocator,
105 args: []const []const u8,63 args: []const []const u8,
106 stdout: *io.OutStream(fs.File.WriteError),64 stdout: *io.OutStream(fs.File.WriteError),
107 native_target: Target,65 native_target: Target,
108) !void {66) !void {
67 const available_glibcs = blk: {
68 const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch |err| {
69 std.debug.warn("unable to find zig installation directory: {}\n", .{@errorName(err)});
70 std.process.exit(1);
71 };
72 defer allocator.free(zig_lib_dir);
73
74 var dir = try std.fs.cwd().openDirList(zig_lib_dir);
75 defer dir.close();
76
77 const vers_txt = try dir.readFileAlloc(allocator, "libc/glibc/vers.txt", 10 * 1024);
78 defer allocator.free(vers_txt);
79
80 var list = std.ArrayList(std.builtin.Version).init(allocator);
81 defer list.deinit();
82
83 var it = mem.tokenize(vers_txt, "\r\n");
84 while (it.next()) |line| {
85 const prefix = "GLIBC_";
86 assert(mem.startsWith(u8, line, prefix));
87 const adjusted_line = line[prefix.len..];
88 const ver = try std.builtin.Version.parse(adjusted_line);
89 try list.append(ver);
90 }
91 break :blk list.toOwnedSlice();
92 };
93 defer allocator.free(available_glibcs);
94
109 const BOS = io.BufferedOutStream(fs.File.WriteError);95 const BOS = io.BufferedOutStream(fs.File.WriteError);
110 var bos = BOS.init(stdout);96 var bos = BOS.init(stdout);
111 var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream);97 var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream);
...@@ -150,7 +136,10 @@ pub fn cmdTargets(...@@ -150,7 +136,10 @@ pub fn cmdTargets(
150 try jws.beginArray();136 try jws.beginArray();
151 for (available_glibcs) |glibc| {137 for (available_glibcs) |glibc| {
152 try jws.arrayElem();138 try jws.arrayElem();
153 try jws.emitString(glibc);139
140 const tmp = try std.fmt.allocPrint(allocator, "{}", .{glibc});
141 defer allocator.free(tmp);
142 try jws.emitString(tmp);
154 }143 }
155 try jws.endArray();144 try jws.endArray();
156145