o ?OgU@sdZddlZddlZddlZgdZdZdZdZd.ddZd/d d Z d d Z da ddZ da ddZddZddZdaddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)0zShared 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)rrr r Z_OSX_SUPPORT_INITIAL_cCs|dur tjd}|tj}tj|\}}tjdkr$|dkr$|d}tj|sB|D]}tj ||}tj|r?|Sq,dS|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. NPATHZwin32z.exe) osenvironsplitpathseppathsplitextsysplatformisfilejoin) executablerpathsbaseZextpfr3/opt/alt/python310/lib64/python3.10/_osx_support.py_find_executables    rFcCsddl}z ddl}|}Wnty!tdtfd}Ynw||)}|r2d||jf}nd||jf}t |sG| d ndWdS1sSwYdS)z0Output from successful command execution or NonerNz/tmp/_osx_support.%szw+bz %s >'%s' 2>&1z%s 2>/dev/null >'%s'utf-8) contextlibtempfileZNamedTemporaryFile ImportErroropenr getpidclosingnamesystemreaddecodestrip)Z commandstringZcapture_stderrrr fpcmdrrr _read_output7s"   $r,cCst|p td|fp dS)z0Find a build tool on current path or using xcrunz/usr/bin/xcrun -find %s)rr,)Ztoolnamerrr_find_build_toolMs  r.cCstdur@daztddd}Wn tyYtSwztd|}W|n|w|dur@d|d ddd atS) z*Return the OS X system version as a stringNr-z0/System/Library/CoreServices/SystemVersion.plistr)encodingz=ProductUserVisibleVersion\s*(.*?).) _SYSTEM_VERSIONr"OSErrorresearchr'closergroupr)rmrrr_get_system_versionVs    r:cCsNtdur%t}|r%ztdd|dDaWtSty$daYtSwtS)z} Return the macOS system version as a tuple The return value is safe to use to compare two version numbers. Ncs|]}t|VqdSNint.0irrr z,_get_system_version_tuple..r0r)_SYSTEM_VERSION_TUPLEr:tupler ValueErrorZ osx_versionrrr_get_system_version_tupleus rHcCs"t|D] }|tr||=qdS)z-Remove original unmodified values for testingN)list startswith_INITPRE) _config_varskrrr_remove_original_valuess  rNcCs8||d}||krt||vr||t|<|||<dS)z@Save modified and original unmodified value of configuration varr-N)getrK)rLcvZnewvalueZoldvaluerrr_save_modified_values   rQcCstdurtStd|fd}d}|D]*}|drd}q|dr&d}q|r>|}|dkr3daq|d r>|dd aqtdurEdatS) z= Returns the root of the default SDK for this system, or '/' Nz%s -c -E -v - zEnd of search listz /usr/include/z.sdk/usr/includei)_cache_default_sysrootr, splitlinesrJr)endswith)cccontentsZ in_incdirslinerrr_default_sysroots&     rYcCst}|r t|dkSdS)z=Returns True if universal builds are supported on this system F)rHboolrGrrr_supports_universal_buildssr^cCst}|r |dkSdS)z9Returns True if arm64 builds are supported on this system) rF)rHrGrrr_supports_arm64_buildssr`cCsdtjvr|S|dd}}t|std}ntj|dr8td| ddf}|r8d|vr8td}|s>t d ||krkt D]&}||vrj|tjvrj||}|d kr[|n|d |d<t ||d |qD|S) z7Find appropriate C compiler for extension module buildsr rZclangZgccz'%s' --version''"'"'zllvm-gcczCannot locate working compilerr z++ )r r rrr.rbasenamerJr,replace SystemError_COMPILER_CONFIG_VARSrQr)rLrVZoldccdatarPZcv_splitrrr_find_appropriate_compilers.     ricCsVtD]&}||vr(|tjvr(||}tjdd|tjd}tdd|}t|||q|S)z5Remove all universal build arguments from config vars -arch\s+\w+\src)flagsz-isysroot\s*\S+)_UNIVERSAL_CONFIG_VARSr r r5subASCIIrQ)rLrPrkrrr_remove_universal_flagss rocCsdtjvr|Std|ddur@td|dddf}|r@tD]}||vr?|tjvr?||}tdd |}t|||q#|S) z-Remove any unsupported archs from config varsr z -arch\s+ppcrNzNecho 'int main{};' | '%s' -c -arch ppc -x c -o /dev/null /dev/null 2>/dev/nullrarbz-arch\s+ppc\w*\src) r r r5r6r&rerlrmrQ)rLZstatusrPrkrrr_remove_unsupported_archss   rpcCsddtjvr0tjd}tD]#}||vr/d||vr/||}tdd|}|d|}t|||q |S)z2Allow override of all archs with ARCHFLAGS env var ARCHFLAGS-archrjrc)r r rlr5rmrQ)rLZarchrPrkrrr_override_all_archs:s    rscCsx|dd}td|}|dur:|d}tj|s:tD]}||vr9|tjvr9||}t dd|}t |||q|S)z+Remove references to any SDKs not availablerr-z-isysroot\s*(\S+)Nr1z-isysroot\s*\S+(?:\s|$)rc) rOr5r6r8r rexistsrlr rmrQ)rLcflagsr9ZsdkrPrkrrr_check_for_unavailable_sdkKs    rvc Csd}}t|}tsd}}n d|v}tdd|D}|s$dtjvr? z|d}|||d=Wn ty<Ynwq%n#tsbtt t |D]}||dkra||dd kra|||d=qJdtjvrr|sr|tjd }|r d d t |D}|sn|d }||d kr|||d=n|||d=qud}|}dd t |D}|s|}dd t |D}|D]}||d kr||d}n ||t d d}|rtj |stjd|dtjdtj|S)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. FTrrcss|] }|dr|VqdS) -isysrootNrJ)r@argrrrrBysz!compiler_fixup..rqr2r1arm64cSg|] \}}|dr|qSrwrxr@rAxrrr z"compiler_fixup..rrwNcSr{r|rxr}rrrrrcSr{r|rxr}rrrrrz2Compiling with an SDK that doesn't seem to exist:  z%Please check your Xcode installation )rIr^anyr r indexrFr`reversedrangelenr enumeraterisdirrstderrwriteflush) Z compiler_soZcc_argsZ stripArchZ stripSysrootridxindicesZsysrootZargvarrrrrfsd         rcCs"tst|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 )r^rorsrvrLrrrrs rcCst|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. )rirprsrrrrrs rcCsp|dd}tp |}|p|}|r|}d}|td|dd}|rAztdd|ddd D}Wn ty@d }Ynwd }|d krd |vrd }td|}tt t |}t |dkrh|d}nK|dkrod}nD|dkrvd }n=|dkr}d}n6|dkrd}n/|dkrd}n(|dkrd}n!td|f|dkrt j dkrd}n|dvrt j dkrd }nd!}|||fS)"z Filter values for get_platform()ZMACOSX_DEPLOYMENT_TARGETr-Zmacosxrcsr;r<r=r?rrrrB rCz#get_platform_osx..r0rr2)r[rZrrZfatz -arch\s+(\S+)r1)rzx86_64Z universal2)i386ppc)rrZintel)rrrZfat3)ppc64rZfat64)rrrrZ universalz%Don't know machine value for archs=%rrlr)ZPowerPCZPower_Macintoshrr)rOr:rKrErrFr)r5findallsortedsetrrmaxsize)rLZosnamereleasemachineZmacverZ macreleaseruZarchsrrrrs\   $       rr<)F)__doc__r r5r__all__rlrgrKrr,r.r3r:rDrHrNrQrSrYr^r`rirorprsrvrrrrrrrrs<      >(P)