
    擖g4v                         S 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rSSKrSSK	r	SSK
r
SSKrSSKrS r " S S5      rS rS r\S:X  a&  \R$                  " \" \R&                  S	S 5      5        gg)
zUtility functions to perform Xcode-style build steps.

These functions are executed via gyp-mac-tool when using the Makefile generator.
    Nc                 n    [        5       nUR                  U 5      nUb  [        R                  " U5        g g N)MacToolDispatchsysexit)argsexecutor	exit_codes      ./usr/lib/python3/dist-packages/gyp/mac_tool.pymainr      s0    yH!!$'I     c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!g )!r   !   zThis class performs all the Mac tooling steps. The methods can either be
executed directly, or dispatched from an argument list.c                     [        U5      S:  a  [        S5      eSU R                  US   5      -  n[        X5      " USS 6 $ )z(Dispatches a string command to a method.   zNot enough argumentszExec%sr   N)len	Exception_CommandifyNamegetattr)selfr	   methods      r   r   MacTool.Dispatch%   sH    t9q=233D00a99t$d12h//r   c                 B    UR                  5       R                  SS5      $ )z<Transforms a tool name like copy-info-plist to CopyInfoPlist- )titlereplace)r   name_strings     r   r   MacTool._CommandifyName-   s      "**333r   c                    US:H  n[         R                  R                  U5      S   R                  5       n[         R                  R	                  U5      (       aQ  [         R                  R                  U5      (       a  [        R                  " U5        [        R                  " X5        OUS:X  a  U R                  X5      $ US:X  a  U R                  X5      $ US:X  a  U(       d  U R                  X5        OP[         R                  R                  U5      (       a  [         R                  " U5        [        R                  " X5        U(       a  US;   a  U R                  U5        ggg)zpCopies a resource file to the bundle/Resources directory, performing any
necessary compilation on each resource.Truer   z.xibz.storyboard.strings)z.plistr#   N)ospathsplitextlowerisdirexistsshutilrmtreecopytree_CopyXIBFile_CopyStringsFileunlinkcopy_ConvertToBinary)r   sourcedestconvert_to_binary	extensions        r   ExecCopyBundleResourceMacTool.ExecCopyBundleResource1   s    .7GG$$V,Q/557	77==  
 ww~~d##d#OOF)& $$V22-'$$V22*$->!!&/ww~~d##		$KK%.D!D!!$' "Er   c           	         [         R                  R                  [         R                  R                  [        5      5      n[         R                  R                  U5      (       a  [         R                  R                  X15      n[         R                  R                  U5      (       a  [         R                  R                  X25      n/ SQn[         R                  S   S:  au  UR                  S/5        S[         R                  ;   a)  UR                  SSSSS	[         R                  S   /5        O&UR                  SS
S	[         R                  S   /5        UR                  SSSX!/5        [        R                  " S5      n[        R                  " S5      n [        R                  " U5      nSn	UR!                  5        HT  n
UR#                  U
5      (       a  U
n	M  UR#                  U
5      (       a  M5  U	(       a  [        U	5        Sn	[        U
5        MV     g! [        R                   a  n[        UR                  5        e SnAff = f)zBCompiles a XIB file with ibtool into a binary plist in the bundle.)xcrunibtool--errors
--warnings	--noticesXCODE_VERSION_ACTUAL0700z--auto-activate-custom-fontsIPHONEOS_DEPLOYMENT_TARGET--target-deviceiphoneipad--minimum-deployment-targetmacMACOSX_DEPLOYMENT_TARGET--output-formathuman-readable-text	--compilez/\*.*\*/z .*note:.*is clipping its contentNr   )r$   r%   dirnamerealpath__file__relpathjoinenvironextendrecompile
subprocesscheck_outputCalledProcessErrorprintoutput
splitlinesmatch)r   r2   r3   baser	   ibtool_section_re	ibtool_restdoutecurrent_section_headerlines              r   r-   MacTool._CopyXIBFileL   s    wwrww//9:77??6""WW\\$/F77??4  77<<+DI::,-6KK789+rzz9) )5

#?@	 )5

#=>	 	 5{DQ	
 JJ{3JJBC		,,T2F "&%%'D &&t,,)-&__T**)01-1*d (  ,, 	!((O	s   H I	.II	c           	      <    [         R                  " SSSSSX/5        g )Nr9   plutil-convertbinary1-o)rS   
check_call)r   r3   s     r   r1   MacTool._ConvertToBinary   s     h
ItTH	
r   c                    U R                  U5      =(       d    SnSSKn[        US5       nUR                  5       nSSS5        UR	                  SW[        U5      5      nUR                  SUSS5      u  pU	(       a  g[        US5       n
U
R                  UR                  U5      R                  S5      5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zFCopies a .strings file using iconv to reconvert the input into UTF-16.UTF-8r   NrbwbUTF-16)
_DetectInputEncodingCoreFoundationopenreadCFDataCreater   CFPropertyListCreateFromXMLDatawritedecodeencode)r   r2   r3   
input_codero   in_filesd_errorfps              r   r.   MacTool._CopyStringsFile   s    ..v6A'
 	&$7A  ''aQ8!AA$1dS$HHQXXj)00:;    s   C
0C
C
C"c                 0   [        US5       n UR                  S5      n SSS5        WR                  S5      (       a  gUR                  S5      (       a  gUR                  S5      (       a  gg! [         a     SSS5        gf = f! , (       d  f       Nl= f)	z}Reads the first few bytes from file_name and tries to guess the text
encoding. Returns None as a guess if it can't detect it.rk      Ns   rm   s   s   ﻿rj   )rp   rq   r   
startswith)r   	file_namer}   headers       r   rn   MacTool._DetectInputEncoding   s     )T"b #
 [)){++//  	 #" #"s(   BA//
B9BBB
Bc                    [        U5       nUR                  5       nSSS5        [        R                  " W5      nU(       a(  UR	                  [
        R                  " US   5      5        [        R                  " U5      n[        R                  " S5      n[        R                   H  n	U	R                  S5      (       a  M  SU	-  n
[        R                  U	   nUR                  XjU5      nSU	-  n
UR                  S[        R                  U	   5      nUR                  XjU5      nSU	-  n
UR                  S[        R                  U	   5      nUR                  XjU5      nM     UR                  5       n[!        [#        U5      5       H6  nXl   R%                  5       R                  S	5      (       d  M+  SXl'   SXlS
-
  '   M8     SR'                  S U 5       5      n[        US5       nUR)                  U5        SSS5        U R+                  U5        US:X  a  U R-                  U5        gg! , (       d  f       GN= f! , (       d  f       NJ= f)zCCopies the |source| Info.plist to the destination directory |dest|.Nr   z[_/\s]r{   z${%s}z${%s:identifier}z${%s:rfc1034identifier}r   z
<string>${r   
c              3   .   #    U  H  oc  M  Uv   M     g 7fr    ).0r`   s     r   	<genexpr>,MacTool.ExecCopyInfoPlist.<locals>.<genexpr>   s     E54$$5s   	wr"   )rp   rq   plistlibreadPlistFromStringupdatejsonloadswritePlistToStringrQ   rR   r$   rO   r   r   subrX   ranger   striprN   rt   _WritePkgInfor1   )r   r2   r3   r4   keysfdlinesplistIDENT_REkeyevarevalueis                r   ExecCopyInfoPlistMacTool.ExecCopyInfoPlist   s    &\RGGIE  ,,U3LLDG,-++E2 ::i(::C~~c""S=DZZ_FMM%v6E &+D\\#rzz#7FMM%v6E,s2D\\#rzz#7FMM%v6E' ,   "s5z"Ax~~**<88#!e # 		E5EE $_HHUO 
 	4 &!!$' 'c \T _s   H)%H;)
H8;
I	c                    [         R                  " U5      nU(       d  gUS   nUS:w  a  gUR                  SS5      n[        U5      S:w  a  Sn[        R
                  R                  [        R
                  R                  U5      S5      n[        US5       nUR                  U U 35        SSS5        g! , (       d  f       g= f)	z@This writes the PkgInfo file from the data stored in Info.plist.NCFBundlePackageTypeAPPLCFBundleSignaturez????   PkgInfor   )
r   	readPlistgetr   r$   r%   rN   rJ   rp   rt   )r   
info_plistr   package_typesignature_coder3   r}   s          r   r   MacTool._WritePkgInfo   s    "":. 236!
 #6?~!#$Nww||BGGOOJ7C$_HH~n%567 __s   B66
Cc                    [         R                  " U[         R                  [         R                  -  [         R                  -  S5      n[
        R                  " U[
        R                  5        [        R                  " U5      $ )z5Emulates the most basic behavior of Linux's flock(1).i  )
r$   rp   O_RDONLYO_NOCTTYO_CREATfcntlflockLOCK_EXrS   call)r   lockfilecmd_listr   s       r   	ExecFlockMacTool.ExecFlock   sM     WWXr{{R[[82::EuMB&x((r   c                    [         R                  " S5      n[         R                  " S5      n[        R                  R	                  5       nSUS'   [
        R                  " U[
        R                  US9nUR                  5       S   R                  S5      nUR                  5        HK  nUR                  U5      (       a  M  UR                  U5      (       a  M3  [        U[        R                  S9  MM     UR                  (       dl  [!        [#        U5      S-
  5       HQ  nX   S	:X  d  M  XS-      R%                  S
5      (       d  M*  [        R&                  " XS-      S5          UR                  $    UR                  $ )zMCalls libtool and filters out '/path/to/libtool: file: foo.o has no
symbols'.z?^.*libtool: (?:for architecture: \S* )?file: .* has no symbols$z^.*libtool: warning for library: .* the table of contents is empty \(no object file members in the library define global symbols\)$1ZERO_AR_DATE)stderrenvr   zutf-8filerf   z.aN)rQ   rR   r$   rO   r0   rS   PopenPIPEcommunicateru   rX   rY   rV   r   r   
returncoder   r   endswithutime)	r   r   
libtool_relibtool_re5r   
libtoolouterrr`   r   s	            r   ExecFilterLibtoolMacTool.ExecFilterLibtool  s3    ZZR

 jjR

 jjoo
 "N%%hzCP
$$&q)009NN$D##D))+2C2CD2I2Id, %
 $$3x=1,-;$&8E?+C+CD+I+IHHX!e_d3$$$	 . $$$r   c                    [         R                  R                  U5      R                  S5      S   n[         R                  R	                  US5      n[         R                  R                  U5      (       d  [         R                  " U5        SU< SU< S3n[        [         R                  R	                  US5      S5       nUR                  U5        S S S 5        g ! , (       d  f       g = f)	N.r   Moduleszframework module z {
  umbrella header "z*.h"

  export *
  module * { export * }
}
zmodule.modulemapr   )	r$   r%   basenamesplitrN   r)   mkdirrp   rt   )r   	frameworkbinarymodule_pathmodule_templatemodule_files         r   ExecPackageIosFrameworkMacTool.ExecPackageIosFramework#  s    !!),2237:ggll9i8ww~~k**HH[! V% 	 "'',,{,>?Eo. FEEs   C
C*c                    [         R                  R                  U5      R                  S5      S   nSnSnSn[         R                  R	                  [         R                  R                  XX#5      5      (       d  g[         R                  " 5       n[         R                  " U5        U R                  U[         R                  R                  Xd5      5        U R                  [         R                  R                  XdU5      U5        U R                  [         R                  R                  XdU5      U5        [         R                  " U5        g)zaTakes a path to Something.framework and the Current version of that and
sets up all the symlinks.r   r   Current	ResourcesVersionsN)	r$   r%   r   r   r)   rN   getcwdchdir_Relink)r   r   versionr   CURRENT	RESOURCESVERSIONSpwds           r   ExecPackageFrameworkMacTool.ExecPackageFramework5  s     !!),2237:	ww~~bggll9PQQ  iik
 	Wbggll8=> 	RWW\\(V<fERWW\\(Y?K 	r   c                     [         R                  R                  U5      (       a  [         R                  " U5        [         R                  " X5        g)zVCreates a symlink to |dest| named |link|. If |link| already exists,
it is overwritten.N)r$   r%   lexistsremovesymlink)r   r3   links      r   r   MacTool._RelinkR  s.     77??4  IIdO


4r   c                    [         R                  R                  U5      R                  S5      S   nU Vs/ s H"  n[         R                  R	                  U5      PM$     nn0 nU HG  n[         R                  R                  U5      nXVU'   XV[         R                  R                  XG5      '   MI     [        X5        g s  snf )Nr   r   )r$   r%   r   r   abspathrN   	WriteHmap)r   outr   all_headersframework_namer   filelistfilenames           r    ExecCompileIosFrameworkHeaderMap(MacTool.ExecCompileIosFrameworkHeaderMapY  s    )))4::3?B=HI[6rwwv.[I!Fww''/H!'X?ERWW\\.;< " 	#  Js   )B<c           
      n   [         R                  R                  US5      n[         R                  R                  U5      (       d  [         R                  " U5        U HU  n[
        R                  " U[         R                  R                  U[         R                  R                  U5      5      5        MW     g )NHeaders)r$   r%   rN   r)   makedirsr*   r0   r   )r   r   copy_headersheader_pathr   s        r   ExecCopyIosFrameworkHeaders#MacTool.ExecCopyIosFrameworkHeadersc  sk    ggll9i8ww~~k**KK$"FKK["'':J:J6:R ST #r   c                 V   / SQnS[         R                  ;   nU(       a  [         R                  S   R                  S5      S   nUS;  a  SnUR                  SUS	S
S	SS[         R                  S   S[         R                  R                  [         R                  S   5      /
5        OXUR                  SSS	SS[         R                  S   S[         R                  R                  [         R                  S   5      /5        U(       a  [        R                  " U5      nUR                  5        H  u  pgSU-   n[        U[        5      (       a  U(       a  UR                  U5        M9  M;  [        U[        5      (       a6  U H.  n	UR                  U5        UR                  [        U	5      5        M0     M  UR                  U5        UR                  [        U5      5        M     UR                  [        [         R                  R
                  U5      5        [        R                   " U5        g)a  Compiles multiple .xcassets files into a single .car file.

This invokes 'actool' to compile all the inputs .xcassets files. The
|keys| arguments is a json-encoded dictionary of extra arguments to
pass to 'actool' when the asset catalogs contains an application icon
or a launch image.

Note that 'actool' does not create the Assets.car file if the asset
catalogs does not contains imageset.
)r9   actoolrG   rH   z--compress-pngsr=   r<   r;   r@   CONFIGURATIONr   )iphoneosiphonesimulatorr  z
--platformrA   rB   rC   rD   rI   CONTENTS_FOLDER_PATHmacosxrE   rF   !UNLOCALIZED_RESOURCES_FOLDER_PATHz--N)r$   rO   r   rP   r%   r   r   r   items
isinstanceboolappendliststrmaprS   rg   )
r   r   inputscommand_lineis_iphone_targetplatformr   valuearg_namevs
             r   ExecCompileXcassetsMacTool.ExecCompileXcassetsj  s   	
 82::Ezz/288=bAH>>, %%1JJ;<GGOOBJJ/E$FG  %1JJ9:GGOOBJJ/R$ST	 ::d#D"jjl
#:eT**$++H5 t,,"$++H5$++CF3 # !''1 ''E
3 + 	C89l+r   c                     0 nU H%  nU R                  U5      nU R                  X55        M'     [        R                  " X15        g)z6Merge multiple .plist files into a single .plist file.N)_LoadPlistMaybeBinary_MergePlistr   
writePlist)r   rW   r  merged_plistr%   r   s         r   ExecMergeInfoPlistMacTool.ExecMergeInfoPlist  s?    D..t4E\1  	L1r   c                 "   U R                  X0R                  5       5      u  pgU R                  X&U5      nSSSU/n	US:X  a  U	R                  SS/5        OU	R                  SU/5        U	R                  SU/5        [        R
                  " U	5        g	)
aQ  Code sign a bundle.

This function tries to code sign an iOS bundle, following the same
algorithm as Xcode:
  1. pick the provisioning profile that best match the bundle identifier,
     and copy it into the bundle as embedded.mobileprovision,
  2. copy Entitlements.plist from user or SDK next to the bundle,
  3. code sign the bundle.
codesignz--forcez--signr"   z--deepz+--preserve-metadata=identifier,entitlementsz--entitlementsz--timestamp=noneN)_InstallProvisioningProfile_GetCFBundleIdentifier_InstallEntitlementsrP   rS   rg   )
r   r   entitlementsprovisioningr%   preservesubstitutions	overridesentitlements_pathr	   s
             r   ExecCodeSignBundleMacTool.ExecCodeSignBundle  s     $(#C#C557$
  !55
 Ix5vKK#PQRKK)+<=>'./d#r   c                    U R                  X5      u  p4n[        R                  R                  [        R                  S   [        R                  S   S5      n[
        R                  " X65        U R                  X%S-   5      nXtS   4$ )a  Installs embedded.mobileprovision into the bundle.

Args:
  profile: string, optional, short name of the .mobileprovision file
    to use, if empty or the file is missing, the best file installed
    will be used
  bundle_identifier: string, value of CFBundleIdentifier from Info.plist

Returns:
  A tuple containing two dictionary: variables substitutions and values
  to overrides when generating the entitlements file.
BUILT_PRODUCTS_DIRr  zembedded.mobileprovisionr   Entitlements)_FindProvisioningProfiler$   r%   rN   rO   r*   copy2_GetSubstitutions)r   profilebundle_identifiersource_pathprovisioning_datateam_idtarget_pathr'  s           r   r!  #MacTool._InstallProvisioningProfile  s~     372O2O3
/ ggllJJ+,JJ-.&

 	[.../@C-P???r   c                    [         R                  R                  [         R                  S   SSS5      n[         R                  R	                  U5      (       d1  [        SU-  [        R                  S9  [        R                  " S5        SnU(       aI  [         R                  R                  X1S	-   5      n[         R                  R                  U5      (       a  U/nU(       d4  [        R                  " [         R                  R                  US
5      5      n0 nU Hz  nU R                  U5      nUR                  S0 5      R                  SS5      nUR                  S/ 5       H.  n	U	 SU 3n
[        R                  " X5      (       d  M'  UUU	4Xh'   M0     M|     U(       d1  [        SU-  [        R                  S9  [        R                  " S5        [        US S9nXk   $ )a  Finds the .mobileprovision file to use for signing the bundle.

Checks all the installed provisioning profiles (or if the user specified
the PROVISIONING_PROFILE variable, only consult it) and select the most
specific that correspond to the bundle identifier.

Args:
  profile: string, optional, short name of the .mobileprovision file
    to use, if empty or the file is missing, the best file installed
    will be used
  bundle_identifier: string, value of CFBundleIdentifier from Info.plist

Returns:
  A tuple of the path to the selected provisioning profile, the data of
  the embedded plist in the provisioning profile and the team identifier
  to use for code signing.

Raises:
  SystemExit: if no .mobileprovision can be used to sign the bundle.
HOMELibraryMobileDevicezProvisioning Profilesz&cannot find mobile provisioning for %sr   r   Nz.mobileprovisionz*.mobileprovisionr.  zapplication-identifierr   TeamIdentifierr   c                     [        U 5      $ r   r   )r  s    r   <lambda>2MacTool._FindProvisioningProfile.<locals>.<lambda>*  s    c!fr   )r   )r$   r%   rN   rO   r(   rV   r   r   r   r)   glob_LoadProvisioningProfiler   fnmatchmax)r   r2  r3  profiles_dirprovisioning_profilesprofile_pathvalid_provisioning_profilesprofile_dataapp_id_patternteam_identifierapp_idselected_keys               r   r/   MacTool._FindProvisioningProfile  s   * ww||JJv	>;R
 ww}}\**8<MNZZ HHQK $77<<@R6RSLww~~l++)5%$$(II\+>?%! ')#1L88FL)--nbAEE("N $0#3#34Db#I+,A.?-@A??6::$$'C/? $J 2 +8<MNZZ HHQK 6<LM*88r   c           
          [         R                  " 5        n[        R                  " SSSSUSUR                  /5        U R                  UR                  5      sSSS5        $ ! , (       d  f       g= f)zExtracts the plist embedded in a provisioning profile.

Args:
  profile_path: string, path to the .mobileprovision file

Returns:
  Content of the plist embedded in the provisioning profile as a dictionary.
securitycmsz-Dz-irf   N)tempfileNamedTemporaryFilerS   rg   namer  )r   rH  temps      r   rC   MacTool._LoadProvisioningProfile-  sV     ((*d!!UD$dDIIN --dii8	 +**s   AA""
A0c                     UR                  5        Hb  u  p4[        U[        5      (       aD  UR                  U0 5      n[        U[        5      (       a  U R	                  XT5        XQU'   MX  XAU'   M^  XAU'   Md     g)z"Merge |plist| into |merged_plist|.N)r  r	  dictr   r  )r   r  r   r   r  merged_values         r   r  MacTool._MergePlist<  sf    ++-JC%&&+//R8lD11$$\9(4%(-%$)S! (r   c                 x    [         R                  " U5      $ ! [         a     Of = f[        R                  " 5        n[
        R                  " XR                  5        [        R                  " SSSUR                  /5        [         R                  " UR                  5      sSSS5        $ ! , (       d  f       g= f)a]  Loads into a memory a plist possibly encoded in binary format.

This is a wrapper around plistlib.readPlist that tries to convert the
plist to the XML format if it can't be parsed (assuming that it is in
the binary format).

Args:
  plist_path: string, path to a plist file, in XML or binary format

Returns:
  Content of the plist as a dictionary.
rc   rd   xml1N)
r   r   r   rS  rT  r*   r0  rU  rS   rg   )r   
plist_pathrV  s      r   r  MacTool._LoadPlistMaybeBinaryI  s    	 %%j11 		((*dLLYY/!!8Z"KL%%dii0 +**s    
%%A$B++
B9c                     UUS.$ )a.  Constructs a dictionary of variable substitutions for Entitlements.plist.

Args:
  bundle_identifier: string, value of CFBundleIdentifier from Info.plist
  app_identifier_prefix: string, value for AppIdentifierPrefix

Returns:
  Dictionary of substitutions to apply when generating Entitlements.plist.
)CFBundleIdentifierAppIdentifierPrefixr   )r   r3  app_identifier_prefixs      r   r1  MacTool._GetSubstitutionsb  s     #4#8
 	
r   c                     [         R                  R                  [         R                  S   [         R                  S   5      nU R	                  U5      nUS   $ )zExtracts CFBundleIdentifier value from Info.plist in the bundle.

Returns:
  Value of CFBundleIdentifier in the Info.plist located in the bundle.
TARGET_BUILD_DIRINFOPLIST_PATHra  )r$   r%   rN   rO   r  )r   info_plist_pathinfo_plist_datas      r   r"  MacTool._GetCFBundleIdentifierq  sM     '',,JJ)*BJJ7G,H
 44_E344r   c                    Un[         R                  R                  [         R                  S   [         R                  S   S-   5      nU(       d1  [         R                  R                  [         R                  S   S5      n[        R
                  " XE5        U R                  U5      nU R                  Xb5      nU(       a  U H  nXv;  d  M
  X7   Xg'   M     [        R                  " Xe5        U$ )a/  Generates and install the ${BundleName}.xcent entitlements file.

Expands variables "$(variable)" pattern in the source entitlements file,
add extra entitlements defined in the .mobileprovision file and the copy
the generated plist to "${BundlePath}.xcent".

Args:
  entitlements: string, optional, path to the Entitlements.plist template
    to use, defaults to "${SDKROOT}/Entitlements.plist"
  substitutions: dictionary, variable substitutions
  overrides: dictionary, values to add to the entitlements

Returns:
  Path to the generated entitlements file.
r-  PRODUCT_NAMEz.xcentSDKROOTzEntitlements.plist)
r$   r%   rN   rO   r*   r0  r  _ExpandVariablesr   r  )r   r$  r'  r(  r4  r7  datar   s           r   r#  MacTool._InstallEntitlements}  s      #ggllJJ+,bjj.H8.S
 '',,rzz)'<>RSK[.))+6$$T9 ? )DI ! 	D.r   c                    [        U[        5      (       a0  UR                  5        H  u  p4UR                  SU-  U5      nM     U$ [        U[        5      (       a!  U Vs/ s H  oPR                  XR5      PM     sn$ [        U[        5      (       a%  U Vs0 s H  ofU R                  X   U5      _M     sn$ U$ s  snf s  snf )aZ  Expands variables "$(variable)" in data.

Args:
  data: object, can be either string, list or dictionary
  substitutions: dictionary, variable substitutions to perform

Returns:
  Copy of data where each references to "$(variable)" has been replaced
  by the corresponding value found in substitutions, or left intact if
  the key was not found.
z$(%s))r	  r  r  r   r  rn  rY  )r   ro  r'  r   r  r  ks          r   rn  MacTool._ExpandVariables  s     dC  +113
||GcM59 4KdD!!EIJT))!;TJJdD!!NRSdt,,TWmDDdSS KSs   B8B=r   N)"__name__
__module____qualname____firstlineno____doc__r   r   r6   r-   r1   r.   rn   r   r   r   r   r   r   r   r   r   r  r  r*  r!  r/  rC  r  r  r1  r"  r#  rn  __static_attributes__r   r   r   r   r   !   s    =04(67r

<*"5(n8,)%>/$:!UF,P2$2@2?9B9*12

5@r   r   c                 (    SU R                  5       -  $ )N   )
bit_length)xs    r   NextGreaterPowerOf2r~    s       r   c                    SnSnSn[        U5      n[        U5      nSSU-  -   n[        S UR                  5        5       5      n[	        U S5      n	U	R                  [        R                  " SUUUUUUU5      5        S	/U-  n
UR                  5        HW  u  pSnU H"  nU[        UR                  5       5      S
-  -  nM$     XUS-
  -     b  US-   nXUS-
  -     b  M  X4XUS-
  -  '   MY     SnU
 H  nUc*  U	R                  [        R                  " SSSS5      5        M0  Uu  pUnU[        U5      -   S-   nU[        [        R                  R                  U5      [        R                  -   5      -   S-   nU[        [        R                  R                  U5      5      -   S-   nU	R                  [        R                  " SUUU5      5        M     U	R                  [        R                  " S5      5        U
 GHd  nUc  M	  Uu  pU	R                  [        R                  " S[        U5      -  U5      5        U	R                  [        R                  " SS5      5        [        R                  R                  U5      [        R                  -   nU	R                  [        R                  " S[        U5      -  U5      5        U	R                  [        R                  " SS5      5        [        R                  R                  U5      nU	R                  [        R                  " S[        U5      -  U5      5        U	R                  [        R                  " SS5      5        GMg     g	)a  Generates a header map based on |filelist|.

Per Mark Mentovai:
  A header map is structured essentially as a hash table, keyed by names used
  in #includes, and providing pathnames to the actual files.

The implementation below and the comment above comes from inspecting:
  http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
while also looking at the implementation in clang in:
  https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
ipamhr   r         c              3   8   #    U  H  n[        U5      v   M     g 7fr   r?  )r   r  s     r   r   WriteHmap.<locals>.<genexpr>  s     E3D%3u::3Ds   rl   z<LHHLLLLN   z<LLLz<xz<%dsz<s )r   r~  rE  valuesrp   rt   structpackr  ordr'   r$   r%   rJ   sepr   )output_namer   magicr   	_reservedcountcapacitystrings_offsetmax_value_lengthr   bucketsr   r%   r   cnext_offsetbucket
key_offsetprefix_offsetsuffix_offsetrZ   s                        r   r   r     s    EGIME"5)H2=)NE8??3DEE
{D
!CII		
 fxGnn&
A3qwwy>B&&C  HqL()5'C HqL()5'+lhl"# ' K>IIfkk&!Q23!LT$J&T2Q6M)C0E0N,OORSSM'#bgg.>.>t.D*EEIKIIfkk&*m]ST  IIfkk$ !LTIIfkk&3t9"4d;<IIfkk$-.77??4(2661DIIfkk&3t9"4d;<IIfkk$-.77##D)DIIfkk&3t9"4d;<IIfkk$-. r   __main__r   )rx  r   rD  rB  r   r$   r   rQ   r*   r  rS   r   rS  r   r   r~  r   rt  r   argvr   r   r   <module>r     sx        	  	    
 P
 P
f!G/T zHHT#((12,  r   