
    "KbO                        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	m
Z
  G d de      Z G d de      Zd Zd	 Zd
 Zd Zd Zd Zd Zed%d       Zed&d       Zd Zd Z ej4                  d      Z ej4                  d      Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$i fdZ%d&dZ& G d d e
jN                        Z( G d! d"e      Z)d# Z*d$ Z+y)'    )with_statementN)collections_abcc                       e Zd Zd Zd Zy)memoizec                      || _         i | _        y N)funccache)selfr	   s     ,/usr/lib/python3/dist-packages/gyp/common.py__init__zmemoize.__init__   s    DIDJ    c                     	 | j                   |   S # t        $ r#  | j                  | }|| j                   |<   |cY S w xY wr   )r
   KeyErrorr	   )r   argsresults      r   __call__zmemoize.__call__   sH    ZZ tyy$fdjjms    )==N)__name__
__module____qualname__r   r    r   r   r   r      s    r   r   c                       e Zd ZdZy)GypErrorzError class representing an error, which is to be presented
  to the user.  The main entry point will catch and display this.
  N)r   r   r   __doc__r   r   r   r   r       s     r   r   c                    | j                   s	|f| _         yt        | j                         dk(  r%t        | j                   d         dz   |z   f| _         yt        | j                   d         dz   |z   f| j                   dd z   | _         y)z2Append a message to the given exception's message.   r    N)r   lenstr)emsgs     r   ExceptionAppendr"   '   sq    	
VAF
166{a!&&)ns"S(*AF!&&)ns"S(*QVVABZ7AFr   c                 P    |D cg c]  }t        |      d   | k(  s| c}S c c}w )zc
  Given a list of qualified targets, return the qualified targets for the
  specified |target|.
  r   ParseQualifiedTarget)targetqualified_listts      r   FindQualifiedTargetsr)   1   s*    
 $	L';A'>q'AV'K!	LL	Ls   ##c                     | j                  dd      }t        |      dk(  r|\  }} nd }| j                  dd      }t        |      dk(  r|\  } }nd }|| |gS )N:r      #)rsplitr   )r&   target_split
build_filetoolsets       r   r%   r%   9   si     sA&,!'ZJsA&,!$VWG
fg	&&r   c                 J   t        |      \  }}}|r| rt        j                  j                  t        j                  j	                  t        j                  j                  |       |            } t        j                  j                  |       st        | d      } n|} |r|}| ||gS )N.)r%   ospathnormpathjoindirnameisabsRelativePath)r0   r&   r1   parsed_build_fileparsed_toolsets        r   ResolveTargetr=   L   s     1EV0L-fn 77##BGGLL1L1B%D Ej WW]]:&!*c2
$jG
fg	&&r   c                     t        |       d   S Nr   r$   )fully_qualified_targets    r   	BuildFilerA   n   s    	4	5a	88r   c                 b    | D ])  }|t         j                  v st         j                  |   c S  |S )zpLook up a key in the environment, with fallback to secondary keys
  and finally falling back to a default value.)r4   environ)var_listdefaultvars      r   GetEnvironFallbackrG   s   s4      c
bjjZZ_ 
.r   c                 *    | dz   |z   }|r|dz   |z   }|S )Nr+   r-   r   )r0   r&   r1   fully_qualifieds       r   QualifiedTargetrJ   |   s+     $v-/%+g5O	r   c                 \   |r t         j                  j                  |       } nt         j                  j                  |       } t         j                  j                  |      }t        j
                  dk(  rct         j                  j                  |       d   j                         t         j                  j                  |      d   j                         k7  r| S | j                  t         j                  j                        }|j                  t         j                  j                        }t        t         j                  j                  ||g            }t         j                  j                  gt        |      |z
  z  ||d  z   }t        |      dk(  ryt        j                  j                  | S )Nwin32r    )r4   r5   realpathabspathsysplatform
splitdrivelowersplitsepr   commonprefixpardirr7   )r5   relative_tofollow_path_symlink
path_splitrelative_to_split
prefix_lenrelative_splits          r   r:   r:      sC    77D!D77??4 D  -+ 	\\W
4 #))+
;'*002	3k zz"''++&*!''4 277''5F(GHI* GGNN#s+<'=
'JKjk*+. 	A 
~	&&r   c                 j    | s| S |dn|}t        |t        j                  j                  ||             S )a  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.
  r3   )r:   r4   r5   r7   )r5   toplevel_dirs     r   InvertRelativePathr`      s4     
K$,,,	lBGGLLt$D	EEr   c                 \    t         j                  j                  |       r| S t        | |      S r   )r4   r5   r9   r:   )r5   rX   s     r   FixIfRelativePathrb      s$    WW]]4K	dK	((r   c                     t         j                  j                  |      }t         j                  j                  t         j                  j	                  ||             S r   )r4   r5   r8   r6   r7   )r5   rX   rel_dirs      r   UnrelativePathre      s:     GGOOK('			"'',,w5	66r   z[	
 #$%&'()*;<=>?[{|}~]|^$z(["\\`])c                     t        | t              st        |       } t        j                  |       rd}nd}|t	        j
                  t        d|       z   |z   }|S )a  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.
  "rM   z\\\1)
isinstancer   _quotesearchresub_escape)argumentquoteencodeds      r   EncodePOSIXShellArgumentrq     sN     
Hc	"8}H]]8EEBFF7GX66>'	.r   c                 j    g }| D ]  }|j                  t        |              dj                  |      S )zEncodes |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   )appendrq   r7   )listencoded_argumentsrn   s      r   EncodePOSIXShellListrv     s?      Ah5h?@A	#	$$r   c                 b   t               }t        |      }|r|j                         }||v r|j                  |       | |   }|j                  t        |j	                  dg                    |j                  t        |j	                  dg                    |rt        |t        |      z
        S )z2Returns the recursive list of target dependencies.dependenciesdependencies_original)setpopaddupdategetrt   )target_dictsrootsrx   pendingrspecs         r   DeepDependencyTargetsr   )  s    ,J'ALQ?DNN3txx345NN3txx 7<=> 	 
lSZ'	((r   c                 J    | D cg c]  }t        |      |k(  s| c}S c c}w )zHFrom a target_list, returns the subset from the specified build_file.
  )rA   )target_listr0   ps      r   BuildFileTargetsr   <  s#     !	?IaLJ$>!	??	?s     c                 <    t        | |      }t        ||      }||z   S )zNReturns all targets (direct and dependencies) for the specified build_file.
  )r   r   )r   r   r0   	bftargets
deptargetss        r   
AllTargetsr   B  s'     {J7)$\9=*	Z	r   c                 4      G  fddt               } |       S )zWrite 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).
  c                   ,    e Zd ZdZ fdZd Z fdZy)WriteOnDiff.<locals>.Writerz?Wrapper around file which only covers the target if it differs.c                 ^   t        j                  dt        j                  j	                        d   dz   t        j                  j	                        d         \  }| _        	 t        j                  |d      | _        y # t        $ r! t        j                  | j
                          w xY w)Nz.tmpr   z.gyp.r   )suffixprefixdirw)
tempfilemkstempr4   r5   rT   tmp_pathfdopentmp_file	Exceptionunlink)r   tmp_fdfilenames     r   r   z$WriteOnDiff.<locals>.Writer.__init__V  s    &..x(+g5ggmmH%a(*fdm		&#. 
		$-- s   &B *B,c                 .    t        | j                  |      S r   )getattrr   )r   attrnames     r   __getattr__z'WriteOnDiff.<locals>.Writer.__getattr__c  s    T]]H--r   c                    	 | j                   j                          d}	 t        j                  | j                  d      }|r t        j                  | j                         y t        j                  d      }t        j                  |       t        j                  | j                  d| z         t        j                  dk(  r4t        j                  j                        rt        j                          t        j"                  | j                         y # t
        $ r)}|j                  t        j                  k7  r Y d }~d }~ww xY w# t$        $ r! t        j                  | j                          w xY w)NF?   i  rL   )r   closefilecmpcmpr   OSErrorerrnoENOENTr4   r   umaskchmodrP   rQ   r5   existsremoverenamer   )r   samer    r   r   s       r   r   z!WriteOnDiff.<locals>.Writer.closeg  s	   &	T]]He<$
  ))DMM
" ((4.%
((5/
((4==%5&.
1\\W$)A IIh
))DMM8
,7  	WW$ %	8  
		$-- s;   E !D !E #B5E 	E"E E EE *E8N)r   r   r   r   r   r   r   )r   s   r   Writerr   T  s    I.'r   r   )object)r   r   s   ` r   WriteOnDiffr   J  s    :v :x 
/r   c                     	 t        j                  t         j                  j                  |              y# t        $ r Y yw xY w)z*Make sure the directory for |path| exists.N)r4   makedirsr5   r8   r   )r5   s    r   EnsureDirExistsr     s2    	KK%&	 		s   25 	A Ac                 ,   dddd}d| v r| d   S t         j                  |v r|t         j                     S t         j                  j                  d      ryt         j                  j                  d      ryt         j                  j                  d      ryt         j                  j                  d	      ry	t         j                  j                  d
      ry
t         j                  j                  d      ryt         j                  j                  d      ryy)zFReturns |params.flavor| if it's set, the system's default flavor else.winmac)cygwinrL   darwinflavorsunossolarisfreebsdopenbsdnetbsdaixzosos390linux)rP   rQ   
startswith)paramsflavorss     r   	GetFlavorr     s     ' (\\W3<<  \\W%\\Y'\\Y'\\X&\\U#\\U#\\W%	r   c           	         dddddj                  | d      }|syt        j                  j                  t        j                  j	                  t        j                  j                  t                    d|z        }t        |      5 }|j                         }ddd       d}|j                  dd      }| dk(  r
|r|d	|z  z  }t        j                  j                  |d
|z        }	t        |	d      5 }
|
j                  dj                  d   |g|dd z                ddd       t        j                  |	d       y# 1 sw Y   xY w# 1 sw Y   ,xY w)zRFinds (flock|mac|win)_tool.gyp in the gyp directory and copies it
  to |out_path|.flockr   r   )r   r   r   r   Nz
%s_tool.pyz!# Generated by gyp. Do not edit.
mac_toolchain_dirz,import os;
os.environ['DEVELOPER_DIR']='%s'
zgyp-%s-toolr   rM   r   r   i  )r~   r4   r5   r7   r8   rO   __file__open	readlineswriter   )r   out_pathgenerator_flagsr   source_pathsource_filesourceheaderr   	tool_path	tool_files              r   CopyToolr     sH    	
 	FD 	 

 ggoobggooh/0,2GI+K %K""$F% 0&&**+>Eu_*
>
 F ggll8]V%;<)Is 3yOO
F#fQRj0133
 ((9e#% %3 3s   D=2,E	=E	Ec                 l    |d }i }g }| D ]%  } ||      }||v rd||<   |j                  |       ' |S )Nc                     | S r   r   )xs    r   <lambda>zuniquer.<locals>.<lambda>  s    ! r   r   )rs   )seqidfunseenr   itemmarkers         r   uniquerr     sS    }DF tT>8Vd	
 Mr   c                   R    e Zd ZddZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zy)
OrderedSetNc                 D    g x| _         }|d ||gz  }i | _        || |z  } y y r   )endmap)r   iterabler   s      r   r   zOrderedSet.__init__  s;    DHsD#sCDH
hd r   c                 ,    t        | j                        S r   )r   r   r   s    r   __len__zOrderedSet.__len__  s    txx=r   c                     || j                   v S r   )r   )r   keys     r   __contains__zOrderedSet.__contains__  s    $((?r   c                 |    || j                   vr.| j                  }|d   }|||gx|d<   x|d<   | j                   |<   y y )Nr   r,   )r   r   )r   r   r   currs       r   r|   zOrderedSet.add   sK    
$((HHcVd*-tS)99d1g9A# r   c                 t    || j                   v r*| j                   j                  |      \  }}}||d<   ||d<   y y )Nr,   r   )r   r{   )r   r   	prev_item	next_items       r   discardzOrderedSet.discard  s=    
dhh"&((,,s"3c9iilil r   c              #   Z   K   | j                   }|d   }||ur|d    |d   }||ury y w)Nr,   r   r   r   r   r   s      r   __iter__zOrderedSet.__iter__  :     
((Cq6D
c/Gm!Wd c/   &++c              #   Z   K   | j                   }|d   }||ur|d    |d   }||ury y w)Nr   r   r   r   s      r   __reversed__zOrderedSet.__reversed__  r   r   c                     | st        d      |r| j                  d   d   n| j                  d   d   }| j                  |       |S )Nzset is emptyr   r   r,   )r   r   r   )r   lastr   s      r   r{   zOrderedSet.pop  sB    ^$$ $((1+a.dhhqk!nCLLJr   c                     | s| j                   j                  dS | j                   j                  dt        |       dS )Nz()())	__class__r   rt   r   s    r   __repr__zOrderedSet.__repr__"  s1    ~~..00~~..T
;;r   c                     t        |t              r0t        |       t        |      k(  xr t        |       t        |      k(  S t	        |       t	        |      k(  S r   )rh   r   r   rt   rz   )r   others     r   __eq__zOrderedSet.__eq__'  sD    %$Y#e*$BdtE{)BBt9E
""r   c                 >    |D ]  }|| vs| j                  |        y r   )r|   )r   r   is      r   r}   zOrderedSet.update-  s#     	
$r   r   T)r   r   r   r   r   r   r|   r   r   r   r{   r  r  r}   r   r   r   r   r     s9    :<
#r   r   c                       e Zd ZdZd Zd Zy)
CycleErrorz9An exception raised when an unexpected cycle is detected.c                     || _         y r   )nodes)r   r  s     r   r   zCycleError.__init__5  s	    DJr   c                 2    dt        | j                        z   S )NzCycleError: cycle involving: )r   r  r   s    r   __str__zCycleError.__str__7  s    *S_<<r   N)r   r   r   r   r   r  r   r   r   r  r  3  s    A=r   r  c                     t              t               t               g fdt        |       D ]
  } |        S )a  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                     | v rt              | v ry j                  |        j                  |         |       D ]
  } |        j                  |        j                  d|        y r?   )r  r|   r   insert)nodeneighborVisit	get_edgesordered_nodesvisitedvisitings     r   r  z"TopologicallySorted.<locals>.VisitT  sn    xx  wKKLLdO HoOODD!r   )r   rz   sorted)graphr  r  r  r  r  r  s    ` @@@@r   TopologicallySortedr  ;  sN    * i )E'U(-
" 
" Um d	$K	r   c                     t         j                  j                  d      xs t         j                  j                  d      xs t         j                  j                  d      xs t         j                  j                  d      xsa t         j                  j                  d      xs@ t         j                  j                  d      xs t         j                  j                  d      S )NGYP_CROSSCOMPILEAR_hostCC_hostCXX_host	AR_target	CC_target
CXX_target)r4   rC   r~   r   r   r   CrossCompileRequestedr%  c  s     **..+
, '
**..
#'
**..
#' **..
$' **..
%	'
 **..
%' **..
&(r   r	  r   ),
__future__r   r   r   os.pathr4   rk   r   rP   	six.movesr   r   r   r   r   r"   r)   r%   r=   rA   rG   rJ   r:   r`   rb   re   compileri   rm   rq   rv   r   r   r   r   r   r   r   r   
MutableSetr   r  r  r%  r   r   r   <module>r+     s  
 &    	  
 %

f 
y 8M'&'D9
 	(' 	('V 	
F 	
F)7D 
3	44 "**[
!.
%)&@ FR	< 02 "V
>++ >B= =&P	(r   