Skip to content

Add ShortenAbsoluteLabelsToRelative configuration option#3492

Open
hartblanc wants to merge 2 commits into
thought-machine:masterfrom
hartblanc:fix/shorten-labels
Open

Add ShortenAbsoluteLabelsToRelative configuration option#3492
hartblanc wants to merge 2 commits into
thought-machine:masterfrom
hartblanc:fix/shorten-labels

Conversation

@hartblanc

@hartblanc hartblanc commented Feb 27, 2026

Copy link
Copy Markdown

This change ensures that absolute labels to package-local targets (e.g. //a/b/c:d) are transformed into local labels (e.g. :d) by the please format command when the new Format.ShortenAbsoluteLabelsToRelative config option is enabled.

The aim of this change is to address #3471.

This change supercedes please-build/buildtools#10.

@hartblanc

hartblanc commented Mar 2, 2026

Copy link
Copy Markdown
Author

After pondering about please-build/puku#147, I'm actually wondering if we want to make plz format or buildtools/build configurable (as this change does).

The approach of gofmt for example, is to not allow any configuration and 'Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.'. This works very nicely for tools which modify go source code, as they are able to always produce well-formatted output by simply calling gofmt (as a library).

For this reason, whilst it seems a little crude at first, I'm wondering if please-build/buildtools#10 might actually be preferable to this approach.

@toastwaffle toastwaffle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please could you fix the lint (otherwise this is good to go)

@peterebden

Copy link
Copy Markdown
Collaborator

After pondering about please-build/puku#147, I'm actually wondering if we want to make plz format or buildtools/build configurable (as this change does).

The approach of gofmt for example, is to not allow any configuration and 'Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.'. This works very nicely for tools which modify go source code, as they are able to always produce well-formatted output by simply calling gofmt (as a library).

For this reason, whilst it seems a little crude at first, I'm wondering if please-build/buildtools#10 might actually be preferable to this approach.

I tend to agree with this. It might be initially disruptive having this reformat but it seems nicer in the long run to have one canonical format than many with lots of flags.

FWIW I don't think we have to change the library in the PR you mentioned; the approach here of calling FormatWithRewriter seems good, but maybe we just set that field to true.

@hartblanc

Copy link
Copy Markdown
Author

FWIW I don't think we have to change the library in the PR you mentioned; the approach here of calling FormatWithRewriter seems good, but maybe we just set that field to true.

My thinking was that it would be preferable to have other tools that format build rules via buildtools/build (e.g. puku) behave the same, which would be achieved by initial approach. If we use the FormatWithRewriter approach we would need to do that everywhere if we wanted to be consistent, which feels easy to forget to do.

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