|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import sys |
| 4 | + |
| 5 | +import yaml |
| 6 | + |
| 7 | +DOC_HEADER = """# File auto-generated on build process. Do not change it. |
| 8 | +# Add new dependencies to dependencies.yaml file instead. |
| 9 | +# |
| 10 | +""" |
| 11 | + |
| 12 | + |
| 13 | +def generate_files(os_distro): |
| 14 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 15 | + with open(os.path.join(current_dir, '../dependencies.yaml')) as fd: |
| 16 | + content = yaml.safe_load(fd) |
| 17 | + |
| 18 | + dev_deps = content.get('development-deps', {}) |
| 19 | + dev_deps = dev_deps.get('common', []) + dev_deps.get(os_distro, []) |
| 20 | + |
| 21 | + runtime_deps = content.get('runtime-deps', {}) |
| 22 | + runtime_deps = runtime_deps.get('common', []) + runtime_deps.get(os_distro, []) |
| 23 | + |
| 24 | + if os_distro == 'ubuntu': |
| 25 | + pkg_deps = 'Depends: ' + ',\n\t'.join(runtime_deps) |
| 26 | + pkg_deps += '\nBuild-Depends: ' + ',\n\t'.join(dev_deps) |
| 27 | + |
| 28 | + elif os_distro in ['fedora', 'opensuse-leap']: |
| 29 | + pkg_deps = '\n'.join(['Requires:\t' + d for d in runtime_deps]) |
| 30 | + pkg_deps += '\n' + '\n'.join(['BuildRequires:\t' + d for d in dev_deps]) |
| 31 | + |
| 32 | + else: |
| 33 | + raise Exception('Unsupported OS distribution') |
| 34 | + |
| 35 | + with open(f'{current_dir}/{os_distro}-pkg-deps', 'w') as fd: |
| 36 | + fd.write(pkg_deps) |
| 37 | + |
| 38 | + with open(f'{current_dir}/../{os_distro}-dev-deps.list', 'w') as fd: |
| 39 | + fd.write(DOC_HEADER + '\n'.join(dev_deps)) |
| 40 | + |
| 41 | + with open(f'{current_dir}/../{os_distro}-runtime-deps.list', 'w') as fd: |
| 42 | + fd.write(DOC_HEADER + '\n'.join(runtime_deps)) |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == '__main__': |
| 46 | + for os_distro in ['ubuntu', 'fedora', 'opensuse-leap']: |
| 47 | + try: |
| 48 | + generate_files(os_distro) |
| 49 | + except Exception: |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | + sys.exit(0) |
0 commit comments