
    F\hV                         S r SSKrSSKrSSKr/ SQrSrSrSrSS jrSS jr	S	 r
SqS
 rSqS rS rS rSq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)zShared OS X support functions.    N)compiler_fixupcustomize_config_varscustomize_compilerget_platform_osx)CFLAGSLDFLAGSCPPFLAGS
BASECFLAGS	BLDSHAREDLDSHAREDCCCXX	PY_CFLAGS
PY_LDFLAGSPY_CPPFLAGSPY_CORE_CFLAGSPY_CORE_LDFLAGS)r   r   r   r   _OSX_SUPPORT_INITIAL_c                    Uc  [         R                  S   nUR                  [         R                  5      n[         R                  R                  U 5      u  p4[        R                  S:X  a  US:w  a  U S-   n [         R                  R                  U 5      (       dQ  U HJ  n[         R                  R                  XP5      n[         R                  R                  U5      (       d  MH  Us  $    gU $ )zTries to find 'executable' in the directories listed in 'path'.

A string listing directories separated by 'os.pathsep'; defaults to
os.environ['PATH'].  Returns the complete filename or None if not found.
NPATHwin32z.exe)
osenvironsplitpathseppathsplitextsysplatformisfilejoin)
executabler   pathsbaseextpfs          #/usr/lib/python3.13/_osx_support.py_find_executabler)      s     |zz&!JJrzz"E  ,IDcVm&(
77>>*%%AQ+Aww~~a  	 
     c                    SSK n SSKnUR                  5       nUR                  U5       nU(       a  U < SUR                  < S3nOU < SUR                  < S3n[
        R                  " U5      (       d-  UR                  5       R                  S	5      R                  5       OSsSSS5        $ ! [         a&    [	        S[
        R                  " 5       < 3S5      n Nf = f! , (       d  f       g= f)
z0Output from successful command execution or Noner   Nz/tmp/_osx_support.zw+bz >'z' 2>&1z 2>/dev/null >''utf-8)
contextlibtempfileNamedTemporaryFileImportErroropenr   getpidclosingnamesystemreaddecodestrip)commandstringcapture_stderrr.   r/   fpcmds         r(   _read_outputr>   7   s     "((*
 
		B	2%2BGG<C,9277CC8:		#rwwy(..0D 
 		  "IIK "" 
 	s   B/ A:C"/-CC"
C0c                 V    [        U 5      =(       d    [        SU < 35      =(       d    S$ )z0Find a build tool on current path or using xcrunz/usr/bin/xcrun -find  )r)   r>   )toolnames    r(   _find_build_toolrB   M   s'    X& X GHr*   c                  l   [         c~  Sq  [        SSS9n  [        R                  " SU R	                  5       5      nU R                  5         Ub2  SR                  UR                  S5      R                  S5      SS	 5      q [         $ [         $ ! U R                  5         f = f! [         a     [         $ f = f)
z*Return the OS X system version as a stringNr@   z0/System/Library/CoreServices/SystemVersion.plistr-   )encodingz=<key>ProductUserVisibleVersion</key>\s*<string>(.*?)</string>.      )
_SYSTEM_VERSIONr2   researchr7   closer!   groupr   OSError)r'   ms     r(   _get_system_versionrO   V   s     	FGRYZAII 89:C 	}"%((1771:+;+;C+@!+D"E ? 	  	  	s   
B! %B B!
B32B3c                      [         c9  [        5       n U (       a(   [        S U R                  S5       5       5      q [         $ [         $ ! [         a
    Sq  [         $ f = f)zm
Return the macOS system version as a tuple

The return value is safe to use to compare
two version numbers.
c              3   8   #    U  H  n[        U5      v   M     g 7fNint.0is     r(   	<genexpr>,_get_system_version_tuple.<locals>.<genexpr>   s     -U>Tc!ff>T   rE    )_SYSTEM_VERSION_TUPLErO   tupler   
ValueErrorosx_versions    r(   _get_system_version_tuplera   u   sb     $)++(--Uk>O>OPS>T-U(U% !     +(*%  +s   !A AAc                 d    [        U 5       H!  nUR                  [        5      (       d  M  X	 M#     g)z-Remove original unmodified values for testingN)list
startswith_INITPRE)_config_varsks     r(   _remove_original_valuesrh      s'     ,<<!!  r*   c                 j    U R                  US5      nX2:w  a  [        U-   U ;  a  X0[        U-   '   X U'   g)z@Save modified and original unmodified value of configuration varr@   N)getre   )rf   cvnewvalueoldvalues       r(   _save_modified_valuern      s;     B'H8b=#D&.X]#r*   c                 t   [         b  [         $ [        U < S3S5      nSnUR                  5        Hw  nUR                  S5      (       a  SnM  UR                  S5      (       a  SnM7  U(       d  M@  UR	                  5       nUS:X  a  Sq MZ  UR                  S	5      (       d  Mr  USS
 q My     [         c  Sq [         $ )z<Returns the root of the default SDK for this system, or '/' Nz -c -E -v - </dev/nullTFz#include <...>zEnd of search listz/usr/include/z.sdk/usr/includei)_cache_default_sysrootr>   
splitlinesrd   r9   endswith)cccontents
in_incdirslines       r(   _default_sysrootrx      s     )%%">EHJ##%??+,,J__122JZ::<D~%),&122)-ds& & %!$!!r*   c                  D    [        5       n U (       a  [        U S:  5      $ S$ )z=Returns True if universal builds are supported on this system
      F)ra   boolr_   s    r(   _supports_universal_buildsr~      s#     ,-K+64w&'AEAr*   c                  2    [        5       n U (       a  U S:  $ S$ )z9Returns True if arm64 builds are supported on this system)   r   F)ra   r_   s    r(   _supports_arm64_buildsr      s     ,-K%0;'!;e;r*   c                 j   S[         R                  ;   a  U $ U S   R                  5       S   =p[        U5      (       d  [	        S5      nOk[         R
                  R                  U5      R                  S5      (       a8  [        SUR                  SS5      < S35      nU(       a  SU;   a  [	        S5      nU(       d  [        S	5      eX:w  ag  [         H]  nX@;   d  M
  U[         R                  ;  d  M   X   R                  5       nUS
:w  a  UOUS-   US'   [        XSR                  U5      5        M_     U $ )z7Find appropriate C compiler for extension module buildsr   r   clanggccr,   '"'"'z' --versionzllvm-gcczCannot locate working compilerr   z++ )r   r   r   r)   rB   r   basenamerd   r>   replaceSystemError_COMPILER_CONFIG_VARSrn   r!   )rf   rt   oldccdatark   cv_splits         r(   _find_appropriate_compilerr      s   " rzz d#))+A..BB g&			"		(	(	/	/ "

3	 := >J$&!'*B/1 	1 
{ (B!b

&:'+113$&%KbR$Y$\sxx7IJ	 ( r*   c                     [          Hm  nX;   d  M
  U[        R                  ;  d  M   X   n[        R                  " SSU[        R
                  S9n[        R                  " SSU5      n[        XU5        Mo     U $ )z5Remove all universal build arguments from config vars-arch\s+\w+\sr   )flagsz-isysroot\s*\S+)_UNIVERSAL_CONFIG_VARSr   r   rI   subASCIIrn   )rf   rk   r   s      r(   _remove_universal_flagsr     se     %"BJJ"6 $EFF+S%rxxHEFF-sE:E 59 % r*   c                 v   S[         R                  ;   a  U $ [        R                  " SU S   5      b  [         R                  " SU S   R                  SS5      < S35      nU(       aR  [         HH  nX ;   d  M
  U[         R                  ;  d  M   X   n[        R                  " SS	U5      n[        XU5        MJ     U $ )
z-Remove any unsupported archs from config varsr   z-arch\s+ppcr   zecho 'int main{};' | 'r,   r   z6' -c -arch ppc -x c -o /dev/null /dev/null 2>/dev/nullz-arch\s+ppc\w*\sr   )	r   r   rI   rJ   r6   r   r   r   rn   )rf   statusrk   r   s       r(   _remove_unsupported_archsr     s     rzz	yyh!78D  4 ((i8;<  -%"BJJ*>(,EFF#6UCE(5A	 - r*   c                     S[         R                  ;   aa  [         R                  S   n[         HD  nX ;   d  M
  SX   ;   d  M  X   n[        R                  " SSU5      nUS-   U-   n[        XU5        MF     U $ )z2Allow override of all archs with ARCHFLAGS env var	ARCHFLAGS-archr   r   )r   r   r   rI   r   rn   )rf   archrk   r   s       r(   _override_all_archsr   :  ss    
 bjj zz+&(B!g1A&A$(/e<d*$\u= ) r*   c                 l   U R                  SS5      n[        R                  " SU5      nUb  UR                  S5      n[        R
                  R                  U5      (       dR  [         HH  nX@;   d  M
  U[        R                  ;  d  M   X   n[        R                  " SSU5      n[        XU5        MJ     U $ )z+Remove references to any SDKs not availabler   r@   z-isysroot\s*(\S+)rF   z-isysroot\s*\S+(?:\s|$)r   )rj   rI   rJ   rL   r   r   existsr   r   r   rn   )rf   cflagsrN   sdkrk   r   s         r(   _check_for_unavailable_sdkr   K  s     h+F
		&/A}ggajww~~c"",%"BJJ*>(,EFF#=sEJE(5A - r*   c                 v   S=p#[        U 5      n [        5       (       d  S=p#OSU;   n[        S U 5       5      nU(       d  S[        R                  ;   a    U R                  S5      nXUS-   2	 M  [        5       (       dB  [        [        [        U 5      5      5       H!  nX   S:X  d  M  XS-      S:X  d  M  XUS-   2	 M#     S[        R                  ;   a+  U(       d$  U [        R                  S   R                  5       -   n U(       a^   [        U 5       VVs/ s H  u  pgUR                  S	5      (       d  M  UPM!     nnnU(       d  OUS
   nX   S	:X  a  XUS-   2	 OXUS-   2	 M]  Sn	Un
[        U5       VVs/ s H  u  pgUR                  S	5      (       d  M  UPM!     nnnU(       d9  U n
[        U 5       VVs/ s H  u  pgUR                  S	5      (       d  M  UPM!     nnnU H$  nX   S	:X  a	  XS-      n	  OX   [        S	5      S n	  O   U	(       a  [        R                  R                  U	5      (       d`  [         R"                  R%                  SU	 S35        [         R"                  R%                  S5        [         R"                  R'                  5         U $ ! [         a     GM  f = fs  snnf s  snnf s  snnf )aM  
This function will strip '-isysroot PATH' and '-arch ARCH' from the
compile flags if the user has specified one them in extra_compile_flags.

This is needed because '-arch ARCH' adds another architecture to the
build, without a way to remove an architecture. Furthermore GCC will
barf if multiple '-isysroot' arguments are present.
FTr   c              3   T   #    U  H  oR                  S 5      (       d  M  Uv   M      g7f)	-isysrootN)rd   )rV   args     r(   rX   !compiler_fixup.<locals>.<genexpr>y  s     Q'3^^K5P33's   (	(r   rG   rF   arm64r   r   Nz2Compiling with an SDK that doesn't seem to exist: 
z%Please check your Xcode installation
)rc   r~   anyr   r   indexr^   r   reversedrangelenr   	enumeraterd   r   isdirr   stderrwriteflush)compiler_socc_args	stripArchstripSysrootr   idxrW   xindicessysrootargvars              r(   r   r   f  s     %$I{#K%'' $('	Lw&	Q'QQK2::-#))'2eAg.	  $%%E#k"234C7*{q5/AW/LCE	* 5 bjj  "BJJ{$;$A$A$CC$-k$:X$:SQall;>Wq$:GXAJE![0eAg.  eAg.  GF%g.L.SQ!,,{2Kq.GL )+ 6T 6!,,{:S1 6T;+%UmGk#k"2"34G  rww}}W--

MgYVXYZ

AB

e    Y  M Us6   J J)6J)7J/J/7J5J5
J&%J&c                 f    [        5       (       d  [        U 5        [        U 5        [        U 5        U $ )a  Customize Python build configuration variables.

Called internally from sysconfig with a mutable mapping
containing name/value pairs parsed from the configured
makefile used to build this interpreter.  Returns
the mapping updated as needed to reflect the environment
in which the interpreter is running; in the case of
a Python from a binary installer, the installed
environment may be very different from the build
environment, i.e. different OS levels, different
built tools, different available CPU architectures.

This customization is performed whenever
distutils.sysconfig.get_config_vars() is first
called.  It may be used in environments where no
compilers are present, i.e. when installing pure
Python dists.  Customization of compiler paths
and detection of unavailable archs is deferred
until the first extension module build is
requested (in distutils.sysconfig.customize_compiler).

Currently called from distutils.sysconfig
)r~   r   r   r   rf   s    r(   r   r     s1    2 &''
 	 - % |,r*   c                 H    [        U 5        [        U 5        [        U 5        U $ )zCustomize compiler path and configuration variables.

This customization is performed when the first
extension module build is requested
in distutils.sysconfig.customize_compiler.
)r   r   r   r   s    r(   r   r     s&     |, l+ %r*   c                 F   U R                  SS5      nU(       a  SU;  a  US-  n[        5       =(       d    UnU=(       d    UnU(       GaB  UnSnU R                  [        S-   U R                  SS5      5      nU(       a&   [        S UR	                  S5      SS	  5       5      nOS
nUS:  a  SUR                  5       ;   a  Sn[        R                  " SU5      n[        [        [        U5      5      5      n[        U5      S:X  a  US   nOUS:X  a  SnOxUS:X  a  SnOoUS:X  a  SnOfUS:X  a  SnO]US:X  a  SnOTUS:X  a  SnOK[        SU< 35      eUS:X  a  [        R                  S:  a  SnOUS;   a  [        R                  S:  a  S nOS!nXU4$ ! [
         a    S
n Nf = f)"z Filter values for get_platform()MACOSX_DEPLOYMENT_TARGETr@   rE   z.0macosxr   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r(   rX   #get_platform_osx.<locals>.<genexpr>  s     "N3Ma3q663MrZ   r   rG   )r{      rz   r   fatz-arch\s+(\S+)rF   )r   x86_64
universal2)i386ppc)r   r   intel)r   r   r   fat3)ppc64r   fat64)r   r   r   r   	universalz#Don't know machine value for archs=r   l        r   )PowerPCPower_Macintoshr   r   )rj   rO   re   r]   r   r^   r9   rI   findallsortedsetr   r   maxsize)rf   osnamereleasemachinemacver
macreleaser   archss           r(   r   r     s    8"=F#V# 	$$&0&J!zF !!(8"3$0$4$4Xr$BD%""N:3C3CC3H13M"NN

 !J'!w&,,.'@ GJJ/8E&U,-E5zQ(--&/),,!33 --!<<% >CEG G  {{e#"66 {{e#!W%%a  %$
%s    $F F F rR   )F)__doc__r   rI   r   __all__r   r   re   r)   r>   rB   rH   rO   r\   ra   rh   rn   rq   rx   r~   r   r   r   r   r   r   r   r   r   r   r[   r*   r(   <module>r      s    $ 	 	 
A  ?  #4Q, <  !&    "2B<;|%P"6M`&R(P&r*   