B
    ›³ëbìJ  ã               @   s^  d Z ddlZddlZddlmZmZ ddlZddlZddl	Zddl
mZ ddlmZmZmZ g adaG dd„ deƒZddeddfd	d
„Zedœdd„Zedœdd„Zdd„ Zdd„ Zedœdd„Zedœdd„Zdd„ Zdd„ Zdd„ ZG dd„ dƒZej   ee¡Z!ej   ee¡Z"ej   ee¡Z#da$d*d d!„Z%d+d"d#„Z&da'd,d$d%„Z(da)d&d'„ Z*d(d)„ Z+dS )-zÎ Tool-specific initialization for the install tool.

There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
é    N)Úcopy2Úcopystat)Ú	SUBST_RAW)ÚStringizeLibSymlinksÚCreateLibSymlinksÚEmitLibSymlinksc               @   s   e Zd ZdS )ÚCopytreeErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú1lib/python3.7/site-packages/SCons/Tool/install.pyr   1   s   r   Fc             C   sô  t  | ¡}|dk	r|| |ƒ}ntƒ }t j||d g }	xN|D ]D}
|
|krNq>t j | |
¡}t j ||
¡}y®t j |¡ræt  |¡}|r¤t  ||¡ t	||| d n@t j 
|¡s¶|r¶w>t j |¡rÚt|||||||d n
|||ƒ n0t j |¡rt|||||||d n
|||ƒ W q> tk
rL } z|	 |jd ¡ W dd}~X Y q> tk
r‚ } z|	 ||t|ƒf¡ W dd}~X Y q>X q>W yt	| |ƒ W nJ tk
rà } z*t|ddƒdkrÐ|	 | |t|ƒf¡ W dd}~X Y nX |	rðt|	ƒ‚|S )aî  Recursively copy a directory tree, SCons version.

    This is a modified copy of the Python 3.7 shutil.copytree function.
    SCons update: dirs_exist_ok dictates whether to raise an
    exception in case dst or any missing parent directory already
    exists. Implementation depends on os.makedirs having a similar
    flag, which it has since Python 3.2.  This version also raises an
    SCons-defined exception rather than the one defined locally to shtuil.
    This version uses a change from Python 3.8.
    TODO: we can remove this forked copy once the minimum Py version is 3.8.

    If exception(s) occur, an Error is raised with a list of reasons.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied. If the file pointed by the symlink doesn't
    exist, an exception will be added in the list of errors raised in
    an Error exception at the end of the copy process.

    You can set the optional ignore_dangling_symlinks flag to true if you
    want to silence this exception. Notice that this has no effect on
    platforms that don't support os.symlink.

    The optional ignore argument is a callable. If given, it
    is called with the `src` parameter, which is the directory
    being visited by copytree(), and `names` which is the list of
    `src` contents, as returned by os.listdir():

        callable(src, names) -> ignored_names

    Since copytree() is called recursively, the callable will be
    called once for each directory that is copied. It returns a
    list of names relative to the `src` directory that should
    not be copied.

    The optional copy_function argument is a callable that will be used
    to copy each file. It will be called with the source path and the
    destination path as arguments. By default, copy2() is used, but any
    function that supports the same signature (like copy()) can be used.

    N)Úexist_ok)Úfollow_symlinks)ÚsymlinksÚignoreÚcopy_functionÚignore_dangling_symlinksÚdirs_exist_okr   Zwinerror)ÚosÚlistdirÚsetÚmakedirsÚpathÚjoinÚislinkÚreadlinkÚsymlinkr   ÚexistsÚisdirÚscons_copytreer   ÚextendÚargsÚOSErrorÚappendÚstrÚgetattr)ÚsrcÚdstr   r   r   r   r   ÚnamesZignored_namesÚerrorsÚnameZsrcnameZdstnameZlinktoÚerrZwhyr   r   r   r    5   sV    ,



 *&r    )Úreturnc             C   s®   t j |¡rxt j | ¡rBt j | ¡shtj dt| ƒt|ƒf ¡‚n&t j | ¡d }t j |¡sht  	|¡ t
|| dd n2t|| ƒ t  |¡}t  | t |tj ¡tjB ¡ dS )zûInstall a source file or directory into a destination by copying.

    Mode/permissions bits will be copied as well, except that the target
    will be made writable.

    Returns:
        POSIX-style error code - 0 for success, non-zero for fail
    z9cannot overwrite non-directory `%s' with a directory `%s'r   T)r   )r   r   r   r   ÚSConsÚErrorsÚ	UserErrorr%   Úsplitr   r    r   ÚstatÚchmodÚS_IMODEÚST_MODEÚS_IWRITE)ÚdestÚsourceÚenvÚparentÚstr   r   r   ÚcopyFuncž   s    	


r<   c             C   s€   t j |¡r"tj dt|ƒ ¡‚nZyt  | ¡ W n   Y nX t|| ƒ t  	|¡}t  
| t	 |t	j ¡t	jB ¡ t| ||ƒ dS )a:  Install a versioned library into a destination by copying.

    Any required symbolic links for other library names are created.

    Mode/permissions bits will be copied as well, except that the target
    will be made writable.

    Returns:
        POSIX-style error code - 0 for success, non-zero for fail
    z2cannot install directory `%s' as a version libraryr   )r   r   r   r.   r/   r0   r%   Úremover   r2   r3   r4   r5   r6   ÚinstallShlibLinks)r7   r8   r9   r;   r   r   r   ÚcopyFuncVersionedLibº   s    

r?   c             C   s¨   g }|  |¡}|j | ¡} |  ¡ }x€|D ]x}tt|dd ƒdd ƒ}|r(xZ|D ]R\}}tj | ¡ ¡}	tj | ¡ ¡}
|j |	|¡}|j |
|¡}| 	||f¡ qJW q(W |S )NÚ
attributesZ
shliblinks)
Ú	arg2nodesÚfsZFileÚget_dirr&   r   r   ÚbasenameÚget_pathr$   )r7   r8   r9   Zinstall_linksZinstall_dirr'   r   ÚlinkZlinktgtZ	link_baseZlinktgt_baseZinstall_linkZinstall_linktgtr   r   r   ÚlistShlibLinksToInstallÔ   s    

rG   c             C   s8   d}t | ||ƒ}|r&td t|ƒ¡ƒ |r4t||ƒ dS )zJIf we are installing a versioned shared library create the required links.Fz installShlibLinks: symlinks={!r}N)rG   ÚprintÚformatr   r   )r7   r8   r9   ÚVerboser   r   r   r   r>   ä   s    
r>   c             C   s–   y|d }W n  t k
r,   tj d¡‚Y nX t| ƒt|ƒksbtdttt|ƒƒttt| ƒƒf ƒ‚x.t	| |ƒD ] \}}|| 
¡ | 
¡ |ƒrndS qnW dS )zÀInstall a source file into a target.

    Uses the function specified in the INSTALL construction variable.

    Returns:
        POSIX-style error code - 0 for success, non-zero for fail
    ÚINSTALLz&Missing INSTALL construction variable.zSInstalling source %s into target %s: target and source lists must have same length.é   r   )ÚKeyErrorr.   r/   r0   ÚlenÚAssertionErrorÚlistÚmapr%   ÚziprE   )Útargetr8   r9   ÚinstallÚtÚsr   r   r   ÚinstallFuncî   s    	 rW   c             C   s¾   y|d }W n  t k
r,   tj d¡‚Y nX t| ƒt|ƒksbtdttt|ƒƒttt| ƒƒf ƒ‚xVt	| |ƒD ]H\}}t
|jdƒrštj | ¡ |jj¡}n| ¡ }||| ¡ |ƒrndS qnW dS )zÆInstall a versioned library into a target.

    Uses the function specified in the INSTALL construction variable.

    Returns:
        POSIX-style error code - 0 for success, non-zero for fail
    ÚINSTALLVERSIONEDLIBz2Missing INSTALLVERSIONEDLIB construction variable.zSInstalling source %s into target %s: target and source lists must have same length.Ú	shlibnamerL   r   )rM   r.   r/   r0   rN   rO   rP   rQ   r%   rR   Úhasattrr@   r   r   r   rC   rY   rE   )rS   r8   r9   rT   rU   rV   Ztpathr   r   r   ÚinstallFuncVersionedLib  s    	 r[   c             C   sZ   |  d¡}|r| |t| |¡S t| d ƒ} t|d ƒ}tj |¡rHd}nd}d||| f S )NZ
INSTALLSTRr   Z	directoryÚfilezInstall %s: "%s" as "%s")ÚgetZsubst_target_sourcer   r%   r   r   r   )rS   r8   r9   Z
installstrÚtyper   r   r   Ú
stringFunc&  s    
r_   c             C   s   t  | ¡ da| |fS )z± An emitter that adds all target files to the list stored in the
    _INSTALLED_FILES global variable. This way all installed files of one
    scons call will be collected.
    N)Ú_INSTALLED_FILESr!   Ú_UNIQUE_INSTALLED_FILES)rS   r8   r9   r   r   r   Úadd_targets_to_INSTALLED_FILES5  s    
rb   c             C   sZ   d}t  | ¡ |r*td ttt| ƒƒ¡ƒ t| d ||ƒ}|rNt||| d ƒ da	| |fS )z± An emitter that adds all target files to the list stored in the
    _INSTALLED_FILES global variable. This way all installed files of one
    scons call will be collected.
    Fz5add_versioned_targets_to_INSTALLED_FILES: target={!r}r   N)
r`   r!   rH   rI   rP   rQ   r%   rG   r   ra   )rS   r8   r9   rJ   r   r   r   r   Ú(add_versioned_targets_to_INSTALLED_FILES@  s    
rc   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDESTDIR_factoryzb A node factory, where all files will be relative to the dir supplied
    in the constructor.
    c             C   s    || _ | ||jj¡d | _d S )Nr   )r9   rA   rB   ÚDirÚdir)Úselfr9   rf   r   r   r   Ú__init__T  s    zDESTDIR_factory.__init__c             C   s   t j |¡}| j |¡S )N)r.   ÚUtilÚmake_path_relativerf   ÚEntry)rg   r+   r   r   r   rk   X  s    zDESTDIR_factory.Entryc             C   s   t j |¡}| j |¡S )N)r.   ri   rj   rf   re   )rg   r+   r   r   r   re   \  s    zDESTDIR_factory.DirN)r	   r
   r   Ú__doc__rh   rk   re   r   r   r   r   rd   P  s   rd   c             K   sî   |r|rdd l }|j d¡‚|s$|}dd l}|j d¡}|rHt| |ƒ}n| j}y|  ||j	¡}W n( t
k
rˆ   |j dt|ƒ ¡‚Y nX |  || jj¡}	g }
xJ|D ]B}x<|	D ]4}| j dtj |j |¡}|
 t| ||f|Ž¡ q®W q¤W |
S )Nr   zCBoth target and dir defined for Install(), only one may be defined.Úinstall_sandboxzsTarget `%s' of Install() is a file, but should be a directory.  Perhaps you have the Install() arguments backwards?Ú.)ÚSCons.Errorsr/   r0   ÚSCons.ScriptÚScriptÚ	GetOptionrd   rB   rA   re   Ú	TypeErrorr%   rk   r   Úsepr+   r!   ÚBaseInstallBuilder)r9   rS   r8   rf   Úkwr.   rm   Útarget_factoryÚdnodesÚsourcesÚtgtÚdnoder'   r   r   r   ÚInstallBuilderWrapperi  s*    

r|   c             K   s<   g }x2t dd„ ||ƒD ]\}}| t| ||f|Ž¡ qW |S )Nc             S   s   | |fS )Nr   )ÚxÚyr   r   r   Ú<lambda>‰  ó    z)InstallAsBuilderWrapper.<locals>.<lambda>)rQ   r!   ru   )r9   rS   r8   rv   Úresultr'   rz   r   r   r   ÚInstallAsBuilderWrapper‡  s    r‚   c             K   sî   |r|rdd l }|j d¡‚|s$|}dd l}|j d¡}|rHt| |ƒ}n| j}y|  ||j	¡}W n( t
k
rˆ   |j dt|ƒ ¡‚Y nX |  || jj¡}	g }
xJ|D ]B}x<|	D ]4}| j dtj |j |¡}|
 t| ||f|Ž¡ q®W q¤W |
S )Nr   zCBoth target and dir defined for Install(), only one may be defined.rm   zsTarget `%s' of Install() is a file, but should be a directory.  Perhaps you have the Install() arguments backwards?rn   )ro   r/   r0   rp   rq   rr   rd   rB   rA   re   rs   r%   rk   r   rt   r+   r!   ÚBaseVersionedInstallBuilder)r9   rS   r8   rf   rv   r.   rm   rw   rx   ry   rz   r{   r'   r   r   r   ÚInstallVersionedBuilderWrapper  s*    

r„   c             C   sF  ddl m}m} ts*da|dddddd	 td kr€|dƒ}|rJt| |ƒ}n| j}tjjt	|j
| jj
d
tgtjji dddddatd krÆ|dƒ}|r t| |ƒ}n| j}tjjt|j
| jj
d
tgddat| d d< t| d d< t| d d< y| d  W n tk
r   t| d< Y nX y| d  W n tk
r@   t| d< Y nX d S )Nr   )Ú	AddOptionrr   rL   z--install-sandboxrm   ÚstringZstorez;A directory under which all installed files will be placed.)r7   r^   ÚactionÚhelpTZInstallF)r+   Ú	recursiveZInstallBuilder)r‡   rw   Úsource_factoryÚmultiÚemitterZsource_scannerr+   ZInstallVersionedBuilder)r‡   rw   rŠ   r‹   rŒ   r+   ZBUILDERSZ_InternalInstallZ_InternalInstallAsZ_InternalInstallVersionedLibrK   rX   )rp   r…   rr   Úaddedru   rd   rB   r.   ZBuilderÚinstall_actionrk   rb   ÚScannerZScannerBaserƒ   ÚinstallVerLib_actionrc   r|   r‚   r„   rM   r<   r?   )r9   r…   rr   rm   rw   r   r   r   Úgenerate°  sX    r‘   c             C   s   dS )NrL   r   )r9   r   r   r   r   ÷  s    r   )NNN)NN)NNN),rl   r   r2   Zshutilr   r   ZSCons.Actionr.   Z
SCons.ToolZ
SCons.UtilZSCons.Substr   ZSCons.Tool.linkCommonr   r   r   r`   ra   r#   r   r    Úintr<   r?   rG   r>   rW   r[   r_   rb   rc   rd   ZActionrŽ   Zinstallas_actionr   ru   r|   r‚   rƒ   r„   r   r‘   r   r   r   r   r   Ú<module>   sD   h



G