ó
    æ“–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)
zˆUtility 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   € Ü‹y€HØ×!Ñ! $Ó'€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   é!   z€This 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   € äˆt‹9�q‹=ÜÐ2Ó3Ð3à˜D×0Ñ0°°a±Ó9Ñ9ˆÜ�tÔ$ d¨1¨2 hÐ/Ð/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        O�U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ÐÜ—G‘G×$Ñ$ VÓ,¨QÑ/×5Ñ5Ó7ˆ	Ü�7‰7�=‰=˜× Ñ ô
 �w‰w�~‰~˜d×#Ñ#Ü—’˜dÔ#Ü�OŠO˜FÕ)Ø˜&Ó Ø×$Ñ$ VÓ2Ð2Ø˜-Ó'Ø×$Ñ$ VÓ2Ð2Ø˜*Ó$Ö->Ø×!Ñ! &Õ/ä�w‰w�~‰~˜d×#Ñ#Ü—	’	˜$”Ü�KŠK˜Ô%æ Ð.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Í  € ô �w‰w�‰œrŸw™w×/Ñ/´Ó9Ó:ˆÜ�7‰7�?‰?˜6×"Ñ"Ü—W‘W—\‘\ $Ó/ˆFÜ�7‰7�?‰?˜4× Ñ Ü—7‘7—<‘< Ó+ˆDâIˆä�:‰:Ð,Ñ-°Ó6Ø�K‰KÐ7Ð8Ô9Ø+¬r¯z©zÓ9Ø—‘à)Ø Ø)ØØ5ÜŸ
™
Ð#?Ñ@ðõ	ð —‘à)ØØ5ÜŸ
™
Ð#=Ñ>ð	ôð 	�‰ØÐ 5°{ÀDÐQô	
ô ŸJšJ {Ó3ÐÜ—J’JÐBÓCˆ	ð	Ü×,Ò,¨TÓ2ˆFð "&ÐØ×%Ñ%Ö'ˆ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 
¨I°t¸TÐ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  p‰U	(       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À$ÈÈ1ÈdÓS‰ˆÞØä�$˜Ô Ø�H‰H�Q—X‘X˜jÓ)×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   é € ÐEª5 4Ÿ$™$ª5ùs   ‚Œ	Ú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Ø—G‘G“IˆE÷ ô ×,Ò,¨UÓ3ˆÞØ�L‰LœŸš D¨¡GÓ,Ô-Ü×+Ò+¨EÓ2ˆô —:’:˜iÓ(ˆÜ—:”:ˆCØ�~‰~˜c×"Ñ"ÙØ˜S‘=ˆDÜ—Z‘Z ‘_ˆFØ—M‘M %¨vÓ6ˆEð &¨Ñ+ˆDØ—\‘\ #¤r§z¡z°#¡Ó7ˆFØ—M‘M %¨vÓ6ˆEà,¨sÑ2ˆDØ—\‘\ #¤r§z¡z°#¡Ó7ˆFØ—M‘M %¨vÓ6ŠEñ' ð, × Ñ Ó"ˆÜ”s˜5“zÖ"ˆAØ‰x�~‰~Ó×*Ñ*¨<×8Ó8Ø�‘Ø#�˜!‘e“ñ #ð —	‘	ÑE©5ÓEÓEˆô �$˜Œ_ Ø�H‰H�UŒO÷ ð
 	×Ñ˜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ä�w‰w�|‰|œBŸG™GŸO™O¨JÓ7¸ÓCˆÜ�$˜Œ_ Ø�H‰H˜�~ 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   € ô �WŠW�XœrŸ{™{¬R¯[©[Ñ8¼2¿:¹:ÑEÀuÓ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  € ô —Z’ZØRó
ˆ
ô —j’jðRó
ˆô
 �j‰j�o‰oÓˆð
 "ˆˆNÑÜ×%Ò% h´z·±ÈCÑPˆ
Ø×$Ñ$Ó& qÑ)×0Ñ0°Ó9ˆØ—N‘NÖ$ˆDØ×#Ñ# D×)Ó)°+×2CÑ2CÀD×2IÓ2IÜ�d¤§¡Ô,ñ %ð
 ×$×$Üœ3˜x›=¨1Ñ,Ö-�Ø‘; $Õ&¨8¸±E©?×+CÑ+CÀD×+IÓ+IÜ—H’H˜X¨!¡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Ñ2°3Ó7¸Ñ:ˆÜ—g‘g—l‘l 9¨iÓ8ˆÜ�w‰w�~‰~˜k×*Ñ*Ü�HŠH�[Ô!øó ›Vð%ð 	ô ”"—'‘'—,‘,˜{Ð,>Ó?ÀÔEÈØ×Ñ˜oÔ.÷ F×EÖEús   Ã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Ñ2°3Ó7¸Ñ:ˆàˆØˆ	Øˆä�w‰w�~‰~œbŸg™gŸl™l¨9ÀÓP×QÑQð ô �iŠi‹kˆÜ
�Š�Ôð 	�‰�WœbŸg™gŸl™l¨8Ó=Ô>ð 	�‰”R—W‘W—\‘\ (°VÓ<¸fÔEØ�‰”R—W‘W—\‘\ (°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.   € ô �7‰7�?‰?˜4× Ñ Ü�IŠI�dŒOÜ
�
Š
�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º[°6”r—w‘w—‘ vÖ.¹[ˆÐIØˆÛ!ˆFÜ—w‘w×'Ñ'¨Ó/ˆHØ!'�XÑØ?E”R—W‘W—\‘\ .Ó;Ó<ñ "ô 	�#Õ ùò 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   € Ü—g‘g—l‘l 9¨iÓ8ˆÜ�w‰w�~‰~˜k×*Ñ*Ü�KŠK˜Ô$Û"ˆFÜ�KŠK˜¤§¡§¡¨[¼"¿'¹'×:JÑ:JÈ6Ó: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À  € ò	
ˆð 8¼2¿:¹:ÑEÐÞÜ—z‘z /Ñ2×8Ñ8¸Ó=¸bÑAˆHØÐ>Ó>Ø,�Ø×Ñà ØØ%ØØ%ØØ1Ü—J‘JÐ;Ñ<ØÜ—G‘G—O‘O¤B§J¡JÐ/EÑ$FÓGðõð ×Ñà ØØ%ØØ1Ü—J‘JÐ9Ñ:ØÜ—G‘G—O‘O¤B§J¡JÐ/RÑ$SÓTð	ôö Ü—:’:˜dÓ#ˆDØ"Ÿj™jžl‘
�Ø #™:�Ü˜e¤T×*Ñ*ÞØ$×+Ñ+¨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Ó4ˆEØ×Ñ˜\Ö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Ø¨ó
Ðð ˜I x°Ð5ˆØ�vÓØ�K‰K˜Ð#PÐQÕRà�K‰KÐ)Ð+<Ð=Ô>Ø�‰Ð'¨Ð.Ô/Ü×Ò˜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~   € ð 37×2OÑ2OØó3
Ñ/ˆ¨ô —g‘g—l‘lÜ�J‰JÐ+Ñ,Ü�J‰JÐ-Ñ.Ø&ó
ˆô
 	�Š�[Ô.Ø×.Ñ.Ð/@È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                  " X¨5      (       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�  € ô* —w‘w—|‘|Ü�J‰J�vÑ 	¨>Ð;Ró
ˆô �w‰w�}‰}˜\×*Ñ*ÜØ8Ð<MÑNÜ—Z‘Zòô �HŠH�QŒKØ $ÐÞÜŸ7™7Ÿ<™<¨Ð@RÑ6RÓSˆLÜ�w‰w�~‰~˜l×+Ñ+Ø)5¨Ð%Þ$Ü$(§I¢IÜ—‘—‘˜\Ð+>Ó?ó%Ð!ð ')Ð#Û1ˆLØ×8Ñ8¸ÓFˆLØ)×-Ñ-¨n¸bÓA×EÑEØ(¨"óˆNð $0×#3Ñ#3Ð4DÀbÖ#I�Ø+Ð,¨AÐ.?Ð-@ÐA�Ü—?’? 6×:Ó:à$Ø$Ø'ðCÐ/Ó?ó $Jñ 2ö +ÜØ8Ð<MÑNÜ—Z‘Zòô �HŠH�QŒKô Ð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)zÏExtracts 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Ü×!Ò!Ø˜U D¨$°¸dÀDÇIÁIÐNôð ×-Ñ-¨d¯i©iÓ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   € àŸ+™+ž-‰JˆCÜ˜%¤×&Ñ&Ø+×/Ñ/°°RÓ8�Ü˜l¬D×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Ü�LŠL˜§Y¡YÔ/Ü×!Ò! 8¨Z¸ÀÇÁÐ"KÔLÜ×%Ò% d§i¡iÓ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   $ )z’Extracts 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   € ô Ÿ'™'Ÿ,™,Ü�J‰JÐ)Ñ*¬B¯J©JÐ7GÑ,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¸   € ð  #ˆÜ—g‘g—l‘lÜ�J‰JÐ+Ñ,¬b¯j©j¸Ñ.HÈ8Ñ.Só
ˆö ÜŸ'™'Ÿ,™,¤r§z¡z°)Ñ'<Ð>RÓSˆKÜ�Š�[Ô.Ø×)Ñ)¨+Ó6ˆØ×$Ñ$ TÓ9ˆÞÛ �Ø•?Ø )¡�D“Iñ !ô 	×Ò˜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¬   € ô �dœC× Ñ Ø+×1Ñ1Ö3‘
�Ø—|‘| G¨c¡M°5Ó9’ñ 4àˆKÜ�dœD×!Ñ!ÙEIÓJÂTÀ×)Ñ)¨!Ö;ÁTÑJÐJÜ�dœD×!Ñ!ÙNRÓSÊdÈ�t×,Ñ,¨T©W°mÓDÒDÉdÑ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?9òB9ò*ò1ò2
ò
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  p¼SnU H"  nU[        UR                  5       5      S
-  -  nM$     X­US-
  -     b  US-   nX­US-
  -     b  M  X¼4X­US-
  -  '   MY     SnU
 HÜ  nUc*  U	R                  [        R                  " SSSS5      5        M0  Uu  p¼U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  p¼U	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   é € ÐEÒ3D¨%œ3˜uŸ:˜:Ò3Dùs   ‚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Ü�‹M€EÜ" 5Ó)€HØ˜2 ™=Ñ)€NÜÑE°8·?±?Ô3DÓEÓEÐä
ˆ{˜DÓ
!€CØ‡I�IÜ�ŠØØØØØØØØó		
ôð ˆf�xÑ€GØ—n‘nÖ&‰
ˆØˆÛˆAØ”3�q—w‘w“y“> BÑ&Ñ&ŠCñ ð ˜H q™LÑ(Ñ)Ñ5Ø˜‘'ˆCð ˜H q™LÑ(Ñ)Ó5à'+ lˆ�h ‘lÑ"Ó#ñ 'ð €KÛˆØ‰>Ø�I‰I”f—k’k &¨!¨Q°Ó2Ö3à!‰LˆTØ$ˆJØ&¬¨T«Ñ2°QÑ6ˆMØ)¬C´·±·±ÀÓ0EÌÏÉÑ0NÓ,OÑOÐRSÑSˆMØ'¬#¬b¯g©g×.>Ñ.>¸tÓ.DÓ*EÑEÈÑIˆKØ�I‰I”f—k’k &¨*°mÀ]ÓSÖTñ ð ‡I�IŒf�kŠk˜$ÓÔ äˆØÓØ!‰LˆTØ�I‰I”f—k’k &¬3¨t«9Ñ"4°dÓ;Ô<Ø�I‰I”f—k’k $¨Ó-Ô.Ü—7‘7—?‘? 4Ó(¬2¯6©6Ñ1ˆDØ�I‰I”f—k’k &¬3¨t«9Ñ"4°dÓ;Ô<Ø�I‰I”f—k’k $¨Ó-Ô.Ü—7‘7×#Ñ# DÓ)ˆDØ�I‰I”f—k’k &¬3¨t«9Ñ"4°dÓ;Ô<Ø�I‰I”f—k’k $¨Ó-×.ò 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ÓØ‡H‚H‰T�#—(‘(˜1˜2�,ÓÕ ð r   