Skip to content

Fix trim path problems#4435

Merged
fmeum merged 1 commit intobazel-contrib:masterfrom
monogon:trimpath
Aug 27, 2025
Merged

Fix trim path problems#4435
fmeum merged 1 commit intobazel-contrib:masterfrom
monogon:trimpath

Conversation

@jscissr
Copy link
Copy Markdown
Contributor

@jscissr jscissr commented Aug 27, 2025

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

There were multiple problems with trim paths:

  • The trim path was inconsistent between non-cgo and cgo. non-cgo trimmed the working directory, and cgo trimmed the parent of the working directory.
  • For non-cgo, paths in external repos are not trimmed when --experimental_sibling_repository_layout is enabled.
  • For cgo, the name of the working directory is included in the output, but this name is not consistent between local and remote builds, breaking reproducibility.

These are fixed here by creating the trim path in the same way for both non-cgo and cgo, and trimming the working directory as well as replacing the parent of the working directory with ... This means that the resulting paths are relative to the working directory.

Additionally, this fixes the existing feature to extend an existing trimpath. It used the wrong separator (: instead of ;), and it applied abs() to the entire trimpath argument instead of the individual paths inside it. (See #2994 (comment) and #2994 (comment))

Which issues(s) does this PR fix?

Fixes: #4434
Fixes: #4161

Copy link
Copy Markdown
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

Love the test, thanks!

There were multiple problems with trim paths:

- The trim path was inconsistent between non-cgo and cgo. non-cgo
  trimmed the working directory, and cgo trimmed the parent of the
  working directory.
- For non-cgo, paths in external repos are not trimmed when
  --experimental_sibling_repository_layout is enabled.
- For cgo, the name of the working directory is included in the output,
  but this name is not consistent between local and remote builds,
  breaking reproducibility.

These are fixed here by creating the trim path in the same way for both
non-cgo and cgo, and trimming the working directory as well as replacing
the parent of the working directory with `..`. This means that the
resulting paths are relative to the working directory.

Additionally, this fixes the existing feature to extend an existing
trimpath. It used the wrong separator (`:` instead of `;`), and it
applied `abs()` to the entire trimpath argument instead of the
individual paths inside it.

Fixes: bazel-contrib#4434
Fixes: bazel-contrib#4161
@fmeum fmeum merged commit e445813 into bazel-contrib:master Aug 27, 2025
1 check passed
@jscissr jscissr deleted the trimpath branch August 27, 2025 16:33
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.

Trim path inconsistency and problems Ability to trimpath a different path in addition to default is not functioning

2 participants