authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-07 12:30:16-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-07 12:30:16-05:00
log3fce8008cc1303cb3a8ed6c2c48cbebc81dadaa8
tree4695f875212d2e9d9a4e2ab5444055c0383af4d7
parent7f4cce3345baab10ff51e898c3810ee58e6bd88b
signaturelock-open Commit is signed but in an unrecognized format.

skip self-hosted for now as we work towards async I/O

1. behavior tests with --test-evented-io 2. std lib tests with --test-evented-io 3. fuzz test evented I/O a bit, make it robust 4. make sure it works on all platforms (kqueue, Windows IOCP, epoll/other) 5. restart efforts on self-hosted

5 files changed, 20 insertions(+), 18 deletions(-)

build.zig+3-4
...@@ -72,14 +72,13 @@ pub fn build(b: *Builder) !void {...@@ -72,14 +72,13 @@ pub fn build(b: *Builder) !void {
72 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;72 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
73 const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;73 const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
74 const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;74 const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
75 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;75 const skip_self_hosted = (b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false) or true; // TODO evented I/O good enough that this passes everywhere
76 if (!skip_self_hosted and builtin.os == .linux) {76 if (!skip_self_hosted) {
77 // TODO evented I/O other OS's
78 test_step.dependOn(&exe.step);77 test_step.dependOn(&exe.step);
79 }78 }
8079
81 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;80 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
82 if (!only_install_lib_files) {81 if (!only_install_lib_files and !skip_self_hosted) {
83 b.default_step.dependOn(&exe.step);82 b.default_step.dependOn(&exe.step);
84 exe.install();83 exe.install();
85 }84 }
lib/std/fs/watch.zig+3
...@@ -11,6 +11,9 @@ const fd_t = os.fd_t;...@@ -11,6 +11,9 @@ const fd_t = os.fd_t;
11const File = std.fs.File;11const File = std.fs.File;
12const Allocator = mem.Allocator;12const Allocator = mem.Allocator;
1313
14const global_event_loop = Loop.instance orelse
15 @compileError("std.fs.Watch currently only works with event-based I/O");
16
14const WatchEventId = enum {17const WatchEventId = enum {
15 CloseWrite,18 CloseWrite,
16 Delete,19 Delete,
src-self-hosted/compilation.zig+12-12
...@@ -29,7 +29,7 @@ const Package = @import("package.zig").Package;...@@ -29,7 +29,7 @@ const Package = @import("package.zig").Package;
29const link = @import("link.zig").link;29const link = @import("link.zig").link;
30const LibCInstallation = @import("libc_installation.zig").LibCInstallation;30const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
31const CInt = @import("c_int.zig").CInt;31const CInt = @import("c_int.zig").CInt;
32const fs = event.fs;32const fs = std.fs;
33const util = @import("util.zig");33const util = @import("util.zig");
3434
35const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB35const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB
...@@ -442,7 +442,7 @@ pub const Compilation = struct {...@@ -442,7 +442,7 @@ pub const Compilation = struct {
442 comp.name = try Buffer.init(comp.arena(), name);442 comp.name = try Buffer.init(comp.arena(), name);
443 comp.llvm_triple = try util.getTriple(comp.arena(), target);443 comp.llvm_triple = try util.getTriple(comp.arena(), target);
444 comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);444 comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);
445 comp.zig_std_dir = try std.fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });445 comp.zig_std_dir = try fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });
446446
447 const opt_level = switch (build_mode) {447 const opt_level = switch (build_mode) {
448 .Debug => llvm.CodeGenLevelNone,448 .Debug => llvm.CodeGenLevelNone,
...@@ -488,8 +488,8 @@ pub const Compilation = struct {...@@ -488,8 +488,8 @@ pub const Compilation = struct {
488 defer comp.events.deinit();488 defer comp.events.deinit();
489489
490 if (root_src_path) |root_src| {490 if (root_src_path) |root_src| {
491 const dirname = std.fs.path.dirname(root_src) orelse ".";491 const dirname = fs.path.dirname(root_src) orelse ".";
492 const basename = std.fs.path.basename(root_src);492 const basename = fs.path.basename(root_src);
493493
494 comp.root_package = try Package.create(comp.arena(), dirname, basename);494 comp.root_package = try Package.create(comp.arena(), dirname, basename);
495 comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");495 comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");
...@@ -521,7 +521,7 @@ pub const Compilation = struct {...@@ -521,7 +521,7 @@ pub const Compilation = struct {
521 if (comp.tmp_dir.getOrNull()) |tmp_dir_result|521 if (comp.tmp_dir.getOrNull()) |tmp_dir_result|
522 if (tmp_dir_result.*) |tmp_dir| {522 if (tmp_dir_result.*) |tmp_dir| {
523 // TODO evented I/O?523 // TODO evented I/O?
524 std.fs.deleteTree(tmp_dir) catch {};524 fs.deleteTree(tmp_dir) catch {};
525 } else |_| {};525 } else |_| {};
526 }526 }
527527
...@@ -797,7 +797,7 @@ pub const Compilation = struct {...@@ -797,7 +797,7 @@ pub const Compilation = struct {
797797
798 async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) BuildError!void {798 async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) BuildError!void {
799 const tree_scope = blk: {799 const tree_scope = blk: {
800 const source_code = fs.readFile(800 const source_code = fs.cwd().readFileAlloc(
801 self.gpa(),801 self.gpa(),
802 root_scope.realpath,802 root_scope.realpath,
803 max_src_size,803 max_src_size,
...@@ -935,8 +935,8 @@ pub const Compilation = struct {...@@ -935,8 +935,8 @@ pub const Compilation = struct {
935 fn initialCompile(self: *Compilation) !void {935 fn initialCompile(self: *Compilation) !void {
936 if (self.root_src_path) |root_src_path| {936 if (self.root_src_path) |root_src_path| {
937 const root_scope = blk: {937 const root_scope = blk: {
938 // TODO async/await std.fs.realpath938 // TODO async/await fs.realpath
939 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {939 const root_src_real_path = fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
940 try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});940 try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
941 return;941 return;
942 };942 };
...@@ -1157,7 +1157,7 @@ pub const Compilation = struct {...@@ -1157,7 +1157,7 @@ pub const Compilation = struct {
1157 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });1157 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
1158 defer self.gpa().free(file_name);1158 defer self.gpa().free(file_name);
11591159
1160 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });1160 const full_path = try fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
1161 errdefer self.gpa().free(full_path);1161 errdefer self.gpa().free(full_path);
11621162
1163 return Buffer.fromOwnedSlice(self.gpa(), full_path);1163 return Buffer.fromOwnedSlice(self.gpa(), full_path);
...@@ -1178,8 +1178,8 @@ pub const Compilation = struct {...@@ -1178,8 +1178,8 @@ pub const Compilation = struct {
1178 const zig_dir_path = try getZigDir(self.gpa());1178 const zig_dir_path = try getZigDir(self.gpa());
1179 defer self.gpa().free(zig_dir_path);1179 defer self.gpa().free(zig_dir_path);
11801180
1181 const tmp_dir = try std.fs.path.join(self.arena(), &[_][]const u8{ zig_dir_path, comp_dir_name[0..] });1181 const tmp_dir = try fs.path.join(self.arena(), &[_][]const u8{ zig_dir_path, comp_dir_name[0..] });
1182 try std.fs.makePath(self.gpa(), tmp_dir);1182 try fs.makePath(self.gpa(), tmp_dir);
1183 return tmp_dir;1183 return tmp_dir;
1184 }1184 }
11851185
...@@ -1351,7 +1351,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) Compilation.Build...@@ -1351,7 +1351,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) Compilation.Build
1351}1351}
13521352
1353fn getZigDir(allocator: *mem.Allocator) ![]u8 {1353fn getZigDir(allocator: *mem.Allocator) ![]u8 {
1354 return std.fs.getAppDataDir(allocator, "zig");1354 return fs.getAppDataDir(allocator, "zig");
1355}1355}
13561356
1357fn analyzeFnType(1357fn analyzeFnType(
src-self-hosted/introspect.zig+1-1
...@@ -14,7 +14,7 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![...@@ -14,7 +14,7 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
14 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });14 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
15 defer allocator.free(test_index_file);15 defer allocator.free(test_index_file);
1616
17 var file = try fs.File.openRead(test_index_file);17 var file = try fs.cwd().openRead(test_index_file);
18 file.close();18 file.close();
1919
20 return test_zig_dir;20 return test_zig_dir;
src-self-hosted/main.zig+1-1
...@@ -724,7 +724,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -724,7 +724,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
724 if (try held.value.put(file_path, {})) |_| return;724 if (try held.value.put(file_path, {})) |_| return;
725 }725 }
726726
727 const source_code = event.fs.readFile(727 const source_code = fs.cwd().readFileAlloc(
728 fmt.allocator,728 fmt.allocator,
729 file_path,729 file_path,
730 max_src_size,730 max_src_size,