B
    b,                 @   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ZddlZddlZddlZddlmZ ddlmZ dej_dej_daddgZdd ZdZdZd	Zd
Zea dd Z!dd Z"ej#j$a%dd Z&da'ee(a)i a*i a+da,dd Z-dd Z.dd Z/dd Z0G dd dej1j2Z3ej14e3 G dd dej5j6Z7G dd de7Z8G dd  d e7Z9d!d" Z:d#d$ Z;G d%d& d&ej<j=j>Z?G d'd( d(Z@G d)d* d*ejAjBZCG d+d, d,ZDG d-d. d.ZEd/d0 ZFdUd1d2ZGdVd4d5ZHdWd6d7ZIdXd8d9ZJdYd:d;ZKdZd=d>ZLd[d@dAZMdBdC ZNdDdE ZOdFdG ZPdHdI ZQd\dJdKZRd]dLdMZSd^dOdPZTd_dQdRZUdSdT ZVdS )`a  Autoconf-like configuration support.

In other words, SConf allows to run tests on the build machine to detect
capabilities of system and do some things based on result: generate config
files, header files for C/C++, update variables in environment.

Tests on the build system can detect if compiler sees header files, if
libraries are installed, if some command line options are supported etc.
    N)Trace)defaultdictZcleanhelpc             C   s   | a d S )N)
build_type)Z	buildtype r   *lib/python3.7/site-packages/SCons/SConf.pySetBuildType@   s    r         c             C   s   d| j _d S )Nr	   )
attributesZconftest_node)noder   r   r   _set_conftest_nodeL   s    r   c             C   s:   | dkrt an(| dkrtan| dkr*tantd|  dS )zRSet the Configure cache mode. mode must be one of "auto", "force",
    or "cache".autoZforcecachez'SCons.SConf.SetCacheMode: Unknown mode N)AUTO
cache_modeFORCECACHE
ValueError)moder   r   r   SetCacheModeO   s    r   c             C   s   | a dS )z:Set the progress display to use (called from SCons.Script)N)progress_display)displayr   r   r   SetProgressDisplay]   s    r   c             C   sr   t t| d d}tddt| d  }|dd|i  ||d    |dd|i  |  d S )Nr   wz[^A-Za-z0-9_]_z3#ifndef %(DEFNAME)s_SEEN
#define %(DEFNAME)s_SEEN

ZDEFNAMEz
#endif /* %(DEFNAME)s_SEEN */
)	openstrresubupperwriteget_contentsdecodeclose)targetsourceenvtZdefnamer   r   r   _createConfigHi   s    r)   c             C   s   dt | d  S )Nzscons: Configure: creating r   )r   )r%   r&   r'   r   r   r   _stringConfigHv   s    r*   c               C   s   t tdkrdS dS d S )Nr   FT)len_ac_config_hsr   r   r   r   NeedConfigHBuilderz   s    r-   c             C   sX   t jtt}t jj|d}| jd|id x&t D ]\}}| || 	| q6W dS )zBCalled if necessary just before the building targets phase begins.)actionSConfigHBuilder)BUILDERSN)
SConsActionr)   r*   BuilderAppendr,   itemsr/   Value)r'   r.   ZsconfigHBldkvr   r   r   CreateConfigHBuilder   s    r9   c               @   s   e Zd ZdS )SConfWarningN)__name__
__module____qualname__r   r   r   r   r:      s   r:   c                   s   e Zd Z fddZ  ZS )
SConfErrorc                s   t  | d S )N)super__init__)selfmsg)	__class__r   r   r@      s    zSConfError.__init__)r;   r<   r=   r@   __classcell__r   r   )rC   r   r>      s   r>   c                   s    e Zd ZdZ fddZ  ZS )ConfigureDryRunErrorztRaised when a file or directory needs to be updated during a Configure
    process, but the user requested a dry-runc                s:   t |tjjjsdt| }ndt| }t | d S )Nz8Cannot create configure directory "%s" within a dry-run.z3Cannot update configure test "%s" within a dry-run.)
isinstancer1   NodeFSFiler   r?   r@   )rA   r%   rB   )rC   r   r   r@      s    zConfigureDryRunError.__init__)r;   r<   r=   __doc__r@   rD   r   r   )rC   r   rE      s   rE   c                   s    e Zd ZdZ fddZ  ZS )ConfigureCacheErrorzbRaised when a use explicitely requested the cache feature, but the test
    is run the first time.c                s   t  dt|  d S )Nz*"%s" is not yet built and cache is forced.)r?   r@   r   )rA   r%   )rC   r   r   r@      s    zConfigureCacheError.__init__)r;   r<   r=   rJ   r@   rD   r   r   )rC   r   rK      s   rK   c             C   s4   t t| d d}||d    |  d S )Nr   r   )r   r   r!   r"   r#   r$   )r%   r&   r'   fdr   r   r   _createSource   s    rM   c             C   s(   t | d d |d   dd S )Nr   z <-
  |
z
  |)r   r"   r#   replace)r%   r&   r'   r   r   r   _stringSource   s    rP   c               @   s$   e Zd ZdZdZdd Zdd ZdS )SConfBuildInfoz
    Special build info for targets of configure tests. Additional members
    are result (did the builder succeed last time?) and string, which
    contains messages of the original build phase.
    )resultstringc             C   s   d | _ d | _d S )N)rR   rS   )rA   r   r   r   r@      s    zSConfBuildInfo.__init__c             C   s   || _ || _d S )N)rR   rS   )rA   rR   rS   r   r   r   set_build_result   s    zSConfBuildInfo.set_build_resultN)r;   r<   r=   rJ   	__slots__r@   rT   r   r   r   r   rQ      s   rQ   c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )StreamerzR
    'Sniffer' for a file-like writable object. Similar to the unix tool tee.
    c             C   s   || _ t | _d S )N)origioStringIOs)rA   rW   r   r   r   r@      s    zStreamer.__init__c          
   C   sZ   | j r| j | y| j| W n2 tk
rT } z| j|  W d d }~X Y nX d S )N)rW   r!   rZ   	TypeErrorr#   )rA   r   er   r   r   r!      s    zStreamer.writec             C   s    x|D ]}|  |d  qW d S )NrN   )r!   )rA   lineslr   r   r   
writelines   s    
zStreamer.writelinesc             C   s
   | j  S )zS
        Return everything written to orig since the Streamer was created.
        )rZ   getvalue)rA   r   r   r   r`      s    zStreamer.getvaluec             C   s   | j r| j   | j  d S )N)rW   flushrZ   )rA   r   r   r   ra      s    
zStreamer.flushN)	r;   r<   r=   rJ   r@   r!   r_   r`   ra   r   r   r   r   rV      s   	rV   c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )SConfBuildTaskz
    This is almost the same as SCons.Script.BuildTask. Handles SConfErrors
    correctly and knows about the current cache_mode.
    c             C   s   t jrt jd| d  d S )Nzscons: Configure: rN   )sconf_global	logstreamr!   )rA   messager   r   r   r      s    zSConfBuildTask.displayc             C   sD   t |ts tjtd|j  n | ddt|j	 
dd  dS )zc
        Logs the original builder messages, given the SConfBuildInfo instance
        bi.
        z8The stored build information has an unexpected class: %sz!The original builder output was:
z  |rN   z
  |N)rF   rQ   r1   Warningswarnr:   rC   r   r   rS   rO   )rA   bir   r   r   display_cached_string   s    
z$SConfBuildTask.display_cached_stringc             C   sb   |   d }t|tr n:t|tjjr2|   n"| d| jd   t	j
|     tjj| S )Nr   z&Caught exception while building "%s":
)exc_info
issubclassr>   r1   Errors
BuildErrorZ	exc_clearr   targetssys
excepthook
TaskmasterZTaskfailed)rA   exc_typer   r   r   rr      s    

zSConfBuildTask.failedc             C   s  d}d}d}d}x| j D ]}|r,td|  | j}t|tr|rLtd ttkrp|t	j
j |rtd nT|rtd|   |rtd|   | t	j
jkr| rd}|rtd	|  |p|j}q|rtd
 d}| t	j
jk}|rtd	|  qW |rtd | ||fS )Nr   FTz%sz: SConfBuildInfoz: set_state(up_to-date)z: get_state() %sz: changed() %sz: changed %sz: elserN   )rn   r   get_stored_infobinforF   rQ   r   r   Z	set_stater1   rG   
up_to_date	get_statechangedrR   )rA   Trx   cached_errorcachabler(   rh   r   r   r   collect_node_states
  sB     

  
      z"SConfBuildTask.collect_node_statesc          
   C   s  | j d  sd S t}|  \}}}ttkr@|s@t| j d nttkrLd}|r|r| dt	| j d   | j d 
 j}| | tjjn|r| dt	| j d   | j d 
 j}| | ntrt| j d nttj } t_t_y\| j d  }| |d< |d< zd|_| j d   W d |j t_ t_ |d< |d< X W n tk
rn    Y n* tk
r   t d }tj| j d |jY n tk
r0 }	 znxd| j D ]Z}
t  }|!|
"  |#d|$  tj%& }||_|
j'( }|)|
j*| |!  qW |	W d d }	~	X Y nhX xd| j D ]Z}
t  }|!|
"  |#d|$  tj%& }||_|
j'( }|)|
j*| |!  q:W d S )Nr   zJBuilding "%s" failed in a previous run and all its sources are up to date.z"%s" is up to date.ZPSTDOUTZPSTDERRr	   )+rn   has_builderrc   r|   r   r   rK   r   r   r   rt   ru   ri   r1   rl   rm   dryrunrE   rV   ro   stdoutstderrZget_build_envcachedZbuildrd   KeyboardInterrupt
SystemExitrj   ZExplicitExitcode	ExceptionrQ   mergeZ	get_binforT   r`   ZSConsignZSConsignEntrydirsconsignZ	set_entryname)rA   sconfZis_up_to_daterz   r{   ru   rZ   r'   	exc_valuer\   r(   Zsconsign_entryr   r   r   r   execute-  sj    
$



zSConfBuildTask.executeN)	r;   r<   r=   rJ   r   ri   rr   r|   r   r   r   r   r   rb      s   #rb   c               @   s   e Zd ZdZi ddddfddZdd	 Zd'd
dZdd Zdd Zd(ddZ	d)ddZ
dd Zdd Zdd ZG dd dZdd Zdd  Zd!d" Zd#d$ Zd%d& ZdS )*	SConfBasea  This is simply a class to represent a configure context. After
    creating a SConf object, you can call any tests. After finished with your
    tests, be sure to call the Finish() method, which returns the modified
    environment.
    Some words about caching: In most cases, it is not necessary to cache
    Test results explicitly. Instead, we use the scons dependency checking
    mechanism. For example, if one wants to compile a test program
    (SConf.TryLink), the compiler is only called, if the program dependencies
    have changed. However, if the program could not be compiled in a former
    SConf run, we need to explicitly cache this error.
    z$CONFIGUREDIRz$CONFIGURELOGNr   c       	      C   s&  t tkrF|| _| | _d|jfdd}| jjj|jk	rL| j| n|| _tslt	j
jjpjt	j
j|jjatdk	rt	jd|dk	rt||}|| _d| _d| _|| _d| _tttttttt t!t"t#t$t%t&t'd}| (| | (| t)||| _*|dk	rt|}|| _+| ,  dS )a<  Constructor. Pass additional tests in the custom_tests-dictionary,
        e.g. custom_tests={'CheckPrivate':MyPrivateTest}, where MyPrivateTest
        defines a custom test.
        Note also the conf_dir and log_file arguments (you may want to
        build tests in the VariantDir, not in the SourceDir)
        Nc          
   S   s>   y|| ||| W n& t k
r8 } z|W d d }~X Y nX dS )NT)r   )Z
dependencyr%   Zprev_niZ	repo_nodeZenv_deciderr\   r   r   r   force_build  s
    z'SConfBase.__init__.<locals>.force_buildzConfigure() called while another Configure() exists.
            Please call .Finish() before creating and second Configure() contextr   )CheckCCCheckCXX	CheckSHCC
CheckSHCXX	CheckFunc	CheckTypeCheckTypeSizeCheckMemberCheckDeclarationCheckHeaderCheckCHeaderCheckCXXHeaderCheckLibCheckLibWithHeader	CheckProg)-r   r   original_envZCloner'   decide_source__code__DeciderSConfFSr1   rG   rH   Z
default_fsfsZpathToprc   rl   	UserErrorrI   substlogfilerd   
lastTargetdepthr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   AddTestsZDirconfdirconfig_h_startup)	rA   r'   Zcustom_testsZconf_dirZlog_filer   _depthr   Zdefault_testsr   r   r   r@     sV    





zSConfBase.__init__c             C   s   |    | jS )z^Call this method after finished with your tests:
                env = sconf.Finish()
        )	_shutdownr'   )rA   r   r   r   Finish  s    zSConfBase.Finishc             C   sb   g }|rd| }| | |dk	r0d||f }nd| }| | | d | jd| | _dS )a  
        Define a pre processor symbol name, with the optional given value in the
        current config header.

        If value is None (default), then #define name is written. If value is not
        none, then #define name value is written.

        comment is a string which will be put as a C comment in the header, to explain the meaning of the value
        (appropriate C comments will be added automatically).
        z/* %s */Nz#define %s %sz
#define %s rN   )appendconfig_h_textjoin)rA   r   valuecommentr]   Zcomment_strZ
define_strr   r   r   Define  s    


zSConfBase.Definec          
   C   s  | j dk	r&tj}| j t_tj}| j t_t }t }tjtjdd x|D ]~}t	| d|_
t|dsvtjj |_d|j_xJ|jddD ]:}t	| | rd|_
t|dstjj |_d|j_qW qLW d}zrt }	td tj|t}
tjd|
}|  x6|D ].}| }|tjjkr|tjjkrd}qW W dt|	 t| tj|dd | j dk	r|t_|t_X |S )zg
        Tries to build the given nodes immediately. Returns 1 on success,
        0 on error.
        Nr	   )change_os_dirr   r   F)scan)rd   ro   r   r   r   getcwdoschdirTopr   Z
store_infohasattrr1   rG   ZAttrsr   Zkeep_targetinfoZchildrenr}   Zget_max_driftZset_max_driftrq   rb   ZJobZJobsrunrw   Zexecutedrv   )rA   nodesZ	oldStdoutZ	oldStderr
old_fs_dirZ
old_os_dirncretZsave_max_driftZtmZjobsstater   r   r   
BuildNodes  sP    







zSConfBase.BuildNodesc          	   C   s   |  |||||| j| jS )a  Wrapper function for handling piped spawns.

        This looks to the calling interface (in Action.py) like a "normal"
        spawn, but associates the call with the PSPAWN variable from
        the construction environment and with the streams to which we
        want the output logged.  This gets slid into the construction
        environment as the SPAWN variable so Action.py doesn't have to
        know or care whether it's spawning a piped command or not.
        )pspawnrd   )rA   Zshescapecmdargsr'   r   r   r   pspawn_wrapper<  s    
zSConfBase.pspawn_wrapperr   c          	   C   s  y| j d | _W n  tk
r0   tjdY nX y| j d }W n  tk
r`   tjdY nX g }| j |}t| d}|dk	rtj	|}t
t| }	t|  d7  < d|||	g}| j|| }
t|
 | j j|
|d	}|| |
}|
|d
 }t| nd}d}|jjj||g| j d}tj	|}d||g}| j |jj}| j |jj}| j|| | }t| zF| j| j d< |||dd}tj|s|g}|| | |}W d|| j d< X |r|d | _nd| _|S )zLow level TryBuild implementation. Normally you don't need to
        call that - you can use TryCompile / TryLink / TryRun instead
        ZPSPAWNz%Missing PSPAWN construction variable.ZSPAWNz$Missing SPAWN construction variable.ZconftestNr	   r   )r%   r&   ZSConfActionsContentDummyTarget)r%   r&   r'   T)r%   r&   Z
SCONF_NODEr   )r'   r   KeyErrorr1   rl   r   r6   r   UtilZhash_signaturer   _ac_build_counterr   r   rI   SConfSourceBuilderextendbuilderr.   r"   r   prefixsuffixr   is_Listr   r   )rA   r   text	extensionZ
save_spawnZnodesToBeBuiltZ
sourcetextfZtextSigZtextSigCounterZtextFileZtextFileNoder&   r%   r.   Z	actionsigZprefZsuffr   rR   r   r   r   TryBuildH  s\    



zSConfBase.TryBuildc             C   sX   t jj|d}| jjd|id | | jj||}| jd d= |rT| j }d|fS dS )zTries to execute the given action with optional source file
        contents <text> and optional source file extension <extension>,
        Returns the status (0 : failed, 1 : ok) and the contents of the
        output file.
        )r.   SConfActionBuilder)r0   r0   r	   )r   r   )r1   r3   r'   r4   r   r   r   Zget_text_contents)rA   r.   r   r   r   ok	outputStrr   r   r   	TryAction  s    
zSConfBase.TryActionc             C   s   |  | jj||S )zCompiles the program given in text to an env.Object, using extension
        as file extension (e.g. '.c'). Returns 1, if compilation was
        successful, 0 otherwise. The target is saved in self.lastTarget (for
        further processing).
        )r   r'   Object)rA   r   r   r   r   r   
TryCompile  s    zSConfBase.TryCompilec             C   s   |  | jj||S )a  Compiles the program given in text to an executable env.Program,
        using extension as file extension (e.g. '.c'). Returns 1, if
        compilation was successful, 0 otherwise. The target is saved in
        self.lastTarget (for further processing).
        )r   r'   Program)rA   r   r   r   r   r   TryLink  s    zSConfBase.TryLinkc       	      C   sx   |  ||}|rt| j}| }| jtj|d }| j	|||ddgg}| 
|}|rttj| }d|fS dS )a  Compiles and runs the program given in text, using extension
        as file extension (e.g. '.c'). Returns (1, outputStr) on success,
        (0, '') otherwise. The target (a file containing the program's stdout)
        is saved in self.lastTarget (for further processing).
        z.out>z	${TARGET}r	   )r   r   )r   r   Zget_internal_pathr   rI   r   pathbasenamer'   ZCommandr   r1   r   Zto_strr"   )	rA   r   r   r   progZpnameoutputr   r   r   r   r   TryRun  s    
zSConfBase.TryRunc               @   s    e Zd ZdZdd Zdd ZdS )zSConfBase.TestWrapperz)A wrapper around Tests (to ensure sanity)c             C   s   || _ || _d S )N)testr   )rA   r   r   r   r   r   r@     s    zSConfBase.TestWrapper.__init__c             O   sX   | j jstjjt| j }| j|f||}| j jd k	rJ| j j|j | j _|	d |S )Nzerror: no result)
r   activer1   rl   r   CheckContextr   r   r   Result)rA   r   kwcontextr   r   r   r   __call__  s    

zSConfBase.TestWrapper.__call__N)r;   r<   r=   rJ   r@   r   r   r   r   r   TestWrapper  s   r   c             C   s   t | |t||  dS )zYAdds test_class to this SConf instance. It can be called with
        self.test_name(...)N)setattrr   r   )rA   Z	test_nameZtest_instancer   r   r   AddTest  s    zSConfBase.AddTestc             C   s&   x |  D ]}| |||  q
W dS )zXAdds all the tests given in the tests dictionary to this SConf
        instance
        N)keysr   )rA   Ztestsr   r   r   r   r     s    zSConfBase.AddTestsc             C   s<   t |}tr"tj|s8t|ntj|s8t| d S )N)r   r~   r   r   isdirrE   makedirs)rA   r   ZdirNamer   r   r   
_createDir  s    
zSConfBase._createDirc             C   sN  | j j| _t| j _| | j | j | jg | jdk	rt	s| jt
krPd}ndt
| j< d}tt| j|}dd }t|| tj|| _| jj| jg t d| j  }t }tjtjdd | jd	|d |d
 t| jf  t| nd| _tjtt}tjj|d}| j jd|id t !| j"d| _#d
| _$| a%dS )zpPrivate method. Set up logstream, and set the environment
        variables necessary for a piped build
        Nar   c             S   s   |    d S )N)r$   )Zlogfr   r   r   conflog_cleanup  s    z+SConfBase._startup.<locals>.conflog_cleanupr   )r   z*file %s,line %d:
	Configure(confdir = %s)
r	   )r.   r   )r0   r   )&r'   r   	lastEnvFsr   r   r   ZupZ
add_ignorer   r~   _ac_config_logsr   r   atexitregisterr1   r   Z
Unbufferedrd   r   	tracebackextract_stackr   r   r   r   r!   r2   rM   rP   r3   r4   r,   getr   r   r   rc   )rA   Zlog_modefpr   tbr   r.   ZsconfSrcBldr   r   r   r     s8    


zSConfBase._startupc             C   s   | j stjd| jdk	r<ts<| jd | j  d| _tt	krr| j
| jj | j
d }|d= | j
j|d d| _ da| jdk	r| jt| j< | j| j
_dS )z(Private method. Reset to non-piped spawnzFinish may be called only once!NrN   r0   r   )r0   r   )r   r1   rl   r   rd   r~   r!   r$   r   r   r'   r   r   r   Replacerc   r   r   r,   r   r   )rA   Zbldsr   r   r   r     s     


zSConfBase._shutdown)NN)Nr   )Nr   )r;   r<   r=   rJ   r@   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   {  s$   M
E
G
	3r   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 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&S )'r   a?  Provides a context for configure tests. Defines how a test writes to the
    screen and log file.

    A typical test is just a callable with an instance of CheckContext as
    first argument:

        def CheckCustom(context, ...):
            context.Message('Checking my weird test ... ')
            ret = myWeirdTestFunction(...)
            context.Result(ret)

    Often, myWeirdTestFunction will be one of
    context.TryCompile/context.TryLink/context.TryRun. The results of
    those are cached, for they are only rebuild, if the dependencies have
    changed.
    c             C   s(   || _ d| _i | _i | _d| _d| _dS )z3Constructor. Pass the corresponding SConf instance.r   Nr   )r   did_show_resultZvardictZhavedictZheaderfilenamer   )rA   r   r   r   r   r@   E  s    zCheckContext.__init__c             C   s   |  | d| j_d| _dS )z]Inform about what we are doing right now, e.g.
        'Checking for SOMETHING ... '
        r	   r   N)Displayr   r   r  )rA   r   r   r   r   MessageW  s    
zCheckContext.Messagec             C   s@   t |tr|}n|rd}nd}| jdkr<| |d  d| _dS )zInform about the result of the test. If res is not a string, displays
        'yes' or 'no' depending on whether res is evaluated as true or false.
        The result is only displayed when self.did_show_result is not set.
        ZyesZnor   rN   r	   N)rF   r   r  r  )rA   resr   r   r   r   r   _  s    

zCheckContext.Resultc             O   s   | j j||S )N)r   r   )rA   r   r   r   r   r   r   p  s    zCheckContext.TryBuildc             O   s   | j j||S )N)r   r   )rA   r   r   r   r   r   r   s  s    zCheckContext.TryActionc             O   s   | j j||S )N)r   r   )rA   r   r   r   r   r   r   v  s    zCheckContext.TryCompilec             O   s   | j j||S )N)r   r   )rA   r   r   r   r   r   r   y  s    zCheckContext.TryLinkc             O   s   | j j||S )N)r   r   )rA   r   r   r   r   r   r   |  s    zCheckContext.TryRunc             C   s0   |dkr| j jS |dkr | j jS td| d S )Nr'   r   z+CheckContext instance has no attribute '%s')r   r'   r   AttributeError)rA   attrr   r   r   __getattr__  s
    zCheckContext.__getattr__c             C   s   d| j _| | jj|| S )Nr	   )r   r   r   r'   r   )rA   r   extr   r   r   	BuildProg  s    zCheckContext.BuildProgc             C   s   d| j _| | jj|| S )Nr	   )r   r   r   r'   r   )rA   r   r  r   r   r   CompileProg  s    zCheckContext.CompileProgc             C   s   d| j _| | jj|| S )Nr	   )r   r   r   r'   ZSharedObject)rA   r   r  r   r   r   CompileSharedObject  s    z CheckContext.CompileSharedObjectc             C   s"   d| j _| ||\}}| |fS )Nr	   )r   r   r   )rA   r   r  stoutr   r   r   RunProg  s    zCheckContext.RunProgc             C   s    | j dg }| j j|d |S )NLIBS)r  )r'   r   r4   )rA   lib_name_listoldLIBSr   r   r   
AppendLIBS  s    zCheckContext.AppendLIBSc             C   s    | j dg }| j j|d |S )Nr  )r  )r'   r   ZPrepend)rA   r  r  r   r   r   PrependLIBS  s    zCheckContext.PrependLIBSc             C   s    | j dg }| j j|d |S )Nr  )r  )r'   r   r   )rA   valr  r   r   r   SetLIBS  s    zCheckContext.SetLIBSc             C   s:   | j jrd| }d| j _t|dd | d| d  d S )Nz	(cached) r   )Zappend_newlinezscons: Configure: rN   )r   r   r   Log)rA   rB   r   r   r   r    s
    zCheckContext.Displayc             C   s   | j jd k	r| j j| d S )N)r   rd   r!   )rA   rB   r   r   r   r    s    zCheckContext.LogN)r;   r<   r=   rJ   r@   r  r   r   r   r   r   r   r  r	  r
  r  r  r  r  r  r  r  r   r   r   r   r   3  s&   

r   c           	   O   sf   | tdrX| ddd |d< x,tD ]$}y
||= W q& tk
rH   Y q&X q&W t| |S tj S d S )NTr   r   r	   )r   r   build_typesr   r   r1   r   ZNull)r   r   Zbtr   r   r   SConf  s    



r  c             C   s    t jj| |||d}d| _| S )N)headerlanguager	   )r1   Conftestr   r  )r   Zfunction_namer  r  r  r   r   r   r     s    r   r   c             C   s    t jj| |||d}d| _| S )N)r  r  r	   )r1   r  r   r  )r   	type_nameincludesr  r  r   r   r   r     s    

r   c             C   s    t jj| ||||d}d| _|S )N)r  r  expectr	   )r1   r  r   r  )r   r  r  r  r  r  r   r   r   r     s
    
r   c             C   s    t jj| |||d}d| _| S )N)r  r  r	   )r1   r  r   r  )r   Zdeclarationr  r  r  r   r   r   r     s
    
r   c             C   s    t jj| |||d}d| _| S )z/Returns the status (False : failed, True : ok).)r  r  r	   )r1   r  r   r  )r   Zaggregate_memberr  r  r  r   r   r   r     s    r   ""c             C   sl   t j| s| g} g }|r0| d }| d d } nd }x(| D ] }|d|d ||d f  q:W d||fS )Nz#include %s%s%s
r   r	   r   )r1   r   r   r   r   )ZheadersZ	leaveLastinclude_quotesr^   Z
lastHeaderrZ   r   r   r   createIncludesFromHeaders  s    
r"  <>c             C   s2   t |d|\}}tjj| ||||d}d| _| S )z,
    A test for a C or C++ header file.
    r	   )r  r!  )r"  r1   r  r   r  )r   r  r!  r  prog_prefixZhdr_to_checkr  r   r   r   r     s    r   c             C   s   t j| }d| _| S )Nr	   )r1   r  r   r  )r   r  r   r   r   r     s    r   c             C   s   t j| }d| _| S )Nr	   )r1   r  r   r  )r   r  r   r   r   r     s    r   c             C   s   t j| }d| _| S )Nr	   )r1   r  r   r  )r   r  r   r   r   r     s    r   c             C   s   t j| }d| _| S )Nr	   )r1   r  r   r  )r   r  r   r   r   r     s    r   c             C   s   t | ||ddS )z%
    A test for a C header file.
    C)r  )r   )r   r  r!  r   r   r   r     s    r   c             C   s   t | ||ddS )z'
    A test for a C++ header file.
    zC++)r  )r   )r   r  r!  r   r   r   r   &  s    r   mainc             C   s@   |s
dg}t j|s|g}t jj| |||||d}d| _| S )z
    A test for a library. See also CheckLibWithHeader.
    Note that library may also be None to test whether the given symbol
    compiles without flags.
    N)r  r  autoaddr	   )r1   r   r   r  r   r  )r   ZlibraryZsymbolr  r  r'  r  r   r   r   r   -  s    
r   c       	   	   C   sP   t |d\}}|sdg}tj|s*|g}tjj| |d||||d}d| _| S )a1  
    Another (more sophisticated) test for a library.
    Checks, if library and header is available for language (may be 'C'
    or 'CXX'). Call maybe be a valid expression _with_ a trailing ';'.
    As in CheckLib, we support library=None, to test if the call compiles
    without extra link flags.
    r   N)callr  r'  r	   )r"  r1   r   r   r  r   r  )	r   Zlibsr  r  r(  r'  r$  Zdummyr  r   r   r   r   D  s    r   c             C   s   t j| |}d| _|S )zsSimple check if a program exists in the path.  Returns the path
    for the application, or None if not found.
    r	   )r1   r  r   r  )r   Z	prog_namer  r   r   r   r   [  s    r   )NN)r   N)r   NN)r   N)NN)r  )r#  N)r  )r  )Nr&  NNr	   )Nr	   )WrJ   ZSCons.compatr1   r   rX   r   r   ro   r   ZSCons.ActionZSCons.BuilderZSCons.ErrorsZ	SCons.JobZSCons.Node.FSZSCons.TaskmasterZ
SCons.UtilZSCons.WarningsZSCons.ConftestZSCons.Debugr   collectionsr   r  ZLogInputFilesZLogErrorMessagesr   r  r   r~   r   r   r   r   r   r   r   r   r   r   r   intr   r   r,   rc   r)   r*   r-   r9   rf   ZSConsWarningr:   ZenableWarningClassrl   r   r>   rE   rK   rM   rP   rG   rH   ZFileBuildInforQ   rV   rq   Z
AlwaysTaskrb   r   r   r  r   r   r   r   r   r"  r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>    s   

!    ; 







	
 

