U Dx`i@sddlZddlZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZddlmZmZmZmZmZddlmZddlmZddlmZdd lmZmZdd lmZm Z m!Z!m"Z"m#Z#z ddl$Z$Wne%k rddl&Z$YnXda'e$(Z)e*Z+d d Z,d dZ-ddZ.e-ede.dKddZ/e-ede/dLddZ0e-ede0dMddZ1e-ede1dNddZ2e-ede2d d!Z3d"d#Z4e-ed$e4dOd%d&Z5e-ed'e5dPd)d*Z6d+dgfd,d-Z7e-ed.e7d/d0Z8e-ed1e8d2e d3<d4e d5<d6e d7<d8e d9<d:e d;<d7_9ej:d?krdd@e dA<e!rde;dBdCej9e_9e Zej?@dIe>dJZAeAdk reBeAdGe qdS)RN)copy) ccompiler)compiler_classgen_lib_optionsget_default_compiler new_compiler CCompiler)DistutilsExecErrorDistutilsModuleErrorDistutilsPlatformError CompileErrorUnknownFileError)customize_compiler) LooseVersion)log)filepath_from_subprocess_outputforward_bytes_to_stdout) cyg2win32 is_sequencemingw32get_num_build_jobs_commandline_dep_stringc Cs|d}tj|sdSt|d}|}W5QRXt|||}|d}||krVdSd|dd} ddtj| dd D} z2t |j } | D]}t |j | krWdSqWnt k rYdSXd S) z Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool .dTrNcSs"g|]}|dkr|ds|qS) :)endswith).0xr!@/tmp/pip-target-zr53vnty/lib/python/numpy/distutils/ccompiler.py Fs z _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsZdep_fileflinesZcmdlineZ last_cmdlinecontentsdepsZt_objr!r!r" _needs_build&s&    r8csfdd}t|||dS)Ncs|f||SNr!)selfargskwfuncr!r"Zz replace_method..)setattr)klass method_namer>mr!r=r"replace_methodXs rEcCsdS)z Does nothing here, but is called by the get_version method and can be overridden by subclasses. In particular it is redefined in the `FCompiler` class where more documentation can be found. Nr!r:r!r!r"CCompiler_find_executablescsrGfind_executablesc Cs|dkr"|}t|r"dt|}t|z&|jr@t|ntj|tjdWnJtj k r}z|j }|j }W5d}~XYn t k rd}d}YnXdSt|rdt|}|jrt |td|rd}nd}td |||fdS) a Execute a command in a sub-process. Parameters ---------- cmd : str The command to execute. display : str or sequence of str, optional The text to add to the log file kept by `numpy.distutils`. If not given, `display` is equal to `cmd`. Returns ------- None Raises ------ DistutilsExecError If the command failed, i.e. the exit status was not 0. N stderrr@sToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)rr*listrinfoverbose subprocess check_outputSTDOUTCalledProcessErroroutput returncoder/rresearchr )r:cmddisplayexcosmsgr!r!r"CCompiler_spawnqs4    r^spawnrc Cs|dkr d}g}|D]}tjtj|\}}tj|d}|tj|d}|dr|dd}|d|} tjtj | } | ||d}||j krt d||f|rtj|}tj |||j } || q|S)a Return the name of the object files for the given source files. Parameters ---------- source_filenames : list of str The list of paths to source files. Paths can be either relative or absolute, this is handled transparently. strip_dir : bool, optional Whether to strip the directory from the returned paths. If True, the file name prepended by `output_dir` is returned. Default is False. output_dir : str, optional If given, this path is prepended to the returned paths to the object files. Returns ------- obj_names : list of str The list of paths to the object files corresponding to the source files in `source_filenames`. Nrz..z"unknown file type '%s' (from '%s'))r%r&splitextnormpath splitdriveisabs startswithrfindbasenameabspathZsrc_extensionsr r*Z obj_extensionappend) r:Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namebaseextidZobj_namer!r!r"CCompiler_object_filenamess&     rqZobject_filenamesc  s<t} ttdkrt| aW5QRX|s0gSddlm} m} m} t | rg} dD]4}t d|}|dkrrqV| d|d |fqVd | } nj }d d |f} t| |||||\}}}||d d } r | d d 7} t| fd d }t | rt|}gg}}|D]r}||krL||\}}jdkrt|}t|}| |r| |s| |||ffn| |||ffqL|}|D]}||qn|}t|dkr$| dkr$ddl}|j| }||||n|D]}||q(|S)a Compile one or more source files. Please refer to the Python distutils API reference for more details. Parameters ---------- sources : list of str A list of filenames output_dir : str, optional Path to the output directory. macros : list of tuples A list of macro definitions. include_dirs : list of str, optional The directories to add to the default include file search path for this compilation only. debug : bool, optional Whether or not to output debug symbols in or alongside the object file(s). extra_preargs, extra_postargs : ? Extra pre- and post-arguments. depends : list of str, optional A list of file names that all targets depend on. Returns ------- objects : list of str A list of object file names, one per source file `sources`. Raises ------ CompileError If compilation fails. Nr) FCompiler is_f_filehas_f90_header)Zf77Zf90ZfixZ compiler_zFortran %s compiler: %srIrzC compiler: %s zcompile options: '%s'z extra options: '%s'cs|\}\}}t|sdSt$|tkrBt|W5QRqXW5QRXtdqz(t|||W5QRXW5tt|W5QRXXdS)Ng?) r8 _global_lock_processing_filesaddtimesleepremove_job_semaphore_compile)r;r0srcrnr1r2r3r:r!r"single_compile-s   "z)CCompiler_compile..single_compileZabsoftr`)rrur{ threading SemaphoreZnumpy.distutils.fcompilerrrrsrt isinstancegetattrrjr* compiler_sorrNZ_setup_compileZ _get_cc_argsrMkeys compiler_typeritemslenZmultiprocessing.poolpoolZ ThreadPoolmapclose)r:sourcesrkmacros include_dirsdebug extra_preargsr2dependsjobsrrrsrtrYZfcZfcompZccompZobjectsbuildrZobjects_to_buildZ f77_objectsZ other_objectsr0r}rnZ build_itemsr[multiprocessingrr!r~r"CCompiler_compilesj+                rcompiler!cstd|jjjjffdd}|dr<|j|dr`jD]\}}|||qJ|dr~jD]}| |qn|dr| |j j |dr| |j j |d r|j|d r|jd S) a Customize compiler using distutils command. Parameters ---------- cmd : class instance An instance inheriting from `distutils.cmd.Command`. ignore : sequence of str, optional List of `CCompiler` commands (without ``'set_'``) that should not be altered. Strings that are checked for are: ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs', 'rpath', 'link_objects')``. Returns ------- None zcustomize %s using %scst|ddk o|kSr9)r)attrrXignorer!r"allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrN __class____name__Zset_include_dirsrrZ define_macrorZundefine_macroZ set_librariesrZset_library_dirsrZset_runtime_library_dirsrZset_link_objectsr)r:rXrrnamevaluemacror!rr"CCompiler_customize_cmdps(     rZ customize_cmdcsg}d}t|j}dD]}||kr||q|D]8}t||r6t||}t|t|}||t|fq6dt|ddfdd|D}d |S) Nr) versionrrZ object_switchZcompile_switchrrrrrz%-r`zs = %scsg|] }|qSr!r!)rpropfmtr!r"r#sz'_compiler_to_string..r) rMZ executablesrrjhasattrrmaxrreprr*)compilerpropsZmxrkeyvr5r!rr"_compiler_to_strings   rcCsXz |Wntk r YnXtjjdkrTtdt|jtt|tddS)z Print the compiler customizations to stdout. Parameters ---------- None Returns ------- None Notes ----- Printing is only done if the distutils log threshold is < 2. razP********************************************************************************N) get_version Exceptionr _global_log thresholdprintrrrFr!r!r"CCompiler_show_customizations    rZshow_customizationc Cstd|jjt||rz|jdWnttfk rFYnXt |drd|j dkr|j s|j d drd\}}nd\}}|j d ||g|j d d |_ n8t |drtd |j ft |d std |jjt |dr*d|j dks"d|j dks"d|j dkr*d|_ntjdkrdd l}dd l}|}zvzTtj|d}t|d} | dW5QRX|j|g|dd|dgdd|_Wntk rd|_YnXW5||Xd S)am Do any platform-specific customization of a compiler instance. This method calls `distutils.sysconfig.customize_compiler` for platform-specific customization, as well as optionally remove a flag to suppress spurious warnings in case C++ code is being compiled. Parameters ---------- dist : object This parameter is not used for anything. need_cxx : bool, optional Whether or not C++ has to be compiled. If so (True), the ``"-Wstrict-prototypes"`` option is removed to prevent spurious warnings. Default is False. Returns ------- None Notes ----- All the default options used by distutils can be extracted with:: from distutils import sysconfig sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO') z customize %sz-Wstrict-prototypesrccrgcc)rg++)rzc++r`Nz#### %s ####### compiler_cxxzMissing compiler_cxx fix for rZclangTr$zfile.cwzint a; z-MMDz-MFr)rkrF)rrNrrrrrzAttributeError ValueErrorrrrrfreplacewarnZ _auto_dependsr%rtempfileshutilmkdtemprmtreer&r*r(writerr ) r:distZneed_cxxabrrtmpdirfnr4r!r!r"CCompiler_customizesR            rZ customize[-.\d]+csfdd}|S)aU Simple matching of version numbers, for use in CCompiler and FCompiler. Parameters ---------- pat : str, optional A regular expression matching version numbers. Default is ``r'[-.\d]+'``. ignore : str, optional A regular expression matching patterns to skip. Default is ``''``, in which case nothing is skipped. start : str, optional A regular expression matching the start of where to start looking for version numbers. Default is ``''``, in which case searching is started at the beginning of the version string given to `matcher`. Returns ------- matcher : callable A function that is appropriate to use as the ``.version_match`` attribute of a `CCompiler` class. `matcher` takes a single parameter, a version string. csz|dd}d}r0t|}|s(dS|}t||d}|sLdSrpt|drp|}q0qpq0|dS)NrrIr)rrVmatchendrWgroup)r:version_stringposrDrpatstartr!r"matcher7s  z%simple_version_match..matcherr!)rrrrr!rr"simple_version_matchsrFc s:|st|dr|jS|z |j}Wntk r<YdSX|rJ|dsNdSz |j}WnDtk rz |jWntk rYYdSXfdd}YnXztj|tj d}WnLtj k r}z|j }|j }W5d}~XYn*t k rd}d}YnXt|}d}d}||kr0||}|r0t|}||_|S) a Return compiler version, or None if compiler is not available. Parameters ---------- force : bool, optional If True, force a new determination of the version, even if the compiler already has a version attribute. Default is False. ok_status : list of int, optional The list of status values returned by the version look-up process for which a version string is returned. If the status value is not in `ok_status`, None is returned. Default is ``[0]``. Returns ------- version : str or None Version string, in the format of `distutils.version.LooseVersion`. rNrcs"t|}|sdS|d}|S)Nr)rVrr)rrDrrr!r"rps   z&CCompiler_get_version..matcherrJrLr@)rrrH version_cmdrZ version_matchZversion_patternrPrQrRrSrTrUr/rr) r:forceZ ok_statusrrrTrZstatusrr!rr"CCompiler_get_versionLsD       rrcCs|jdkr|St|}|jdg|jdd|_tjdrrd|jdkrr|jd|jdg|jdd|_n|jdg|jdd|_|S)z Return the C++ compiler. Parameters ---------- None Returns ------- cxx : class instance The C++ compiler, as a `CCompiler` instance. )msvcintelwintelemwrr`NaixZ ld_so_aixra)rrrrsysplatformrf linker_so)r:cxxr!r!r"CCompiler_cxx_compilers  rZ cxx_compiler)intelccompilerZIntelCCompilerz(Intel C Compiler for 32-bit applicationsintel)rZIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsintele)rZIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsintelem)rZIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsr)rZIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsr)Z pathccompilerZPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationspathcc))linux.*r)rr)rr)rr)ntr)rrwin32)Zmingw32ccompilerZMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)rz+Setting mingw32 as default compiler for nt.))rrc Cs|dkrttjk}|dkr$tj}z"|dkr6t|}t|\}}}Wn8tk r~d|}|dk rr|d|}t|YnXd|}z t |Wnt k r"} znt | }t dt ||dd}z t |Wn8t k r} zt | }t d|W5d} ~ XYnXW5d} ~ XYnXztj|} t| |} Wn&tk rdt d||fYnX| d||}||_td| |S) Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerznumpy.distutils.z,%s in numpy.distutils; trying from distutilsz4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s'znew_compiler returns %s)rZ get_thresholdINFOr%rrrKeyErrorr __import__ ImportErrorstrrNr rmodulesvarsrOr) platrrOdry_runr module_name class_namelong_descriptionr]emodulerBr!r!r"rsP    *   rcCsBt||||}g}|D]&}t|r2|t|q||q|Sr9)_distutils_gen_lib_optionsrextendrMrj)rrruntime_library_dirsrrZlib_optsror!r!r"rs r)Zmsvc9rZ_msvcZbcppZcygwincZemxcZunixcz distutils.r)N)rr)NNNrNNN)r!)r)rrr)NNNrr)Cr%rVrr+rxrPr distutilsrdistutils.ccompilerrrrrrdistutils.errorsr r r r r distutils.sysconfigrZdistutils.versionrZnumpy.distutilsrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrrrZdummy_threadingr{Lockrusetrvr8rErGr^rqrrrrrrrrZ_default_compilersrrNZ_distutils_new_compilerrZ_ccrget_mrAr!r!r!r"s      2   ?  -    )   Q  /C     ,