def METHOD_NAME() -> int:
    logging.basicConfig(
        level=logging.INFO,
        format="[" + os.path.basename(__file__) + "] %(asctime)s %(levelname)s: %(message)s")
    parser = argparse.ArgumentParser(usage="usage: gen_version_info.py <output_path>")
    parser.add_argument("--build-type", help="Set build type", type=str)
    parser.add_argument("--git-hash", help="Set git hash", type=str)
    parser.add_argument("output_path", help="Output file to be generated.", type=str)
    args = parser.parse_args()
    output_path = args.output_path
    hostname = socket.gethostname()
    build_time = "%s %s" % (strftime("%d %b %Y %H:%M:%S", localtime()), time.tzname[0])
    username: Optional[str]
    try:
        username = os.getlogin()
    except OSError as ex:
        logging.warning(("Got an OSError trying to get the current user name, " +
                         "trying a workaround: {}").format(ex))
        # https://github.com/gitpython-developers/gitpython/issues/39
        try:
            username = pwd.getpwuid(os.getuid()).pw_name
        except KeyError:
            username = os.getenv('USER')
            if not username:
                id_output = subprocess.check_output('id').decode('utf-8').strip()
                ID_OUTPUT_RE = re.compile(r'^uid=\d+[(]([^)]+)[)]\s.*')
                match = ID_OUTPUT_RE.match(id_output)
                if match:
                    username = match.group(1)
                else:
                    logging.warning(
                        "Couldn't get user name from the environment, either parse 'id' output: %s",
                        id_output)
                    raise
    git_repo_dir = get_yb_src_root_from_build_root(os.getcwd(), must_succeed=False, verbose=True)
    if git_repo_dir:
        clean_repo = is_git_repo_clean(git_repo_dir)
    else:
        clean_repo = False
    git_hash: Optional[str]
    if args.git_hash:
        # Git hash provided on the command line.
        git_hash = args.git_hash
    elif 'YB_VERSION_INFO_GIT_SHA1' in os.environ:
        git_hash = os.environ['YB_VERSION_INFO_GIT_SHA1']
        logging.info("Git SHA1 provided using the YB_VERSION_INFO_GIT_SHA1 env var: %s", git_hash)
    elif git_repo_dir:
        # No command line git hash, find it in the local git repository.
        git_hash = get_git_sha1(git_repo_dir)
    else:
        git_hash = None
    path_to_version_file = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "..", "..", "version.txt")
    with open(path_to_version_file) as version_file:
        version_string = version_file.read().strip()
    match = re.match(r"(\d+\.\d+\.\d+\.\d+)", version_string)
    if not match:
        parser.error("Invalid version specified: {}".format(version_string))
        sys.exit(1)
    version_number = match.group(1)
    build_type = args.build_type
    # Add the Jenkins build ID
    build_id = os.getenv("BUILD_ID", "")
    # This will be replaced by the release process.
    build_number = os.getenv("YB_RELEASE_BUILD_NUMBER") or "PRE_RELEASE"
    d = os.path.dirname(output_path)
    if d != "" and not os.path.exists(d):
        os.makedirs(d)
    log_file_path = os.path.join(d, os.path.splitext(os.path.basename(__file__))[0] + '.log')
    file_log_handler = logging.FileHandler(log_file_path)
    file_log_handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s: %(message)s"))
    logging.getLogger('').addHandler(file_log_handler)
    data = {
            "git_hash": git_hash,
            "build_hostname": hostname,
            "build_timestamp": build_time,
            "build_username": username,
            # In version_info.cc we expect build_clean_repo to be a "true"/"false" string.
            "build_clean_repo": boolean_to_json_str(clean_repo),
            "build_id": build_id,
            "build_type": build_type,
            "version_number": version_number,
            "build_number": build_number
            }
    content = json.dumps(data)
    # Frequently getting errors here when rebuilding on NFS:
    # https://gist.githubusercontent.com/mbautin/572dc0ab6b9c269910c1a51f31d79b38/raw
    attempts_left = 10
    while attempts_left > 0:
        try:
            with open(output_path, "w") as f:
                f.write(content)
            break
        except IOError as ex:
            if attempts_left == 0:
                raise ex
            if 'Resource temporarily unavailable' in str(ex):
                time.sleep(0.1)
        attempts_left -= 1
    return 0