B
    ²>[™  ã               @   sZ   d dl Zd dlmZmZ d dlZd dlZd dlmZ ej	j
j
Zdd„ ZG dd„ deƒZ
dS )é    N)ÚnewerÚnewer_group)Úsha1c             C   s   t j | ¡d | S )Nr   )ÚosÚpathÚsplitext)r   Z
new_suffix© r   ú+lib/python3.7/site-packages/sipdistutils.pyÚreplace_suffix   s    r
   c               @   s˜   e Zd ZdZejdd… Zdd„ eD ƒZedg7 Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )Ú	build_extzWCompile SIP descriptions, then build C/C++ extensions (compile/link to build directory)Nc             C   s   g | ]}|d    d¡s|‘qS )r   Zswig)Ú
startswith)Ú.0Zoptr   r   r	   ú
<listcomp>$   s    zbuild_ext.<listcomp>)z	sip-opts=Nz list of sip command line optionsc             C   s   t  | ¡ d | _d S )N)Úbuild_ext_baseÚinitialize_optionsÚsip_opts)Úselfr   r   r	   r   *   s    
zbuild_ext.initialize_optionsc             C   s.   t  | ¡ | jd krg | _n| j d¡| _d S )Nú )r   Úfinalize_optionsr   Úsplit)r   r   r   r	   r   .   s    

zbuild_ext.finalize_optionsc             C   st   xbt |ƒ ¡ D ]R}| dd¡\}}| ¡ dkrg }x(| ¡ D ]}| tj |  ¡ |¡¡ q<W |S qW t	d| ƒ‚dS )z¨
        Parse the sbf file specified to extract the name of the generated source
        files. Make them absolute assuming they reside in the temp directory.
        ú=é   Úsourceszcannot parse SIP-generated '%s'N)
ÚopenÚ	readlinesr   ÚstripÚappendr   r   ÚjoinÚ_sip_output_dirÚRuntimeError)r   ÚsbfÚLÚkeyÚvalueÚoutÚor   r   r	   Ú_get_sip_output_list5   s    zbuild_ext._get_sip_output_listc             C   sD   dd l }| ¡ }tjdkr>tj tj |j¡¡d s>|jd S |jS )Nr   Úntr   z.exe)Ú	sipconfigÚConfigurationr   Únamer   r   ÚbasenameÚsip_bin)r   r(   Úcfgr   r   r	   Ú	_find_sipD   s    

zbuild_ext._find_sipc             C   s   dd l }| ¡ }|jS )Nr   )r(   r)   Zsip_inc_dir)r   r(   r-   r   r   r	   Ú_sip_inc_dirL   s    zbuild_ext._sip_inc_dirc             C   s   dd l }| ¡ }|jS )Nr   )r(   r)   Zdefault_sip_dir)r   r(   r-   r   r   r	   Ú_sip_sipfiles_dirQ   s    zbuild_ext._sip_sipfiles_dirc             C   s   |   ¡ }tt|dƒ ¡ ƒ ¡ S )NÚrb)r.   r   r   ÚreadZ	hexdigest)r   r,   r   r   r	   Ú_sip_calc_signatureV   s    zbuild_ext._sip_calc_signaturec             C   s   t j |  ¡ d¡S )Nzsip.signature)r   r   r   r   )r   r   r   r	   Ú_sip_signature_fileZ   s    zbuild_ext._sip_signature_filec             C   s   | j S )N)Z
build_temp)r   r   r   r	   r   ]   s    zbuild_ext._sip_output_dirc             C   st   | j }| j s^dd„ |jD ƒ}|r^|  ¡ }tj |¡s<d| _ n"t|ƒ ¡ }|  ¡ }||kr^d| _ t	 
| |¡ || _ d S )Nc             S   s   g | ]}|  d ¡r|‘qS )z.sip)Úendswith)r   Úsourcer   r   r	   r   d   s    z-build_ext.build_extension.<locals>.<listcomp>T)Úforcer   r4   r   r   Úisfiler   r2   r3   r   Úbuild_extension)r   ZextZoldforceÚsip_sourcesZsigfileZold_sigZnew_sigr   r   r	   r9   `   s    zbuild_ext.build_extensionc             C   s>  | j s
d S |d k	rFt| jƒdkr.| j |j¡ |j |  ¡ ¡ |j}n| j |  ¡ ¡ g }dd„ |D ƒ}t	j
 |  ¡ ¡s†t	 |  ¡ ¡ g }dd„ |D ƒ}dd„ |D ƒ}g }|  ¡ }x‚|D ]z}t	j
 |¡}	t	j
 |  ¡ t|	dƒ¡}
t|g| |
ƒsø| jr|  |||
¡ t|  ¡ dƒ |  ¡ ¡ |  |
¡}| |¡ q¸W || S )Nr   c             S   s$   g | ]}t j |¡d  dkr|‘qS )r   z.sip)r   r   r   )r   Úfr   r   r	   r   ˆ   s    z*build_ext.swig_sources.<locals>.<listcomp>c             S   s   g | ]}|  d ¡r|‘qS )z.sip)r5   )r   r6   r   r   r	   r      s    c             S   s   g | ]}|  d ¡s|‘qS )z.sip)r5   )r   r6   r   r   r	   r   ‘   s    z.sbfÚw)Ú
extensionsÚlenr   ÚextendZ	swig_optsZinclude_dirsr   r/   Údependsr   r   Úisdirr   Úmakedirsr.   r+   r   r
   r   r7   Ú_sip_compiler   r4   Úwriter3   r&   )r   r   Ú	extensionr@   r:   Zother_sourcesZgenerated_sourcesr,   ZsipZsipbasenamer    r$   r   r   r	   Úswig_sourcess   s4    

zbuild_ext.swig_sourcesc          
   C   s0   |   |g| j d|  ¡ d|d|  ¡ |g ¡ d S )Nz-cz-bz-I)Zspawnr   r   r0   )r   r,   r6   r    r   r   r	   rC   ¢   s
    zbuild_ext._sip_compile)N)Ú__name__Ú
__module__Ú__qualname__Zdescriptionr   Zuser_optionsr   r   r&   r.   r/   r0   r3   r4   r   r9   rF   rC   r   r   r   r	   r      s"   
/r   )Zdistutils.command.build_extZ	distutilsZdistutils.dep_utilr   r   r   ÚsysZhashlibr   Zcommandr   r   r
   r   r   r   r	   Ú<module>   s   
