B
    ›³ëb  ã               @   sV   d Z dZddlZddlZddlZddlZddlZdd„ Ze 	d¡Z
dd„ Zd	d
„ ZdS )z—SCons.Tool.PharLapCommon

This module contains common code used by all Tools for the
Phar Lap ETS tool chain.  Right now, this is linkloc and
386asm.

z,__FILE__ __REVISION__ __DATE__ __DEVELOPER__é    Nc              C   sŒ   t jjst j d¡‚yNt j t jjd¡} t j | d¡\}}| d¡}|dkrX|d|… }t	j
 |¡S  t jjk
r†   t j d¡‚Y nX dS )z¢Reads the registry to find the installed path of the Phar Lap ETS
    development kit.

    Raises UserError if no installed version of Phar Lap can
    be found.z$No Windows registry module was foundzSOFTWARE\Pharlap\ETSZBaseDirú r   NzICannot find Phar Lap ETS path in the registry.  Is it installed properly?)ÚSConsÚUtilZcan_read_regÚErrorsZInternalErrorZRegOpenKeyExÚHKEY_LOCAL_MACHINEZRegQueryValueExÚfindÚosÚpathÚnormpathZRegErrorÚ	UserError)ÚkÚvalÚtypeÚidx© r   ú7lib/python3.7/site-packages/SCons/Tool/PharLapCommon.pyÚgetPharLapPath(   s    
r   z#define\s+ETS_VER\s+([0-9]+)c           	   C   sj   t j tƒ t j d¡¡} t j | ¡s0tj d¡‚t	| dƒ}t
 | ¡ ¡}W dQ R X |rft| d¡ƒS dS )aº  Returns the version of the installed ETS Tool Suite as a
    decimal number.  This version comes from the ETS_VER #define in
    the embkern.h header.  For example, '#define ETS_VER 1010' (which
    is what Phar Lap 10.1 defines) would cause this method to return
    1010. Phar Lap 9.1 does not have such a #define, but this method
    will return 910 as a default.

    Raises UserError if no installed version of Phar Lap can
    be found.zinclude/embkern.hzSCannot find embkern.h in ETS include directory.
Is Phar Lap ETS installed properly?ÚrNé   iŽ  )r   r	   Újoinr   r
   Úexistsr   r   r   ÚopenÚREGEX_ETS_VERÚsearchÚreadÚintÚgroup)Zinclude_pathÚfZmor   r   r   ÚgetPharLapVersionD   s    r   c          
   C   sÀ   t ƒ }y| d }W n  tk
r2   i }|| d< Y nX tj |dtj |d¡¡ tj |dtj |d¡¡ tj |dtj |d¡¡ tj |dtj |tj d¡¡¡ t ƒ | d	< t	t
ƒ ƒ| d
< dS )zqThis function adds the path to the Phar Lap binaries, includes,
    and libraries, if they are not already there.ZENVÚPATHÚbinZINCLUDEZincludeZLIBÚlibz	lib/vclibZPHARLAP_PATHZPHARLAP_VERSIONN)r   ÚKeyErrorr   r   ZAddPathIfNotExistsr   r	   r   r
   Ústrr   )ÚenvZph_pathZenv_dictr   r   r   ÚaddPharLapPathsY   s     




r%   )Ú__doc__Z__revision__r   Úos.pathZSCons.Errorsr   Z
SCons.UtilÚrer   Úcompiler   r   r%   r   r   r   r   Ú<module>   s   
