o 6aJc@sdZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl Z ddl mZddlmZddlmZddlmZddlmZmZmZmZd d Zee j_ed Zed Z Gd dde jj!Z"ddZ#ddZ$ddZ%ddZ&d>ddZ'ddZ(ddZ)ddZ*d d!Z+iZ,ejd"krz/ddl-Z-d#e,d$<d%e,d&<d'e,d(<d)e,d*<e.e-d+re-j/0d,d-\Z1Z2Z3e-j/e,e1e2<[1[2[3Wne4ye 5d.Ynwd/d0Z6d?d2d3Z7d4d5Z8d6d7Z9d8d9Z:d:d;Z;d.a exists for gcc. If not, build it. # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) # 3. Force windows to use g77 N)log) StrictVersion) UnixCCompiler)get_build_version)UnknownFileError)msvc_runtime_librarymsvc_runtime_versionmsvc_runtime_majorget_build_architecturecCst}|dur gS|gS)zBReplacement for outdated version of get_msvcr from cygwinccompilerN)r)msvcrr B/usr/lib/python3/dist-packages/numpy/distutils/mingw32ccompiler.pyget_msvcr_replacement$srz\[Ordinal/Name Pointer\] Tablez$^\s+\[([\s*[0-9]*)\] ([a-zA-Z0-9_]*)c@sHeZdZdZdZ   d ddZ      d ddZ  dd d ZdS)Mingw32CCompilerzH A modified MingW32 compiler compatible with an MSVC built Python. mingw32rc Cstjj|||||jdur6z tddg}Wn ttfy%d}Ynwt d|}|r6t | d|_|jdkr>d}nd}|j dkrId|_n|j dkrQd |_tt}td d }|s`|re|d t} | rr|d d| tdkr|jdkr|jdddddn6|jdddddn,|jdkr|jdddd|j|fdn|jdkr|jdd dd!dn |jd"d#d$d%dd g|_dS)&Ngccz -dumpversionz (\d+\.\d+)z2.91.57z--entry _DllMain@12dllwrapzg++T)debugNPY_MINGW_USE_CUSTOM_MSVCR__MSVCRT_VERSION__z0x%04iAMD64z4.0z/gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -WallzCgcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypeszgcc -g -mno-cygwinzgcc -g -mno-cygwin -shared)compiler compiler_so linker_exe linker_soz#gcc -g -DDEBUG -DMS_WIN64 -O0 -Wallz7gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypeszgcc -gzgcc -g -shared3.0.0zgcc -mno-cygwin -O2 -wz0gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypeszg++ -mno-cygwinz%s -mno-cygwin -mdll -static %szgcc -mno-cygwin -O2 -Wallz-gcc -mno-cygwin -O2 -Wall -Wstrict-prototypeszg++ -mno-cygwin -sharedz gcc -O2 -Wallz!gcc -O2 -Wall -Wstrict-prototypeszg++ z g++ -shared) distutilscygwinccompilerCygwinCCompiler__init__ gcc_version subprocess check_outputOSErrorCalledProcessErrorresearchrgroup linker_dlllinkerbuild_import_librarybuild_msvcr_library define_macrorr set_executables compiler_cxx) selfverbosedry_runforce out_stringresult entry_point msvcr_successmsvcr_dbg_success msvcr_versionr r r r!9s            zMingw32CCompiler.__init__NcCspt}|r|s g}||||||||||d| | | | | f}|jdkr)tjjj}ntj}||d|jj dS)Nr) rappendr"rrr linkr__code__ co_argcount)r1 target_descobjectsoutput_filename output_dir libraries library_dirsruntime_library_dirsexport_symbolsr extra_preargsextra_postargs build_temp target_langruntime_libraryargsfuncr r r r<s2   zMingw32CCompiler.linkrc Cs|durd}g}|D]\}tjtj|\}}tj|\}}|r(|dd}||jddgvr9td||f|rAtj|}|dksI|dkrY|tj ||||j q |tj |||j q |S)Nrr.rcz.resz"unknown file type '%s' (from '%s')) ospathsplitextnormcase splitdrivesrc_extensionsrbasenamer;join obj_extension) r1source_filenames strip_dirrB obj_namessrc_namebaseextdrvr r r object_filenamess.      z!Mingw32CCompiler.object_filenames)rrr)NrNNNN)rr)__name__ __module__ __qualname____doc__ compiler_typer!r<r_r r r r r2s" u ,rc Cs@tjg}ttdrtjtjkr|tjnttdr'tjtjkr'|tjgd}g}|D]}|D] }|tj||q3q/dtj vrS|tjtj ddt tj dd\}}t }|dkrod||d }n |d krzd |d }nd }td||D]}tj||} tj| r| Sqtd||f)N base_prefix real_prefix)rlibbin SYSTEMROOTSystem32CPythonpython.dllPyPylibpypyz-c.dllz!Unknown platform {implementation}zLooking for %sz%s not found in %s)sysprefixhasattrrer;rfrOrPrVenvirontuple version_infoplatformpython_implementationprintexists ValueError) stemssub_dirslib_dirsstemfolder major_version minor_versionimplementationdllnamedllr r r find_python_dlls6    rcCstdd|g}|dS)Nz objdump.exez-p )r#r$split)rstr r r dump_tables rc Cs(t|}tt|D] }t||rnq tdg}t|dt|D]}t||}|rF|t | d | dfq't|dkrTt d|t|d1}|dtj||d|d |d |D] }|d |dqvWd d S1swYd S) zGiven a dll file location, get all its exported symbols and dump them into the given def file. The .def file will be overwrittenzSymbol table not foundrrkrzNo symbols found in %swzLIBRARY %s z,;CODE PRELOAD MOVEABLE DISCARDABLE z;DATA PRELOAD SINGLE z EXPORTS z%s N)rrangelen_STARTmatchdecoder{_TABLEr;intr)striprwarnopenwriterOrPrU) rdfiledumpisymsjmdsr r r generate_def s.$     "rcs4dddtfdd}dd}||p||S)Namd64x86)rIntelcsdtjtjddd}tj|sdSt|D]\}}}||vr/|vr/tj||SqdS)NWINDIRz C:\WINDOWSwinsxs)rOrPrVrtgetrzwalk)dll_name winsxs_pathrootdirsfilesarchr r _find_dll_in_winsxsEs z%find_dll.._find_dll_in_winsxscSsLtjgtjddD]}tj||}tj|r#tj|Sq dS)NPATH;) rqrrrOrtrrPrVrzabspath)rrPfilepathr r r _find_dll_in_pathPs  z#find_dll.._find_dll_in_path)r )rrrr rr find_dll@s  rFc CstjdkrdSt}|durtddS|dkr tddSt}|r)|d7}d|}tjtj d|}tj |rFtd |fd S|d }t |}|sYt d |dSd |}tjtj d|}t d||ft||dd|d|g} t| } t|| S)NntFz?Skip building import library: Runtime is not compiled with MSVCPz=Skip building msvcr library: custom functionality not presentrzlib%s.alibsz(Skip building msvcr library: "%s" existsTrnz*Cannot build msvcr library: "%s" not foundz lib%s.defz&Building msvcr library: "%s" (from %s)dlltool-d-l)rOnamer rrrrPrVrqrrisfilerrinforr#callremove) r msvcr_ver msvcr_nameout_nameout_filemsvcr_dll_namedll_filedef_namedef_filecmdretcoder r r r-ZsH       r-cCs<tjdkrdSt}|dkrtS|dkrtStd|)NrrrzUnhandled arch %s)rOrr _build_import_library_amd64_build_import_library_x86r{rr r r r,s  r,c Csttjdd\}}gd}tjg}ttdr%tjtjkr%|tjnttdr6tjtjkr6|tjddg}g}|D]}|||f}|D]}|D] } |tj || |qLqHq>|D]} tj | rld| fSq^d |d fS) zACheck if an import library for the Python runtime already exists.Nrk)zlibpython%d%d.azlibpython%d%d.dll.azlibpython%d.%d.dll.arerfrrgTFr) rurqrvrrrsrer;rfrOrPrVr) rrpatternsr|r} candidatespatfilenamestem_dirrfullnamer r r _check_for_import_libs*     rcCst\}}|rtd|dSt}td||fdttjdd}tj tj d|}t ||dd|d|g}t |dS) N)Skip building import library: "%s" existsz4Building import library (arch=AMD64): "%s" (from %s)python%d%d.defrkrrrr)rrrrrrurqrvrOrPrVrrrr# check_call) out_existsrrrrrr r r rs   rcCst\}}|rtd|dSdttjdd}tjtj d|}tj |sZt tdr8tjtj d|}nt tdrGtjtj d|}nd}tj |rR|}ntd |dStd |d d lm}d ttjdd}tjtj d|}|j|j|gdd}||\} } t|d} || | |j| Wdn1swYt} dd| d|d|g} t| }|rtddS)z; Build the import libraries for Mingw32-gcc on Windows rNzpython%d%d.librkrrerfrz+Cannot build import library: "%s" not foundz(Building import library (ARCH=x86): "%s"r)lib2defrF)shellrrz --dllnamez--defz --output-libz:Failed to build import library for gcc. Linking will fail.)rrrrurqrvrOrPrVrrrrsrerfrrnumpy.distutilsrgetnm DEFAULT_NMparse_nmr output_def DEF_HEADERrr#r$)rrlib_namelib_filebase_librrr nm_outputdlistflistfidrrstatusr r r rsJ             rwin32z 8.0.50727.4280z 9.0.21022.890z10.0.30319.460100z 14.15.26726.0140CRT_ASSEMBLY_VERSION.rkz9Cannot import msvcrt: using manifest will not be possiblecCsTz tt|d|}Wntytd||fdwtd}||||dS)zUGiven a major and minor version of the MSVCR, returns the corresponding XML file. z)Version %d,%d of MSVCRT not supported yetNa )fullvermajmin)_MSVCRVER_TO_FULLVERstrKeyErrorr{textwrapdedent)rrrtemplater r r msvc_manifest_xml2s  rrcCs4|dkrd}n |dkrd}ntd|d||fS)aWReturn the rc file used to generate the res file which will be embedded as manifest for given manifest file name, of given type ('dll' or 'exe'). Parameters ---------- name : str name of the manifest file to embed type : str {'dll', 'exe'} type of the binary which will embed the manifest rrkexerzType %s not supportedz&#include "winuser.h" %d RT_MANIFEST %s)r{)rtyperctyper r r manifest_rcRs  rcCs2t}|r|t|kstdt||fdSdS)z6msver is the ms runtime version used for the MANIFEST.zKDiscrepancy between linked msvcr (%d) and the one about to be embedded (%d)N)r rr{)msverrr r r !check_embedded_msvcr_match_linkedjs  rcCs&tj|dgd}tj|dS)Nyocr)rOrPrU_gen_temp_sourcefilerQ)configr\r r r configtest_namevsrcCst|}|jj}||dS)Nz .manifest)rr exe_extension)rrexextr r r manifest_namezs rcCst|}|dS)NrN)r)rrr r r rc_namesrcCst}|durH|dkrJt|t|d\}}tt|t|}tt|d}|j t|| |WddS1sAwYdSdSdS)Nrr) get_build_msvc_versionrrrrrrr temp_filesr;r)rrma_strmi_strmanxmlmanr r r generate_manifests "r)F)r)=rcrOrwrqr#r'rnumpy.distutils.ccompilernumpyrrdistutils.cygwinccompilerrdistutils.versionrdistutils.unixccompilerrdistutils.msvccompilerrr distutils.errorsrnumpy.distutils.misc_utilrrr r rr get_msvcrcompilerrr rrrrrr-r,rrrrmsvcrtrsrrmajorminorrest ImportErrorrrrrrrrrr r r r sj        B) ; $B