o 6ak@sddlZddlZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZddlmZmZmZmZmZddlmZddlmZddlmZdd lmZmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$ddl%Z%da&e%'Z(e)Z*d d Z+d dZ,ddZ-e,ede-dKddZ.e,ede.dLddZ/e,ede/   dMddZ0e,ede0dNddZ1e,ede1d d!Z2d"d#Z3e,ed$e3dOd%d&Z4e,ed'e4dPd)d*Z5d+dgfd,d-Z6e,ed.e6d/d0Z7e,ed1e7d2e d3<d4e d5<d6e d7<d8e d9<d:e d;<d7_8ej9d?kr&d@e dA<e!r&e:dBdCej8e_8e Z;    dQdDdEZ e e_ e Z?dIe=dJZ@e@durWeAe@dGe q@dS)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_stringsanitize_cxx_flagsc Cs|d}tj|s dSt|d }|}Wdn1s wYt|||}|d}||kr5dSd|dd} ddtj| dd D} zt |j } | D]}t |j | kraWdSqSWd St ynYdSw) 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";/usr/lib/python3/dist-packages/numpy/distutils/ccompiler.py Esz _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsdep_fileflinescmdline last_cmdlinecontentsdepst_objr"r"r# _needs_build%s.      r=csfdd}t|||dS)Ncs|g|Ri|SNr")selfargskwfuncr"r#Ysz replace_method..)setattr)klass method_namerCmr"rBr#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_executablesbsrKfind_executablesc Cs:|dur|}t|rdt|}t|z|jr"t|WdStj|tjdWdStj yE}z |j }|j }WYd}~n6d}~wt yv}z&d|d}z | tjj}Wntyi| d}Ynwd}WYd}~nd}~wwt|rdt|}|jrt|td|rd }nd }td |||f) 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 stderrz z utf8sToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)rr+listrinfoverbose subprocess check_outputSTDOUTCalledProcessErroroutput returncoder0encodesysstdoutencodingAttributeErrorrresearchr )r?cmddisplayexcosemsgr"r"r#CCompiler_spawnpsF     rispawnrc Cs|durd}g}|D]h}tjtj|\}}tj|d}|tj|d}|drN|dd}|d|} tjtj | } | ||d}||j vr[t d||f|rctj|}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 startswithrfindbasenameabspathsrc_extensionsr r+ obj_extensionappend) r?source_filenames strip_dir output_dir obj_namessrc_namebaseextidobj_namer"r"r#CCompiler_object_filenamess&     robject_filenamesc sBt} ttdurt| aWdn1swY|s"gSddlm} m} m} t | rVg} dD]}t d|}|durCq5| d|d |fq5d | } n j }d d |f} t| |||||\}}}||d d } r| d d 7} t| fd d }t | rt|}gg}}|D]4}||vr||\}}jdkrt|}t|}| |r| |s| |||ffq| |||ffq|}|D]}||qn|}t|dkr| dkrddl}|j| }|||||S|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)f77f90fix compiler_zFortran %s compiler: %srMrzC compiler: %s zcompile options: '%s'z extra options: '%s'cs|\}\}}t|sdS t|tvr$t| WdnWdn1s.wYtdqz7t|||Wdn1sQwYWtt|WddS1sjwYdSt t|Wdw1swYw)NTg?) r= _global_lock_processing_filesaddtimesleep_job_semaphore_compileremove)r@r1srcr~r2r3r4r?r"r#single_compile2s.     ( z)CCompiler_compile..single_compileabsoftrk)rrr threading Semaphorenumpy.distutils.fcompilerrrr isinstancegetattrrwr+ compiler_sorrS_setup_compile _get_cc_argsrRkeys compiler_typeritemslenmultiprocessing.poolpool ThreadPoolmapclose)r?sourcesrzmacros include_dirsdebug extra_preargsr3dependsjobsrrrrcfcfcompccompobjectsbuildrobjects_to_build f77_objects other_objectsr1rr~ build_itemsremultiprocessingrr"rr#CCompiler_compilesr+                rcompiler"cstd|jjjjft|drd|jdvr|jdfdd}|dr0|j|d rBj D] \}}| ||q7|d rQj D]}| |qI|d r^| |jj|d rk||jj|d ru|j|dr|jdSdS)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 %scompilerclangrz-ffp-exception-behavior=strictcst|dduo |vSr>)r)attrrbignorer"r#allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrS __class____name__hasattrrrwset_include_dirsrr define_macrorundefine_macro set_librariesrset_library_dirsrset_runtime_library_dirsrset_link_objectsr)r?rbrrnamevaluemacror"rr#CCompiler_customize_cmdus.      r customize_cmdcsg}d}t|j}dD] }||vr||q |D]}t||r7t||}t|t|}||t|fqdt|ddfdd|D}d |S) Nr) versionrr object_switchcompile_switchrrrrrz%-rkzs = %scsg|]}|qSr"r")r propfmtr"r#r$sz'_compiler_to_string..r) rR executablesrrwrrmaxrreprr+)rpropsmxrkeyvr7r"rr#_compiler_to_strings     rcCsZz|Wn tyYnwtjjdkr+tdt|jtt|tddSdS)z Print the compiler customizations to stdout. Parameters ---------- None Returns ------- None Notes ----- Printing is only done if the distutils log threshold is < 2. rlzP********************************************************************************N) get_version Exceptionr _global_log thresholdprintrrrJr"r"r#CCompiler_show_customizations      rshow_customizationc Cstd|jjt||rrz|jdWn ttfy"Ynwt |drVd|j dvrV|j sU|j d dr?d\}}nd\}}|j d ||g|j d d |_ nt |drdtd |j ft |d srtd |jjt |drd|j dvsd|j dvsd|j dvrd|_d Stjdkrdd l}dd l}|}zQz4tj|d}t|d } | dWd n1swY|j|g|dd|dgdd|_Wn tyd|_Yn wW||d SW||d S||wd 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++rkNz#### %s ####### compiler_cxxzMissing compiler_cxx fix for rrTr%zfile.cwzint a; z-MMDz-MFr)rzrF)rrSrrrrrr_ ValueErrorrrrrqreplacewarn _auto_dependsr&rtempfileshutilmkdtempr'r+r)writerr rmtree) r?distneed_cxxabrrtmpdirfnr6r"r"r#CCompiler_customizesd               r 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}rt|}|sdS|} t||d}|s'dSr7t|dr7|}q |dS)NrrMr)rr`matchendragroup)r?version_stringposrHrpatstartr"r#matcherBs   z%simple_version_match..matcherr")rrr r r"rr#simple_version_match(sr Fc s.|s t|dr |jS|z|j}Wn tyYdSw|r$|ds&dSz|j}Wn tyKz|jWn tyBYYdSwfdd}Ynwz tj|tj d}Wn%tj yo}z |j }|j }WYd}~nd}~wt y{d}d}Ynwt|}d}d}||vr||}|rt|}||_|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|}|s dS|d}|S)Nr)r`rr)rrHrrr"r#r {s  z&CCompiler_get_version..matcherrNrQ)rrrL version_cmdr_ version_matchversion_patternrUrVrWrXrYrZr0rr) r?force ok_statusrr rYrdstatusrr"r r#CCompiler_get_versionWsN         rrcCs|jdvr|St|}|j|_|jdgt|jdd|_tjdr@d|jdvr@|jd|jdg|jdd|_|S|jdg|jdd|_|S)z Return the C++ compiler. Parameters ---------- None Returns ------- cxx : class instance The C++ compiler, as a `CCompiler` instance. )msvcintelwintelemwrrkNaix ld_so_aixrl) rrrrrr\platformrq linker_so)r?cxxr"r"r#CCompiler_cxx_compilers   r cxx_compiler)intelccompilerIntelCCompilerz(Intel C Compiler for 32-bit applicationsintel)rIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsintele)rIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsintelem)rIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsr)rIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsr) pathccompilerPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationspathcc))linux.*r!)r+r#)r+r%)r+r*)ntr)r,rwin32)mingw32ccompilerMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)rz+Setting mingw32 as default compiler for nt.))r,rc Csp|dur ttjk}|durtj}z|durt|}t|\}}}Wnty<d|}|dur8|d|}t|wd|}zt |WnAt y} z5t | }t dt ||dd}zt |Wnt y}} z t | }t d|d} ~ wwWYd} ~ nd} ~ wwz tj|} t| |} Wntyt d||fw| 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)r get_thresholdINFOr&rrrKeyErrorr __import__ ImportErrorstrrSr r\modulesvarsrTr) platrrTdry_runr module_name class_namelong_descriptionrhrgmodulerFr"r"r#rs^         rcCsBt||||}g}|D]}t|r|t|q ||q |Sr>)_distutils_gen_lib_optionsrextendrRrw)rrruntime_library_dirsrrlib_optsrr"r"r#r s r)msvc9r_msvcbcppcygwincemxcunixcz distutils.rr>)rr)NNNrNNN)r")r)rrr)NNNrr)Br&r`r\r,rrUr distutilsrdistutils.ccompilerrrrrrdistutils.errorsr r r r r distutils.sysconfigrdistutils.versionrnumpy.distutilsrnumpy.distutils.exec_commandrrnumpy.distutils.misc_utilrrrrrrrrLockrsetrr=rIrKrirrrrrrr rr_default_compilersrrS_distutils_new_compilerr?_ccr7get_mrEr"r"r"r#s      2  E  -    /   Q / C    ,