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

New formula internal json v3 dependencies format #17153

Conversation

apainintheneck
Copy link
Contributor

@apainintheneck apainintheneck commented Apr 26, 2024

  • 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?

See #16410 (comment)

This implements a new way of storing dependencies in the internal formula JSON v3 format. The goal is that this format is easier to understand at a glance, easier to generate and easier to parse. I think with this PR two of those three goals have been achieved.

The parsing code ended up being a similar level of complexity to what we saw before. In the end, the JSON output will be slightly larger as mentioned in the thread linked above but the overall JSON size will still be much smaller than before. We're talking about half a megabyte difference when the total savings will end up being around 11 megabytes out of what was originally a 24 megabyte file (I haven't double-checked these numbers but they should be in the neighborhood and more details can be found in the thread).

The generation code is much simpler than before. Take a look at the old Formula#dependencies_hash method and the new Formula#dependencies_list method.

The biggest risk here is that it affects JSON generation for the public formula JSON v2 format or that the current JSON parsing logic doesn't work the same way it did before. If there are any problems with the internal JSON v3 parsing, no one's using it right now so it's not a big deal.

@apainintheneck apainintheneck added the install from api Relates to API installs label Apr 26, 2024
@apainintheneck apainintheneck changed the title WIP: New formula json dependencies format WIP: New formula internal json v3 dependencies format Apr 26, 2024
@apainintheneck apainintheneck force-pushed the new-formula-json-dependencies-format branch from 32ee8ae to 541305a Compare April 28, 2024 01:09
@apainintheneck apainintheneck changed the title WIP: New formula internal json v3 dependencies format New formula internal json v3 dependencies format Apr 30, 2024
@apainintheneck apainintheneck marked this pull request as ready for review April 30, 2024 05:39
@MikeMcQuaid
Copy link
Member

The biggest risk here is that it affects JSON generation for the public formula JSON v2 format or that the current JSON parsing logic doesn't work the same way it did before.

Might be nice to verify this by manually generating the formulae.brew.sh API output and diffing them?

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.

Looks good. All comments non-blocking. Happy to merge and iterate further. Thanks @apainintheneck!

Library/Homebrew/formula.rb Outdated Show resolved Hide resolved
return if spec_symbol != :stable && spec_symbol != :head

send(spec_symbol)&.declared_deps&.each_with_object({}) do |dep, dep_hash|
next if dep.implicit? # Remove all implicit deps
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to say why they are being removed rather than that they are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment was copied from the old logic. I'll do some digging and update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like implicit dependencies are really only needed when building from source and are used when downloading and unpacking files. See DependencyCollector for more details.

Library/Homebrew/formula.rb Outdated Show resolved Hide resolved
- rename #dependencies_list to #internal_dependencies_hash
  - the initial implementation returned an array but now it doesn't
- simplify usage of #tap in #internal_dependencies_hash
- remove safe navigation operator usages in #internal_dependencies_hash
- better document why implicit dependencies are not included in the API JSON
- add new test fixture formula to better test generation of uses from
  macos bounds with the new internal json format
@apainintheneck
Copy link
Contributor Author

I'm hoping that I've addressed all of the feedback in 6ad02b8. Let me know if there's anything I've missed.

It adds a new test for a formula with uses from macOS bounds, cleans up syntax and adds some more documentation.

@apainintheneck
Copy link
Contributor Author

The biggest risk here is that it affects JSON generation for the public formula JSON v2 format or that the current JSON parsing logic doesn't work the same way it did before.

Might be nice to verify this by manually generating the formulae.brew.sh API output and diffing them?

Yeah, I ran some extra tests locally and everything looks good to me. I'm not too worried about the generation side of things since that's relatively easy to test. The loading side is a bit more difficult but I didn't really touch anything that should affect the JSON v2 loading logic and those things are covered by some tests too. It was more just to let everyone know in case something goes haywire.

$ brew api-readall-test --formula
Generating formulae API ... and mocking formula API loader.
Read core formula and saw no failures!
$ brew generate-api-diff --formula --stat
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Switched to branch 'new-formula-json-dependencies-format'
 .../api/internal/v3/homebrew-core.json                                                                          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Note: It makes sense that the internal JSON v3 file is different after this change but everything else looks to be identical.

See my repo with dev commands for more info about each of them: https://github.com/apainintheneck/homebrew-dev-utils

@MikeMcQuaid MikeMcQuaid merged commit 7c0b989 into Homebrew:master May 1, 2024
25 checks passed
@MikeMcQuaid
Copy link
Member

Thanks @apainintheneck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
install from api Relates to API installs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants