Skip to content
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

Utils: shortened brew paths #11537

Merged
merged 3 commits into from
Jun 16, 2021
Merged

Conversation

alebcay
Copy link
Member

@alebcay alebcay commented Jun 15, 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?

Overview

This PR adds:

  • New file in Utils module, utils/path
    • Utils.path_is_parent_of? determines if one Pathname/String is a parent of another Pathname/String
    • Utils.shortened_brew_path expresses a Pathname/String as a shell expansion where possible, e.g. /usr/local/Cellar/cmake as $(brew --cellar)/cmake. Where possible, it can also express a Pathname as a formula's opt prefix, e.g. /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home becomes $(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home
  • Methods in language/java
    • Language::Java.short_java_home_shell, Language::Java.short_java_home_env, Language::Java.overridable_short_java_home_env which are shortened versions of the existing respective methods

This PR also modifies write_env_script, write_exec_script, and write_jar_script to use shortened_brew_path.

Rationale

Now that we are bottling everything, there are many cases where we can't use all: bottles because an env script, exec script, jar script etc. has a platform-dependent HOMEBREW_PREFIX in it (e.g. /usr/local vs /opt/homebrew).

The result is that we have to carry extra copies of some bottles where the bulk of the payload is the same. This is especially the case in Java based formulae, where the resulting bottle can be tens or hundreds of megabytes in size.

Commands like $(brew --prefix), $(brew --cellar), etc. don't invoke the full Homebrew installation (they short-circuit to shell script instead), so using these where possible in scripts makes the resulting bottle portable while adding minimal performance cost.

A resulting env script might look something like this:

#!/bin/bash
JAVA_HOME="${JAVA_HOME:-$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home}" exec "$(brew --cellar)/mill/0.9.8/libexec/mill"  "$@"

I'm especially open to input on the naming of any of the new methods introduced in this PR. Wasn't really sure about a most suitable name so just went with my gut for now.

Note: I'm not happy with the tests for the additional Java methods right now. In the test env, they evaluate to $(brew --prefix)/opt/openjdk/libexec/... when in practice (from testing with formulae) it actually produces a more desired $(brew --prefix openjdk)/libexec/.... Both are technically correct (when openjdk is installed), but just wanted to point out this slight discrepancy. I think this is due to how the openjdk formula is being mocked in that test, but after trying to manually set up folders/symlink them where appropriate in the test, I still couldn't get it working exactly as desired.

@BrewTestBot
Copy link
Member

Review period will end on 2021-06-16 at 01:53:16 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jun 15, 2021
Copy link
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.

I like the idea but implementation needs some tweaks!

@alebcay
Copy link
Member Author

alebcay commented Jun 15, 2021

Moved some things around. Now the new methods live in utils/path.

@alebcay alebcay requested a review from MikeMcQuaid June 15, 2021 13:32
@alebcay alebcay changed the title extend/pathname: shortened brew paths Utils: shortened brew paths Jun 15, 2021
Copy link
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! 🎉

@BrewTestBot BrewTestBot added waiting for feedback Merging is blocked until sufficient time has passed for review and removed waiting for feedback Merging is blocked until sufficient time has passed for review labels Jun 16, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jun 16, 2021
@MikeMcQuaid MikeMcQuaid merged commit 6a5891f into Homebrew:master Jun 16, 2021
mistydemeo added a commit to mistydemeo/brew that referenced this pull request Jun 18, 2021
@mistydemeo mistydemeo mentioned this pull request Jun 18, 2021
7 tasks
mistydemeo added a commit that referenced this pull request Jun 18, 2021
@github-actions github-actions bot added the outdated PR was locked due to age label Jul 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants