Refactor build_tools/build_detect_version