o
    5‘ði5  ã                   @  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 )z´distutils.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   úg/root/parts/websockify/install/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d�| _t| jƒ | jd ur| j | j¡ | jd ur3| jD ]\}}| j ||¡ q'| j	d urD| j	D ]}| j 
|¡ q;|  | j ¡ d S )N)r   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   Úlibr2   Ú
build_infor   r   r    r'   j   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(   r7   r8   r
   Úextend)r   Ú	filenamesr@   r=   rC   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 )	NrC   rD   rE   zbuilding '%s' libraryÚmacrosr   )Ú
output_dirrJ   r   r   )rK   r   )rF   r(   r7   r8   r
   r   Úinfor   Úcompiler   r   Úcreate_static_libr   )r   r   r@   r=   rC   rJ   r   Úobjectsr   r   r    r1   ¨   s*   

ÿ

ûÿäzbuild_clib.build_libraries)r"   r#   )Ú__name__Ú
__module__Ú__qualname__Údescriptionr   Ú__annotations__r   r   r   r!   r-   r5   r'   rB   rI   r1   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    