diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-10 15:09:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-12 00:14:08 -0700 |
| commit | a966eee090d55c7d61484333af675c80115bf188 (patch) | |
| tree | 9df97f8551ce59a4f163d4bd23b145c5bcb44858 /lib/std/Build/Step.zig | |
| parent | f2856403c6997ff1317c968abed0871df9586c7c (diff) | |
| download | zig-a966eee090d55c7d61484333af675c80115bf188.tar.gz zig-a966eee090d55c7d61484333af675c80115bf188.zip | |
std.Build.Step.WriteFile: fix handling of directories
and add file system watching integration.
`addDirectoryWatchInput` now returns a `bool` which helps remind the
caller to
1. call addDirectoryWatchInputFromPath on any derived paths
2. but only if the dependency is not already captured by a step
dependency edge.
The make function now recursively walks all directories and adds the
found files to the cache hash rather than incorrectly only adding the
directory name to the cache hash.
closes #20571
Diffstat (limited to 'lib/std/Build/Step.zig')
| -rw-r--r-- | lib/std/Build/Step.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index a2640492ba..5c77bd3367 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -634,7 +634,11 @@ pub fn addWatchInput(step: *Step, lazy_file: 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 { +/// +/// Paths derived from this directory should also be manually added via +/// `addDirectoryWatchInputFromPath` if and only if this function returns +/// `true`. +pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Allocator.Error!bool { 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), @@ -648,13 +652,19 @@ pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Alloc }); }, // Nothing to watch because this dependency edge is modeled instead via `dependants`. - .generated => {}, + .generated => return false, } + return true; } /// Any changes inside the directory will trigger invalidation. /// /// See also `addDirectoryWatchInput` which takes a `Build.LazyPath` instead. +/// +/// This function should only be called when it has been verified that the +/// dependency on `path` is not already accounted for by a `Step` dependency. +/// In other words, before calling this function, first check that the +/// `Build.LazyPath` which this `path` is derived from is not `generated`. pub fn addDirectoryWatchInputFromPath(step: *Step, path: Build.Cache.Path) !void { return addWatchInputFromPath(step, path, "."); } |
