B
    ‘Í‚^Œ@  ã               @   s  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZmZmZmZmZmZmZmZ dZdgZdZdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ dejƒZdd„ ZG dd„ deƒZ dd„ Z!dd„ Z"e"ej#j$ƒej#_$dS )z?Module called for configuring, compiling and installing targetsé    )Úwith_statementN)	ÚUtilsÚ	ConfigureÚLogsÚOptionsÚ	ConfigSetÚContextÚErrorsÚBuildÚNodeÚ	configureÚbuildc          
   C   s~  t  ¡  tj|kr.t  d|tj|¡ t d¡ |t_|  t_t_	| }t
j d¡}ttjƒdkrÀt
j | tjd ¡}t
j |¡tjkrÀt
j |¡rÀt
j t
j |¡¡}t
j |¡}d}tj d¡ t d¡}|jdd�\}}	}
|jrø|j } t_t_d}|j�r|jt_|�s@x0tD ](}x |	D ]}| |¡�rd}P �qW �qW |}�x‚|�rÈyt
  |¡}W n& t!k
�r‚   g }t  d|¡ Y nX t"j#|k�r†t$ $¡ }
y*|
 %t
j |t"j#¡¡ t
 &|¡t&j' }W n t(k
�rØ   Y n®X xŠ|
j|
j|
jfD ]f}|�sú�qìt)j*�r||k�rPd}P n<yt
 &|¡t&j' }W n t!k
�r>   Y nX ||k�rìd}P �qìW t  +d|¡ d	}|�r†|
jt_|
jt_|
jt_P tj�s tj|k�r |t_t
j |¡}||k�r¸P |}|�rHP �qHW t
j t
j tjtj¡¡}t
j ,|¡�s0|j-�rt  +d
¡ |j. /¡  t d¡ t  dtj¡ t d¡ yt
 0tj¡ W n. t!k
�rn   t  dtj¡ t d¡ Y nX yt1|ƒ W n” t2j3k
�rÈ } z*t  4d|j5¡ t  t6|ƒ¡ t d¡ W dd}~X Y nJ t7k
�r } z*t  dtj¡ t8j9tj:d� t d¡ W dd}~X Y nX |j;�rXddl<}ddl=}| >di i d¡ | ?d¡}| @d¡ Ad¡ �n"yPy
tBƒ  W n@   |jC�ržddlC}t D¡ \}}}t8 9¡  | E|¡ n‚ Y nX W nÐ t2j3k
�rþ } z4t jFdk�rØt  4d|j5¡ t  |jG¡ t d¡ W dd}~X Y n| tHk
�r   ‚ Y nf t7k
�rN } zt8j9tj:d� t d¡ W dd}~X Y n, tIk
�rx   t  4dd¡ t d¡ Y nX dS )aG  
	This is the main entry point, all Waf execution starts here.

	:param current_directory: absolute path representing the current directory
	:type current_directory: string
	:param version: version number
	:type version: string
	:param wafdir: absolute path representing the directory of the waf library
	:type wafdir: string
	z8Waf script %r and library %r do not match (directory %r)é   ZNOCLIMBTÚoptions)Zallow_unknownzDirectory %r is unreadable!zinvalid lock file in %sFz8These are the generic options (no wscript/project found)r   zOWaf: Run from a folder containing a %r file (or try -h for the generic options)z Waf: The folder %r is unreadableZREDNz$Waf: The wscript in %r is unreadable)Úfileé   z6from waflib import Scripting; Scripting.run_commands()z	profi.txtZtimeéK   ZInterruptedéD   )Jr   Zinit_logr   Z
WAFVERSIONÚerrorÚsysÚexitZwaf_dirÚrun_dirÚ
launch_dirÚosÚenvironÚgetÚlenÚargvÚpathÚjoinÚbasenameZWSCRIPT_FILEÚisfileÚnormpathÚdirnameÚabspathÚpopÚcreate_contextZparse_cmd_argsÚtopÚtop_dirÚoutÚout_dirÚno_climb_commandsÚ
startswithÚlistdirÚOSErrorr   Úlockfiler   ÚloadÚstatÚST_INOÚEnvironmentErrorr   Zis_win32ÚwarnÚexistsÚwhelpÚparserÚ
print_helpÚchdirÚset_main_moduler	   ÚWafErrorZpprintZverbose_msgÚstrÚ	ExceptionÚ	tracebackZ	print_excÚstdoutZprofileÚcProfileÚpstatsZrunctxZStatsZ
sort_statsZprint_statsÚrun_commandsÚpdbÚexc_infoZpost_mortemÚverboseÚmsgÚ
SystemExitÚKeyboardInterrupt)Zcurrent_directoryÚversionÚwafdirZ	start_dirZno_climbZpotential_wscriptr   Úctxr   ÚcommandsÚenvÚkÚyÚcurÚlstZinoÚxr0   Úino2ÚnextZwscriptÚer@   rA   ÚprC   ÚtypeÚvalueÚtb© rZ   ú+/wcdo/src/waf-tools/waf/waflib/Scripting.pyÚwaf_entry_point   sö    














r\   c             C   s~   t  | ¡t _| t j_dd„ }xtttfD ]}||ƒ q(W dt jjkrNtj	t j_
dt jjkrdtj	t j_dt jjkrztj	t j_dS )aZ  
	Read the main wscript file into :py:const:`waflib.Context.Context.g_module` and
	bind default functions such as ``init``, ``dist``, ``distclean`` if not defined.
	Called by :py:func:`waflib.Scripting.waf_entry_point` during the initialization.

	:param file_path: absolute path representing the top-level wscript file
	:type file_path: string
	c             S   s$   | j }|tjjkr ttj|| ƒ d S )N)Ú__name__r   Úg_moduleÚ__dict__Úsetattr)ÚobjÚnamerZ   rZ   r[   Úset_defÅ   s    z set_main_module.<locals>.set_defÚinitÚshutdownr   N)r   Úload_moduler^   Ú	root_pathÚdistÚ	distcleanÚ	distcheckr_   r   Znadard   re   r   )Ú	file_pathrc   rN   rZ   rZ   r[   r:   ¶   s    	

r:   c              C   s\   t  d¡} |  ¡  tjs<tttƒr0tj t¡ ntj 	t¡ tj
jrX| j ¡  t d¡ dS )z˜
	Parses the command-line options and initialize the logging system.
	Called by :py:func:`waflib.Scripting.waf_entry_point` during the initialization.
	r   r   N)r   r&   Úexecuter   rL   Ú
isinstanceÚdefault_cmdÚlistÚextendÚappendr   r6   r7   r8   r   r   )rK   rZ   rZ   r[   Úparse_optionsÓ   s    


rr   c             C   s>   t  | ¡}t ¡ |_tj|_| |_z| ¡  W d| 	¡  X |S )z¤
	Executes a single Waf command. Called by :py:func:`waflib.Scripting.run_commands`.

	:param cmd_name: command to execute, like ``build``
	:type cmd_name: string
	N)
r   r&   r   ZTimerÚ	log_timerr   r   Úcmdrl   Zfinalize)Úcmd_namerK   rZ   rZ   r[   Úrun_commandã   s    


rv   c              C   sJ   t ƒ  tdƒ x.tjr<tj d¡} t| ƒ}t d| |j¡ qW tdƒ dS )zè
	Execute the Waf commands that were given on the command-line, and the other options
	Called by :py:func:`waflib.Scripting.waf_entry_point` during the initialization, and executed
	after :py:func:`waflib.Scripting.parse_options`.
	rd   r   z%r finished successfully (%s)re   N)rr   rv   r   rL   r%   r   Úinfors   )ru   rK   rZ   rZ   r[   rB   õ   s    rB   c          
   C   sÒ   xnt  | ¡D ]`\}}}xT|D ]L}| d¡rt j ||¡}yt  |¡ W q tk
rf   t d|¡ Y qX qW qW x6t	j
dfD ](}yt  |¡ W q| tk
r¢   Y q|X q|W yt tj¡ W n tk
rÌ   Y nX dS )z—
	Distclean function called in the particular case when::

		top == out

	:param dirname: absolute path of the folder to clean
	:type dirname: string
	)z.oz.mocz.exezCould not remove %rz
config.logN)r   ÚwalkÚendswithr   r   Úremover.   r   r4   r   ZDBFILEÚshutilÚrmtreer
   Z	CACHE_DIR)r#   ÚrootÚdirsÚfilesÚfÚfnamerR   rZ   rZ   r[   Údistclean_dir  s"    	


r‚   c       
      C   s‚  dd„ }t jsJx:t d¡D ],}x&d ¡ D ]}| |¡r(||tjƒ q(W qW d}| jj	r^| jj
}yt |¡}W n  tk
rŒ   t d|¡ dS X t j|k�r~tj |t j¡}yt |¡}W n  tk
rØ   t d|¡ dS X |jræ|jsöt d|¡ dS |j|jk�rt|jƒ n||jtjƒ |jg}| jj	�s<| |j¡ | jj�sR| |j¡ x*|D ]"}tj |t j¡}	||	tjƒ �qXW dS )zremoves build folders and datac          
   S   sL   y|| ƒ W n: t k
rF } z|jtjkr6t d| ¡ W d d }~X Y nX d S )NzCould not remove %r)r3   ÚerrnoZENOENTr   r4   )rN   ÚfunrU   rZ   rZ   r[   Úremove_and_log%  s
    z!distclean.<locals>.remove_and_logÚ.z.waf-2 waf-2 .waf3-2 waf3-2zCould not read %rNzInvalid lock file %r)r   rL   r   r-   Úsplitr,   r{   r|   r   Zno_lock_in_topr)   r.   r   r4   r/   r   r   r   r3   r*   r(   r‚   rq   Zno_lock_in_runr   rz   )
rK   r…   rN   rR   rP   rQ   r€   rM   Zenv_dirsrV   rZ   rZ   r[   ri   "  sF    



ri   c               @   sh   e Zd ZdZdZdZdZi Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚDistz5creates an archive containing the project source coderh   ztar.bz2c             C   s$   |   tj tjj¡g¡ |  ¡  dS )z3
		See :py:func:`waflib.Context.Context.execute`
		N)Úrecurser   r   r#   r   r^   rg   Úarchive)ÚselfrZ   rZ   r[   rl   _  s    zDist.executec             C   sŒ  ddl }|  ¡ }y
| j W n tk
r6   | j| _Y nX | j |¡}y| ¡  W n tk
rd   Y nX |  ¡ }| j	 
d¡r¼| | ¡ d| j	 dd¡ ¡}x|D ]}|  ||¡ qžW | ¡  nx| j	dk�r*ddl}|j| ¡ d|jd�}x8|D ]0}|  ¡ d	 | | j¡ }	| | ¡ |	|j¡ qìW | ¡  n
|  d
¡ yddlm}
 W n tk
�r^   d}Y nX d|
|jdd�ƒ ¡  }t d| j|¡ dS )z!
		Creates the source archive.
		r   Nztar.zw:Ú ÚzipÚw)Zcompressionú/z3Valid algo types are tar.bz2, tar.gz, tar.xz or zip)Úsha256z (sha256=%r)Úrb)ÚflagszNew archive created: %s%s)ÚtarfileÚget_arch_nameÚ	base_pathÚAttributeErrorr   Z	make_nodeÚdeleter.   Ú	get_filesÚalgor,   Úopenr$   ÚreplaceÚadd_tar_fileÚcloseÚzipfileZZipFileZZIP_DEFLATEDÚget_base_nameÚ	path_fromÚwriteZfatalZhashlibr�   ÚImportErrorÚreadZ	hexdigestr   rw   Ú	arch_name)r‹   r“   r¤   Únoder   ÚtarrR   rž   r�   Zarchive_namer�   ZdigestrZ   rZ   r[   rŠ   f  s>    






zDist.archivec             C   s   |  ¡ S )z¿
		Return the path to use for a node in the tar archive, the purpose of this
		is to let subclases resolve symbolic links or to change file names

		:return: absolute path
		:rtype: string
		)r$   )r‹   r¥   rZ   rZ   r[   Úget_tar_path•  s    zDist.get_tar_pathc          	   C   s„   |   |¡}|j||  ¡ d | | j¡ d�}d|_d|_d|_d|_t	j
 |¡rvt|dƒ�}|j||d� W dQ R X n
| |¡ dS )zu
		Adds a file to the tar archive. Symlinks are not verified.

		:param x: file path
		:param tar: tar file object
		r�   )rb   Zarcnamer   r}   r‘   )ZfileobjN)r§   Z
gettarinfoÚget_tar_prefixr    r•   ZuidÚgidÚunameZgnamer   r   r!   rš   Zaddfile)r‹   rR   r¦   rV   Ztinfor€   rZ   rZ   r[   rœ   Ÿ  s    
"zDist.add_tar_filec             C   s$   y| j S  tk
r   |  ¡ S X dS )zW
		Returns the base path for files added into the archive tar file

		:rtype: string
		N)Z
tar_prefixr–   rŸ   )r‹   rZ   rZ   r[   r¨   ³  s    zDist.get_tar_prefixc             C   sF   y
| j  W n4 tk
r>   |  ¡ d | j | j| j¡ | _ Y nX | j S )z©
		Returns the archive file name.
		Set the attribute *arch_name* to change the default value::

			def dist(ctx):
				ctx.arch_name = 'ctx.tar.bz2'

		:rtype: string
		r†   )r¤   r–   rŸ   Úext_algor   r™   )r‹   rZ   rZ   r[   r”   ¾  s
    

&zDist.get_arch_namec             C   sT   y
| j  W nB tk
rL   ttjtjdƒ}ttjtjdƒ}|d | | _ Y nX | j S )zæ
		Returns the default name of the main directory in the archive, which is set to *appname-version*.
		Set the attribute *base_name* to change the default value::

			def dist(ctx):
				ctx.base_name = 'files'

		:rtype: string
		Znonamez1.0ú-)Z	base_namer–   Úgetattrr   r^   ZAPPNAMEÚVERSION)r‹   ZappnamerI   rZ   rZ   r[   rŸ   Î  s    

zDist.get_base_namec          	   C   s`   y| j S  tk
rZ   tjd | _ tjrT| j tj¡}|rT|  j d| | j	¡ 7  _ | j S X dS )zÞ
		Returns the patterns to exclude for finding the files in the top-level directory.
		Set the attribute *excl* to change the default value::

			def dist(ctx):
				ctx.excl = 'build **/*.o **/*.class'

		:rtype: string
		zy **/waf-2.* **/.waf-2.* **/waf3-2.* **/.waf3-2.* **/*~ **/*.rej **/*.orig **/*.pyc **/*.pyo **/*.bak **/*.swp **/.lock-w*ú N)
Úexclr–   r   Zexclude_regsr   r*   r}   Z	find_noder    r•   )r‹   ZndrZ   rZ   r[   Úget_exclà  s    
zDist.get_exclc             C   s8   y
| j }W n( tk
r2   | jjd|  ¡ d�}Y nX |S )ap  
		Files to package are searched automatically by :py:func:`waflib.Node.Node.ant_glob`.
		Set *files* to prevent this behaviour::

			def dist(ctx):
				ctx.files = ctx.path.find_node('wscript')

		Files are also searched from the directory 'base_path', to change it, set::

			def dist(ctx):
				ctx.base_path = path

		:rtype: list of :py:class:`waflib.Node.Node`
		z**/*)r°   )r   r–   r•   Zant_globr±   )r‹   r   rZ   rZ   r[   r˜   ô  s
    
zDist.get_filesN)r]   Ú
__module__Ú__qualname__Ú__doc__rt   r„   r™   r«   rl   rŠ   r§   rœ   r¨   r”   rŸ   r±   r˜   rZ   rZ   rZ   r[   rˆ   X  s   /
rˆ   c             C   s   dS )z.makes a tarball for redistributing the sourcesNrZ   )rK   rZ   rZ   r[   rh   	  s    rh   c               @   s0   e Zd ZdZdZdZdd„ Zdd„ Zdd„ Zd	S )
Ú	DistCheckz4creates an archive with dist, then tries to build itrj   c             C   s,   |   tj tjj¡g¡ |  ¡  |  ¡  dS )z3
		See :py:func:`waflib.Context.Context.execute`
		N)	r‰   r   r   r#   r   r^   rg   rŠ   Úcheck)r‹   rZ   rZ   r[   rl     s    zDistCheck.executec             C   sR   g }t jjrt t jj¡}ndd„ tjD ƒ}tjtjd ddddd| g| }|S )	Nc             S   s   g | ]}|  d ¡r|‘qS )r¬   )r,   )Ú.0rR   rZ   rZ   r[   ú
<listcomp>  s    z0DistCheck.make_distcheck_cmd.<locals>.<listcomp>r   r   r   ZinstallZ	uninstallz
--destdir=)r   r   Zdistcheck_argsÚshlexr‡   r   r   Ú
executable)r‹   ZtmpdirZcfgrt   rZ   rZ   r[   Úmake_distcheck_cmd  s    "zDistCheck.make_distcheck_cmdc          	   C   s²   ddl }ddl}| |  ¡ ¡�}x|D ]}| |¡ q&W W dQ R X | d|  ¡ ¡}|  |¡}tj	j
||  ¡ d� ¡ }|r†t d| ¡‚tj |¡r t d| ¡‚t |  ¡ ¡ dS )zI
		Creates the archive, uncompresses it and tries to build the project
		r   Nz.inst)Úcwdzdistcheck failed with code %rz.distcheck succeeded, but files were left in %s)Útempfiler“   rš   r”   ÚextractZmkdtemprŸ   r»   r   Ú
subprocessÚPopenÚwaitr	   r;   r   r   r5   r{   r|   )r‹   r½   r“   ÚtrR   Zinstdirrt   ZretrZ   rZ   r[   r¶   #  s    

zDistCheck.checkN)	r]   r²   r³   r´   r„   rt   rl   r»   r¶   rZ   rZ   rZ   r[   rµ     s   	rµ   c             C   s   dS )z4checks if the project compiles (tarball from 'dist')NrZ   )rK   rZ   rZ   r[   rj   9  s    rj   c                s   ‡ fdd„}|S )zI
	Decorator that enables context commands to run *configure* as needed.
	c          	      sB  t jsˆ | ƒS t ¡ }d}y| tj tjt	j
¡¡ W n" tk
rX   t d¡ d}Y nhX |jtjkrld}nTd}xN|jD ]:}yt |t |d¡f¡}W qx tk
r°   d}P Y qxX qxW ||jk}|�r6|jpÎd}t jdk�r"t	jj}tj}|jrú|jt	j_|jt_zt|ƒ W d|t	j_|t_X nt|ƒ t| jƒ nˆ | ƒS dS )	zJ
		Wraps :py:func:`waflib.Context.Context.execute` on the context class
		FzConfiguring the projectTr   r‘   r   ZclobberN)r   Z
autoconfigr   r0   r   r   r   r   r(   r   r/   r3   r   r4   r   r   r   Zh_listZreadfÚhashZ
config_cmdr   r_   r   rv   rt   )r‹   rM   Z	do_configÚhr€   rt   ÚtmpZlaunch_dir_tmp)Úexecute_methodrZ   r[   rl   A  sD    





zautoconfigure.<locals>.executerZ   )rÆ   rl   rZ   )rÆ   r[   Úautoconfigure=  s    .rÇ   )%r´   Z
__future__r   r   r¹   r{   r>   rƒ   r   r1   Úwaflibr   r   r   r   r   r   r	   r
   r   Zbuild_dir_overrider+   rn   r\   r:   rr   rv   rB   r‚   ri   rˆ   rh   rµ   rj   rÇ   ZBuildContextrl   rZ   rZ   rZ   r[   Ú<module>   s*   8, %6 2,3