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yddlZW n ek
r\   ddl	ZY nX ddl
mZmZmZmZmZmZmZmZmZmZ dZdZdZdZd ¡ Zd	ZdZd
ZdZejdkrÄdZG dd„ dejƒZ e !d¡e "dd¡dd„ ƒƒZ#ej$dd„ ƒZ%ej$dd„ ƒZ&ej$dd„ ƒZ'ej$dd„ ƒZ(G dd„ dejƒZ)G dd„ de ƒZ*G d d!„ d!e*ƒZ+G d"d#„ d#e ƒZ,G d$d%„ d%e ƒZ-G d&d'„ d'e ƒZ.G d(d)„ d)e ƒZ/dS )*zp
Classes related to the build phase (build, clean, install, step, etc)

The inheritance tree is the following:

é    N)
ÚNodeÚRunnerÚTaskGenÚUtilsÚ	ConfigSetÚTaskÚLogsÚOptionsÚContextÚErrorsZc4chez	_cache.pyi9  iÇúÿÿz4root node_sigs task_sigs imp_sigs raw_deps node_depsZ	cfg_filesé   éÿÿÿÿÚclic                   sz  e Zd ZdZdZdZ‡ fdd„Zdd„ Zee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dVdd„Zdd „ Zd!d"„ ZeeeƒZd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Z d5d6„ Z!d7d8„ Z"dWd9d:„Z#d;d<„ Z$d=d>„ Z%dXd@dA„Z&dBdC„ Z'dDdE„ Z(dFdG„ Z)dHdI„ Z*dJdK„ Z+dLdM„ Z,dNdO„ Z-dPdQ„ Z.dRdS„ Z/dTdU„ Z0‡  Z1S )YÚBuildContextzexecutes the buildÚbuildÚ c                s  t t| ƒjf |Ž d| _| dtj¡| _| dtj¡| _| dtj¡| _tj	| _	t
| _| d¡| _| jsztj | jt¡| _i | _i | _i | _i | _i | _i | _i | _tjj| _tjj| _tjj| _tjj| _t t ¡| _!d| _"g | _#i | _$x"t%D ]}t&| |ƒsðt'| |i ƒ qðW d S )Nr   Útop_dirÚout_dirÚrun_dirÚ	cache_dir)(Úsuperr   Ú__init__Ú
is_installÚgetr
   r   r   r   Ú
launch_dirÚ	POST_LAZYÚ	post_moder   ÚosÚpathÚjoinÚ	CACHE_DIRÚall_envsZ	node_sigsZ	task_sigsZimp_sigsZ	node_depsZraw_depsÚtask_gen_cache_namesr	   ÚoptionsÚjobsÚtargetsÚkeepÚprogress_barr   ÚdefaultdictÚlistÚdeps_manÚcurrent_groupÚgroupsÚgroup_namesÚSAVED_ATTRSÚhasattrÚsetattr)ÚselfÚkwÚv)Ú	__class__© ú'/wcdo/src/waf-tools/waf/waflib/Build.pyr   7   s8    





zBuildContext.__init__c             C   s&   | j s| jS tj | jtj | j ¡¡S )z$Getter for the variant_dir attribute)Úvariantr   r   r   r   Únormpath)r1   r5   r5   r6   Úget_variant_dir’   s    zBuildContext.get_variant_dirNc             O   s2   | |d< t j||Ž}i | _| j|| d¡d� |S )aw  
		Create a task generator and add it to the current build group. The following forms are equivalent::

			def build(bld):
				tg = bld(a=1, b=2)

			def build(bld):
				tg = bld()
				tg.a = 1
				tg.b = 2

			def build(bld):
				tg = TaskGen.task_gen(a=1, b=2)
				bld.add_to_group(tg, None)

		:param group: group name to add the task generator to
		:type group: string
		ÚbldÚgroup)r;   )r   Útask_genr"   Úadd_to_groupr   )r1   Úkr2   Úretr5   r5   r6   Ú__call__™   s
    zBuildContext.__call__c             C   s   t  d¡‚dS )zT
		Build contexts cannot be copied

		:raises: :py:class:`waflib.Errors.WafError`
		zbuild contexts cannot be copiedN)r   ÚWafError)r1   r5   r5   r6   Ú__copy__²   s    zBuildContext.__copy__c             C   s¸   | j  | j¡}|st d¡‚|jdt dd�}|s<t d¡‚xv|D ]n}| |¡ td¡ dd¡}t	 	| 
¡ ¡}|| j|< x6|t D ]*}| j  |¡}|rž| ¡ s‚t d	| ¡‚q‚W qBW d
S )a  
		The configuration command creates files of the form ``build/c4che/NAMEcache.py``. This method
		creates a :py:class:`waflib.ConfigSet.ConfigSet` instance for each ``NAME`` by reading those
		files and stores them in :py:attr:`waflib.Build.BuildContext.allenvs`.
		z:The project was not configured: run "waf configure" first!z**/*%sT)Úquietz5The cache directory is empty: reconfigure the projectr   ú\ú/z7Missing configuration file %r, reconfigure the project!N)ÚrootÚ	find_noder   r   rA   Úant_globÚCACHE_SUFFIXÚ	path_fromÚreplacer   Úabspathr!   Ú	CFG_FILESÚfind_resourceÚexists)r1   ÚnodeÚlstÚxÚnameÚenvÚfZnewnoder5   r5   r6   Ú	load_envsº   s    



zBuildContext.load_envsc             C   sZ   t j | j¡rt j | j¡s&t d¡‚| j | j¡ | _| _	| j 
| j¡| _| j ¡  dS )a*  
		Initialize the project directory and the build directory by creating the nodes
		:py:attr:`waflib.Build.BuildContext.srcnode` and :py:attr:`waflib.Build.BuildContext.bldnode`
		corresponding to ``top_dir`` and ``variant_dir`` respectively. The ``bldnode`` directory is
		created if necessary.
		z:The project was not configured: run "waf configure" first!N)r   r   Úisabsr   r   r   rA   rF   Úfind_dirÚsrcnodeÚ	make_nodeÚvariant_dirÚbldnodeÚmkdir)r1   r5   r5   r6   Ú	init_dirsÑ   s
    
zBuildContext.init_dirsc             C   s"   |   ¡  | js|  ¡  |  ¡  dS )zŸ
		Restore data from previous builds and call :py:meth:`waflib.Build.BuildContext.execute_build`.
		Overrides from :py:func:`waflib.Context.Context.execute`
		N)Úrestorer!   rV   Úexecute_build)r1   r5   r5   r6   Úexecuteß   s    zBuildContext.executec             C   sÖ   t  d| j¡ |  | jg¡ |  ¡  t ¡ | _z|  	¡  W d| j
dkr”tj ¡ r”| jjpZd}|  ||t jjt jj¡}t j|tjt jjt jjdœd� t  d| j¡ X yd| j_| `W n tk
rÈ   Y nX |  ¡  dS )ac  
		Execute the build by:

		* reading the scripts (see :py:meth:`waflib.Context.Context.recurse`)
		* calling :py:meth:`waflib.Build.BuildContext.pre_build` to call user build functions
		* calling :py:meth:`waflib.Build.BuildContext.compile` to process the tasks
		* calling :py:meth:`waflib.Build.BuildContext.post_build` to call user build functions
		zWaf: Entering directory `%s'Nr   )ÚstreamÚc1Úc2)ÚextrazWaf: Leaving directory `%s')r   Úinfor[   Úrecurser   Ú	pre_buildr   ÚTimerÚtimerÚcompiler'   ÚsysÚstderrÚisattyÚproducerÚ	processedÚprogress_lineÚcolorsÚBLUEÚNORMALÚ
cursor_offÚ	cursor_onr:   ÚAttributeErrorÚ
post_build)r1   ÚcÚmr5   r5   r6   r`   é   s"    

 zBuildContext.execute_buildc          
   C   s>  yt   tj | jd¡¡}W n tk
r.   Y n4X |jtjk rFt	 
d¡‚x|jD ]}| jf |Ž qNW tj | jtj¡}yt |d¡}W n$ ttfk
r¨   t d|¡ Y nŠX zztj ¡  | jt_yt |¡}W n0 tk
rü } zt d||¡ W dd}~X Y n&X x"tD ]}t| || |i ¡ƒ �qW W dtj ¡  X |   ¡  dS )zg
		Load data from a previous run, sets the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS`
		zbuild.config.pyzMProject was configured with a different version of Waf, please reconfigure itÚrbz2build: Could not load the build cache %s (missing)z.build: Could not pickle the build cache %s: %rN)!r   r   r   r   r   ÚEnvironmentErrorÚversionr
   Ú
HEXVERSIONr   rA   ÚtoolsÚsetupr[   ÚDBFILEr   ÚreadfÚEOFErrorr   Údebugr   Úpickle_lockÚacquireÚ
node_classÚNod3ÚcPickleÚloadsÚ	Exceptionr.   r0   r   Úreleaser^   )r1   rT   ÚtZdbfnÚdataÚerR   r5   r5   r6   r_   	  s0    

 
zBuildContext.restorec          	   C   sØ   i }xt D ]}t| |ƒ||< q
W tj | jtj¡}z"tj	 
¡  | jt_t |t¡}W dtj	 ¡  X tj|d |dd� y4t |¡}t |¡ tjs¨t |d |j|j¡ W n ttfk
rÂ   Y nX t |d |¡ dS )z—
		Store data for next runs, set the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS`. Uses a temporary
		file to avoid problems on ctrl+c.
		Nz.tmpÚwb)rz   )r.   Úgetattrr   r   r   r[   r
   r�   r   r…   r†   r‡   rˆ   r‰   ÚdumpsÚPROTOCOLrŒ   r   ÚwritefÚstatÚremoveÚis_win32ÚchownÚst_uidÚst_gidrw   ÚOSErrorÚrename)r1   rŽ   rR   ZdbÚstr5   r5   r6   Ústore.  s$    



zBuildContext.storec             C   s†   t  d¡ t | | j¡| _|  ¡ | j_y| j ¡  W n& t	k
rZ   |  
¡ rT|  ¡  ‚ Y nX |  
¡ rl|  ¡  | jjr‚t | jj¡‚dS )zÙ
		Run the build by creating an instance of :py:class:`waflib.Runner.Parallel`
		The cache file is written when at least a task was executed.

		:raises: :py:class:`waflib.Errors.BuildError` in case the build fails
		zbuild: compile()N)r   r„   r   ZParallelr$   ro   Úget_build_iteratorZbiterÚstartÚKeyboardInterruptÚis_dirtyrž   Úerrorr   Ú
BuildError)r1   r5   r5   r6   rk   L  s    
zBuildContext.compilec             C   s   | j jS )N)ro   Zdirty)r1   r5   r5   r6   r¢   e  s    zBuildContext.is_dirtyc             C   sL   t |tƒr(x|D ]}|  ||¡ qW dS t ||¡}t|dƒrH| | ¡ dS )aF  
		Import waf tools defined during the configuration::

			def configure(conf):
				conf.load('glib2')

			def build(bld):
				pass # glib2 is imported implicitly

		:param tool: tool list
		:type tool: list
		:param tooldir: optional tool directory (sys.path)
		:type tooldir: list of string
		:param funs: unused variable
		Nr€   )Ú
isinstancer)   r€   r
   Ú	load_toolr/   )r1   ÚtoolÚtooldirÚfunsÚiÚmoduler5   r5   r6   r€   h  s    


zBuildContext.setupc             C   s,   y| j | j S  tk
r&   | j d S X dS )zGetter for the env propertyr   N)r!   r7   ÚKeyError)r1   r5   r5   r6   Úget_env�  s    zBuildContext.get_envc             C   s   || j | j< dS )zSetter for the env propertyN)r!   r7   )r1   Úvalr5   r5   r6   Úset_env‡  s    zBuildContext.set_envc             C   sˆ   |st d| ƒ‚t|tjƒr"|}n&tj |¡r<| j |¡}n| j |¡}|sXt d| ƒ‚t|tƒrt| j	|  
|¡ n| j	|  |¡ dS )aŠ  
		Adds a dependency from a node object to a value::

			def build(bld):
				bld.add_manual_dependency(
					bld.path.find_resource('wscript'),
					bld.root.find_resource('/etc/fstab'))

		:param path: file path
		:type path: string or :py:class:`waflib.Node.Node`
		:param value: value to depend
		:type value: :py:class:`waflib.Node.Node`, byte object, or function returning a byte object
		zInvalid input path %rzCould not find the path %rN)Ú
ValueErrorr¥   r   r   r   rW   rF   rN   r)   r*   ÚextendÚappend)r1   r   ÚvaluerP   r5   r5   r6   Úadd_manual_dependency�  s    
z"BuildContext.add_manual_dependencyc             C   s2   y| j S  tk
r,   | j | j¡| _ | j S X dS )zNReturns the launch directory as a :py:class:`waflib.Node.Node` object (cached)N)Zp_lnrw   rF   rX   r   )r1   r5   r5   r6   Úlaunch_node¬  s
    zBuildContext.launch_nodec                s°   ˆ j sˆ j‰ ˆ stjS ttˆ ƒƒt|ƒ }y
| j}W n tk
rR   i  }| _Y n"X y
| j| S  tk
rr   Y nX ‡ fdd„|D ƒ}t 	|¡ ||< }t
 dt |¡|¡ |S )a/  
		Hashes configuration set variables::

			def build(bld):
				bld.hash_env_vars(bld.env, ['CXX', 'CC'])

		This method uses an internal cache.

		:param env: Configuration Set
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:param vars_lst: list of variables
		:type vars_list: list of string
		c                s   g | ]}ˆ | ‘qS r5   r5   )Ú.0Úa)rT   r5   r6   ú
<listcomp>Ô  s    z.BuildContext.hash_env_vars.<locals>.<listcomp>zenvhash: %s %r)ÚtableÚparentr   ÚSIG_NILÚstrÚidZ	cache_envrw   r¬   Úh_listr   r„   Úto_hex)r1   rT   Zvars_lstÚidxÚcacherQ   r?   r5   )rT   r6   Úhash_env_varsµ  s"    

zBuildContext.hash_env_varsc          
   C   s|   | j }|sLx@| jD ]6}x0|D ](}y|||j< W q tk
rB   Y qX qW qW y|| S  tk
rv   t d| ¡‚Y nX dS )an  
		Fetches a task generator by its name or its target attribute;
		the name must be unique in a build::

			def build(bld):
				tg = bld(name='foo')
				tg == bld.get_tgen_by_name('foo')

		This method use a private internal cache.

		:param name: Task generator name
		:raises: :py:class:`waflib.Errors.WafError` in case there is no task genenerator by that name
		z/Could not find a task generator for the name %rN)r"   r,   rS   rw   r¬   r   rA   )r1   rS   rÁ   ÚgÚtgr5   r5   r6   Úget_tgen_by_nameÙ  s    
zBuildContext.get_tgen_by_namec             C   sä   t j ¡ sdS tt|ƒƒ}t jd7  _tjtjd  }d| | }d||f }||||||f }	d|| j|f }
t	 
¡ t|	ƒ t|
ƒ dt|ƒ  dt|ƒ  }|dk r®d}|| | d }d	| d
  |¡}t	j|	||
f }|S )zt
		Computes a progress bar line displayed when running ``waf -p``

		:returns: progress bar line
		:rtype: string
		r   r   é   g      Y@z [%%%dd/%%d][%%s%%2d%%%%%%s][%s][z	][%s%s%s]é   é   ú=ú>)rl   rm   rn   Úlenr¼   r   Úrot_idxÚrot_chrrj   r   Úget_term_colsÚljustÚ	indicator)r1   rÀ   ÚtotalZcol1Zcol2ÚnZindZpcÚfsÚleftÚrightZcolsZratioZbarÚmsgr5   r5   r6   rq   ö  s     
0zBuildContext.progress_linec             O   s   t j||ŽS )zC
		Wraps :py:func:`waflib.TaskGen.declare_chain` for convenience
		)r   Údeclare_chain)r1   r>   r2   r5   r5   r6   r×     s    zBuildContext.declare_chainc             C   s"   xt | dg ƒD ]}|| ƒ qW dS )zkExecutes user-defined methods before the build starts, see :py:meth:`waflib.Build.BuildContext.add_pre_fun`Úpre_funsN)r‘   )r1   rz   r5   r5   r6   rh     s    zBuildContext.pre_buildc             C   s"   xt | dg ƒD ]}|| ƒ qW dS )zrExecutes user-defined methods after the build is successful, see :py:meth:`waflib.Build.BuildContext.add_post_fun`Ú	post_funsN)r‘   )r1   rz   r5   r5   r6   rx      s    zBuildContext.post_buildc             C   s2   y| j  |¡ W n tk
r,   |g| _ Y nX dS )zÉ
		Binds a callback method to execute after the scripts are read and before the build starts::

			def mycallback(bld):
				print("Hello, world!")

			def build(bld):
				bld.add_pre_fun(mycallback)
		N)rØ   r²   rw   )r1   Úmethr5   r5   r6   Úadd_pre_fun%  s    
zBuildContext.add_pre_func             C   s2   y| j  |¡ W n tk
r,   |g| _ Y nX dS )zì
		Binds a callback method to execute immediately after the build is successful::

			def call_ldconfig(bld):
				bld.exec_command('/sbin/ldconfig')

			def build(bld):
				if bld.cmd == 'install':
					bld.add_pre_fun(call_ldconfig)
		N)rÙ   r²   rw   )r1   rÚ   r5   r5   r6   Úadd_post_fun4  s    zBuildContext.add_post_func             C   s@   | j s|  ¡  |dkr"| j | j S || jkr6| j| S | j | S )z�
		Returns the build group named `x`, or the current group if `x` is None

		:param x: name or number or None
		:type x: string, int or None
		N)r,   Ú	add_groupr+   r-   )r1   rR   r5   r5   r6   Ú	get_groupD  s    

zBuildContext.get_groupc             C   s6   t |tjƒst |tjƒst‚| |_|  |¡ |¡ dS )zgAdds a task or a task generator to the build; there is no attempt to remove it if it was already added.N)r¥   r   r<   r   ÚAssertionErrorr:   rÞ   r²   )r1   Útgenr;   r5   r5   r6   r=   S  s    zBuildContext.add_to_groupc             C   sB   t |tƒs| j| }x(| jD ]}t| j| ƒt|ƒkr|S qW dS )z 
		Returns the name of the input build group

		:param g: build group object or build group index
		:type g: integer or list
		:return: name
		:rtype: string
		r   )r¥   r)   r,   r-   r½   )r1   rÃ   rR   r5   r5   r6   Úget_group_nameY  s    	

zBuildContext.get_group_namec             C   sB   t |ƒ}x4t| jƒD ]&\}}x|D ]}t |ƒ|kr"|S q"W qW dS )a  
		Returns the index of the group containing the task generator given as argument::

			def build(bld):
				tg = bld(name='nada')
				0 == bld.get_group_idx(tg)

		:param tg: Task generator object
		:type tg: :py:class:`waflib.TaskGen.task_gen`
		:rtype: int
		N)r½   Ú	enumerater,   )r1   rÄ   Zserª   Útmpr�   r5   r5   r6   Úget_group_idxi  s    
zBuildContext.get_group_idxTc             C   sL   |r|| j krt d|¡‚g }|| j |< | j |¡ |rHt| jƒd | _dS )a•  
		Adds a new group of tasks/task generators. By default the new group becomes
		the default group for new task generators (make sure to create build groups in order).

		:param name: name for this group
		:type name: string
		:param move: set this new group as default group (True by default)
		:type move: bool
		:raises: :py:class:`waflib.Errors.WafError` if a group by the name given already exists
		z"add_group: name %s already presentr   N)r-   r   rA   r,   r²   rË   r+   )r1   rS   ÚmoverÃ   r5   r5   r6   rÝ   |  s    
zBuildContext.add_groupc             C   sP   t |tƒrF| j| }x6t| jƒD ] \}}t|ƒt|ƒkr || _P q W n|| _dS )aç  
		Sets the build group at position idx as current so that newly added
		task generators are added to this one by default::

			def build(bld):
				bld(rule='touch ${TGT}', target='foo.txt')
				bld.add_group() # now the current group is 1
				bld(rule='touch ${TGT}', target='bar.txt')
				bld.set_group(0) # now the current group is 0
				bld(rule='touch ${TGT}', target='truc.txt') # build truc.txt before bar.txt

		:param idx: group name or group index
		:type idx: string or int
		N)r¥   r¼   r-   râ   r,   r½   r+   )r1   rÀ   rÃ   rª   rã   r5   r5   r6   Ú	set_group�  s    

zBuildContext.set_groupc          
   C   sV   d}xL| j D ]B}x<|D ]4}y|t|jƒ7 }W q tk
rH   |d7 }Y qX qW qW |S )a   
		Approximate task count: this value may be inaccurate if task generators
		are posted lazily (see :py:attr:`waflib.Build.BuildContext.post_mode`).
		The value :py:attr:`waflib.Runner.Parallel.total` is updated during the task execution.

		:rtype: int
		r   r   )r,   rË   Útasksrw   )r1   rÑ   r;   rÄ   r5   r5   r6   rÑ   §  s    
zBuildContext.totalc             C   s`   g }d}xN| j  d¡D ]>}|  |¡}|  |¡}||krB|}|g}q||kr| |¡ qW ||fS )a“  
		This method returns a pair containing the index of the last build group to post,
		and the list of task generator objects corresponding to the target names.

		This is used internally by :py:meth:`waflib.Build.BuildContext.get_build_iterator`
		to perform partial builds::

			$ waf --targets=myprogram,myshlib

		:return: the minimum build group index, and list of task generators
		:rtype: tuple
		r   ú,)r%   ÚsplitrÅ   rä   r²   )r1   Zto_postZmin_grprS   rÄ   rz   r5   r5   r6   Úget_targets¸  s    

zBuildContext.get_targetsc             C   s"   g }x| j D ]}| |¡ qW |S )zI
		Returns a list of all task generators for troubleshooting purposes.
		)r,   r±   )r1   rQ   rÃ   r5   r5   r6   Úget_all_task_genÑ  s    zBuildContext.get_all_task_genc                s>  dd„ }ˆj dkr4xˆjˆj D ]}||ƒ q W �nˆj r€ˆjˆjk rfx6ˆjˆj D ]}||ƒ qTW nxÒˆjD ]}| ¡  qnW nºˆ ¡ ‰ˆ ˆj¡r¦t	 
d¡ ˆj‰n*ˆ ˆj¡sÐt	 
dˆ ¡ ˆj ¡ ¡ ˆj‰dd„ ‰ ‡ ‡‡fdd	„}ˆjtk�rˆˆjk�r|ƒ �rˆj‰x*ˆjˆj D ]}ˆ |ˆƒ�r||ƒ �qW d
S )z•
		Post task generators from the group indexed by self.current_group; used internally
		by :py:meth:`waflib.Build.BuildContext.get_build_iterator`
		c             S   s*   y
| j }W n tk
r   Y nX |ƒ  d S )N)Úpostrw   )rÄ   rU   r5   r5   r6   Útgpostß  s
    
z'BuildContext.post_group.<locals>.tgpostÚ*z6Building from the build directory, forcing --targets=*z<CWD %s is not under %s, forcing --targets=* (run distclean?)c             S   s2   y
| j }W n tk
r   Y nX | |¡r.dS d S )NT)r   rw   Úis_child_of)rÄ   ÚlnÚpr5   r5   r6   Úis_postú  s    

z(BuildContext.post_group.<locals>.is_postc                 sB   x<t ˆjƒD ].\} }| ˆjkrx|D ]}ˆ |ˆƒr$dS q$W qW d S )NT)râ   r,   r+   )rª   rÃ   rÄ   )rò   rð   r1   r5   r6   Úis_post_group  s
    


z.BuildContext.post_group.<locals>.is_post_groupN)r%   r,   r+   Ú_min_grpÚ	_exact_tgrì   rµ   rï   r\   r   ÚwarnrY   rL   r   r   )r1   rí   rÄ   ró   r5   )rò   rð   r1   r6   Ú
post_groupÚ  s2    

	zBuildContext.post_groupc          	   C   sL   g }xB| j | D ]4}y| |j¡ W q tk
rB   | |¡ Y qX qW |S )zÂ
		Returns all task instances for the build group at position idx,
		used internally by :py:meth:`waflib.Build.BuildContext.get_build_iterator`

		:rtype: list of :py:class:`waflib.Task.Task`
		)r,   r±   rç   rw   r²   )r1   rÀ   rç   rÄ   r5   r5   r6   Úget_tasks_group  s    zBuildContext.get_tasks_groupc             c   s¸   | j r | j dkr |  ¡ \| _| _| jtkrLx t| jƒD ]\| _}|  	¡  q6W xZt| jƒD ]L\| _}| jt
krt|  	¡  |  | j¡}t |¡ t |¡ || _|rX|V  qXW x
g V  qªW dS )zÞ
		Creates a Python generator object that returns lists of tasks that may be processed in parallel.

		:return: tasks which can be executed immediately
		:rtype: generator returning lists of :py:class:`waflib.Task.Task`
		rî   N)r%   rê   rô   rõ   r   r   râ   r,   r+   r÷   ÚPOST_AT_ONCErø   r   Zset_file_constraintsZset_precedence_constraintsZ	cur_tasks)r1   Ú_rç   r5   r5   r6   rŸ   "  s     




zBuildContext.get_build_iteratorc             K   sD   |st ‚| f d||dœ|—Ž}|j|_d|_| dd¡s@| ¡  |S )ag  
		Creates a task generator to install files on the system::

			def build(bld):
				bld.install_files('${DATADIR}', self.path.find_resource('wscript'))

		:param dest: path representing the destination directory
		:type dest: :py:class:`waflib.Node.Node` or string (absolute path)
		:param files: input files
		:type files: list of strings or list of :py:class:`waflib.Node.Node`
		:param env: configuration set to expand *dest*
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:param relative_trick: preserve the folder hierarchy when installing whole folders
		:type relative_trick: bool
		:param cwd: parent node for searching srcfile, when srcfile is not an instance of :py:class:`waflib.Node.Node`
		:type cwd: :py:class:`waflib.Node.Node`
		:param postpone: execute the task immediately to perform the installation (False by default)
		:type postpone: bool
		Úinstall_task)ÚfeaturesÚ
install_toÚinstall_fromÚinstall_filesÚpostponeT)rß   rý   ÚdestÚtyper   rì   )r1   r  Úfilesr2   rÄ   r5   r5   r6   rÿ   I  s    zBuildContext.install_filesc             K   sD   |st ‚| f d||dœ|—Ž}|j|_d|_| dd¡s@| ¡  |S )aî  
		Creates a task generator to install a file on the system with a different name::

			def build(bld):
				bld.install_as('${PREFIX}/bin', 'myapp', chmod=Utils.O755)

		:param dest: destination file
		:type dest: :py:class:`waflib.Node.Node` or string (absolute path)
		:param srcfile: input file
		:type srcfile: string or :py:class:`waflib.Node.Node`
		:param cwd: parent node for searching srcfile, when srcfile is not an instance of :py:class:`waflib.Node.Node`
		:type cwd: :py:class:`waflib.Node.Node`
		:param env: configuration set for performing substitutions in dest
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:param postpone: execute the task immediately to perform the installation (False by default)
		:type postpone: bool
		rû   )rü   rý   rþ   Ú
install_asr   T)rß   rý   r  r  r   rì   )r1   r  Zsrcfiler2   rÄ   r5   r5   r6   r  e  s    zBuildContext.install_asc             K   sJ   |st ‚| f d||dœ|—Ž}|j|_d|_||_| dd¡sF| ¡  |S )aE  
		Creates a task generator to install a symlink::

			def build(bld):
				bld.symlink_as('${PREFIX}/lib/libfoo.so', 'libfoo.so.1.2.3')

		:param dest: absolute path of the symlink
		:type dest: :py:class:`waflib.Node.Node` or string (absolute path)
		:param src: link contents, which is a relative or absolute path which may exist or not
		:type src: string
		:param env: configuration set for performing substitutions in dest
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:param add: add the task created to a build group - set ``False`` only if the installation task is created after the build has started
		:type add: bool
		:param postpone: execute the task immediately to perform the installation
		:type postpone: bool
		:param relative_trick: make the symlink relative (default: ``False``)
		:type relative_trick: bool
		rû   )rü   rý   rþ   Ú
symlink_asr   T)rß   rý   r  r  Úlinkr   rì   )r1   r  Úsrcr2   rÄ   r5   r5   r6   r    s    zBuildContext.symlink_as)NN)N)NT)2Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úcmdr7   r   r9   Úpropertyr[   r@   rB   rV   r^   ra   r`   r_   rž   rk   r¢   r€   r­   r¯   rT   r´   rµ   rÂ   rÅ   rq   r×   rh   rx   rÛ   rÜ   rÞ   r=   rá   rä   rÝ   ræ   rÑ   rê   rë   r÷   rø   rŸ   rÿ   r  r  Ú__classcell__r5   r5   )r4   r6   r   1   sZ   [

 %

	$

	9'r   rû   Zprocess_ruleZprocess_sourcec             C   s   | j f | jŽ dS )zwCreates the installation task for the current task generator; uses :py:func:`waflib.Build.add_install_task` internally.N)Úadd_install_taskÚ__dict__)r1   r5   r5   r6   Úprocess_install_task�  s    r  c             K   s   | j jsdS |d sdS |d dkrBtjrB| d¡r>d|d< ndS |  d¡ }| _| dtj¡|_| d	d
¡px| dd
¡|_	| dd¡|_
|d |_|d  |_|_|d |_| d¡pÄ| d| j¡|_| d¡|_| d¡|_| ¡  | dd¡sü| ¡  |S )z²
	Creates the installation task for the current task generator, and executes it immediately if necessary

	:returns: An installation task
	:rtype: :py:class:`waflib.Build.inst`
	Nrý   r  r  Zwin32_installr  ÚinstÚchmodr  r   rþ   Úrelative_trickFÚcwdÚrelative_baseÚinstall_userÚinstall_groupr   T)r:   r   r   r—   r   Zcreate_taskrû   ÚO644r  r  r  r  rý   r  rþ   r   r  r  r  Ú
init_filesÚrun_now)r1   r2   Útskr5   r5   r6   r  £  s,    



r  c             K   s   d|d< | j f |ŽS )zr
	Creates an installation task for files

	:returns: An installation task
	:rtype: :py:class:`waflib.Build.inst`
	rÿ   r  )r  )r1   r2   r5   r5   r6   Úadd_install_filesÆ  s    r  c             K   s   d|d< | j f |ŽS )zz
	Creates an installation task for a single file

	:returns: An installation task
	:rtype: :py:class:`waflib.Build.inst`
	r  r  )r  )r1   r2   r5   r5   r6   Úadd_install_asÑ  s    r  c             K   s   d|d< | j f |ŽS )z|
	Creates an installation task for a symbolic link

	:returns: An installation task
	:rtype: :py:class:`waflib.Build.inst`
	r  r  )r  )r1   r2   r5   r5   r6   Úadd_symlink_asÜ  s    r  c                   s’   e Zd ZdZdd„ Zdd„ Zdd„ Z‡ fdd	„Zd
d„ Zd!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‡  ZS )"r  z—Task that installs files or symlinks; it is typically executed by :py:class:`waflib.Build.InstallContext` and :py:class:`waflib.Build.UnInstallContext`c             C   s   dS )z<Returns an empty string to disable the standard task displayr   r5   )r1   r5   r5   r6   Ú__str__é  s    zinst.__str__c             C   s(   | j | j | j| jj ¡ g }t |¡S )z(Returns a unique identifier for the task)ÚinputsÚoutputsr  Ú	generatorr   rL   r   r¾   )r1   rQ   r5   r5   r6   Úuidí  s    zinst.uidc             C   s  | j dkrg }n(| j | j¡}| j dkr8t|ƒdks8t‚|  |¡ |  ¡ }g }| j dkr�| jrxt	j
 | jt	j
 |¡¡| _| | jjj |¡¡ nt| j dkr²| | jjj |¡¡ nRxP|D ]H}| jrÚt	j
 || | j¡¡}nt	j
 ||j¡}| | jjj |¡¡ q¸W |  |¡ dS )z1
		Initializes the task input and output nodes
		r  r  r   N)r  r#  Zto_nodesrþ   rË   rß   Z
set_inputsÚget_install_pathr  r   r   Úrelpathr  Údirnamer²   r:   rF   rZ   r   rJ   r  rS   Zset_outputs)r1   r!  r  r"  ÚyZdestfiler5   r5   r6   r  ò  s(    





zinst.init_filesc                s,   t t| ƒ ¡ }|tjkr(| jjjr(tjS |S )z�
		Installation tasks are always executed, so this method returns either :py:const:`waflib.Task.ASK_LATER` or :py:const:`waflib.Task.RUN_ME`.
		)	r   r  Úrunnable_statusr   ÚSKIP_MEr#  r:   r   ÚRUN_ME)r1   r?   )r4   r5   r6   r)    s    zinst.runnable_statusc             C   s   dS )z&
		Disables any post-run operations
		Nr5   )r1   r5   r5   r6   Úpost_run  s    zinst.post_runTc             C   s†   t | jtjƒr| j ¡ }ntj t | j| j	¡¡}tj 
|¡sPtj | j	j|¡}|r‚tjjr‚tj tjjtj |¡d  tj¡¡}|S )z¿
		Returns the destination path where files will be installed, pre-pending `destdir`.

		Relative paths will be interpreted relative to `PREFIX` if no `destdir` is given.

		:rtype: string
		r   )r¥   rý   r   rL   r   r   r8   r   Ú
subst_varsrT   rW   r   ÚPREFIXr	   r#   ÚdestdirÚ
splitdriveÚlstripÚsep)r1   r/  r  r5   r5   r6   r%    s    &zinst.get_install_pathc             C   s>   t jr$t|ƒdkr$| d¡s$d| }t ||¡ |  |¡ dS )aJ  
		Copies a file from src to tgt, preserving permissions and trying to work
		around path limitations on Windows platforms. On Unix-like platforms,
		the owner/group of the target file may be set through install_user/install_group

		:param src: absolute path
		:type src: string
		:param tgt: absolute path
		:type tgt: string
		i  z\\?\N)r   r—   rË   Ú
startswithÚshutilÚcopy2Ú	fix_perms)r1   r  Útgtr5   r5   r6   Úcopy_fun0  s    zinst.copy_func             C   s@   x:|r:t j |¡}yt  |¡ W q tk
r6   P Y qX qW dS )zk
		Removes empty folders recursively when uninstalling.

		:param tgt: absolute path
		:type tgt: string
		N)r   r   r'  Úrmdirr›   )r1   r7  r5   r5   r6   Úrm_empty_dirsB  s    zinst.rm_empty_dirsc             C   sÄ   | j jj}|sdS x | jD ]}|tkr|j ¡  qW | jdkrj|tkrL| jpP| j	}|| j
| jd  ¡ ƒ nV|tkrx| jp|| j}| j j ¡ }x4t| j| jƒD ]"\}}|| ¡ | ¡ | |¡ƒ qšW dS )z+
		Performs file or symlink installation
		Nr  r   )r#  r:   r   r"  ÚINSTALLrº   r]   r  Údo_linkÚ	do_unlinkr  rL   Ú
do_installÚdo_uninstallrµ   Úzipr!  rJ   )r1   r   rR   Úfunrµ   r(  r5   r5   r6   ÚrunP  s    

zinst.runc             C   s>   |   ¡ }|tjtjfkr*t d| |f ¡‚|  ¡  tj| _dS )zf
		Try executing the installation task right now

		:raises: :py:class:`waflib.Errors.TaskNotReady`
		zCould not process %r: status %rN)	r)  r   r+  r*  r   ÚTaskNotReadyrB  ÚSUCCESSZhasrun)r1   Ústatusr5   r5   r6   r  d  s
    zinst.run_nowc       
   
   K   s’  t jjs„yt |¡}t |¡}W n tk
r4   Y nPX |jd |jkr„|j|jkr„| jj	j
s€tjj}tjj}t d|||||¡ dS | jj	j
s²tjj}tjj}t d|||||¡ y$t |tjt t |¡j¡B ¡ W n tk
rê   Y nX yt |¡ W n tk
�r   Y nX y|  ||¡ W nj tk
�rŒ }	 zJtj |¡�sRt d|¡ ntj |¡�slt d|¡ t d| |	¡‚W dd}	~	X Y nX dS )	aD  
		Copies a file from src to tgt with given file permissions. The actual copy is only performed
		if the source and target file sizes or timestamps differ. When the copy occurs,
		the file is always first removed and then copied so as to prevent stale inodes.

		:param src: file name as absolute path
		:type src: string
		:param tgt: file destination, as absolute path
		:type tgt: string
		:param lbl: file source description
		:type lbl: string
		:param chmod: installation mode
		:type chmod: int
		:raises: :py:class:`waflib.Errors.WafError` if the file cannot be written
		rÇ   z%s- install %s%s%s (from %s)Fz%s+ install %s%s%s (from %s)zFile %r does not existzInput %r is not a filezCould not install the file %rN)r	   r#   Úforcer   r•   r›   Úst_mtimeÚst_sizer#  r:   r'   r   rr   rt   rs   rf   r  r   r  ÚS_IMODEÚst_moder|   r–   r8  r   rO   r£   Úisfiler   rA   )
r1   r  r7  Úlblr2   Zst1Zst2rc   rd   r�   r5   r5   r6   r>  p  s@    


$zinst.do_installc             C   sv   t jsXt| ddƒpt| jddƒ}t| ddƒp8t| jddƒ}|sB|rXt  ||pNd|pTd¡ tj |¡srt || j¡ dS )aÎ  
		Change the ownership of the file/folder/link pointed by the given path
		This looks up for `install_user` or `install_group` attributes
		on the task or on the task generator::

			def build(bld):
				bld.install_as('${PREFIX}/wscript',
					'wscript',
					install_user='nobody', install_group='nogroup')
				bld.symlink_as('${PREFIX}/wscript_link',
					Utils.subst_vars('${PREFIX}/wscript', bld.env),
					install_user='nobody', install_group='nogroup')
		r  Nr  r   )	r   r—   r‘   r#  Úlchownr   r   Úislinkr  )r1   r7  Úuserr;   r5   r5   r6   r6  ¯  s    zinst.fix_permsc             K   s¶   t j |¡rJt  |¡|krJ| jjjs²tjj	}tjj
}t d|||||¡ nhyt  |¡ W n tk
rl   Y nX | jjjsœtjj	}tjj
}t d|||||¡ t  ||¡ |  |¡ dS )z«
		Creates a symlink from tgt to src.

		:param src: file name as absolute path
		:type src: string
		:param tgt: file destination, as absolute path
		:type tgt: string
		z%s- symlink %s%s%s (to %s)z%s+ symlink %s%s%s (to %s)N)r   r   rN  Úreadlinkr#  r:   r'   r   rr   rt   rs   rf   r–   r›   Úsymlinkr6  )r1   r  r7  r2   rc   rd   r5   r5   r6   r<  Å  s    	

zinst.do_linkc          
   K   s°   | j jjs,tjj}tjj}t d||||¡ yt 	|¡ W nf t
k
r  } zH|jtjkr�t| ddƒstd| _t d¡ tjdkr�t d|j|j¡ W dd}~X Y nX |  |¡ dS )z1
		See :py:meth:`waflib.Build.inst.do_install`
		z%s- remove %s%s%sÚuninstall_errorNTzHbuild: some files could not be uninstalled (retry with -vv to list them)r   z#Could not remove %s (error code %r))r#  r:   r'   r   rr   rt   rs   rf   r   r–   r›   ÚerrnoÚENOENTr‘   rR  rö   ÚverboseÚfilenamer:  )r1   r  r7  rL  r2   rc   rd   r�   r5   r5   r6   r?  ß  s    


$zinst.do_uninstallc             K   s^   y:| j jjs.tjj}tjj}t d||||¡ t 	|¡ W n t
k
rN   Y nX |  |¡ dS )z.
		See :py:meth:`waflib.Build.inst.do_link`
		z%s- remove %s%s%sN)r#  r:   r'   r   rr   rt   rs   rf   r   r–   r›   r:  )r1   r  r7  r2   rc   rd   r5   r5   r6   r=  ô  s    
zinst.do_unlink)T)r  r	  r
  r  r   r$  r  r)  r,  r%  r8  r:  rB  r  r>  r6  r<  r?  r=  r  r5   r5   )r4   r6   r  ç  s    	
?r  c                   s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )ÚInstallContextz"installs the targets on the systemÚinstallc                s   t t| ƒjf |Ž t| _d S )N)r   rW  r   r;  r   )r1   r2   )r4   r5   r6   r     s    zInstallContext.__init__)r  r	  r
  r  r  r   r  r5   r5   )r4   r6   rW    s   rW  c                   s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )ÚUninstallContextzremoves the targets installedÚ	uninstallc                s   t t| ƒjf |Ž t| _d S )N)r   rY  r   Ú	UNINSTALLr   )r1   r2   )r4   r5   r6   r     s    zUninstallContext.__init__)r  r	  r
  r  r  r   r  r5   r5   )r4   r6   rY  
  s   rY  c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚCleanContextzcleans the projectÚcleanc             C   s@   |   ¡  | js|  ¡  |  | jg¡ z|  ¡  W d|  ¡  X dS )z7
		See :py:func:`waflib.Build.BuildContext.execute`.
		N)r_   r!   rV   rg   r   r]  rž   )r1   r5   r5   r6   ra     s    zCleanContext.executec                sÔ   t  d¡ tˆ dƒr.xŽˆ jD ]}| ¡  qW nvˆ jˆ jkr¤g }x.ˆ j ¡ D ] }| 	‡ fdd„|t
 D ƒ¡ qJW dt }x,ˆ jjd|dd�D ]}||kr˜qŠ| ¡  qŠW i ˆ j_x"tD ]}|d	krÀq²tˆ |i ƒ q²W d
S )a  
		Remove most files from the build directory, and reset all caches.

		Custom lists of files to clean can be declared as `bld.clean_files`.
		For example, exclude `build/program/myprogram` from getting removed::

			def build(bld):
				bld.clean_files = bld.bldnode.ant_glob('**',
					excl='.lock* config.log c4che/* config.h program/myprogram',
					quiet=True, generator=True)
		zbuild: clean calledÚclean_filesc             3   s   | ]}ˆ j  |¡V  qd S )N)rF   Úfind_or_declare)r¶   rU   )r1   r5   r6   ú	<genexpr>8  s    z%CleanContext.clean.<locals>.<genexpr>z'.lock* *conf_check_*/** config.log %s/*z**/*T)ÚexclrC   rF   N)r   r„   r/   r^  Údeleter\   rY   r!   Úvaluesr±   rM   r    rH   rF   Úchildrenr.   r0   )r1   rÒ   rQ   rT   Zexcluded_dirsr3   r5   )r1   r6   r]  #  s$    

 
zCleanContext.cleanN)r  r	  r
  r  r  ra   r]  r5   r5   r5   r6   r\    s   r\  c               @   s   e Zd ZdZdZdd„ ZdS )ÚListContextzlists the targets to executer)   c       	   
   C   s  |   ¡  | js|  ¡  |  | jg¡ |  ¡  t ¡ | _xB| j	D ]8}x2|D ]*}y
|j
}W n tk
rj   Y qHX |ƒ  qHW q>W y|  d¡ W n tjk
rž   Y nX t| jƒ}|rÀtdd„ |D ƒƒnd}xH|D ]@}| j| }t|ddƒ}|rú| |¡}d| }tjd||d� qÊW d	S )
zÙ
		In addition to printing the name of each build target,
		a description column will include text for each task
		generator which has a "description" field set.

		See :py:func:`waflib.Build.BuildContext.execute`.
		r   c             s   s   | ]}t |ƒV  qd S )N)rË   )r¶   r�   r5   r5   r6   r`  m  s    z&ListContext.execute.<locals>.<genexpr>r   Údescriptionz: %sÚGREEN)ÚlabelN)r_   r!   rV   rg   r   rh   r   ri   rj   r,   rì   rw   rÅ   r   rA   Úsortedr"   Úmaxr‘   rÏ   r   Úpprint)	r1   rÃ   rÄ   rU   r%   Ú	line_justÚtargetrà   Zdescriptr5   r5   r6   ra   I  s4    






zListContext.executeN)r  r	  r
  r  r  ra   r5   r5   r5   r6   re  E  s   re  c                   s4   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	ÚStepContextz7executes tasks in a step-by-step fashion, for debuggingÚstepc                s    t t| ƒjf |Ž tjj| _d S )N)r   rn  r   r	   r#   r  )r1   r2   )r4   r5   r6   r     s    zStepContext.__init__c          
   C   sV  | j st d¡ t | ¡ dS g }| jr>| jdkr>| j d¡}�x| jD �]}xB|D ]:}|rh|j|krhqTy
|j	}W n t
k
r†   Y qTX |ƒ  qTW xº| j  d¡D ]ª}|  |¡}xš|D ]’}t|tjƒrÌ|g}n|j}xr|D ]j}d}	x |jD ]}
||
dd�rèd}	P qèW x$|jD ]}
||
dd��r
d}	P �q
W |	rØ| ¡ }t d||¡ qØW q´W q W qHW dS )	a  
		Overrides :py:meth:`waflib.Build.BuildContext.compile` to perform a partial build
		on tasks matching the input/output pattern given (regular expression matching)::

			$ waf step --files=foo.c,bar.c,in:truc.c,out:bar.o
			$ waf step --files=in:foo.cpp.1.o # link task only

		zLAdd a pattern for the debug build, for example "waf step --files=main.c,app"Nrî   rè   F)ÚoutputTz%s -> exit %r)r  r   rö   r   rk   r%   ré   r,   rS   rì   rw   Úget_matcherr¥   r   rç   r!  r"  rB  rf   )r1   r%   rÃ   rÄ   rU   ÚpatZmatcherrQ   r  Zdo_execrP   r?   r5   r5   r6   rk   ƒ  sF    	







zStepContext.compilec                s–   d‰d‰|  d¡r$d‰| dd¡}n|  d¡r>d‰| dd¡}| j |¡‰ d‰ˆ s€|  d¡sdd| }| d	¡svd
| }t |¡‰‡ ‡‡‡fdd„}|S )zÉ
		Converts a step pattern into a function

		:param: pat: pattern of the form in:truc.c,out:bar.o
		:returns: Python function that uses Node objects as inputs and returns matches
		:rtype: function
		Tzin:Fr   zout:Nú^z^.+?%sú$z%s$c                s6   |rˆsdS |sˆsdS ˆ r$ˆ | kS ˆ  |  ¡ ¡S d S )NF)ÚmatchrL   )rP   rp  )ÚanodeÚinnÚoutÚpatternr5   r6   ru  Ñ  s    z&StepContext.get_matcher.<locals>.match)r3  rK   rF   rG   ÚendswithÚrerk   )r1   rr  ru  r5   )rv  rw  rx  ry  r6   rq  ¶  s$    	





zStepContext.get_matcher)	r  r	  r
  r  r  r   rk   rq  r  r5   r5   )r4   r6   rn  {  s
   3rn  c               @   s    e Zd ZdZd ZZdd„ ZdS )Ú
EnvContextzOSubclass EnvContext to create commands that require configuration data in 'env'Nc             C   s(   |   ¡  | js|  ¡  |  | jg¡ dS )z7
		See :py:func:`waflib.Build.BuildContext.execute`.
		N)r_   r!   rV   rg   r   )r1   r5   r5   r6   ra   à  s    zEnvContext.execute)r  r	  r
  r  rA  r  ra   r5   r5   r5   r6   r|  Ý  s   r|  )0r  r   rl   rS  r{  r4  r•   r‰   ÚImportErrorÚpickleÚwaflibr   r   r   r   r   r   r   r	   r
   r   r    rI   r;  r[  ré   r.   rM   rù   r   r“   Úplatformr   ZfeatureZbefore_methodr  Ztaskgen_methodr  r  r  r  r  rW  rY  r\  re  rn  r|  r5   r5   r5   r6   Ú<module>
   sN   00
      r#  36b