File: //opt/saltstack/salt/lib/python3.10/site-packages/ppbt/__pycache__/common.cpython-310.pyc
o
�N�g� � @ s� d Z ddlZddlZddlZddlZddlZddlZdZe�e �Z
G dd� de�Zddd�Z
dd � Ze
e� �Ze�e�jd
e� d� Ze�e�jd
Zee Ze�e��� jjde� d
� Zdd� Zddd�Zddd�ZdS )z
Toolchain build environment.
� Nz0.1.8c @ s e Zd ZdZdS )�
PPBTExceptionz.
Base class for all ppbt exceptions.
N)�__name__�
__module__�__qualname__�__doc__� r r �?/opt/saltstack/salt/lib/python3.10/site-packages/ppbt/common.pyr s r c C sX |st j}| s
t� } |dkr| � d�S |dkr| � d�S |dkr%| � d�S td|� ���)a�
Get the target triplet for the specified machine and platform.
If any of the args are None, it will try to deduce what they should be.
:param machine: The machine for the triplet
:type machine: str
:param plat: The platform for the triplet
:type plat: str
:raises BuildError: If the platform is unknown
:return: The target triplet
:rtype: str
�darwinz-macos�win32z-win�linuxz
-linux-gnuzUnknown platform )�sys�platform�
build_archr )�machine�platr r r �get_triplet s
r c C s t �� } | �� S )z%
Return the current machine.
)r
r �lower)r r r r r 9 s r Z
_toolchainz.tar.xzzppbt-z
.dist-infoc C sp |� d�rd}n|� d�rd}n
|� d�rd}nd}t�||��}|�| � W d � dS 1 s1w Y dS ) z�
Extract an archive to a specific location.
:param to_dir: The directory to extract to
:type to_dir: str
:param archive: The archive to extract
:type archive: str
�tgzzr:gz�xzzr:xz�bz2zr:bz2�rN)�endswith�tarfile�open�
extractall)�to_dir�archive� read_type�tr r r �extract_archiveL s
"�r Fc C sB t �� r
| s
t�d� dS t�d� tttt�� t d }|�� r�g }t�d� t
|d��}t�|�D ]}|�
|� q3W d � n1 sEw Y t
tt�d d��}t�|�D ]}|�
|� qYW d � n1 skw Y t|dd � d
�}t
|d��}t�|�}|D ]}|�|� q�W d � dS 1 s�w Y dS dS )z(
Extract the toolchain tarball.
zToolchain directory existszExtract archive�RECORDzUpdate pkg metadatar Nz.recordc S s | d S )Nr r )�_r r r �<lambda>t s zextract.<locals>.<lambda>)�key�w)� TOOLCHAIN�exists�log�debug�infor �TOOLCHAIN_ROOT�str�ARCHIVE�DISTINFOr �csv�reader�append�sorted�writerZwriterow)Z overwrite�record�records�fp�rowr2 r r r �extracta s4
����
�"��r7 c C s� t �� s| r
t� ntd��t d t }t � |� d�|� d�dt � dt� d�dt � dt� d�dt � dt� d�dt � dt� d �d
�S )z&
Toolchain build environment.
zToolchain not extracted�binz-gccz-g++z-I�/z/sysroot/usr/includez-Lz/sysroot/lib)ZTOOLCHAIN_PATH�CC�CXX�CFLAGS�CPPFLAGSZCMAKE_FLAGS�LDFLAGS)r% r&