diff options
Diffstat (limited to 'scripts/package-build/build.py')
-rwxr-xr-x | scripts/package-build/build.py | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/scripts/package-build/build.py b/scripts/package-build/build.py index 99180e17..9c1df7b3 100755 --- a/scripts/package-build/build.py +++ b/scripts/package-build/build.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2024 VyOS maintainers and contributors +# Copyright (C) 2024-2025 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 @@ -58,7 +58,6 @@ def apply_patches(repo_dir: Path, patch_dir: Path) -> None: series.write(patch.name + '\n') print(f"I: Applied patch: {patch.name}") - def prepare_package(repo_dir: Path, install_data: str) -> None: """Prepare a package""" if not install_data: @@ -75,12 +74,11 @@ def prepare_package(repo_dir: Path, install_data: str) -> None: raise -def build_package(package: list, dependencies: list, patch_dir: Path) -> None: +def build_package(package: list, patch_dir: Path) -> None: """Build a package from the repository Args: package (list): List of Packages from toml - dependencies (list): List of additional dependencies patch_dir (Path): Directory containing patches """ repo_name = package['name'] @@ -94,12 +92,51 @@ def build_package(package: list, dependencies: list, patch_dir: Path) -> None: # Check out the specific commit run(['git', 'checkout', package['commit_id']], cwd=repo_dir, check=True) - # Ensure dependencies - ensure_dependencies(dependencies) - - # Apply patches if any - if (repo_dir / 'patches'): - apply_patches(repo_dir, patch_dir) + # The `pre_build_hook` is an optional configuration defined in `package.toml`. + # It executes after the repository is checked out and before the build process begins. + # This hook allows you to perform preparatory tasks, such as creating directories, + # copying files, or running custom scripts/commands. + # + # Usage: + # - Single command: + # pre_build_hook = "echo 'Hello Pre-Build-Hook'" + # + # - Multi-line commands: + # pre_build_hook = """ + # mkdir -p ../hello/vyos + # mkdir -p ../vyos + # cp example.txt ../vyos + # """ + # + # - Combination of commands and scripts: + # pre_build_hook = "ls -l; ./script.sh" + pre_build_hook = package.get('pre_build_hook', '') + if pre_build_hook: + try: + print(f'I: execute pre_build_hook for the package "{repo_name}"') + run(pre_build_hook, cwd=repo_dir, check=True, shell=True) + except CalledProcessError as e: + print(e) + print(f"I: pre_build_hook failed for the {repo_name}") + raise + + # Apply patches if the 'apply_patches' key is set to True (default) in the package configuration + # This allows skipping patch application for specific packages when desired + # + # Usage: + # apply_patches = false + # + # Default to True if the key is missing + if package.get('apply_patches', True): + # Check if the 'patches' directory exists in the repository + if (repo_dir / 'patches'): + apply_patches(repo_dir, patch_dir / repo_name) + + # Sanitize the commit ID and build a tarball for the package + commit_id_sanitized = package['commit_id'].replace('/', '_') + tarball_name = f"{repo_name}_{commit_id_sanitized}.tar.gz" + run(['tar', '-czf', tarball_name, '-C', str(repo_dir.parent), repo_name], check=True) + print(f"I: Tarball created: {tarball_name}") # Prepare the package if required if package.get('prepare_package', False): @@ -171,11 +208,14 @@ if __name__ == '__main__': packages = config['packages'] patch_dir = Path(args.patch_dir) - for package in packages: - dependencies = package.get('dependencies', {}).get('packages', []) + # Load global dependencies + global_dependencies = config.get('dependencies', {}).get('packages', []) + if global_dependencies: + ensure_dependencies(global_dependencies) + for package in packages: # Build the package - build_package(package, dependencies, patch_dir) + build_package(package, patch_dir) # Clean up build dependency packages after build cleanup_build_deps(Path(package['name'])) |