a
    $ac                     @   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
Z
ddlZddlZddlZddlZzddlZW n ey   ddlZY n0 ejdkrejd dk rzddlZW q ey   ddlZY q0 nddlZz
ejZW n$ ey   G dd deZY n0 ddlmZmZ zddlZW n: eyh   zddlZW n eyb   dZY n0 Y n0 dd	lmZ zdd
l m!Z! W n: ey   zddl m"Z! W n ey   Y n0 Y n20 ze! #  W n  e$y   ddl m"Z! Y n0 zddl%Z%W nV eyT   dej&vr$dej&d< G dd de'Z%G dd de'Z(e( e%_(e%_)Y n0 d* Z+dZ,dZ-g dZ.dZ/G dd de0Z1G dd de'Z2G dd de'Z3G dd de'Z4ej5dkpej
dkpejd kZ6dd#d$Z7dd&d'Z8d(d) Z9dd*d+Z:dd,d-Z;d.d/ Z<e7Z=e8Z>e9Z?e@ed0r<ejAd1k r<e:Z7e;Z8e<Z9zd2*d3ZBW n$ eCyn   ddlDZDd4d5 ZEY n
0 d6d5 ZEd7eE_ d8d9 ZFejGZGe6reFZGd:d; ZHd<d= ZId>d? ZJd@dA ZKdBdC ZLeMdDZNdEdF ZOdaPdGdH ZQej
dIkreLZRn2e6rej&SdJrejTUdKreQZRneOZRneKZRdLeR_ dMdN ZVddOdPZWdQdR ZXdSdT ZYeMdUZZdVdW Z[dXdY Z\ejAdZk rd[d\ Z]e\j e]_ e]Z\d]d^ Z^d_d` Z_eMdaZ`dbdc Zaddde Zbdfdg Zcdhdi ZdG djdk dke'Zedldm Zfdndo Zgdpdq Zhdrds Zidtdu Zjg Zkdvdw aldxdy Zmdd{d|Zni fd}d~Zoi fddapdddaqdd ZrejAdk rNe6rZejAdkrdeser ej&Sdsej
dksejTseoaped alaqdS )z
Utilities and platform-specific fixes

The portability fixes try to provide a consistent behavior of the Waf API
through Python versions 2.5 to 3.X and across different platforms (win32, linux, etc)
    )with_statementNposix   c                   @   s   e Zd ZdS )TimeoutExpiredN)__name__
__module____qualname__ r	   r	   g/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/third_party/waf/waflib/Utils.pyr   !   s   r   )dequedefaultdict)Errors)md5)sha1ZJOBS1c                   @   s   e Zd ZdZdS )	threadingzm
		A fake threading class for platforms lacking the threading module.
		Use ``waf -j1`` on those platforms
		N)r   r   r   __doc__r	   r	   r	   r
   r   F   s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )LockzFake Lock classc                 C   s   d S Nr	   selfr	   r	   r
   acquireN   s    zLock.acquirec                 C   s   d S r   r	   r   r	   r	   r
   releaseP   s    zLock.releaseN)r   r   r   r   r   r   r	   r	   r	   r
   r   L   s   r   ZSIG_NIL_SIG_NIL_i  i  )\|/-c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )ordered_iter_dictzUOrdered dictionary that provides iteration from the most recently inserted keys firstc                 O   s$   t  | _tj| g|R i | d S r   )r   lstdict__init__)r   kkwr	   r	   r
   r    e   s    zordered_iter_dict.__init__c                 C   s   t |  t | _d S r   )r   clearr   r   r   r	   r	   r
   r#   h   s    
zordered_iter_dict.clearc                 C   s8   |t | v r| j| t | || | j| d S r   )r   keysr   remove__setitem__append)r   keyvaluer	   r	   r
   r&   k   s    zordered_iter_dict.__setitem__c                 C   s4   t | | z| j| W n ty.   Y n0 d S r   )r   __delitem__r   r%   
ValueError)r   r(   r	   r	   r
   r*   p   s
    zordered_iter_dict.__delitem__c                 C   s
   t | jS r   reversedr   r   r	   r	   r
   __iter__v   s    zordered_iter_dict.__iter__c                 C   s
   t | jS r   r,   r   r	   r	   r
   r$   x   s    zordered_iter_dict.keysN)
r   r   r   r   r    r#   r&   r*   r.   r$   r	   r	   r	   r
   r   c   s   r   c                   @   s   e Zd ZdZdZdd ZdS )lru_nodez.
	Used by :py:class:`waflib.Utils.lru_cache`
	nextprevr(   valc                 C   s   | | _ | | _d | _d | _d S r   r0   r   r	   r	   r
   r       s    zlru_node.__init__N)r   r   r   r   	__slots__r    r	   r	   r	   r
   r/   {   s   r/   c                   @   s.   e Zd ZdZdZdddZdd Zdd	 Zd
S )	lru_cachez;
	A simple least-recently used cache with lazy allocation
	)maxlentableheadd   c                 C   s,   || _ i | _t | _| j| j_| j| j_d S r   )r6   r7   r/   r8   r1   r2   )r   r6   r	   r	   r
   r       s
    
zlru_cache.__init__c                 C   s\   | j | }|| ju r|jS |j|j_|j|j_| jj|_| j|_| | _ |j_|j_|jS r   )r7   r8   r3   r1   r2   )r   r(   noder	   r	   r
   __getitem__   s    




zlru_cache.__getitem__c                 C   s   || j v r&| j | }||_| | nt| j | jk r`t }| j|_| jj|_| |j_|j_n0| jj }| _z| j |j	= W n t
y   Y n0 ||_	||_|| j |< d S r   )r7   r3   r;   lenr6   r/   r8   r2   r1   r(   KeyError)r   r(   r3   r:   r	   r	   r
   r&      s"    


zlru_cache.__setitem__N)r9   )r   r   r   r   r4   r    r;   r&   r	   r	   r	   r
   r5      s
   
r5   c                   @   s(   e Zd Zdd Zdd Zdd ZeZdS )lazy_generatorc                 C   s   || _ || _d S r   )funparams)r   r?   r@   r	   r	   r
   r       s    zlazy_generator.__init__c                 C   s   | S r   r	   r   r	   r	   r
   r.      s    zlazy_generator.__iter__c                 C   s8   z
| j }W n$ ty.   | j| j  }| _ Y n0 t|S r   )itAttributeErrorr?   r@   r1   )r   rA   r	   r	   r
   __next__   s
    
zlazy_generator.__next__N)r   r   r   r    r.   rC   r1   r	   r	   r	   r
   r>      s   r>   r   win32ntrlatin-1c                 C   s   t jdkrfd|vrf|d7 }t| |}| }W d   n1 sB0    Y  |r\||}q| }n2t| |}| }W d   n1 s0    Y  |S )a  
	Reads an entire file into a string. See also :py:meth:`waflib.Node.Node.readf`::

		def build(ctx):
			from waflib import Utils
			txt = Utils.readf(self.path.find_node('wscript').abspath())
			txt = ctx.path.find_node('wscript').read()

	:type  fname: string
	:param fname: Path to file
	:type  m: string
	:param m: Open mode
	:type encoding: string
	:param encoding: encoding value, only used for python 3
	:rtype: string
	:return: Content of the file
	   bN)sys
hexversionopenreaddecode)fnamemencodingftxtr	   r	   r
   readf   s    &
&rT   wc                 C   s\   t jdkr$d|vr$||}|d7 }t| |}|| W d   n1 sN0    Y  dS )a  
	Writes an entire file from a string.
	See also :py:meth:`waflib.Node.Node.writef`::

		def build(ctx):
			from waflib import Utils
			txt = Utils.writef(self.path.make_node('i_like_kittens').abspath(), 'some data')
			self.path.make_node('i_like_kittens').write('some data')

	:type  fname: string
	:param fname: Path to file
	:type   data: string
	:param  data: The contents to write to the file
	:type  m: string
	:param m: Open mode
	:type encoding: string
	:param encoding: encoding value, only used for python 3
	rH   rI   N)rJ   rK   encoderL   write)rO   datarP   rQ   rR   r	   r	   r
   writef   s
    
rY   c                 C   sR   t  }t| d*}| r,|d} ||  qW d   n1 s@0    Y  | S )z
	Computes a hash value for a file by using md5. Use the md5_tstamp
	extension to get faster build hashes if necessary.

	:type fname: string
	:param fname: path to the file to hash
	:return: hash of the file contents
	:rtype: string or bytes
	rb@ N)r   rL   rM   updatedigest)rO   rP   rR   r	   r	   r
   h_file  s    

*r^   c                 C   s   t jt jB }d|v r|t jO }d|v r0|t jO }zt | |}W n ty^   td|  Y n0 tj	dkrd|vr|d7 }t 
||} |  }W d    n1 s0    Y  |r||}q| }n4t 
||} |  }W d    n1 s0    Y  |S )NrI   +Cannot read from %rrH   )osO_NOINHERITO_RDONLYO_BINARYO_RDWRrL   OSErrorIOErrorrJ   rK   fdopenrM   rN   )rR   rP   rQ   flagsfdrS   r	   r	   r
   readf_win32"  s&    

&
&rk   c                 C   s   t jdkr$d|vr$||}|d7 }tjtjB tjB tjB }d|v rN|tjO }d|v r`|tj	O }zt
| |}W n ty   td|  Y n0 t||} | | W d    n1 s0    Y  d S )NrH   rI   r_   zCannot write to %r)rJ   rK   rV   ra   O_CREATO_TRUNCO_WRONLYrb   rd   re   rL   rf   rh   rW   )rR   rX   rP   rQ   ri   rj   r	   r	   r
   writef_win32:  s    


ro   c                 C   s   zt | t jt jB t jB }W n ty<   td|  Y n0 t }t |d*}| rl|d} |	|  qRW d    n1 s0    Y  |
 S )Nr`   rZ   r[   )ra   rL   rd   rc   rb   rf   r   rh   rM   r\   r]   )rO   rj   rP   rR   r	   r	   r
   h_file_win32J  s    
*rp   rb   i   hexc                 C   s"   t | }t|ts|d}|S )Nzutf-8)binasciiZhexlify
isinstancestrrN   )sretr	   r	   r
   to_hexd  s    


rx   c                 C   s
   |  dS )Nrr   )rV   )rv   r	   r	   r
   rx   j  s    z`
Return the hexadecimal representation of a string

:param s: string to convert
:type s: string
c                    s   | szddl }W n  ty0   dd dD  Y S 0 d}d}|||  |jj|| | } fddtt|| D S t	| d	kr| d
 dkr| t
j7 } t
j| std|  }tj|_|t
| S )z
	Lists the contents of a folder in a portable manner.
	On Win32, returns the list of drive letters: ['C:', 'X:', 'Z:'] when an empty string is given.

	:type s: string
	:param s: a string, which can be empty on Windows
	r   Nc                 S   s   g | ]}|d  qS )z:\r	   .0xr	   r	   r
   
<listcomp>      z!listdir_win32.<locals>.<listcomp>ZABCDEFGHIJKLMNOPQRSTUVWXYZ      c                    s0   g | ](}t  jd | d | d  dqS )r~      ascii)ru   rawrN   )rz   ibufr	   r
   r|     r}   r      :z%s is not a directory)ctypesImportErrorZcreate_string_bufferwindllkernel32ZGetLogicalDriveStringsAZbyrefrangeintr<   ra   seppathisdirrf   errnoENOENTlistdir)rv   r   ZdlenZ	maxdrivesZndriveser	   r   r
   listdir_win32t  s"    
r   c                 C   sd   t | trt| d} t | tr`d}tdD ],}|t| k r.|dd|  t| |  7 }q.|S | S )a  
	Converts a string, tuple or version number into an integer. The number is supposed to have at most 4 digits::

		from waflib.Utils import num2ver
		num2ver('1.3.2') == num2ver((1,3,2)) == num2ver((1,3,2,0))

	:type ver: string or tuple of numbers
	:param ver: a version number
	.r   r~      r   )rt   ru   tuplesplitr   r<   r   )Zverrw   r   r	   r	   r
   num2ver  s    


r   c                 C   s   t | tr|  S | S dS )a  
	Converts a string argument to a list by splitting it by spaces.
	Returns the object if not a string::

		from waflib.Utils import to_list
		lst = to_list('a b c d')

	:param val: list of string or space-separated string
	:rtype: list
	:return: Argument converted to list
	N)rt   ru   r   )r3   r	   r	   r
   to_list  s    
r   c                  C   sd   zdd l } W n ty   Y n20 z| jj }W n tyB   Y n0 |rPd| S tjjpbt	r`dS dS )Nr   zcp%dcp1252rG   )
r   r   r   r   ZGetConsoleCPrB   rJ   stdoutrQ   is_win32)r   Zcodepager	   r	   r
   console_encoding  s    r   c                 C   s
   |  dS )Nr   )r   r   r	   r	   r
   split_path_unix  s    r   c                 C   s:   |  dr0| ddd  }d|d  |d< |S | dS )N//r   r   r   )
startswithr   r   rw   r	   r	   r
   split_path_cygwin  s
    
r   z[/\\]+c                 C   sR   |  drHt| dd  }d|d  |d< |d dkrD|dd  S |S t| S )N\\r   r   z\\?)r   re_spr   r   r	   r	   r
   split_path_win32  s    
r   c                 C   sZ   |  drR|  dsRts<tg dtjjp0dat at	j
tt	j |  } t| S )N)r   r   )r   r   )Zcygpathz-wr   rG   )r   msysroot
subprocessZcheck_outputrN   rJ   r   rQ   stripra   r   normpathr   r   r   r	   r	   r
   split_path_msys  s    r   cygwinZMSYSTEMr   z
Splits a path by / or \; do not confuse this function with with ``os.path.split``

:type  path: string
:param path: path to split
:return:     list of string
c              
   C   sb   t j| s^zt |  W nB ty\ } z*t j| sHtjd|  |dW Y d}~n
d}~0 0 dS )z
	Ensures that a directory exists (similar to ``mkdir -p``).

	:type  path: string
	:param path: Path to directory
	:raises: :py:class:`waflib.Errors.WafError` if the folder cannot be added.
	zCannot create the folder %r)exN)ra   r   r   makedirsrf   r   WafError)r   r   r	   r	   r
   	check_dir  s    r   c                 C   s   | st ddd }tj| \}}|r<|| r<tj| S |pDtj}|d tjD ]4}|d}tj|| }||rVtj|  S qVdS )a  
	Ensures that a program exists

	:type name: string
	:param name: path to the program
	:param env: configuration object
	:type env: :py:class:`waflib.ConfigSet.ConfigSet`
	:return: path of the program or None
	:raises: :py:class:`waflib.Errors.WafError` if the folder cannot be added.
	zCannot execute an empty string!c                 S   s   t j| ot | t jS r   )ra   r   isfileaccessX_OK)fpathr	   r	   r
   is_exe  s    zcheck_exe.<locals>.is_exePATH"N)	r+   ra   r   r   abspathenvironpathsepr   join)nameenvr   r   rO   r   Zexe_filer	   r	   r
   	check_exe  s    

r   c                 K   s,   |  D ]\}}t| |st| || qdS )z
	Sets default attributes on a class instance

	:type cls: class
	:param cls: the class to update the given attributes in.
	:type kw: dict
	:param kw: dictionary of attributes names and values.
	N)itemshasattrsetattr)clsr"   r!   vr	   r	   r
   	def_attrs)  s    	
r   c                 C   s(   t dd| }t dd|}| }|S )z
	Converts a string into an identifier suitable for C defines.

	:type  s: string
	:param s: String to convert
	:rtype: string
	:return: Identifier suitable for C defines
	z[^a-zA-Z0-9]_z_+)resubupper)rv   Zfur	   r	   r
   quote_define_name6  s    	r   z\s|'|"c                 C   s"   t | tr| S ddd | D S )zF
	Escapes a command:
	['ls', '-l', 'arg space'] -> ls -l 'arg space'
	 c                 s   s$   | ]}t |rt|n|V  qd S r   )re_shsearchreprry   r	   r	   r
   	<genexpr>P  r}   zshell_escape.<locals>.<genexpr>)rt   ru   r   )cmdr	   r	   r
   shell_escapeI  s    
r   c                 C   s   t t|   S )z
	Hashes lists of ordered data.

	Using hash(tup) for tuples would be much more efficient,
	but Python now enforces hash randomization

	:param lst: list to hash
	:type lst: list of strings
	:return: hash of the list
	)r   r   rV   r]   r   r	   r	   r
   h_listR  s    r   rH   c                 C   s   t t|  S r   )r   r   r]   r   r	   r	   r
   h_list_python2`  s    r   c                 C   s   z| j W S  ty   t| tjrdt| j}|t| j	
  |t| j t|| _ | j  Y S zt| }W n ty   d}Y n0 z
|| _ W n ty   Y n0 | Y S 0 dS )z
	Hash functions

	:param fun: function to hash
	:type  fun: function
	:return: hash of the function
	:rtype: string or bytes
	ZnocodeN)coderB   rt   	functoolspartiallistargsextendsortedkeywordsr   r'   h_funfuncr   inspect	getsourceEnvironmentError)r?   r   hr	   r	   r
   r   e  s$    	




r   c                 C   s^   t | tr| }n4t | ts$t | tr8tdd | D }ntt| }tjdkrZ|dd}|S )z
	Hashes objects recursively

	:param ins: input object
	:type ins: string or list or tuple or function
	:rtype: string or bytes
	c                 S   s   g | ]}t |qS r	   )h_cmdry   r	   r	   r
   r|     r}   zh_cmd.<locals>.<listcomp>rH   rG   xmlcharrefreplace)rt   ru   r   r   r   rJ   rK   rV   )insrw   r	   r	   r
   r     s    	

r   z(\\\\)|(\$\$)|\$\{([^}]+)\}c                    s    fdd}t || S )a!  
	Replaces ${VAR} with the value of VAR taken from a dict or a config set::

		from waflib import Utils
		s = Utils.subst_vars('${PREFIX}/bin', env)

	:type  expr: string
	:param expr: String to perform substitution on
	:param params: Dictionary or config set to look up variable values.
	c                    sT   |  drdS |  drdS z |  dW S  tyN    |  d  Y S 0 d S )Nr   r   r   $r   )groupZget_flatrB   )rP   r@   r	   r
   repl_var  s    

zsubst_vars.<locals>.repl_var)	reg_substr   )exprr@   r   r	   r   r
   
subst_vars  s    r   c                 C   s   | dkrdS | dv rdS dS )z
	Returns the binary format based on the unversioned platform name,
	and defaults to ``elf`` if nothing is found.

	:param key: platform name
	:type  key: string
	:return: string representing the binary format
	darwinzmac-o)rD   r   ZuwinZmsyspeelfr	   )r(   r	   r	   r
   destos_to_binfmt  s
    	r   c                  C   s   t j} | drlddlm} |d} | dkr2dS | dr@dS | d	krLd
S | dkrXdS | dv rddS |  } | dkrxdS | dks| d
kr| S | dkrtjdkrdS t	
d| d S )a?  
	Returns the unversioned platform name.
	Some Python platform names contain versions, that depend on
	the build environment, e.g. linux2, freebsd6, etc.
	This returns the name without the version number. Exceptions are
	os2 and win32, which are returned verbatim.

	:rtype: string
	:return: Unversioned platform name
	javar   )Systemzos.namezMac OS Xr   zWindows rD   zOS/2Zos2zHP-UXzhp-ux)ZSunOSZSolarisZsunosZpowerpcclirE   z\d+$)rJ   platformr   Z	java.langr   ZgetPropertylowerra   r   r   r   )rv   r   r	   r	   r
   unversioned_sys_platform  s,    


r   c                  O   s   dS )z 
	Does nothing

	:return: None
	Nr	   )r!   r"   r	   r	   r
   nada  s    r   c                   @   s:   e Zd ZdZdd Zdd Zdd Zeedr6d	d Zd
S )Timerz
	Simple object for timing the execution of commands.
	Its string representation is the duration::

		from waflib.Utils import Timer
		timer = Timer()
		a_few_operations()
		s = str(timer)
	c                 C   s   |   | _d S r   )now
start_timer   r	   r	   r
   r      s    zTimer.__init__c                 C   s   |   | j }t|tjs&tj|d}|j}t|jd\}}t|d\}}||jd 7 }d}|rl|d| 7 }|st|r|d| 7 }|s|s|r|d| 7 }d	||f S )
N)secondsi  <   gư>rq   z%ddz%dhz%dmz%s%.3fs)	r   r   rt   datetimeZ	timedeltadaysdivmodr   Zmicroseconds)r   Zdeltar   ZhoursremZminutesr   resultr	   r	   r
   __str__  s    zTimer.__str__c                 C   s
   t j  S r   )r   Zutcnowr   r	   r	   r
   r     s    z	Timer.nowperf_counterc                 C   s   t  S r   )timer  r   r	   r	   r
   r     s    N)	r   r   r   r   r    r  r   r   r  r	   r	   r	   r
   r     s   	
r   c              	   C   sZ   t d}i }t|  D ]:}z"|| \}}}}|||< W q tyR   Y q0 q|S )zY
	Reads property files, used by msvc.py

	:param path: file to read
	:type path: string
	z^([^=]+)=\'(.*)\'$)r   compilerT   
splitlinesr   r   r+   )r   Zspdcliner   leftrightr	   r	   r
   read_la_file  s    
r  c                    s$   i   fdd} |_ j|_|S )a:  
	Decorator: let a function cache its results, use like this::

		@run_once
		def foo(k):
			return 345*2343

	.. note:: in practice this can cause memory leaks, prefer a :py:class:`waflib.Utils.lru_cache`

	:param fun: function to execute
	:type fun: function
	:return: the return value of the function executed
	c                     s6   z
 |  W S  t y0   |  }| | < | Y S 0 d S r   )r=   )r!   rw   cacher?   r	   r
   wrap:  s    
zrun_once.<locals>.wrap)Z	__cache__r   )r?   r  r	   r  r
   run_once+  s
    r  c                 C   sH   t sdS zt | d|d  }W n ty2   Y n0 tj|rD|S dS )zm
	Returns the value of a registry key for an executable

	:type key: string
	:type filename: list of string
	Nz:Software\Microsoft\Windows\CurrentVersion\App Paths\%s.exer   )winreg
QueryValuerf   ra   r   r   )r(   filenamer  r	   r	   r
   get_registry_app_pathE  s    r  c                   C   s:   t jdkr6t d dkr6t jdr6t jds6dS dS )zj
	Guess the default ``/usr/lib`` extension for 64-bit applications

	:return: '64' or ''
	:rtype: string
	r   r   Z64bitz
/usr/lib64z
/usr/lib32Z64rq   )ra   r   r   Zarchitecturer   existsr	   r	   r	   r
   lib64V  s
    
r  c                 C   s   t jt j| S r   )ra   r   r   
expanduser)pr	   r	   r
   	sane_pathd  s    r  c               
   C   sj   z
t  W S  tyd   tjtjttj d } t	j
dt| g}tj|tjtjdt d Y S 0 dS )zb
	Returns a process object that can execute commands as sub-processes

	:rtype: subprocess.Popen
	zprocessor.pyz-cr   )r   stdinbufsizeZ	close_fdsN)process_poolpop
IndexErrorra   r   dirnamer   __file__r   rJ   
executablerT   r   PopenPIPEr   )filepathr   r	   r	   r
   get_processm  s    
r%  c              	   C   sN  | dsttj|d< ztt| ||g}W n" tt	fyT   t
| || Y S 0 t }|slt
| ||S |j| |jd  |j  |j }|std|j t| tt|}t|dksJ |\}}}}	}
|	rD|	dkr t|
nD|	dkrt|
n0|	dkr<t| |d |d	}||_|nt|
|||fS )
zA
	Delegates process execution to a pre-forked process instance.
	r   
zPreforked sub-process %r died   rf   r+   r   timeoutr(  output)getr   ra   r   base64Z	b64encodecPickledumps	TypeErrorrB   run_regular_processr%  r  rW   rV   flushr   readlinerf   pidr  r'   loadsZ	b64decoder<   r+   r   stderr	Exception)r   kwargscargsobjprocr   rw   outerrr   traceexcr	   r	   r
   run_prefork_processz  s<    








r?  c                 C   sv   t |tr4ddl}||}|s,td| |d }t |trhddl}||}|s`td| |d }t| ||S )z
	Change the owner/group of a path, raises an OSError if the
	ownership change fails.

	:param user: user to change
	:type user: int or str
	:param group: group to change
	:type group: int or str
	r   NzUnknown user %rr   zUnknown group %r)	rt   ru   pwdgetpwnamrf   grpgetgrnamra   lchown)r   userr   rA  entryrC  r	   r	   r
   rE    s    




rE  c           	   
   C   s>  t j| fi |}|ds&|drz|jf i |\}}W nj ty   |drrttdrrt|jt	j
 n|  | \}}t|j|d |d}||_|Y n0 |j}nd\}}z|jf i |}W nd ty2 } zJ|dr
ttdr
t|jt	j
 n|  |  |W Y d}~n
d}~0 0 |||fS )	z;
	Executes a subprocess command by using subprocess.Popen
	r   r5  Zstart_new_sessionkillpgr(  r)  )NNN)r   r"  r+  Zcommunicater   r   ra   rH  r3  signalSIGKILLkillr   r5  
returncodewait)	r   r7  r8  r:  r;  r<  r>  statusr   r	   r	   r
   r0    s.    
r0  c                 C   s0   | dr | dr t| ||S t| ||S dS )z
	Executes a subprocess by using a pre-forked process when possible
	or falling back to subprocess.Popen. See :py:func:`waflib.Utils.run_prefork_process`
	and :py:func:`waflib.Utils.run_regular_process`
	r   r5  N)r+  r?  r0  )r   r7  r8  r	   r	   r
   run_process  s    rO  Fc                 C   sd   |st | tt d} zdd t| D }W n tyJ   tat aa	Y n0 |D ]}t
| qPdS )aL  
	Allocates an amount of processes to the default pool so its size is at least *n*.
	It is useful to call this function early so that the pre-forked
	processes use as little memory as possible.

	:param n: pool size
	:type n: integer
	:param force: if True then *n* more processes are added to the existing pool
	:type force: bool
	r   c                 S   s   g | ]
}t  qS r	   )r%  ry   r	   r	   r
   r|     r}   z&alloc_process_pool.<locals>.<listcomp>N)maxr<   r  r   rf   r0  rO  r   r%  alloc_process_poolr'   )nZforcer   r{   r	   r	   r
   rQ    s    rQ  c               	   C   s<   t D ]2} zt| jd W n ty,   Y q0 |   qd S )N	   )r  ra   rK  r3  rf   rM  )r!   r	   r	   r
   atexit_pool  s    rT  i i ZWAF_NO_PREFORKr   )rF   rG   )rU   rG   )rF   rG   )rU   rG   )N)r@  r@  )F)tr   Z
__future__r   atexitra   rJ   r   r   r   r   r   r,  rI  r   r  r-  r   pickler   version_infoZsubprocess32r   r   rB   r6  collectionsr   r   Z_winregr  waflibr   Zhashlibr   r   r]   r+   r   r   objectr   ThreadrV   SIG_NILO644O755Zrot_chrZrot_idxr   r   r/   r5   r>   r   r   rT   rY   r^   rk   ro   rp   Z
readf_unixZwritef_unixZh_file_unixr   rK   r{   LookupErrorrs   rx   r   r   r   r   r   r   r   r  r   r   r   r   Z
split_pathr+  r!  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r%  r?  rE  r0  rO  rQ  rT  registerr	   r	   r	   r
   <module>   s  `

<"
 



	

	"
'%(

	
"