a :jgp@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZddlmZmZmZmZmZddlmZddlmZdd lmZdd lmZm Z dd l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(Z(da)e(*Z+e,Z-d d Z.ddZ/ddZ0e/ede0dPddZ1e/ede1dQddZ2e/ede2dRddZ3e/ede3dSddZ4e/ed e4d!d"Z5d#d$Z6e/ed%e6dTd&d'Z7e/ed(e7dUd*d+Z8d,dgfd-d.Z9e/ed/e9d0d1Z:e/ed2e:d3e d4<d5e d6<d7e d8<d9e d:<d;e d<<d=e d><d?e d@<dAe dB<e j;dC7_;ejdDkrjdEe dF<e$rjedKdLZee _dMD]0Z?ej@AdNe?dOZBeBdureCeBdLeqdS)WN)copy)Path) 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|sdSt|}|}Wdn1s>0Yt|||}|d}||krhdSd|dd} ddtj| ddD} z2t |j } | D]}t |j | krWdSqWnt yYdS0d S) z Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool .dTNcSs"g|]}|dkr|ds|qS) :)endswith).0xr"C/usr/local/lib/python3.9/site-packages/numpy/distutils/ccompiler.py Gsz _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsZdep_fileflinesZcmdlineZ last_cmdlinecontentsdepsZt_objr"r"r# _needs_build's&  &   r9csfdd}t|||dS)Ncs|g|Ri|SNr")selfargskwfuncr"r#[z replace_method..)setattr)klass method_namer?mr"r>r#replace_methodYs 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"r;r"r"r#CCompiler_find_executablesdsrHfind_executablesc Cs`|dur |nttj}|dur8|}t|r8dt|}t|z,|jrZt j ||dnt j |t j |dWnt j y}z|j }|j}WYd}~nrd}~0ty}zLd|d}z|tjj}Wnty|d}Yn0d}WYd}~nd}~00dSt|r"dt|}|jr2t|td |rFd }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`. env : a dictionary for environment variables, optional Returns ------- None Raises ------ DistutilsExecError If the command failed, i.e. the exit status was not 0. N )env)stderrrKz z utf8sToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)dictr&environrr+listrinfoverbose subprocess check_outputSTDOUTCalledProcessErroroutput returncoder0encodesysstdoutencodingAttributeErrorrresearchr ) r;cmddisplayrKexcosemsgr"r"r#CCompiler_spawnrs>    rhspawnrc Cs|dur d}g}|D]}tjtj|\}}tj|d}|tj|d}|dr|dd}|d|} tjtj | } | ||d}||j vrt 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_extensionsrr+Z obj_extensionappend) r;Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namebaseextidobj_namer"r"r#CCompiler_object_filenamess&     r|Zobject_filenamesc s|t} t"tdurt| aWdn1s20Y|sDgSddlm} m} m} t | rg} dD]4}t d|}|durqj| d|d |fqjd | } nj }d d |f} t| |||||\}}}||d d } r| d d 7} t| fd d }t | rt|}gg}}|D]|}||vr`||\}}jdkrt|}t|}t|j| vr| |s| |||ffn| |||ffq`|}|D]}||qn|}t|dkrd| dkrdddlm}|| }|||}Wdn1sP0Yt|n|D]}||qh|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) FCompilerFORTRAN_COMMON_FIXED_EXTENSIONShas_f90_header)Zf77f90ZfixZ compiler_zFortran %s compiler: %srJrzC compiler: %s zcompile options: '%s'z extra options: '%s'cs|\}\}}t|sdSt0|tvrDt|WdqnWdn1sX0Ytdqzjt$|||Wdn1s0YWtt|Wdn1s0Yn0tt|Wdn1s0Y0dS)Ng?) r9 _global_lock_processing_filesaddtimesleep_job_semaphore_compileremove)r<r1srcrxr2r3r4r;r"r#single_compile4s  , 4*z)CCompiler_compile..single_compileZabsoftrj)ThreadPoolExecutor)rrr threading SemaphoreZnumpy.distutils.fcompilerr}r~r isinstancegetattrrtr+ compiler_sorrRZ_setup_compileZ _get_cc_argsrQkeys compiler_typerrsuffixloweritemslenconcurrent.futuresrmap)r;sourcesrumacros include_dirsdebug extra_preargsr3dependsjobsr}r~rrbfcZfcompZccompobjectsbuildrZobjects_to_buildZ f77_objectsZ other_objectsr1rrxZ build_itemsrdrpoolresr"rr#CCompiler_compilesl((              ,  rcompiler"cs(td|jjjjft|dr`d|jdvr`tdkrHtjdks`|j d|j dfdd }|d r| j |d rj D]\}}|||q|d rĈjD]}||q|d r||jj|dr||jj|dr|j|dr$|jdS)a Customize compiler using distutils command. Parameters ---------- cmd : class instance An instance inheriting from ``distutils.cmd.Command``. ignore : sequence of str, optional List of ``distutils.ccompiler.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 %scompilerclangrarm64darwinz-ftrapping-mathcst|dduo|vSr:)r)attrraignorer"r#allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrR __class____name__hasattrrplatformmachiner[rtrZset_include_dirsrrZ define_macrorZundefine_macroZ set_librariesrZset_library_dirsrZset_runtime_library_dirsrZset_link_objectsr)r;rarrnamevaluemacror"rr#CCompiler_customize_cmdxs<           rZ customize_cmdcsg}d}t|j}dD]}||vr||q|D]8}t||r6t||}t|t|}||t|fq6dt|ddfdd|D}d |S) Nr) versionrrZ object_switchZcompile_switchrrrrrz%-rjzs = %scsg|] }|qSr"r")r propfmtr"r#r$rAz'_compiler_to_string..r) rQZ executablesrrtrrmaxrreprr+)rpropsZmxrkeyvr6r"rr#_compiler_to_strings   rcCsVz |WntyYn0tjjdkrRtdt|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. rkzP********************************************************************************N) get_version Exceptionr _global_log thresholdprintrrrGr"r"r#CCompiler_show_customizations     rZshow_customizationc Cstd|jjt||rz|jdWnttfyDYn0t |drd|j dvr|j s|j d dr~d\}}nd\}}|j d ||g|j d d |_ n8t |drtd |j ft |d std |jjt |dr(d|j dvs d|j dvs d|j dvr(d|_ntjdkrdd l}dd l}|}zzjtj|d}t|d} | dWd n1s0Y|j|g|dd|dgdd|_Wntyd|_Yn0W||n ||0d S)ao 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++rjNz#### %s ####### compiler_cxxzMissing compiler_cxx fix for rrTr%zfile.cwzint a; z-MMDz-MFr)rurF)rrRrrrrrr^ ValueErrorrrrrpreplacewarnZ _auto_dependsr&rtempfileshutilmkdtempr'r+r)writerr rmtree) r;distZneed_cxxabrrZtmpdirfnr5r"r"r#CCompiler_customizesR        *   rZ customize[-.\d]+csfdd}|S)ak 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 ``distutils.ccompiler.CCompiler`` class. `matcher` takes a single parameter, a version string. csz|dd}d}r0t|}|s(dS|}t||d}|sLdSrpt|drp|}q0qpq0|dS)NrrJr)rr_matchendr`group)r;version_stringposrErpatstartr"r#matcherLs  z%simple_version_match..matcherr")rrrrr"rr#simple_version_match2srFc s2|st|dr|jS|z |j}Wnty:YdS0|rH|dsLdSz |j}Wn@tyz |jWntyYYdS0fdd}Yn0ztj|tj d}WnJtj y}z|j }|j }WYd}~n.d}~0t yd}d}Yn0t|}d}d}||vr(||}|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)r_rr)rrErrr"r#rs   z&CCompiler_get_version..matcher)rLrNrA)rrrI version_cmdr^Z version_matchZversion_patternrTrUrVrWrXrYr0rr) r;forceZ ok_statusrrrXrcstatusrr"rr#CCompiler_get_versionasD           rrcCs|jdvr|St|}|j|_|jdgt|jdd|_tjdr|d|jdvr||jd|jdg|jdd|_tjdr|j d |j d |j d n|jdg|jdd|_|S) z Return the C++ compiler. Parameters ---------- None Returns ------- cxx : class instance The C++ compiler, as a ``distutils.ccompiler.CCompiler`` instance. )msvcintelwintelemwrrjN)aixos400Z ld_so_aixrkrz-D__STDC_FORMAT_MACROSz-fno-extern-tls-init) rrrrrr[rrp linker_sort)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)Z armccompilerZ ArmCCompilerzArm C Compilerarm)ZfujitsuccompilerZFujitsuCCompilerzFujitsu C CompilerZfujitsu))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|durttjk}|dur$tj}z"|dur6t|}t|\}}}Wn6ty|d|}|durp|d|}t|Yn0d|}z t |Wnt y$} zxt | }t dt ||dd}z t |Wn:t y} z t | }t d|WYd} ~ n d} ~ 00WYd} ~ n d} ~ 00ztj|} t| |} Wn$tydt d||fYn0| 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__ ImportErrorstrrRr r[modulesvarsrSr) platrrSdry_runr module_name class_namelong_descriptionrgrfmodulerCr"r"r#rsP     2   rcCsBt||||}g}|D]&}t|r2|t|q||q|Sr:)_distutils_gen_lib_optionsrextendrQrt)rrruntime_library_dirsrrZlib_optsryr"r"r#r s r)Zmsvc9rZ_msvcZbcppZcygwincZemxcZunixcz distutils.r)NN)rr)NNNrNNN)r")r)rrr)NNNrr)Dr&r_r[rr,rrTrpathlibr distutilsrdistutils.ccompilerrrrrr distutils.errorsr r r r rdistutils.sysconfigrZdistutils.versionrZnumpy.distutilsrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrrrrLockrsetrr9rFrHrhr|rrrrrrrrZ_default_compilersrRZ_distutils_new_compilerrZ_ccrget_mrBr"r"r"r#s       2   G  -    6   Q  /C $    ,