a
    ”$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   sz  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!yx   g }t  d|¡ Y n0 t"j#|v r~t$ $¡ }
z*|
 %t
j |t"j#¡¡ t
 &|¡t&j' }W n t(yÌ   Y n²0 |
j|
j|
jfD ]l}|sìqÞt)j*r
||krHd} q\n>zt
 &|¡t&j' }W n t!y2   Y n0 ||krÞd} q\qÞt  +d|¡ d	}|r~|
jt_|
jt_|
jt_qÄtjs˜tj|v r˜|t_t
j |¡}||kr²qÄ|}|r@qÄq@t
j t
j tjtj¡¡}t
j ,|¡s*|j-rt  +d
¡ |j. /¡  t d¡ t  dtj¡ t d¡ zt
 0tj¡ W n, t!yf   t  dtj¡ t d¡ Y n0 zt1|ƒ W n˜ t2j3yÂ } z2t  4d|j5¡ t  t6|ƒ¡ t d¡ W Y d}~nTd}~0  t7y } z2t  dtj¡ t8j9tj:d t d¡ W Y d}~n
d}~0 0 |j;rTd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0 W nÐ t2j3yü } z<t jFdkrÒt  4d|j5¡ t  |jG¡ t d¡ W Y d}~n‚d}~0  tHy   ‚ Y nf t7yL } z$t8j9tj:d t d¡ W Y d}~n2d}~0  tIyt   t  4dd¡ t d¡ Y n0 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)é   ÚNOCLIMBTÚoptions)Ú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 unreadableÚ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   Úinit_logr   Ú
WAFVERSIONÚerrorÚsysÚexitÚwaf_dirÚrun_dirÚ
launch_dirÚosÚenvironÚgetÚlenÚargvÚpathÚjoinÚbasenameÚWSCRIPT_FILEÚisfileÚnormpathÚdirnameÚabspathÚpopÚcreate_contextÚparse_cmd_argsÚtopÚtop_dirÚoutÚout_dirÚno_climb_commandsÚ
startswithÚlistdirÚOSErrorr   Úlockfiler   ÚloadÚstatÚST_INOÚEnvironmentErrorr   Úis_win32ÚwarnÚexistsÚwhelpÚparserÚ
print_helpÚchdirÚset_main_moduler	   ÚWafErrorÚpprintÚverbose_msgÚstrÚ	ExceptionÚ	tracebackÚ	print_excÚstdoutÚ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Úxr9   Úino2ÚnextÚwscriptÚerN   rO   ÚprQ   ÚtypeÚvalueÚtb© ri   úk/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/third_party/waf/waflib/Scripting.pyÚwaf_entry_point   sö    










 

rk   c                 C   sz   t  | ¡t _| t j_dd„ }tttfD ]}||ƒ q&dt jjvrJtj	t j_
dt jjvr`tj	t j_dt jjv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vr ttj|| ƒ d S )N)Ú__name__r   Úg_moduleÚ__dict__Úsetattr)ÚobjÚnameri   ri   rj   Úset_defÅ   s    z set_main_module.<locals>.set_defÚinitÚshutdownr   N)r   Úload_modulerm   Ú	root_pathÚdistÚ	distcleanÚ	distcheckrn   r   Únadars   rt   r   )Z	file_pathrr   r\   ri   ri   rj   rD   ¶   s    	


rD   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   rZ   Ú
isinstanceÚdefault_cmdÚlistÚextendÚappendr   r@   rA   rB   r   r   ©rY   ri   ri   rj   Úparse_optionsÓ   s    


r‚   c                 C   sF   t  | ¡}t ¡ |_tj|_| |_z| ¡  W | 	¡  n
| 	¡  0 |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   ÚTimerÚ	log_timerr   r   Úcmdr{   Úfinalize©Úcmd_namerY   ri   ri   rj   Úrun_commandã   s    


r‰   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`.
	rs   r   z%r finished successfully (%s)rt   N)r‚   r‰   r   rZ   r-   r   Úinfor„   r‡   ri   ri   rj   rP   õ   s    rP   c              
   C   sÀ   t  | ¡D ]Z\}}}|D ]J}| d¡rt j ||¡}zt  |¡ W q ty`   t d|¡ Y q0 qq
t	j
dfD ]&}zt  |¡ W qp ty”   Y qp0 qpzt tj¡ W n tyº   Y n0 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&   Úremover7   r   r>   r   ÚDBFILEÚshutilÚrmtreer
   Ú	CACHE_DIR)r+   ÚrootÚdirsÚfilesÚfÚfnamer`   ri   ri   rj   Ú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y   t d|¡ Y dS 0 t j|v rœtj |t j¡}zt |¡}W n  tyÜ   t d|¡ Y dS 0 |jrì|j süt d|¡ dS |j|jkrt|jƒ n||jtjƒ |jg}tj 	d¡sP| j
jsP| |j¡ tj 	d	¡st| j
jst| |j¡ |D ]"}tj |t j¡}	||	tjƒ qxdS )
zremoves build folders and datac              
   S   sN   z|| ƒ W n< t yH } z$|jtjkr4t d| ¡ W Y d }~n
d }~0 0 d S )Nr‹   )r<   ÚerrnoÚENOENTr   r>   )r\   Úfunrd   ri   ri   rj   Úremove_and_log%  s
    z!distclean.<locals>.remove_and_logÚ.z.waf-2 waf-2 .waf3-2 waf3-2ÚNO_LOCK_IN_TOPzCould not read %rNzInvalid lock file %rÚNO_LOCK_IN_RUN)r   rZ   r    r6   Úsplitr5   r   r‘   r!   r"   r   Úno_lock_in_topr2   r7   r   r>   r8   r%   r&   r   r<   r3   r1   r˜   r€   Úno_lock_in_runr   rŽ   )
rY   rœ   r\   r`   r^   r_   r–   r[   Zenv_dirsre   ri   ri   rj   rx   "  sF    
rx   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 coderw   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   rm   rv   Úarchive©Úselfri   ri   rj   r{   _  s    zDist.executec                 C   s~  ddl }|  ¡ }z
| j W n ty4   | j| _Y n0 | j |¡}z| ¡  W n ty`   Y n0 |  ¡ }| 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yP   d}Y n0 d|
|jddƒ ¡  }t d| j|¡ dS )z!
		Creates the source archive.
		r   Nztar.zw:Ú ÚzipÚw)Ú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%   Ú	make_nodeÚdeleter7   Ú	get_filesÚalgor5   Úopenr,   ÚreplaceÚadd_tar_fileÚcloseÚzipfileÚZipFileÚZIP_DEFLATEDÚget_base_nameÚ	path_fromÚwriteÚfatalÚhashlibr®   ÚImportErrorÚreadÚ	hexdigestr   rŠ   Ú	arch_name)r¨   r±   rÈ   Únoder•   Útarr`   r½   rª   Úarchive_namer®   Údigestri   ri   rj   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É   ri   ri   rj   Úget_tar_path•  s    zDist.get_tar_pathc                 C   s˜   |   |¡}|j||  ¡ d | | j¡ d}d|_d|_d|_d|_t	j
 |¡rŠt|dƒ}|j||d W d  ƒ q”1 s~0    Y  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­   )rq   Zarcnamer   r“   r¯   )ÚfileobjN)rÍ   Z
gettarinfoÚget_tar_prefixrÁ   r³   ÚuidÚgidÚunameÚgnamer    r%   r)   r¹   Zaddfile)r¨   r`   rÊ   re   Ztinfor–   ri   ri   rj   r»   Ÿ  s    
".zDist.add_tar_filec                 C   s(   z| j W S  ty"   |  ¡  Y S 0 dS )zW
		Returns the base path for files added into the archive tar file

		:rtype: string
		N)Z
tar_prefixr´   rÀ   r§   ri   ri   rj   rÏ   ³  s    zDist.get_tar_prefixc                 C   sD   z
| j  W n2 ty<   |  ¡ d | j | j| j¡ | _ Y n0 | 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§   ri   ri   rj   r²   ¾  s
    

&zDist.get_arch_namec                 C   sR   z
| j  W n@ tyJ   ttjtjdƒ}ttjtjdƒ}|d | | _ Y n0 | 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ú-)Ú	base_namer´   Úgetattrr   rm   ÚAPPNAMEÚVERSION)r¨   ZappnamerW   ri   ri   rj   rÀ   Î  s    

zDist.get_base_namec              	   C   sd   z| j W S  ty^   tjd | _ tjrT| j tj¡}|rT|  j d| | j	¡ 7  _ | j  Y S 0 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   Úexclude_regsr   r3   r“   Ú	find_noderÁ   r³   )r¨   Zndri   ri   rj   Úget_exclà  s    
zDist.get_exclc                 C   s6   z
| j }W n& ty0   | jjd|  ¡ d}Y n0 |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³   Úant_globrÞ   )r¨   r•   ri   ri   rj   r·   ô  s
    
zDist.get_filesN)rl   Ú
__module__Ú__qualname__Ú__doc__r…   r›   r¸   rÔ   r{   r¦   rÍ   r»   rÏ   r²   rÀ   rÞ   r·   ri   ri   ri   rj   r£   X  s   /
r£   c                 C   s   dS )z.makes a tarball for redistributing the sourcesNri   r   ri   ri   rj   rw   	  s    rw   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 itry   c                 C   s,   |   tj tjj¡g¡ |  ¡  |  ¡  dS r¤   )	r¥   r    r%   r+   r   rm   rv   r¦   Úcheckr§   ri   ri   rj   r{     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Õ   )r5   )Ú.0r`   ri   ri   rj   Ú
<listcomp>  ó    z0DistCheck.make_distcheck_cmd.<locals>.<listcomp>r   r   r   ÚinstallÚ	uninstallz
--destdir=)r   r   Zdistcheck_argsÚshlexr    r   r$   Ú
executable)r¨   ZtmpdirÚcfgr…   ri   ri   rj   Úmake_distcheck_cmd  s    "zDistCheck.make_distcheck_cmdc                 C   sÂ   ddl }ddl}| |  ¡ ¡$}|D ]}| |¡ q$W d  ƒ n1 sH0    Y  | 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²   ÚextractÚmkdtemprÀ   rí   r   Ú
subprocessÚPopenÚwaitr	   rE   r    r%   r?   r   r‘   )r¨   rï   r±   Útr`   Zinstdirr…   Úretri   ri   rj   rä   #  s    *
zDistCheck.checkN)	rl   rà   rá   râ   r›   r…   r{   rí   rä   ri   ri   ri   rj   rã     s   	rã   c                 C   s   dS )z4checks if the project compiles (tarball from 'dist')Nri   r   ri   ri   rj   ry   9  s    ry   c                    s   ‡ fdd„}|S )zI
	Decorator that enables context commands to run *configure* as needed.
	c              	      sL  t jsˆ | ƒS t ¡ }d}z| tj tjt	j
¡¡ W n  tyV   t d¡ d}Y nf0 |jtjkrjd}nRd}|jD ]<}zt |t |d¡f¡}W qt ty®   d}Y  q¼Y qt0 qt||jk}|r@|jpÊd}t jdkr,t	jj}tj}|jrö|jt	j_|jt_zt|ƒ W |t	j_|t_n|t	j_|t_0 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   Ú
autoconfigr   r9   r    r%   r&   r   r1   r   r8   r<   r   r>   r   r•   r   Úh_listÚreadfÚhashÚ
config_cmdr   rn   r   r‰   r…   )r¨   r[   Z	do_configÚhr–   r…   ÚtmpZlaunch_dir_tmp©Úexecute_methodri   rj   r{   A  sH    






ÿ
zautoconfigure.<locals>.executeri   )rÿ   r{   ri   rþ   rj   Úautoconfigure=  s    .r   )%râ   Ú
__future__r   r    rê   r   rJ   r™   r   r:   Úwaflibr   r   r   r   r   r   r	   r
   r   Zbuild_dir_overrider4   r}   rk   rD   r‚   r‰   rP   r˜   rx   r£   rw   rã   ry   r   ÚBuildContextr{   ri   ri   ri   rj   Ú<module>   s*   8, %6 2,3