3
^Ã_^>š  ã            	   @   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mZmZm	Z	 dZ
dZdZdZdZdZd	Zd3Zd4Zd5Zd6Zd
ZdZdZi ZG dd„ deƒZedefi ƒZG dd„ deƒZejdkrÌdd„ Zejj e_ ee_dd„ Z dd„ Z!G dd„ deƒZ"dd„ Z#dd„ Z$ej%dƒZ&ej%d ƒZ'ej%d!ej(ƒZ)d"d#„ Z*ej%d$ej(ƒZ+d%d&„ Z,d7d(d)„Z-d*d+„ Z.ddd,g g g g d'df	d-d.„Z/d/d0„ Z0eZ1G d1d2„ d2eƒZ2dS )8z6
Tasks represent atomic operations such as processes.
é    N)ÚUtilsÚLogsÚErrorsé   é   é   é   é   é	   a  
def f(tsk):
	env = tsk.env
	gen = tsk.generator
	bld = gen.bld
	cwdx = tsk.get_cwd()
	p = env.get_flat
	def to_list(xx):
		if isinstance(xx, str): return [xx]
		return xx
	tsk.last_cmd = cmd = ''' %s ''' % s
	return tsk.exec_command(cmd, cwd=cwdx, env=env.env or None)
a�  
def f(tsk):
	env = tsk.env
	gen = tsk.generator
	bld = gen.bld
	cwdx = tsk.get_cwd()
	def to_list(xx):
		if isinstance(xx, str): return [xx]
		return xx
	def merge(lst1, lst2):
		if lst1 and lst2:
			return lst1[:-1] + [lst1[-1] + lst2[0]] + lst2[1:]
		return lst1 + lst2
	lst = []
	%s
	if '' in lst:
		lst = [x for x in lst if x]
	tsk.last_cmd = lst
	return tsk.exec_command(lst, cwd=cwdx, env=env.env or None)
zå
def f(tsk):
	sig = tsk.generator.bld.hash_env_vars(tsk.env, tsk.vars)
	tsk.m.update(sig)
	env = tsk.env
	gen = tsk.generator
	bld = gen.bld
	cwdx = tsk.get_cwd()
	p = env.get_flat
	buf = []
	%s
	tsk.m.update(repr(buf).encode())
c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )Ústore_task_typezä
	Metaclass: store the task classes into the dict pointed by the
	class attribute 'register' which defaults to :py:const:`waflib.Task.classes`,

	The attribute 'run_str' is compiled into a method 'run' bound to the task class.
	c                sÜ   t t| ƒj|||ƒ | j}|dkrØ|dkrØt| dd ƒr¤t| j| jƒ\}}tj	| jƒ| _
| j| _d | _|| _tt| j| ƒƒ| _| jjƒ  | jrÈt| jƒ}|rÈ|| _n$t| dd ƒrÈd| jkrÈtj	| jƒ| _
| t| dtƒ|< d S )NÚevilÚTaskÚrun_strÚrunÚhcodeÚregister)Úsuperr   Ú__init__Ú__name__ÚgetattrÚcompile_funr   Úshellr   Úh_cmdr   Zorig_run_strr   ÚlistÚsetÚvarsÚsortÚcompile_sig_varsÚsig_varsÚ__dict__Úclasses)ÚclsÚnameÚbasesÚdictÚfÚdvarsÚfun)Ú	__class__© ú6/home/yuhw/wc/wct-package/waf-tools/waf/waflib/Task.pyr   l   s$    

zstore_task_type.__init__)r   Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r)   r)   )r(   r*   r   e   s   r   r   c               @   sN  e Zd ZdZg ZdZdZdZg Zg Z	g Z
g ZejZdZdZdZdZdMZ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%d0d1„ Z&d2d3„ Z'd4d5„ Z(d6d7„ Z)d8d9„ Z*d:d;„ Z+d<d=„ Z,d>d?„ Z-d@dA„ Z.dBdC„ Z/dDdE„ Z0dFZ1dGdH„ Z2dIdJ„ Z3dKdL„ Z4dFS )Nr   a{  
	Task objects represents actions to perform such as commands to execute by calling the `run` method.

	Detecting when to execute a task occurs in the method :py:meth:`waflib.Task.Task.runnable_status`.

	Detecting which tasks to execute is performed through a hash value returned by
	:py:meth:`waflib.Task.Task.signature`. The task signature is persistent from build to build.
	FÚGREENr   ÚhasrunÚ	generatorÚenvÚinputsÚoutputsÚ	dep_nodesÚ	run_afterc             O   sX   t | _y|d | _W n tk
r.   | | _Y nX |d | _g | _g | _g | _tƒ | _	d S )Nr1   r2   )
ÚNOT_RUNr0   r1   ÚKeyErrorr2   r3   r4   r5   r   r6   )ÚselfÚkÚkwr)   r)   r*   r   Â   s    
zTask.__init__c             C   s   | j ƒ |j ƒ kS )N)Úpriority)r9   Úotherr)   r)   r*   Ú__lt__Ø   s    zTask.__lt__c             C   s   | j ƒ |j ƒ kS )N)r<   )r9   r=   r)   r)   r*   Ú__le__Ú   s    zTask.__le__c             C   s   | j ƒ |j ƒ k S )N)r<   )r9   r=   r)   r)   r*   Ú__gt__Ü   s    zTask.__gt__c             C   s   | j ƒ |j ƒ kS )N)r<   )r9   r=   r)   r)   r*   Ú__ge__Þ   s    zTask.__ge__c             C   sX   | j j}t| ddƒp t|d|jƒ}t|tƒrTtjj|ƒrF|j	j
|ƒ}n| j jj
|ƒ}|S )zO
		:return: current working directory
		:rtype: :py:class:`waflib.Node.Node`
		ÚcwdN)r1   Úbldr   ÚbldnodeÚ
isinstanceÚstrÚosÚpathÚisabsÚrootÚ	make_node)r9   rC   Úretr)   r)   r*   Úget_cwdá   s    
zTask.get_cwdc             C   sX   |}d|kr|j ddƒ}d|kr,|j ddƒ}||ksLd|ksLd|ksLd|krTd| }|S )	z¬
		Surround a process argument by quotes so that a list of arguments can be written to a file

		:param x: flag
		:type x: string
		:return: quoted flag
		:rtype: string
		ú\z\\ú"z\"ú ú	ú'z"%s")Úreplace)r9   ÚxÚoldr)   r)   r*   Ú
quote_flagï   s    	 zTask.quote_flagc             C   s   | j | j t| jddƒ fS )zw
		Priority of execution; the higher, the earlier

		:return: the priority value
		:rtype: a tuple of numeric values
		Ztg_idx_countr   )ÚweightÚ
prio_orderr   r1   )r9   r)   r)   r*   r<     s    zTask.priorityc                s$   |d g‡ fdd„|dd… D ƒfS )z½
		Splits a list of process commands into the executable part and its list of arguments

		:return: a tuple containing the executable first and then the rest of arguments
		:rtype: tuple
		r   c                s   g | ]}ˆ j |ƒ‘qS r)   )rV   )Ú.0rT   )r9   r)   r*   ú
<listcomp>  s    z&Task.split_argfile.<locals>.<listcomp>r   Nr)   )r9   Úcmdr)   )r9   r*   Úsplit_argfile
  s    zTask.split_argfilec             K   sž  d|kr| j ƒ |d< t| dƒr(| j|d< | jjr~t|jdƒpH| jjpHtjƒ }|d< t	| jjt
ƒrj| jjntjj| jjƒ|d< t| dƒr’| j|d< t| dƒr¦| j|d< t	|t
ƒ�sŒtjrØtdd„ |D ƒƒt|ƒ d	k}nt|ƒd
k}|oòt| ddƒ�rŒ| j|ƒ\}}z^tjƒ \}}tj|dj|ƒjƒ ƒ tj|ƒ tj�rHtjd||ƒ | jjj|d| g f|ŽS ytj |ƒ W n t!k
�rˆ   Y nX X | jjj|f|ŽS )a¶  
		Wrapper for :py:meth:`waflib.Context.Context.exec_command`.
		This version set the current working directory (``build.variant_dir``),
		applies PATH settings (if self.env.PATH is provided), and can run long
		commands through a temporary ``@argfile``.

		:param cmd: process command to execute
		:type cmd: list of string (best) or string (process will use a shell)
		:return: the return code
		:rtype: int

		Optional parameters:

		#. cwd: current working directory (Node or string)
		#. stdout: set to None to prevent waf from capturing the process standard output
		#. stderr: set to None to prevent waf from capturing the process standard error
		#. timeout: timeout value (Python 3)
		rB   Útimeoutr2   ÚPATHÚstdoutÚstderrc             S   s   g | ]}t |ƒ‘qS r)   )Úlen)rY   Úargr)   r)   r*   rZ   8  s    z%Task.exec_command.<locals>.<listcomp>i    i@ Zallow_argsfileTz
zargfile: @%r -> %rú@N)"rM   Úhasattrr]   r2   r^   r$   ÚgetrG   ÚenvironrE   rF   ÚpathsepÚjoinr_   r`   r   Úis_win32Úsumra   r   r\   ÚtempfileÚmkstempÚwriteÚencodeÚcloser   ÚverboseÚdebugr1   rC   Úexec_commandÚremoveÚOSError)r9   r[   r;   r2   Ztoo_longÚargsÚfdÚtmpr)   r)   r*   rr     s:    

$*



 
zTask.exec_commandc          #   C   sø   y| j jj| jƒ = W n tk
r(   Y nX y| jƒ }W n$ tk
rZ   tjƒ | _	t
| _Y n`X |rn|| _t| _nLy| jƒ  W n8 tjk
r�   Y n* tk
r²   tjƒ | _	t
| _Y nX t| _| jtkrô| jrôy| j jj| jƒ = W n tk
rò   Y nX dS )zd
		Runs the task and handles errors

		:return: 0 or None if everything is fine
		:rtype: integer
		N)r1   rC   Ú	task_sigsÚuidr8   r   Ú	ExceptionÚ	tracebackÚ
format_excÚerr_msgÚ	EXCEPTIONr0   Úerr_codeÚCRASHEDÚpost_runr   ÚWafErrorÚSUCCESSÚscanÚimp_sigs)r9   rL   r)   r)   r*   ÚprocessO  s2    	

zTask.processc             C   s„   | j jjdkrdS | jƒ }|r€|jr,|j}nt}| j jjdkrjtjj}tjj}|j	|t
jd||dœd� n|j	|ddddœd� dS )z1Writes the execution status on the context loggerr   Nr   Ú )ÚstreamÚ
terminatorÚc1Úc2)Úextra)r‰   rŠ   r‹   )r1   rC   Úprogress_barÚdisplayÚloggerr   ÚcolorsÚ
cursor_offÚ	cursor_onÚinfoÚsysr`   )r9   rC   Úsr�   rŠ   r‹   r)   r)   r*   Úlog_displayx  s    zTask.log_displayc                sD  t j| jƒ}t jj}| jjj‰ ‡ fdd„}| jjjdkrP| jjj|ƒ ˆ j	||ƒS | jjjdkrêt
| jjjƒ}ydjdd„ | jD ƒƒ}W n tk
rž   d}Y nX ydjd	d„ | jD ƒƒ}W n tk
rÒ   d}Y nX d
ˆ j	|ƒ |||f S t
| ƒ}|súdS ˆ j	}tt
|ƒƒ}	d|	|	f }
| jƒ }|�r.|d7 }|
|ƒ |||||f S )zi
		Returns an execution status for the console, the progress bar, or the IDE output.

		:rtype: string
		c                  s   ˆ j ˆ jjƒ  S )N)Ú	processedÚreadyÚqsizer)   )Úmasterr)   r*   Úcur•  s    zTask.display.<locals>.curr   r   ú,c             S   s   g | ]
}|j ‘qS r)   )r"   )rY   Únr)   r)   r*   rZ   Ÿ  s    z Task.display.<locals>.<listcomp>r‡   c             S   s   g | ]
}|j ‘qS r)   )r"   )rY   r�   r)   r)   r*   rZ   £  s    z3|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|
Nz[%%%dd/%%%dd] %%s%%s%%s%%s
rP   )r   r�   ÚcolorÚNORMALr1   rC   Úproducerr�   Úprogress_lineÚtotalrF   Útimerrh   r3   ÚAttributeErrorr4   ra   Úkeyword)r9   Úcol1Úcol2r›   ZelaÚinsÚoutsr•   r¢   r�   Úfsr;   r)   )rš   r*   rŽ   ‹  s6    


zTask.displayc             C   s.   t | jƒt | jƒt | jƒt | jƒ| jj| jfS )z–
		Identifies a task type for all the constraints relevant for the scheduler: precedence, file production

		:return: a hash value
		:rtype: string
		)ÚtupleÚbeforeÚafterÚext_inÚext_outr(   r   r   )r9   r)   r)   r*   Úhash_constraints´  s    zTask.hash_constraintsc             C   sÆ   t jrd| t| ddƒf }nd}t| jddƒ}t| ddƒr@| jS | jsRd|| f S | jtkrŒyd	|| j|f S  tk
rˆ   d
||f S X n6| jt	kr¢d||f S | jt
kr´d| S d|| jf S dS )zU
		Returns an error message to display the build failure reasons

		:rtype: string
		z: %r
%rÚlast_cmdr‡   z* (run with -v to display more information)r"   r}   Nz/task in %r was not executed for some reason: %rz+ -> task in %r failed with exit status %r%sz -> task in %r failed%sz -> missing files in %r%sz/ -> %r canceled because of missing dependenciesz!invalid status for task in %r: %r)r   rp   r   r1   r}   r0   r€   r   r¤   ÚMISSINGÚCANCELED)r9   Úmsgr"   r)   r)   r*   Úformat_error½  s$    


zTask.format_errorc                sv   | j | ‰ ˆ sg S t|tƒr(| j | }n|}tˆ tƒrH‡ fdd„|D ƒS g }x |D ]}|jˆ ƒ |j|ƒ qRW |S dS )a˜  
		Enable scriptlet expressions of the form ${FOO_ST:FOO}
		If the first variable (FOO_ST) is empty, then an empty list is returned

		The results will be slightly different if FOO_ST is a list, for example::

			env.FOO    = ['p1', 'p2']
			env.FOO_ST = '-I%s'
			# ${FOO_ST:FOO} returns
			['-Ip1', '-Ip2']

			env.FOO_ST = ['-a', '-b']
			# ${FOO_ST:FOO} returns
			['-a', '-b', 'p1', '-a', '-b', 'p2']
		c                s   g | ]}ˆ | ‘qS r)   r)   )rY   rT   )rw   r)   r*   rZ   ñ  s    zTask.colon.<locals>.<listcomp>N)r2   rE   rF   ÚextendÚappend)r9   Zvar1Zvar2ÚitÚlstÚyr)   )rw   r*   ÚcolonØ  s    




z
Task.colonc             C   sÆ   | j j}| jr:|jdƒs | j r:| jd }|j|jjƒ ƒS | jpD| jsN| j jS t| jƒdkrv| jd }|j|jjƒ ƒS dj	dd„ | jD ƒƒ}dj	dd„ | jD ƒƒ}| jr®d	}nd
}d| j j|||f S )zstring to display to the userÚlibÚprogramr   r   rP   c             S   s   g | ]}|j |jjƒ ƒ‘qS r)   )Ú	path_fromÚctxÚlaunch_node)rY   Úar)   r)   r*   rZ     s    z Task.__str__.<locals>.<listcomp>c             S   s   g | ]}|j |jjƒ ƒ‘qS r)   )r¾   r¿   rÀ   )rY   rÁ   r)   r)   r*   rZ     s    z -> r‡   z
%s: %s%s%s)r¼   r½   )
r(   r   r4   Úendswithr3   r¾   r¿   rÀ   ra   rh   )r9   r"   ÚnodeZsrc_strZtgt_strÚsepr)   r)   r*   Ú__str__ù  s     

zTask.__str__c             C   sN   | j j}|jd	ƒrdS t| jƒdkr6t| jƒdkr6dS | jsJ| jrFdS dS dS )
z4Display keyword used to prettify the console outputsr¼   r½   ZLinkingr   Z	CompilingZCreatingZRunningZ
Processing)r¼   r½   )r(   r   rÂ   ra   r3   r4   )r9   r"   r)   r)   r*   r¥     s    
zTask.keywordc             C   s–   y0dj dd„ | jD ƒƒ}dj dd„ | jD ƒƒ}W n@ tk
rp   dj dd„ | jD ƒƒ}dj dd„ | jD ƒƒ}Y nX dj dt| ƒ | jjd	|d
|dgƒS )zfor debugging purposesrœ   c             S   s   g | ]
}|j ‘qS r)   )r"   )rY   rT   r)   r)   r*   rZ     s    z!Task.__repr__.<locals>.<listcomp>c             S   s   g | ]
}|j ‘qS r)   )r"   )rY   rT   r)   r)   r*   rZ      s    c             S   s   g | ]}t |ƒ‘qS r)   )rF   )rY   rT   r)   r)   r*   rZ   "  s    c             S   s   g | ]}t |ƒ‘qS r)   )rF   )rY   rT   r)   r)   r*   rZ   #  s    r‡   z
	{task %r: rP   z -> ú})rh   r3   r4   r¤   Úidr(   r   )r9   r¨   r©   r)   r)   r*   Ú__repr__  s    zTask.__repr__c             C   sb   y| j S  tk
r\   tj| jjƒ}|j}x | j| j D ]}||j	ƒ ƒ q8W |j
ƒ | _ | j S X dS )a  
		Returns an identifier used to determine if tasks are up-to-date. Since the
		identifier will be stored between executions, it must be:

			- unique for a task: no two tasks return the same value (for a given build context)
			- the same for a given task instance

		By default, the node paths, the class name, and the function are used
		as inputs to compute a hash.

		The pointer to the object (python built-in 'id') will change between build executions,
		and must be avoided in such hashes.

		:return: hash value
		:rtype: string
		N)Úuid_r¤   r   Úmd5r(   r   Úupdater3   r4   ÚabspathÚdigest)r9   ÚmÚuprT   r)   r)   r*   ry   &  s    
zTask.uidc             C   s*   t |tƒr|  j|7  _n| jj|ƒ dS )zj
		Appends the nodes to the *inputs* list

		:param inp: input nodes
		:type inp: node or list of nodes
		N)rE   r   r3   r·   )r9   Zinpr)   r)   r*   Ú
set_inputsA  s    
zTask.set_inputsc             C   s*   t |tƒr|  j|7  _n| jj|ƒ dS )zl
		Appends the nodes to the *outputs* list

		:param out: output nodes
		:type out: node or list of nodes
		N)rE   r   r4   r·   )r9   Úoutr)   r)   r*   Úset_outputsM  s    
zTask.set_outputsc             C   s   t |tƒst‚| jj|ƒ dS )a  
		Run this task only after the given *task*.

		Calling this method from :py:meth:`waflib.Task.Task.runnable_status` may cause
		build deadlocks; see :py:meth:`waflib.Tools.fc.fc.runnable_status` for details.

		:param task: task
		:type task: :py:class:`waflib.Task.Task`
		N)rE   r   ÚAssertionErrorr6   Úadd)r9   Útaskr)   r)   r*   Úset_run_afterY  s    
zTask.set_run_afterc             C   s|   y| j S  tk
r   Y nX tj| jƒ| _| jƒ  | jƒ  | jrhy| j	ƒ  W n t
jk
rf   | jƒ S X | jjƒ  }| _ |S )a�  
		Task signatures are stored between build executions, they are use to track the changes
		made to the input nodes (not to the outputs!). The signature hashes data from various sources:

		* explicit dependencies: files listed in the inputs (list of node objects) :py:meth:`waflib.Task.Task.sig_explicit_deps`
		* implicit dependencies: list of nodes returned by scanner methods (when present) :py:meth:`waflib.Task.Task.sig_implicit_deps`
		* hashed data: variables/values read from task.vars/task.env :py:meth:`waflib.Task.Task.sig_vars`

		If the signature is expected to give a different result, clear the cache kept in ``self.cache_sig``::

			from waflib import Task
			class cls(Task.Task):
				def signature(self):
					sig = super(Task.Task, self).signature()
					delattr(self, 'cache_sig')
					return super(Task.Task, self).signature()

		:return: the signature value
		:rtype: string or bytes
		)Ú	cache_sigr¤   r   rÊ   r   rÎ   Úsig_explicit_depsr   r„   Úsig_implicit_depsr   Ú
TaskRescanÚ	signaturerÍ   )r9   rL   r)   r)   r*   rÛ   f  s    
zTask.signaturec             C   s&  | j j}|jdk rtS x&| jD ]}|js,tS |jtk rtS qW y| j	ƒ }W n t
jk
r`   tS X | jƒ }y|j| }W n  tk
r˜   tjd| ƒ tS X ||kr²tjd| ƒ tS x`| jD ]V}|jj|ƒ}|sÞtjd| ƒ tS ||k� røtjd| ƒ tS |jƒ sºtjd| ƒ tS qºW | j�r"t�p$tS )zÓ
		Returns the Task status

		:return: a task state in :py:const:`waflib.Task.RUN_ME`,
			:py:const:`waflib.Task.SKIP_ME`, :py:const:`waflib.Task.CANCEL_ME` or :py:const:`waflib.Task.ASK_LATER`.
		:rtype: int
		r   zHtask: task %r must run: it was never run before or the task code changedz2task: task %r must run: the task signature changedz7task: task %r must run: an output node has no signaturezCtask: task %r must run: an output node was produced by another taskz5task: task %r must run: an output node does not exist)r1   rC   Ú
is_installÚSKIP_MEr6   r0   Ú	ASK_LATERÚSKIPPEDÚ	CANCEL_MErÛ   r   ÚTaskNotReadyry   rx   r8   r   rq   ÚRUN_MEr4   Ú	node_sigsre   ÚexistsÚ
always_run)r9   rC   ÚtZnew_sigÚkeyZprev_sigrÃ   Úsigr)   r)   r*   Úrunnable_status’  sB    


zTask.runnable_statusc             C   sˆ   | j j}xD| jD ]:}|jƒ s<t| _d|jƒ  | _tj	| jƒ‚| j
ƒ |j|< qW | jƒ |j| j
ƒ < | js„y| `W n tk
r‚   Y nX dS )z’
		Called after successful execution to record that the task has run by
		updating the entry in :py:attr:`waflib.Build.BuildContext.task_sigs`.
		z-> missing file: %rN)r1   rC   r4   rä   r²   r0   rÌ   r}   r   r‚   ry   rã   rÛ   rx   Úkeep_last_cmdr±   r¤   )r9   rC   rÃ   r)   r)   r*   r�   Æ  s    zTask.post_runc             C   sÄ   | j j}| jj}x | j| j D ]}||jƒ ƒ qW |jrÀ|j}x€| j| j D ]p}y|| }W n t	k
rr   wLY nX xF|D ]>}y|jƒ }W n$ t
k
r®   t|dƒrª|ƒ }Y nX ||ƒ qzW qLW dS )z™
		Used by :py:meth:`waflib.Task.Task.signature`; it hashes :py:attr:`waflib.Task.Task.inputs`
		and :py:attr:`waflib.Task.Task.dep_nodes` signatures.
		Ú__call__N)r1   rC   rÎ   rË   r3   r5   Úget_bld_sigÚdeps_manr4   r8   r¤   rd   )r9   rC   ÚupdrT   Zadditional_depsÚdÚvr)   r)   r*   rØ   Ù  s$    

zTask.sig_explicit_depsc                s8   | j j‰ ‡ fdd„| j| j D ƒ}| jjtj|ƒƒ dS )a  
		Enable rebuilds on input files task signatures. Not used by default.

		Example: hashes of output programs can be unchanged after being re-linked,
		despite the libraries being different. This method can thus prevent stale unit test
		results (waf_unit_test.py).

		Hashing input file timestamps is another possibility for the implementation.
		This may cause unnecessary rebuilds when input tasks are frequently executed.
		Here is an implementation example::

			lst = []
			for node in self.inputs + self.dep_nodes:
				st = os.stat(node.abspath())
				lst.append(st.st_mtime)
				lst.append(st.st_size)
			self.m.update(Utils.h_list(lst))

		The downside of the implementation is that it absolutely requires all build directory
		files to be declared within the current build.
		c                s$   g | ]}|j ƒ rˆ jˆ j|  ‘qS r)   )Úis_bldrx   rã   )rY   rÃ   )rC   r)   r*   rZ     s    z(Task.sig_deep_inputs.<locals>.<listcomp>N)r1   rC   r3   r5   rÎ   rË   r   Úh_list)r9   r¹   r)   )rC   r*   Úsig_deep_inputsö  s    zTask.sig_deep_inputsc             C   s$   | j jj| j| jƒ}| jj|ƒ dS )a˜  
		Used by :py:meth:`waflib.Task.Task.signature`; it hashes :py:attr:`waflib.Task.Task.env` variables/values
		When overriding this method, and if scriptlet expressions are used, make sure to follow
		the code in :py:meth:`waflib.Task.Task.compile_sig_vars` to enable dependencies on scriptlet results.

		This method may be replaced on subclasses by the metaclass to force dependencies on scriptlet code.
		N)r1   rC   Úhash_env_varsr2   r   rÎ   rË   )r9   rè   r)   r)   r*   r     s    zTask.sig_varsNc             C   sl  | j j}| jƒ }|jj|g ƒ}|rÊy|| jƒ kr4|S W n€ tjk
rN   ‚ Y nj tk
r¶   xT|j	j| jƒ g ƒD ]>}|j
ƒ  rp|jƒ  rpy|jj|j= W qp tk
r¬   Y qpX qpW Y nX |j|= tjdƒ‚| jƒ \|j	|< |j|< tj�rtjd| |j	| |j| ƒ y| jƒ |j|< W nN tk
�rf   x4|j	j| jƒ g ƒD ]}|jƒ �s>tjd|| ƒ �q>W ‚ Y nX dS )a¥  
		Used by :py:meth:`waflib.Task.Task.signature`; it hashes node signatures
		obtained by scanning for dependencies (:py:meth:`waflib.Task.Task.scan`).

		The exception :py:class:`waflib.Errors.TaskRescan` is thrown
		when a file has changed. In this case, the method :py:meth:`waflib.Task.Task.signature` is called
		once again, and return here to call :py:meth:`waflib.Task.Task.scan` and searching for dependencies.
		Zrescanz(deps: scanner for %s: %r; unresolved: %rzPDependency %r for %r is missing: check the task declaration and the build order!N)r1   rC   ry   r…   re   Úcompute_sig_implicit_depsr   rá   ÚEnvironmentErrorÚ	node_depsrñ   rä   ÚparentÚchildrenr"   r8   rÚ   r„   Úraw_depsr   rp   rq   Úwarn)r9   rC   rç   ÚprevrT   r:   r)   r)   r*   rÙ   -  s8    	

zTask.sig_implicit_depsc             C   sF   | j j}| jƒ  x*| jjjj| jƒ g ƒD ]}||jƒ ƒ q(W | j j	ƒ S )zé
		Used by :py:meth:`waflib.Task.Task.sig_implicit_deps` for computing the actual hash of the
		:py:class:`waflib.Node.Node` returned by the scanner.

		:return: a hash value for the implicit dependencies
		:rtype: string or bytes
		)
rÎ   rË   Úare_implicit_nodes_readyr1   rC   r÷   re   ry   rì   rÍ   )r9   rî   r:   r)   r)   r*   rõ   ^  s
    zTask.compute_sig_implicit_depsc             C   sð   | j j}y
|j}W n tk
r0   i  |_}Y nX y||j }W nJ tk
rŠ   i  }||j< x&|jD ]}x|jD ]}|||< qrW qfW Y nX d}x6|jj	| j
ƒ g ƒD ] }||kr¤| jj|| ƒ d}q¤W |rìx| jD ]}|jsÔtjdƒ‚qÔW dS )zÒ
		For each node returned by the scanner, see if there is a task that creates it,
		and infer the build order

		This has a low performance impact on null builds (1.86s->1.66s) thanks to caching (28s->1.86s)
		FTz	not readyN)r1   rC   Zdct_implicit_nodesr¤   Úcurrent_groupr8   Ú	cur_tasksr4   r÷   re   ry   r6   rÔ   r0   r   rá   )r9   rC   ÚcacheÚdctÚtskrT   Zmodifiedr)   r)   r*   rý   p  s*    
zTask.are_implicit_nodes_ready)r0   r1   r2   r3   r4   r5   r6   )5r   r+   r,   r-   r   rå   r   rž   r®   r¯   r¬   r­   r   ÚSIG_NILr   rê   rW   Útree_weightrX   Ú	__slots__r   r>   r?   r@   rA   rM   rV   r<   r\   rr   r†   r–   rŽ   r°   rµ   r»   rÅ   r¥   rÈ   ry   rÐ   rÒ   rÖ   rÛ   ré   r�   rØ   ró   r   r„   rÙ   rõ   rý   r)   r)   r)   r*   r   Š   s`   		<))	!
,41r   i   c             C   sr   y| j S  tk
rl   tj| jjjddƒƒ}|j}x(| j| j	 D ]}||j
ƒ jddƒƒ q@W |jƒ | _ | j S X d S )Nzlatin-1Úxmlcharrefreplace)rÉ   r¤   r   rÊ   r(   r   rn   rË   r3   r4   rÌ   rÍ   )r9   rÎ   rÏ   rT   r)   r)   r*   ry   ’  s    
ry   c             C   s\   t j}x$||jƒD ]}||| jƒkrdS qW | jj||jƒkrBdS |jj|| jƒkrXdS dS )aC  
	Returns a non-zero value if task t1 is to be executed before task t2::

		t1.ext_out = '.h'
		t2.ext_in = '.h'
		t2.after = ['t1']
		t1.before = ['t2']
		waflib.Task.is_before(t1, t2) # True

	:param t1: Task object
	:type t1: :py:class:`waflib.Task.Task`
	:param t2: Task object
	:type t2: :py:class:`waflib.Task.Task`
	r   r   )r   Úto_listr®   r¯   r(   r   r­   r¬   )Út1Út2r  r:   r)   r)   r*   Ú	is_beforeŸ  s    r
  c             C   sÆ   t jtƒ}t jtƒ}xf| D ]^}x|jD ]}|| j|ƒ q&W x|jD ]}|| j|ƒ qDW x|jD ]}|| j|ƒ qbW qW t|jƒ ƒj|jƒ ƒ}x.|D ]&}x || D ]}|j	j
|| ƒ q¦W q˜W dS )z¢
	Updates the ``run_after`` attribute of all tasks based on the task inputs and outputs

	:param tasks: tasks
	:type tasks: list of :py:class:`waflib.Task.Task`
	N)r   Údefaultdictr   r3   rÔ   r5   r4   ÚkeysÚintersectionr6   rË   )Útasksr¨   r©   rT   rÁ   Zlinksr:   r)   r)   r*   Úset_file_constraints»  s    



r  c               @   s*   e Zd ZdZdd„ Zdd„ ZeedƒZdS )Ú	TaskGroupz…
	Wrap nxm task order constraints into a single object
	to prevent the creation of large list/set objects

	This is an optimization
	c             C   s   || _ || _d| _d S )NF)rü   ÚnextÚdone)r9   rü   r  r)   r)   r*   r   Ù  s    zTaskGroup.__init__c             C   s   x| j D ]}|jstS qW tS )N)rü   r0   r7   rƒ   )r9   r:   r)   r)   r*   Ú
get_hasrunÞ  s    zTaskGroup.get_hasrunN)r   r+   r,   r-   r   r  Úpropertyr0   r)   r)   r)   r*   r  Ò  s   r  c             C   s4  t jtƒ}x"| D ]}|jƒ }|| j|ƒ qW t|jƒ ƒ}t|ƒ}xìt|ƒD ]à}|||  d }xÊt|d |ƒD ]¸}|||  d }	t||	ƒr˜|}
|}nt|	|ƒrp|}
|}nqp|||
  }
|||  }t|
ƒdk sÞt|ƒdk rúxH|D ]}|j	j
|
ƒ qäW qptt|
ƒt|ƒƒ}x|D ]}|j	j|ƒ �qW qpW qLW dS )z±
	Updates the ``run_after`` attribute of all tasks based on the after/before/ext_out/ext_in attributes

	:param tasks: tasks
	:type tasks: list of :py:class:`waflib.Task.Task`
	r   r   r   N)r   r  r   r°   r·   r  ra   Úranger
  r6   rË   r  r   rÔ   )r  Zcstr_groupsrT   Úhr  ÚmaxiÚir  Újr	  rÁ   ÚbÚgroupr)   r)   r*   Úset_precedence_constraintsæ  s2    





r  c             C   s   i }t | |ƒ |d S )zµ
	Compiles a scriptlet expression into a Python function

	:param c: function to compile
	:type c: string
	:return: the function 'f' declared in the input string
	:rtype: function
	r%   )Úexec)ÚcÚdcr)   r)   r*   Úfunex  s    	
r   z"(?P<var>\w+)|(?P<or>\|)|(?P<and>&)z^(SRC|TGT)\W+.*?$zM(?P<backslash>\\)|(?P<dollar>\$\$)|(?P<subst>\$\{(?P<var>\w+)(?P<code>.*?)\})c                s   g ‰‡fdd„}t j|| ƒp| } g ‰‡fdd„‰ ‡ fdd„}g }|j}�xpˆD �]f\}}|dkr||rr|d| ƒ n|d	ƒ qN|d
kr |r–|d| ƒ n|dƒ qN|�r¢|jdƒ�rRˆ |ƒ |dd… }|dkrÔd}nl|d
krâd}n^tj|ƒ�r d|dd…  }n@tj|ƒ�rd|dd…  }n"ˆ |ƒ |dd… d"k�r@d| }|d||f ƒ nN|jdƒ�r„tj||dd… ƒ}|d||f ƒ nd||f }	ˆ |	ƒ ||	ƒ qNˆ |ƒ |d| ƒ qNW |�rÐddj|ƒ }nd }t| |f }
t	j
d!|
jƒ jƒ ƒ t|
ƒˆfS )#zH
	Creates a compiled function to execute a process through a sub-shell
	c                sD   | j }|dƒrdS |dƒrdS |dƒr@ˆ j|dƒ|dƒfƒ dS d S )	NZdollarú$Z	backslashz\\ÚsubstÚvarÚcodez%s)r  r·   )ÚmatchÚg)Úextrr)   r*   Úrepl%  s    zcompile_fun_shell.<locals>.replc                s   | ˆ krˆ j | ƒ d S )N)r·   )rT   )r&   r)   r*   Úadd_dvar1  s    z#compile_fun_shell.<locals>.add_dvarc                s:   | j dƒrdS | j dƒrdS | j dƒ}ˆ |ƒ d| S d S )NÚandz and Úorz or r#  zenv[%r])r  )rÎ   rT   )r)  r)   r*   Úreplc5  s    


z compile_fun_shell.<locals>.replcÚSRCztsk.inputs%sz1" ".join([a.path_from(cwdx) for a in tsk.inputs])ÚTGTztsk.outputs%sz2" ".join([a.path_from(cwdx) for a in tsk.outputs])ú:r   Nz'[a.path_from(cwdx) for a in tsk.inputs]z([a.path_from(cwdx) for a in tsk.outputs]z[tsk.inputs%s]r   z[tsk.outputs%s]r  ÚgenrC   z%rz" ".join(tsk.colon(%r, %s))ú?zp(%r) if (%s) else ""z%s%szp('%s')z%% (%s) z,
		r‡   z
action: %s)r  r0  rC   )Úreg_actÚsubr·   Ú
startswithÚre_novarr%  Úre_condrh   ÚCOMPILE_TEMPLATE_SHELLr   rq   ÚstripÚ
splitlinesr   )Úliner(  r,  ZparmÚappr#  ÚmethrÎ   ÚexprÚcallr  r)   )r)  r&   r'  r*   Úcompile_fun_shell   s^    



r?  z[(?P<space>\s+)|(?P<subst>\$\{(?P<var>\w+)(?P<code>.*?)\})|(?P<text>([^$ \t\n\r\f\v]|\$\$)+)c                sp  g }g ‰d}|j }‡fdd„‰ ‡ fdd„}�xtj| ƒD �]ö}|jdƒrRd}q8�n²|jdƒrz|d|jdƒjd	d
ƒ ƒ �nŠ|jdƒ�r|jdƒ}|jdƒ}|dkrÀ|r´|d| ƒ n|dƒ �nD|dkræ|rÚ|d| ƒ n|dƒ �n|�rð|jdƒ�rœˆ |ƒ |dd… }|dk�rd}nn|dk�r,d}n^tj|ƒ�rJd|dd…  }n@tj|ƒ�rhd|dd…  }n"ˆ |ƒ |dd… d)k�rŠd| }|d||f ƒ nR|jdƒ�rÎtj	||dd… ƒ}|d||f ƒ n d||f }	ˆ |	ƒ |d |	 ƒ n|d!| ƒ ˆ |ƒ |�r,d"|d* |d+ f }
|d,= |
|d-< d$}q8W d%d&„ |D ƒ}t
d'j|ƒ }tjd(|jƒ jƒ ƒ t|ƒˆfS ).zH
	Creates a compiled function to execute a process without a sub-shell
	Fc                s   | ˆ krˆ j | ƒ d S )N)r·   )rT   )r&   r)   r*   r)  |  s    z%compile_fun_noshell.<locals>.add_dvarc                s:   | j dƒrdS | j dƒrdS | j dƒ}ˆ |ƒ d| S d S )Nr*  z and r+  z or r#  zenv[%r])r  )rÎ   rT   )r)  r)   r*   r,  €  s    


z"compile_fun_noshell.<locals>.replcZspaceÚtextz[%r]z$$r!  r"  r#  r$  r-  z[tsk.inputs%s]z'[a.path_from(cwdx) for a in tsk.inputs]r.  z[tsk.outputs%s]z([a.path_from(cwdx) for a in tsk.outputs]r/  r   Nr   r  r0  rC   z%rztsk.colon(%r, %s)r1  z to_list(env[%r] if (%s) else [])z%s%szto_list(%s)zto_list(env[%r])zmerge(%s, %s)r   Tc             S   s   g | ]}d | ‘qS )zlst.extend(%s)r)   )rY   rT   r)   r)   r*   rZ   Ã  s    z'compile_fun_noshell.<locals>.<listcomp>z
	z
action: %s)r  r0  rC   éþÿÿÿéÿÿÿÿrB  rB  )r·   Úreg_act_noshellÚfinditerr  rS   r4  r5  r%  r6  r3  ÚCOMPILE_TEMPLATE_NOSHELLrh   r   rq   r8  r9  r   )r:  ÚbufÚmerger;  r,  rÎ   r#  r$  r=  r>  rw   r'   r)   )r)  r&   r*   Úcompile_fun_noshells  sp    





rH  Fc                s²   t | tƒr:| jdƒdks4| jdƒdks4| jdƒdkršd}n`g }g ‰ xB| D ]:}t |tƒrxt||ƒ\}}||7 }ˆ j|ƒ qHˆ j|ƒ qHW ‡ fdd„}||fS |r¦t| ƒS t| ƒS dS )	a�  
	Parses a string expression such as '${CC} ${SRC} -o ${TGT}' and returns a pair containing:

	* The function created (compiled) for use as :py:meth:`waflib.Task.Task.run`
	* The list of variables that must cause rebuilds when *env* data is modified

	for example::

		from waflib.Task import compile_fun
		compile_fun('cxx', '${CXX} -o ${TGT[0]} ${SRC} -I ${SRC[0].parent.bldpath()}')

		def build(bld):
			bld(source='wscript', rule='echo "foo\${SRC[0].name}\bar"')

	The env variables (CXX, ..) on the task must not hold dicts so as to preserve a consistent order.
	The reserved keywords ``TGT`` and ``SRC`` represent the task input and output nodes

	ú<r   ú>z&&Tc                s"   xˆ D ]}|| ƒ}|r|S qW d S )Nr)   )rÕ   rT   rL   )Úfuns_lstr)   r*   Úcomposed_funé  s
    
z!compile_fun.<locals>.composed_funN)rE   rF   Úfindr   r·   r?  rH  )r:  r   Z	dvars_lstrT   r'   r&   rL  r)   )rK  r*   r   È  s     
*

r   c             C   sN   g }x.t | ƒD ]"}|dd… dkr|jd| ƒ qW |rJttdj|ƒ ƒS dS )	aÍ  
	This method produces a sig_vars method suitable for subclasses that provide
	scriptlet code in their run_str code.
	If no such method can be created, this method returns None.

	The purpose of the sig_vars method returned is to ensures
	that rebuilds occur whenever the contents of the expression changes.
	This is the case B below::

		import time
		# case A: regular variables
		tg = bld(rule='echo ${FOO}')
		tg.env.FOO = '%s' % time.time()
		# case B
		bld(rule='echo ${gen.foo}', foo='%s' % time.time())

	:param vars: env variables such as CXXFLAGS or gen.foo
	:type vars: list of string
	:return: A sig_vars method relevant for dependencies if adequate, else None
	:rtype: A function, or None in most cases
	Nr   r  r0  rC   zbuf.append(%s)z
	)r  r0  rC   )Úsortedr·   r   ÚCOMPILE_TEMPLATE_SIG_VARSrh   )r   rF  rT   r)   r)   r*   r   õ  s    r   r/   c
             C   s˜   |pg || ||	dœ}
t |tƒs(t |tƒr2||
d< n||
d< ttƒ| tf|
ƒ}|t| < |rdtj|ƒ|_|rttj|ƒ|_	|r„tj|ƒ|_
|r”tj|ƒ|_|S )a»  
	Returns a new task subclass with the function ``run`` compiled from the line given.

	:param func: method run
	:type func: string or function
	:param vars: list of variables to hash
	:type vars: list of string
	:param color: color to use
	:type color: string
	:param shell: when *func* is a string, enable/disable the use of the shell
	:type shell: bool
	:param scan: method scan
	:type scan: function
	:rtype: :py:class:`waflib.Task.Task`
	)r   rž   r"   r   r„   r   r   )rE   rF   r«   Útyper   r    r   r  r®   r¯   r¬   r­   )r"   Úfuncr   rž   r®   r¯   r¬   r­   r   r„   Úparamsr!   r)   r)   r*   Útask_factory  s&    
rS  c             C   s   dd„ }|| _ | S )zJ
	Task class decorator to enable rebuilds on input files task signatures
	c             S   s   t j| ƒ t j| ƒ d S )N)r   rØ   ró   )r9   r)   r)   r*   rØ   C  s    
z&deep_inputs.<locals>.sig_explicit_deps)rØ   )r!   rØ   r)   r)   r*   Údeep_inputs?  s    rT  c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTaskSemaphorea0  
	Task semaphores provide a simple and efficient way of throttling the amount of
	a particular task to run concurrently. The throttling value is capped
	by the amount of maximum jobs, so for example, a `TaskSemaphore(10)`
	has no effect in a `-j2` build.

	Task semaphores are typically specified on the task class level::

		class compile(waflib.Task.Task):
			semaphore = waflib.Task.TaskSemaphore(2)
			run_str = 'touch ${TGT}'

	Task semaphores are meant to be used by the build scheduler in the main
	thread, so there are no guarantees of thread safety.
	c             C   s   || _ tƒ | _tƒ | _dS )zD
		:param num: maximum value of concurrent tasks
		:type num: int
		N)Únumr   ÚlockingÚwaiting)r9   rV  r)   r)   r*   r   \  s    zTaskSemaphore.__init__c             C   s   t | jƒ| jkS )z?Returns True if this semaphore cannot be acquired by more tasks)ra   rW  rV  )r9   r)   r)   r*   Ú	is_lockede  s    zTaskSemaphore.is_lockedc             C   s&   | j ƒ rtd| j ƒ‚| jj|ƒ dS )zÔ
		Mark the semaphore as used by the given task (not re-entrant).

		:param tsk: task object
		:type tsk: :py:class:`waflib.Task.Task`
		:raises: :py:class:`IndexError` in case the resource is already acquired
		zCannot lock more %rN)rY  Ú
IndexErrorrW  rÔ   )r9   r  r)   r)   r*   Úacquirei  s    zTaskSemaphore.acquirec             C   s   | j j|ƒ dS )zË
		Mark the semaphore as unused by the given task.

		:param tsk: task object
		:type tsk: :py:class:`waflib.Task.Task`
		:raises: :py:class:`KeyError` in case the resource is not acquired by the task
		N)rW  rs   )r9   r  r)   r)   r*   Úreleaseu  s    zTaskSemaphore.releaseN)r   r+   r,   r-   r   rY  r[  r\  r)   r)   r)   r*   rU  L  s
   	rU  rB  rA  éýÿÿÿéüÿÿÿ)F)3r-   rG   Úrer”   rk   r{   Úwaflibr   r   r   r7   r²   r€   r~   r³   rß   rƒ   rÞ   rÝ   râ   rà   r7  rE  rO  r    rP  r   Úobjectr   r   Ú
hexversionry   r
  r  r  r  r   Úcompiler6  r5  ÚMr2  r?  rC  rH  r   r   rS  rT  ZTaskBaserU  r)   r)   r)   r*   Ú<module>   s^   ("      


*

RU
-,
