#!/usr/bin/env python3

##  Copyright (c) 2023 caryoscelus
##
##  zeronet-conservancy is free software: you can redistribute it and/or modify it under the
##  terms of the GNU General Public License as published by the Free Software
##  Foundation, either version 3 of the License, or (at your option) any later version.
##
##  zeronet-conservancy is distributed in the hope that it will be useful, but
##  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
##  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
##  details.
##
## You should have received a copy of the GNU General Public License along with
## zeronet-conservancy. If not, see <https://www.gnu.org/licenses/>.
##

"""A small script to generate build info"""

from util import Git

import sys

def main(argv):
    if len(argv) < 2:
        print(f'Useage: {argv[0]} <build-type>')
        print('Known build types:')
        sys.exit(1)
    else:
        writeBuildInfo(argv[1])

def writeBuildInfo(build_type):
    bvars = {
        'build_type': build_type,
        'branch': Git.branch(),
        'commit': Git.commit(),
    }
    code = '\n'.join(f'{var} = {repr(val)}' for var, val in bvars.items())
    content = \
        '# auto-generated by buildinfo.py\n' \
        '# This file should not persist in git tree\n' + code + '\n'
    with open('src/Build.py', 'w') as f:
        f.write(content)

if __name__ == '__main__':
    from sys import argv
    main(argv)
