a DOg U@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|durtjd}|tj}tj|\}}tjdkrH|dkrH|d}tj|s|D]&}tj ||}tj|rX|SqXdS|SdS)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. NPATHwin32z.exe) osenvironsplitpathseppathsplitextsysplatformisfilejoin) executablerpathsbaseextpfr$/usr/lib64/python3.9/_osx_support.py_find_executables     rFcCsddl}zddl}|}Wn&tyBtdtfd}Yn0||R}|rdd||jf}nd||jf}t |s| d ndWdS1s0YdS)z0Output from successful command execution or NonerNz/tmp/_osx_support.%szw+bz %s >'%s' 2>&1z%s 2>/dev/null >'%s'zutf-8) contextlibtempfileNamedTemporaryFile ImportErroropenr getpidclosingnamesystemreaddecodestrip)Z commandstringZcapture_stderrr r!fpcmdrrr _read_output7s    r.cCst|ptd|fpdS)z0Find a build tool on current path or using xcrunz/usr/bin/xcrun -find %s)rr.)Ztoolnamerrr_find_build_toolMs  r0cCs~tdurzdaz td}Wnty*YnP0ztd|}W|n |0|durzd|d dddatS)z*Return the OS X system version as a stringNr/z0/System/Library/CoreServices/SystemVersion.plistz=ProductUserVisibleVersion\s*(.*?).) _SYSTEM_VERSIONr$OSErrorresearchr)closergroupr)rmrrr_get_system_versionVs   r;cCsJtdurFt}|rFztdd|dDaWntyDdaYn0tS)z} Return the macOS system version as a tuple The return value is safe to use to compare two version numbers. Ncss|]}t|VqdSNint.0irrr z,_get_system_version_tuple..r1r)_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}||kr,t||vr,||t|<|||<dS)z@Save modified and original unmodified value of configuration varr/N)getrK)rLcvZnewvalueZoldvaluerrr_save_modified_values  rQcCstdur tStd|fd}d}|D]T}|drzEnd of search listz /usr/include/z.sdk/usr/includei)_cache_default_sysrootr. splitlinesrJr+endswith)cccontentsZ in_incdirslinerrr_default_sysroots$    rYcCst}|rt|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|s4td}n/dev/nullrarbz-arch\s+ppc\w*\src) r rr6r7r(rerlrmrQ)rLstatusrPrkrrr_remove_unsupported_archss  rqcCsddtjvr`tjd}tD]F}||vrd||vr||}tdd|}|d|}t|||q|S)z2Allow override of all archs with ARCHFLAGS env var ARCHFLAGS-archrjrc)r rrlr6rmrQ)rLZarchrPrkrrr_override_all_archs:s   rtcCsx|dd}td|}|durt|d}tj|sttD]8}||vr:|tjvr:||}t dd|}t |||q:|S)z+Remove references to any SDKs not availablerr/z-isysroot\s*(\S+)Nr2z-isysroot\s*\S+(?:\s|$)rc) rOr6r7r9r rexistsrlrrmrQ)rLcflagsr:ZsdkrPrkrrr_check_for_unavailable_sdkKs    rwc Csd}}t|}ts d}}nd|v}tdd|D}|sHdtjvrz|d}|||d=WqHtyzYqYqH0qHnFtstt t |D].}||dkr||dd kr|||d=qdtjvr|s|tjd }|r>d d t |D}|sq>|d }||d kr.|||d=q|||d=qd}|}dd t |D}|st|}dd t |D}|D]B}||d kr||d}qn||t d d}qqx|rtj |sd dlm} | d|| d|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. FTrscss|]}|dr|VqdS) -isysrootNrJ)r@argrrrrByrCz!compiler_fixup..rrr3r2arm64cSsg|]\}}|dr|qSrxryr@rAxrrr rCz"compiler_fixup..rrxNcSsg|]\}}|dr|qSr|ryr}rrrrrCcSsg|]\}}|dr|qSr|ryr}rrrrrC)logz4Compiling with an SDK that doesn't seem to exist: %sz$Please check your Xcode installation)rIr^anyr rindexrFr`reversedrangelenr enumeraterisdirZ distutilsrwarn) Z compiler_soZcc_argsZ stripArchZ stripSysrootridxindicesZsysrootZargvarrrrrrfsZ        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^rortrwrLrrrrs 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. )rirqrtrrrrrs rcCs|dd}tp|}|p|}|r|}d}|td|dd}|rz$tdd|ddd D}Wqtyd }Yq0nd }|d krDd |vrDd }td|}tt t |}t |dkr|d}nj|dkrd}n\|dkrd }nN|dkrd}n>|dkrd}n.|dkr$d}n|dkr4d}ntd|fn<|dkr`t j dkrd}n |dvrt j dkr|d }nd!}|||fS)"z Filter values for get_platform()ZMACOSX_DEPLOYMENT_TARGETr/Zmacosxrcss|]}t|VqdSr<r=r?rrrrBrCz#get_platform_osx..r1rr3)r[rrZrsZfatz -arch\s+(\S+)r2)r{x86_64Z universal2)i386ppc)rrZintel)rrrZfat3)ppc64rZfat64)rrrr universalz%Don't know machine value for archs=%rrlr)ZPowerPCZPower_Macintoshrr)rOr;rKrErrFr+r6findallsortedsetrrmaxsize)rLZosnamereleasemachineZmacverZ macreleaservZarchsrrrrsX    $             r)N)F)__doc__r r6r__all__rlrgrKrr.r0r4r;rDrHrNrQrSrYr^r`rirorqrtrwrrrrrrrrs:      >(Q)