B
    ›³ëb–S  ã               @   s8  d Z ddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddlZddlZdadd„ Zdd„ add„ Zd	d
„ Zdd„ Zej ed¡ZejjZejjZejjZejjZejj Z!ej"j# $¡ Z$ej"j# %¡ Z%ej dd¡Z&ej dd¡Z'ej dd¡Z(ej dd¡Z)ej dd¡Z*ej dd¡Z+ej dd¡Z,ej dd¡Z-ej dd¡Z.ej dd ¡Z/ej d!d"¡Z0ejj1Z1d#d$„ Z2ej3ej4ej5d%œej6ej7ej8d%œej9ej:ej;d%œd&œZ<d'd(„ Z=d)d*„ Z>e1e=e>ƒZ?dad,d-„Z@e1e@dbd.d/„ƒZAdcd0d1„ZBddd2d3„ZCe1eBeCƒZDd4d5„ ZEe1eEd6d/„ ƒZFd7d8„ ZGe1eGd9d/„ eHd:ZId;d<„ ZJe1eJd=d/„ ƒZKd>d/„ ddd+fd?d@„ZLdAdB„ ZMdedCdD„ZNdEdF„ ZOddeMfdGdH„ZPG dIdJ„ dJƒZQG dKdL„ dLƒZRdMdN„ ZSdOdP„ ZTi ejjgdQdRejjUejjVi ejjWeLePeNdSdTdUdVeSdWdXdYeTeQdZejXjYeRd[d\ƒeRd[d]ƒeRd[d^ƒeRd[d_ƒd`œZZdS )fa  Builders and other things for the local site.

Here's where we'll duplicate the functionality of autoconf until we
move it into the installation procedure or use something like qmconf.

The code that reads the registry to find MSVC components was borrowed
from distutils.msvccompiler.
é    Nc              O   s   t S )z=Returns the already-created default construction environment.)Ú_default_env)ÚargsÚkw© r   ú-lib/python3.7/site-packages/SCons/Defaults.pyÚ_fetch_DefaultEnvironment:   s    r   c              O   s2   t s.ddl}|jj| |Ža t  d¡ tadt _t S )a­  
    Initial public entry point for creating the default construction
    Environment.

    After creating the environment, we overwrite our name
    (DefaultEnvironment) with the _fetch_DefaultEnvironment() function,
    which more efficiently returns the initialized default construction
    environment without checking for its existence.

    (This function still exists with its _default_check because someone
    else (*cough* Script/__init__.py *cough*) may keep a reference
    to this function.  So we can't use the fully functional idiom of
    having the name originally be a something that *only* creates the
    construction environment and then overwrites the name.)
    r   NZcontent)r   Ú
SCons.UtilZEnvironmentZDeciderr   ÚDefaultEnvironmentZ_CacheDir_path)r   r   ÚSConsr   r   r   r	   @   s    
r	   c             C   s   x| D ]}d |j _qW | |fS )N)Ú
attributesÚshared)ÚtargetÚsourceÚenvÚtgtr   r   r   ÚStaticObjectEmitter^   s    
r   c             C   s   x| D ]}d|j _qW | |fS )Né   )r   r   )r   r   r   r   r   r   r   ÚSharedObjectEmitterd   s    
r   c          	   C   sv   |  d¡}|dks"|dks"|dkrrxN| D ]F}y|jj}W n tk
rP   d }Y nX |s(tj d||d f ¡‚q(W d S )Nz'$STATIC_AND_SHARED_OBJECTS_ARE_THE_SAMEÚ0Ú ÚFalsezFSource file: %s is static and is not compatible with shared target: %sr   )Úsubstr   r   ÚAttributeErrorr
   ÚErrorsÚ	UserError)r   r   r   ZsameÚsrcr   r   r   r   ÚSharedFlagCheckerj   s    


r   z$CCCOMz	$CCCOMSTRz$SHCCCOMz$SHCCCOMSTRz$CXXCOMz
$CXXCOMSTRz	$SHCXXCOMz$SHCXXCOMSTRz$DCOMz$DCOMSTRz$SHDCOMz
$SHDCOMSTRz$ASCOMz	$ASCOMSTRz$ASPPCOMz$ASPPCOMSTRz$LINKCOMz$LINKCOMSTRz
$SHLINKCOMz$SHLINKCOMSTRz$LDMODULECOMz$LDMODULECOMSTRc             C   sZ   t j | ¡rFg }x"| D ]}| dt|ƒ d ¡ qW dd |¡ d S dt| ƒ d S d S )Nú"ú[z, ú])r
   ÚUtilÚis_ListÚappendÚstrÚjoin)ÚdestZ	elem_strsÚelementr   r   r   Úget_paths_str    s    
r'   )ÚrÚwÚx)ÚuÚgÚoc                sö  dd l }ddlm‰  |jj | ¡ |j | ¡s4| g} |j |¡r`d‡ fdd„|D ƒkr`t	|dƒ}|j |¡sŽx| D ]}t
 t|ƒ|¡ qrW ndt|ƒ}xX| d¡D ]H}d|kr¸d}n$d|krÆd}nd	|krÔd	}ntd
ƒ‚| |¡}t|ƒdkrútdƒ‚|d  ¡  dd¡}|d  ¡ }d}	xR|D ]J}
xB|D ]:}y|	t|
 | B }	W n tk
rd   tdƒ‚Y nX q.W q$W xz| D ]r}t
 t|ƒ¡j}|dkr¨t
 t|ƒ|	¡ n@|dkrÈt
 t|ƒ||	B ¡ n |d	krxt
 t|ƒ||	 @ ¡ qxW q¤W d S )Nr   )Údigitsc                s   g | ]}|ˆ k‘qS r   r   )Ú.0Úi)r.   r   r   ú
<listcomp>Ä   s    zchmod_func.<locals>.<listcomp>é   ú,ú=ú+ú-zCould not find +, - or =é   zMore than one operator foundÚaZugor   z&Unrecognized user or permission format)r   Ústringr.   ÚNodeÚFSÚinvalidate_node_memosr    r!   Ú	is_StringÚintÚosÚchmodr#   ÚsplitÚSyntaxErrorÚlenÚstripÚreplaceÚpermission_dicÚKeyErrorÚstatÚst_mode)r%   Úmoder
   r&   Z	operationÚoperatorZoperation_listÚuserZ
permissionZnew_permr+   ÚpZ	curr_permr   )r.   r   Ú
chmod_func¾   sN    "








rN   c             C   s<   dd l }|j |¡s$dt| ƒ|f S dt| ƒt|ƒf S d S )Nr   zChmod(%s, 0%o)zChmod(%s, "%s"))r   r    r=   r'   r#   )r%   rJ   r
   r   r   r   Úchmod_strfuncê   s    rO   Tc             C   s¼   t | ƒ} t |ƒ}tjj | ¡ tj |¡rTtj 	| ¡rTx|D ]}t
 || ¡ q<W dS tj |¡rŠ|rvt t |¡| ¡S t| tj |¡ƒS n.tj |¡r¦t
 || ¡ dS t
 || |¡ dS dS )zÿ
    If symlinks (is true), then a symbolic link will be
    shallow copied and recreated as a symbolic link; otherwise, copying
    a symbolic link will be equivalent to copying the symbolic link's
    final target regardless of symbolic link depth.
    r   N)r#   r
   r:   r;   r<   r    r!   r?   ÚpathÚisdirÚshutilZcopy2ÚislinkÚsymlinkÚreadlinkÚ	copy_funcÚrealpathÚisfileZcopytree)r%   r   ÚsymlinksÚfiler   r   r   rV   õ   s     
rV   c             C   s   d| |f S )NzCopy("%s", "%s")r   )r%   r   rY   r   r   r   Ú<lambda>  ó    r[   c             C   sŒ   t jj | ¡ t j | ¡s | g} xf| D ]^}t|ƒ}tj 	|¡pHtj 
|¡}|sT|sTq&tj |¡rztj 
|¡szt |d¡ q&t |¡ q&W d S )NT)r
   r:   r;   r<   r    r!   r#   r?   rP   ÚexistsrS   rQ   rR   ZrmtreeÚunlink)r%   Ú
must_existÚentryZentry_existsr   r   r   Údelete_func  s    
ra   c             C   s   dt | ƒ S )Nz
Delete(%s))r'   )r%   r_   r   r   r   Údelete_strfunc+  s    rb   c             C   sD   t jj | ¡ t j | ¡s | g} x| D ]}tjt|ƒdd q&W d S )NT)Úexist_ok)	r
   r:   r;   r<   r    r!   r?   Úmakedirsr#   )r%   r`   r   r   r   Ú
mkdir_func2  s
    
re   c             C   s   dt | ƒ S )Nz	Mkdir(%s))r'   )Z_dirr   r   r   r[   ;  r\   c             C   s,   t jj | ¡ t jj |¡ t || ¡ d S )N)r
   r:   r;   r<   rR   Zmove)r%   r   r   r   r   Ú	move_func>  s    rf   c             C   s   d| |f S )NzMove("%s", "%s")r   )r%   r   r   r   r   r[   E  r\   )Zconvertc          
   C   sŠ   t jj | ¡ t j | ¡s | g} xd| D ]\}t|ƒ}tt ¡ ƒ}t	j
 |¡rXt	j
 |¡}nt|dƒ
 |}W d Q R X t	 |||f¡ q&W d S )Nr)   )r
   r:   r;   r<   r    r!   r#   r>   Útimer?   rP   r]   ÚgetatimeÚopenÚutime)r%   rZ   ÚmtimeZatimer   r   r   Ú
touch_funcI  s    
rl   c             C   s   dt | ƒ S )Nz	Touch(%s))r'   )rZ   r   r   r   r[   Y  r\   c             C   s   | S )Nr   )r*   r   r   r   r[   _  r\   c       
      C   sb   |s|S |t j |¡ |||¡ƒ}|dk	r.|}|s:dg}	ng }	|	t| |||ƒ7 }	|s^|	dg7 }	|	S )a
  
    Creates a new list from 'items_iter' by first interpolating each element
    in the list using the 'env' dictionary and then calling f on the
    list, and finally calling _concat_ixes to concatenate 'prefix' and
    'suffix' onto each element of the list.
    Nz$(z$))r
   ÚPathListÚ
subst_pathÚ_concat_ixes)
ÚprefixÚ
items_iterÚsuffixr   Úfr   r   Zaffect_signatureÚlÚvaluer   r   r   Ú_concat_  s    
rv   c             C   s  g }t | | tjj¡ƒ} t | |tjj¡ƒ}xÐtj |¡D ]À}t|tjj	j
ƒrZ| |¡ q:t |ƒ}|r:| r¦| d dkrŠ| | dd… ¡ n|dt| ƒ… | kr¦| | }| |¡ |r:|d dkrÔ| |dd… ¡ q:|t|ƒ d… |kr:|d | |d< q:W |S )a  
    Creates a new list from 'items_iter' by concatenating the 'prefix' and
    'suffix' arguments onto each element of the list.  A trailing space
    on 'prefix' or leading space on 'suffix' will cause them to be put
    into separate list elements rather than being concatenated.
    éÿÿÿÿú Nr   r   )r#   r   r
   ÚSubstZ	SUBST_RAWr    ÚflattenÚ
isinstancer:   r;   ÚFiler"   rC   )rp   rq   rr   r   Úresultr*   r   r   r   ro   {  s*    

ro   c             C   s:  |s|S t |ƒs2|d }|tkr.t |ƒr.|}nt}tt|jtj |¡ƒƒ}tt|jtj |¡ƒƒ}g }xÄtj	 	|¡ 
|dd¡D ]ª}	t|	tjjjƒrž| |	¡ q~tj |	¡s²t|	ƒ}	x2|D ]*}
t|
ƒ}|	d|… |
kr¸|	|d… }	P q¸W x6|D ].}t|ƒ}|	| d… |krì|	d| … }	P qìW | |	¡ q~W || |||ƒS )a  
    This is a wrapper around _concat()/_concat_ixes() that checks for
    the existence of prefixes or suffixes on list items and strips them
    where it finds them.  This is used by tools (like the GNU linker)
    that need to turn something like 'libfoo.a' into '-lfoo'.
    rv   N)Úcallablerv   ro   ÚlistÚmapr   r
   r    rz   rm   rn   r{   r:   r;   r|   r"   r=   r#   rC   )rp   Zitmsrr   ZstripprefixesZstripsuffixesr   ÚcZenv_cÚstrippedrt   ZstripprefixZlspZstripsuffixZlssr   r   r   Ú
_stripixes¡  s8    


rƒ   c             C   s€  t j | ¡rg }xø| D ]ð}|dkr(qqt j |¡s>t|tƒr‚t|ƒdkrn| t|d ƒd t|d ƒ ¡ n| t|d ƒ¡ qt j |¡rØxx| 	¡ D ]:\}}|dk	rÄ| t|ƒd t|ƒ ¡ q˜| t|ƒ¡ q˜W qt j 
|¡rô| t|ƒ¡ qt j dt|ƒ ¡‚qW nnt j | ¡rrg }xZt|  	¡ ƒD ]>\}}|dkrP| t|ƒ¡ n| t|ƒd t|ƒ ¡ q.W n
t| ƒg}|S )zXprocess defines, resolving strings, lists, dictionaries, into a list of
    strings
    Nr7   r   r4   r   z.DEFINE %s is not a list, dict, string or None.)r
   r    r!   r{   ÚtuplerC   r"   r#   Zis_DictÚitemsr=   r   r   ÚreprÚsorted)Údefsrt   ÚdZmacroru   ÚkÚvr   r   r   ÚprocessDefinesÖ  s2    
$
"
rŒ   c             C   s   || |j t|ƒ||d||ƒS )zzA wrapper around _concat_ixes that turns a list or string
    into a list of C preprocessor command-line definitions.
    )r   r   )Z
subst_listrŒ   )rp   rˆ   rr   r   r   r   r   r   r   r   Ú_defines   s    r   c               @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚNullCmdGeneratoraY  This is a callable class that can be used in place of other
    command generators if you don't want them to do anything.

    The __call__ method for this class simply returns the thing
    you instantiated it with.

    Example usage:
    env["DO_NOTHING"] = NullCmdGenerator
    env["LINKCOM"] = "${DO_NOTHING('$LINK $SOURCES $TARGET')}"
    c             C   s
   || _ d S )N)Úcmd)Úselfr   r   r   r   Ú__init__  s    zNullCmdGenerator.__init__Nc             C   s   | j S )N)r   )r   r   r   r   Zfor_signaturer   r   r   Ú__call__  s    zNullCmdGenerator.__call__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‘   r’   r   r   r   r   rŽ     s   
rŽ   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚVariable_Method_Callera<  A class for finding a construction variable on the stack and
    calling one of its methods.

    We use this to support "construction variables" in our string
    eval()s that actually stand in for methods--specifically, use
    of "RDirs" in call to _concat that should actually execute the
    "TARGET.RDirs" method.  (We used to support this by creating a little
    "build dictionary" that mapped RDirs to the method, but this got in
    the way of Memoizing construction environments, because we had to
    create new environment objects to hold the variables.)
    c             C   s   || _ || _d S )N)ÚvariableÚmethod)r   r˜   r™   r   r   r   r‘   (  s    zVariable_Method_Caller.__init__c             O   sz   ydd  W n$ t k
r0   t ¡ d jj}Y nX | j}x<|rt||jkrl|j| }|rlt|| jƒ}|||ŽS |j}q:W d S )Nr   r   r7   )	ÚZeroDivisionErrorÚsysÚexc_infoÚtb_frameÚf_backr˜   Úf_localsÚgetattrr™   )r   r   r   Úframer˜   r‹   r™   r   r   r   r’   ,  s    



zVariable_Method_Caller.__call__N)r“   r”   r•   r–   r‘   r’   r   r   r   r   r—     s   r—   c             C   s4   y|   d| ¡r| | S W n tk
r.   Y nX dS )z 
    if version_var is not empty, returns env[flags_var], otherwise returns None
    :param env:
    :param version_var:
    :param flags_var:
    :return:
    ú$N)r   rG   )r   Zversion_varÚ	flags_varr   r   r   Ú__libversionflags>  s    r¤   c             C   sB   y(|   d| ¡s|   d| ¡r&| | S W n tk
r<   Y nX dS )zÍ
    if $version_var1 or $version_var2 is not empty, returns env[flags_var], otherwise returns None
    :param env:
    :param version_var1:
    :param version_var2:
    :param flags_var:
    :return:
    r¢   N)r   rG   )r   Zversion_var1Zversion_var2r£   r   r   r   Ú__lib_either_version_flagN  s    	r¥   z#/.sconf_tempz#/config.logz7${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}zg${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE, affect_signature=False)}za${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE, affect_signature=False)}zL${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__, TARGET, SOURCE)}zA${__libversionflags(__env__,"SHLIBVERSION","_SHLIBVERSIONFLAGS")}zG${__libversionflags(__env__,"LDMODULEVERSION","_LDMODULEVERSIONFLAGS")}zC${__libversionflags(__env__,"DSHLIBVERSION","_DSHLIBVERSIONFLAGS")}rx   ZTARGETÚDirÚDirsr|   ÚRDirs)ZBUILDERSZSCANNERSZCONFIGUREDIRZCONFIGURELOGZCPPSUFFIXESZ	DSUFFIXESZENVZIDLSUFFIXESrv   r   rƒ   Z	_LIBFLAGSZ_LIBDIRFLAGSZ_CPPINCFLAGSZ_CPPDEFFLAGSr¤   Z__SHLIBVERSIONFLAGSZ__LDMODULEVERSIONFLAGSZ__DSHLIBVERSIONFLAGSr¥   ZTEMPFILEZTEMPFILEARGJOINZTEMPFILEARGESCFUNCr¦   r§   r|   r¨   )T)T)r   )r   )N)[r–   r?   rR   rH   r›   rg   ZSCons.Actionr
   ZSCons.BuilderZSCons.CacheDirZSCons.EnvironmentZSCons.PathListZSCons.Scanner.DirZSCons.SubstZ
SCons.Toolr   r   r	   r   r   r   ZActionZSharedCheckZToolZCScannerZCScanZDScannerZDScanZLaTeXScannerZ	LaTeXScanZSourceFileScannerZObjSourceScanZProgramScannerZProgScanÚScannerr¦   Z
DirScannerZDirEntryScannerZCActionZ	ShCActionZ	CXXActionZShCXXActionZDActionZ	ShDActionZASActionZ
ASPPActionZ
LinkActionZShLinkActionZLdModuleLinkActionZActionFactoryr'   ÚS_IRUSRÚS_IWUSRÚS_IXUSRÚS_IRGRPÚS_IWGRPÚS_IXGRPÚS_IROTHÚS_IWOTHÚS_IXOTHrF   rN   rO   ZChmodrV   ZCopyra   rb   ZDeletere   ZMkdirrf   r#   ZMoverl   ZTouchrv   ro   rƒ   rŒ   r   rŽ   r—   r¤   r¥   Z	CSuffixesZ	DSuffixesZIDLSuffixesry   Zquote_spacesZConstructionEnvironmentr   r   r   r   Ú<module>    sÒ   ,






&
5*#