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.

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.

3 participants