diff options
author | zsdc <taras@vyos.io> | 2023-06-20 15:58:56 +0300 |
---|---|---|
committer | zsdc <taras@vyos.io> | 2023-06-20 18:04:07 +0300 |
commit | fee69c5c7cafb2959b8b46b22c105b9c1eb82176 (patch) | |
tree | 27d09e1bd37b8e32ae3524003d4dc6211e3956ef /packages/vpp/build.py | |
parent | deb4cb7f4d4b3f5a9b132b7c4528d4b94329a89f (diff) | |
download | vyos-build-fee69c5c7cafb2959b8b46b22c105b9c1eb82176.tar.gz vyos-build-fee69c5c7cafb2959b8b46b22c105b9c1eb82176.zip |
VPP: T1797: Added build scripts for VPP
Diffstat (limited to 'packages/vpp/build.py')
-rwxr-xr-x | packages/vpp/build.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/packages/vpp/build.py b/packages/vpp/build.py new file mode 100755 index 00000000..d1dd54b1 --- /dev/null +++ b/packages/vpp/build.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +from argparse import ArgumentParser +from pathlib import Path +from subprocess import run +from sys import exit +from json import load as json_load + + +def check_args(args) -> bool: + """Check command arguments + + Args: + args (Namespace): Namespace with arguments + + Returns: + bool: check result + """ + sources_dir = Path(f'../{args.package}') + if not sources_dir.exists(): + print(f'Sourced directory {sources_dir.as_posix()} does not exist') + return False + return True + + +# apply patches +def apply_patches(package_name: str) -> bool: + """Apply patches to sources directory + + Args: + package_name (str): package name (the same as sources directory) + """ + patches_dir = Path(f'../patches/{package_name}') + if patches_dir.exists(): + for patch_file in patches_dir.iterdir(): + patch_cmd: list[str] = [ + 'git', '-c', 'user.email=support@vyos.io', '-c', + 'user.name=vyos', 'am', + patch_file.as_posix() + ] + print(f'Applying patch: {patch_file.name}') + if run(patch_cmd).returncode != 0: + return False + return True + + +def build_package(package_name: str) -> bool: + """Build a package using commands from external file + + Args: + package_name (str): package name + + Returns: + bool: build status + """ + build_config_path: str = f'../build_{package_name}.json' + with open(build_config_path, 'r') as openfile: + try: + build_params = json_load(openfile) + except Exception as err: + print(f'Error parsing config file {build_config_path}: {err}') + return False + + for cmd in build_params.get('build_commands', []): + print(f'Building: {cmd}') + if run(cmd).returncode != 0: + return False + + return True + + +# build a package +if __name__ == '__main__': + # prepare argument parser + arg_parser = ArgumentParser() + arg_parser.add_argument('--package', + required=True, + help='Package name to build') + args = arg_parser.parse_args() + + if not check_args(args): + exit(1) + + if not apply_patches(args.package): + exit(1) + + if not build_package(args.package): + exit(1) + + exit() |