U e5dUã@sàdZddlZddlZddlZddddgZdZdZd Zd-d d „Zd.d d„Z dd„Z da dd„Z da dd„Zdd„Zdd„Zdadd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d„Zd*d„Zd+d„Zd,d„ZdS)/zShared OS X support functions.éNÚcompiler_fixupÚcustomize_config_varsÚcustomize_compilerÚget_platform_osx) ÚCFLAGSZLDFLAGSZCPPFLAGSZ BASECFLAGSÚ BLDSHAREDÚLDSHAREDÚCCÚCXXZ PY_CFLAGSZ PY_LDFLAGSZ PY_CPPFLAGSZPY_CORE_CFLAGSZPY_CORE_LDFLAGS)rrr r Z_OSX_SUPPORT_INITIAL_cCsŒ|dkrtjd}| tj¡}tj |¡\}}tjdkrH|dkrH|d}tj |¡s„|D]&}tj  ||¡}tj |¡rX|SqXdS|SdS)zÚTries 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ÚPATHZwin32z.exe) ÚosÚenvironÚsplitÚpathsepÚpathÚsplitextÚsysÚplatformÚisfileÚjoin)Ú executablerÚpathsÚbaseZextÚpÚf©rú$/usr/lib64/python3.8/_osx_support.pyÚ_find_executables     rFc Csªddl}zddl}| ¡}Wn(tk rDtdt ¡fdƒ}YnX| |¡P}|rfd||jf}nd||jf}t  |¡s|  ¡  d¡  ¡ndW5QR£SQRXdS)z0Output from successful command execution or NonerNz/tmp/_osx_support.%szw+bz %s >'%s' 2>&1z%s 2>/dev/null >'%s'zutf-8) Ú contextlibÚtempfileZNamedTemporaryFileÚ ImportErrorÚopenr ÚgetpidÚclosingÚnameÚsystemÚreadÚdecodeÚstrip)Z commandstringZcapture_stderrrrÚfpÚcmdrrrÚ _read_output7s ÿÿ  r+cCst|ƒptd|fƒpdS)z0Find a build tool on current path or using xcrunz/usr/bin/xcrun -find %sÚ)rr+)ZtoolnamerrrÚ_find_build_toolMs  ÿþr-cCsxtdkrtdaz tdƒ}Wntk r,YnHXzt d| ¡¡}W5| ¡X|dk rtd | d¡  d¡dd…¡atS)z*Return the OS X system version as a stringNr,z0/System/Library/CoreServices/SystemVersion.plistz=ProductUserVisibleVersion\s*(.*?)Ú.éé) Ú_SYSTEM_VERSIONr!ÚOSErrorÚcloseÚreÚsearchr&rÚgroupr)rÚmrrrÚ_get_system_versionVs  ÿ r8cCsLtdkrHtƒ}|rHztdd„| d¡DƒƒaWntk rFdaYnXtS)z} Return the macOS system version as a tuple The return value is safe to use to compare two version numbers. Ncss|]}t|ƒVqdS©N©Úint©Ú.0ÚirrrÚ sz,_get_system_version_tuple..r.r)Ú_SYSTEM_VERSION_TUPLEr8ÚtuplerÚ ValueError©Z osx_versionrrrÚ_get_system_version_tupleus rDcCs"t|ƒD]}| t¡r||=qdS)z-Remove original unmodified values for testingN)ÚlistÚ startswithÚ_INITPRE)Ú _config_varsÚkrrrÚ_remove_original_valuesˆs  rJcCs8| |d¡}||kr,t||kr,||t|<|||<dS)z@Save modified and original unmodified value of configuration varr,N)ÚgetrG)rHÚcvZnewvalueZoldvaluerrrÚ_save_modified_values  rMcCsŽtdk r tStd|fdƒ}d}| ¡D]T}| d¡rzEnd of search listz /usr/includeú/z.sdk/usr/includeiôÿÿÿ)Ú_cache_default_sysrootr+Ú splitlinesrFr(Úendswith)ÚccÚcontentsZ in_incdirsÚlinerrrÚ_default_sysroot™s$    rUcCstƒ}|rt|dkƒSdS)z=Returns True if universal builds are supported on this system©é éF)rDÚboolrCrrrÚ_supports_universal_builds²srZcCstƒ}|r|dkSdS)z9Returns True if arm64 builds are supported on this system)é rF)rDrCrrrÚ_supports_arm64_builds¼sr\cCsÚdtjkr|S|d ¡d}}t|ƒs4tdƒ}n/dev/nullr]r^z-arch\s+ppc\w*\sr_) r r r4r5r%rarhrirM)rHZstatusrLrgrrrÚ_remove_unsupported_archss þÿ rlcCsddtjkr`tjd}tD]F}||krd||kr||}t dd|¡}|d|}t|||ƒq|S)z2Allow override of all archs with ARCHFLAGS env varÚ ARCHFLAGSú-archrfr_)r r rhr4rirM)rHZarchrLrgrrrÚ_override_all_archs:s   rocCsx| dd¡}t d|¡}|dk rt| d¡}tj |¡sttD]8}||kr:|tjkr:||}t  dd|¡}t |||ƒq:|S)z+Remove references to any SDKs not availablerr,z-isysroot\s*(\S+)Nr/z-isysroot\s*\S+(?:\s|$)r_) rKr4r5r6r rÚexistsrhr rirM)rHÚcflagsr7ZsdkrLrgrrrÚ_check_for_unavailable_sdkKs    rrc Csød}}t|ƒ}tƒs d}}nd|k}tdd„|Dƒƒ}|sHdtjkr‚z| d¡}|||d…=WqHtk r|YqÈYqHXqHnFtƒsÈtt t |ƒƒƒD].}||dkr˜||dd kr˜|||d…=q˜dtjkrè|sè|tjd  ¡}|r@d d „t |ƒDƒ}|s q@|d }||d kr0|||d…=qî|||d…=qîd}|}dd „t |ƒDƒ}|sv|}dd „t |ƒDƒ}|D]B}||d kr ||d}q¾n||t d ƒd…}q¾qz|rôtj  |¡sôd 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. FTrncss|]}| d¡r|VqdS)ú -isysrootN©rF)r=Úargrrrr?ys z!compiler_fixup..rmr0r/Úarm64cSsg|]\}}| d¡r|‘qS©rsrt©r=r>ÚxrrrÚ ‘s z"compiler_fixup..rrsNcSsg|]\}}| d¡r|‘qSrwrtrxrrrrz¡s cSsg|]\}}| d¡r|‘qSrwrtrxrrrrz¤s )Úlogz4Compiling with an SDK that doesn't seem to exist: %sz$Please check your Xcode installation)rErZÚanyr r ÚindexrBr\ÚreversedÚrangeÚlenrÚ enumeraterÚisdirZ distutilsr{Úwarn) Z compiler_soZcc_argsZ stripArchZ stripSysrootr}ÚidxÚindicesZsysrootZargvarr{rrrrfsZ      ÿ cCs"tƒst|ƒt|ƒt|ƒ|S)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 )rZrkrorr©rHrrrr·s cCst|ƒt|ƒt|ƒ|S)zÅCustomize compiler path and configuration variables. This customization is performed when the first extension module build is requested in distutils.sysconfig.customize_compiler). )rerlror†rrrràs cCsŒ| dd¡}tƒp|}|p|}|r‚|}d}| td| dd¡¡}|rˆz$tdd„| d¡dd …Dƒƒ}WqŒtk r„d }YqŒXnd }|d krFd | ¡krFd }t d|¡}tt t |ƒƒƒ}t |ƒdkrÚ|d}nj|dkrèd}n\|dkröd }nN|dkrd}n>|dkrd}n.|dkr&d}n|dkr6d}ntd|fƒ‚n<|dkrbt j dkr‚d}n |dkr‚t j dkr~d }nd!}|||fS)"z Filter values for get_platform()ZMACOSX_DEPLOYMENT_TARGETr,Zmacosxrcss|]}t|ƒVqdSr9r:r<rrrr?sz#get_platform_osx..r.rr0)rWrrVrnZfatz -arch\s+(\S+)r/)rvÚx86_64Z universal2)Úi386Úppc)rˆr‡Zintel)rˆr‰r‡Zfat3)Úppc64r‡Zfat64)rˆr‰rŠr‡Z universalz%Don't know machine value for archs=%rrˆlr‡)ZPowerPCZPower_MacintoshrŠr‰)rKr8rGrArrBr(r4ÚfindallÚsortedÚsetr€rÚmaxsize)rHZosnameÚreleaseÚmachineZmacverZ macreleaserqZarchsrrrrôsX    ÿ$        ÿ    )N)F)Ú__doc__r r4rÚ__all__rhrcrGrr+r-r1r8r@rDrJrMrOrUrZr\rerkrlrorrrrrrrrrrÚsBü      >(Q)