ó
óÏù]c           @   sg  d  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 d d l	 Z d Z
 d Z d Z d Z d e j e j e f Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z e j ƒ  Z e Z d Z d Z  d Z! g  Z" d „  Z# d e$ f d „  ƒ  YZ% e% d e& f i  ƒ Z' d e' f d „  ƒ  YZ( i  Z) e d „ Z* e e e+ d „ Z, d S(   s3   
Classes and functions enabling the command system
iÿÿÿÿN(   t   Utilst   Errorst   Logsi  s   2.0.11t(   a97f6fb0941091b4966b625f15ec32fa783a8beci   s   .wafpickle-%s-%d-%dt   APPNAMEt   VERSIONt   topt   outt   wscriptt    i   i    c         O   sI   x* t  D]" } | j |  k r | | | Ž  Sq Wt | | Ž  } |  | _ | S(   s¿  
	Returns a new :py:class:`waflib.Context.Context` instance corresponding to the given command.
	Used in particular by :py:func:`waflib.Scripting.run_command`

	:param cmd_name: command name
	:type cmd_name: string
	:param k: arguments to give to the context class initializer
	:type k: list
	:param k: keyword arguments to give to the context class initializer
	:type k: dict
	:return: Context object
	:rtype: :py:class:`waflib.Context.Context`
	(   t   classest   cmdt   Contextt   fun(   t   cmd_namet   kt   kwt   xt   ctx(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   create_contextI   s    	t   store_contextc           B   s   e  Z d  Z d „  Z RS(   s  
	Metaclass that registers command classes into the list :py:const:`waflib.Context.classes`
	Context classes must provide an attribute 'cmd' representing the command name, and a function
	attribute 'fun' representing the function name that the command uses.
	c         C   sœ   t  t |  ƒ j | | | ƒ |  j } | d k r5 d  Sy |  j Wn$ t k
 rf t j d | ƒ ‚ n Xt |  d d  ƒ sˆ |  j |  _
 n  t j d |  ƒ d  S(   NR   R   s.   Missing command for the context class %r (cmd)R   i    (   R   R   (   t   superR   t   __init__t   __name__R   t   AttributeErrorR   t   WafErrort   getattrt   NoneR   R
   t   insert(   t   clst   namet   basest   dct(    (    s$   /git_repos/ams-lv2/waflib/Context.pyR   d   s    	(   R   t
   __module__t   __doc__R   (    (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR   ^   s   R   R   c           B   s¼   e  Z d  Z e Z i  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d e e d d „ Z d „  Z d	 „  Z d
 „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z g  d „ Z RS(   sÒ  
	Default context for waf commands, and base class for new command contexts.

	Context objects are passed to top-level functions::

		def foo(ctx):
			print(ctx.__class__.__name__) # waflib.Context.Context

	Subclasses must define the class attributes 'cmd' and 'fun':

	:param cmd: command to execute as in ``waf cmd``
	:type cmd: string
	:param fun: function name to execute when the command is called
	:type fun: string

	.. inheritance-diagram:: waflib.Context.Context waflib.Build.BuildContext waflib.Build.InstallContext waflib.Build.UninstallContext waflib.Build.StepContext waflib.Build.ListContext waflib.Configure.ConfigurationContext waflib.Scripting.Dist waflib.Scripting.DistCheck waflib.Build.CleanContext

	c         K   sÌ   y | d } Wn t  k
 r' t } n Xt d t j j f i  ƒ |  _ d |  j _ |  |  j _ |  j d d  ƒ |  _	 d  |  _
 |  j	 j | ƒ |  _ g  |  _ i |  d 6|  d 6|  d 6|  d 6|  _ d  |  _ d  S(	   Nt   run_dirt   Nod3s   waflib.NodeR	   R   t   conft   bldt   opt(   t   KeyErrorR#   t   typet   waflibt   Nodet
   node_classR!   R   R   t   roott
   cur_scriptt   find_dirt   patht
   stack_patht	   exec_dictt   logger(   t   selfR   t   rd(    (    s$   /git_repos/ams-lv2/waflib/Context.pyR   –   s    
		%c         C   s?   y |  j  } Wn t k
 r  n Xt j | ƒ t |  d ƒ d S(   s3   
		Called to free resources such as logger files
		R3   N(   R3   R   R   t   free_loggert   delattr(   R4   R3   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   finalize©   s    c   
      O   sš   t  j | ƒ } t  j | j d d ƒ ƒ } | j d t ƒ } xW | D]O } t | | d | ƒ} t | | j d |  j ƒ d ƒ }	 |	 rC |	 |  ƒ qC qC Wd S(   s+  
		Loads a Waf tool as a module, and try calling the function named :py:const:`waflib.Context.Context.fun`
		from it.  A ``tooldir`` argument may be provided as a list of module paths.

		:param tool_list: list of Waf tool names to load
		:type tool_list: list of string or space-separated string
		t   tooldirR	   t   with_sys_pathR   N(   R    t   to_listt   gett   Truet	   load_toolR   R   R   (
   R4   t	   tool_listR   R   t   toolsR0   R:   t   tt   moduleR   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   loadµ   s    !c         C   s#   |  j  t j j t j ƒ g ƒ d S(   s‘   
		Here, it calls the function name in the top-level wscript file. Most subclasses
		redefine this method to provide additional functionality.
		N(   t   recurset   osR0   t   dirnamet   g_modulet	   root_path(   R4   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   executeÇ   s    c         C   s,   |  j  j |  j ƒ | |  _ | j |  _ d S(   s!  
		Method executed immediately before a folder is read by :py:meth:`waflib.Context.Context.recurse`.
		The current script is bound as a Node object on ``self.cur_script``, and the current path
		is bound to ``self.path``

		:param node: script
		:type node: :py:class:`waflib.Node.Node`
		N(   R1   t   appendR.   t   parentR0   (   R4   t   node(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   pre_recurseÎ   s    		c         C   s1   |  j  j ƒ  |  _ |  j r- |  j j |  _ n  d S(   s¸   
		Restores ``self.cur_script`` and ``self.path`` right after :py:meth:`waflib.Context.Context.recurse` terminates.

		:param node: script
		:type node: :py:class:`waflib.Node.Node`
		N(   R1   t   popR.   RK   R0   (   R4   RL   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   post_recurseÜ   s    	c         B   s†  y |  j  } Wn e k
 r- i  } |  _  n XxQe j | ƒ D]@} e j j | ƒ sw e j j |  j j ƒ  | ƒ } n  e j j | e	 ƒ } | d | pŸ |  j
 }	 |  j j |	 ƒ }
 |
 r,| sÎ |
 | k r,e | |
 <|  j |
 ƒ z3 |
 j d | ƒ } e | |
 j ƒ  d ƒ |  j UWd |  j |
 ƒ Xq> |
 s> |  j j | ƒ }
 |
 | pS|  j
 f } |
 r| sr| | k re | | <|  j |
 ƒ z~ e |
 j ƒ  d | ƒ} e | | p¶|  j
 d ƒ } | sü| sÑw> n  e j d | pæ|  j
 |
 j ƒ  f ƒ ‚ n  | |  ƒ Wd |  j |
 ƒ Xq~|
 s~| s-q> n  y e j | ƒ Wn$ e k
 rde j d | ƒ ‚ n Xe j d | ƒ ‚ q~q> q> Wd S(	   sÅ  
		Runs user-provided functions from the supplied list of directories.
		The directories can be either absolute, or relative to the directory
		of the wscript file

		The methods :py:meth:`waflib.Context.Context.pre_recurse` and
		:py:meth:`waflib.Context.Context.post_recurse` are called immediately before
		and after a script has been executed.

		:param dirs: List of directories to visit
		:type dirs: list of string or space-separated string
		:param name: Name of function to invoke from the wscript
		:type  name: string
		:param mandatory: whether sub wscript files are required to exist
		:type  mandatory: bool
		:param once: read the script file once for a particular context
		:type once: bool
		t   _t   rUt   execNt   encodings   No function %r defined in %ss   Cannot read the folder %rs   No wscript file in directory %s(   t   recurse_cacheR   R    R;   RE   R0   t   isabst   joint   abspatht   WSCRIPT_FILER   R-   t	   find_nodeR=   RM   t   readt   compileR2   RO   t   load_moduleR   R   R   R   t   listdirt   OSError(   R4   t   dirsR   t	   mandatoryt   onceRS   t   cachet   dt   WSCRIPTt   WSCRIPT_FUNRL   t   function_codet   tupt   wscript_modulet   user_function(    (    s$   /git_repos/ams-lv2/waflib/Context.pyRD   ç   sP    !
!
+c         C   sr   t  j rn t j j d ƒ } | d k rK t | t ƒ sK t j | ƒ } qK n  t  j	 d | ƒ t  j	 d | ƒ n  d  S(   Nt   WAF_CMD_FORMATt   strings
   runner: %rs   runner_env: kw=%s(
   R   t   verboseRE   t   environR<   t
   isinstancet   strR    t   shell_escapet   debug(   R4   R   R   t   fmt(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   log_command*  s    	c   
      K   sâ  t  j } t | t ƒ | d <|  j | | ƒ |  j rH |  j j | ƒ n  d | k rd | j | d <n  d | k r€ | j | d <n  t j	 rÂ | d rÂ t  j
 | d ƒ rÂ t j d | d ƒ ‚ n  i  } d | k rt j d k r| d | d <d | k rt | d <qn  | d =n  d	 | k rU| d	 rK| d	 | d	 <| j | d
 <n  | d	 =n  d | k rŽt | d t ƒ sŽ| d j ƒ  | d <qŽn  | j d t ƒ } y" t  j | | | ƒ \ } } } Wn2 t k
 rö}	 t j d t |	 ƒ d |	 ƒ‚ n X| rjt | t ƒ s$| j | d d ƒ} n  |  j rC|  j j d | ƒ qjt j | d i t j d 6d d 6ƒn  | rÞt | t ƒ s—| j | d d ƒ} n  |  j r·|  j j d | ƒ qÞt j | d i t j d 6d d 6ƒn  | S(   s.  
		Runs an external process and returns the exit status::

			def run(tsk):
				ret = tsk.generator.bld.exec_command('touch foo.txt')
				return ret

		If the context has the attribute 'log', then captures and logs the process stderr/stdout.
		Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the
		stdout/stderr values captured.

		:param cmd: command argument for subprocess.Popen
		:type cmd: string or list
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: process exit status
		:rtype: integer
		:raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
		:raises: :py:class:`waflib.Errors.WafError` in case of execution failure
		t   shellt   stdoutt   stderri    s   Program %s not found!t   timeouti  t   start_new_sessiont   inputt   stdint   cwdt	   decode_ass   Execution failure: %st   ext   errorst   replaces   out: %st   extrat   streamR	   t   c1s   err: %s(   R    t
   subprocessRn   Ro   Rs   R3   t   infot   PIPER   Rl   t	   check_exeR   R   t   syst
   hexversionR=   RW   RN   t   default_encodingt   run_processt	   Exceptiont   decodeRq   Ru   t   errorRv   (
   R4   R   R   Rƒ   t   cargsRS   t   retR   t   errt   e(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   exec_command3  sX    		(


"#	'	'c         K   s  t  j } t | t ƒ | d <|  j | | ƒ | j d d ƒ } | j d t ƒ } t j	 r’ | d r’ t  j
 | d ƒ r’ t j d | d ƒ ‚ n  | j | d <| d <| d k rÃ |  j | ƒ n  i  } d | k rt j d	 k r| d | d <d
 | k rt | d
 <qn  | d =n  d | k rV| d rL| d | d <| j | d <n  | d =n  d | k r�t | d t ƒ s�| d j ƒ  | d <q�n  | j d t ƒ } y" t  j | | | ƒ \ } }	 }
 Wn2 t k
 r÷} t j d t | ƒ d | ƒ‚ n Xt |	 t ƒ s|	 j | d d ƒ}	 n  t |
 t ƒ sF|
 j | d d ƒ}
 n  |	 rx| t k rx| t k rx|  j d |	 ƒ n  |
 rª| t k rª| t k rª|  j d |
 ƒ n  | rít j d | | f ƒ } | | _ |
 | _ |	 | _ | ‚ n  | t k r|	 |
 f S| t k r|
 S|	 S(   s»  
		Executes a process and returns stdout/stderr if the execution is successful.
		An exception is thrown when the exit status is non-0. In that case, both stderr and stdout
		will be bound to the WafError object (configuration tests)::

			def configure(conf):
				out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH)
				(out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH)
				(out, err) = conf.cmd_and_log(cmd, input='\n'.encode(), output=waflib.Context.STDOUT)
				try:
					conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH)
				except Errors.WafError as e:
					print(e.stdout, e.stderr)

		:param cmd: args for subprocess.Popen
		:type cmd: list or string
		:param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate.
		:type kw: dict
		:returns: a tuple containing the contents of stdout and stderr
		:rtype: string
		:raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process
		:raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object
		Rt   t   quiett   outputi    s   Program %r not found!Ru   Rv   Rw   i  Rx   Ry   Rz   R{   R|   s   Execution failure: %sR}   R~   R   s   out: %ss   err: %ss   Command %r returned %rN(   R    Rƒ   Rn   Ro   Rs   RN   R   t   STDOUTR   Rl   R†   R   R   R…   t   to_logR‡   Rˆ   R=   RW   R‰   RŠ   R‹   RŒ   t   BOTHt   STDERRt
   returncodeRv   Ru   (   R4   R   R   Rƒ   R“   t   to_retRŽ   RS   R�   R   R�   R‘   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   cmd_and_log€  sb    	(


"#				
c         C   s´   |  j  r/ |  j  j d |  j j ƒ  | f ƒ n  y |  j  j d j } Wn t k
 rY n? Xt j j	 d ƒ rˆ d | t
 j | ƒ f } n d | | f } |  j j | d | ƒ‚ d S(   sf  
		Prints an error message in red and stops command execution; this is
		usually used in the configuration section::

			def configure(conf):
				conf.fatal('a requirement is missing')

		:param msg: message to display
		:type msg: string
		:param ex: optional exception object
		:type ex: exception
		:raises: :py:class:`waflib.Errors.ConfigurationError`
		s   from %s: %si    t   WAF_PRINT_FAILURE_LOGs   Log from (%s):
%s
s   %s
(complete log in %s)R}   N(   R3   R„   R0   RW   t   handlerst   baseFilenameR   RE   Rm   R<   R    t   readfR~   t   ConfigurationError(   R4   t   msgR}   t   logfile(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   fatalÕ  s    	&c         C   sM   | s
 d S|  j  r& |  j  j | ƒ n# t j j t | ƒ ƒ t j j ƒ  d S(   s  
		Logs information to the logger (if present), or to stderr.
		Empty messages are not printed::

			def build(bld):
				bld.to_log('starting the build')

		Provide a logger on the context class or override this method if necessary.

		:param msg: message
		:type msg: string
		N(   R3   R„   R‡   Rv   t   writeRo   t   flush(   R4   R¡   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR–   ñ  s    	c         O   s²   y | d } Wn t  k
 r+ | d } n X|  j | | � y | d } Wn t  k
 rg | d } n X| j d ƒ } t | t ƒ s› | r’ d p• d } n  |  j | | | � d S(	   s  
		Prints a configuration message of the form ``msg: result``.
		The second part of the message will be in colors. The output
		can be disabled easly by setting ``in_msg`` to a positive value::

			def configure(conf):
				self.in_msg = 1
				conf.msg('Checking for library foo', 'ok')
				# no output

		:param msg: message to display to the user
		:type msg: string
		:param result: result to display
		:type result: string or boolean
		:param color: color to use, see :py:const:`waflib.Logs.colors_lst`
		:type color: string
		R¡   i    t   resulti   t   colort   GREENt   YELLOWN(   R(   t	   start_msgR<   Rn   Ro   t   end_msg(   R4   R   R   R¡   R¦   R§   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR¡     s    c         O   s  | j  d ƒ r d S| j  d ƒ p) | d } y  |  j rK |  j d 7_ d SWn t k
 rh d |  _ n X|  j d 7_ y t |  j t | ƒ ƒ |  _ Wn) t k
 rÂ t d t | ƒ ƒ |  _ n Xx( |  j d | f D] } |  j | ƒ q× Wt j d d	 | j	 |  j ƒ d
 d ƒd S(   se   
		Prints the beginning of a 'Checking for xxx' message. See :py:meth:`waflib.Context.Context.msg`
		R“   NR¡   i    i   i(   t   -t   NORMALs   %s :t   sepR	   (
   R<   t   in_msgR   t   maxt	   line_justt   lenR–   R   t   pprintt   ljust(   R4   R   R   R¡   R   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyRª   +  s"    	c         O   sÿ   | j  d ƒ r d S|  j d 8_ |  j r/ d S| j  d ƒ pE | d } d } | t k rc d } n! | sx d } d	 } n t | ƒ } |  j | ƒ y | d
 } WnI t k
 rê t | ƒ d k rá | d t j k rá | d } që | } n Xt j	 | | ƒ d S(   sU   Prints the end of a 'Checking for' message. See :py:meth:`waflib.Context.Context.msg`R“   Ni   R¦   i    R¨   t   oks	   not foundR©   R§   (
   R<   R¯   R=   Ro   R–   R(   R²   R   t
   colors_lstR³   (   R4   R   R   R¦   t   defcolorR¡   R§   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR«   C  s*    			%
c         C   sU  t  j j t ƒ ru |  j j t ƒ j d ƒ j | ƒ } x| D]1 } | j | k r= t | j j	 d d ƒ ƒ q= q= WnÜ d d l
 m } | t ƒ } | j ƒ  } x± | D]© } t j d | j	 d d ƒ | ƒ sÒ q¤ n  t  j j | ƒ } t } x; | D]3 }	 |	 j	 d d ƒ }
 t j |
 | ƒ rñ t } qñ qñ W| s¤ | j	 d d ƒ } t | ƒ q¤ q¤ Wd	 S(
   s   
		Loads third-party extensions modules for certain programming languages
		by trying to list certain files in the extras/ directory. This method
		is typically called once for a programming language group, see for
		example :py:mod:`waflib.Tools.compiler_c`

		:param var: glob expression, for example 'cxx\_\*.py'
		:type var: string
		:param ban: list of exact file names to exclude
		:type ban: list of string
		s   waflib/extrass   .pyR	   iÿÿÿÿ(   t	   PyZipFiles   waflib/extras/%st   *s   .*N(   RE   R0   t   isdirt   waf_dirR-   RY   t   ant_globR   R>   R   t   zipfileR¸   t   namelistt   ret   matcht   basenamet   FalseR=   (   R4   t   vart   bant   lstR   R¸   t   waflibst   ft   dobant   bt   r(    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   load_special_toolsa  s(    $#"N(   R   R!   R"   R   R~   R@   R   R8   RC   RI   RM   RO   R   R=   RD   Rs   R’   R›   R£   R–   R¡   Rª   R«   RË   (    (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR   x   s&   						C			M	U		$		c         B   s×   y e  |  SWn e k
 r n Xe j e ƒ } y e j |  d d d | ƒ} Wn$ e k
 rt e j	 d |  ƒ ‚ n Xe
 j j |  ƒ } e j j d | ƒ z e | |  d ƒ | j UWd e j j | ƒ X| e  |  <| S(   sÎ   
	Loads a wscript file as a python module. This method caches results in :py:attr:`waflib.Context.cache_modules`

	:param path: file path
	:type path: string
	:return: Loaded Python module
	:rtype: module
	t   mRQ   RS   s   Could not read the file %ri    RR   N(   t   cache_modulesR(   t   impt
   new_moduleRX   R    RŸ   t   EnvironmentErrorR   R   RE   R0   RF   R‡   R   R[   t   __dict__t   remove(   R0   RS   RB   t   codet
   module_dir(    (    s$   /git_repos/ams-lv2/waflib/Context.pyR\   ‰  s     	
c   	      C   sç  |  d k r d }  n |  j  d d ƒ }  | sB t j } g  t _ n  z…| rð t | t ƒ s` t ‚ | t j t _ z= y t |  ƒ Wn( t k
 r« } t t j ƒ | _ ‚  n XWd x | D] } t j j	 | ƒ q· WXt j
 |  } | t j |  <| S| st j j d t ƒ n  z{ yL xE d D]3 } y t | |  ƒ PWqt k
 rKd } qXqWt |  ƒ Wn( t k
 r…} t t j ƒ | _ ‚  n XWd | s£t j j	 t ƒ n  Xt j
 | |  } | t j |  <| SWd | sât j | 7_ n  Xd S(   s�  
	Importx a Waf tool as a python module, and stores it in the dict :py:const:`waflib.Context.Context.tools`

	:type  tool: string
	:param tool: Name of the tool
	:type  tooldir: list
	:param tooldir: List of directories to search for the tool module
	:type  with_sys_path: boolean
	:param with_sys_path: whether or not to search the regular sys.path, besides waf_dir and potentially given tooldirs
	t   javat   javaws   ++t   xxNi    s   waflib.Tools.%ss   waflib.extras.%ss	   waflib.%ss   %s(   s   waflib.Tools.%ss   waflib.extras.%ss	   waflib.%ss   %s(   R   R‡   R0   Rn   t   listt   AssertionErrort
   __import__t   ImportErrort   waf_sys_pathRÒ   t   modulesR   R@   R   R»   R   (	   t   toolR9   R   R:   t	   back_pathR‘   Rc   R�   R   (    (    s$   /git_repos/ams-lv2/waflib/Context.pyR>   §  sT    		  (-   R"   RE   R¿   RÎ   R‡   R*   R    R   R   t   waflib.Nodet
   HEXVERSIONt
   WAFVERSIONt   WAFREVISIONt   ABIt   platformRˆ   t   DBFILER   R   t   TOPt   OUTRX   t
   launch_dirR#   t   top_dirt   out_dirR»   t   console_encodingR‰   R   RG   R•   R˜   R—   R
   R   R)   R   t   objectR   R   RÍ   R\   R=   R>   (    (    (    s$   /git_repos/ams-lv2/waflib/Context.pyt   <module>   sB   0	ÿ ÿ 