a
    $a@h                     @   s\  d 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	m
Z
mZ eeZg dZG dd deZddddg g g g dddd	fd
dZdd Zdd Zdd ZeZdd ZeZdd Zed*ddZeddd Zededdd Zeddd Zed ejZ G d!d" d"ejZ!ed#d$d% Z"G d&d' d'e!Z#ed'eddd(d) Z$dS )+a   
Task generators

The class :py:class:`waflib.TaskGen.task_gen` encapsulates the creation of task objects (low-level code)
The instances can have various parameters, but the creation of task nodes (Task.py)
is deferred. To achieve this, various methods are called from the method "apply"
    N)TaskUtilsLogsErrors	ConfigSetNode).hz.hppz.hxxz.hhc                   @   s   e Zd ZdZe ZeeZ	dd Z
dd Zdd Zdd	 Zd
d Zdd ZeeeZdd Zdd Zdd ZdddZdd ZdS )task_gena  
	Instances of this class create :py:class:`waflib.Task.Task` when
	calling the method :py:meth:`waflib.TaskGen.task_gen.post` from the main thread.
	A few notes:

	* The methods to call (*self.meths*) can be specified dynamically (removing, adding, ..)
	* The 'features' are used to add methods to self.meths and then execute them
	* The attribute 'path' is a node representing the location of the task generator
	* The tasks created are added to the attribute *tasks*
	* The attribute 'idx' is a counter of task generators in the same path
	c                 O   s(  g | _ d| _g | _g | _g | _d|vr>t | _d| _d| _n|d | _	| j	j
 | _|d| j	j| _| j }z&| j	j|dd  | _| j	j|< W n, ty   i | j	_d | _| j	j|< Y n0 z| j	jd  | _| j	_W n" ty   d | _| j	_Y n0 | D ]\}}t| || qdS )a  
		Task generator objects predefine various attributes (source, target) for possible
		processing by process_rule (make-like rules) or process_source (extensions, misc methods)

		Tasks are stored on the attribute 'tasks'. They are created by calling methods
		listed in ``self.meths`` or referenced in the attribute ``features``
		A topological sort is performed to execute the methods in correct order.

		The extra key/value elements passed in ``kw`` are set as attributes
		 bldr   Npath   )sourcetargetmethsfeaturestasksr   envidxr   r   derivegetabspathAttributeErrortg_idx_countitemssetattr)selfkkwr   keyval r!   i/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/third_party/waf/waflib/TaskGen.py__init__(   s0    


&ztask_gen.__init__c                 C   s   d| j | j f S )Debugging helperz<task_gen %r declared in %s>)namer   r   r   r!   r!   r"   __str__a   s    ztask_gen.__str__c              	   C   sL   g }| j D ](}|dvr
|d|tt| |f  q
dd|| j f S )r$   )r   r   compiled_tasksr   z%s=%szbld(%s) in %sz, )__dict__appendreprgetattrjoinr   r   )r   lstxr!   r!   r"   __repr__e   s
    
ztask_gen.__repr__c                 C   s   | j jS )a   
		Current working directory for the task generator, defaults to the build directory.
		This is still used in a few places but it should disappear at some point as the classes
		define their own working directory.

		:rtype: :py:class:`waflib.Node.Node`
		)r   bldnoder&   r!   r!   r"   get_cwdm   s    ztask_gen.get_cwdc                 C   sb   z| j W S  ty\   t| jtrDdd | jD }d| }| _ nt| j }| _ | Y S 0 dS )a  
		If the attribute ``name`` is not set on the instance,
		the name is computed from the target name::

			def build(bld):
				x = bld(name='foo')
				x.get_name() # foo
				y = bld(target='bar')
				y.get_name() # bar

		:rtype: string
		:return: name of this task generator
		c                 S   s   g | ]}t |qS r!   )str.0r/   r!   r!   r"   
<listcomp>       z%task_gen.get_name.<locals>.<listcomp>,N)_namer   
isinstancer   listr-   r3   )r   r.   r%   r!   r!   r"   get_namew   s    ztask_gen.get_namec                 C   s
   || _ d S N)r9   )r   r%   r!   r!   r"   set_name   s    ztask_gen.set_namec                 C   s   t |tr| S |S dS )z
		Ensures that a parameter is a list, see :py:func:`waflib.Utils.to_list`

		:type val: string or list of string
		:param val: input to return as a list
		:rtype: list
		N)r:   r3   split)r   r    r!   r!   r"   to_list   s    
ztask_gen.to_listc              	      s>  t | ddrdS d| _t| j}|td  t| j| _| jD ]2}t| }|r^|| qB|t	j
vrBtd| qBi  | j}|D ]}||v r||  |< qg }|D ](}  D ]}||v r qq|| q|jdd g }|rn| }||v r|| z | }	W n ty"   Y q0  |= |	D ]<} D ]}
| |
 v r6 q.q6|| |jdd q.q rdg}  D ]*\}}|d	| fd
d|D f  qtd||| _td| t|  |D ]P}zt | |}W n" ty   td| Y n0 td|t|  |  qtd| j dS )a  
		Creates tasks for this task generators. The following operations are performed:

		#. The body of this method is called only once and sets the attribute ``posted``
		#. The attribute ``features`` is used to add more methods in ``self.meths``
		#. The methods are sorted by the precedence table ``self.prec`` or `:waflib:attr:waflib.TaskGen.task_gen.prec`
		#. The methods are then executed in order
		#. The tasks created are added to :py:attr:`waflib.TaskGen.task_gen.tasks`
		postedNFT*z;feature %r does not exist - bind at least one method to it?)reversez'Cycle detected in the method execution:z- %s after %sc                    s   g | ]}| v r|qS r!   r!   r4   precr!   r"   r6      r7   z!task_gen.post.<locals>.<listcomp>
ztask_gen: posting %s %dz'%r is not a valid task generator methodztask_gen: -> %s (%d)ztask_gen: posted %s)r,   rA   setr   updatefeatsr   r@   r   r   classesr   warnrE   valuesr*   sortpopKeyErrorr   r   WafErrorr-   debugidr   r%   )r   keysr/   stZprec_tbltmpaoutenlstybufr   vr!   rD   r"   post   sp    







$
ztask_gen.postc              	   C   s   |j }| jD ]R}z||r,| j| W   S W q ty\   ||rX| j|  Y   S Y q0 qt| j }td||f dS )a  
		Returns the ``@extension`` method to call for a Node of a particular extension.

		:param node: Input file to process
		:type node: :py:class:`waflib.Tools.Node.Node`
		:return: A method able to process the input node by looking at the extension
		:rtype: function
		z/File %r has no mapping in %r (load a waf tool?)N)	r%   mappingsendswith	TypeErrormatchr;   rS   r   rP   )r   noder%   r   rS   r!   r!   r"   get_hook   s    	


ztask_gen.get_hookNc                 K   sP   t j| | j | d}|r&|| |r4|| |j| | j	| |S )a7  
		Creates task instances.

		:param name: task class name
		:type name: string
		:param src: input nodes
		:type src: list of :py:class:`waflib.Tools.Node.Node`
		:param tgt: output nodes
		:type tgt: list of :py:class:`waflib.Tools.Node.Node`
		:return: A task object
		:rtype: :py:class:`waflib.Task.Task`
		)r   	generator)
r   rJ   r   r   
set_inputsset_outputsr)   rH   r   r*   )r   r%   srctgtr   taskr!   r!   r"   create_task	  s    

ztask_gen.create_taskc              	   C   s   |   }| jD ]D}|dv rqq|dv r:t||t| | qt||tt| | qd|_t|trx| j j| 	 |_
n
|	 |_
|S )ag  
		Makes a copy of a task generator. Once the copy is made, it is necessary to ensure that the
		it does not create the same output files as the original, or the same files may
		be compiled several times.

		:param env: A configuration set
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:return: A copy
		:rtype: :py:class:`waflib.TaskGen.task_gen`
		)r   r   )r   r   F)r   r)   r   r,   copyrA   r:   r3   Zall_envsr   r   )r   r   Znewobjr/   r!   r!   r"   clone  s    


ztask_gen.clone)NN)__name__
__module____qualname____doc__r   ordered_iter_dictr^   defaultdictrG   rE   r#   r'   r0   r2   r<   r>   propertyr%   r@   r]   rc   rj   rl   r!   r!   r!   r"   r	      s   
9

T
r	   r
   BLUEFc                    sh   t t |}s|tj||||||	|d	  fdd} jD ]}|tj|< qT|S )a  
	Creates a new mapping and a task class for processing files by extension.
	See Tools/flex.py for an example.

	:param name: name for the task class
	:type name: string
	:param rule: function to execute or string to be compiled in a function
	:type rule: string or function
	:param reentrant: re-inject the output file in the process (done automatically, set to 0 to disable)
	:type reentrant: int
	:param color: color for the task output
	:type color: string
	:param ext_in: execute the task only after the files of such extensions are created
	:type ext_in: list of string
	:param ext_out: execute the task only before files of such extensions are processed
	:type ext_out: list of string
	:param before: execute instances of this task before classes of the given names
	:type before: list of string
	:param after: execute instances of this task after classes of the given names
	:type after: list of string
	:param decider: if present, function that returns a list of output file extensions (overrides ext_out for output files, but not for the build order)
	:type decider: function
	:param scan: scanner function for the task
	:type scan: function
	:param install_path: installation path for the output nodes
	:type install_path: string
	)colorext_inext_outbeforeafterscanshellc           	         s   rd }|  |}d}r*| |n j}|D ]p}|j||d}|j| d krt|tk r| j| n(| jD ] }|j	|rz| j|  qqz|d7 }q4r| j
|jd| _|S )Nr   )rv   r   
install_toinstall_from)rj   rw   
change_extoutputsr*   intr   r^   r%   r_   add_install_filesinstall_task)	r   rb   Z_ext_intskZcntextr/   r   rZ   clsdeciderrv   install_pathr%   	reentrantr!   r"   x_file^  s&    

zdeclare_chain.<locals>.x_file)r   r@   r   task_factoryrv   r	   r^   )r%   ruler   ru   rv   rw   rx   ry   r   rz   r   r{   r   r/   r!   r   r"   declare_chain;  s    


r   c                 C   s   t t| j|  | S )a0  
	Decorator that registers method as a task generator method.
	The function must accept a task generator as first parameter::

		from waflib.TaskGen import taskgen_method
		@taskgen_method
		def mymethod(self):
			pass

	:param func: task generator method to add
	:type func: function
	:rtype: function
	)r   r	   rm   )funcr!   r!   r"   taskgen_method}  s    r   c                     s    fdd}|S )aj  
	Decorator that registers a task generator method that will be executed when the
	object attribute ``feature`` contains the corresponding key(s)::

		from waflib.Task import feature
		@feature('myfeature')
		def myfunction(self):
			print('that is my feature!')
		def build(bld):
			bld(features='myfeature')

	:param k: feature names
	:type k: list of string
	c                    s.   t t| j|   D ]}t| | jg q| S r=   )r   r	   rm   rI   rH   )r   r%   r   r!   r"   deco  s    zfeature.<locals>.decor!   r   r   r!   r   r"   feature  s    r   c                     s    fdd}|S )a  
	Decorator that registera task generator method which will be executed
	before the functions of given name(s)::

		from waflib.TaskGen import feature, before
		@feature('myfeature')
		@before_method('fun2')
		def fun1(self):
			print('feature 1!')
		@feature('myfeature')
		def fun2(self):
			print('feature 2!')
		def build(bld):
			bld(features='myfeature')

	:param k: method names
	:type k: list of string
	c                    s.   t t| j|   D ]}tj| j | q| S r=   r   r	   rm   rE   addr   Zfun_namer   r!   r"   r     s    zbefore_method.<locals>.decor!   r   r!   r   r"   before_method  s    r   c                     s    fdd}|S )a  
	Decorator that registers a task generator method which will be executed
	after the functions of given name(s)::

		from waflib.TaskGen import feature, after
		@feature('myfeature')
		@after_method('fun2')
		def fun1(self):
			print('feature 1!')
		@feature('myfeature')
		def fun2(self):
			print('feature 2!')
		def build(bld):
			bld(features='myfeature')

	:param k: method names
	:type k: list of string
	c                    s.   t t| j|   D ]}tj| | j q| S r=   r   r   r   r!   r"   r     s    zafter_method.<locals>.decor!   r   r!   r   r"   after_method  s    r   c                     s    fdd}|S )a|  
	Decorator that registers a task generator method which will be invoked during
	the processing of source files for the extension given::

		from waflib import Task
		class mytask(Task):
			run_str = 'cp ${SRC} ${TGT}'
		@extension('.moo')
		def create_maa_file(self, node):
			self.create_task('mytask', node, node.change_ext('.maa'))
		def build(bld):
			bld(source='foo.moo')
	c                    s&   t t| j|   D ]}| tj|< q| S r=   )r   r	   rm   r^   )r   r/   r   r!   r"   r     s    zextension.<locals>.decor!   r   r!   r   r"   	extension  s    r   c                 C   s   g }|p| j }|j}t|tjr&|g}t|D ]Z}t|trH||}n"t|drX|}n|| 	| q0|st
d|| f || q0|S )a  
	Flatten the input list of string/nodes/lists into a list of nodes.

	It is used by :py:func:`waflib.TaskGen.process_source` and :py:func:`waflib.TaskGen.process_rule`.
	It is designed for source files, for folders, see :py:func:`waflib.Tools.ccroot.to_incnodes`:

	:param lst: input list
	:type lst: list of string and nodes
	:param path: path from which to search the nodes (by default, :py:attr:`waflib.TaskGen.task_gen.path`)
	:type path: :py:class:`waflib.Tools.Node.Node`
	:rtype: list of :py:class:`waflib.Tools.Node.Node`
	r%   zsource not found: %r in %r)r   find_resourcer:   r   r   r@   r3   hasattrextendto_nodesr   rP   r*   )r   r.   r   rU   findr/   rb   r!   r!   r"   r     s     



r   rB   c                 C   s4   |  t| dg | _| jD ]}| || | qdS )a2  
	Processes each element in the attribute ``source`` by extension.

	#. The *source* list is converted through :py:meth:`waflib.TaskGen.to_nodes` to a list of :py:class:`waflib.Node.Node` first.
	#. File extensions are mapped to methods having the signature: ``def meth(self, node)`` by :py:meth:`waflib.TaskGen.extension`
	#. The method is retrieved through :py:meth:`waflib.TaskGen.task_gen.get_hook`
	#. When called, the methods may modify self.source to append more source to process
	#. The mappings can map an extension or a filename (see the code below)
	r   N)r   r,   r   rc   )r   rb   r!   r!   r"   process_source  s    
r   c                 C   s  t | ddsdS tt | ddp2| jp2t | jd| j}z| jj}W n ty`   i  }| j_Y n0 t | dd}t | dd}t | dd	}t | d
d}t | dg }t | dd}t | dd}	t | dd}
t | dd}t| d }}|rt|}t	
|| j|||||	|||f
}d}|
r4z|| }W n ty2   Y n0 |s | j}|durdd }t|trzt|}|| t|}n||f}tj|||||d}|rt|d| j |	rt|d| j |rt| |r| j|_n|rdd }||_|
r |||< | |}dD ]}t||t | |g  qt| dr>| j|_t| drR| j|_t | ddrh| j|_t | ddr|d|_t | ddr0t| jtr| j | _t| jts| jg| _| jD ]>}t|tr|j| j| n|j !  |j| qt | d dr0| j"| j#|jt | dt	j$d!| _%t | d"drR| &| j'|_(g | _'t | d#drh| j)|_)t|j*t+j,rt+,|j*||_*dS )$aI  
	Processes the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::

		def build(bld):
			bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')

	Main attributes processed:

	* rule: command to execute, it can be a tuple of strings for multiple commands
	* chmod: permissions for the resulting files (integer value such as Utils.O755)
	* shell: set to False to execute the command directly (default is True to use a shell)
	* scan: scanner function
	* vars: list of variables to trigger rebuilds, such as CFLAGS
	* cls_str: string to display when executing the task
	* cls_keyword: label to display when executing the task
	* cache_rule: by default, try to re-use similar classes, set to False to disable
	* source: list of Node or string objects representing the source files required by this task
	* target: list of Node or string objects representing the files that this task creates
	* cwd: current working directory (Node or string)
	* stdout: standard output, set to None to prevent waf from capturing the text
	* stderr: standard error, set to None to prevent waf from capturing the text
	* timeout: timeout for command execution (Python 3)
	* always: whether to always run the command (False by default)
	* deep_inputs: whether the task must depend on the input file tasks too (False by default)
	r   Nr%   rm   chmodr{   Tru   rt   rz   varscls_strcls_keywordZ
cache_ruleTruedeep_inputsFdepsc                 S   s$   | j D ]}t| | jj qd S r=   )r   osr   r   rd   )r   r/   r!   r!   r"   	chmod_funa  s    
zprocess_rule.<locals>.chmod_fun)r{   ru   r'   keywordc                 S   sV   g }| j t| j dd D ]2}| j j|}|sB| j jd|  || q|g gS )Nr   z$Could not find %r (was it declared?))rd   r@   r,   r   r   r   fatalr*   )r   nodesr/   rb   r!   r!   r"   rz   y  s    zprocess_rule.<locals>.scanry   rx   rv   rw   stdoutstderrtimeoutalwaysr   r   r}   r~   r   r   cwd)-r,   r3   r   r   r   Zcache_rule_attrr   r   rR   r   h_listrO   r:   tupler;   r*   r   r   r   r   r   r   rz   rj   r   r   r   
always_runr?   r   r   find_or_declareparentmkdirr   r   O644r   r   r   inputsr   run	functoolspartial)r   r%   cacher   r{   ru   rz   _varsr   r   Z	use_cacher   Zscan_valZhas_depsr   r   r   r   r   r/   r!   r!   r"   process_rule   s    & 








r   seqc                 C   s   | j r$| j d dkr$| j d dS t| ddr4dS t| jddrt| jj  | jjjD ]}| jD ]}|| qbqX| | j_dS )a  
	Adds a strict sequential constraint between the tasks generated by task generators.
	It works because task generators are posted in order.
	It will not post objects which belong to other folders.

	Example::

		bld(features='javac seq')
		bld(features='jar seq')

	To start a new sequence, set the attribute seq_start, for example::

		obj = bld(features='seq')
		obj.seq_start = True

	Note that the method is executed in last position. This is more an
	example than a widely-used solution.
	sequence_orderNZ	seq_startprev)r   r*   r,   r   r   r]   r   set_run_after)r   r/   rZ   r!   r!   r"   r     s    
r   z@(\w+)@c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	subst_pczy
	Creates *.pc* files from *.pc.in*. The task is executed whenever an input variable used
	in the substitution changes.
	c                 C   s2   t | jddr.| jD ]}t| | jj qdS )zTPrivate for the time being, we will probably refactor this into run_str=[run1,chmod]r   N)r,   rd   r   r   r   r   )r   r/   r!   r!   r"   force_permissions  s    
zsubst_pc.force_permissionsc           	         s:  t | jddrxt| jD ]R\}}|| j| dd t| j| 	 }t
| j| 	 |j|jf q|   dS t | jddr| j| }|s|   |S | jd jt | jddd	}t | jd
dr| j| |}|dur| jd j|t | jddd	 |   dS |dd}g   fdd}t | jdt||}z| jj}W n ty   i } D ]d}t | j|dp| j| p| j|  }zd|}W n ty   t|}Y n0 |||< qfY n0 || }| jd j|t | jddd	  | jjj|  < zt| d W n ty,   Y n0 |   dS )z#Substitutes variables in a .in fileZis_copyNrbwbfunr   encodingzlatin-1)r   	subst_fun%z%%c                    s,   | j }|dr( |d d|d S dS )Nr   z%%(%s)sr
   )groupr*   )ra   gr.   r!   r"   repl  s
    zsubst_pc.run.<locals>.replre_m4r
   	cache_sig)r,   rd   	enumerater   writer   readr   statr   utimest_atimest_mtimer   r   r   replacer   subdctr   r   upperr-   r`   r3   r   raw_depsuiddelattr)	r   ir/   r   retcoder   drU   r!   r   r"   r     sT     
*zsubst_pc.runc                    s    j j} j} jj}t j ddr:|t j j	  t j ddr^|t j j
	   j jj  g }|||}||  fdd|D }|t|  j S )zJ
		Compute a hash (signature) of the variables used in the substitution
		r   Nr   c                    s   g | ]}t  j|d qS )r
   )r,   rd   r4   r&   r!   r"   r6   :  r7   z%subst_pc.sig_vars.<locals>.<listcomp>)rd   r   r   mrH   r,   r   h_funr   encoder   r   r   r   hash_env_varsr   digest)r   r   r   updr   Zact_sigr.   r!   r&   r"   sig_vars&  s    zsubst_pc.sig_varsN)rm   rn   ro   rp   r   r   r   r!   r!   r!   r"   r     s   >r   .pc.inc                 C   s4   |  d||dd}| jt| dd|jd| _dS )z
	Processes *.pc.in* files to *.pc*. Installs the results to ``${PREFIX}/lib/pkgconfig/`` by default

		def build(bld):
			bld(source='foo.pc.in', install_path='${LIBDIR}/pkgconfig/')
	r   z.pcr   r   z${LIBDIR}/pkgconfig/r|   N)rj   r   r   r,   r   r   )r   rb   r   r!   r!   r"   
add_pcfile?  s    r   c                   @   s   e Zd ZdS )substN)rm   rn   ro   r!   r!   r!   r"   r   K  s   r   c                 C   s  t t| dg }t|tjr$|g}t t| dg }t|tjrH|g}t|t|krftd|  t||D ]|\}}|r|std|  d\}}t|t	rt|t	r||kr| j
|}| j
 |}tj
| s|j  nXt|t	r| j
|}nt|tjr|}t|t	r2| j
|}nt|tjrD|}|s\td|| f | d||}dD ]$}t| |d	}	|	rnt|||	 qntD ](}
|j|
r|jd
g |_ qqt| dd	}|rp| j||t| dt jd| _qpg | _d	S )a  
	Defines a transformation that substitutes the contents of *source* files to *target* files::

		def build(bld):
			bld(
				features='subst',
				source='foo.c.in',
				target='foo.c',
				install_path='${LIBDIR}/pkgconfig',
				VAR = 'val'
			)

	The input files are supposed to contain macros of the form *@VAR@*, where *VAR* is an argument
	of the task generator object.

	This method overrides the processing by :py:meth:`waflib.TaskGen.process_source`.
	r   r   z&invalid number of source/target for %rznull source or target for %r)NNzcould not find %r for %rr   r   Nr   r   r   r   )r   r@   r,   r:   r   lenr   rP   zipr3   r   	find_nodeget_bld	make_noder   isfiler   r   r   r   r   rj   r   HEADER_EXTSr%   r_   rw   r   r   r   r   )r   rg   rh   r/   rZ   rV   br   r   r    Zxtinst_tor!   r!   r"   process_substN  sT    

r   )N)%rp   rk   rer   r   waflibr   r   r   r   r   r   rr   rG   rI   r   objectr	   r   r   r   r   rx   r   ry   r   r   r   r   r   compileMr   r   r   r   r   r!   r!   r!   r"   <module>   sF     
  (
B!
 
$c
