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/relenv/build/__pycache__/common.cpython-310.pyc
o

�N�g���@sZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#Z$dZ%zddl&m'Z'm(Z(ddl)m*Z*Wne+y�dZ%Ynwe�,e-�Z.d	Z/d
Z0dZ1dZ2d
Z3dej4vZ5dZ6dZ7dZ8dIdd�Z9dd�Z:dJdd�Z;dd�Z<dd�Z=dd�Z>dKdd�Z?dd �Z@d!d"�ZAd#d$�ZBd%d&�ZCd'd(�ZDd)d*�ZEd+d,�ZFd-d.�ZGd/d0�ZHd1d2�ZIGd3d4�d4�ZJGd5d6�d6�ZKGd7d8�d8�ZLeL�ZMGd9d:�d:�ZNd;d<�ZOd=d>�ZPd?d@�ZQdAdB�ZRdCdD�ZSdEdF�ZTdIdGdH�ZUdS)Lz
Build process common methods.
�N)�
HTMLParser)�DATA_DIR�LINUX�
MODULE_DIR�RelenvException�
build_arch�download_url�extract_archive�format_shebang�get_download_location�
get_toolchain�get_triplet�runcmd�	work_dirs�	fetch_urlT)�InvalidVersion�parse)�LooseVersionFzzzzzZCIaBimport os; import sys; from importlib import util; from pathlib import Path; spec = util.spec_from_file_location('relenv.runtime', str(Path(__file__).parent / 'site-packages' / 'relenv' / 'runtime.py')); mod = util.module_from_spec(spec); sys.modules['relenv.runtime'] = mod; spec.loader.exec_module(mod); mod.bootstrap();a�
import pathlib, sys, platform, os

def build_arch():
    machine = platform.machine()
    return machine.lower()

def get_triplet(machine=None, plat=None):
    if not plat:
        plat = sys.platform
    if not machine:
        machine = build_arch()
    if plat == "darwin":
        return f"{machine}-macos"
    elif plat == "win32":
        return f"{machine}-win"
    elif plat == "linux":
        return f"{machine}-linux-gnu"
    else:
        raise RelenvException("Unknown platform {}".format(platform))



pydir = pathlib.Path(__file__).resolve().parent
if sys.platform == "win32":
    DEFAULT_DATA_DIR = pathlib.Path.home() / "AppData" / "Local" / "relenv"
else:
    DEFAULT_DATA_DIR = pathlib.Path.home() / ".local" / "relenv"

if "RELENV_DATA" in os.environ:
    DATA_DIR = pathlib.Path(os.environ["RELENV_DATA"]).resolve()
else:
    DATA_DIR = DEFAULT_DATA_DIR

buildroot = pydir.parent.parent
toolchain = DATA_DIR / "toolchain" / get_triplet()
build_time_vars = {}
for key in _build_time_vars:
    val = _build_time_vars[key]
    orig = val
    if isinstance(val, str):
        val = val.format(
            BUILDROOT=buildroot,
            TOOLCHAIN=toolchain,
        )
    build_time_vars[key] = val
cCs|duri}trtj��dSg}|D]]}||��s!d�t�}nJ||vr\t��}||vr3d|f||<||d|krKd||d|t��f||<d�t	||ddkrXdnd�}n||vrfd�t
�}nd�t	�}|�|�q|�d	t�tj�
d
�tj�
d�|��tj��dS)a�
    Prints the UI during the relenv building process.

    :param events: A dictionary of events that are updated during the build process
    :type events: dict
    :param processes: A dictionary of build processes
    :type processes: dict
    :param fails: A list of processes that have failed
    :type fails: list
    :param flipstat: A dictionary of process statuses, defaults to {}
    :type flipstat: dict, optional
    Nz {}.r�z {}{}� �.u {}✘z  �
�)�CICD�sys�stdout�flush�is_set�format�YELLOW�time�random�GREEN�RED�append�END�write�join)�events�	processes�failsZflipstatZuiline�name�status�now�r.�G/opt/saltstack/salt/lib/python3.10/site-packages/relenv/build/common.py�print_ui�s0

 "
r0cCst|durt�d�dSt|d�� }t�|�����}||kr(td|�d|����Wd�dS1s3wYdS)aS
    Verify the checksum of a files.

    :param file: The path to the file to check.
    :type file: str
    :param checksum: The checksum to verify against
    :type checksum: str

    :raises RelenvException: If the checksum verification failed

    :return: True if it succeeded, or False if the checksum was None
    :rtype: bool
    Nz,Can't verify checksum because none was givenF�rbz,sha1 checksum verification failed. expected=z found=T)�log�error�open�hashlib�sha1�read�	hexdigestr)�file�checksum�fpZ
file_checksumr.r.r/�verify_checksum�s
��
��r<cCs>|g}t�|�D]\}}}|D]}|�tj�||��qq|S)a7
    Get all directories under and including the given root.

    :param root: The root directory to traverse
    :type root: str
    :param recurse: Whether to recursively search for directories, defaults to True
    :type recurse: bool, optional

    :return: A list of directories found
    :rtype: list
    )�os�walkr$�pathr')�rootZrecurse�paths�dirs�filesr+r.r.r/�all_dirs�s�rDcC�dS�Nr.)rB�envr.r.r/�populate_env��rHcCs~dd�|j�g}|d�d�dkr!|d�|d�d�|d�g7}t||||d	�td
dg|||d	�td
dg|||d	�d
S)a'
    The default build function if none is given during the build process.

    :param env: The environment dictionary
    :type env: dict
    :param dirs: The working directories
    :type dirs: ``relenv.build.common.Dirs``
    :param logfp: A handle for the log file
    :type logfp: file
    �./configure�--prefix={}�RELENV_HOST�linux����
--build={}�RELENV_BUILD�	--host={}�rG�stderrr�make�-j8�installN�r�prefix�findr�rGrB�logfp�cmdr.r.r/�
build_default�s
��r]cCst|||dd�S)NT)�fips)�
build_openssl)rGrBr[r.r.r/�build_openssl_fips�sr`cCs<d}tjdkr'd}|ddkrd}n|ddkrd}n	td	|d����g}n d
}|ddkr2d}n|ddkr;d}n	td	|d����dg}|rN|�d�d
|�d|��d|j��ddddddddg}|�|�t||||d�tddg|||d�|r�t�t	�
d�dt	�
|j�dd�d Stddg|||d�d S)!z�
    Build openssl.

    :param env: The environment dictionary
    :type env: dict
    :param dirs: The working directories
    :type dirs: ``relenv.build.common.Dirs``
    :param logfp: A handle for the log file
    :type logfp: file
    �aarch64�darwinZdarwin64�RELENV_HOST_ARCH�x86_64z	x86_64-cc�arm64zarm64-cczUnable to build rMz-Wl,-z,noexecstackzenable-fipsz./Configure�-z	--prefix=z--openssldir=/etc/sslz--libdir=libz--api=1.1.1z--sharedz--with-rand-seed=os,egdz
enable-md2z
enable-egdzno-idearRrTrUZ	providerszfips.so�libzossl-modulesZ
install_swN)r�platformrr$rX�extendr�shutil�copy�pathlib�Path)rGrBr[r^�arch�platZextended_cmdr\r.r.r/r_�sZ
�

�

��r_c	Cs�ddddddd�|j�dg}|d	�d
�dkr'|d�|d
�d�|d	�g7}t||||d�tddg|||d�tddg|||d�dS)z�
    Build sqlite.

    :param env: The environment dictionary
    :type env: dict
    :param dirs: The working directories
    :type dirs: ``relenv.build.common.Dirs``
    :param logfp: A handle for the log file
    :type logfp: file
    rJz
--with-sharedz--without-staticz--enable-threadsafez--disable-readlinez--disable-dependency-trackingrKz--enable-add-ons=nptl,portsrLrMrNrO�RELENV_BUILD_ARCHrQrRrTrUrVNrWrZr.r.r/�build_sqlite7s"
�
�rqcCsP|�d�r&z|�dd�ddd�}|dkr|WSWdSty%YdSwdS)Nztar.gzrfri�����latest)�endswith�split�
IndexError)�href�xr.r.r/�tarball_versiones
���rxcCs<d|vr|�d�ddd�}djdd�|�d�D��SdS)	NZ
releaselog�/r���z{:d}{:02d}{:02d}00cSsg|]}t|��qSr.)�int)�.0�_r.r.r/�
<listcomp>rsz"sqlite_version.<locals>.<listcomp>r})rtr)rv�linkr.r.r/�sqlite_versionos�r�cCsd|vr|�d�dSdS)Nztag/z/vrN)rt�rvr.r.r/�github_versionus�r�cC�t�d|�r|dd�SdS)Nz	\d\.\d\d/rN��re�matchr�r.r.r/�krb_versionz��r�cCr�)Nz(\d+\.)+\d/rNr�r�r.r.r/�python_versionr�r�cCs6d|vrd|vr|dd��d�d�dd�SdSdS)N�downloadrri�ryrNzlibuuid-r)�rsplit�replacer�r.r.r/�uuid_version�s�r�cCs&Gdd�dt�}|�}|�|�|jS)Nc@seZdZgZdd�ZdS)zparse_links.<locals>.HrefParsercSs4|dkrt|��dd�}|r|j�|�dSdSdS)N�arvr)�dict�get�hrefsr$)�self�tagZattrsrr.r.r/�handle_starttag�s�z/parse_links.<locals>.HrefParser.handle_starttagN)�__name__�
__module__�__qualname__r�r�r.r.r.r/�
HrefParser�sr�)r�feedr�)�textr��parserr.r.r/�parse_links�s	
r�c
	Cs�t��}t||�|�d�|����}d}zt|�}Wnty+t|�}d}Ynwg}t	|�D]%}||�}	|	rW|rD|�
t|	��q2z	|�
t|	��Wq2tyVYq2wq2|��t|||�dS)NrFT)
�io�BytesIOr�seekr7�decoderrrr�r$�sort�compare_versions)
r+�location�func�currentr;r�Zloose�versionsr}�versionr.r.r/�check_files�s2

���	r�c	CsT|D]%}z||krtd|�d|�d|���Wqty'td|���YqwdS)NzFound new version of rz > zUnable to compare versions )�print�	TypeError)r+r�r�r�r.r.r/r��s���r�c@s�eZdZdZ							d#dd�Zdd�Zedd	��Zed
d��Zedd
��Z	edd��Z
edd��Zdd�Zdd�Z
dd�Zdd�Zedd��Zedd��Zd$dd �Zd!d"�ZdS)%�Downloada
    A utility that holds information about content to be downloaded.

    :param name: The name of the download
    :type name: str
    :param url: The url of the download
    :type url: str
    :param signature: The signature of the download, defaults to None
    :type signature: str
    :param destination: The path to download the file to
    :type destination: str
    :param version: The version of the content to download
    :type version: str
    :param sha1: The sha1 sum of the download
    :type sha1: str

    Nrc

Cs:||_||_||_||_||_||_||_||_|	|_dSrF)	r+�url_tpl�fallback_url_tpl�
signature_tpl�destinationr�r:�	checkfunc�checkurl)
r�r+�url�fallback_url�	signaturer�r�r:r�r�r.r.r/�__init__�s
zDownload.__init__c
Cs*t|j|j|j|j|j|j|j|j|j	�	SrF)
r�r+r�r�r�r�r�r:r�r��r�r.r.r/rk�s�z
Download.copycC�|jj|jd�S�N�r�)r�rr�r�r.r.r/r���zDownload.urlcCs|jr|jj|jd�SdSr�)r�rr�r�r.r.r/r��s�zDownload.fallback_urlcCr�r�)r�rr�r�r.r.r/�
signature_url�r�zDownload.signature_urlcCs"|j�dd�\}}t�|j�|S)Nryr)r�r�rlrmr�)r�r}r+r.r.r/�filepathszDownload.filepathcCr�r�)r�rr�r�r.r.r/�
formatted_urlr�zDownload.formatted_urlc
Cs|zt|j|jt�dfWSty=}z&|jr2td|j�d|�d��t|j|jt�dfWYd}~SWYd}~dSd}~ww)z�
        Download the file.

        :return: The path to the downloaded content, and whether it was downloaded.
        :rtype: tuple(str, bool)
        TzDownload failed z (z); trying fallback urlN)rr�r�r�	Exceptionr�r�)r��excr.r.r/�
fetch_file	s ���zDownload.fetch_filecCst|j|jt�S)zz
        Download the file signature.

        :return: The path to the downloaded signature.
        :rtype: str
        )rr�r�r)r�r�r.r.r/�fetch_signatureszDownload.fetch_signaturecCs
|j��S)z�
        True when the artifact already exists on disk.

        :return: True when the artifact already exists on disk
        :rtype: bool
        )r��existsr�r.r.r/r� s
zDownload.existscCrErFr.r�r.r.r/�
valid_hash)rIzDownload.valid_hashc
Csl|durt�d�dSztdd||gtjtjd�WdSty5}zt�d||�WYd}~dSd}~ww)	aK
        True when the archive's signature is valid.

        :param archive: The path to the archive to validate
        :type archive: str
        :param signature: The path to the signature to validate against
        :type signature: str

        :return: True if it validated properly, else False
        :rtype: bool
        Nz,Can't check signature because none was givenFZgpgz--verify)rSrTz%Signature validation failed on %s: %s)r2r3r�
subprocess�PIPEr)�archiver�r�r.r.r/�validate_signature,s

���zDownload.validate_signaturec
CsFzt||�WdSty"}zt�d||�WYd}~dSd}~ww)a<
        True when when the archive matches the sha1 hash.

        :param archive: The path to the archive to validate
        :type archive: str
        :param checksum: The sha1 sum to validate against
        :type checksum: str
        :return: True if the sums matched, else False
        :rtype: bool
        Tz sha1 validation failed on %s: %sNF)r<rr2r3)r�r:r�r.r.r/�validate_checksumGs
��zDownload.validate_checksumFcCs(tj|jjdd�d}|r|��\}}n)d}t|j|j�}|jr-tj	�
|�r-|�||j�}|r7t�
d|j�n|��\}}d}|r�|jdurW|��\}	}|�|j|	�}
|oV|
}|jdurh|�|j|j�}|og|}|s�t�d|j|j�|r�tj�d|j�d|j�d	��tj��|r�|s�t�d
�|S)z�
        Downloads the url and validates the signature and sha1 sum.

        :return: Whether or not validation succeeded
        :rtype: bool
        T��exist_okFz %s already downloaded, skipping.NzChecksum did not match %s: %sz
Checksum did not match z: �
r)r=�makedirsr��parentr�rr�r�r:r?r�r�r2�debugr�r�r��warningr+rrSr&r�exit)r��force_download�show_ui�exit_on_failureZ
downloadedr}Z
file_is_valid�destZvalid�sigZ	valid_sigZvalid_checksumr.r.r/�__call__Zs<

�

zDownload.__call__cCs8|jr|j}n	|j�dd�d}t|j||j|j�dS)Nryrr)r�r�r�r�r+r�r�)r�r�r.r.r/�
check_version�szDownload.check_version)NNrrNNN)FFF)r�r�r��__doc__r�rk�propertyr�r�r�r�r�r�r�r�r��staticmethodr�r�r�r�r.r.r.r/r��s>
�




		


*r�c@sTeZdZdZdd�Zedd��Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�ZdS)�Dirsa"
    A container for directories during build time.

    :param dirs: A collection of working directories
    :type dirs: ``relenv.common.WorkDirs``
    :param name: The name of this collection
    :type name: str
    :param arch: The architecture being worked with
    :type arch: str
    cCsR||_||_||_|j|_|j|_|j|_|j|_|j|_	t
jd�|�d�|_
dS)Nz{}_build)rX)r+r�rnr@�buildr��	downloads�logs�src�sources�tempfileZmkdtempr�tmpbuild)r�rBr+rnr�r.r.r/r��sz
Dirs.__init__cCs:tjdkrt|jd�Stjdkrt|jd�St|j|j�S)Nrb�r@�win32)rrhrr@rnr�r.r.r/�	toolchain�s


zDirs.toolchaincC�8tjdkrd�|j�Stjdkrd�|j�Sd�|j�S�Nrbz{}-macosr�z{}-winz{}-linux-gnu�rrhrrnr�r.r.r/�_triplet��


z
Dirs._tripletcCs|j|j�d|j��S)Nrf)r�r�r�r�r.r.r/rX�szDirs.prefixc	Cs&|j|j|j|j|j|j|j|jd�S)z[
        Return an object used for pickling.

        :return: The picklable state
        �r+rnr@r�r�r�r�r�r�r�r.r.r/�__getstate__�s�zDirs.__getstate__cCsT|d|_|d|_|d|_|d|_|d|_|d|_|d|_|d|_d	S)
z�
        Unwrap the object returned from unpickling.

        :param state: The state to unpickle
        :type state: dict
        r+rnr@r�r�r�r�r�N)r+rnr@r�r�r�r�r�)r��stater.r.r/�__setstate__�s






zDirs.__setstate__cs�fdd�dD�S)z�
        Get a dictionary representation of the directories in this collection.

        :return: A dictionary of all the directories
        :rtype: dict
        csi|]}|t�|��qSr.)�getattr)r|rwr�r.r/�
<dictcomp>�s
��z Dirs.to_dict.<locals>.<dictcomp>)r@rXr�r�r�r�r�r.r�r.r�r/�to_dict�s
�zDirs.to_dictN)r�r�r�r�r�r�r�r�rXr�r�r�r.r.r.r/r��s


r�c@s eZdZdZdd�Zdd�ZdS)�Buildsz
    Collection of builds.
    cCs
i|_dSrF)�buildsr�r.r.r/r��s
zBuilds.__init__cOsdd|vr|�d�}|s
|rtd��nt|i|��}||jvr(|j|i|j|<|S||j||j<|S)NZbuilderz9builder keyword can not be used with other kwargs or args)�pop�RuntimeError�Builderr�r�)r�rh�args�kwargsr�r.r.r/�add�s
��
�z
Builds.addN)r�r�r�r�r�r�r.r.r.r/r��sr�c@s�eZdZdZddeedddfdd�Zdd	�Zd
d�Ze	dd
��Z
d"dd�Z	d#dd�Zdd�Z
dd�Zd$dd�Zd%dd�Zdd�Z							d&dd�Zd d!�ZdS)'r�a�
    Utility that handles the build process.

    :param root: The root of the working directories for this build
    :type root: str
    :param recipies: The instructions for the build steps
    :type recipes: list
    :param build_default: The default build function, defaults to ``build_default``
    :type build_default: types.FunctionType
    :param populate_env: The default function to populate the build environment, defaults to ``populate_env``
    :type populate_env: types.FunctionType
    :param force_download: If True, forces downloading the archives even if they exist, defaults to False
    :type force_download: bool
    :param arch: The architecture being built
    :type arch: str
    NFrdrcCs�||_t|�|_t�|_t|j�|_||_t|j�|_||_|jj	|j�d|j��|_
|jj|_|jj
|_|dur>i|_n||_||_||_||_t|jjd�|_|�|j�dS)Nrfr�)r@rrBrr
�
build_tripletrn�tripletr�r�rXr�r�r�r��recipiesr]rHr�rZ
toolchains�set_arch)r�r@r�r]rHr�rnr�r.r.r/r�s$



zBuilder.__init__cCs�i}|jD]}|j|}|d|d|dr|d��ndd�||<qt|j||j|j|j|j|�}||jdd_||jdd_	|S)N�
build_func�wait_onr��r�r�r��python)
r�rkr�r@r]rHr�rnr�r:)r�r�r:r�r+r}r�r.r.r/rk?s&

��	zBuilder.copycCsX||_t|j�|_|jj|j�d|j��|_tjdvr!d|_	dSt
|j|jj�|_	dS)zu
        Set the architecture for the build.

        :param arch: The arch to build
        :type arch: str
        rf)rbr�N)rnr
r�rBr�r�rXrrhr�rr@)r�rnr.r.r/r�Us

zBuilder.set_archcCr�r�r�r�r.r.r/r�dr�zBuilder._tripletcCsN|durg}|dur
|j}|durt|fd|ji|��}|||d�|j|<dS)a�
        Add a step to the build process.

        :param name: The name of the step
        :type name: str
        :param build_func: The function that builds this step, defaults to None
        :type build_func: types.FunctionType, optional
        :param wait_on: Processes to wait on before running this step, defaults to None
        :type wait_on: list, optional
        :param download: A dictionary of download information, defaults to None
        :type download: dict, optional
        Nr�r)r]r�r�r�)r�r+r�r�r�r.r.r/r�ms
�zBuilder.add�WARNINGc	Cs>t�d�}tjdkr|st��}|�t�|��|�|�|jD]}t	|tj�r4|�
t�d|�d���q |jj
��sDtj|jj
dd�t|j||j|j�}	tj|	jdd�tj|	jdd�tj|	jdd�|��durwt�d�|��duslt�tj�|	jd	�|��d
�}
t�|	j|�d��}|�|�|�tj �t�!�}|r�t"|	jt#|j$��|	j|j$j%�&d�d
|	_'t�(|	j'�nt�(|	j�tjdkr�tj)�*�}ndtj)di}d|d<d|d<|j+|d<|j|d<|j,|d<|j-|d<|j.ddj|d<|d�/dd�d
|d<dtj)v�rtj)d|d<|j-|jk�r+t0d}
t#|
dd�|d <|�1||	�|	�2�}|D]}t3�4d!|||��q7|D]}t3�4d"|||��qFz<z|||	|
�WWt�(|�t3�5|�|
�6�St7�y~t3�8d#�t�9d�YnwWt�(|�t3�5|�|
�6�dSt�(|�t3�5|�|
�6�w)$a�
        Run a build step.

        :param name: The name of the step to run
        :type name: str
        :param event: An event to track this process' status and alert waiting steps
        :type event: ``multiprocessing.Event``
        :param build_func: The function to use to build this step
        :type build_func: types.FunctionType
        :param download: The ``Download`` instance for this step
        :type download: ``Download``

        :return: The output of the build function
        Nr�z%(asctime)s z %(message)sTr�F�333333�?z{}.log�w�.logz.tarr�PATH�1�RELENV_DEBUG�RELENV_BUILDENVrLrcrPrprr�ZRELENV_PY_VERSIONrr�RELENV_PY_MAJOR_VERSIONZRELENV_DATA�native�bin�python3�RELENV_NATIVE_PYzDirectory %s %szEnvironment %s %sz
Build failure):�logging�	getLoggerrrh�
StreamHandler�setLevel�getLevelName�
addHandler�handlers�
isinstance�setFormatter�	FormatterrBr�r�r=r�r�rnr�r�r�rXrr �sleepr�r4r?r'r�FileHandler�NOTSET�getcwdr	�strr�r+rt�source�chdir�environrkr�r�rr�r�rrHr�r2�info�
removeHandler�closer��	exceptionr�)r�r+�eventr�r�r��	log_levelZroot_log�handlerrBr[�cwdrG�native_rootr}�kr.r.r/�run�s�



��
�


�






�
�


�

zBuilder.runcCst�|j�dS)z1
        Clean up the build directories.
        N)rj�rmtreerXr�r.r.r/�cleanup�szBuilder.cleanupc	Cs�|j|jfD]#}zt�|�Wqty!tj�d|���Yqty)Yqw|j�d�}|fD]}zt	�
|�Wq3tyEYq3wdS)zE
        Completely clean up the remnants of a relenv build.
        zUnable to remove directory: �.tar.xzN)rXr�rjr,�PermissionErrorrrSr&�FileNotFoundErrorr=�remove)r�r}r�r.r.r/�clean�s �
��z
Builder.cleancCs4|dur	t|j�}g}i}i}|rtj�d�t�d�|r$t|||�|D].}|j|d}|dur4q&t�	�}	|	�
�|	||<tj||||dd�d�}
|
��|
||<q&|r�t|�
��D]&}
|
�d�|rlt|||�|
jdurrq]|�|
j�|
jd	kr�|�|
j�q]|sW|r�t|||�tj�d
�|r�dSdS)z�
        Download all of the needed archives.

        :param steps: The steps to download archives for, defaults to None
        :type steps: list, optional
        NzStarting downloads 
zStarting downloadsr�T)r�r�r�)r+�targetr�rrr�)�listr�rrr&r2r!r0�multiprocessing�Event�set�Process�start�valuesr'�exitcoder�r+r$rSrr�)r��stepsr�r�r*r)r(r+r�r%�proc�failr.r.r/�download_files�sV

��	



��zBuilder.download_filesTc	CsRg}i}i}i}|rtj�d�t|||�t�d�|D]Q}	t��}
|
||	<t|j	|	�}||d<||d<|�
dg�}|dd�D]}
|
|vrM|�|
�qB|||	<||	sZ|
��tj
|	|j|	|
f|d�}|��|||	<q|r�t|���D]`}|�d�|r�t|||�|jdur�qw|�
|j�|jd	kr�|�|j�d
}nd}|D]2}	|j||	vr�|r�|	|vr�||	��t�d�||	�|j�||	s�||	��s�||	��q�qw|sq|�r�tj�d
�i}|D]}|jj|�d�}zWt�|��G}|�d	d�|� �}|d}|d	k�r|�|�n|�d	�|�!�}|�r8tj�dd|�d�dd�tj�|�!�d�Wd�n	1�sCwYWnt"�yZd|��||<Ynwt�#d|�t�#|�q�|�rotj�$�|�r{t�%d�|�&�t�'d�|�r�t�d�t|||�tj�d�tj�$�|�r�t�%d�|�&�dSdS)z�
        Build!

        :param steps: The steps to run, defaults to None
        :type steps: list, optional
        :param cleanup: Whether to clean up or not, defaults to True
        :type cleanup: bool, optional
        zStarting builds
zStarting buildsr�r&r�N)r+r3r�r�rrTFg�������?z%The following failures were reported
r�iz====================rr�z

zLog file not found: zBuild step %s has failedzPerforming cleanup.r)(rrr&r0r2r!r5r6r�r�r�r1r7r8r+r9r4r:r'r;r+r$�	terminater rrrSrBr�r�r4r��tellr7r0r3rr�r-r�)r�r<r-r�r&r*r(Zwaitsr)r+r%r�r�r}r=Z
is_failureZ	last_outsr>Zlog_filer;�endZindZlast_outr.r.r/r�9s�	

��




���

 ����





�z
Builder.buildcCs,g}|jr|j��s|�d|j�d��|S)z�
        Check pre-requsists for build.

        This method verifies all requrements for a successful build are satisfied.

        :return: Returns a list of string describing failed checks
        :rtype: list
        zToolchain for zC does not exist. Please use relenv toolchain to obtain a toolchain.)r�r�r$rn)r�r>r.r.r/�
check_prereqs�s	�zBuilder.check_prereqscCsRt�d�}|�tj�|st��}	|	�t�|��|�|	�tj|j	j
dd�t�|j	j
d�}	|	�tj�|�|	�|rB|�
|�|durI|j}|��}
|
rg|
D]}tj�|�d��qQtj��t�d�|rm|��|j|jkr�td}|��s�dtjvr�tjd}
n|j}
d	d
lm}|dt|
d�|j|||d�|j||||d
�dS)a�
        Set the architecture, define the steps, clean if needed, download what is needed, and build.

        :param steps: The steps to run, defaults to None
        :type steps: list, optional
        :param arch: The architecture to build, defaults to None
        :type arch: str, optional
        :param clean: If true, cleans the directories first, defaults to True
        :type clean: bool, optional
        :param cleanup: Cleans up after build if true, defaults to True
        :type cleanup: bool, optional
        :param force_download: Whether or not to download the content if it already exists, defaults to True
        :type force_download: bool, optional
        NTr�z	build.logr�rrZRELENV_NATIVE_PY_VERSIONr)�creater�)r�r�)r�r&) rrrrrrrr=r�rBr�r�INFOr�r�rDrrSr&rr�r2rrnrr�r r�Z
relenv.createrEr?r�)r�r<rnr2r-r�r�r&r2r'Zfailuresr}r)r�rEr.r.r/r��s@






zBuilder.__call__cCs8d}t|j�D]}|j|d}|sq|��sd}q|S)NTr�F)r4r�r�)r��success�stepr�r.r.r/�check_versions�s�zBuilder.check_versions)NNN)Fr)NFF)NTFr)NNTTFFr)r�r�r�r�r]rHr�rkr�r�r�r�r+r-r2r?r�rDr�rIr.r.r.r/r�s>
�!


�]

<j
�Er�cCsZt|d��_}z
|�t|������}Wn.ty#YWd�dStyA}zt�d|�WYd}~Wd�dSd}~ww||krWt�d|||�	Wd�dS|����}Wd�n1sgwYt|d��}|�	|�|�	|�Wd�n1s�wYt|d��}|��}Wd�n1s�wYt�
d||�d	S)
a
    Replace a file's shebang.

    :param path: The path of the file to patch
    :type path: str
    :param old: The old shebang, will only patch when this is found
    :type old: str
    :param name: The new shebang to be written
    :type name: str
    r1NFzUnhandled exception: %rz"Shebang doesn't match: %s %r != %rr�rzPatched shebang of %s => %rT)r4r7�len�encoder��UnicodeErrorr�r2r�r&r!)r?�old�newr;�datar�r.r.r/�
patch_shebangs6�
����
�
�rQcCs>t�t|��D]\}}}|D]
}ttj�||�||�qqdS)a
    Traverse directory and patch shebangs.

    :param path: The of the directory to traverse
    :type path: str
    :param old: The old shebang, will only patch when this is found
    :type old: str
    :param name: The new shebang to be written
    :type name: str
    N)r=r>rrQr?r')r?rNrOr@�_dirsrCr9r.r.r/�patch_shebangs#s
��rScs�i}�fdd�}�fdd�}t|j�D]&}|j|}t|t�r5||fD]}	|	|�}t�d||j||�q#|||<qt|ddd��}
|
�d�|
�d	�tj||
d
�|
�t	�Wd�dS1scwYdS)a�
    Create a Relenv Python environment's sysconfigdata.

    Helper method used by the `finalize` build method to create a Relenv
    Python environment's sysconfigdata.

    :param mod: The module to operate on
    :type mod: ``types.ModuleType``
    :param destfile: Path to the file to write the data to
    :type destfile: str
    :param buildroot: Path to the root of the build
    :type buildroot: str
    :param toolchain: Path to the root of the toolchain
    :type toolchain: str
    c�|�t��d�S)Nz{BUILDROOT}�r�r�r})�	buildrootr.r/�<lambda>D�z!install_sysdata.<locals>.<lambda>crT)Nz{TOOLCHAIN}rUrV)r�r.r/rXErYzSYSCONFIG [%s] %s => %sr�utf8)�encodingzC# system configuration generated and used by the relenv at runtime
z_build_time_vars = )�streamN)
�sortedZbuild_time_varsrrr2r!r4r&�pprint�
SYSCONFIGDATA)�modZdestfilerWr�rPZ
fbuildrootZ
ftoolchain�key�valr}�fr.)rWr�r/�install_sysdata3s$


�
"�rdcCsPt�|�D] \}}}|D]}|�d�dkr$|�d�r$|dd�SqqdS)z�
    Find sysconfigdata directory for python installation.

    :param pymodules: Path to python modules (e.g. lib/python3.10)
    :type pymodules: str

    :return: The name of the sysconig data module
    :rtype: str
    Z
sysconfigdatarN�.pyN���)r=r>rYrs)�	pymodulesr@rBrCr9r.r.r/�find_sysconfigdatafs
���rhc	
Cs�|d}t�t|�d��
}|�t�Wd�n1swY|d}tj|dd�dD]=}t|}||}t�|d��%}t�|d��}|�|���Wd�n1sWwYWd�n1sfwYq.dS)	z(
    Install a base relenv runtime.
    z
relenv.pthrN�relenvTr�)z
runtime.pyzrelocate.pyz	common.pyz__init__.pyrJ)	r�r4rr&�
RELENV_PTHr=r�rr7)	�sitepackagesZ
relenv_pthr;rir+r�r�ZrfpZwfpr.r.r/�install_runtimevs"������rlc	s�tjj�jt�jd�d�t��j�d}dd�}|||��t�	�}t
��}tj}t��gt_zt
t|��}Wt�|�|t_n	t�|�|t_w�|�d�}	t||	�j�j�t��j�d}
�d}t|��jdd	}�d
�dkr��j�d<�d
}��d�tt|�ddg���d�d�|
d�d���d�|
d�d�dd�d���g}
td�}|
D]}t�d||�ttt��j�d�||�q�tjdkr�d�d�d�d��}tt�|d�d�t|
d�d����td���d ���rtt�d �d!td"��d1����fd$d%�	}|d&�tjd'���r-|tjd(d)�n|d*d(d)�gd+�}�j�d,�}t�d-|�tj |d.d/��}t!|�j|��Wd0�d0S1�s_wYd0S)2aU
    Run after we've fully built python.

    This method enhances the newly created python with Relenv's runtime hacks.

    :param env: The environment dictionary
    :type env: dict
    :param dirs: The working directories
    :type dirs: ``relenv.build.common.Dirs``
    :param logfp: A handle for the log file
    :type logfp: file
    zrelocate.py.log)Z
log_file_namergcSs:t�|�D]\}}}|D]
}|�d�r|SqqdS)Nr)r=r>�
startswith)�libdirr@rBrCr}r.r.r/�find_pythonlib�s
���z finalize.<locals>.find_pythonlibrer�
site-packagesr
rcrp�RELENV_CROSSrz
RUN ENSURE PIP
�-mZ	ensurepiprRz#!{}rr
rrrz/python3zPatch shebang %r with  %rrMzconfig-rfrLzpython-config.pyz../../../bin/python3zcgi.pyz#! /usr/local/bin/pythonz../../bin/python3Fcs���d|�d|�d��d}�jdd}tjtkr*�d�dkr*�d}�d	}t|�d
ddt|�g}|r<|�d
�|rF|�d�|��t|���d�dS)Nz	
RUN PIP rr�rr
rcrprprrrZpiprVz	--upgradez--target={}rR)	r&rXrrhrrr$rr)Zpkg�upgrader3rr\�rBrGr[rgr.r/�runpip�s$
�
zfinalize.<locals>.runpipZwheelz.gitT)rsri)z/bin/python*z	/bin/pip*z/bin/relenvz/lib/python*/ensurepip/*z/lib/python*/site-packages/*z
/include/*z*.soz/lib/*.so.*z*.az*.pyz*.dylibr.z
Archive is %szw:xz)�modeN�F)"ri�relocate�mainrXrr�rlrmr=rrhrr?�
__import__rrdr�rlr&rrrtr
r2r!rSrhrQr�rr��tarfiler4�create_archive)rGrBr[rnror(�modnamer?r`r�ZbindirrkrZshebangsZ
newshebangZshebangZpyconfru�globsr�r;r.rtr/�finalize�s�

�

�	���
�
�$�rcCs�|durt�dt���t�d|j�t�|�D]I\}}}t�|��|�}|D]9}||}	d}
|D]}t	j
�
d|	|�r@d}
nq1|
rV|durMt�d|	�|j|	|	dd�q'|dur`t�d	|	�q'qdS)
aj
    Create an archive.

    :param tarfp: A pointer to the archive to be created
    :type tarfp: file
    :param toarchive: The path to the directory to archive
    :type toarchive: str
    :param globs: A list of filtering patterns to match against files to be added
    :type globs: list
    :param logfp: A pointer to the log file
    :type logfp: file
    NzCurrent directory %szCreating archive %sFryTz	Adding %s)�	recursivezSkipping %s)r2r!r=rr+r>rlrm�relative_to�glob�fnmatchr�)ZtarfpZ	toarchiver~r[r@rRrCZrelrootrc�relpath�matches�gr.r.r/r|s,
����r|rF)Trw)Vr�rZos.pathr=r5rlr�rjr{r�r r�r!rr�r5r^r�Zhtml.parserrZ
relenv.commonrrrrrrr	r
rrr
rrrZrelenv.relocateriZCHECK_VERSIONS_SUPPORTZpackaging.versionrrZlooseversionr�ImportErrorrr�r2r"rr#r%ZMOVEUPr rZ	NODOWLOADrjr_r0r<rDrHr]r`r_rqrxr�r�r�r�r�r�r�r�r�r�r�r�r�rQrSrdrhrlrr|r.r.r.r/�<module>s�@�

�
1(

@.
	Pez 3