
    擖gX                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	   " S S5      r
 " S S\5      rS rS rS	 rS
 rS rS rS r\
S&S j5       r\
S'S j5       rS rS r\R0                  " S5      r\R0                  " S5      rS rS rS rS rS rS r S r!S r"0 4S jr#S 4S jr$ " S S \	5      r% " S! S"\5      r&S# r'S$ r(S% r)g)(    N)
MutableSetc                        \ rS rSrS rS rSrg)memoize   c                     Xl         0 U l        g N)funccache)selfr	   s     ,/usr/lib/python3/dist-packages/gyp/common.py__init__memoize.__init__   s    	
    c                      U R                   U   $ ! [         a"    U R                  " U6 nX R                   U'   Us $ f = fr   )r
   KeyErrorr	   )r   argsresults      r   __call__memoize.__call__   sD    	::d## 	YY%F%JJtM	s    )==)r
   r	   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__ r   r   r   r      s    r   r   c                       \ rS rSrSrSrg)GypError    z|Error class representing an error, which is to be presented
to the user.  The main entry point will catch and display this.
r   N)r   r   r   r   __doc__r   r   r   r   r   r       s     	r   r   c                    U R                   (       d	  U4U l         g[        U R                   5      S:X  a%  [        U R                   S   5      S-   U-   4U l         g[        U R                   S   5      S-   U-   4U R                   SS -   U l         g)z2Append a message to the given exception's message.   r    N)r   lenstr)emsgs     r   ExceptionAppendr'   (   sq    66	QVV	affQi.3&,.affQi.3&,.;r   c                 Z    U Vs/ s H  n[        U5      S   U :X  d  M  UPM     sn$ s  snf )z]
Given a list of qualified targets, return the qualified targets for the
specified |target|.
r!   ParseQualifiedTarget)targetqualified_listts      r   FindQualifiedTargetsr.   2   s.    
 &N~!)=a)@)Cv)MA~NNNs   ((c                     U R                  SS5      n[        U5      S:X  a  Uu  p OS nU R                  SS5      n[        U5      S:X  a  Uu  pOS nX U/$ )N:r!      #)rsplitr#   )r+   target_split
build_filetoolsets       r   r*   r*   :   sg     ==a(L
<A+V
==a(L
<A(((r   c                 n   [        U5      u  p1nU(       a  U (       a  [        R                  R                  [        R                  R	                  [        R                  R                  U 5      U5      5      n [        R                  R                  U 5      (       d  [        U S5      n OUn U(       a  UnXU/$ )N.)r*   ospathnormpathjoindirnameisabsRelativePath)r5   r+   r6   parsed_build_fileparsed_toolsets        r   ResolveTargetrB   M   s     3Gv2N/ ))RWW__Z8:KLJ 77==,,)*c:
*J ((r   c                     [        U 5      S   $ Nr   r)   )fully_qualified_targets    r   	BuildFilerF   p   s     67::r   c                 j    U  H,  nU[         R                  ;   d  M  [         R                  U   s  $    U$ )znLook up a key in the environment, with fallback to secondary keys
and finally falling back to a default value.)r9   environ)var_listdefaultvars      r   GetEnvironFallbackrL   u   s/     "**::c?"  Nr   c                 4    U S-   U-   nU(       a  US-   U-   nU$ )Nr0   r2   r   )r5   r+   r6   fully_qualifieds       r   QualifiedTargetrO   ~   s+     !3&/O)C/'9r   c                 h   U(       a  [         R                  R                  U 5      O[         R                  R                  U 5      n [         R                  R                  U5      n[        R
                  S:X  ad  [         R                  R                  U 5      S   R                  5       [         R                  R                  U5      S   R                  5       :w  a  U $ U R                  [         R                  R                  5      nUR                  [         R                  R                  5      n[        [         R                  R                  X4/5      5      n[         R                  R                  /[        U5      U-
  -  X5S  -   n[        U5      S:X  a  g[         R                  R                  " U6 $ )Nwin32r    )r9   r:   realpathabspathsysplatform
splitdrivelowersplitsepr#   commonprefixpardirr<   )r:   relative_tofollow_path_symlink
path_splitrelative_to_split
prefix_lenrelative_splits          r   r?   r?      s?    &9277D!bggood>SD''"";/K ||w
4 #))+77k*1-335	6  BGGKK(J#))"''++6 RWW)):*IJKJ ggnn%+; N >a 77<<((r   c                 t    U (       d  U $ Uc  SOUn[        U[        R                  R                  X5      5      $ )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.
r8   )r?   r9   r:   r<   )r:   toplevel_dirs     r   InvertRelativePathre      s2     &.3LLbggll<&FGGr   c                 d    [         R                  R                  U 5      (       a  U $ [        X5      $ r   )r9   r:   r>   r?   )r:   r]   s     r   FixIfRelativePathrg      s%    	ww}}T**r   c                     [         R                  R                  U5      n[         R                  R                  [         R                  R	                  X 5      5      $ r   )r9   r:   r=   r;   r<   )r:   r]   rel_dirs      r   UnrelativePathrj      s8     ggook*G77BGGLL788r   z[	
 #$%&'()*;<=>?[{|}~]|^$z(["\\`])c                     [        U [        5      (       d  [        U 5      n [        R                  U 5      (       a  SOSnU[        R
                  " [        SU 5      -   U-   nU$ )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.
"rR   z\\\1)
isinstancer$   _quotesearchresub_escape)argumentquoteencodeds      r   EncodePOSIXShellArgumentrv     sP     h$$x===**CEbffWgx885@GNr   c                 n    / nU  H  nUR                  [        U5      5        M     SR                  U5      $ )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"   )appendrv   r<   )listencoded_argumentsrs   s      r   EncodePOSIXShellListr{     s8       !9(!CD 88%&&r   c                 z   [        5       n[        U5      nU(       a  UR                  5       nXB;   a  M  UR                  U5        X   nUR                  [        UR	                  S/ 5      5      5        UR                  [        UR	                  S/ 5      5      5        U(       a  M  [        U[        U5      -
  5      $ )z2Returns the recursive list of target dependencies.dependenciesdependencies_original)setpopaddupdategetry   )target_dictsrootsr}   pendingrspecs         r   DeepDependencyTargetsr   (  s    5L%jG
KKMs488NB789s488$;R@AB ' s5z)**r   c                 T    U  Vs/ s H  n[        U5      U:X  d  M  UPM     sn$ s  snf )zHFrom a target_list, returns the subset from the specified build_file.
  )rF   )target_listr5   ps      r   BuildFileTargetsr   ;  s'     #A{!ilj&@A{AAAs   %%c                 6    [        X5      n[        X5      nX4-   $ )zNReturns all targets (direct and dependencies) for the specified build_file.
  )r   r   )r   r   r5   	bftargets
deptargetss        r   
AllTargetsr   A  s!     !9I&|?J!!r   c                 ,   ^   " U 4S jS5      nU" 5       $ )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                   >   > \ rS rSrSrU 4S jrS rU 4S jrS rSr	g)	WriteOnDiff.<locals>.WriteriS  z?Wrapper around file which only covers the target if it differs.c                 ~  > [        5       (       a  SO[        R                  R                  T5      n[        R
                  " S[        R                  R                  T5      S   S-   US9u  o l         [        R                  " US5      U l	        g ! [         a"    [        R                  " U R                  5        e f = f)NrR   z.tmpr!   z.gyp.)suffixprefixdirwb)IsCygwinr9   r:   r=   tempfilemkstemprY   tmp_pathfdopentmp_file	Exceptionunlink)r   base_temp_dirtmp_fdfilenames      r   r   $WriteOnDiff.<locals>.Writer.__init__V  s     #+**B"''//(2KM$,$4$4ww}}X.q1G;!%!FM
 "		&$ 7 		$--(s   3B ,B<c                 .    [        U R                  U5      $ r   )getattrr   )r   attrnames     r   __getattr__'WriteOnDiff.<locals>.Writer.__getattr__m  s    4==(33r   c                 "  >  U R                   R                  5         Sn [        R                  " U R                  TS5      nU(       a!  [        R                  " U R                  5        g [        R                  " S5      n[        R                  " U5        [        R                  " U R                  SU) -  5        [        R                  S:X  a:  [        R                  R                  T5      (       a  [        R                   " T5        [        R"                  " U R                  T5        g ! [
         a*  nUR                  [        R                  :w  a  e  S nAGNS nAff = f! [$         a"    [        R                  " U R                  5        e f = f)NF?   i  rQ   )r   closefilecmpcmpr   OSErrorerrnoENOENTr9   r   umaskchmodrU   rV   r:   existsremoverenamer   )r   samer%   r   r   s       r   r   !WriteOnDiff.<locals>.Writer.closeq  s   (##%";;t}}hFD
  IIdmm, HHTNEHHUOHHT]]EUFN;||w.277>>(3K3K 		(+IIdmmX6;  ww%,,. /<  		$--(s;   E" "D+ 'E" *C E" +
E5EE" EE" ",Fc                 X    U R                   R                  UR                  S5      5        g )Nutf-8)r   writeencode)r   ss     r   r   !WriteOnDiff.<locals>.Writer.write  s    MM 12r   )r   r   N)
r   r   r   r   r   r   r   r   r   r   )r   s   r   Writerr   S  s    M	.	4)	V	3r   r   r   )r   r   s   ` r   WriteOnDiffr   I  s    J3 J3X 8Or   c                      [         R                  " [         R                  R                  U 5      5        g! [         a     gf = f)z*Make sure the directory for |path| exists.N)r9   makedirsr:   r=   r   )r:   s    r   EnsureDirExistsr     s2    
BGGOOD)* s   36 
AAc                 Z   SSSS.nSU ;   a  U S   $ [         R                  U;   a  U[         R                     $ [         R                  R                  S5      (       a  g[         R                  R                  S5      (       a  g[         R                  R                  S	5      (       a  g	[         R                  R                  S
5      (       a  g
[         R                  R                  S5      (       a  g[         R                  R                  S5      (       a  g[         R                  S:X  a  gg)zFReturns |params.flavor| if it's set, the system's default flavor else.winmac)cygwinrQ   darwinflavorsunossolaris)	dragonflyfreebsdr   openbsdnetbsdaix)os390zosr   os400linux)rU   rV   
startswith)paramsflavorss     r   	GetFlavorr     s     G 6h
||ws||$$
||w''
||788
||y))
||x((
||u%%
||/00
||wr   c           	         SSSSSSS.R                  U S5      nU(       d  g[        R                  R                  [        R                  R	                  [        R                  R                  [        5      5      SU-  5      n[        U5       nUR                  5       nSSS5        SnUR                  SS5      nU S:X  a  U(       a  US	U-  -  n[        R                  R                  US
U-  5      n	[        U	S5       n
U
R                  SR                  WS   U/USS -   5      5        SSS5        [        R                  " U	S5        g! , (       d  f       N= f! , (       d  f       N7= f)zPFinds (flock|mac|win)_tool.gyp in the gyp directory and copies it
to |out_path|.flockr   r   )r   r   r   r   iosr   Nz
%s_tool.pyz!# Generated by gyp. Do not edit.
mac_toolchain_dirz,import os;
os.environ['DEVELOPER_DIR']='%s'
zgyp-%s-toolwrR   r   r!   i  )r   r9   r:   r<   r=   rT   __file__open	readlinesr   r   )r   out_pathgenerator_flagsr   source_pathsource_filesourceheaderr   	tool_path	tool_files              r   CopyToolr     s:     
c&$   '',,
12L64IK 
k	k&&( 
 2F'++,?F,BEVVV X}v'=>I	i	F 3fQRj @AB 
 HHY 
	 
	s   E?,E
E
E*c                     U $ r   r   )xs    r   <lambda>r     s    r   c                 h    0 n/ nU  H'  nU" U5      nXR;   a  M  SX%'   UR                  U5        M)     U$ )Nr!   )rx   )seqidfunseenr   itemmarkers         r   uniquerr     sA    DFt>d  Mr   c                   ^    \ rS rSrSS jrS rS rS rS rS r	S	 r
SS
 jrS rS rS rSrg)
OrderedSeti  Nc                 B    / =U l         nUS X"/-  n0 U l        Ub  X-  n g g r   endmap)r   iterabler   s      r   r   OrderedSet.__init__  s7    3cD  r   c                 ,    [        U R                  5      $ r   )r#   r   r   s    r   __len__OrderedSet.__len__
  s    488}r   c                     XR                   ;   $ r   )r   )r   keys     r   __contains__OrderedSet.__contains__  s    hhr   c                 |    XR                   ;  a-  U R                  nUS   nXU/=US'   =US'   U R                   U'   g g )Nr!   r1   )r   r   )r   r  r   currs       r   r   OrderedSet.add  sG    hh((Cq6D033/??DG?c!ftxx} r   c                 p    XR                   ;   a'  U R                   R                  U5      u  pnX2S'   X#S'   g g )Nr1   r!   )r   r   )r   r  	prev_item	next_items       r   discardOrderedSet.discard  s5    ((?(,S(9%CI$aL$aL r   c              #   \   #    U R                   nUS   nX!La  US   v   US   nX!La  M  g g 7f)Nr1   r   r   r   r   r  s      r   __iter__OrderedSet.__iter__  5     hh1voq'M7D o   &,,c              #   \   #    U R                   nUS   nX!La  US   v   US   nX!La  M  g g 7f)Nr!   r   r  r  s      r   __reversed__OrderedSet.__reversed__#  r  r  c                     U (       d  [        S5      eU(       a  U R                  S   S   OU R                  S   S   nU R                  U5        U$ )Nzset is emptyr!   r   r1   )r   r   r  )r   lastr  s      r   r   OrderedSet.pop+  sB    >** $dhhqk!n$((1+a.S
r   c                     U (       d  U R                   R                   S3$ U R                   R                   S[        U 5      < S3$ )Nz()())	__class__r   ry   r   s    r   __repr__OrderedSet.__repr__2  s?    nn--.b11..))*!DJ>;;r   c                     [        U[        5      (       a5  [        U 5      [        U5      :H  =(       a    [        U 5      [        U5      :H  $ [	        U 5      [	        U5      :H  $ r   )rm   r   r#   ry   r   )r   others     r   __eq__OrderedSet.__eq__7  sG    eZ((t9E
*HtDzT%[/HH4yCJ&&r   c                 F    U H  nX ;  d  M
  U R                  U5        M     g r   )r   )r   r   is      r   r   OrderedSet.update=  s    A} r   r   r   T)r   r   r   r   r   r   r  r   r  r  r  r   r  r"  r   r   r   r   r   r   r     s:    @%<
'r   r   c                   $    \ rS rSrSrS rS rSrg)
CycleErroriC  z9An exception raised when an unexpected cycle is detected.c                     Xl         g r   nodes)r   r,  s     r   r   CycleError.__init__F  s    
r   c                 2    S[        U R                  5      -   $ )NzCycleError: cycle involving: )r$   r,  r   s    r   __str__CycleError.__str__I  s    .TZZ@@r   r+  N)r   r   r   r   r   r   r/  r   r   r   r   r)  r)  C  s    CAr   r)  c                    ^^^^^ [        T5      m[        5       m[        5       m/ mUUUUU4S jm[        U 5       H  nT" U5        M     T$ )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                    > U T;   a  [        T5      eU T;   a  g TR                  U 5        TR                  U 5        T" U 5       H  nT" U5        M     TR                  U 5        TR                  SU 5        g rD   )r)  r   r   insert)nodeneighborVisit	get_edgesordered_nodesvisitedvisitings     r   r6  "TopologicallySorted.<locals>.Visitg  si    8X&&7?DT!$H(O (Q%r   )r   r   sorted)graphr7  r4  r6  r8  r9  r:  s    ` @@@@r   TopologicallySortedr>  M  sI    * 	"IeGuHM
& 
& ud r   c                     [         R                  R                  S5      =(       d    [         R                  R                  S5      =(       d    [         R                  R                  S5      =(       d    [         R                  R                  S5      =(       dk    [         R                  R                  S5      =(       dE    [         R                  R                  S5      =(       d    [         R                  R                  S5      $ )NGYP_CROSSCOMPILEAR_hostCC_hostCXX_host	AR_target	CC_target
CXX_target)r9   rH   r   r   r   r   CrossCompileRequestedrG  x  s     	

)* 	(::>>)$	(::>>)$	( ::>>*%	( ::>>+&		(
 ::>>+&	( ::>>,'r   c                       [         R                  " S[         R                  [         R                  S9n U R	                  5       S   R                  S5      nS[        U5      ;   $ ! [         a     gf = f)Nuname)stdoutstderrr   r   CYGWINF)
subprocessPopenPIPESTDOUTcommunicatedecoder$   r   )outrJ  s     r   r   r     sg    JOOJ4E4E
 "1%,,W53v;&& s   A!A$ $
A10A1r'  r   )*r   r   os.pathr9   rp   r   rU   rM  collections.abcr   r   r   r   r'   r.   r*   rB   rF   rL   rO   r?   re   rg   rj   compilern   rr   rv   r{   r   r   r   r   r   r   r   r   r   r)  r>  rG  r   r   r   r   <module>rW     s  
    	  
  &
 	y 	<O)& )F;
 	') 	')T 	
H 	
H+9D 
2	34 **[
!(
'+&B"Vr< 02 #Z # 	> >BA A(Vr   