107 lines
4.4 KiB
Python
107 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
SPDX-FileCopyrightText: 2023-2025 PeppermintOS Team
|
|
(peppermintosteam@proton.me)
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
This module is responsible for installing common packages into the root filesystem (rootfs)
|
|
of the PeppermintOS build. It reads the list of packages to be installed from a YAML file
|
|
and uses the XBPS package manager to perform the installation according to the
|
|
host-execution strategy.
|
|
|
|
Credits:
|
|
- PeppermintOS Team (peppermintosteam@proton.me) - Development and maintenance of the project.
|
|
|
|
License:
|
|
This code is distributed under the GNU General Public License version 3 or later (GPL-3.0-or-later).
|
|
For more details, please refer to the LICENSE file included in the project or visit:
|
|
https://www.gnu.org/licenses/gpl-3.0.html
|
|
"""
|
|
|
|
import yaml
|
|
import logging
|
|
import sys
|
|
import os
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
sys.path.insert(0, BASE_DIR)
|
|
|
|
try:
|
|
from builder.core.command_runner import run_command
|
|
from builder.configs import logger_config
|
|
from builder.core.config_loader import load_yaml_config
|
|
from builder.core import bootstrap
|
|
|
|
logger = logger_config.setup_logger('packages_install')
|
|
except ImportError as e:
|
|
try:
|
|
basic_logger = logging.getLogger(__name__)
|
|
logging.basicConfig(level=logging.ERROR)
|
|
basic_logger.error(f"Error importing necessary modules for packages_install: {e}. Ensure your environment is set up correctly.")
|
|
except Exception:
|
|
print(f"Error importing necessary modules for packages_install: {e}. Ensure your environment is set up correctly.")
|
|
sys.exit(1)
|
|
|
|
|
|
def install_common_packages_rootfs_yaml(paths, common_packages_yaml_path, target_architecture, host_architecture, repositories_data):
|
|
"""
|
|
Installs common packages into the rootfs from a YAML file, using the host-execution strategy.
|
|
|
|
Args:
|
|
paths (dict): Dictionary of build paths. Required to get rootfs path and cache dir.
|
|
common_packages_yaml_path (str): Path to the YAML file containing the common package lists.
|
|
Expected structure: {<architecture>: [package list]}
|
|
target_architecture (str): The target architecture (e.g., 'aarch64').
|
|
host_architecture (str): The architecture of the host system.
|
|
repositories_data (list): List of repository dictionaries from YAML config.
|
|
Expected structure: [{'name': '...', 'uri': '...', 'architectures': [...]}, ...]
|
|
|
|
Raises:
|
|
subprocess.CalledProcessError: If the xbps-install command fails.
|
|
ValueError: If configuration data is missing or incorrect.
|
|
KeyError: If required paths are not found.
|
|
"""
|
|
|
|
logger.info(f"=> Installing common packages into ROOTFS ({target_architecture}) using YAML: {common_packages_yaml_path}")
|
|
|
|
if not isinstance(paths, dict):
|
|
logger.error("Paths dictionary is missing or incorrect.")
|
|
raise ValueError("Paths dictionary is required.")
|
|
|
|
try:
|
|
common_packages_config = load_yaml_config(common_packages_yaml_path, os.path.basename(common_packages_yaml_path))
|
|
except Exception as e:
|
|
logger.error(f"Error loading common packages YAML '{common_packages_yaml_path}': {e}")
|
|
raise
|
|
|
|
common_packages_for_arch = common_packages_config.get(target_architecture, [])
|
|
|
|
if not common_packages_for_arch:
|
|
logger.warning(f"No common packages defined for architecture {target_architecture} in {common_packages_yaml_path}. Skipping installation.")
|
|
return
|
|
|
|
adapted_package_structure = {"rootfs": {target_architecture: common_packages_for_arch}}
|
|
|
|
common_packages_args = bootstrap.construct_xbps_install_args(
|
|
"rootfs",
|
|
paths,
|
|
target_architecture,
|
|
repositories_data,
|
|
adapted_package_structure
|
|
)
|
|
|
|
if not common_packages_args:
|
|
logger.warning("Skipping common packages installation due to failure in constructing xbps-install arguments.")
|
|
return
|
|
|
|
common_install_command = ["/usr/bin/xbps-install"] + common_packages_args
|
|
|
|
logger.info(f"Executing common packages installation command (host): {' '.join(common_install_command)}")
|
|
try:
|
|
run_command(common_install_command)
|
|
logger.info(f"=> Installation of common packages into ROOTFS completed.")
|
|
except Exception as e:
|
|
logger.error(f"Error executing XBPS_INSTALL_CMD for common packages: {e}")
|
|
raise
|