refactor buildstep.py into smaller bits (backport from nine)