Skip to content

Commit a4cca76

Browse files
fix: watch local packages to refetch if files are added/updated (#1489)
Call `repository_ctx.watch_tree` to ensure that repositories are refetched for local SPM packages if new files are added or removed. This will also cause a refetch if a file's content changes, but I didn't see a way to only watch for changes to file creation/deletion. Without this I was experiencing issues where local SPM packages would fail to compile after pulling down changes from git because new files were added without the repo's `BUILD.bazel` file being updated as well. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 0cfeb00 commit a4cca76

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

swiftpkg/bzlmod/swift_deps.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _declare_pkgs_from_package(module_ctx, from_package, config_pkgs, config_swi
6060
not dep.source_control:
6161
# buildifier: disable=print
6262
print("""
63-
WARNING: {name} is unresolved and won't be available duing the build, resolve \
63+
WARNING: {name} is unresolved and won't be available during the build, resolve \
6464
the Swift package to make it available.\
6565
""".format(name = dep.name))
6666
continue

swiftpkg/internal/local_swift_package.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ load(":repo_rules.bzl", "repo_rules")
1414
_CODE_IGNORE_LIST = [".", "..", ".build"]
1515

1616
def _list_contents(repository_ctx, repo_dir, path):
17+
# Watch directory to ensure the repo is refetched if new files are added to the local package.
18+
# watch_tree was added in Bazel 7.1.0 so we need to check that it exists before calling it.
19+
if hasattr(repository_ctx, "watch_tree"):
20+
repository_ctx.watch_tree(path)
21+
1722
exec_result = repository_ctx.execute(
1823
["ls", "-a", "-1", path],
1924
working_directory = repo_dir,

0 commit comments

Comments
 (0)