formula_installer: default_formula using build.

Use the build options instead of whether the requirement is optional to
work out if it is needed. This handles the case of an optional
requirement becoming needed because it's a dependency for another
formula.

Closes #31476.