Commit 3fce8008cc

Andrew Kelley <andrew@ziglang.org>
2020-02-07 18:30:16
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
1 parent 7f4cce3
Changed files (5)
lib/std/fs/watch.zig
@@ -11,6 +11,9 @@ const fd_t = os.fd_t;
 const File = std.fs.File;
 const Allocator = mem.Allocator;
 
+const global_event_loop = Loop.instance orelse
+    @compileError("std.fs.Watch currently only works with event-based I/O");
+
 const WatchEventId = enum {
     CloseWrite,
     Delete,
src-self-hosted/compilation.zig
@@ -29,7 +29,7 @@ const Package = @import("package.zig").Package;
 const link = @import("link.zig").link;
 const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
 const CInt = @import("c_int.zig").CInt;
-const fs = event.fs;
+const fs = std.fs;
 const util = @import("util.zig");
 
 const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB
@@ -442,7 +442,7 @@ pub const Compilation = struct {
         comp.name = try Buffer.init(comp.arena(), name);
         comp.llvm_triple = try util.getTriple(comp.arena(), target);
         comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);
-        comp.zig_std_dir = try std.fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });
+        comp.zig_std_dir = try fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });
 
         const opt_level = switch (build_mode) {
             .Debug => llvm.CodeGenLevelNone,
@@ -488,8 +488,8 @@ pub const Compilation = struct {
         defer comp.events.deinit();
 
         if (root_src_path) |root_src| {
-            const dirname = std.fs.path.dirname(root_src) orelse ".";
-            const basename = std.fs.path.basename(root_src);
+            const dirname = fs.path.dirname(root_src) orelse ".";
+            const basename = fs.path.basename(root_src);
 
             comp.root_package = try Package.create(comp.arena(), dirname, basename);
             comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");
@@ -521,7 +521,7 @@ pub const Compilation = struct {
         if (comp.tmp_dir.getOrNull()) |tmp_dir_result|
             if (tmp_dir_result.*) |tmp_dir| {
                 // TODO evented I/O?
-                std.fs.deleteTree(tmp_dir) catch {};
+                fs.deleteTree(tmp_dir) catch {};
             } else |_| {};
     }
 
@@ -797,7 +797,7 @@ pub const Compilation = struct {
 
     async fn rebuildFile(self: *Compilation, root_scope: *Scope.Root) BuildError!void {
         const tree_scope = blk: {
-            const source_code = fs.readFile(
+            const source_code = fs.cwd().readFileAlloc(
                 self.gpa(),
                 root_scope.realpath,
                 max_src_size,
@@ -935,8 +935,8 @@ pub const Compilation = struct {
     fn initialCompile(self: *Compilation) !void {
         if (self.root_src_path) |root_src_path| {
             const root_scope = blk: {
-                // TODO async/await std.fs.realpath
-                const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
+                // TODO async/await fs.realpath
+                const root_src_real_path = fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
                     try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
                     return;
                 };
@@ -1157,7 +1157,7 @@ pub const Compilation = struct {
         const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
         defer self.gpa().free(file_name);
 
-        const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
+        const full_path = try fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
         errdefer self.gpa().free(full_path);
 
         return Buffer.fromOwnedSlice(self.gpa(), full_path);
@@ -1178,8 +1178,8 @@ pub const Compilation = struct {
         const zig_dir_path = try getZigDir(self.gpa());
         defer self.gpa().free(zig_dir_path);
 
-        const tmp_dir = try std.fs.path.join(self.arena(), &[_][]const u8{ zig_dir_path, comp_dir_name[0..] });
-        try std.fs.makePath(self.gpa(), tmp_dir);
+        const tmp_dir = try fs.path.join(self.arena(), &[_][]const u8{ zig_dir_path, comp_dir_name[0..] });
+        try fs.makePath(self.gpa(), tmp_dir);
         return tmp_dir;
     }
 
@@ -1351,7 +1351,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) Compilation.Build
 }
 
 fn getZigDir(allocator: *mem.Allocator) ![]u8 {
-    return std.fs.getAppDataDir(allocator, "zig");
+    return fs.getAppDataDir(allocator, "zig");
 }
 
 fn analyzeFnType(
src-self-hosted/introspect.zig
@@ -14,7 +14,7 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
     const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
     defer allocator.free(test_index_file);
 
-    var file = try fs.File.openRead(test_index_file);
+    var file = try fs.cwd().openRead(test_index_file);
     file.close();
 
     return test_zig_dir;
src-self-hosted/main.zig
@@ -724,7 +724,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
         if (try held.value.put(file_path, {})) |_| return;
     }
 
-    const source_code = event.fs.readFile(
+    const source_code = fs.cwd().readFileAlloc(
         fmt.allocator,
         file_path,
         max_src_size,
build.zig
@@ -72,14 +72,13 @@ pub fn build(b: *Builder) !void {
     const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
     const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
     const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
-    const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
-    if (!skip_self_hosted and builtin.os == .linux) {
-        // TODO evented I/O other OS's
+    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
+    if (!skip_self_hosted) {
         test_step.dependOn(&exe.step);
     }
 
     const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
-    if (!only_install_lib_files) {
+    if (!only_install_lib_files and !skip_self_hosted) {
         b.default_step.dependOn(&exe.step);
         exe.install();
     }