U
    *e4                     @   s   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	 G dd dZ
G d	d
 d
e
ZG dd deZG dd deZG dd deZdS )    N   )UserException)Installable)OLDEST_SUPPORTED_MINOR)SIP_VERSION_STRc                   @   s   e Zd ZdZdd ZdS )	BuildablezS Encapsulate the components used to build something that can be
    installed.
    c                 C   s>   || _ || _g | _g | _tj|j|| _tj| jdd dS ) Initialise the buildable. Texist_okN)	projectnameZbuilder_settingsinstallablesospathjoin	build_dirmakedirs)selfr   r    r   1lib/python3.8/site-packages/sipbuild/buildable.py__init__&   s    zBuildable.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   !   s   r   c                       s6   e Zd ZdZdd fdd
Zdd Zdd	 Z  ZS )
BuildableFromSourceszT Encapsulate the sources used to build an extension module, executable
    etc.
    Fuses_limited_apic                   s   t  || |jrd}n|r2|js2td||| _|| _g | _g | _	g | _
g | _g | _g | _g | _g | _g | _d| _| jr| jdt dS )r   FzB{0} cannot use the limited API without using a shared 'sip' modulezPy_LIMITED_API=0x03{0:02x}0000N)superr   Zpy_debugZ
sip_moduler   formattargetr   Zdefine_macrossourcesheadersinclude_dirsZ	librarieslibrary_dirsZextra_compile_argsZextra_link_argsZextra_objectsdebugappendr   )r   r   r   r    r   	__class__r   r   r   7   s6    
zBuildableFromSources.__init__c                 C   s<   |  | j| _|  | j| _|  | j| _|  | j| _dS )zL Make all file and directory names relative to the build directory.
        N)_relative_namesr#   r"   r!   r$   r   r   r   r   make_names_relativeV   s    z(BuildableFromSources.make_names_relativec              	   C   st   g }|D ]f}zBt j|| jg}t j|\}}t|dkrLt j|| j}W n tk
rb   Y nX || q|S )z Return a list of times made relative to build directory.  Note that
        we only really do this for cosmetic reasons to simplify what the user
        might see.
        r   )	r   r   
commonpathr   
splitdrivelenrelpath
ValueErrorr&   )r   namesZ	rel_namesfncommon_r   r   r   r)   `   s    z$BuildableFromSources._relative_names)r   r   r   r   r   r+   r)   __classcell__r   r   r'   r   r   2   s   
r   c                   @   s   e Zd ZdZdS )BuildableExecutablez6 Encapsulate the sources used to build an executable. N)r   r   r   r   r   r   r   r   r6   {   s   r6   c                       s6   e Zd ZdZdd fdd
Zdd Zdd	 Z  ZS )
BuildableModulez< Encapsulate the sources used to build an extension module. Fr   c                   s4   t  j|||dd |d || _d| _d| _dS ) Initialise the sources. .r   FN)r   r   splitfq_name
exceptionsZstatic)r   r   r   r<   r   r'   r   r   r      s    zBuildableModule.__init__c                 C   s   t j| jddd S )z Return the sub-directory the extension module should be installed
        in relative to the eventual target directory.
        r9   Nr:   )r   sepr   r<   r;   r*   r   r   r   get_install_subdir   s    z"BuildableModule.get_install_subdirc                 C   s@   | j jdkrdS tjj}| jr8|D ]}d|kr"|  S q"|d S )z: Return the filename extension that a module should have. Zwin32z.pydz.abi3r   )r   Zpy_platform	importlib	machineryEXTENSION_SUFFIXESr   )r   suffixessr   r   r   get_module_extension   s    
z$BuildableModule.get_module_extension)r   r   r   r   r   r?   rE   r5   r   r   r'   r   r7      s   r7   c                       s6   e Zd ZdZdd fdd
Zdd Zdd	 Z  ZS )
BuildableBindingsz[ Encapsulate the sources used to build the extension module for a set of
    bindings.
    Fr   c                   s*   t  j|j|dd ||d || _dS )r8   r9   r:   r   N)r   r   r   r;   bindings)r   rG   r<   r   r'   r   r   r      s    zBuildableBindings.__init__c                 C   s"   t j| j | j}t||dS )z? Return an installable for the buildable's bindings directory. )target_subdir)r   r   r   r   Zget_bindings_dirr   r   )r   r   rH   r   r   r   get_bindings_installable   s    z*BuildableBindings.get_bindings_installablec           	   	   C   s   t j|| j}t j|dd t j|| jd }| d}|j| | j| | j	}t
|dn}| jjrrtnd}ddd	 |jD }dd
d	 |jD }|d| j |d|| jj|| W 5 Q R X dS )zW Write the configuration of the bindings and add it as an
        installable.
        Tr	   z.tomlZconfigw z, c                 S   s   g | ]}d  |qS z"{}"r   ).0tr   r   r   
<listcomp>   s     z9BuildableBindings.write_configuration.<locals>.<listcomp>c                 S   s   g | ]}d  |qS rL   rM   )rN   fr   r   r   rP      s     z1# Automatically generated configuration for {0}.
z^
sip-version = "{}"
sip-abi-version = "{}"
module-tags = [{}]
module-disabled-features = [{}]
N)r   r   r   r   r   rI   filesr&   r   rG   openr   version_infor   tagsZdisabled_featureswriter   r<   Zabi_version)	r   Zbindings_dirZconfig_pathinstallablerG   ZcfZsip_version_strrU   Zdisabledr   r   r   write_configuration   s(    
   z%BuildableBindings.write_configuration)r   r   r   r   r   rI   rX   r5   r   r   r'   r   rF      s   rF   )r@   r   r=   r   rW   r   Zpy_versionsr   versionr   r   r   r6   r7   rF   r   r   r   r   <module>   s   I%