Skip to content

Serialize FormulaStructs in the internal API#21456

Merged
Rylan12 merged 1 commit intomainfrom
serialize-formula-structs
Feb 1, 2026
Merged

Serialize FormulaStructs in the internal API#21456
Rylan12 merged 1 commit intomainfrom
serialize-formula-structs

Conversation

@Rylan12
Copy link
Copy Markdown
Member

@Rylan12 Rylan12 commented Jan 26, 2026

This is a cleaner attempt of #21429.

I've added serialize and deserialize methods to FormulaStruct to efficiently store formula data in JSON format. After the simplifications made in #21455, the code needed to accomplish this is pretty straightforward.

The goal is that the only special handling needed in FormulaStruct#serialize and FormulaStruct#deserialize is for cases where there is a simpler way to store the data than is needed by Formulary. At the moment, the only two customizations needed are:

  • bottle data: only need to store the relevant checksum (and can leave information like the bottle tag, cellar, and rebuild if they are the default values)
  • dependency/uses_from_macos information: deduplicate dependencies that are both stable and head deps by storing shared dependencies separately

I also added a handful of methods to Utils so they can, eventually, be used by CaskStruct. I've added tests for all of these methods.

@Rylan12 Rylan12 force-pushed the serialize-formula-structs branch from b36efc6 to 4742a6e Compare January 26, 2026 02:23
@Rylan12 Rylan12 force-pushed the extract-formula-struct-generator branch from 671bca4 to f91a070 Compare January 26, 2026 02:23
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.

Thanks! Good to merge when comments addressed.

@Rylan12 Rylan12 force-pushed the extract-formula-struct-generator branch 2 times, most recently from f552819 to 7f0c605 Compare January 26, 2026 15:23
@Rylan12 Rylan12 force-pushed the serialize-formula-structs branch from 4742a6e to 517a518 Compare January 26, 2026 15:23
Base automatically changed from extract-formula-struct-generator to main January 26, 2026 16:05
@Rylan12 Rylan12 force-pushed the serialize-formula-structs branch 2 times, most recently from 59813a2 to 905ec90 Compare January 31, 2026 15:07
Copilot AI review requested due to automatic review settings January 31, 2026 15:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds serialization and deserialization functionality to FormulaStruct to enable efficient JSON storage for the internal API. The implementation provides methods to convert FormulaStruct instances to/from JSON-compatible hashes, with special handling for bottle data (storing only relevant checksums and omitting default values) and comprehensive utility methods for symbol/string conversion and removing blank values.

Changes:

  • Added serialize and deserialize methods to FormulaStruct with special bottle handling
  • Implemented utility methods (format_arg_pair, stringify_symbol, deep_stringify_symbols, deep_unstringify_symbols, deep_compact_blank) for data transformation
  • Updated generate-formula-api.rb to use the new serialization instead of the previous custom implementation
  • Added tests for all new utility methods

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Library/Homebrew/api/formula_struct.rb Core implementation: adds serialization constants, serialize/deserialize methods, and utility methods for symbol handling and data compaction
Library/Homebrew/dev-cmd/generate-formula-api.rb Refactored to use new serialization methods, replacing ~50 lines of custom logic with a simple serialize() call
Library/Homebrew/test/api/formula_struct_spec.rb Added comprehensive tests for utility methods (format_arg_pair, stringify_symbol, deep_stringify_symbols, deep_unstringify_symbols, deep_compact_blank)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Rylan12 Rylan12 force-pushed the serialize-formula-structs branch from 905ec90 to e1396c7 Compare January 31, 2026 15:55
@Rylan12
Copy link
Copy Markdown
Member Author

Rylan12 commented Jan 31, 2026

Okay, assuming CI is good here, let's merge so we can get the JSON files in formulae.brew.sh, and move onto the next step

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.

Looks good thanks! Can self-merge as-is with or without changes.

@Rylan12 Rylan12 enabled auto-merge February 1, 2026 13:56
@Rylan12 Rylan12 force-pushed the serialize-formula-structs branch from 4244d36 to ad57998 Compare February 1, 2026 14:08
@Rylan12 Rylan12 added this pull request to the merge queue Feb 1, 2026
Merged via the queue into main with commit c8fbbb7 Feb 1, 2026
37 checks passed
@Rylan12 Rylan12 deleted the serialize-formula-structs branch February 1, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants