Skip to content

Support path mapping collisions for identical files#29601

Open
layus wants to merge 1 commit into
bazelbuild:masterfrom
layus:feature/allow-mapping-collision-of-identical-files
Open

Support path mapping collisions for identical files#29601
layus wants to merge 1 commit into
bazelbuild:masterfrom
layus:feature/allow-mapping-collision-of-identical-files

Conversation

@layus
Copy link
Copy Markdown
Contributor

@layus layus commented May 20, 2026

Description

As per https://bazelbuild.slack.com/archives/CA31HN1T3/p1778851259301539?thread_ts=1775817669.172489&cid=CA31HN1T3 discussion with @fmeum , This implements support for path collisions amongst mapped files as long as their content is the same.

Motivation

I hope this fixes two issues. One with silently colliding declared inputs, taking the first one. And another when the same file ends-up showing in the dependencies through two different transitions, in particular with discovered inputs, like cc rules do.

Build API Changes

Oddly enough, the change has minimal impact on the APIs. All it adds is an optional @Nullable InputMetadataProvider to PathMapper create() method.

Checklist

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

Release Notes

RELNOTES: None

@layus layus requested review from a team, lberki, pzembrod and trybka as code owners May 20, 2026 14:37
@layus layus requested review from mai93 and removed request for a team May 20, 2026 14:37
@github-actions github-actions Bot added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-CPP Issues for C++ rules team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels May 20, 2026
Comment thread src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java Outdated
@layus layus force-pushed the feature/allow-mapping-collision-of-identical-files branch from b8632a4 to e9d1321 Compare May 21, 2026 08:36
@layus layus force-pushed the feature/allow-mapping-collision-of-identical-files branch from e9d1321 to 03a0959 Compare May 21, 2026 08:46
@bharadwaj08-one
Copy link
Copy Markdown

@layus Could you please take a look at the failing checks?

@bharadwaj08-one bharadwaj08-one added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels May 21, 2026
@layus
Copy link
Copy Markdown
Contributor Author

layus commented May 21, 2026

@bharadwaj08-one Not much to go by: src/main/tools/linux-sandbox-pid1.cc:204: "mount": Permission denied
Maybe it tries to mount conflicting tree artifacts at the same location ?

ERROR: 'linux-sandbox' was requested for explicit default strategies but no strategy with that identifier was registered. Valid values are: [dynamic_worker, processwrapper-sandbox, standalone, dynamic, remote, worker, sandboxed, local]
Seems odd, I did not touch any of that.

For some reason the errors seem sanbox related. Seems pretty unrelated to the changes here, unless they all cover collisions that were silently ignored before ?
Any chance to rerun them just o be sure ?

Add InputMetadataProvider to PathMappers.create() to verify that
colliding inputs from different configurations have identical file
digests. Update StrippingPathMapper and MerkleTreeComputer to check
digest equality when path collisions are detected.
@layus layus force-pushed the feature/allow-mapping-collision-of-identical-files branch from 03a0959 to 6235cef Compare May 21, 2026 19:41
@layus
Copy link
Copy Markdown
Contributor Author

layus commented May 21, 2026

@bharadwaj08-one Done, rebased and fixed.

private static PathFragment strip(PathFragment execPath) {
return execPath
.subFragment(0, 1)
// Keep the config segment, but replace it with a fixed string to improve cacheability while
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Keep this comment


/** Tests for collision handling in {@link StrippingPathMapper#isPathStrippable}. */
@RunWith(JUnit4.class)
public final class StrippingPathMapperTest {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test feels too synthetic to me. I think you can drop it.

Instead, could you add an integration test to path_mapping_test.sh that creates a situation in which two collising inputs are in fact identical and then verify that path mapping was used for the action?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How would you reliably check that path mapping is used. the only thing I can think of right now is parsing bazel build -s to find /cfg/ in there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can put the test in https://cs.opensource.google/bazel/bazel/+/master:src/test/shell/integration/config_stripped_outputs_test.sh and use the helpers defined in the _lib.sh file.

@bharadwaj08-one bharadwaj08-one added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Configurability platforms, toolchains, cquery, select(), config transitions team-Remote-Exec Issues and PRs for the Execution (Remote) team team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants