-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Use cached json API file for formulae and cask specified paths #17615
Conversation
I'm seeing some places where brew/Library/Homebrew/cmd/info.rb Lines 252 to 254 in 5e7765c
It seems like there is an assumption that casks should be loadable from the source file path as well. This kind of breaks that assumption doesn't it. In practice, it shouldn't matter since a lot of those places are wrapped in without API blocks but it does make the code harder to reason about and possibly more error prone. brew/Library/Homebrew/dev-cmd/bump.rb Line 346 in 5e7765c
I wonder if there's a better place to apply this change so that the path is consistent in |
I guess you could argue that that assumption has already been broken for a while though since it's been nullable this whole time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to Formula#specified_path
seems reasonable. The only place it's really used has a check for formulas that have been loaded from the API.
brew/Library/Homebrew/formula_installer.rb
Lines 1109 to 1136 in 5e7765c
def post_install_formula_path | |
# Use the formula from the keg when any of the following is true: | |
# * We're installing from the JSON API | |
# * We're installing a local bottle file | |
# * The formula doesn't exist in the tap (or the tap isn't installed) | |
# * The formula in the tap has a different `pkg_version``. | |
# | |
# In all other cases, including if the formula from the keg is unreadable | |
# (third-party taps may `require` some of their own libraries) or if there | |
# is no formula present in the keg (as is the case with very old bottles), | |
# use the formula from the tap. | |
keg_formula_path = formula.opt_prefix/".brew/#{formula.name}.rb" | |
return keg_formula_path if formula.loaded_from_api? | |
return keg_formula_path if formula.local_bottle_path.present? | |
tap_formula_path = formula.specified_path | |
return keg_formula_path unless tap_formula_path.exist? | |
begin | |
keg_formula = Formulary.factory(keg_formula_path) | |
tap_formula = Formulary.factory(tap_formula_path) | |
return keg_formula_path if keg_formula.pkg_version != tap_formula.pkg_version | |
tap_formula_path | |
rescue FormulaUnavailableError, FormulaUnreadableError | |
tap_formula_path | |
end | |
end |
Maybe it'd make more sense to have two methods that distinguish diagnostic paths, like those used in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. I agree with @apainintheneck in might be nice to differentiate between "location on disk this was loaded from" and "where we'd expect this to be" but: that can (and should) be in a follow-up PR.
One optional naming tweak and this is good to go (without a rereview being needed).
Personally: I'm not sure we should ever be outputting non-loadable paths to users. I agree in the receipts, if we want/need two paths, to always have a differentiation between "loaded from" and "expected location on disk" is valuable but, even then, I wonder about the merits of including paths that don't/won't exist here. Feels unnecessarily confusing. |
You're right about the I agree, it does kind of seem like there should be two distinct path methods (which is also what we have in formulae with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this approach. Worst-case scenario we get an error message because someone tried to load a cask using the source file path outside of a without API block. That error message should be explanatory enough and easy to fix. Adding another method wouldn't really help things. Thanks for humoring my idea while I thought it out though.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This PR aligns
Formula#specified_path
andCask#sourcefile_path
with each other. Now, when loading from the API, these methods return the file path of the cached JSON API file that was used byHomebrew::API
when loading. If the formula/cask was loaded from a ruby file, that file is returned. If the cask was loaded directly from a different JSON file, the path to that file is returned, instead.Addressing a discussion point from #17554 (comment): both
ruby_source_path
andruby_source_checksum
are manually set when loading from the API, so those methods don't need to be adjusted with this change.Loading a formula
From the API
Without the API
Directly from a ruby file
Loading a cask
From the API
Without the API
Directly from a ruby file
Directly from a json file