U C^ l@sddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddlTddlmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#m$Z$z ddl%Z%Wne&k r ddl'Z%YnXda(e%)Z*e+Z,d dZ-ddZ.ddZ/e.e0de/dMddZ1e.e0de1dNddZ2e.e0de2dOddZ3e.e0de3dPdd Z4e.e0d!e4d"d#Z5d$d%Z6e.e0d&e6dQd'd(Z7e.e0d)e7dRd+d,Z8d-dgfd.d/Z9e.e0d0e9d1d2Z:e.e0d3e:d4e;d5<d6e;d7<d8e;d9<d:e;d;<de;d?<e jdDdEe j<e _Es z _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsZdep_fileflinesZcmdlineZ last_cmdlinecontentsdepsZt_objr r r! _needs_build%s&    r7cs:tjddkrtd|}n fdd}t|||dS)Nrcs|f||SNr )selfargskwfuncr r!\z replace_method..)sys version_infotypes MethodTypesetattr)klass method_namer>mr r=r!replace_methodWs rIcCsdS)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_executablesesrKfind_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_spawnss4    rbspawnrc 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_extensionsUnknownFileErrorr)Z obj_extensionappend) r:Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namebaseextidZobj_namer r r!CCompiler_object_filenamess&     rvZobject_filenamesc  s`t} ttdkrt| aW5QRX|s0gStjddkrTddlm} m } m } nddl m} m } m } t | rg} dD]4}t d|}|dkrqz| d|d |fqzd | } nj}d d |f} t| |||||\}}}||d d } r.| d d 7} t| fdd}t | rt|}gg}}|D]r}||krp||\}}jdkrt|}t|}| |r| |s||||ffn||||ffqp|}|D]}||qn|}t|dkrH| dkrHddl}|j| }||||n|D]}||qL|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. Nrr8rd) FCompiler is_f_filehas_f90_header)Zf77Zf90ZfixZ compiler_zFortran %s compiler: %srMrzC compiler: %s zcompile options: '%s'z extra options: '%s'cs|\}\}}t|sdSt$|tkrBt|W5QRqXW5QRXtdqz(t|||W5QRXW5tt|W5QRXXdS)Ng?) r7 _global_lock_processing_filesaddtimesleepremove_job_semaphore_compile)r;r/srcrsr0r1r2r:r r!single_compile3s   "z)CCompiler_compile..single_compileZabsoft) rrzr threading SemaphorerArBZ fcompilerrwrxryZnumpy.distutils.fcompiler isinstancegetattrror) compiler_sorrRZ_setup_compileZ _get_cc_argsrQkeys compiler_typeritemslenZmultiprocessing.poolpoolZ ThreadPoolmapclose)r:sourcesrpmacros include_dirsdebug extra_preargsr1dependsjobsrwrxryr]ZfcZfcompZccompZobjectsbuildrZobjects_to_buildZ f77_objectsZ other_objectsr/rrsZ build_itemsr_multiprocessingrr rr!CCompiler_compilesn+                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)attrr\ignorer r!allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrR __class____name__Zset_include_dirsrrZ define_macrorZundefine_macroZ set_librariesrZset_library_dirsrZset_runtime_library_dirsrZset_link_objectsr)r:r\rrnamevaluemacror rr!CCompiler_customize_cmdvs(     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%-rdzs = %scsg|] }|qSr r )rpropfmtr r!r"sz'_compiler_to_string..r) rQZ executablesrrohasattrrmaxrreprr))compilerpropsZmxrkeyvr4r 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. rezP********************************************************************************N) rr get_version Exception _global_log thresholdprintrrrJr 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++rdNz#### %s ####### compiler_cxxzMissing compiler_cxx fix for rZclangTr#zfile.cwzint a; z-MMDz-MFr)rprF)rrRrrr rrAttributeError ValueErrorrrrrjreplacewarnZ _auto_dependsr$rtempfileshutilmkdtemprmtreer%r)r'writerr ) r:distZneed_cxxabrrZtmpdirfnr3r 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)NrrMr)rrZmatchendr[group)r:version_stringposrHrpatstartr r!matcherEs  z%simple_version_match..matcherr )rrrrr rr!simple_version_match+srFc 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)rZrr)rrHrrr r!r~s   z&CCompiler_get_version..matcherrNrPr@)rrrL version_cmdrZ version_matchZversion_patternrTrUrVrWrXrYr.rr ) r:forceZ ok_statusrrrXr^statusrr rr!CCompiler_get_versionZsD       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. )msvcintelwintelemwrrdNaixZ ld_so_aixre)rrrrrAplatformrj 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 Csr|dkrttjk}|dkr$tj}z"|dkr6t|}t|\}}}Wn8tk r~d|}|dk rr|d|}t|YnXd|}z t |Wnvt k r t t }t dt ||dd}z t |Wn,t k rt t }td|YnXYnXztj|} t| |} Wn&tk rLtd||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$rZget_default_compilercompiler_classKeyErrorr __import__ ImportErrorstrrrRr rAmodulesvarsrSr) platrrSdry_runr module_name class_namelong_descriptionramodulerFr r r! new_compilersP         rcCsBt||||}g}|D]&}t|r2|t|q||q|Sr9)_distutils_gen_lib_optionsrextendrQro)rrruntime_library_dirsrrZlib_optsrtr r r!gen_lib_options s r)Zmsvc9rZ_msvcZbcppZcygwincZemxcZunixcz distutils.r)N)rr)NNNrNNN)r )r)rrr)NNNrr)H __future__rrrr$rZrArCr*r}rTr distutilsrdistutils.ccompilerdistutils.errorsrr r r distutils.sysconfigr Zdistutils.versionr Znumpy.distutilsrZnumpy.distutils.compatrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrrrZdummy_threadingrLockrzsetr{r7rIrKZ CCompilerrbrvrrrrrrrrrZ_default_compilersrrRrZ_distutils_new_compilerrrZ_ccrget_mrEr r r r!s       2  ?  -    ) #  Q  /C     ,