The BuildOptions object is instantiated once and then shared by every Formula object that gets created. This is troublesome when upgrading because there is no way to modify ARGV by temporarily loading options from a prior install receipt so that f.recursive_deps will properly return the dependencies of a formula.
This is addressed indirectly by #14456; dependencies should no longer be declared using language-level conditionals, but rather via metadata that is examined during expansion in the installer. I've eliminated the ad-hoc dependency expansion in upgrade and moved it back into the installer.
Now that I finally have some free time over the holidays, I intend to complete this work.
Perfect. Thanks tackling this one Jack!
#14456 is merged. Dependencies declared with :optional and :recommended now generate options, eliminating the need for depends_on :foo if build.include? "with-foo" style declarations.
depends_on :foo if build.include? "with-foo"
This doesn't cover all use cases (for example, an option that includes more than one dependency still requires real Ruby conditionals) but more work will be done to clean this up, e.g. #14315.