Skip to content

pathname: convert Cellar to opt paths before symlinking#11351

Closed
carlocab wants to merge 1 commit intoHomebrew:masterfrom
carlocab:opt-symlinks
Closed

pathname: convert Cellar to opt paths before symlinking#11351
carlocab wants to merge 1 commit intoHomebrew:masterfrom
carlocab:opt-symlinks

Conversation

@carlocab
Copy link
Copy Markdown
Member

@carlocab carlocab commented May 9, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Some formulae (e.g. include-what-you-use) install symlinks to a
descendant of another formula's prefix in their install methods.

Currently, install_symlink fully resolves symlinks, so using it to
install such a symlink creates a reference to a Cellar path. This
reference is invalidated with version or revision bumps to the
referenced formula.

Let's fix that by converting Cellar references into equivalent opt
references before constructing the relative path.

I'm hoping that the Cellar-to-opt conversion will prove useful elsewhere
(e.g. keg_relocate), so I've created a separate method for it.


CC @sjackman (Ref. #5793)

@carlocab carlocab requested a review from sjackman May 9, 2021 03:13
@BrewTestBot
Copy link
Copy Markdown
Contributor

Review period will end on 2021-05-11 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label May 9, 2021
@carlocab
Copy link
Copy Markdown
Member Author

carlocab commented May 9, 2021

For include-what-you-use, before:

❯ ll
Permissions Size User     Date Modified Name
lrwxr-xr-x    38 carlocab 21 Nov  2020  clang -> ../../../../llvm@11/11.1.0_1/lib/clang

After:

❯ ll
Permissions Size User     Date Modified Name
lrwxr-xr-x    36 carlocab 9 May 04:43  clang -> ../../../../../opt/llvm@11/lib/clang

Cf. Homebrew/homebrew-core#76030

Some formulae (e.g. `include-what-you-use`) install symlinks to a
descendant of another formula's prefix in their install methods.

Currently, `install_symlink` fully resolves symlinks, so using it to
install such a symlink creates a reference to a Cellar path. This
reference is invalidated with version or revision bumps to the
referenced formula.

Let's fix that by converting Cellar references into equivalent opt
references before constructing the relative path.

I'm hoping that the Cellar-to-opt conversion will prove useful elsewhere
(e.g. `keg_relocate`), so I've created a separate method for it.
Copy link
Copy Markdown
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Makes sense to me

sig { returns(Pathname) }
def to_opt
return self unless descend.include? HOMEBREW_CELLAR
return self if relative?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This line doesn't actually do anything (descend.include? is false whenever relative? is true). However, I think it makes what's happening clearer.

@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label May 10, 2021
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label May 10, 2021
@BrewTestBot
Copy link
Copy Markdown
Contributor

Review period skipped due to critical label.

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Great work! Optional feedback.

# No-op if {Pathname} is not a descendant of HOMEBREW_CELLAR
# or if {Pathname} is a relative path.
sig { returns(Pathname) }
def to_opt
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you plan to use this in formulae? If so, I'd prefer not to have this extend Pathname. If not, can you make it private (and perhaps consider pulling it into utils)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, there's no reason to use it in formulae, I think. Let me look at moving it/making it private.

@MikeMcQuaid
Copy link
Copy Markdown
Member

@carlocab I'm good for this to be merged if/when you are?

@carlocab
Copy link
Copy Markdown
Member Author

There are still two issues:

  1. This code doesn't handle trailing slashes correctly. I can fix that. (Though I'm also not sure whether we need to be so careful with handling those.)
  2. We might not want to do this cellar-to-opt conversion when creating symlinks that reference paths in the same keg. I'm not sure it's harmful, but doing this conversion can create some weird symlinks.

As an illustration of the second issue, suppose I have the following in an install method:

bin.install_symlink lib/"libfoo.dylib"

The existing behaviour would be to create the following symlink in bin:

libfoo.dylib -> ../lib/libfoo.dylib

With this change, we would have that symlink look something like

libfoo.dylib -> ../../../../opt/foo/lib/libfoo.dylib

It doesn't hurt, but it's bound to confuse some people looking at it.

@Bo98
Copy link
Copy Markdown
Member

Bo98 commented May 31, 2021

  1. We might not want to do this cellar-to-opt conversion when creating symlinks that reference paths in the same keg.

Given we generally have decent support for side-by-side versioned kegs (although this has somewhat faded over the years on the CLI side), I think it is indeed ideal to keep versioned Cellar references when used in the same keg.

@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Jun 22, 2021
@github-actions github-actions bot closed this Jun 29, 2021
@github-actions github-actions bot added the outdated PR was locked due to age label Jul 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age stale No recent activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants