WcUcsdZddlZddlZddlZgdZdZdZdZddZdd Z d Z da d Z da d Zd ZdZdadZdZdZdZdZdZdZdZdZdZdZdZdS)zShared OS X support functions.N)compiler_fixupcustomize_config_varscustomize_compilerget_platform_osx) CFLAGSZLDFLAGSZCPPFLAGSZ BASECFLAGS BLDSHAREDLDSHAREDCCCXXZ PY_CFLAGSZ PY_LDFLAGSZ PY_CPPFLAGSZPY_CORE_CFLAGSZPY_CORE_LDFLAGS)rrrr Z_OSX_SUPPORT_INITIAL_cs|tjd}|jtj}tjj |\}}t jdkr |dkr|dz}tjj|sO|D]I}tjj||}tjj|sG|cSdS|S)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. NZPATHZwin32z.exe) osenvironsplitZpathseppathZsplitextsysZplatformZisfilejoin)Z executabler ZpathsZbaseZextZpfs %/usr/lib64/python3.12/_osx_support.py_find_executablers  |zz&! JJrzz "E  ,ID# cVmm&( 77>>* % %  A Q +Aww~~a  tFcsddl} ddl}|j}|j|5}|r|d|jd}n|d|jd}t j|s0|jjd jndcdddS#t$r(t dt j d}YwxYw#1swYdSxYw) z0Output from successful command execution or NonerNz/tmp/_osx_support.zw+bz >'z' 2>&1z 2>/dev/null >''utf-8) contextlibtempfileZNamedTemporaryFileZ ImportErroropenr ZgetpidZclosingZnamesystemreadZdecodestrip)Z commandstringZcapture_stderrrrZfpZcmd r _read_outputr7sN "  ( ( *   B Q2 >%2]]BGGGGProductUserVisibleVersion\s*(.*?).) _SYSTEM_VERSIONrresearchrZclosergroupr ZOSError)rm r_get_system_versionr*Vs FGRYZZA  II89:C }"%((1771:+;+;C+@!+D"E ?        sB.'BB+. CCcst;t}|r- td|jdDatStS#t$r daYtSwxYw)z} Return the macOS system version as a tuple The return value is safe to use to compare two version numbers. Nc32K|]}t|dSNZint.0ir)r z,_get_system_version_tuple..s"-U-Uc!fffff-U-Urr!)_SYSTEM_VERSION_TUPLEr*tupler ValueErrorZ osx_versionrr_get_system_version_tupler7usy$)+ ; +(--U-Uk>O>OPS>T-U-U(U% !   + + +(*%%   +s%A AAcs^t|D]}|jts||=dS)z-Remove original unmodified values for testingN)list startswith_INITPRE) _config_varsZkr)r_remove_original_valuesr<s;,    << ! !Q  rcst|j|d}||krt|z|vr ||t|z<|||<dS)z@Save modified and original unmodified value of configuration varrN)getr:)r;cvZnewvalueZoldvalue r_save_modified_valuer@sMB'HH8b= #D#D&. X]#LrcsLttSt|dd}d}|jD]a}|jdrd}|jdrd}-|s0|j }|dkrdaJ|j d s]|dd actdatS) z= Returns the root of the default SDK for this system, or '/' Nz -c -E -v - zEnd of search listz /usr/includez/z.sdk/usr/includei)_cache_default_sysrootrZ splitlinesr9rZendswith)ccZcontentsZ in_incdirsZliner?r_default_sysrootrCs)%%""">EHJ##% 4 4 ??+ , ,JJ __1 2 2JJ Z::Zcv_splitrr_find_appropriate_compilerrLsJ" rzzd#))+A..B B  g &   "  ( ( / /| " 3 : : :=> 4J$&&!'*B 2/1 1 U{{( K KB\!!b &:&:'+113$&%KKbbR$Y $\2sxx7IJJJ rcstD]u}||vs|tjvs||}tjdd|tj }tjdd|}t |||w|S)z5Remove all universal build arguments from config vars -arch\s+\w+\srI)flagsz-isysroot\s*\S+)_UNIVERSAL_CONFIG_VARSr r r%subZASCIIr@)r;r>rN r_remove_universal_flagsrRs%::   "BJJ"6"6 $EFF+S%rxxHHEFF-sE:E r5 9 9 9 rcs|dtjvr|Stjd|dtjd|dj ddd}|rTt D]K}||vs|tjvs||}tjd d |}t|||M|S) z-Remove any unsupported archs from config varsrz -arch\s+ppcrNzecho 'int main{};' | 'rrHz6' -c -arch ppc -x c -o /dev/null /dev/null 2>/dev/nullz-arch\s+ppc\w*\srI) r r r%r&rrJrOrPr@)r;Zstatusr>rNr?r_remove_unsupported_archsrSs rzz yyh!78D4 ((i888 ;< 6- B B%%"BJJ*>*>(,EFF#6UCE(r5AAA rcsdtjvrjtjd}tD]J}||vsd||vs||}tjdd|}|dz|z}t |||L|S)z2Allow override of all archs with ARCHFLAGS env var ARCHFLAGS-archrMrI)r r rOr%rPr@)r;Zarchr>rNr?r_override_all_archsrV:s bjj  zz+&( > >B\!!gb1A&A&A$R(/e< d*$\2u=== rcsn|jdd}tjd|}||jd}tj j |sTtD]K}||vs|tjvs||}tjdd|}t|||M|S)z+Remove references to any SDKs not availablerrz-isysroot\s*(\S+)Nr"z-isysroot\s*\S+(?:\s|$)rI) r=r%r&r'r r ZexistsrOr rPr@)r;cflagsr(Zsdkr>rNrr_check_for_unavailable_sdkrXKs  h +F &/A}ggajww~~c"", B B%%"BJJ*>*>(,EFF#=sEJE(r5AAA rcsdx}}t|}tsdx}}nd|v}td|D}|sdtjvr |j d}|||dz=tsLttt|D]'}||dks||dzdks |||dz=)dtjvr+|s)|tjdjz}|r? d t|D}|sn&|d }||d kr |||dz=n|||dz=>d }|}d t|D}|s|}dt|D}|D]1}||d kr ||dz}n||td d }|rtjj|sftj j#d|dtj j#dtj j%|S#t $rY~wxYw)ae 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. FTrUc3sBK|]}|jds|dS) -isysrootNr9)r/Zargr)rr1z!compiler_fixup..ys-QQ3S^^K5P5P33333QQrrTr#r"arm64c@g|]\}}|jds|SrYrZr/r0ZxrQr "compiler_fixup..s)XXXSQqall;>W>WqqqXrrrYNcr\r]rZr^rQrr_r`s)LLLSQq!,,{2K2KqqqLrcr\r]rZr^rQrr_r`s)TTT1!,,{:S:S111Trz2Compiling with an SDK that doesn't seem to exist: z z%Please check your Xcode installation )r8rFZanyr r indexr5rGZreversedZrangelenr Z enumerater ZisdirrZstderrZwriteZflush) Z compiler_soZcc_argsZ stripArchZ stripSysrootraZidxZindicesZsysrootZargvars rrrfs %$I {#K % ' '$(' LLw& QQ'QQQ yK2::-- #))'2eAg . $ % %E#k"234 + +C37**{3q5/AW/L/LCE **bjj  "BJJ{$;$A$A$CC |XXIk$:XXG7AJE5![00eAg .. eAg .G FLLIg.LLG 7TT + 6TT #;+ % %SUmG ESk#k"2"34G wrww}}W-- YgYYYZZ ABB  e    sH77 IIcslts t|t|t||S)aCustomize 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 )rFrRrVrXr;rrrrs:2 & ' ' -- %%|,, rcsTt|t|t||S)zCustomize compiler path and configuration variables. This customization is performed when the first extension module build is requested in distutils.sysconfig.customize_compiler. )rLrSrVrcrrrrs/|,,l++ %% rcs"|jdd}tp|}|p|}|rP|}d}|jtdz|jdd}|r* td|j dddD}nd }|d krd |j vrd }tjd |}ttt|}t|dkr |d}n|dkrd}ny|dkrd }np|dkrd}ng|dkrd}n^|dkrd}nU|dkrd}nLt d||dkrtjdkr!d}n|dvrtjdkrd}nd }|||fS#t $rd }YwxYw)!z Filter values for get_platform()ZMACOSX_DEPLOYMENT_TARGETrZmacosxrc3r+r,r-r.r)rr1z#get_platform_osx.. s""N"Na3q66666"N"Nrr!rr#)rEirDrUZfatz -arch\s+(\S+)r")r[x86_64Z universal2)i386ppc)rerdZintel)rerfrdZfat3)ppc64rdZfat64)rerfrgrdZ universalz#Don't know machine value for archs=relrd)ZPowerPCZPower_Macintoshrgrf)r=r*r:r4r r5rr%ZfindallZsortedZsetrbrZmaxsize)r;ZosnameZreleaseZmachineZmacverZ macreleaserWZarchss rrrs   8" =F$&0&J  !zF v !!(8"3$0$4$4Xr$BD : %""N"N:3C3CC3H13M"N"NN !J ' ! !w&,,.'@'@GJJ/8E&U,-E5zQ(---&/)),,,!333 ---!<<<% j>CeEGG  {{e##" 6 6 6{{e##! GW %%a % % %$  %s(E>> F Fr,)F)Z__doc__r r%rZ__all__rOrKr:rrr r$r*r3r7r<r@rArCrFrGrLrRrSrVrXrrrrr2rrrhs$$    A ? #4QQQQ,<!!!&      """2BBB<<<;;;|   %%%P"6MMM`&&&R(K&K&K&K&K&r