o
    LK&ha                     @  s   d Z ddlm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mZ dd	lmZ dd
lmZ ddlmZ G dd deZdS )zdistutils.command.build_clib

Implements the Distutils 'build_clib' command, to build a C/C++ library
that is included in the module distribution and needed by an extension
module.    )annotationsN)Callable)log)ClassVar   )new_compilershow_compilers)Command)DistutilsSetupError)customize_compilerc                   @  s   e Zd ZU dZg dZded< ddgZded< d	d
defgZded< dd Z	dddZ
dddZdddZdd Zdd ZdddZd
S )
build_clibz/build C/C++ libraries used by Python extensions))zbuild-clib=bz%directory to build C/C++ libraries to)zbuild-temp=tz,directory to put temporary build by-products)debuggz"compile with debugging information)forcefz2forcibly build everything (ignore file timestamps))z	compiler=czspecify the compiler typez$ClassVar[list[tuple[str, str, str]]]user_optionsr   r   zClassVar[list[str]]boolean_optionszhelp-compilerNzlist available compilerszAClassVar[list[tuple[str, str | None, str, Callable[[], object]]]]help_optionsc                 C  s:   d | _ d | _d | _d | _d | _d | _d | _d| _d | _d S )NF)	r   
build_temp	librariesinclude_dirsdefineundefr   r   compilerself r   [/var/www/html/venv/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.pyinitialize_options-   s   
zbuild_clib.initialize_optionsreturnNonec                 C  sl   |  dddddd | jj| _| jr| | j | jd u r$| jjp"g | _t| jtr4| jtj	| _d S d S )Nbuild)r   r   )r   r   )r   r   )r   r   )r   r   )
set_undefined_optionsdistributionr   check_library_listr   
isinstancestrsplitospathsepr   r   r   r    finalize_options<   s    
	
zbuild_clib.finalize_optionsc                 C  s   | j sd S t| j| j| jd| _t| j | jd ur!| j| j | jd ur5| jD ]\}}| j	|| q)| j
d urF| j
D ]}| j| q=| | j  d S )N)r   dry_runr   )r   r   r   r.   r   r   r   set_include_dirsr   define_macror   undefine_macrobuild_libraries)r   namevaluemacror   r   r    runW   s   




zbuild_clib.runc                 C  s   t |ts	td|D ]?}t |tst|dkrtd|\}}t |ts)tdd|v s7tjdkrAtj|v rAtd|d  dt |tsJtd	qd
S )a`  Ensure that the list of libraries is valid.

        `library` is presumably provided as a command option 'libraries'.
        This method checks that it is a list of 2-tuples, where the tuples
        are (library_name, build_info_dict).

        Raise DistutilsSetupError if the structure is invalid anywhere;
        just returns otherwise.
        z+'libraries' option must be a list of tuplesr   z*each element of 'libraries' must a 2-tuplezNfirst element of each tuple in 'libraries' must be a string (the library name)/zbad library name 'r   z'': may not contain directory separatorszMsecond element of each tuple in 'libraries' must be a dictionary (build info)N)	r(   listr
   tuplelenr)   r+   sepdict)r   r   libr3   
build_infor   r   r    r'   l   s(   



zbuild_clib.check_library_listc                 C  s,   | j sd S g }| j D ]	\}}|| q
|S )N)r   append)r   	lib_nameslib_name_build_infor   r   r    get_library_names   s   zbuild_clib.get_library_namesc                 C  s^   |  | j g }| jD ]!\}}|d}|d u st|ttfs'td| d|| q|S )Nsources in 'libraries' option (library 'D'), 'sources' must be present and must be a list of source filenames)r'   r   getr(   r8   r9   r
   extend)r   	filenamesrA   r>   rD   r   r   r    get_source_files   s   

zbuild_clib.get_source_filesc                 C  s   |D ]I\}}| d}|d u st|ttfstd| dt|}td| | d}| d}| jj|| j	||| j
d}| jj||| j| j
d qd S )	NrD   rE   rF   zbuilding '%s' librarymacrosr   )
output_dirrK   r   r   )rL   r   )rG   r(   r8   r9   r
   r   infor   compiler   r   create_static_libr   )r   r   rA   r>   rD   rK   r   objectsr   r   r    r2      s*   



zbuild_clib.build_libraries)r"   r#   )__name__
__module____qualname__descriptionr   __annotations__r   r   r   r!   r-   r6   r'   rC   rJ   r2   r   r   r   r    r      s   
 



$r   )__doc__
__future__r   r+   collections.abcr   distutils._logr   typingr   	ccompilerr   r   corer	   errorsr
   	sysconfigr   r   r   r   r   r    <module>   s    