Skip to content

Ensure that rctx.symlink invalidates correctly if it is a copy#28682

Closed
fmeum wants to merge 3 commits intobazelbuild:masterfrom
fmeum:28575-symlink-content
Closed

Ensure that rctx.symlink invalidates correctly if it is a copy#28682
fmeum wants to merge 3 commits intobazelbuild:masterfrom
fmeum:28575-symlink-content

Conversation

@fmeum
Copy link
Copy Markdown
Collaborator

@fmeum fmeum commented Feb 17, 2026

Description

When rctx.symlink is implemented as a copy (on Windows with default settings), the target is now watched so that modifications to it are still seen through the fake "symlink".

Motivation

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: rctx.symlink now implicitly watches the target if it falls back to a copy.

@fmeum fmeum force-pushed the 28575-symlink-content branch from 74cd481 to 4d9c878 Compare February 17, 2026 14:00
@fmeum fmeum force-pushed the 28575-symlink-content branch from 4d9c878 to 2c1b25e Compare February 17, 2026 14:33
@fmeum fmeum changed the title WIP WIP: Fix rctx.symlink invalidation on Windows Feb 17, 2026
@fmeum fmeum changed the title WIP: Fix rctx.symlink invalidation on Windows Ensure that rctx.symlink invalidates correctly if it is a copy Feb 17, 2026
@fmeum fmeum marked this pull request as ready for review February 17, 2026 18:58
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Feb 17, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly ensures that ctx.symlink invalidates correctly when emulated as a copy, for example on Windows. The change adds a watch on the symlink target when native symlinks are not supported. The implementation is sound and is accompanied by good tests. I've added one comment about an opportunity to improve test coverage for file permissions.


self.RunBazel(args=['build', '@other_repo//:file'], cwd=work_dir)

def doTestSymlinkToFileInOtherRepoNoticesFileChange(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This is a great test for file content changes. To make it more robust, consider also testing the preservation of file permissions, especially the executable bit. When ctx.symlink is emulated as a copy on Windows, the file permissions are not preserved by the current implementation in WindowsFileSystem, which could lead to issues if the linked file is an executable script.

You could extend this test or add a new one where data.txt is an executable script, and the genrule attempts to execute it. This would highlight the issue and ensure the symlink emulation is correct with respect to permissions as well.

@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Feb 17, 2026

@bazel-io fork 9.1.0

Copy link
Copy Markdown
Member

@meteorcloudy meteorcloudy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@meteorcloudy meteorcloudy added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Feb 18, 2026
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Feb 18, 2026

@meteorcloudy I realized that this has an issue, will send a fix later.

@fmeum fmeum force-pushed the 28575-symlink-content branch from b8006d1 to c9bb725 Compare February 18, 2026 17:58
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Feb 18, 2026

@meteorcloudy PTAL, I decided to add the symlink bit to the fingerprint since I could see cache entries without the additional watch polluting (local or remote) repo contents caches when the startup flag is flipped. I haven't managed to reproduce this in a test.

@fmeum fmeum requested a review from meteorcloudy February 18, 2026 17:59
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Feb 23, 2026
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Feb 23, 2026
…elbuild#28682)

### Description
When `rctx.symlink` is implemented as a copy (on Windows with default settings), the target is now watched so that modifications to it are still seen through the fake "symlink".
Motivation

### Build API Changes
No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes
RELNOTES: `rctx.symlink` now implicitly watches the target if it falls back to a copy.

Closes bazelbuild#28682.

PiperOrigin-RevId: 873775628
Change-Id: I6bd9d38e19b20e3342802ab4a11acd319b7ac52f
github-merge-queue Bot pushed a commit that referenced this pull request Feb 23, 2026
…opy (#28682) (#28741)

### Description
When `rctx.symlink` is implemented as a copy (on Windows with default
settings), the target is now watched so that modifications to it are
still seen through the fake "symlink".
Motivation

### Build API Changes
No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes
RELNOTES: `rctx.symlink` now implicitly watches the target if it falls
back to a copy.

Closes #28682.

PiperOrigin-RevId: 873775628
Change-Id: I6bd9d38e19b20e3342802ab4a11acd319b7ac52f

Commit
6dd6396

Co-authored-by: Fabian Meumertzheim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants