diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-09 23:15:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-12 00:14:08 -0700 |
| commit | 7bccef3e4e4d48c2e1d34ec28754d8c33902f2bb (patch) | |
| tree | cc708ebeb8f8885c3ca4cfaa273a1eaee5101f87 /lib/std/Build/Step | |
| parent | 26bdc836d2d9b2654f7f95fec34c6276070f2a59 (diff) | |
| download | zig-7bccef3e4e4d48c2e1d34ec28754d8c33902f2bb.tar.gz zig-7bccef3e4e4d48c2e1d34ec28754d8c33902f2bb.zip | |
std.Build.Watch: introduce special file "." to watch entire dir
And use it to implement InstallDir Step watch integration.
I'm not seeing any events triggered when I run `mkdir` in the watched
directory, however, and I have not yet figured out why.
Diffstat (limited to 'lib/std/Build/Step')
| -rw-r--r-- | lib/std/Build/Step/InstallDir.zig | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/std/Build/Step/InstallDir.zig b/lib/std/Build/Step/InstallDir.zig index ca38e09ec1..9cd71e7828 100644 --- a/lib/std/Build/Step/InstallDir.zig +++ b/lib/std/Build/Step/InstallDir.zig @@ -59,12 +59,14 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void { _ = prog_node; const b = step.owner; const install_dir: *InstallDir = @fieldParentPtr("step", step); + step.clearWatchInputs(); const arena = b.allocator; const dest_prefix = b.getInstallPath(install_dir.options.install_dir, install_dir.options.install_subdir); - const src_dir_path = install_dir.options.source_dir.getPath2(b, step); - var src_dir = b.build_root.handle.openDir(src_dir_path, .{ .iterate = true }) catch |err| { - return step.fail("unable to open source directory '{}{s}': {s}", .{ - b.build_root, src_dir_path, @errorName(err), + const src_dir_path = install_dir.options.source_dir.getPath3(b, step); + try step.addDirectoryWatchInput(install_dir.options.source_dir); + var src_dir = src_dir_path.root_dir.handle.openDir(src_dir_path.subPathOpt() orelse ".", .{ .iterate = true }) catch |err| { + return step.fail("unable to open source directory '{}': {s}", .{ + src_dir_path, @errorName(err), }); }; defer src_dir.close(); @@ -88,12 +90,16 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void { } // relative to src build root - const src_sub_path = b.pathJoin(&.{ src_dir_path, entry.path }); + const src_sub_path = try src_dir_path.join(arena, entry.path); const dest_path = b.pathJoin(&.{ dest_prefix, entry.path }); const cwd = fs.cwd(); switch (entry.kind) { - .directory => try cwd.makePath(dest_path), + .directory => { + const subdir_path = try src_dir_path.join(arena, entry.path); + try step.addDirectoryWatchInputFromPath(subdir_path); + try cwd.makePath(dest_path); + }, .file => { for (install_dir.options.blank_extensions) |ext| { if (mem.endsWith(u8, entry.path, ext)) { @@ -103,14 +109,14 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void { } const prev_status = fs.Dir.updateFile( - b.build_root.handle, - src_sub_path, + src_sub_path.root_dir.handle, + src_sub_path.sub_path, cwd, dest_path, .{}, ) catch |err| { - return step.fail("unable to update file from '{}{s}' to '{s}': {s}", .{ - b.build_root, src_sub_path, dest_path, @errorName(err), + return step.fail("unable to update file from '{}' to '{s}': {s}", .{ + src_sub_path, dest_path, @errorName(err), }); }; all_cached = all_cached and prev_status == .fresh; |
