o bc?@sdZddlZddlZddlZddlmZmZmZddlZddl m Z ddl m Z ddl mZmZmZmZddlmZddlmZd d ZGd d d e ZGd ddeZdZdZdZddZedZddZddZ ddZ!dS)adistutils.cygwinccompiler Provides the CygwinCCompiler class, a subclass of UnixCCompiler that handles the Cygwin port of the GNU C compiler to Windows. It also contains the Mingw32CCompiler class which handles the mingw32 port of GCC (same as cygwin in no-cygwin mode). N)PopenPIPE check_output) UnixCCompiler) write_file)DistutilsExecErrorCCompilerError CompileErrorUnknownFileError) LooseVersion)find_executablecCstjd}|dkr>tj|d|d}|dkrdgS|dkr#dgS|d kr*d gS|d kr1d gS|d kr8dgStd|dS)zaInclude the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later. zMSC v. 1300msvcr701310msvcr711400msvcr801500msvcr901600msvcr100zUnknown MS Compiler version %s N)sysversionfind ValueError)msc_posmsc_verr 0/usr/lib/python3.10/distutils/cygwinccompiler.py get_msvcr=s  r"c@sZeZdZdZdZdZdZdZdZdZ dZ dd d Z d d Z    dddZ dddZdS)CygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows. cygwinz.o.az.dllzlib%s%sz%s%sz.exercCst||||t\}}|d||f|tur!|d|t\|_|_|_ ||j d|j|j|j f|jdkrCd|_ nd|_ |jdkrNd}nd }|j d d d d d|j |fd|jdkrodg|_ |ddSt|_ dS)Nz%Python's GCC status: %s (details: %s)zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.z: gcc %s, ld %s, dllwrap %s z2.10.90gccdllwrap2.13-shared -mdll -staticzgcc -mcygwin -O -Wallzgcc -mcygwin -mdll -O -Wallzg++ -mcygwin -O -Wallz gcc -mcygwinz%s -mcygwin %scompiler compiler_so compiler_cxx linker_exe linker_so2.91.57msvcrtz,Consider upgrading to a newer version of gcc)r__init__check_config_h debug_print CONFIG_H_OKwarn get_versions gcc_version ld_versiondllwrap_version compiler_type linker_dllset_executables dll_librariesr")selfverbosedry_runforcestatusdetails shared_optionr r r!r3bsN      zCygwinCCompiler.__init__c Cs|dks|dkr&z |dd|d|gWdSty%}zt|d}~wwz||j||d|g|WdStyH}zt|d}~ww)z:Compiles the source by spawning GCC and windres if needed..rc.reswindresz-iz-oN)spawnrr r-)r@objsrcextcc_argsextra_postargspp_optsmsgr r r!_compiles zCygwinCCompiler._compileNcCsHt| pg} t|p g}t|pg}||j|dur||jks)|jdkrtj|d}tjtj |\}}tj ||d}tj |d|d}dtj |dg}|D]}| |q]| t ||fd ||jd kr| d |g| d |gn| || s| d t||||||||d| | | | | dS)zLink the objects.Nr&rz.deflibr%z LIBRARY %sEXPORTSz writing %sr'z --output-libz--defz-s)copyextendr? EXECUTABLEr=ospathdirnamesplitextbasenamejoinappendexecuterrlink)r@ target_descobjectsoutput_filename output_dir libraries library_dirsruntime_library_dirsexport_symbolsdebug extra_preargsrO build_temp target_langtemp_dirdll_name dll_extensiondef_filelib_filecontentssymr r r!r`sB         zCygwinCCompiler.linkcCs|durd}g}|D]H}tjtj|\}}||jddgvr)td||f|r1tj|}|dvrE|tj||||j q |tj|||j q |S)z#Adds supports for rc and res files.NrtrGrHz"unknown file type '%s' (from '%s'))rHrG) rXrYr[normcasesrc_extensionsr r\r^r] obj_extension)r@source_filenames strip_dirrd obj_namessrc_namebaserMr r r!object_filenamess&    z CygwinCCompiler.object_filenamesrrr) NNNNNrNNNN)rrt)__name__ __module__ __qualname____doc__r<rwstatic_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_format exe_extensionr3rRr`r}r r r r!r#Ws" ; Nr#c@seZdZdZdZdddZdS)Mingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows. mingw32rc Csxt|||||jdkrd}nd}|jdkrd}nd}tr#td|jdd d d d |j||fd g|_t |_dS)Nr(r)r*r1z--entry _DllMain@12rtz1Cygwin gcc cannot be used with --compiler=mingw32z gcc -O -Wallzgcc -mdll -O -Wallz g++ -O -Wallr&z%s %s %sr+) r#r3r:r9 is_cygwingccrr>r=r?r")r@rArBrCrF entry_pointr r r!r3s.   zMingw32CCompiler.__init__Nr~)rrrrr<r3r r r r!rsrokznot ok uncertainc Csddlm}dtjvrtdfS|}z(t|}zd|vr+td|fW|WSt d|fW|WS|wt yV}zt d||j ffWYd }~Sd }~ww) awCheck if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". r) sysconfigGCCzsys.version mentions 'GCC'__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '%s': %sN) distutilsrrrr6get_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINstrerror)rfnconfig_hexcr r r!r4Fs$       r4s(\d+\.\d+(\.\d+)*)cCst|d}t|durdSt|dtdj}z |}W|n|wt|}|dur1dSt | d S)zFind the version of an executable by running `cmd` in the shell. If the command is not found, or the output does not match `RE_VERSION`, returns None. rNT)shellstdout) splitr rrrrr RE_VERSIONsearchr groupdecode)cmd executableout out_stringresultr r r!_find_exe_versionss    rcCsgd}tdd|DS)zg Try to find out the versions of gcc, ld and dllwrap. If not possible it returns None for it. )zgcc -dumpversionzld -vzdllwrap --versioncSsg|]}t|qSr )r).0rr r r! sz get_versions..)tuple)commandsr r r!r8sr8cCstddg}|dS)z>Try to determine if the gcc that would be used is from cygwin.r&z -dumpmachinescygwin)rstripendswith)rr r r!rs r)"rrXrrU subprocessrrrredistutils.unixccompilerrdistutils.file_utilrdistutils.errorsrrr r distutils.versionr distutils.spawnr r"r#rr6rrr4compilerrr8rr r r r!s./    ;1 +