B []k@sddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddlTddlmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#m$Z$y 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 _Esz _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsZdep_fileflinesZcmdlineZ last_cmdlinecontentsdepsZt_objrrr _needs_build%s&      r6cs:tjddkrtd|}n fdd}t|||dS)Nrcs|f||S)Nr)selfargskw)funcrr \z replace_method..)sys version_infotypes MethodTypesetattr)klass method_namer;mr)r;r replace_methodWs rFcCsdS)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)r8rrr CCompiler_find_executablesesrGfind_executablesc Cs|dkr"|}t|r"dt|}t|yt|WnJtjk rj}z|j}|j }Wdd}~XYn t k rd}d}YnXdSt|rdt|}t |t d|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 r=sToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)rr(listrinfo subprocess check_outputCalledProcessErroroutput returncoder-rresearchr)r8cmddisplayexcosmsgrrr CCompiler_spawnss,   rZspawnrc Cs|dkr d}g}x|D]}tjtj|\}}tj|d}|tj|d}|dr|dd}|d|} tjtj | } | ||d}||j krt d||f|rtj|}tj |||j } || qW|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) r8Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namebaseextidZobj_namerrr CCompiler_object_filenamess&     rnZobject_filenamesc  spt} ttdkrt| aWdQRX|s0gStjddkrTddlm} m } m } nddl m} m } m } t | rg} x.single_compileZabsoft) rrrrw threading Semaphorer>r?Z fcompilerrorprqZnumpy.distutils.fcompiler isinstancegetattrrgr( compiler_sorrLZ_setup_compileZ _get_cc_argsrKkeys compiler_typeritemslenZmultiprocessing.poolpoolZ ThreadPoolmapclose)r8sourcesrhmacros include_dirsdebug extra_preargsr0dependsjobsrorprqrUZfcZfcompZccompZobjectsbuildr{Zobjects_to_buildZ f77_objectsZ other_objectsr.rzrkZ build_itemsrWmultiprocessingrr)r/r0r1r8r CCompiler_compilesh+                  rcompilercstd|jjjjffdd}|dr<|j|drdxjD]\}}|||qLW|drxjD]}| |qtW|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|kS)N)r)attr)rTignorerr allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrL __class____name__Zset_include_dirsrrZ define_macrorZundefine_macroZ set_librariesrZset_library_dirsrZset_runtime_library_dirsrZset_link_objectsr)r8rTrrnamevaluemacror)rTrr CCompiler_customize_cmdrs&    rZ customize_cmdcsg}d}t|j}xdD]}||kr||qWx@|D]8}t||r.r) rKZ executablesrrghasattrrmaxrreprr()compilerpropsZmxrkeyvr3r)rr _compiler_to_strings    rcCsXy |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. r]zP********************************************************************************N) get_version Exceptionr _global_log thresholdprintrr)r8rrr CCompiler_show_customizations    rZshow_customizationc Cstd|jjt||ry|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}|}zvyTtj|d}t|d} | dWd QRX|j|g|dd|dgdd|_Wntk rd|_YnXWd ||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)rzg++)rzc++r\Nz#### %s ####### compiler_cxxzMissing compiler_cxx fix for zg++ZclangTr"zfile.cwzint a; z-MMDz-MFz.d)rhrF)rrLrrr rryAttributeError ValueErrorrrrrbreplacewarnZ _auto_dependsr#rtempfileshutilmkdtempr$r(r&writerr rmtree) r8distZneed_cxxabrrZtmpdirfnr2rrr CCompiler_customizesJ        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. cs~|dd}d}r0t|}|s(dS|}xBt||d}|sNdSrnt|drn|}q2Pq2W|dS)NrrIr)rrRmatchendrSgroup)r8version_stringposrE)rpatstartrr matcherAs   z%simple_version_match..matcherr)rrrrr)rrrr simple_version_match'srFc s2|st|dr|jS|y |j}Wntk r:dSX|rH|dsLdSy |j}Wn@tk ry |jWntk rdSXfdd}YnXytj|tj d}WnJtj k r}z|j }|j }Wdd}~XYn(t k rd}d}YnXt|}d}d}||kr(||}|r(t|}||_|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)rRrr)rrEr)rrr rzs   z&CCompiler_get_version..matcher)stderrrJr=)rrrH version_cmdrZ version_matchZversion_patternrMrNSTDOUTrOrPrQr-rr ) r8forceZ ok_statusrrrPrVstatusrr)rr CCompiler_get_versionVsD      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_aixr])rrrrr>platformrb linker_so)r8cxxrrr 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))zlinux.*r)zlinux.*r)zlinux.*r)zlinux.*r)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|dkrtj}y"|dkr t|}t|\}}}Wn8tk rhd|}|dk r\|d|}t|YnXd|}y t|Wnrtk rtt }t dt||dd}y t|Wn*tk rtt }t d|YnXYnXyt j|} t| |} Wn&tk r2t d||fYnX| d||}t d| |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)r#rZget_default_compilercompiler_classKeyErrorr __import__ ImportErrorstrrrrLr r>modulesvarsr) platrverbosedry_runr module_name class_namelong_descriptionrYmodulerCrrr new_compilersD         rcCsFt||||}g}x.|D]&}t|r4|t|q||qW|S)N)_distutils_gen_lib_optionsrextendrKrg)rrruntime_library_dirsrrZlib_optsrlrrr gen_lib_optionss r)Zmsvc9rZ_msvcZbcppZcygwincZemxcZunixcz distutils.r)N)rr)NNNrNNN)r)r)rrr)NNrrr)H __future__rrrr#rRr>r@r)rurMr distutilsrdistutils.ccompilerdistutils.errorsrr r r distutils.sysconfigr Zdistutils.versionr Znumpy.distutilsrZnumpy.distutils.compatrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrr|rZdummy_threadingrwLockrrsetrsr6rFrGZ CCompilerrZrnrrrrrrrrrZ_default_compilersrrLrZ_distutils_new_compilerrrZ_ccrget_mrBrrrr s       2  ;  -    ) #  Q  /C      %