Ë
    !åhiA€  ã                   ó„  — d 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m	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ ddlmZ ddlZddlmZ ddlmZ  ej<                  e«      Z d„ Z!d„ Z"d„ Z#d	„ Z$d
„ Z%d„ Z&d„ Z'de(de)fd„Z*d„ Z+d„ Z,d„ Z-d„ Z. G d„ de/«      Z0 G d„ de/«      Z1d„ Z2d"d„Z3d„ Z4d"d„Z5d„ Z6d#d„Z7d„ Z8d„ Z9d „ Z:d!„ Z;y)$z
Utils for macOS platform.
é    N)ÚLC_BUILD_VERSIONÚLC_CODE_SIGNATUREÚLC_ID_DYLIBÚLC_LOAD_DYLIBÚLC_LOAD_UPWARD_DYLIBÚLC_LOAD_WEAK_DYLIBÚLC_PREBOUND_DYLIBÚLC_REEXPORT_DYLIBÚLC_RPATHÚLC_SEGMENT_64Ú	LC_SYMTABÚLC_UUIDÚLC_VERSION_MIN_MACOSX)ÚMachO)Úcompatc                  ó\   — t        «       } | r t        j                  j                  | «      ryy)z
    Check if Python interpreter was installed via Homebrew command 'brew'.

    :return: True if Homebrew else otherwise.
    TF)Úget_homebrew_prefixr   Úbase_prefixÚ
startswith©Ú
env_prefixs    úAC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/utils/osx.pyÚis_homebrew_envr   .   ó(   € ô %Ó&€JÙ”f×(Ñ(×3Ñ3°JÔ?ØØó    c                  ó\   — t        «       } | r t        j                  j                  | «      ryy)z
    Check if Python interpreter was installed via Macports command 'port'.

    :return: True if Macports else otherwise.
    TF)Úget_macports_prefixr   r   r   r   s    r   Úis_macports_envr   ;   r   r   c                  ó¨   — t        j                  d«      } t        j                  j	                  t        j                  j	                  | «      «      } | S )z9
    :return: Root path of the Homebrew environment.
    Úbrew©ÚshutilÚwhichÚosÚpathÚdirname©Úprefixs    r   r   r   H   ó6   € ô �\‰\˜&Ó!€Fä�W‰W�_‰_œRŸW™WŸ_™_¨VÓ4Ó5€FØ€Mr   c                  ó¨   — t        j                  d«      } t        j                  j	                  t        j                  j	                  | «      «      } | S )z9
    :return: Root path of the Macports environment.
    Úportr!   r'   s    r   r   r   R   r)   r   c                 óÄ   — | j                   D �cg c]   }|d   j                  t        t        hv sŒ|‘Œ" }}t	        |«      dk(  sJ dt	        |«      › d�«       ‚|d   S c c}w )zJ
    Helper that finds the version command in the given MachO header.
    r   é   zNExpected exactly one LC_BUILD_VERSION or LC_VERSION_MIN_MACOSX command, found ú!)ÚcommandsÚcmdr   r   Úlen)Úheaderr0   Úversion_cmds      r   Ú_find_version_cmdr4   \   sr   € ð #)§/¡/Öm˜3°S¸±V·Z±ZÔDTÔVkÐClÒ5l’3Ðm€KÐmÜˆ{Ó˜qÒ ð mØ
XÔY\Ð]hÓYiÐXjÐjkÐlómÐ à�q‰>Ðùò ns
   � A°Ac                 ó|   — t        | «      }|j                  d   }t        |«      }t        |d   j                  «      S )zÙ
    Obtain the version of macOS SDK against which the given binary was built.

    NOTE: currently, version is retrieved only from the first arch slice in the binary.

    :return: (major, minor, revision) tuple
    r   r-   )r   Úheadersr4   Ú_hex_tripletÚsdk)ÚfilenameÚbinaryr2   r3   s       r   Úget_macos_sdk_versionr;   h   s:   € ô �8‹_€FØ�^‰^˜AÑ€Fä# FÓ+€KÜ˜ A™×*Ñ*Ó+Ð+r   c                 ó6   — | dz  dz	  }| dz  dz	  }| dz  }|||fS )Ni  ÿ é   i ÿ  é   éÿ   © )ÚversionÚmajorÚminorÚrevisions       r   r7   r7   w   s6   € à�xÑ BÑ&€EØ�vÑ !Ñ#€EØ˜$‘€HØ�%˜Ð!Ð!r   r9   Úreturnc                 ó(  — g }t        | «      j                  D ]`  }t        |«      }|d   j                  t        k(  r|j                  |d   j                  «       ŒC|j                  |d   j                  «       Œb t        t        t        |«      «      S )z}
    Get the -macosx-version-min used to compile a macOS binary.

    For fat binaries, the minimum version is selected.
    r   r-   )r   r6   r4   r0   r   ÚappendrA   ÚminosÚminÚmapr7   )r9   Úversionsr2   r0   s       r   Úmacosx_version_minrL      s{   € ð €HÜ˜“/×)Ñ)ò *ˆÜ Ó'ˆØˆq‰6�:‰:Ô.Ò.Ø�O‰O˜C ™FŸN™NÕ+ð �O‰O˜C ™FŸL™LÕ)ð*ô Œs”< Ó*Ó+Ð+r   c                 óŽ  — d|cxk  rdk  sJ d«       ‚ J d«       ‚d|cxk  rdk  sJ d«       ‚ J d«       ‚d|cxk  rdk  sJ d«       ‚ J d«       ‚t        | «      }|j                  d   }t        |«      }|dz  |dz  z  |z  |d   _        t	        |j
                  d	«      5 }|j                  |«       d
d
d
«       y
# 1 sw Y   y
xY w)zª
    Overwrite the macOS SDK version declared in the given binary with the specified version.

    NOTE: currently, only version in the first arch slice is modified.
    r   r?   zInvalid major version value!zInvalid minor version value!zInvalid revision value!r=   r>   r-   úrb+N)r   r6   r4   r8   Úopenr9   Úwrite)r9   rB   rC   rD   r:   r2   r3   Úfps           r   Úset_macos_sdk_versionrR   ‘   sã   € ð �Ô˜ÒÐ<Ð<Ó<ÑÐ<Ð<Ó<ÐØ�Ô˜ÒÐ<Ð<Ó<ÑÐ<Ð<Ó<ÐØ�Ô˜CÒÐ:Ð!:Ó:ÑÐ:Ð!:Ó:Ðä�8‹_€FØ�^‰^˜AÑ€Fä# FÓ+€Kà "™ u°¡zÑ1°HÑ<€K��NÔä	ˆf�o‰o˜uÓ	%ð ¨Ø�‰�RÔ÷÷ ñ ús   Â B;Â;Cc                 ód  — t         j                  j                  | «      }t        | «      }|j                  d   }|j
                  D �cg c]  }|d   j                  t        k(  sŒ|‘Œ }}t        |«      dk(  sJ d«       ‚d}|j
                  D �cg c].  }|d   j                  t        k(  sŒ|d   j                  |k(  sŒ-|‘Œ0 }}t        |«      dk(  sJ d«       ‚|d   d   }|j
                  D �cg c]  }|d   j                  t        k(  sŒ|‘Œ }}t        |«      dk(  sJ d«       ‚|d   d   }||j                  |j                  z   z
  |_        ||j                  |j                  z   z
  |_        t#        |j$                  «      j'                  d«      rd	nd
}	t)        j*                  |j                   |	z  «      |	z  |_        t/        | d«      5 }
|j1                  |
«       ddd«       |j2                  �r
ddlm}m}m}m}m} t/        | d«      5 }
|jA                  |
«      }|jB                  |k(  r2tE        |jF                  «      D �cg c]  }|jA                  |
«      ‘Œ }}n@|jB                  |k(  r1tE        |jF                  «      D �cg c]  }|jA                  |
«      ‘Œ }}d   }||j                  z
  |_$        |
jK                  d«       |jM                  |
«       |D ]  }|jM                  |
«       Œ 	 ddd«       yyc c}w c c}w c c}w # 1 sw Y   �Œ1xY wc c}w c c}w # 1 sw Y   yxY w)a  
    Fixes the Mach-O headers to make code signing possible.

    Code signing on macOS does not work out of the box with embedding .pkg archive into the executable.

    The fix is done this way:
    - Make the embedded .pkg archive part of the Mach-O 'String Table'. 'String Table' is at end of the macOS exe file,
      so just change the size of the table to cover the end of the file.
    - Fix the size of the __LINKEDIT segment.

    Note: the above fix works only if the single-arch thin executable or the last arch slice in a multi-arch fat
    executable is not signed, because LC_CODE_SIGNATURE comes after LC_SYMTAB, and because modification of headers
    invalidates the code signature. On modern arm64 macOS, code signature is mandatory, and therefore compilers
    create a dummy signature when executable is built. In such cases, that signature needs to be removed before this
    function is called.

    Mach-O format specification: http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/Mach-O.5.html
    éÿÿÿÿr   z#Executable contains code signature!s   __LINKEDIT      r-   z(Expected exactly one __LINKEDIT segment!z$Expected exactly one SYMTAB section!Úarm64i @  i   rN   N)Ú	FAT_MAGICÚFAT_MAGIC_64Úfat_archÚ
fat_arch64Ú
fat_header)'r$   r%   Úgetsizer   r6   r/   r0   r   r1   r   Úsegnamer   ÚoffsetÚstroffÚstrsizeÚfileoffÚfilesizeÚ_get_arch_stringr2   r   ÚmathÚceilÚvmsizerO   rP   ÚfatÚmacholib.mach_orV   rW   rX   rY   rZ   Úfrom_fileobjÚmagicÚrangeÚ	nfat_archÚsizeÚseekÚ
to_fileobj)r9   Ú	file_sizeÚ
executabler2   r0   Úsign_secÚ__LINKEDIT_NAMEÚlinkedit_segÚ
symtab_secÚ	page_sizerQ   rV   rW   rX   rY   rZ   rf   ÚiÚarchsÚarchs                       r   Úfix_exe_for_code_signingry   §   së  € ô( —‘—‘ Ó)€Iô �x“€JØ×Ñ Ñ#€Fð  &Ÿ™ÖR˜°#°a±&·*±*Ô@QÓ2Q’ÐR€HÐRÜˆx‹=˜AÒÐDÐDÓDÐð <€OØ#)§?¡?Öx˜C°c¸!±f·j±jÄMÓ6QÐVYÐZ[ÑV\×VdÑVdÐhwÓVw’CÐx€LÐxÜˆ|Ó Ò!ÐMÐ#MÓMÐ!Ø ‘? 1Ñ%€Là!'§¡ÖL˜#°C¸±F·J±JÄ)Ó4K’#ÐL€JÐLÜˆz‹?˜aÒÐGÐ!GÓGÐØ˜A‘˜qÑ!€Jð  # f§m¡m°j×6GÑ6GÑ&GÑH€JÔØ%¨¯©¸×9MÑ9MÑ)MÑN€LÔô ,¨F¯M©MÓ:×EÑEÀgÔN‘ÐTZ€IÜŸ)™) L×$9Ñ$9¸IÑ$EÓFÈÑR€LÔô 
ˆh˜Ó	ð  "Ø×Ñ˜Ô÷ð
 ‡~ƒ~ß_Õ_Ü�(˜EÓ"ð 	$ bð ×)Ñ)¨"Ó-ˆCØ�y‰y˜IÒ%Ü<AÀ#Ç-Á-Ó<PÖQ°q˜×.Ñ.¨rÕ2ÐQ�ÑQØ—‘˜lÒ*Ü>CÀCÇMÁMÓ>RÖS¸˜×0Ñ0°Õ4ÐS�ÐSà˜‘9ˆDØ! D§K¡KÑ/ˆDŒIà�G‰G�AŒJØ�N‰N˜2ÔØò $�Ø—‘ Õ#ñ$÷	$ð 	$ð ùòY Sùò
 yùò M÷<ñ üò RùâS÷	$ð 	$úsa   ÁL Á$L ÂLÂ+LÂ>LÃ/L
ÄL
ÇLÈ8L&ÉLÉ)L&ÊL!Ê AL&ÌLÌ
L&Ì&L/c                 ó‚   — | j                   }| j                  dz  }|dk(  r|dk(  ryy|dk(  r|dk(  ryy	|d
k(  ryJ d«       ‚)z¹
    Converts cputype and cpusubtype from mach_o.mach_header_64 into arch string comparible with lipo/codesign.
    The list of supported architectures can be found in man(1) arch.
    iÿÿÿi  r>   Úx86_64hÚx86_64i  é   Úarm64erU   é   Úi386zUnhandled architecture!)ÚcputypeÚ
cpusubtype)r2   r�   r‚   s      r   rb   rb     s\   € ð �n‰n€GØ×"Ñ" ZÑ/€JØ�.Ò Ø˜Š?ØàØ	�OÒ	#Ø˜Š?ØàØ	�AŠØØ+Ð+Ó+ˆ5r   c                 óŒ  ‡— ddl }|j                  «       }t        |d«      5 Št        ˆfd„d«      D ]  }|j	                  |«       Œ 	 ddd«       t        | «      }|j                  D ]—  }|j                  D �cg c]  }|d   j                  t        k(  sŒ|‘Œ }}|sŒ6|d   }|d   j                  }	|j                  «       }
|
j	                  |	«       |
j                  «       dd }t        |«      dk(  sJ ‚||d   _
        Œ™ t        | d«      5 Š|j                  ‰«       ddd«       y# 1 sw Y   ŒáxY wc c}w # 1 sw Y   yxY w)	aG  
    Modifies the Mach-O image UUID stored in the LC_UUID command (if present) in order to ensure that different
    frozen applications have different identifiers. See TN3178 for details on why this is required:
    https://developer.apple.com/documentation/technotes/tn3178-checking-for-and-resolving-build-uuid-problems
    r   NÚrbc                  ó&   •— ‰ j                  d«      S )Ni    )Úread)rQ   s   €r   ú<lambda>z'update_exe_identifier.<locals>.<lambda>&  s   ø€  "§'¡'¨$£-€ r   r   r-   r=   rN   )ÚhashlibÚsha1rO   ÚiterÚupdater   r6   r/   r0   r   ÚuuidÚcopyÚdigestr1   rP   )r9   Úpkg_filenamerˆ   Úpkg_hashÚchunkrp   r2   r0   Úuuid_cmdÚoriginal_uuidÚcombined_hashÚnew_uuidrQ   s               @r   Úupdate_exe_identifierr–     sF  ø€ ó Ø�|‰|‹~€HÜ	ˆl˜DÓ	!ð # RÜÓ/°Ó5ò 	#ˆEØ�O‰O˜EÕ"ñ	#÷#ô
 �x“€JØ×$Ñ$ò $ˆà#)§?¡?ÖL˜C°c¸!±f·j±jÄGÓ6K’CÐLˆÐLÙØØ˜A‘;ˆð ! ™×(Ñ(ˆð
 !Ÿ™›ˆØ×Ñ˜]Ô+à ×'Ñ'Ó)¨#¨2Ð.ˆÜ�8‹} Ò"Ð"Ð"à#ˆ�‰Õð'$ô, 
ˆh˜Ó	ð  "Ø×Ñ˜Ô÷ð ÷9#ð #üò M÷(ð ús#   ¢&D)Á9D5ÂD5ÄD:Ä)D2Ä:Ec                   ó   — e Zd ZdZy)ÚInvalidBinaryErrorz]
    Exception raised by `get_binary_architectures` when it is passed an invalid binary.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r@   r   r   r˜   r˜   E  s   „ ñð 	r   r˜   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚIncompatibleBinaryArchErrorzq
    Exception raised by `binary_to_target_arch` when the passed binary fails the strict architecture check.
    c                 ó2   •— d}t         ‰| �  |› d|› �«       y )NzMhttps://pyinstaller.org/en/stable/feature-notes.html#macos-multi-arch-supportz, For details about this error message, see: )ÚsuperÚ__init__)ÚselfÚmessageÚurlÚ	__class__s      €r   r¡   z$IncompatibleBinaryArchError.__init__P  s#   ø€ Ø]ˆÜ‰Ñ˜G˜9Ð$PÐQTÐPUÐVÕWr   )r™   rš   r›   rœ   r¡   Ú__classcell__)r¥   s   @r   rž   rž   L  s   ø„ ñ÷Xð Xr   rž   c                 óâ   — 	 t        | «      }t        |j                  «      |j
                  D �cg c]  }t        |j                  «      ‘Œ c}fS # t        $ r}t        d«      |‚d}~ww xY wc c}w )zÅ
    Inspects the given binary and returns tuple (is_fat, archs), where is_fat is boolean indicating fat/thin binary,
    and arch is list of architectures with lipo/codesign compatible names.
    zInvalid Mach-O binary!N)r   Ú
ValueErrorr˜   Úboolrf   r6   rb   r2   )r9   rp   ÚeÚhdrs       r   Úget_binary_architecturesr¬   U  sf   € ð
BÜ˜8“_ˆ
ô �
—‘ÓÈ*×J\ÑJ\Ö!]À3Ô"2°3·:±:Õ">Ò!]Ð]Ð]øô ò BÜ Ð!9Ó:ÀÐAûðBüâ!]s   ‚A ¯A,Á	A)ÁA$Á$A)c                 óò   — |xs | }dd|| d|g}t        j                  |t         j                  t         j                  d¬«      }|j                  r(t        d|› d|j                  › d|j                  › �«      ‚y	)
z\
    Convert the given fat binary into thin one with the specified target architecture.
    Úlipoz-thinú-outputúutf-8©ÚstdoutÚstderrÚencodingúlipo command (ú) failed with error code ú
!
output: N©Ú
subprocessÚrunÚPIPEÚSTDOUTÚ
returncodeÚSystemErrorr²   )r9   Ú	thin_archÚoutput_filenameÚcmd_argsÚps        r   Úconvert_binary_to_thin_archrÃ   a  sw   € ð &Ò1¨€OØ˜ ¨H°iÀÐQ€HÜ�‰�x¬
¯©Ä
×@QÑ@QÐ\cÔd€AØ‡|‚|Ü˜N¨8¨*Ð4MÈaÏlÉlÈ^Ð[fÐgh×goÑgoÐfpÐqÓrÐrð r   c                 óæ   — ddd| g|¢}t        j                  |t         j                  t         j                  d¬«      }|j                  r(t        d|› d|j                  › d|j                  › �«      ‚y	)
zJ
    Merge the given single-arch thin binary files into a fat binary.
    r®   z-creater¯   r°   r±   rµ   r¶   r·   Nr¸   )rÀ   Úslice_filenamesrÁ   rÂ   s       r   Úmerge_into_fat_binaryrÆ   l  sn   € ð ˜	 9¨oÐPÀÐP€HÜ�‰�x¬
¯©Ä
×@QÑ@QÐ\cÔd€AØ‡|‚|Ü˜N¨8¨*Ð4MÈaÏlÉlÈ^Ð[fÐgh×goÑgoÐfpÐqÓrÐrð r   c                 ó  — |s| }t        | «      \  }}|dk(  r|st        |› d�«      ‚y
|r:||vrt        |› d|› d�«      ‚t        j                  d| ||«       t	        | |«       y
||vrt        |› d|› d|d   › d	�«      ‚y
)z‰
    Check that the given binary contains required architecture slice(s) and convert the fat binary into thin one,
    if necessary.
    Ú
universal2z is not a fat binary!z does not contain slice for r.   z1Converting fat binary %s (%s) to thin binary (%s)z" is incompatible with target arch z (has arch: r   z)!N)r¬   rž   ÚloggerÚdebugrÃ   )r9   Útarget_archÚdisplay_nameÚis_fatrw   s        r   Úbinary_to_target_archrÎ   v  sÀ   € ñ
 Øˆä,¨XÓ6�M€FˆEØ�lÒ"ÙÜ-°°Ð>SÐ.TÓUÐUð ñ Ø %Ñ'Ü1°\°NÐB^Ð_jÐ^kÐklÐ2mÓnÐnä�L‰LÐLÈhÐXdÐfqÔrÜ'¨°+Õ>à %Ñ'Ü1Ø#�nÐ$FÀ{ÀmÐS_Ð`eÐfgÑ`hÐ_iÐikÐlóð ð (r   c                 ó  — t         j                  d| «       ddd| g}t        j                  |t        j                  t        j
                  d¬«      }|j                  r(t        d|› d|j                  › d	|j                  › �«      ‚y
)zp
    Remove the signature from all architecture slices of the given binary file using the codesign utility.
    zRemoving signature from file %rú/usr/bin/codesignz--removeú--all-architecturesr°   r±   úcodesign command (r¶   r·   N)	rÉ   rÊ   r¹   rº   r»   r¼   r½   r¾   r²   )r9   rÁ   rÂ   s      r   Úremove_signature_from_binaryrÓ   ’  s~   € ô ‡L�LÐ2°HÔ=Ø# ZÐ1FÈÐQ€HÜ�‰�x¬
¯©Ä
×@QÑ@QÐ\cÔd€AØ‡|‚|ÜÐ.¨x¨jÐ8QÐRS×R^ÑR^ÐQ_Ð_jÐkl×ksÑksÐjtÐuÓvÐvð r   c                 ó¸  — g }|sd}n|j                  d«       |r"|j                  d«       |j                  |«       |r|j                  d«       t        j                  d| «       dd|dd	d
g|¢| ‘}t        j                  |t        j
                  t        j                  d¬«      }|j                  r(t        d|› d|j                  › d|j                  › �«      ‚y)zj
    Sign the binary using codesign utility. If no identity is provided, ad-hoc signing is performed.
    ú-z--options=runtimez--entitlementsz--deepzSigning file %rrÐ   z-sz--forcerÑ   z--timestampr°   r±   rÒ   r¶   r·   N)
rG   rÉ   rÊ   r¹   rº   r»   r¼   r½   r¾   r²   )r9   ÚidentityÚentitlements_fileÚdeepÚ
extra_argsrÁ   rÂ   s          r   Úsign_binaryrÚ   �  sä   € ð €JÙØ‰à×ÑÐ-Ô.ÙØ×ÑÐ*Ô+Ø×ÑÐ+Ô,ÙØ×Ñ˜(Ô#ä
‡L�LÐ" HÔ-à˜T 8¨YÐ8MÈ}ðØ_iðØksð€Hô 	�‰�x¬
¯©Ä
×@QÑ@QÐ\cÔd€AØ‡|‚|ÜÐ.¨x¨jÐ8QÐRS×R^ÑR^ÐQ_Ð_jÐkl×ksÑksÐjtÐuÓvÐvð r   c                 óP  — t        | «      \  }}|r~t        j                  «       5 }g }|D ]M  }t        j                  j                  ||«      }t        | ||¬«       t        ||«       |j                  |«       ŒO t        | g|¢­Ž  ddd«       yt        | |«       y# 1 sw Y   yxY w)aé  
    Modify the given dylib's identity (in LC_ID_DYLIB command) and the paths to dependent dylibs (in LC_LOAD_DYLIB)
    commands into `@rpath/<basename>` format, remove any existing rpaths (LC_RPATH commands), and add a new rpath
    (LC_RPATH command) with the specified path.

    Uses `install-tool-name` utility to make the changes.

    The system libraries (e.g., the ones found in /usr/lib) are exempted from path rewrite.

    For multi-arch fat binaries, this function extracts each slice into temporary file, processes it separately,
    and then merges all processed slices back into fat binary. This is necessary because `install-tool-name` cannot
    modify rpaths in cases when an existing rpath is present only in one slice.
    )rÀ   N)
r¬   ÚtempfileÚTemporaryDirectoryr$   r%   ÚjoinrÃ   Ú_set_dylib_dependency_pathsrG   rÆ   )r9   Útarget_rpathrÍ   rw   ÚtmpdirrÅ   rx   Úslice_filenames           r   Úset_dylib_dependency_pathsrã   µ  s¤   € ô$ -¨XÓ6�M€FˆEáÜ×(Ñ(Ó*ð 	>¨fØ ˆOØò 7�Ü!#§¡§¡¨f°dÓ!;�Ü+¨H°dÈNÕ[Ü+¨N¸LÔIØ×&Ñ& ~Õ6ð	7ô
 " (Ð=¨_Ó=÷	>ð 	>ô 	$ H¨lÕ;÷	>ð 	>ús   ¥A!BÂB%c                 ó  — t         t        t        t        t        h}t        | «      }d}t        «       }t        «       }|j                  D ]•  }|j                  D ]„  }|d   j                  }	|	|vr|	t        t        hvrŒ%|d   j                  d«      j                  d«      }
|	|v r|j                  |
«       Œ^|	t        k(  r|j                  |
«       Œy|	t        k(  sŒƒ|
}Œ† Œ— ~d}|r>t        t!        j"                  d«      t!        j"                  |«      j$                  z  «      }g }d}|D ]›  }t&        j(                  j+                  |«      rŒ#dd	g}t-        |D �cg c]  }||v ‘Œ c}«      rŒCd
}t        t!        j"                  d«      t!        j"                  |«      j$                  z  «      }||k(  rŒ‰|j/                  ||f«       Œ� g }|r||k7  r|d|gz  }|D ]  \  }}|d||gz  }Œ |D ]  }||k(  rŒ	|d|gz  }Œ |r||vr|d|gz  }|sydg|¢| ‘}t1        j2                  |t0        j4                  t0        j6                  d¬«      }|j8                  r(t;        d|› d|j8                  › d|j<                  › �«      ‚yc c}w )z‘
    The actual implementation of set_dylib_dependency_paths functionality.

    Implicitly assumes that a single-arch thin binary is given.
    Nr   r}   r°   ú z@rpathFz"/Library/Frameworks/Tcl.framework/z!/Library/Frameworks/Tk.framework/Tz-idz-changez-delete_rpathz
-add_rpathÚinstall_name_toolr±   zinstall_name_tool command (r¶   r·   )r   r   r   r	   r
   r   Úsetr6   r/   r0   r   r   ÚdecodeÚrstripÚaddÚstrÚpathlibÚPurePathÚnameÚmacholibÚutilÚin_system_pathÚanyrG   r¹   rº   r»   r¼   r½   r¾   r²   )r9   rà   Ú_RELOCATABLEr:   Údylib_idÚrpathsÚlinked_libsr2   r0   Úlc_typer%   Únormalized_dylib_idÚchanged_lib_pathsÚrpath_requiredÚ
linked_libÚ_exemptionsÚxÚnew_pathÚinstall_name_tool_argsÚoriginal_pathÚrpathrÁ   rÂ   s                          r   rß   rß   ×  sâ  € ô 	ÜÜÜÜð€Lô �8‹_€Fà€HÜ‹U€FÜ“%€Kà—.‘.ò  ˆØ—?‘?ò 	 ˆCØ˜!‘f—j‘jˆGØ˜lÑ*¨w¼xÌÐ>UÑ/UØð �q‘6—=‘= Ó)×0Ñ0°Ó8ˆDà˜,Ñ&Ø—‘ Õ%ØœHÒ$Ø—
‘
˜4Õ ØœKÓ'Ø‘ñ	 ð ð  	ð ÐÙÜ!¤'×"2Ñ"2°8Ó"<¼w×?OÑ?OÐPXÓ?Y×?^Ñ?^Ñ"^Ó_Ðð
 ÐØ€NØ!ò 9ˆ
ä�=‰=×'Ñ'¨
Ô3Øð 1Ø/ð
ˆô ¨Ö5 A��Z’Ò5Ô6Øð ˆä”w×'Ñ'¨Ó1´G×4DÑ4DÀZÓ4P×4UÑ4UÑUÓVˆØ˜Ò!Øà× Ñ  *¨hÐ!7Õ8ð19ð6  Ðñ Ð2°hÒ>Ø 5Ð*=Ð">Ñ>Ðð $5ò GÑˆ�xØ 9¨m¸XÐ"FÑFÑðGð
 ò 
ˆØ�LÒ ØØØØð#
ñ 	
Ñð
ñ ˜,¨fÑ4ØØØð#
ñ 	
Ðñ "Øð $ÐGÐ&<ÐG¸hÐG€HÜ�‰�x¬
¯©Ä
×@QÑ@QÐ\cÔd€AØ‡|‚|ÜØ)¨(¨Ð3LÈQÏ\É\ÈNÐZeÐfg×fnÑfnÐeoÐpó
ð 	
ð ùòa 6s   ÅI?
c                 óì   — t        j                  | «      } | j                  j                  j                  dk7  ry| j                  j                  j                  j                  | j                  dz   k7  ryy)zK
    Check if the given shared library is part of a .framework bundle.
    ÚVersionsFz
.frameworkT)rì   rí   Úparentrî   )Úlib_paths    r   Úis_framework_bundle_libr  Q  s^   € ô
 ×Ñ Ó)€Hð ‡�×Ñ×"Ñ" jÒ0ØØ‡�×Ñ×$Ñ$×)Ñ)¨X¯]©]¸\Ñ-IÒIØàr   c           
      ó¢  ‡— d}t        «       }t        «       }t        «       Š| D �]k  \  }}}|dk7  rŒt        j                  |«      }t        j                  |«      }t	        |«      sŒDt	        |«      sŒP|j
                  dz  dz  }	|	j                  «       s‘|j
                  j
                  j
                  dz  dz  }
|
j                  «       sYd}|j
                  j
                  j
                  }t        j                  rt        d|› d�«      ‚t        j                  d|«       �Œ|
}	|j
                  dz  dz  }|j                  t        |«      t        |	«      d	f«       |j                  t        |j
                  j
                  d
z  «      t        |j
                  j                  «      df«       ‰j                  |j
                  j
                  d
z  «       |j
                  j
                  j
                  }|j                  t        ||j                  z  «      t        t        j                  d«      |j                  z  «      df«       |j                  t        |dz  «      ddf«       ‰j                  |dz  «       |j                  |«       �Œn h d£}|D ]¦  }| D ]Ÿ  \  }}}t        j                  |«      }	 |j                  |«      }|j"                  }|d   dk7  rŒC|d   }||vrŒM|j                  t        ||z  «      t        t        j                  d«      |z  «      df«       ‰j                  ||z  «       Œ¡ Œ¨ ‰rVg }| D ]N  \  }}}t        j                  |«      }t%        ˆfd„|j&                  D «       «      rŒ;|j)                  |||f«       ŒP n| }|rt        j                  d«       |t+        |«      z   S # t         $ r Y �Œ/w xY w)a  
    Scan the given TOC list of collected files for shared libraries that are collected from macOS .framework bundles,
    and collect the bundles' Info.plist files. Additionally, create/restore the following symbolic links:
      - `Versions/Current` pointing to the `Versions/<version>` directory containing the binary
      - `<name>` in the top-level .framework directory, pointing to `Versions/Current/<name>`
      - `Resources` in the top-level .framework directory, pointing to `Versions/Current/Resources`
      - additional directories in top-level .framework directory, pointing to their counterparts in `Versions/Current`
        directory.

    Returns updated TOC list with added entries for the discovered Info.plist files and generated symbolic links.
    FÚBINARYÚ	Resourcesz
Info.plistTzCould not find Info.plist in r.   z Could not find Info.plist in %s!ÚDATAÚCurrentÚSYMLINKzVersions/CurrentzVersions/Current/Resources>   ÚHeadersÚHelpersÚ	Librariesr	  Ú
FrameworksÚDocumentationr   r  r}   c              3   ó&   •K  — | ]  }|‰v –— Œ
 y ­w©Nr@   )Ú.0Údest_parentÚframework_symlinked_dirss     €r   ú	<genexpr>z7collect_files_from_framework_bundles.<locals>.<genexpr>æ  s   øè ø€ Ò`¸{�;Ð":Ô:Ñ`ùs   ƒzœOne or more collected .framework bundles have missing Info.plist file. If you are building an .app bundle, you will most likely not be able to code-sign it.)rç   rì   ÚPathrí   r  r  Úis_filer   Ústrict_collect_moder¾   rÉ   Úwarningrê   rë   rî   Úrelative_tor¨   Úpartsrò   ÚparentsrG   Úsorted)Úcollected_filesÚinvalid_framework_foundÚframework_entriesÚframework_pathsÚ	dest_nameÚsrc_nameÚtypecodeÚsrc_pathÚ	dest_pathÚinfo_plist_srcÚinfo_plist_src_topÚframework_dirÚinfo_plist_destÚdest_framework_pathÚVALID_SUBDIRSÚremaining_pathÚremaining_path_partsÚdir_nameÚfiltered_tocr  s                      @r   Ú$collect_files_from_framework_bundlesr3  a  së  ø€ ð $Ðä›ÐÜ“e€OÜ"›uÐð *9ó A1Ñ%ˆ	�8˜XØ�xÒØä—<‘< Ó)ˆÜ×$Ñ$ YÓ/ˆ	ô ' xÔ0Øô ' yÔ1Øð "Ÿ™¨;Ñ6¸ÑEˆØ×%Ñ%Ô'ð "*§¡×!7Ñ!7×!>Ñ!>ÀÑ!LÈ|Ñ![ÐØ%×-Ñ-Ô/ð +/Ð'Ø (§¡× 6Ñ 6× =Ñ =�Ü×-Ò-Ü%Ð(EÀmÀ_ÐTUÐ&VÓWÐWä—N‘NÐ#EÀ}ÔUÙØ/ˆNØ#×*Ñ*¨[Ñ8¸<ÑGˆØ×Ñœs ?Ó3´S¸Ó5HÈ&ÐQÔRð
 	×Ñœs 9×#3Ñ#3×#:Ñ#:¸YÑ#FÓGÌÈY×M]ÑM]×MbÑMbÓIcÐenÐoÔpØ ×$Ñ$ Y×%5Ñ%5×%<Ñ%<¸yÑ%HÔIà'×.Ñ.×5Ñ5×<Ñ<Ðð
 	×ÑÜÐ# i§n¡nÑ4Ó5Ü”× Ñ Ð!3Ó4°y·~±~ÑEÓFØð
ô 	ð 	×ÑÜÐ# kÑ1Ó2Ø(Øð
ô 	ð
 	!×$Ñ$Ð%8¸;Ñ%FÔGð 	×ÑÐ/Ö0ðCA1òL d€Mà.ò IÐØ-<ò 	IÑ)ˆI�x Ü×(Ñ(¨Ó3ˆIðØ!*×!6Ñ!6Ð7JÓ!K�ð $2×#7Ñ#7Ð ð $ AÑ&¨*Ò4Øð ,¨AÑ.ˆHØ˜}Ñ,Øà×!Ñ!ÜÐ'¨(Ñ2Ó3Ü”G×$Ñ$Ð%7Ó8¸8ÑCÓDØð#ô ð
 %×(Ñ(Ð)<¸xÑ)GÕHñ3	IðIñ@  Øˆà-<ò 	AÑ)ˆI�x Ü×(Ñ(¨Ó3ˆIäÓ`Èi×N_ÑN_Ô`Ô`Øà×Ñ ¨H°hÐ ?Õ@ñ	Að 'ˆñ Ü�‰ðHô	
ð
 œ&Ð!2Ó3Ñ3Ð3øô] ò Úðús   Ê;OÏ	OÏOr  )NNF)<rœ   rc   r$   rì   r¹   r"   rÜ   rg   r   r   r   r   r   r   r	   r
   r   r   r   r   r   Úmacholib.MachOr   Úmacholib.utilrï   ÚPyInstaller.logÚlogÚloggingÚPyInstallerr   Ú	getLoggerr™   rÉ   r   r   r   r   r4   r;   r7   rë   ÚtuplerL   rR   ry   rb   r–   Ú	Exceptionr˜   rž   r¬   rÃ   rÆ   rÎ   rÓ   rÚ   rã   rß   r  r3  r@   r   r   ú<module>r=     sô   ðñó Û 	Û Û Û Û ÷÷ ÷ õ õ !Û å !Ý à	ˆ×	Ñ	˜8Ó	$€ò
ò
òòò	ò,ò"ð, ð ,¨ó ,ò$ò,Z$òz,ò.'ôT	˜ô 	ôX )ô Xò	^ósòsóò8wówò0<òDw
òtó T4r   