Serialize FormulaStructs in the internal API#21456
Conversation
b36efc6 to
4742a6e
Compare
671bca4 to
f91a070
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks! Good to merge when comments addressed.
f552819 to
7f0c605
Compare
4742a6e to
517a518
Compare
59813a2 to
905ec90
Compare
There was a problem hiding this comment.
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
serializeanddeserializemethods toFormulaStructwith 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.rbto 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.
905ec90 to
e1396c7
Compare
|
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 |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Looks good thanks! Can self-merge as-is with or without changes.
4244d36 to
ad57998
Compare
This is a cleaner attempt of #21429.
I've added
serializeanddeserializemethods toFormulaStructto 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#serializeandFormulaStruct#deserializeis for cases where there is a simpler way to store the data than is needed byFormulary. At the moment, the only two customizations needed are:uses_from_macosinformation: deduplicate dependencies that are both stable and head deps by storing shared dependencies separatelyI also added a handful of methods to
Utilsso they can, eventually, be used byCaskStruct. I've added tests for all of these methods.