Move a bunch of build.py functionality into functions that could be used by external project