Skip to content

Include unresolved symlink target into the source directory hash #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 16, 2025

This makes it so that changes to the targets of unresolved symlinks invalidate actions that depend on the source directory containing them.

Work towards bazelbuild#25834

Summary by CodeRabbit

  • New Features

    • Added integration tests to verify how changes in source directories and their contents affect build invalidation, including scenarios with files, directories, and symlinks.
  • Bug Fixes

    • Improved handling of dangling symlinks during filesystem traversal to ensure more robust and consistent behavior.
  • Tests

    • Introduced comprehensive tests covering source directory changes, symlink handling, package boundary violations, and symlink cycles.

fmeum added 3 commits April 15, 2025 18:06
This makes it so that changes to the targets of unresolved symlinks invalidate actions that depend on the source directory containing them.
@gandalf-repo
Copy link

@coderabbitai full review

Copy link

coderabbitai bot commented Apr 16, 2025

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Apr 16, 2025

Walkthrough

This update introduces a new integration test class, SourceDirectoryIntegrationTest, to verify Bazel's handling of source directories, especially regarding action invalidation when directory contents change. The test is registered in the build configuration. Additionally, the danglingSymlink factory method in ResolvedFileFactory is refactored to internally compute symlink digests, removing the need for an explicit metadata parameter. All usages of this method, including in production and test code, are updated to match the new signature. No changes are made to the overall control flow or error handling.

Changes

File(s) Change Summary
src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java Updated calls to ResolvedFileFactory.danglingSymlink to remove the third argument (rootInfo.metadata), reflecting the new method signature.
src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java Refactored danglingSymlink in ResolvedFileFactory to compute the digest internally using SHA-256 of the symlink target, with a special prefix to avoid collisions. Removed the HasDigest metadata parameter from the method signature. Added necessary imports for digest computation.
src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java Updated test cases to remove the third argument (EMPTY_METADATA) from calls to danglingSymlink, matching the new method signature.
src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java Added a comprehensive new integration test class for source directory invalidation, symlink handling, and error scenarios in Bazel. Includes multiple test cases and helper methods for asserting action invalidation.
src/test/java/com/google/devtools/build/lib/skyframe/BUILD Added a new java_test target for SourceDirectoryIntegrationTest, specifying sources, dependencies, and JVM flags.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant BazelBuildSystem
    participant SourceDirectory
    participant ActionExecutor

    TestRunner->>BazelBuildSystem: Trigger build with genrule consuming SourceDirectory
    BazelBuildSystem->>SourceDirectory: Scan directory and contents
    SourceDirectory-->>BazelBuildSystem: Return files, dirs, symlinks info
    BazelBuildSystem->>ActionExecutor: Decide if action needs invalidation
    ActionExecutor-->>BazelBuildSystem: Execute genrule if invalidated
    BazelBuildSystem-->>TestRunner: Report build result and action execution events
Loading

Poem

In the warren of source and symlink's delight,
A rabbit hops, testing changes by night.
With digests now crafted from symlinked string,
No more metadata—just hashes we bring!
New tests leap in, directories explored,
Ensuring Bazel's builds are never ignored.
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java (1)

181-188: Clarify rationale for ignoring the test.

The test is marked with @Ignore("TODO(#25834)"). Are you planning to address this soon, or should it remain disabled?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0c98a2 and 3e2fb54.

📒 Files selected for processing (5)
  • src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java (1 hunks)
  • src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java (2 hunks)
  • src/test/java/com/google/devtools/build/lib/skyframe/BUILD (1 hunks)
  • src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java (2 hunks)
  • src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java (1 hunks)
🔇 Additional comments (8)
src/test/java/com/google/devtools/build/lib/skyframe/BUILD (1)

1924-1943: Appropriate integration test addition for source directory symlink handling

This new test target will verify proper handling of source directories including symlinks, which aligns well with the PR's objective of ensuring unresolved symlink targets are included in source directory hashing.

src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java (2)

833-833: Updated method call to match the new signature

The signature of danglingSymlink has been updated to no longer take a metadata parameter since it now computes the digest internally.


847-847: Updated method call to match the new signature

Consistent update to remove the metadata parameter from danglingSymlink call, reflecting the factory method's new signature.

src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java (1)

189-191: Updated method call to match the new signature

The code has been correctly updated to use the new signature of danglingSymlink, which now computes the digest internally from the symlink target rather than requiring an explicit metadata parameter.

src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java (2)

579-588: Document the collision-avoidance approach.

XORing the first byte of the SHA-256 digest to avoid collisions with regular file digests is clever but not immediately obvious. Consider adding a short comment explaining the rationale behind digest[0] ^= 1;.


17-24:

❓ Verification inconclusive

Consider verifying ISO_8859_1 usage for non-Latin filenames.

The imports for ISO_8859_1 and DigestHashFunction look fine, but if there's a possibility of non-Latin filename characters, consider verifying that converting them to ISO-8859-1 will not produce unexpected results.

Would you like to run a quick check across the codebase for potential non-ASCII path usage?


🏁 Script executed:

#!/bin/bash
# Description: Find lines that reference `PathFragment.create` with potential non-ASCII usage
rg -A 3 "PathFragment\.create\(.*[^\x00-\x7F].*\)"

Length of output: 52


Manual Verification Recommended: Confirm ISO_8859_1 Handling for Non-Latin Filenames

The initial grep check for non-ASCII usage in calls to PathFragment.create returned no results. However, the absence of evidence from this low-yield search means we cannot conclusively rule out potential issues with non-Latin filenames. Please perform a manual review of any file path encoding logic that may rely on ISO-8859-1 to ensure that filenames with non-Latin characters are handled correctly.

  • Verify that conversions or operations involving ISO_8859_1 (as imported in this file) are safe for non-Latin filename characters.
  • Re-assess any related logic in file path manipulations across the codebase to avoid encoding issues.
src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java (2)

45-86: Kudos on the comprehensive setup method.

The setUpGenrule() method meticulously sets up a varied directory structure with nested files, symlinks, and dangling symlinks to test invalidation semantics thoroughly. Nice job covering a wide range of conditions!


214-233: Great coverage of edge-cases and failure scenarios.

Your tests for crossing package boundaries and infinite symlink expansions are well-structured. This ensures you catch potential breakages in complex real-world scenarios.

@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

Copy link

refacto-test bot commented Jul 15, 2025

🤖 Refacto.AI: PR Summary & Reviewer Guide

Warning: Requirements context (e.g., linked ticket) was not provided. Analysis is based solely on PR metadata and code diff, which may be incomplete.

🎯 1. The Goal (Why was this PR raised?)

This PR aims to include unresolved symlink targets into the source directory hash, ensuring that changes to dangling symlink targets are properly tracked and invalidate dependent actions when necessary.

🗺️ 2. The Changes (What was implemented?)

Goal / Requirement Addressed Implementation Details (File & Key Changes)
Modify dangling symlink handling "src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java" (Modified):
- Changed the danglingSymlink method to compute a digest based on the symlink target path.
- Added logic to ensure the digest doesn't collide with regular files by flipping a bit in the first byte.
- Removed the metadata parameter as it's now generated internally.
Update function calls "src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java" (Modified):
- Updated the call to danglingSymlink to remove the metadata parameter.
Update tests "src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java" (Modified):
- Updated test cases to call danglingSymlink without the metadata parameter.
Add integration tests "src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java" (Added):
- Added comprehensive integration tests to verify that actions consuming source directories are properly invalidated when directory contents change.
- Tests specifically verify that modifying dangling symlinks invalidates dependent actions.
Update build configuration "src/test/java/com/google/devtools/build/lib/skyframe/BUILD" (Modified):
- Added a new test target for the SourceDirectoryIntegrationTest with appropriate dependencies.

🤔 3. Key Areas for Human Review

Area of Concern: Hash Generation for Dangling Symlinks

  • File: "src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java" (Lines 576-590)
  • Why: This change modifies how dangling symlinks are hashed, which directly affects build invalidation. The code now generates a digest based on the symlink target path and ensures it doesn't collide with regular files.
  • Testing Instruction: Verify that changing a dangling symlink target (without changing the symlink itself) properly invalidates dependent actions by running the test "SourceDirectoryIntegrationTest.danglingSymlinkModified_invalidatesAction".

Area of Concern: Integration Test Completeness

  • File: "src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java"
  • Why: This is a new test file that verifies the core functionality of the PR. It's important to ensure the test cases are comprehensive and correctly validate the behavior.
  • Testing Instruction: Review the test cases to ensure they cover all relevant scenarios for source directory invalidation, particularly focusing on the tests related to dangling symlinks (lines 195-208).

Area of Concern: Potential Performance Impact

  • File: "src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java" (Lines 579-585)
  • Why: The code now computes SHA-256 hashes for dangling symlink targets, which could have performance implications if there are many dangling symlinks in a project.
  • Testing Instruction: Consider benchmarking the performance impact with a project that contains many dangling symlinks before and after this change.

Copy link

refacto-test bot commented Jul 15, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

Copy link

refacto-test bot commented Jul 15, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

Copy link

refacto-test bot commented Jul 15, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

1 similar comment
@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

Copy link

refacto-test bot commented Jul 15, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

@visz11
Copy link
Collaborator

visz11 commented Jul 15, 2025

/refacto-test

Copy link

refacto-test bot commented Jul 15, 2025

🤖 Refacto.AI: PR Summary & Reviewer Guide

Warning: Requirements context (e.g., linked ticket) was not provided. Analysis is based solely on PR metadata and code diff, which may be incomplete.

🎯 1. The Goal (Why was this PR raised?)

This PR aims to include unresolved symlink targets into the source directory hash, ensuring that changes to dangling symlinks properly invalidate dependent actions. The implementation modifies how dangling symlinks are handled in the filesystem traversal system.

🗺️ 2. The Changes (What was implemented?)

Goal / Requirement Addressed Implementation Details (File & Key Changes)
Include symlink target in hash src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java (Modified):
- Modified the danglingSymlink method to compute a digest based on the symlink target path string.
- Added logic to ensure the digest doesn't collide with regular file digests by XORing the first byte with 1.
Update symlink handling src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java (Modified):
- Updated the call to danglingSymlink to remove the metadata parameter which is no longer needed.
Add comprehensive tests src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java (Added):
- Added extensive integration tests for source directory invalidation scenarios.
- Tests verify that changes to symlinks (including dangling ones) properly trigger action invalidation.
Update test cases src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java (Modified):
- Updated test cases to use the new danglingSymlink method signature without the metadata parameter.
Configure test build src/test/java/com/google/devtools/build/lib/skyframe/BUILD (Modified):
- Added configuration for the new SourceDirectoryIntegrationTest.

🤔 3. Key Areas for Human Review

Area of Concern: Symlink Digest Computation

  • File: src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java (Lines 576-589)
  • Why: This change modifies core functionality for how dangling symlinks are handled in the build system. The digest computation is critical for proper action invalidation.
  • Testing Instruction: Verify that the digest computation for dangling symlinks is correct by testing a build with a dangling symlink, then modifying the symlink target without changing where it points (should invalidate the action).

Area of Concern: Integration Test Coverage

  • File: src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java
  • Why: This new test file contains critical test cases that verify the behavior of the system. The tests include complex scenarios with symlinks, file modifications, and directory structures.
  • Testing Instruction: Review the test cases to ensure they cover all relevant edge cases, particularly focusing on the danglingSymlinkModified_invalidatesAction test which directly tests the feature being implemented.

Area of Concern: Potential Bug in Symlink Handling

  • File: src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java (Lines 174-183)
  • Why: There is an ignored test case marked with @Ignore("TODO(#25834)") which suggests there might be a known issue with handling empty directories replaced with identical symlinks.
  • Testing Instruction: Check if the issue referenced by Enable BAZEL_TRACK_SOURCE_DIRECTORIES by default bazelbuild/bazel#25834 is related to this change and whether this PR should address it or if it's intentionally left for future work.

Copy link

refacto-test bot commented Jul 15, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants