ó
ÓnäZc           @€  sÈ  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 e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e e d „ ƒ Z e d d „ ƒ Z d „  Z d „  Z e j d ƒ Z e j d ƒ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% i  d „ Z& d d „ Z' d e j( f d „  ƒ  YZ) d  e f d! „  ƒ  YZ* d" „  Z+ d# „  Z, d S($   iÿÿÿÿ(   t   with_statementNt   memoizec           B€  s   e  Z d  „  Z d „  Z RS(   c         C€  s   | |  _  i  |  _ d  S(   N(   t   funct   cache(   t   selfR   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __init__   s    	c         G€  sD   y |  j  | SWn. t k
 r? |  j | Œ  } | |  j  | <| SXd  S(   N(   R   t   KeyErrorR   (   R   t   argst   result(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __call__   s    (   t   __name__t
   __module__R   R	   (    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR      s   	t   GypErrorc           B€  s   e  Z d  Z RS(   s€   Error class representing an error, which is to be presented
  to the user.  The main entry point will catch and display this.
  (   R
   R   t   __doc__(    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR      s   c         C€  s   |  j  s | f |  _  ne t |  j  ƒ d k rQ t |  j  d ƒ d | f |  _  n, t |  j  d ƒ d | f |  j  d |  _  d S(   s2   Append a message to the given exception's message.i   i    t    N(   R   t   lent   str(   t   et   msg(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   ExceptionAppend&   s
    	$c         C€  s-   g  | D]" } t  | ƒ d |  k r | ^ q S(   sc   
  Given a list of qualified targets, return the qualified targets for the
  specified |target|.
  i   (   t   ParseQualifiedTarget(   t   targett   qualified_listt   t(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   FindQualifiedTargets0   s    c         C€  s   |  j  d d ƒ } t | ƒ d k r3 | \ } }  n d  } |  j  d d ƒ } t | ƒ d k rl | \ }  } n d  } | |  | g S(   Nt   :i   i   t   #(   t   rsplitR   t   None(   R   t   target_splitt
   build_filet   toolset(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR   8   s    c         C€  sš   t  | ƒ \ } } } | r~ |  ru t j j t j j t j j |  ƒ | ƒ ƒ }  t j j |  ƒ s{ t |  d ƒ }  q{ q~ | }  n  | r | } n  |  | | g S(   Nt   .(   R   t   ost   patht   normpatht   joint   dirnamet   isabst   RelativePath(   R   R   R   t   parsed_build_filet   parsed_toolset(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   ResolveTargetK   s    
!		c         C€  s   t  |  ƒ d S(   Ni    (   R   (   t   fully_qualified_target(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt	   BuildFilem   s    c         C€  s/   x( |  D]  } | t  j k r t  j | Sq W| S(   sp   Look up a key in the environment, with fallback to secondary keys
  and finally falling back to a default value.(   R!   t   environ(   t   var_listt   defaultt   var(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   GetEnvironFallbackr   s    c         C€  s)   |  d | } | r% | d | } n  | S(   NR   R   (    (   R   R   R   t   fully_qualified(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   QualifiedTarget{   s    c         C€  s   | r t  j j |  ƒ }  n t  j j |  ƒ }  t  j j | ƒ } t j d k r t  j j |  ƒ d j ƒ  t  j j | ƒ d j ƒ  k r |  Sn  |  j t  j j	 ƒ } | j t  j j	 ƒ } t
 t  j j | | g ƒ ƒ } t  j j g t
 | ƒ | | | } t
 | ƒ d k rd St  j j | Œ  S(   Nt   win32i    t    (   R!   R"   t   realpatht   abspatht   syst   platformt
   splitdrivet   lowert   splitt   sepR   t   commonprefixt   pardirR$   (   R"   t   relative_tot   follow_path_symlinkt
   path_splitt   relative_to_splitt
   prefix_lent   relative_split(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR'   …   s     c         C€  s>   |  s
 |  S| d k r d n | } t | t j j | |  ƒ ƒ S(   s  Given a path like foo/bar that is relative to toplevel_dir, return
  the inverse relative path back to the toplevel_dir.

  E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path)))
  should always produce the empty string, unless the path contains symlinks.
  R    N(   R   R'   R!   R"   R$   (   R"   t   toplevel_dir(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   InvertRelativePath±   s    c         C€  s#   t  j j |  ƒ r |  St |  | ƒ S(   N(   R!   R"   R&   R'   (   R"   R@   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   FixIfRelativePath¿   s    c         C€  s1   t  j j | ƒ } t  j j t  j j | |  ƒ ƒ S(   N(   R!   R"   R%   R#   R$   (   R"   R@   t   rel_dir(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   UnrelativePathÆ   s    s   [	
 #$%&'()*;<=>?[{|}~]|^$s   (["\\`])c         C€  s]   t  |  t ƒ s t |  ƒ }  n  t j |  ƒ r6 d } n d } | t j t d |  ƒ | } | S(   s¬  Encodes |argument| suitably for consumption by POSIX shells.

  argument may be quoted and escaped as necessary to ensure that POSIX shells
  treat the returned value as a literal representing the argument passed to
  this function.  Parameter (variable) expansions beginning with $ are allowed
  to remain intact without escaping the $, to allow the argument to contain
  references to variables to be expanded by the shell.
  t   "R5   s   \\\1(   t
   isinstanceR   t   _quotet   searcht   ret   subt   _escape(   t   argumentt   quotet   encoded(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   EncodePOSIXShellArgument  s    
	c         C€  s7   g  } x! |  D] } | j  t | ƒ ƒ q Wd j | ƒ S(   sÄ   Encodes |list| suitably for consumption by POSIX shells.

  Returns EncodePOSIXShellArgument for each item in list, and joins them
  together using the space character as an argument separator.
  R   (   t   appendRU   R$   (   t   listt   encoded_argumentsRR   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   EncodePOSIXShellList  s    c         C€  s©   t  ƒ  } t  | ƒ } x} | r” | j ƒ  } | | k r< q n  | j | ƒ |  | } | j t  | j d g  ƒ ƒ ƒ | j t  | j d g  ƒ ƒ ƒ q Wt | t  | ƒ ƒ S(   s2   Returns the recursive list of target dependencies.t   dependenciest   dependencies_original(   t   sett   popt   addt   updatet   getRW   (   t   target_dictst   rootsRZ   t   pendingt   rt   spec(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   DeepDependencyTargets(  s    		
#c         C€  s)   g  |  D] } t  | ƒ | k r | ^ q S(   sH   From a target_list, returns the subset from the specified build_file.
  (   R,   (   t   target_listR   t   p(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   BuildFileTargets;  s    c         C€  s&   t  |  | ƒ } t | | ƒ } | | S(   sN   Returns all targets (direct and dependencies) for the specified build_file.
  (   Ri   Rf   (   Rg   Ra   R   t	   bftargetst
   deptargets(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt
   AllTargetsA  s    c         €  s#   d t  f ‡  f d †  ƒ  Y} | ƒ  S(   sú   Write to a file only if the new contents differ.

  Arguments:
    filename: name of the file to potentially write to.
  Returns:
    A file like object which will write to temporary file and only overwrite
    the target if it differs (on close).
  t   Writerc           €  s5   e  Z d  Z ‡  f d †  Z d „  Z ‡  f d †  Z RS(   s?   Wrapper around file which only covers the target if it differs.c         €  s   t  j d d d t j j ˆ  ƒ d d d t j j ˆ  ƒ d ƒ \ } |  _ y t j | d ƒ |  _ Wn$ t k
 rŠ t j	 |  j ƒ ‚  n Xd  S(	   Nt   suffixs   .tmpt   prefixi   s   .gyp.t   diri    t   wb(
   t   tempfilet   mkstempR!   R"   R<   t   tmp_patht   fdopent   tmp_filet	   Exceptiont   unlink(   R   t   tmp_fd(   t   filename(    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR   U  s    	"c         S€  s   t  |  j | ƒ S(   N(   t   getattrRv   (   R   t   attrname(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __getattr__b  s    c         €  s  yò |  j  j ƒ  t } y t j |  j ˆ  t ƒ } Wn+ t k
 r_ } | j t j k r` ‚  q` n X| ry t	 j
 |  j ƒ nx t	 j d ƒ } t	 j | ƒ t	 j |  j d | @ƒ t j d k rÞ t	 j j ˆ  ƒ rÞ t	 j ˆ  ƒ n  t	 j |  j ˆ  ƒ Wn$ t k
 rt	 j
 |  j ƒ ‚  n Xd  S(   Ni?   i¶  R4   (   Rv   t   closet   Falset   filecmpt   cmpRt   t   OSErrort   errnot   ENOENTR!   Rx   t   umaskt   chmodR8   R9   R"   t   existst   removet   renameRw   (   R   t   sameR   R…   (   Rz   (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR~   f  s&    
!(   R
   R   R   R   R}   R~   (    (   Rz   (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyRm   S  s   	(   t   object(   Rz   Rm   (    (   Rz   s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   WriteOnDiffI  s    
<c         C€  s5   y t  j t  j j |  ƒ ƒ Wn t k
 r0 n Xd S(   s*   Make sure the directory for |path| exists.N(   R!   t   makedirsR"   R%   R‚   (   R"   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   EnsureDirExists’  s    c         C€  sç   i d d 6d d 6d d 6} d |  k r/ |  d St  j | k rI | t  j St  j j d ƒ r_ d St  j j d	 ƒ ru d	 St  j j d
 ƒ r‹ d
 St  j j d ƒ r¡ d St  j j d ƒ r· d St  j j d ƒ rÍ d St  j j d ƒ rã d Sd S(   sF   Returns |params.flavor| if it's set, the system's default flavor else.t   wint   cygwinR4   t   mact   darwint   flavort   sunost   solarist   freebsdt   openbsdt   netbsdt   aixt   zost   os390t   linux(   R8   R9   t
   startswith(   t   paramst   flavors(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt	   GetFlavorš  s.    
c      
   C€  s2  i d d 6d d 6d d 6d d 6j  |  d ƒ } | s8 d St j j t j j t j j t ƒ ƒ d | ƒ } t | ƒ  } | j	 ƒ  } Wd QXd } | j  d	 d ƒ } |  d k rÅ | rÅ | d
 | 7} n  t j j | d | ƒ }	 t |	 d ƒ / }
 |
 j
 d j | d | g | d ƒ ƒ Wd QXt j |	 d ƒ d S(   sR   Finds (flock|mac|win)_tool.gyp in the gyp directory and copies it
  to |out_path|.t   flockR™   R•   R‘   R   Ns
   %s_tool.pys!   # Generated by gyp. Do not edit.
t   mac_toolchain_dirs,   import os;
os.environ['DEVELOPER_DIR']='%s'
s   gyp-%s-toolt   wR5   i    i   ií  (   R`   R   R!   R"   R$   R%   R7   t   __file__t   opent	   readlinest   writeR†   (   R“   t   out_patht   generator_flagsRo   t   source_patht   source_filet   sourcet   headerR¢   t	   tool_patht	   tool_file(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   CopyTool¸  s,    
	((c         C€  sn   | d  k r d „  } n  i  } g  } xC |  D]; } | | ƒ } | | k rO q+ n  d | | <| j | ƒ q+ W| S(   Nc         S€  s   |  S(   N(    (   t   x(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   <lambda>å  R5   i   (   R   RV   (   t   seqt   idfunt   seenR   t   itemt   marker(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   uniquerã  s     
t
   OrderedSetc           B€  sq   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d „ Z d „  Z d	 „  Z d
 „  Z RS(   c         C€  sF   g  |  _  } | d  | | g 7} i  |  _ | d  k	 rB |  | O}  n  d  S(   N(   t   endR   t   map(   R   t   iterableRº   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR   ò  s
    	c         C€  s   t  |  j ƒ S(   N(   R   R»   (   R   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __len__ù  s    c         C€  s   | |  j  k S(   N(   R»   (   R   t   key(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __contains__ü  s    c         C€  sO   | |  j  k rK |  j } | d } | | | g | d <| d <|  j  | <n  d  S(   Ni   i   (   R»   Rº   (   R   R¾   Rº   t   curr(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR^   ÿ  s    	
c         C€  sE   | |  j  k rA |  j  j | ƒ \ } } } | | d <| | d <n  d  S(   Ni   i   (   R»   R]   (   R   R¾   t	   prev_itemt	   next_item(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   discard  s    
c         c€  s=   |  j  } | d } x# | | k	 r8 | d V| d } q Wd  S(   Ni   i    (   Rº   (   R   Rº   RÀ   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __iter__  s
    	
	c         c€  s=   |  j  } | d } x# | | k	 r8 | d V| d } q Wd  S(   Ni   i    (   Rº   (   R   Rº   RÀ   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __reversed__  s
    	
	c         C€  sN   |  s t  d ƒ ‚ n  | r, |  j d d n |  j d d } |  j | ƒ | S(   Ns   set is emptyi   i    i   (   R   Rº   RÃ   (   R   t   lastR¾   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR]     s
    (c         C€  s1   |  s d |  j  j f Sd |  j  j t |  ƒ f S(   Ns   %s()s   %s(%r)(   t	   __class__R
   RW   (   R   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __repr__!  s    c         C€  sS   t  | t ƒ r= t |  ƒ t | ƒ k o< t |  ƒ t | ƒ k St |  ƒ t | ƒ k S(   N(   RL   R¹   R   RW   R\   (   R   t   other(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __eq__&  s    .c         C€  s1   x* | D]" } | |  k r |  j  | ƒ q q Wd  S(   N(   R^   (   R   R¼   t   i(    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR_   ,  s    N(   R
   R   R   R   R½   R¿   R^   RÃ   RÄ   RÅ   t   TrueR]   RÈ   RÊ   R_   (    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR¹   ñ  s   								t
   CycleErrorc           B€  s    e  Z d  Z d „  Z d „  Z RS(   s9   An exception raised when an unexpected cycle is detected.c         C€  s   | |  _  d  S(   N(   t   nodes(   R   RÎ   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyR   4  s    c         C€  s   d t  |  j ƒ S(   Ns   CycleError: cycle involving: (   R   RÎ   (   R   (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   __str__6  s    (   R
   R   R   R   RÏ   (    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyRÍ   2  s   	c         €  sd   t  ˆ ƒ ‰ t ƒ  ‰ t ƒ  ‰ g  ‰ ‡  ‡ ‡ ‡ ‡ f d †  ‰  x t |  ƒ D] } ˆ  | ƒ qL Wˆ S(   sÔ  Topologically sort based on a user provided edge definition.

  Args:
    graph: A list of node names.
    get_edges: A function mapping from node name to a hashable collection
               of node names which this node has outgoing edges to.
  Returns:
    A list containing all of the node in graph in topological order.
    It is assumed that calling get_edges once for each node and caching is
    cheaper than repeatedly calling get_edges.
  Raises:
    CycleError in the event of a cycle.
  Example:
    graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
    def GetEdges(node):
      return re.findall(r'\$\(([^))]\)', graph[node])
    print TopologicallySorted(graph.keys(), GetEdges)
    ==>
    ['a', 'c', b']
  c         €  s‡   |  ˆ k r t  ˆ ƒ ‚ n  |  ˆ k r+ d  Sˆ j |  ƒ ˆ j |  ƒ x ˆ |  ƒ D] } ˆ  | ƒ qR Wˆ j |  ƒ ˆ j d |  ƒ d  S(   Ni    (   RÍ   R^   Rˆ   t   insert(   t   nodet   neighbor(   t   Visitt	   get_edgest   ordered_nodest   visitedt   visiting(    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyRÓ   S  s    (   R   R\   t   sorted(   t   graphRÔ   RÑ   (    (   RÓ   RÔ   RÕ   RÖ   R×   s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   TopologicallySorted:  s    		c           C€  s|   t  j j d ƒ p{ t  j j d ƒ p{ t  j j d ƒ p{ t  j j d ƒ p{ t  j j d ƒ p{ t  j j d ƒ p{ t  j j d ƒ S(   Nt   GYP_CROSSCOMPILEt   AR_hostt   CC_hostt   CXX_hostt	   AR_targett	   CC_targett
   CXX_target(   R!   R-   R`   (    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   CrossCompileRequestedb  s    (-   t
   __future__R    t   collectionsRƒ   R€   t   os.pathR!   RO   Rr   R8   R‹   R   Rw   R   R   R   R   R*   R,   R1   R3   RÌ   R'   R   RG   RH   RJ   t   compileRM   RQ   RU   RY   Rf   Ri   Rl   RŒ   RŽ   R    R°   R¸   t
   MutableSetR¹   RÍ   RÚ   Râ   (    (    (    s.   /usr/lib/python2.7/dist-packages/gyp/common.pyt   <module>   sL   	
			"				
+		"						I		+A	(