
    "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j        d          Z ej        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
j'                  Z( G d" d#e          Z)d$ Z*d% Z+dS )(    )with_statementN)collections_abcc                       e Zd Zd Zd ZdS )memoizec                 "    || _         i | _        d S N)funccache)selfr	   s     ,/usr/lib/python3/dist-packages/gyp/common.py__init__zmemoize.__init__   s    DIDJJJ    c                 j    	 | j         |         S # t          $ r  | j        | }|| j         |<   |cY S w xY wr   )r
   KeyErrorr	   )r   argsresults      r   __call__zmemoize.__call__   sR    Z   ty$fdjmmms     22N)__name__
__module____qualname__r   r    r   r   r   r      s2              r   r   c                       e Zd ZdZdS )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| _         dS t          | j                   dk    r(t          | j         d                   dz   |z   f| _         dS t          | j         d                   dz   |z   f| j         dd         z   | _         dS )z2Append a message to the given exception's message.   r    N)r   lenstr)emsgs     r   ExceptionAppendr"   '   s    	
 8VAFFF
16{{a!&)nns"S(*AFFF!&)nns"S(*QVABBZ7AFFFr   c                        fd|D             S )zc
  Given a list of qualified targets, return the qualified targets for the
  specified |target|.
  c                 F    g | ]}t          |          d          k    |S )r   ParseQualifiedTarget).0ttargets     r   
<listcomp>z(FindQualifiedTargets.<locals>.<listcomp>6   s1    	L	L	L';A'>'>q'AV'K'K!'K'K'Kr   r   )r)   qualified_lists   ` r   FindQualifiedTargetsr,   1   s     
 
M	L	L	L^	L	L	LLr   c                     |                      dd          }t          |          dk    r|\  }} nd }|                      dd          }t          |          dk    r|\  } }nd }|| |gS )N:r      #)rsplitr   )r)   target_split
build_filetoolsets       r   r&   r&   9   s     sA&&,!'ZJsA&&,!$VWWG
fg	&&r   c                 Z   t          |          \  }}}|r| rt          j                            t          j                            t          j                            |           |                    } t          j                            |           st          | d          } n|} |r|}| ||gS )N.)r&   ospathnormpathjoindirnameisabsRelativePath)r3   r)   r4   parsed_build_fileparsed_toolsets        r   ResolveTargetr@   L   s     1EV0L0L-fn % % 7##BGLL1L1L1B%D %D E Ej W]]:&& 3!*c22
$j G
fg	&&r   c                 ,    t          |           d         S Nr   r%   )fully_qualified_targets    r   	BuildFilerD   n   s    	4	5	5a	88r   c                 T    | D ]$}|t           j        v r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.)r7   environ)var_listdefaultvars      r   GetEnvironFallbackrJ   s   s<       c
bjZ_ 	.r   c                 *    | dz   |z   }|r|dz   |z   }|S )Nr.   r0   r   )r3   r)   r4   fully_qualifieds       r   QualifiedTargetrM   |   s0     $v-/ 6%+g5O	r   Tc                 b   |r t           j                            |           } nt           j                            |           } t           j                            |          }t          j        dk    rrt           j                            |           d                                         t           j                            |          d                                         k    r| S |                     t           j        j	                  }|                    t           j        j	                  }t          t           j                            ||g                    }t           j        j        gt          |          |z
  z  ||d          z   }t          |          dk    rdS t          j        j        | S )Nwin32r    )r7   r8   realpathabspathsysplatform
splitdrivelowersplitsepr   commonprefixpardirr:   )r8   relative_tofollow_path_symlink
path_splitrelative_to_split
prefix_lenrelative_splits          r   r=   r=      sb     !7D!!DD7??4  D  --+ 	\W
4  #))++
;''*0022	3 	3k zz"'+&&*!''44 27''5F(GHHII* GN#s+<'='=
'JKjkk*+. 	A2 
~	&&r   c                 r    | s| S |dn|}t          |t          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.
  Nr6   )r=   r7   r8   r:   )r8   toplevel_dirs     r   InvertRelativePathrc      s?     
 K$,,,	lBGLLt$D$D	E	EEr   c                 d    t           j                            |           r| S t          | |          S r   )r7   r8   r<   r=   )r8   r[   s     r   FixIfRelativePathre      s-    W]]4 K	dK	(	((r   c                     t           j                            |          }t           j                            t           j                            ||                     S r   )r7   r8   r;   r9   r:   )r8   r[   rel_dirs      r   UnrelativePathrh      s=     GOOK(('			"',,w55	6	66r   z[	
 #$%&'()*;<=>?[{|}~]|^$z(["\\`])c                     t          | t                    st          |           } t                              |           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.
  "rP   z\\\1)
isinstancer   _quotesearchresub_escape)argumentquoteencodeds      r   EncodePOSIXShellArgumentrt     sc     
Hc	"	" 8}}H]]8 EEEBF7GX666>'	.r   c                 ~    g }| D ]$}|                     t          |                     %d                    |          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   )appendrt   r:   )listencoded_argumentsrq   s      r   EncodePOSIXShellListry     sN      A Ah5h??@@@@	#	$	$$r   c                    t                      }t          |          }|r|                                }||v r|                    |           | |         }|                    t          |                    dg                                |                    t          |                    dg                                |t          |t          |          z
            S )z2Returns the recursive list of target dependencies.dependenciesdependencies_original)setpopaddupdategetrw   )target_dictsrootsr{   pendingrspecs         r   DeepDependencyTargetsr   )  s    ,JJ' ?ALQ?DNN3txx3344555NN3txx 7<<==>>> 	 ? 
lSZZ'	(	((r   c                      fd| D             S )zHFrom a target_list, returns the subset from the specified build_file.
  c                 :    g | ]}t          |          k    |S r   )rD   )r'   pr3   s     r   r*   z$BuildFileTargets.<locals>.<listcomp>?  s)    	?	?	?IaLLJ$>$>!$>$>$>r   r   )target_listr3   s    `r   BuildFileTargetsr   <  s      
@	?	?	?[	?	?	??r   c                 L    t          | |          }t          ||          }||z   S )zNReturns all targets (direct and dependencies) for the specified build_file.
  )r   r   )r   r   r3   	bftargets
deptargetss        r   
AllTargetsr   B  s-     {J77)$\9==*	Z	r   c                 B      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dS )WriteOnDiff.<locals>.Writerz?Wrapper around file which only covers the target if it differs.c                 ^   t          j        dt          j                                      d         dz   t          j                                      d                   \  }| _        	 t          j        |d          | _        d S # t          $ r t          j	        | j                    w xY w)Nz.tmpr   z.gyp.r   )suffixprefixdirw)
tempfilemkstempr7   r8   rW   tmp_pathfdopentmp_file	Exceptionunlink)r   tmp_fdfilenames     r   r   z$WriteOnDiff.<locals>.Writer.__init__V  s    &.x((+g5gmmH%%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                                          d}	 t          j        | j        d          }n-# t
          $ r }|j        t          j        k    r Y d }~nd }~ww xY w|rt          j	        | j                   d S t          j
        d          }t          j
        |           t          j        | j        d| z             t          j        dk    r3t          j                                      rt          j                   t          j        | j                   d S # t$          $ r t          j	        | j                    w xY w)NF?   i  rO   )r   closefilecmpcmpr   OSErrorerrnoENOENTr7   r   umaskchmodrS   rT   r8   existsremoverenamer   )r   samer    r   r   s       r   r   z!WriteOnDiff.<locals>.Writer.closeg  sU   &	T]He<<$$ 	 	 	W$$ %$$$$	  	- )DM
"
"
"
"
" (4..%
(5///
(4=%5&.
1
1
1\W$$)A)A$ Ih
)DM8
,
,
,
,
,   
	$-   s8   D* ; D* 
A%A D*  A%%D* B#D* *%EN)r   r   r   r   r   r   r   )r   s   r   Writerr   T  s\        II    . . .' ' ' ' ' ' 'r   r   )object)r   r   s   ` r   WriteOnDiffr   J  sE    : : : : : : :v : : :x 
/r   c                     	 t          j        t           j                            |                      dS # t          $ r Y dS w xY w)z*Make sure the directory for |path| exists.N)r7   makedirsr8   r;   r   )r8   s    r   EnsureDirExistsr     sM    	K%%&&&&&	 	 	 	DD	s   15 
AAc                 8   dddd}d| v r| d         S t           j        |v r|t           j                 S t           j                            d          rdS t           j                            d          rdS t           j                            d          rdS t           j                            d	          rd	S t           j                            d
          rd
S t           j                            d          rdS t           j                            d          rdS dS )zFReturns |params.flavor| if it's set, the system's default flavor else.winmac)cygwinrO   darwinflavorsunossolarisfreebsdopenbsdnetbsdaixzosos390linux)rS   rT   
startswith)paramsflavorss     r   	GetFlavorr     s     ' (\W3<  \W%% 9\Y'' 9\Y'' 9\X&& 8\U## 5\U## 5\W%% 5	r   c           	         ddddd                     | d          }|sdS t          j                            t          j                            t          j                            t                              d|z            }t          |          5 }|                                }ddd           n# 1 swxY w Y   d}|                     dd          }| dk    r
|r|d	|z  z  }t          j                            |d
|z            }	t          |	d          5 }
|
	                    d                    |d         |g|dd         z                        ddd           n# 1 swxY w Y   t          j
        |	d           dS )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   rP   r   r   i  )r   r7   r8   r:   r;   rR   __file__open	readlineswriter   )r   out_pathgenerator_flagsr   source_pathsource_filesourceheaderr   	tool_path	tool_files              r   CopyToolr     s    	 
 	FD 	 
 
F goobgooh//00,2GI I+K %K""$$F% % % % % % % % % % % % % % % 0&&**+>EEu__*_
>
 F gll8]V%;<<)Is 3yOO
F#fQRRj0113 3 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3
 (9es$   B22B69B6<E  E$'E$c                 v    |d }i }g }| D ],} ||          }||v rd||<   |                     |           -|S )Nc                     | S r   r   )xs    r   <lambda>zuniquer.<locals>.<lambda>  s    ! r   r   )rv   )seqidfunseenr   itemmarkers         r   uniquerr     sb    }DF  tT>>8VdMr   c                   T    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dS )
OrderedSetNc                 H    g x| _         }|d ||gz  }i | _        || |z  } d S d S r   )endmap)r   iterabler   s      r   r   zOrderedSet.__init__  sB    DHsD#sCDH
hddd r   c                 *    t          | j                  S r   )r   r   r   s    r   __len__zOrderedSet.__len__  s    tx==r   c                     || j         v S r   )r   )r   keys     r   __contains__zOrderedSet.__contains__  s    $(?r   c                 h    || j         vr(| j        }|d         }|||gx|d<   x|d<   | j         |<   d S d S )Nr   r/   )r   r   )r   r   r   currs       r   r   zOrderedSet.add   sO    
$(HcVd*-tS)99d1g9A# r   c                 l    || j         v r*| j                             |          \  }}}||d<   ||d<   d S d S )Nr/   r   )r   r~   )r   r   	prev_item	next_items       r   discardzOrderedSet.discard  sD    
dh"&(,,s"3"3c9iililll r   c              #   `   K   | j         }|d         }||ur|d         V  |d         }||ud S d S )Nr/   r   r   r   r   r   s      r   __iter__zOrderedSet.__iter__  H      
(Cq6D
c//Gmmm!Wd c//////r   c              #   `   K   | j         }|d         }||ur|d         V  |d         }||ud S d S )Nr   r   r   r   s      r   __reversed__zOrderedSet.__reversed__  r   r   Tc                     | st          d          |r| j        d         d         n| j        d         d         }|                     |           |S )Nzset is emptyr   r   r/   )r   r   r   )r   lastr   s      r   r~   zOrderedSet.pop  sQ     %^$$$ 
4$(1+a..dhqk!nCLLJr   c                 b    | s| j         j        dS | j         j        dt          |           dS )Nz()())	__class__r   rw   r   s    r   __repr__zOrderedSet.__repr__"  s>     1~...00~...T



;;r   c                     t          |t                    r@t          |           t          |          k    ot          |           t          |          k    S t	          |           t	          |          k    S r   )rk   r   r   rw   r}   )r   others     r   __eq__zOrderedSet.__eq__'  sY    %$$ CYY#e**$BdtE{{)BBt99E

""r   c                 B    |D ]}|| vr|                      |           d S r   )r   )r   r   is      r   r   zOrderedSet.update-  s4      	
$ r   r   T)r   r   r   r   r   r   r   r   r   r   r~   r  r	  r   r   r   r   r   r     s               : : :         < < <
# # #    r   r   c                       e Zd ZdZd Zd ZdS )
CycleErrorz9An exception raised when an unexpected cycle is detected.c                     || _         d S r   )nodes)r   r  s     r   r   zCycleError.__init__5  s    DJJJr   c                 0    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  s8        A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d S                     |                                |             |           D ]} |                               |                                d|            d S rB   )r  r   r   insert)nodeneighborVisit	get_edgesordered_nodesvisitedvisitings     r   r  z"TopologicallySorted.<locals>.VisitT  s    xx   wfKKLLIdOO  eHooooOODD!!!!!r   )r   r}   sorted)graphr  r  r  r  r  r  s    ` @@@@r   TopologicallySortedr  ;  s    * i  )EE'UU(-
" 
" 
" 
" 
" 
" 
" 
" 
" Umm  d	E$KKKK	r   c                     t           j                            d          pt           j                            d          pt           j                            d          p{t           j                            d          p\t           j                            d          p=t           j                            d          pt           j                            d          S )NGYP_CROSSCOMPILEAR_hostCC_hostCXX_host	AR_target	CC_target
CXX_target)r7   rF   r   r   r   r   CrossCompileRequestedr(  c  s     *..+
,
, '
*..
#
#'
*..
#
#' *..
$
$' *..
%
%	'
 *..
%
%' *..
&
&(r   r  r   ),
__future__r   r   r   os.pathr7   rn   r   rS   	six.movesr   r   r   r   r   r"   r,   r&   r@   rD   rJ   rM   r=   rc   re   rh   compilerl   rp   rt   ry   r   r   r   r   r   r   r   r   
MutableSetr   r  r  r(  r   r   r   <module>r.     s  
 & % % % % %    				  



 % % % % % %

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