HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/ppbt/__pycache__/build.cpython-310.pyc
o

�N�gE#�@s
dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlmZmZddlZdZdZdZdejvZdZd	e�d
e�d�ZeZeZGdd
�d
ejje �Z!dd�Z"ddd�Z#ddd�Z$dd�Z%d dd�Z&d!dd�ZdS)"z8
Build a ppbt wheel which includes a toolchain archive.
�N)�build_sdist�build_wheelz1.26.0zLhttp://crosstool-ng.org/download/crosstool-ng/crosstool-ng-{version}.tar.bz2z0https://github.com/crosstool-ng/crosstool-ng.gitZCIz0.18.0z4https://github.com/NixOS/patchelf/releases/download/z
/patchelf-z.tar.gzc@seZdZdZdS)�
BuildErrorzGeneric build error.N)�__name__�
__module__�__qualname__�__doc__�r	r	�>/opt/saltstack/salt/lib/python3.10/site-packages/ppbt/build.pyr'srcCstj�|tj�|��S)a
    Get the full path to where the url will be downloaded to.

    :param url: The url to donwload
    :type url: str
    :param dest: Where to download the url to
    :type dest: str

    :return: The path to where the url will be downloaded to
    :rtype: str
    )�os�path�join�basename)�url�destr	r	r
�get_download_location+sr��c
Cs�|dkrd}d}||kr=|d7}z
tjj||d�}Wntjjtjjtjjfy8||kr/�t	�
|d�Ynw||ksz#d}|�|�}|rZ|�|�|�d�}|sGW|�
�dSW|�
�dS|�
�w)zn
    Fetch the contents of a url.

    This method will store the contents in the given file like object.
    �r)�timeout�
i�i(N)�urllib�request�urlopen�error�	HTTPError�URLError�http�client�RemoteDisconnected�time�sleep�read�write�close)r�fp�backoffr�n�fin�size�blockr	r	r
�	fetch_url:s6
���


��r+T�<cCs�t||�}|rtd|�d|���t|d�}z
t||||�W|StyM}z!|r8td|�d|��tjdd�zt�|�W�t	yHY�wd}~ww)	a�
    Download the url to the provided destination.

    This method assumes the last part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)

    :param url: The url to download
    :type url: str
    :param dest: Where to download the url to
    :type dest: str
    :param verbose: Print download url and destination to stdout
    :type verbose: bool

    :raises urllib.error.HTTPError: If the url was unable to be downloaded

    :return: The path to the downloaded content
    :rtype: str
    zDownloading z -> �wbzUnable to download: � T)�file�flushN)
r�print�openr+�	Exception�sys�stderrr�unlink�OSError)rr�verboser&r�local�fout�excr	r	r
�download_urlYs&

	�����r<cOs6tj|i|��}|jdkrtd�d�|d����|S)aQ
    Run a command.

    Run the provided command, raising an Exception when the command finishes
    with a non zero exit code.  Arguments are passed through to ``subprocess.run``

    :return: The process result
    :rtype: ``subprocess.CompletedProcess``

    :raises BuildError: If the command finishes with a non zero exit code
    rzBuild cmd '{}' failedr.)�
subprocess�run�
returncoder�formatr
)�args�kwargs�procr	r	r
�runcmd|s
rDc Cs
t�t���}t�tj�dt����}|d}d}�zdtd|���|jdd�|rB|d}|��sAt�	|�t
�dd	d
|tg�n|dt
��}|��s_tjt
d�}t||�}tj�||�t�	|�|d
}	|	��rttd|	���ntd�tddg�tdg�td|	���tj��}
t��}|ddd}td|���|jdd�tj�|
�}
||
}td|���|��r�td�|��n�|ddd|d�|
�}|��s�td�|��t�d�t|d��+}td�t|d d!��}|�|���Wd�n	1�swYWd�n	1�swYt�	|�tj��}||d"<t��d#k�r:d$|d%<d$|d&<t �rAd'|d(<tt!|	�d)g|d*�tt!|	�dg|d*�|d+t"��}|dd,}|���rotd-|���ntd.t#���tt#|�}tj�||�t�	|�|���r�td/|���ntd0�t
�dg�t
�dg�t$�|dd,||
d1d,�t�	|�|
�d2�}|
�d3�}d4d5|�d6|�|
�g}t
�|�t|d!��v}t%�&|�}t�'|�D]c\}}}t�|��(|�}|D]R}td7|�d8|���||}t|d9��3}|��}t)�*t+�,|��-���.d:��/�}t!t�d�d|�}|�0|d;|��t1|�g�Wd�n	1�s>wY�q�q�Wd�n	1�sRwYtd<|�d=|���t$�||�td<|�d=|���t$�||�Wt�	|�dSt�	|�w)>z�Build a toolchain and include it in the wheel.

    - Downloads and installs crosstool-ng for building a toolchain.
    - Compile a toolchain
    - Add patchelf to the toolchain's binaries
    - Create a tarball to be included in the wheel
    ZPWD�buildNz  ** Build dir is: T)�exist_okzcrosstool-ng�git�clonez-bz
crosstool-ng-)�versionzct-ngzUsing existing ct-ng: zCompiling ct-ngz./configurez--enable-localZmakezUsing compiled ct-ng: �src�ppbtZ
_toolchainztoolchain: zArch dir is zToolchain directory exists: {}Z_configz{}-ct-ng.configzToolchain config missing: {}r�rzWriting crosstool-ng .configz.config�wZ	CT_PREFIXr�yZCT_ALLOW_BUILD_AS_ROOTZCT_ALLOW_BUILD_AS_ROOT_SUREr'ZCT_LOG_PROGRESS�source)�envz	patchelf-�patchelfz Using existing patchelf source: zFetchin patchelf source: z Using existing patchelf binary: zBuild patchelf�binz.tar.xzz.tar.xz.record�tarz-Cz-cJfzArchive z / �rb�=zsha256=zCopying z to )2�pathlib�Pathr�getcwd�environ�getr1�mkdir�exists�chdirr=r>�CT_GIT_REPO�	CT_NG_VER�CT_URLr@r<rK�common�extract_archiverD�
build_arch�platform�machine�get_tripletr4�exitr2r#r"�copy�getuid�CICD�str�PATCHELF_VERSION�PATCHELF_SOURCE�shutil�csv�writer�walk�relative_to�base64�urlsafe_b64encode�hashlib�sha256�digest�rstrip�decodeZwriterow�len) �branchZuse_tempdir�cwd�rootrEZarchdirZctngdirr�archiveZctng�archre�	toolchain�tripletZconfigZrfpZwfprPrOrQ�record�cmdZrwriterZ_dirs�filesZrelroot�f�relpathr%�dataZhshZhashpathr	r	r
�
build_ppbt�s�
�



������
���

����



 




������r�cCst�t|||�S)zPEP 517 wheel creation hook.)r��_build_wheel)Zwheel_directoryZmetadata_directoryZconfig_settingsr	r	r
rsr)rr)Trr,)NT)NN)'rrsroru�http.clientrrrVrdrnr=r4r �urllib.errorr�urllib.requestZsetuptools.build_metarrZppbt.commonrKr_r`r^rYrjrlrmr�Z_build_sdistraZ
PPBTException�RuntimeErrorrrr+r<rDr�r	r	r	r
�<module>sJ
���

#