Repository navigation
Conversation
`copy(src, dst)` copies a single file into the repository (or the working directory of a module extension) and preserves its executable bit. On file systems that support it, the copy is created as a copy-on-write clone of the source (`clonefile` on macOS, `copy_file_range` on Linux), so it doesn't take up additional disk space. The source is watched by default, which can be controlled via `watch_src`. Unlike a symlink to a file in the main repo or in another repo, a copy doesn't prevent a reproducible repo from being stored in the local and remote repo contents caches. Emulating a copy via `ctx.file(dst, ctx.read(src))` loads the file into memory and loses the executable bit. Contrary to `symlink`, `copy` is also available on `module_ctx` since it watches the source in the same way on all platforms and thus doesn't result in platform-specific lockfiles. Work towards bazelbuild#31434 and bazelbuild#31456.
`repository_ctx.copy` and `module_ctx.copy` now also accept a directory as `src`. It is copied as if each file in it were copied individually: * Symlinks to files and directories are followed, so the copy doesn't contain any symlinks. * Existing files below `dst` are overwritten and all other files below `dst` are kept, which matches `extract`. * Executable bits are preserved and the copied files are writable. The source directory is watched in the same way as by `repository_ctx.watch_tree`, which also follows symlinks. Symlink cycles, dangling symlinks and overlapping `src` and `dst` are errors.
repository_ctx.copy preserves executable bits. Include executable bits in regular FileStateValue comparisons, directory-tree digests and copied file inputs so chmod invalidates cached copies. Keep ordinary reads and watches content-only. Use FILE_CONTENTS for content-only records and include the executable bit in FILE records. Old FILE records revalidate once, including affected module lockfiles.
dzbarsky
requested review from
Wyverald,
lberki and
meteorcloudy
as code owners
October 15, 2026 22:56
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #31461.
repository_ctx.copypreserves executable bits, but its recorded inputscurrently only check file contents. Changing a source from 0644 to 0755 can
therefore reuse a stale, non-executable copy.
Include executable bits in
FileStateValuecomparisons, directory-treedigests and copied-file records. Regular reads and watches still record only
contents. Old
FILErecords revalidate once; new content-only records useFILE_CONTENTS, so affected module lockfiles need regeneration.