U
    HZûaü@  ã                   @   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<tD ](}|	D ]}| |¡�rd} �q�q�q|}|�rÊzt
  |¡}W n& t!k
�rz   g }t  d|¡ Y nX t"j#|k�r„t$ $¡ }
z*|
 %t
j |t"j#¡¡ t
 &|¡t&j' }W n t(k
�rÐ   Y n´X |
j|
j|
jfD ]n}|�sð�qât)j*�r||k�rNd} �qbn@zt
 &|¡t&j' }W n t!k
�r8   Y nX ||k�râd} �qb�qât  +d|¡ d	}|�r„|
jt_|
jt_|
jt_�qÊtj�sžtj|k�rž|t_t
j |¡}||k�r¸�qÊ|}|�r@�qÊ�q@t
j t
j tjtj¡¡}t
j ,|¡�s0|j-�rt  +d
¡ |j. /¡  t d¡ t  dtj¡ t d¡ zt
 0tj¡ W n. t!k
�rn   t  dtj¡ t d¡ Y nX zt1|ƒ W n” t2j3k
�rÈ } z*t  4d|j5¡ t  t6|ƒ¡ t d¡ W 5 d}~X Y nJ t7k
�r } z*t  dtj¡ t8j9tj:d� t d¡ W 5 d}~X Y nX |j;�rXddl<}ddl=}| >di i d¡ | ?d¡}| @d¡ Ad¡ �n"zPz
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 5 d}~X Y n| tHk
�r   ‚ Y nf t7k
�rN } zt8j9tj:d� t d¡ W 5 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.txtÚ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Úxr1   Úino2ÚnextZwscriptÚerA   rB   ÚprD   ÚtypeÚvalueÚtb© r[   ú+/wcdo/src/waf-tools/waf/waflib/Scripting.pyÚwaf_entry_point   sö    












r]   c                 C   sz   t  | ¡t _| t j_dd„ }tttfD ]}||ƒ q&dt jjkrJtj	t j_
dt jjkr`tj	t j_dt jjkrvt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Únamer[   r[   r\   Úset_defÅ   s    z set_main_module.<locals>.set_defÚinitÚshutdownr   N)r   Úload_moduler_   Ú	root_pathÚdistÚ	distcleanÚ	distcheckr`   r   Znadare   rf   r   )Ú	file_pathrd   rO   r[   r[   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   rM   Ú
isinstanceÚdefault_cmdÚlistÚextendÚappendr   r7   r8   r9   r   r   ©rL   r[   r[   r\   Úparse_optionsÓ   s    


rt   c                 C   s>   t  | ¡}t ¡ |_tj|_| |_z| 	¡  W 5 | ¡  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
	)
r   r'   r   ZTimerÚ	log_timerr   r   ÚcmdZfinalizerm   ©Zcmd_namerL   r[   r[   r\   Úrun_commandã   s    


rx   c                  C   sF   t ƒ  tdƒ tjr:tj d¡} t| ƒ}t d| |j¡ q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`.
	re   r   z%r finished successfully (%s)rf   N)rt   rx   r   rM   r&   r   Úinforu   rw   r[   r[   r\   rC   õ   s    rC   c              
   C   sÆ   t  | ¡D ]\\}}}|D ]L}| d¡rt j ||¡}zt  |¡ W q tk
rb   t d|¡ Y qX qq
t	j
dfD ](}zt  |¡ W qr tk
r˜   Y qrX qrz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.exeúCould not remove %rz
config.logN)r   ÚwalkÚendswithr   r    Úremover/   r   r5   r   ZDBFILEÚshutilÚrmtreer
   Z	CACHE_DIR)r$   ÚrootÚdirsÚfilesÚfÚfnamerS   r[   r[   r\   Údistclean_dir  s"    	
r…   c           
      C   s¤  dd„ }t jsBt d¡D ](}d ¡ D ]}| |¡r$||tjƒ q$qd}tj 	d¡sZ| j
jrb| j
j}zt |¡}W n" tk
r’   t d|¡ Y dS X t j|k�r tj |t j¡}zt |¡}W n" tk
rà   t d|¡ Y dS X |jrð|j�s t d|¡ dS |j|jk�rt|jƒ n||jtjƒ |jg}tj 	d¡�sT| j
j�sT| |j¡ tj 	d	¡�sx| j
j�sx| |j¡ |D ]"}tj |t j¡}	||	tjƒ �q|dS )
zremoves build folders and datac              
   S   sL   z|| ƒ W n: t k
rF } z|jtjkr6t d| ¡ W 5 d }~X Y nX d S )Nrz   )r4   ÚerrnoZENOENTr   r5   )rO   ÚfunrV   r[   r[   r\   Úremove_and_log%  s
    z!distclean.<locals>.remove_and_logÚ.z.waf-2 waf-2 .waf3-2 waf3-2ZNO_LOCK_IN_TOPzCould not read %rNzInvalid lock file %rZNO_LOCK_IN_RUN)r   rM   r   r.   Úsplitr-   r~   r   r   r   r   Zno_lock_in_topr*   r/   r   r5   r0   r   r    r   r4   r+   r)   r…   rr   Zno_lock_in_runr   r}   )
rL   rˆ   rO   rS   rQ   rR   rƒ   rN   Zenv_dirsrW   r[   r[   r\   rj   "  sF    
rj   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 coderi   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_   rh   Úarchive©Úselfr[   r[   r\   rm   _  s    zDist.executec                 C   s„  ddl }|  ¡ }z
| j W n tk
r6   | j| _Y nX | j |¡}z| ¡  W n tk
rd   Y nX |  ¡ }| j	 
d¡r¸| | ¡ d| j	 dd¡ ¡}|D ]}|  ||¡ qœ| ¡  nt| j	dk�r"ddl}|j| ¡ d|jd�}|D ]0}|  ¡ d	 | | j¡ }	| | ¡ |	|j¡ qæ| ¡  n
|  d
¡ zddlm}
 W n tk
�rV   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   ry   Ú	arch_name)r�   r˜   r©   Únoder‚   ÚtarrS   r£   r’   Zarchive_namer•   Zdigestr[   r[   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ª   r[   r[   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 5 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”   )rc   Zarcnamer   r€   r–   )ZfileobjN)r¬   Z
gettarinfoÚget_tar_prefixr¥   rš   ZuidÚgidÚunameZgnamer   r   r"   rŸ   Zaddfile)r�   rS   r«   rW   Ztinforƒ   r[   r[   r\   r¡   Ÿ  s    
"zDist.add_tar_filec                 C   s*   z| j W S  tk
r$   |  ¡  Y 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�   r[   r[   r\   r­   ³  s    zDist.get_tar_prefixc                 C   sF   z
| 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�   r[   r[   r\   r™   ¾  s
    

&zDist.get_arch_namec                 C   sT   z
| 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appnamerJ   r[   r[   r\   r¤   Î  s    

zDist.get_base_namec              	   C   sf   z| j W S  tk
r`   tjd | _ tjrV| j tj¡}|rV|  j d| | j	¡ 7  _ | j  Y 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ndr[   r[   r\   Úget_exclà  s    
zDist.get_exclc                 C   s8   z
| 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‚   r[   r[   r\   r�   ô  s
    
zDist.get_filesN)r^   Ú
__module__Ú__qualname__Ú__doc__rv   r‡   rž   r°   rm   rŽ   r¬   r¡   r­   r™   r¤   r¶   r�   r[   r[   r[   r\   r‹   X  s   /
r‹   c                 C   s   dS )z.makes a tarball for redistributing the sourcesNr[   rs   r[   r[   r\   ri   	  s    ri   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 itrk   c                 C   s,   |   tj tjj¡g¡ |  ¡  |  ¡  dS rŒ   )	r�   r   r   r$   r   r_   rh   rŽ   Úcheckr�   r[   r[   r\   rm     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-   )Ú.0rS   r[   r[   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cfgrv   r[   r[   r\   Úmake_distcheck_cmd  s    "zDistCheck.make_distcheck_cmdc              	   C   s®   ddl }ddl}| |  ¡ ¡�}|D ]}| |¡ q$W 5 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   r6   r~   r   )r�   rÂ   r˜   ÚtrS   Zinstdirrv   Zretr[   r[   r\   r»   #  s    
zDistCheck.checkN)	r^   r·   r¸   r¹   r‡   rv   rm   rÀ   r»   r[   r[   r[   r\   rº     s   	rº   c                 C   s   dS )z4checks if the project compiles (tarball from 'dist')Nr[   rs   r[   r[   r\   rk   9  s    rk   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}z| tj tjt	j
¡¡ W n" tk
rX   t d¡ d}Y nhX |jtjkrld}nTd}|jD ]>}zt |t |d¡f¡}W qv tk
r²   d}Y  qÀY qvX qv||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 5 |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   r1   r   r   r    r   r)   r   r0   r4   r   r5   r   r‚   r   Zh_listZreadfÚhashZ
config_cmdr   r`   r   rx   rv   )r�   rN   Z	do_configÚhrƒ   rv   ÚtmpZlaunch_dir_tmp©Úexecute_methodr[   r\   rm   A  sD    






zautoconfigure.<locals>.executer[   )rÌ   rm   r[   rË   r\   Úautoconfigure=  s    .rÍ   )%r¹   Z
__future__r   r   r¾   r~   r?   r†   r   r2   Úwaflibr   r   r   r   r   r   r	   r
   r   Zbuild_dir_overrider,   ro   r]   r;   rt   rx   rC   r…   rj   r‹   ri   rº   rk   rÍ   ZBuildContextrm   r[   r[   r[   r\   Ú<module>   s*   8, %6 2,3