B
    ›³ëb4h  ã               @   sŽ  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mZmZmZmZ ddlmZ ddlm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G dd„ deƒZej ej¡a da!i Z"da#d	d
„ Z$dd„ Z%G dd„ dƒZ&g Z'dd„ Z(dZ)d$dd„Z*dd„ Z+ej,fdd„Z-dd„ Z.G dd„ dej/j0ƒZ1e1ej/_/dd„ Z2da3dd„ Z4G d d!„ d!ƒZ5d"d#„ Z6dS )%z@This module defines the Python API provided to SConscript files.é    N)Úis_ListÚ	is_StringÚis_DictÚflatten)ÚSConscriptNodesé   )ÚMainc               @   s   e Zd ZdS )ÚSConscriptReturnN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú6lib/python3.7/site-packages/SCons/Script/SConscript.pyr	   1   s   r	   c              C   sZ   ydd  W n$ t k
r0   t ¡ d jj} Y nX x| j d¡tkrL| j} q4W | j| jfS )zjReturn the locals and globals for the function that called
    into this module in the current call stack.r   r   é   r
   )	ÚZeroDivisionErrorÚsysÚexc_infoÚtb_frameÚf_backÚ	f_globalsÚgetr
   Úf_locals)Úframer   r   r   Úget_calling_namespaces>   s     	
r   c          
   C   sž   t ƒ \}}i }yXxR| D ]J}t|ƒr.| |¡ qy|| ||< W q tk
r^   || ||< Y qX qW W n2 tk
r˜ } ztj d| ¡‚W dd}~X Y nX |S )zCompute a dictionary of exports given one of the parameters
    to the Export() function or the exports argument to SConscript().z$Export of non-existent variable '%s'N)r   r   ÚupdateÚKeyErrorÚSConsÚErrorsÚ	UserError)ÚexportsZlocZglobÚretvalZexportÚxr   r   r   Úcompute_exportsT   s    

"r"   c               @   s   e Zd ZdZdd„ ZdS )ÚFramez/A frame on the SConstruct/SConscript call stackc             C   s\   t ƒ | _d | _| ¡ | _t|ƒ| _t|tj	j	ƒr8|| _
n |dkrHd | _
n| t|ƒ¡| _
d S )Nú-)ÚBuildDefaultGlobalsÚglobalsr    ÚgetcwdÚprev_dirr"   r   Ú
isinstancer   ÚNodeÚ
sconscriptÚFileÚstr)ÚselfÚfsr   r+   r   r   r   Ú__init__k   s    

zFrame.__init__N)r
   r   r   Ú__doc__r0   r   r   r   r   r#   i   s   r#   c           
   O   sº   g }y@t | ƒ}x2|D ]*}x$| ¡ D ]}| td j| ¡ q"W qW W n2 tk
rv } ztj d| ¡‚W d d }~X Y nX t	|ƒdkr”|d td _
nt|ƒtd _
| dd¡}|r¶t‚d S )Néÿÿÿÿz$Return of non-existent variable '%s'r   r   ÚstopT)r   ÚsplitÚappendÚ
call_stackr&   r   r   r   r   Úlenr    Útupler   r	   )ÚvarsÚkwr    ZfvarsÚvarÚvr!   r3   r   r   r   ÚReturn}   s    
 "r=   z% Stack boTTom %c             C   s†   |st jjr,|dk	r,d|  ¡  }t j |¡‚|dkr‚t jjrdd|  ¡  }t j t jj	|¡ dt j_nd|  ¡  }t j t jj	|¡ dS )a†  Take appropriate action on missing file in SConscript() call.

    Print a warning or raise an exception on missing file, unless
    missing is explicitly allowed by the *must_exist* value.
    On first warning, print a deprecation message.

    Args:
        f (str): path of missing configuration file
        must_exist (bool): if true, fail.  If false, but not ``None``,
          allow the file to be missing.  The default is ``None``,
          which means issue the warning.  The default is deprecated.

    Raises:
        UserError: if *must_exist* is true or if global
          :data:`SCons.Script._no_missing_sconscript` is true.
    FzFatal: missing SConscript '%s'NzŠCalling missing SConscript without error is deprecated.
Transition by adding must_exist=False to SConscript calls.
Missing SConscript '%s'z Ignoring missing SConscript '%s')
r   ÚScriptZ_no_missing_sconscriptZget_internal_pathr   r   Z#_warn_missing_sconscript_deprecatedÚWarningsÚwarnZMissingSConscriptWarning)ÚfÚ
must_existÚmsgr   r   r   Úhandle_missing_SConscript”   s    

rD   c             O   sø  | j }| j ¡ }| dg ¡}g }x²|D ]¨}t t| ||ƒ¡ tj}zÈt	j
jd t	j
_|dkr|ttj ¡ td jƒ n’t|t	jjƒr|}	n|  t|ƒ¡}	d }
t |	¡ | j|dd |	 ¡ rÚ|	 ¡ }t| ¡ dƒ}
nf|	 ¡  ¡ r|	 ¡  ¡ }t| ¡ dƒ}
n<|	 ¡ r@|	 ¡  |	 ¡  |	 d ¡ |	  ¡ r@t|	 ¡ dƒ}
|
rüy|d }W n( t!k
rz   |  "|	j# $|¡¡}Y n,X |  "|¡}| %|	j#¡s¦|  "|	j# $|¡¡}y| j|t&d W n4 t'k
rì   | j|dd t( |j# ¡ ¡ Y nX |	j# ¡ gtj t_td j )t*di¡ td j d	¡}ytd jd	= W n t!k
rL   Y nX z^yBt+j,rbt- .¡ }|
 ¡ }|
j/}|
 0¡  tt1||d
ƒtd jƒ W n t2k
r¨   Y nX W d t+j,rÚt- .¡ | }t3d|	 ¡ |d f ƒ |d k	røtd j )t4|i¡ X nt5|	| dd ¡ƒ W d t	j
jd t	j
_|t_t 6¡ }y| j|j7t&d W n~ t'k
rÂ   | j|j7dd |j7 ¡ }| 8¡  yt( | ¡ ¡ W n2 t'k
r¼ } zt	j9j:r¬|‚W d d }~X Y nX Y nX | |j;¡ X q(W t<|ƒdkrì|d S t=|ƒS d S )Nr   r   r$   r2   )Zchange_os_dirÚrbÚsrc_dirr   Ú__file__ÚexeczSConscript:%s  took %0.3f msg     @@rB   )>ZTopZSConstruct_dirÚrdirr   r6   r5   r#   r   Úpathr   r>   Úsconscript_readingrH   ÚstdinÚreadr&   r)   r*   r,   r-   r   ÚaddÚchdirZrexistsZrfileÚopenÚget_abspathZsrcnodeZhas_src_builderZbuildZbuiltZbuilder_setÚexistsr   ÚDirÚdirÚget_pathÚis_underÚsconscript_chdirÚOSErrorÚosr   Ústack_bottomr   Z
print_timeÚtimeZperf_counterÚnameÚcloseÚcompiler	   ÚprintrG   rD   Úpopr(   Z_createZActionZexecute_actionsr    r7   r8   )r/   Úfilesr:   ÚtopZsdr   ZresultsÚfnZold_sys_pathrA   Z_file_ZactualrF   ZldirZold_fileZ
start_timeZ
scriptdataZ
scriptnameÚelapsedr   rI   Úer   r   r   Ú_SConscript·   s¦    





	




rf   c             C   sÐ   t  ¡ \}}}|}x|r,t|jjkr,|j}qW |s6|}t |¡}y
|j}W n8 t	k
r‚   t
|ƒ}|dd… dkr~|dd… }Y nX |  d||f ¡ x4|D ],\}}}	}
|  d||f ¡ |  d|
 ¡ qœW dS )zöPrint an exception stack trace just for the SConscript file(s).
    This will show users who have Python errors where the problem is,
    without cluttering the output with all of the internal calls leading
    up to where we exec the SConscript.Né   zexceptions.z%s: %s:
z  File "%s", line %d:
z    %s
)r   r   rZ   r   r   Útb_nextÚ	tracebackÚ
extract_tbr
   ÚAttributeErrorr-   Úwrite)ÚfileÚexc_typeÚ	exc_valueZexc_tbÚtbÚstackÚtypeÚfnameÚlineÚfuncÚtextr   r   r   ÚSConscript_exceptionO  s"    


rw   c             C   sL   t  ¡ d }x|r&t|jjkr&|j}qW |s8tj d¡‚t	 
|¡d | _dS )zhAnnotate a node with the stack frame describing the
    SConscript file and line number that created it.r   z%could not find SConscript stack framer   N)r   r   rZ   r   r   rh   r   r   ZInternalErrorri   Úextract_stackZcreator)Znoderp   r   r   r   Úannotateh  s    
ry   c               @   s–   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zd%dd„Z	dd„ Z
d&dd„Zdd„ Zdd„ Zdd„ Zd'dd„Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$S )(ÚSConsEnvironmenta9  An Environment subclass that contains all of the methods that
    are particular to the wrapper SCons interface and which aren't
    (or shouldn't be) part of the build engine itself.

    Note that not all of the methods of this class have corresponding
    global functions, there are some private methods.
    c             C   s   ||kp||ko||kS )zqReturn 1 if 'major' and 'minor' are greater than the version
        in 'v_major' and 'v_minor', and 0 otherwise.r   )r.   ÚmajorÚminorÚv_majorÚv_minorr   r   r   Ú_exceeds_version„  s    z!SConsEnvironment._exceeds_versionc             C   sl   |  d¡d   d¡}t|d ƒ}tt d|d ¡ ¡ ƒ}t|ƒdkr^tt d|d ¡ ¡ ƒ}nd}|||fS )zµSplit a version string into major, minor and (optionally)
        revision parts.

        This is complicated by the fact that a version string can be
        something like 3.2b1.ú r   Ú.z\d+r   é   r   )r4   ÚintÚreÚmatchÚgroupr7   )r.   Zversion_stringÚversionr}   r~   Z
v_revisionr   r   r   Ú_get_major_minor_revision‰  s    z*SConsEnvironment._get_major_minor_revisionc                sö  g }t |ƒdkrzy|d }W n  tk
r<   tj d¡‚Y nX t|ƒsL|g}ttt|ƒƒ}| 	dd¡‰ ‡ fdd„|D ƒ}nFt |ƒdkr|d }n0t |ƒd	kr´|d }|  
|d ¡}ntj d
¡‚t|ƒsÎ|g}| 	d¡rì| |  
|d ¡¡ | 	d¡}|rît |ƒdkrtj d¡‚| 	dd¡}| 	d¡}|s`tj t|d ƒ¡\}}	tj t|ƒ|	¡g}n~t|tjjƒs|| j |¡}|d }
t|
tjjƒs | j |
¡}
|
 |¡rÌ|
 |¡}	tj t|ƒ|	¡g}n
|
 ¡ g}||d< | j |||¡ ||fS )a$  
        Convert the parameters passed to SConscript() calls into a list
        of files and export variables.  If the parameters are invalid,
        throws SCons.Errors.UserError. Returns a tuple (l, e) where l
        is a list of SConscript filenames and e is a list of exports.
        r   Údirsz(Invalid SConscript usage - no parametersr\   Ú
SConscriptc                s   g | ]}t j |ˆ ¡‘qS r   )rY   rJ   Újoin)Ú.0Ún)r\   r   r   ú
<listcomp>­  s    z>SConsEnvironment._get_SConscript_filenames.<locals>.<listcomp>r   r   z/Invalid SConscript() usage - too many argumentsr   Úvariant_dirzOInvalid SConscript() usage - can only specify one SConscript with a variant_dirÚ	duplicaterF   )r7   r   r   r   r   r   ÚlistÚmapr-   r   ÚSplitÚextendrY   rJ   r4   r‹   r)   r*   r/   rS   r,   rV   rU   rQ   Z
VariantDir)r.   Úlsr:   r   r‰   ra   r   r   rF   rs   rc   r   )r\   r   Ú_get_SConscript_filenames˜  sT    





z*SConsEnvironment._get_SConscript_filenamesc             O   s>   t jjst j d¡‚| dd¡d |d< t jjj| f|ž|ŽS )Nz1Calling Configure from Builders is not supported.Ú_depthr   r   )	r   r>   rK   r   r   r   ÚEnvironmentÚBaseÚ	Configure)r.   Úargsr:   r   r   r   rš   â  s    zSConsEnvironment.Configurec             G   s   t j | |¡ d S )N)r   r>   Z_Set_Default_Targets)r.   Ztargetsr   r   r   ÚDefaultè  s    zSConsEnvironment.Defaultr   c             C   sz   t jdkr t j t jjd¡ dS |  t j¡}||||fk rv|rNd|||f }nd||f }td|t jf ƒ t d¡ dS )z8Exit abnormally if the SCons version is not late enough.Z__VERSION__z5EnsureSConsVersion is ignored for development versionNz%d.%d.%dz%d.%dz3SCons %s or greater required, but you have SCons %sr   )	r   Ú__version__r?   r@   ZDevelopmentVersionWarningrˆ   r_   r   Úexit)r.   r{   r|   ZrevisionZ	scons_verZscons_ver_stringr   r   r   ÚEnsureSConsVersionë  s    
z#SConsEnvironment.EnsureSConsVersionc             C   s<   t j||fk r8t j ¡ d }td|||f ƒ t  d¡ dS )z9Exit abnormally if the Python version is not late enough.r   z8Python %d.%d or greater required, but you have Python %sr   N)r   Úversion_infor‡   r4   r_   rž   )r.   r{   r|   r<   r   r   r   ÚEnsurePythonVersionü  s    z$SConsEnvironment.EnsurePythonVersionc             C   s   t  |¡ d S )N)r   rž   )r.   Úvaluer   r   r   ÚExit  s    zSConsEnvironment.Exitc             O   s0   x |D ]}t  t|  |¡ƒ¡ qW t  |¡ d S )N)Úglobal_exportsr   r"   r“   )r.   r9   r:   r;   r   r   r   ÚExport  s    
zSConsEnvironment.Exportc             C   s   t S )N)Ú
launch_dir)r.   r   r   r   ÚGetLaunchDir  s    zSConsEnvironment.GetLaunchDirc             C   s   |   |¡}tjj |¡S )N)Úsubstr   r>   r   Ú	GetOption)r.   r\   r   r   r   r©     s    
zSConsEnvironment.GetOptionFc             C   s"   | j |dd}tjj||d d S )Nr   )Úraw)r5   )r¨   r   r>   ZHelpFunction)r.   rv   r5   r   r   r   ÚHelp  s    zSConsEnvironment.Helpc          
   G   s¶   y~t d }|j}|j}xd|D ]\}|  |¡}xL|D ]D}|dkrR| t¡ | |¡ q0||krh|| ||< q0t| ||< q0W qW W n2 tk
r° } ztj 	d| ¡‚W d d }~X Y nX d S )Nr2   Ú*z$Import of non-existent variable '%s')
r6   r&   r   r“   r   r¤   r   r   r   r   )r.   r9   r   r&   r   r;   r<   r!   r   r   r   ÚImport  s    



zSConsEnvironment.Importc       	         sš   ˆ j fdd„}tt||ƒƒ}i }xN| ¡ D ]B\}}t|ƒrFˆ   |¡}ntj |¡rd‡ fdd„|D ƒ}|||< q*W ˆ  ||¡\}}||d< t	ˆ j
f|ž|ŽS )aû  Execute SCons configuration files.

        Parameters:
            *ls (str or list): configuration file(s) to execute.

        Keyword arguments:
            dirs (list): execute SConscript in each listed directory.
            name (str): execute script 'name' (used only with 'dirs').
            exports (list or dict): locally export variables the
              called script(s) can import.
            variant_dir (str): mirror sources needed for the build in
             a variant directory to allow building in it.
            duplicate (bool): physically duplicate sources instead of just
              adjusting paths of derived files (used only with 'variant_dir')
              (default is True).
            must_exist (bool): fail if a requested script is missing
              (default is False, default is deprecated).

        Returns:
            list of variables returned by the called script

        Raises:
            UserError: a script is not found and such exceptions are enabled.
        c             S   s(   t j | ¡rtt|| ƒƒ} n|| ƒ} | S )N)r   ÚUtilr   r‘   r’   )r!   r¨   r   r   r   Úsubst_elementD  s    z2SConsEnvironment.SConscript.<locals>.subst_elementc                s"   g | ]}t |ƒrˆ  |¡n|‘qS r   )r   r¨   )rŒ   r<   )r.   r   r   rŽ   P  s    z/SConsEnvironment.SConscript.<locals>.<listcomp>r   )r¨   r‘   r’   Úitemsr   r   r®   r   r–   rf   r/   )	r.   r•   r:   r¯   Zsubst_kwÚkeyÚvalra   r   r   )r.   r   rŠ   *  s    zSConsEnvironment.SConscriptc             C   s   |a d S )N)rW   )r.   Úflagr   r   r   ÚSConscriptChdirW  s    z SConsEnvironment.SConscriptChdirc             C   s   |   |¡}tjj ||¡ d S )N)r¨   r   r>   r   Ú	SetOption)r.   r\   r¢   r   r   r   rµ   [  s    
zSConsEnvironment.SetOptionN)r   )r   )F)r
   r   r   r1   r   rˆ   r–   rš   rœ   rŸ   r¡   r£   r¥   r§   r©   r«   r­   rŠ   r´   rµ   r   r   r   r   rz   x  s"   J


-rz   c              O   s*   t jjst j d¡‚d|d< t jj| |ŽS )Nz1Calling Configure from Builders is not supported.r   r—   )r   r>   rK   r   r   ZSConf)r›   r:   r   r   r   rš   d  s    rš   c              C   s   t stj ¡ } tj | ¡a t S )N)Ú_DefaultEnvironmentProxyr   ÚDefaultsÚDefaultEnvironmentr˜   ZNoSubstitutionProxy)Zdefault_envr   r   r   Úget_DefaultEnvironmentProxy{  s    
r¹   c               @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚDefaultEnvironmentCallaö  A class that implements "global function" calls of
    Environment methods by fetching the specified method from the
    DefaultEnvironment's class.  Note that this uses an intermediate
    proxy class instead of calling the DefaultEnvironment method
    directly so that the proxy can override the subst() method and
    thereby prevent expansion of construction variables (since from
    the user's point of view this was called as a global function,
    with no associated construction environment).r   c             C   s    || _ |rtjj| _nt| _d S )N)Úmethod_namer   r·   r¸   Úfactoryr¹   )r.   r»   r¨   r   r   r   r0   ‹  s    zDefaultEnvironmentCall.__init__c             O   s   |   ¡ }t|| jƒ}|||ŽS )N)r¼   Úgetattrr»   )r.   r›   r:   ÚenvÚmethodr   r   r   Ú__call__‘  s    zDefaultEnvironmentCall.__call__N)r   )r
   r   r   r1   r0   rÀ   r   r   r   r   rº   ‚  s   
rº   c              C   s^   t dkrVi a ddl} | jj}|t| jƒfdd„}x$t|t| jƒƒD ]}|| t |< qBW t  ¡ S )zi
    Create a dictionary containing all the default globals for
    SConstruct and SConscript files.
    Nr   c             S   s   t ||  |ƒ S )N)r)   )ÚmÚdZmtyper   r   r   Únot_a_module£  s    z)BuildDefaultGlobals.<locals>.not_a_module)Ú
GlobalDictZSCons.Scriptr>   Ú__dict__rr   ÚfilterrT   Úcopy)r   rÂ   rÃ   rÁ   r   r   r   r%   —  s    r%   )N)7r1   r   ZSCons.ActionZSCons.BuilderZSCons.DefaultsZSCons.EnvironmentZSCons.ErrorsZ
SCons.NodeZSCons.Node.AliasZSCons.Node.FSZSCons.PlatformZSCons.SConfZ
SCons.ToolZ
SCons.Utilr   r   r   r   r   Ú r   rY   Úos.pathr„   r   ri   r[   Ú	Exceptionr	   rJ   ÚabspathÚcurdirr¦   rÄ   r¤   rW   r   r"   r#   r6   r=   rZ   rD   rf   Ústderrrw   ry   r˜   r™   rz   rš   r¶   r¹   rº   r%   r   r   r   r   Ú<module>   sZ   
#  k