U ,aU@sdZddlZddlZddlZddddgZdZdZd Zd-d d Zd.d dZ ddZ da ddZ da ddZddZddZdaddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)dZd*dZd+dZd,dZdS)/zShared OS X support functions.Ncompiler_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|dkrtjd}|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. NPATHZwin32z.exe) osenvironsplitpathseppathsplitextsysplatformisfilejoin) executablerpathsbaseZextpfr1/opt/alt/python38/lib64/python3.8/_osx_support.py_find_executables     rFc Csddl}zddl}|}Wn(tk rDtdtfd}YnX||P}|rfd||jf}nd||jf}t |s| d ndW5QRSQRXdS)z0Output from successful command execution or NonerNz/tmp/_osx_support.%szw+bz %s >'%s' 2>&1z%s 2>/dev/null >'%s'zutf-8) contextlibtempfileZNamedTemporaryFile ImportErroropenr getpidclosingnamesystemreaddecodestrip)Z commandstringZcapture_stderrrrfpcmdrrr _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  r-cCsxtdkrtdaz td}Wntk r,YnHXztd|}W5|X|dk rtd|d dddatS)z*Return the OS X system version as a stringNr,z0/System/Library/CoreServices/SystemVersion.plistz=ProductUserVisibleVersion\s*(.*?).) _SYSTEM_VERSIONr!OSErrorcloseresearchr&rgroupr)rmrrr_get_system_versionVs   r8cCsLtdkrHt}|rHztdd|dDaWntk rFdaYnXtS)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 sz,_get_system_version_tuple..r.r)_SYSTEM_VERSION_TUPLEr8tupler ValueErrorZ osx_versionrrr_get_system_version_tupleus rDcCs"t|D]}|tr||=qdS)z-Remove original unmodified values for testingN)list startswith_INITPRE) _config_varskrrr_remove_original_valuess  rJcCs8||d}||kr,t||kr,||t|<|||<dS)z@Save modified and original unmodified value of configuration varr,N)getrG)rHcvZnewvalueZoldvaluerrr_save_modified_values  rMcCstdk r tStd|fd}d}|D]T}|drzEnd of search listz /usr/include/z.sdk/usr/includei)_cache_default_sysrootr+ splitlinesrFr(endswith)cccontentsZ in_incdirslinerrr_default_sysroots$    rUcCst}|rt|dkSdS)z=Returns True if universal builds are supported on this system F)rDboolrCrrr_supports_universal_buildssrZcCst}|r|dkSdS)z9Returns True if arm64 builds are supported on this system) rF)rDrCrrr_supports_arm64_buildssr\cCsdtjkr|S|dd}}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||}tdd|}|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}td|}|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 rexistsrhr rirM)rHcflagsr7ZsdkrLrgrrr_check_for_unavailable_sdkKs    rrc Csd}}t|}ts d}}nd|k}tdd|D}|sHdtjkrz|d}|||d=WqHtk r|YqYqHXqHnFtstt t |D].}||dkr||dd kr|||d=qdtjkr|s|tjd }|r@d d t |D}|s q@|d }||d kr0|||d=q|||d=qd}|}dd t |D}|sv|}dd t |D}|D]B}||d kr||d}qn||t d d}qqz|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. FTrncss|]}|dr|VqdS) -isysrootNrF)r=argrrrr?ys z!compiler_fixup..rmr0r/arm64cSsg|]\}}|dr|qSrsrtr=r>xrrr s z"compiler_fixup..rrsNcSsg|]\}}|dr|qSrwrtrxrrrrzs cSsg|]\}}|dr|qSrwrtrxrrrrzs )logz4Compiling with an SDK that doesn't seem to exist: %sz$Please check your Xcode installation)rErZanyr r indexrBr\reversedrangelenr enumeraterisdirZ distutilsr{warn) Z compiler_soZcc_argsZ stripArchZ stripSysrootr}idxindicesZsysrootZargvarr{rrrrfsZ       cCs"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 )rZrkrorrrHrrrrs cCst|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). )rerlrorrrrrs cCs|dd}tp|}|p|}|r|}d}|td|dd}|rz$tdd|ddd D}Wqtk rd }YqXnd }|d krFd |krFd }td|}tt t |}t |dkr|d}nj|dkrd}n\|dkrd }nN|dkrd}n>|dkrd}n.|dkr&d}n|dkr6d}ntd|fn<|dkrbt j dkrd}n |dkrt 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/)rvx86_64Z universal2)i386ppc)rrZintel)rrrZfat3)ppc64rZfat64)rrrrZ universalz%Don't know machine value for archs=%rrlr)ZPowerPCZPower_Macintoshrr)rKr8rGrArrBr(r4findallsortedsetrrmaxsize)rHZosnamereleasemachineZmacverZ macreleaserqZarchsrrrrsX    $            )N)F)__doc__r r4r__all__rhrcrGrr+r-r1r8r@rDrJrMrOrUrZr\rerkrlrorrrrrrrrrrsB      >(Q)