build: move build methods into a class
build: make deps an attribute of Build
build: expand requirements only once
build: expand dependencies only once

Closes #20081.