3
^Ã_^Œ@  ã               @   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 jƒ  tj|kr.t jd|tj|ƒ tjdƒ |t_|  t_t_	| }t
jjdƒ}ttjƒdkrÀt
jj| tjd ƒ}t
jj|ƒtjkrÀt
jj|ƒrÀt
jjt
jj|ƒƒ}t
jj|ƒ}d}tjjdƒ tjdƒ}|jdd�\}}	}
|jrø|j } t_t_d}|j�r|jt_|�s@x0tD ](}x |	D ]}|j|ƒ�rd}P �qW �qW |}�x‚|�rÈyt
j |ƒ}W n& t!k
�r‚   g }t jd|ƒ Y nX t"j#|k�r†t$j$ƒ }
y*|
j%t
jj|t"j#ƒƒ t
j&|ƒ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
j&|ƒt&j' }W n t!k
�r>   Y nX ||k�rìd}P �qìW t j+d|ƒ d	}|�r†|
jt_|
jt_|
jt_P tj�s tj|k�r |t_t
jj|ƒ}||k�r¸P |}|�rHP �qHW t
jjt
jjtjtjƒƒ}t
jj,|ƒ�s0|j-�rt j+d
ƒ |j.j/ƒ  tjdƒ t jdtjƒ tjdƒ yt
j0tjƒ W n. t!k
�rn   t jdtjƒ tjdƒ Y nX yt1|ƒ W n” t2j3k
�rÈ } z,t j4d|j5ƒ t jt6|ƒƒ tjdƒ W Y dd}~X nJ t7k
�r } z,t jdtjƒ t8j9tj:d� tjdƒ W Y dd}~X nX |j;�rXddl<}ddl=}|j>di i dƒ |j?dƒ}|j@dƒjAdƒ �n"yPy
tBƒ  W n@   |jC�ržddlC}tjDƒ \}}}t8j9ƒ  |jE|ƒ n‚ Y nX W nÐ t2j3k
�rþ } z6t jFdk�rØt j4d|j5ƒ t j|jGƒ tjdƒ W Y dd}~X n| tHk
�r   ‚ Y nf t7k
�rN } zt8j9tj:d� tjdƒ W Y dd}~X n, tIk
�rx   t j4ddƒ tj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	   ÚWafErrorÚ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ÚerA   rB   ÚprD   ÚtypeÚvalueÚtb© r[   ú;/home/yuhw/wc/wct-package/waf-tools/waf/waflib/Scripting.pyÚwaf_entry_point   sö    














r]   c             C   s~   t j| ƒ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Ú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   )Z	file_pathrd   rO   r[   r[   r\   r:   ¶   s    	

r:   c              C   s\   t jdƒ} | jƒ  tjs<tttƒr0tjjtƒ ntjj	tƒ tj
jrX| jjƒ  tj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   r6   r7   r8   r   r   )rL   r[   r[   r\   Úparse_optionsÓ   s    


rr   c          
   C   s>   t j| ƒ}tjƒ |_tj|_| |_z|jƒ  W d|j	ƒ  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   Úfinalize)Úcmd_namerL   r[   r[   r\   Úrun_commandã   s    


rw   c              C   sJ   t ƒ  tdƒ x.tjr<tjjdƒ} t| ƒ}tj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`.
	re   r   z%r finished successfully (%s)rf   N)rr   rw   r   rM   r%   r   Úinfors   )rv   rL   r[   r[   r\   rC   õ   s    rC   c             C   sÒ   xnt j| ƒD ]`\}}}xT|D ]L}|jdƒrt jj||ƒ}yt j|ƒ W q tk
rf   tjd|ƒ Y qX qW qW x6t	j
dfD ](}yt j|ƒ W q| tk
r¢   Y q|X q|W ytj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
	ú.oú.mocú.exezCould not remove %rz
config.logN)ry   rz   r{   )r   ÚwalkÚendswithr   r   Úremover.   r   r4   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sJx:tjdƒD ],}x&djƒ D ]}|j|ƒr(||tjƒ q(W qW d}| jj	r^| jj
}ytj|ƒ}W n  tk
rŒ   tjd|ƒ dS X t j|k�r„tjj|t jƒ}ytj|ƒ}W n  tk
rØ   tjd|ƒ dS X |j sì|j � rütjd|ƒ dS |j|jk�rt|jƒ n||jtjƒ |jg}| jj	�sB|j|jƒ | jj�sX|j|jƒ x*|D ]"}tjj|t jƒ}	||	tjƒ �q^W dS )zremoves build folders and datac             S   sL   y|| ƒ W n: t k
rF } z|jtjkr6tjd| ƒ W Y d d }~X nX d S )NzCould not remove %r)r3   ÚerrnoÚENOENTr   r4   )rO   ÚfunrV   r[   r[   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   rM   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   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$   | j tjjtjjƒgƒ | jƒ  dS )z3
		See :py:func:`waflib.Context.Context.execute`
		N)Úrecurser   r   r#   r   r_   rh   Úarchive)Úselfr[   r[   r\   rl   _  s    zDist.executec             C   sŒ  ddl }| jƒ }y
| j W n tk
r6   | j| _Y nX | jj|ƒ}y|jƒ  W n tk
rd   Y nX | jƒ }| j	j
dƒr¼|j|jƒ d| j	jddƒ ƒ}x|D ]}| j||ƒ qžW |jƒ  nx| j	dk�r*ddl}|j|jƒ d|jd�}x8|D ]0}| jƒ d	 |j| jƒ }	|j|jƒ |	|jƒ qìW |jƒ  n
| jd
ƒ yddlm}
 W n tk
�r^   d}Y nX d|
|jdd�ƒjƒ  }tj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   rx   Ú	arch_name)r�   r˜   r©   Únoderƒ   ÚtarrS   r£   r’   Zarchive_namer•   Zdigestr[   r[   r\   r�   f  s>    






zDist.archivec             C   s   |j ƒ 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 |ƒ}|j|| jƒ d |j| jƒ d�}d|_d|_d|_d|_t	j
j|ƒrvt|dƒ�}|j||d� W dQ R X n
|j|ƒ 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$   y| j S  tk
r   | jƒ 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   y
| j  W n4 tk
r>   | jƒ d | j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   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appnamerJ   r[   r[   r\   r¤   Î  s    

zDist.get_base_namec             C   s`   y| j S  tk
rZ   tjd | _ tjrT| jjtjƒ}|rT|  j d|j| 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ndr[   r[   r\   Úget_exclà  s    
zDist.get_exclc             C   s8   y
| j }W n( tk
r2   | jjd| jƒ 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__rt   r‰   rž   r°   rl   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[   )rL   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,   | j tjjtjjƒgƒ | jƒ  | jƒ  dS )z3
		See :py:func:`waflib.Context.Context.execute`
		N)	rŽ   r   r   r#   r   r_   rh   r�   Úcheck)r�   r[   r[   r\   rl     s    zDistCheck.executec             C   sR   g }t jjrtj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 | ]}|j 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cfgrt   r[   r[   r\   Úmake_distcheck_cmd  s    "zDistCheck.make_distcheck_cmdc             C   s²   ddl }ddl}|j| jƒ ƒ�}x|D ]}|j|ƒ q&W W dQ R X |jd| jƒ ƒ}| j|ƒ}tj	j
|| jƒ d�jƒ }|r†tjd| ƒ‚tjj|ƒr tjd| ƒ‚tj| jƒ ƒ 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˜   ÚtrS   Zinstdirrt   Zretr[   r[   r\   r»   #  s    

zDistCheck.checkN)	r^   r·   r¸   r¹   r‰   rt   rl   rÀ   r»   r[   r[   r[   r\   rº     s   	rº   c             C   s   dS )z4checks if the project compiles (tarball from 'dist')Nr[   )rL   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jƒ }d}y|jtjjtjt	j
ƒƒ W n" tk
rX   tjdƒ d}Y nhX |jtjkrld}nTd}xN|jD ]:}ytj|tj|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   rw   rt   )r�   rN   Z	do_configÚhr„   rt   ÚtmpZlaunch_dir_tmp)Úexecute_methodr[   r\   rl   A  sD    





zautoconfigure.<locals>.executer[   )rË   rl   r[   )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   rw   rC   r†   rj   r�   ri   rº   rk   rÌ   ZBuildContextrl   r[   r[   r[   r\   Ú<module>   s*   8, %6 2,3