Currently, all code-generation in Idol is performed by free functions. This is problematic for adding new configuration parameters to the API, as adding an additional parameter to these functions is a breaking change, requiring "every build script in Hubris" to be updated. On the other hand, the current API surface already has a bunch of functions that essentially call another function with one parameter excluded, such as build_server_support and build_restricted_server_support; adding new parameters which are defaulted in this manner gets unwieldy very fast.
Therefore, this commit introduces a Generator type, which serves as a builder pattern for code generation settings. The bodies of the existing free functions have been moved to methods on Generator, with the free functions now being thin wrappers around
Generator::default().<the_function>(). This way, we can freely add any number of new configuration options to the Generator struct, without having to worry about breaking all callers of the code generation.
Right now the only parameter configured by Generator is whether or not to run prettyplease formatting on the generated code. In the future, it will also be used to configure automatic counter generation (this change was factored out from PR #41 to make that diff easier to review).
Currently, all code-generation in Idol is performed by free functions. This is problematic for adding new configuration parameters to the API, as adding an additional parameter to these functions is a breaking change, requiring "every build script in Hubris" to be updated. On the other hand, the current API surface already has a bunch of functions that essentially call another function with one parameter excluded, such as
build_server_support
andbuild_restricted_server_support
; adding new parameters which are defaulted in this manner gets unwieldy very fast.Therefore, this commit introduces a
Generator
type, which serves as a builder pattern for code generation settings. The bodies of the existing free functions have been moved to methods onGenerator
, with the free functions now being thin wrappers aroundGenerator::default().<the_function>()
. This way, we can freely add any number of new configuration options to theGenerator
struct, without having to worry about breaking all callers of the code generation.Right now the only parameter configured by
Generator
is whether or not to runprettyplease
formatting on the generated code. In the future, it will also be used to configure automatic counter generation (this change was factored out from PR #41 to make that diff easier to review).