brew icon indicating copy to clipboard operation
brew copied to clipboard

New formula internal json v3 dependencies format

Open apainintheneck opened this issue 2 months ago • 1 comments

  • [x] Have you followed the guidelines in our Contributing document?
  • [x] Have you checked to ensure there aren't other open Pull Requests for the same change?
  • [x] 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.
  • [x] Have you successfully run brew style with your changes locally?
  • [x] Have you successfully run brew typecheck with your changes locally?
  • [ ] Have you successfully run brew tests with your changes locally?

See https://github.com/Homebrew/brew/issues/16410#issuecomment-1963079892

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 avatar Apr 26 '24 04:04 apainintheneck

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?

MikeMcQuaid avatar Apr 30 '24 08:04 MikeMcQuaid

I'm hoping that I've addressed all of the feedback in https://github.com/Homebrew/brew/pull/17153/commits/6ad02b8e340e163ce90beccb33d0f297d96e7b03. 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 avatar May 01 '24 06:05 apainintheneck

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

apainintheneck avatar May 01 '24 06:05 apainintheneck

Thanks @apainintheneck!

MikeMcQuaid avatar May 01 '24 07:05 MikeMcQuaid