
    wff1|                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZmZmZ ddlmZ  ej8                  d      Zd Z G d de      Zy)zdistutils.command.build_ext

Implements the Distutils 'build_ext' command, for building extension
modules (currently limited to C extensions, should accommodate C++
extensions ASAP).    N)log)	USER_BASE   )newer_group)Command)CCompilerErrorCompileErrorDistutilsErrorDistutilsOptionErrorDistutilsPlatformErrorDistutilsSetupError)	Extension)customize_compilerget_config_h_filenameget_python_version)get_platformz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$c                      ddl m}   |         y )Nr   show_compilers)	ccompilerr   r   s    `C:\xampp-8.1.2\htdocs\client\python\Lib\site-packages\setuptools/_distutils/command/build_ext.pyr   r   !   s    *    c                   6   e Zd ZdZdej
                  z  Zddddd e       z  fdd	d
dez   fddddddez   fddddddddddgZg dZ	ddde
fgZd  Zed!        Zd" Zd# Zd$ Zd% Zd& Zd' Zd( Zd) Zej0                  d*        Zd+ Zd, Zd- Zd. Zd/ Zd0 Zd1 Z d2 Z!y)3	build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s'))z
build-lib=bz(directory for compiled extension modules)zbuild-temp=tz1directory for temporary files (build by-products)z
plat-name=pz>platform name to cross-compile for, if supported (default: %s))inplaceiziignore build-lib and put compiled extensions into the source directory alongside your pure Python moduleszinclude-dirs=Iz.list of directories to search for header files)zdefine=DzC preprocessor macros to define)zundef=Uz!C preprocessor macros to undefine)z
libraries=lz!external C libraries to link withzlibrary-dirs=Lz.directories to search for external C libraries)zrpath=Rz7directories to search for shared C libraries at runtime)zlink-objects=Oz2extra explicit link objects to include in the link)debuggz'compile/link with debugging information)forcefz2forcibly build everything (ignore file timestamps))z	compiler=czspecify the compiler type)z	parallel=jznumber of parallel build jobs)swig-cppNz)make SWIG create C++ files (default is C))z
swig-opts=Nz!list of SWIG command line options)zswig=Nzpath to the SWIG executable)userNz#add user include, library and rpath)r   r'   r)   r-   r.   zhelp-compilerNzlist available compilersc                 *   d | _         d | _        d | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        y )Nr   )
extensions	build_lib	plat_name
build_tempr   packageinclude_dirsdefineundef	librarieslibrary_dirsrpathlink_objectsr'   r)   compilerswigswig_cpp	swig_optsr.   parallelselfs    r   initialize_optionszbuild_ext.initialize_optionsk   s     
 
 

		r   c              #   (  K   | j                  d      sy| j                  rd yt        j                  dk(  rE| j                  d      }| j                  d      }t        j
                  j                  ||       y| j                  d       yw)z
        Resolve Python's library directory for building extensions
        that rely on a shared Python library.

        See python/cpython#44264 and python/cpython#48686
        Py_ENABLE_SHAREDN.zosbase
platlibdirLIBDIR)get_config_varpython_buildsysplatformospathjoin)	sysconfiginstalled_dirlib_dirs      r   _python_lib_dirzbuild_ext._python_lib_dir   s      ''(:;!!I<<5  &44V<M..|<G'',,}g66 **844s   BBc           
         ddl m} | j                  ddddddd	d
       | j                  | j                  j
                  | _        | j                  j                  | _        |j                         }|j                  d      }| j                  | j                  j                  xs g | _	        t        | j                  t              r.| j                  j                  t        j                        | _	        t        j                   t        j"                  k7  rG| j                  j%                  t        j&                  j)                  t        j                   d             | j                  j+                  |j                  t        j&                  j                               ||k7  rB| j                  j+                  |j                  t        j&                  j                               | j-                  d       | j-                  d       | j.                  g | _        | j0                  g | _        nHt        | j0                  t              r.| j0                  j                  t        j                        | _        | j2                  g | _        nHt        | j2                  t              r.| j2                  j                  t        j                        | _        t        j4                  dk(  r| j0                  j%                  t        j&                  j)                  t        j                   d             t        j"                  t        j6                  k7  rG| j0                  j%                  t        j&                  j)                  t        j"                  d             | j8                  r0t        j&                  j)                  | j:                  d      | _        n/t        j&                  j)                  | j:                  d      | _        | j                  j%                  t        j&                  j=                  t?                            | j0                  j%                  t        j"                         | j@                  dk(  rd}n| j@                  dd  }t        j&                  j)                  t        j                   d      }|r t        j&                  j)                  ||      }| j0                  j%                  |       t        jB                  d d dk(  r||jD                  sU| j0                  j%                  t        j&                  j)                  t        j6                  ddtG               z   d             n| j0                  j%                  d       | j0                  j+                  | jI                  |             | jJ                  r2| jJ                  j                  d      }|D cg c]  }|df c}| _%        | jL                  r | jL                  j                  d      | _&        | jN                  g | _'        n | jN                  j                  d      | _'        | jP                  rt        j&                  j)                  tR        d      }t        j&                  j)                  tR        d      }	t        j&                  jU                  |      r| j                  j%                  |       t        j&                  jU                  |	      r6| j0                  j%                  |	       | j2                  j%                  |	       t        | jV                  t              r	 tY        | jV                        | _+        y y c c}w # tZ        $ r t]        d       w xY w)!Nr   )rR   build)r1   r1   )r3   r3   )r<   r<   )r'   r'   )r)   r)   )r@   r@   )r2   r2      )plat_specificincluder8   r;   ntlibsDebugReleasewin32   PCbuild   cygwinlibpythonconfigrF   ,1 zparallel should be an integer)/	distutilsrR   set_undefined_optionsr4   distributionext_packageext_modulesr0   get_python_incr5   
isinstancestrsplitrO   pathseprM   exec_prefixbase_exec_prefixappendrP   rQ   extendensure_string_listr8   r9   r:   nameprefixr'   r3   dirnamer   r2   rN   rL   r   rU   r6   r7   r?   r.   r   isdirr@   int
ValueErrorr   )
rB   rR   
py_includeplat_py_includesuffixnew_libdefinessymboluser_includeuser_libs
             r   finalize_optionszbuild_ext.finalize_options   sB   '""&($$&		
 <<,,88DL++77 --/
#222C$ $ 1 1 > > D"Dd''- $ 1 1 7 7

 CD ??c222$$RWW\\#//9%MN 	  !1!1"''//!BCj($$_%:%:277??%KL,/ >>!DN$ "D))3/ $ 1 1 7 7

 CD::DJ

C())"**5DJ
 77d? $$RWW\\#//6%JK##szz1!!((c6J6JF)STzz"$'',,t"H"$'',,t	"J $$RWW__5J5L%MN$$S%9%9: ~~(  +ggll3??I>G'',,w7$$W- <<x'))!!((GGLL

E86H6J+JH !!((-  !5!5i!@A ;;kk'',G7>?VFC=?DK
 ::))#.DJ>>!DN!^^11#6DN 9977<<	9=Lww||Iu5Hww}}\*!!((6ww}}X&!!((2

!!(+dmmS)L #DMM 2 */ @4  L*+JKKLs   ]+]0 0^c                 P   ddl m} | j                  sy | j                  j	                         rc| j                  d      }| j                  j                  |j                         xs g        | j                  j                  |j                          || j                  | j                  | j                  | j                        | _        t!        | j                         t"        j$                  dk(  r<| j&                  t)               k7  r%| j                  j+                  | j&                         | j,                  %| j                  j/                  | j,                         | j0                  0| j0                  D ]!  \  }}| j                  j3                  ||       # | j4                  ,| j4                  D ]  }| j                  j7                  |        | j                  %| j                  j9                  | j                         | j                  %| j                  j;                  | j                         | j<                  %| j                  j?                  | j<                         | j@                  %| j                  jC                  | j@                         | jE                          y )Nr   )new_compiler
build_clib)r<   verbosedry_runr)   r[   )#r   r   r0   rl   has_c_librariesget_finalized_commandr8   rw   get_library_namesr9   rv   r   r<   r   r   r)   r   rO   ry   r2   r   
initializer5   set_include_dirsr6   define_macror7   undefine_macroset_librariesset_library_dirsr:   set_runtime_library_dirsr;   set_link_objectsbuild_extensions)rB   r   r   ry   valuemacros         r   runzbuild_ext.run'  s   , 
 ,,.33LAJNN!!*">">"@"FBG$$Z%:%:; %]]LLLL**	
 	4==) 77d?t~~?MM$$T^^4 (MM**4+<+<=;;"#{{ 8e**478::! 4,,U34>>%MM''7(MM**4+<+<=::!MM224::>(MM**4+<+<= 	r   c                    t        |t              st        d      t        |      D ]  \  }}t        |t              rt        |t
              rt        |      dk7  rt        d      |\  }}t        j                  d|       t        |t              rt        j                  |      st        d      t        |t              st        d      t	        ||d         }dD ]#  }|j                  |      }|t        |||       % |j                  d
      |_        d|v rt        j                  d       |j                  d      }|rg |_        g |_        |D ]  }	t        |	t
              rt        |	      dv st        d      t        |	      dk(  r|j"                  j%                  |	d          Xt        |	      dk(  sg|j                   j%                  |	        |||<    y	)a  Ensure that the list of extensions (presumably provided as a
        command option 'extensions') is valid, i.e. it is a list of
        Extension objects.  We also support the old-style list of 2-tuples,
        where the tuples are (ext_name, build_info), which are converted to
        Extension instances here.

        Raise DistutilsSetupError if the structure is invalid anywhere;
        just returns otherwise.
        z:'ext_modules' option must be a list of Extension instancesr   zMeach element of 'ext_modules' option must be an Extension instance or 2-tuplezvold-style (ext_name, build_info) tuple found in ext_modules for extension '%s' -- please convert to Extension instancezRfirst element of each tuple in 'ext_modules' must be the extension name (a string)zOsecond element of each tuple in 'ext_modules' must be a dictionary (build info)sources)r5   r9   r8   extra_objectsextra_compile_argsextra_link_argsNr:   def_filez9'def_file' element of build info dict no longer supportedmacros)rX   r   z9'macros' element of build info dict must be 1- or 2-tuplerX   r   )rp   listr   	enumerater   tuplelenr   warningrq   extension_name_rematchdictgetsetattrruntime_library_dirsdefine_macrosundef_macrosrv   )
rB   r0   r   extext_name
build_infokeyvalr   r   s
             r   check_extensions_listzbuild_ext.check_extensions_listi  s    *d+%L   
+ H	 FAs#y) c5)SX])4 
 $' HjKK: 	 x-2C2I2I(2S)< 
 j$/)8  Hj&;<C 
+ !nnS)?Cc*
+ (2~~g'>C$Z'WX  ^^H-F$&!#% # 	8E&ue4Uv9M14  5zQ((//a9Uq))007	8  JqMQH	 r   c                     | j                  | j                         g }| j                  D ]  }|j                  |j                          |S N)r   r0   rw   r   )rB   	filenamesr   s      r   get_source_fileszbuild_ext.get_source_files  sF    ""4??3	 ?? 	*CS[[)	*r   c                     | j                  | j                         g }| j                  D ],  }|j                  | j                  |j                               . |S r   )r   r0   rv   get_ext_fullpathry   )rB   outputsr   s      r   get_outputszbuild_ext.get_outputs  sP     	""4??3
 ?? 	<CNN400:;	<r   c                     | j                  | j                         | j                  r| j                          y | j	                          y r   )r   r0   r@   _build_extensions_parallel_build_extensions_serialrA   s    r   r   zbuild_ext.build_extensions  s3    ""4??3==++-))+r   c                    | j                   }| j                   du rt        j                         }	 ddlm} || j                          y  |      5 }| j                  D cg c]  }|j                  | j                  |        }}t        | j                  |      D ]/  \  }}| j                  |      5  |j                          d d d        1 	 d d d        y # t
        $ r d }Y w xY wc c}w # 1 sw Y   [xY w# 1 sw Y   y xY w)NTr   )ThreadPoolExecutor)max_workers)r@   rO   	cpu_countconcurrent.futuresr   ImportErrorr   r0   submitbuild_extensionzip_filter_build_errorsresult)rB   workersr   executorr   futuresfuts          r   r   z$build_ext._build_extensions_parallel  s    --==D llnG	= ?))+G4 	!FJoo?B 4 4c:G   9 !S..s3 !JJL! !!		! 	!  	G	! !	! 	!sG   C C:!#C)/C:3C.
C:C&%C&)C:.C73C::Dc                     | j                   D ]-  }| j                  |      5  | j                  |       d d d        / y # 1 sw Y   :xY wr   )r0   r   r   )rB   r   s     r   r   z"build_ext._build_extensions_serial  sK    ?? 	*C**3/ *$$S)* *	** *s	   >A	c              #      K   	 d  y # t         t        t        f$ r8}|j                  s | j	                  d|j
                   d|        Y d }~y d }~ww xY ww)Nzbuilding extension "z
" failed: )r   r
   r	   optionalwarnry   )rB   r   es      r   r   zbuild_ext._filter_build_errors  sR     	F= 	F<<II,SXXJjDEE	Fs*   A	 AA.AAAAc                    |j                   }|t        |t        t        f      st	        d|j
                  z        t        |      }| j                  |j
                        }||j                  z   }| j                  s.t        ||d      s!t        j                  d|j
                         y t        j                  d|j
                         | j                  ||      }|j                  xs g }|j                   d d  }|j"                  D ]  }|j%                  |f        | j&                  j)                  || j*                  ||j,                  | j                  ||j                        }|d d  | _        |j0                  r|j3                  |j0                         |j4                  xs g }|j6                  xs | j&                  j9                  |      }	| j&                  j;                  ||| j=                  |      |j>                  |j@                  || jC                  |      | j                  | j*                  |	
       y )Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)
output_dirr   r5   r'   extra_postargsdepends)r8   r9   r   r   export_symbolsr'   r3   target_lang)"r   rp   r   r   r   ry   sortedr   r   r)   r   r   r'   infoswig_sourcesr   r   r   rv   r<   compiler3   r5   _built_objectsr   rw   r   languagedetect_languagelink_shared_objectget_librariesr9   r   get_export_symbols)
rB   r   r   ext_pathr   
extra_argsr   r7   objectsr   s
             r   r   zbuild_ext.build_extension  s   ++?*WtUm"D%-/2xx8  /((2CKK'

k'8WEII<chhGHH.9
 ##GS1  ++1r
""1%%% 	$EMM5(#	$ --''))**%KK ( 
 &aj
 NN3,,-((.B
 <<I4==#@#@#I((((-))!$!9!9%2237**  	) 	
r   c                    g }g }i }| j                   rt        j                  d       | j                   sd| j                  v sd|j                  v rd}nd}|D ]k  }t        j
                  j                  |      \  }}	|	dk(  r1|j                  |dz   |z          |j                  |       |d   ||<   [|j                  |       m |s|S | j                  xs | j                         }
|
dg}|j                  | j                         | j                   r|j                  d       | j                  s"|j                  D ]  }|j                  |        |D ]5  }||   }t        j                  d	||       | j                  |d
||gz          7 |S )zWalk the list of source files in 'sources', looking for SWIG
        interface (.i) files.  Run SWIG on all that are found, and
        return a modified 'sources' list with SWIG source files replaced
        by the generated C (or C++) files.
        z/--swig-cpp is deprecated - use --swig-opts=-c++z-c++z.cppz.cz.i_wrapz-pythonzswigging %s to %sz-o)r>   r   r   r?   rO   rP   splitextrv   r=   	find_swigrw   r   spawn)rB   r   	extensionnew_sourcesr   swig_targets
target_extsourcerH   r   r=   swig_cmdotargets                 r   r   zbuild_ext.swig_sourcesU  s     ==KKIJ MM$..()---JJ 	+F''**62KT3d{""4'>J#>?##F+'22V$""6*	+ yy,DNN,)$'==OOF# ~~(( #"# # 	:F!&)FHH(&&9JJx4"889	:
 r   c                 $   t         j                  dk(  ryt         j                  dk(  rNdD ]H  }t         j                  j                  d|z  d      }t         j                  j	                  |      sF|c S  yt        dt         j                  z        )zReturn the name of the SWIG executable.  On Unix, this is
        just "swig" -- it should be in the PATH.  Tries a bit harder on
        Windows.
        posixr=   r[   )z1.3z1.2z1.1z	c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s')rO   ry   rP   rQ   isfiler   )rB   versfns      r   r   zbuild_ext.find_swig  s    
 77gWW_ . "WW\\,"5zB77>>"%I"
 "(#%'WW- r   c                    | j                  |      }|j                  d      }| j                  |d         }| j                  sMt	        j
                  j                  |dd |gz    }t        j
                  j                  | j                  |      S dj                  |dd       }| j                  d      }t        j
                  j                  |j                  |            }t        j
                  j                  ||      S )zReturns the path of the filename for a given extension.

        The file is located in `build_lib` or directly in the package
        (inplace option).
        rF   r   Nr   build_py)get_ext_fullnamerr   get_ext_filenamer   rO   rP   rQ   r1   r   abspathget_package_dir)rB   r   fullnamemodpathfilenamer4   r   package_dirs           r   r   zbuild_ext.get_ext_fullpath  s     ((2..%((5|| ww||WSb\XJ%>?H77<<99 ((71R=)--j9ggooh&>&>w&GH ww||K22r   c                 B    | j                   |S | j                   dz   |z   S )zSReturns the fullname of a given extension name.

        Adds the `package.` prefixrF   )r4   )rB   r   s     r   r   zbuild_ext.get_ext_fullname  s'     <<O<<#%00r   c                 ~    ddl m} |j                  d      } |d      }t        j                  j
                  | |z   S )zConvert the name of an extension (eg. "foo.bar") into the name
        of the file from which it will be loaded (eg. "foo/bar.so", or
        "foo\bar.pyd").
        r   rK   rF   
EXT_SUFFIX)rR   rK   rr   rO   rP   rQ   )rB   r   rK   r   
ext_suffixs        r   r   zbuild_ext.get_ext_filename  s7    
 	/>>#&#L1
ww||X&33r   c                 d   |j                   j                  d      d   }	 |j                  d       d|z   }d	|z   }||j                  vr|j                  j                  |       |j                  S # t        $ r6 d|j                  d      j	                  dd      j                  d      z   }Y xw xY w)
a  Return the list of symbols that a shared extension has to
        export.  This either uses 'ext.export_symbols' or, if it's not
        provided, "PyInit_" + module_name.  Only relevant on Windows, where
        the .pyd file (DLL) must export the module "PyInit_" function.
        rF   r   ascii_U_punycode   -   _PyInit)ry   rr   encodeUnicodeEncodeErrorreplacedecoder   rv   )rB   r   ry   r   initfunc_names        r   r   zbuild_ext.get_export_symbols  s     xx~~c"2&	  KK  4ZF 6) 2 22%%m4!!! " 	XDKK
3;;D$GNNwWWF	Xs   A0 0<B/.B/c                 4   t         j                  dk(  rwddlm} t	        | j
                  |      sOd}| j                  r|dz   }|t         j                  dz	  t         j                  dz	  dz  fz  }|j                  |gz   S |j                  S dd	l	m
} d
} |d      rVt        t         d      rd}nCt         j                  dk(  rd}n-dt        j                  v r |d      dk7  rd}n |d      dk(  rd}|r |d      }|j                  d|z   gz   S |j                  S )zReturn the list of libraries to link against when building a
        shared extension.  On most platforms, this is just 'ext.libraries';
        on Windows, we add the Python library (eg. python20.dll).
        r_   r   )MSVCCompilerz
python%d%d_d         r  FrE   getandroidapilevelTrc   _PYTHON_HOST_PLATFORMANDROID_API_LEVELr   MACHDEP	LDVERSIONre   )rM   rN   _msvccompilerr  rp   r<   r'   
hexversionr8   rR   rK   hasattrrO   environ)rB   r   r  template	pythonlibrK   link_libpython	ldversions           r   r   zbuild_ext.get_libraries  s    <<7"4dmm\:'::'$H$NNb(^^r)T1( 	 }}	{22< }}) 3"N013 45%)N\\X-%)N,

:%&9:a?)-'	2h>)-*;7	}}9(<'===}}r   )"__name__
__module____qualname__descriptionrO   rs   sep_byr   user_optionsboolean_optionsr   help_optionsrC   staticmethodrU   r   r   r   r   r   r   r   r   
contextlibcontextmanagerr   r   r   r   r   r   r   r   r    r   r   r   r   '   sF   LK( $bjj0FGQ*n-	
	
 <vE	

 	<<@<vE	

 	STAL7;GA6=K&LP HO 
$ :NKL0 5 50ILV@ DW r,!**
 F FO
b7r2361	4"*5r   r   ) __doc__r4  rO   rerM   distutils._logr   siter   	_modifiedr   corer   errorsr   r	   r
   r   r   r   r   r   rR   r   r   r   utilr   r   r   r   r   r6  r   r   <module>r?     sc     	 	 
   #   " U U  BJJUV y yr   