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.zig | |
| 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.zig')
| -rw-r--r-- | lib/std/Build/Step.zig | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index e41912d548..a2640492ba 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -160,6 +160,7 @@ pub const Inputs = struct { }; pub const Table = std.ArrayHashMapUnmanaged(Build.Cache.Path, Files, Build.Cache.Path.TableAdapter, false); + /// The special file name "." means any changes inside the directory. pub const Files = std.ArrayListUnmanaged([]const u8); pub fn populated(inputs: *Inputs) bool { @@ -611,8 +612,9 @@ pub fn clearWatchInputs(step: *Step) void { step.inputs.clear(gpa); } -pub fn addWatchInput(step: *Step, lazy_path: Build.LazyPath) Allocator.Error!void { - switch (lazy_path) { +/// Places a *file* dependency on the path. +pub fn addWatchInput(step: *Step, lazy_file: Build.LazyPath) Allocator.Error!void { + switch (lazy_file) { .src_path => |src_path| try addWatchInputFromBuilder(step, src_path.owner, src_path.sub_path), .dependency => |d| try addWatchInputFromBuilder(step, d.dependency.builder, d.sub_path), .cwd_relative => |path_string| { @@ -629,6 +631,34 @@ pub fn addWatchInput(step: *Step, lazy_path: Build.LazyPath) Allocator.Error!voi } } +/// Any changes inside the directory will trigger invalidation. +/// +/// See also `addDirectoryWatchInputFromPath` which takes a `Build.Cache.Path` instead. +pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Allocator.Error!void { + switch (lazy_directory) { + .src_path => |src_path| try addDirectoryWatchInputFromBuilder(step, src_path.owner, src_path.sub_path), + .dependency => |d| try addDirectoryWatchInputFromBuilder(step, d.dependency.builder, d.sub_path), + .cwd_relative => |path_string| { + try addDirectoryWatchInputFromPath(step, .{ + .root_dir = .{ + .path = null, + .handle = std.fs.cwd(), + }, + .sub_path = path_string, + }); + }, + // Nothing to watch because this dependency edge is modeled instead via `dependants`. + .generated => {}, + } +} + +/// Any changes inside the directory will trigger invalidation. +/// +/// See also `addDirectoryWatchInput` which takes a `Build.LazyPath` instead. +pub fn addDirectoryWatchInputFromPath(step: *Step, path: Build.Cache.Path) !void { + return addWatchInputFromPath(step, path, "."); +} + fn addWatchInputFromBuilder(step: *Step, builder: *Build, sub_path: []const u8) !void { return addWatchInputFromPath(step, .{ .root_dir = builder.build_root, @@ -636,6 +666,13 @@ fn addWatchInputFromBuilder(step: *Step, builder: *Build, sub_path: []const u8) }, std.fs.path.basename(sub_path)); } +fn addDirectoryWatchInputFromBuilder(step: *Step, builder: *Build, sub_path: []const u8) !void { + return addDirectoryWatchInputFromPath(step, .{ + .root_dir = builder.build_root, + .sub_path = sub_path, + }); +} + fn addWatchInputFromPath(step: *Step, path: Build.Cache.Path, basename: []const u8) !void { const gpa = step.owner.allocator; const gop = try step.inputs.table.getOrPut(gpa, path); |
