U
    –rfx  ã                   @   sH   d Z ddlZddlZddlZdd„ Zdd„ Zdd„ Zed	krDee ƒ dS )
a§  
A script to wrap all e3sm compilations. This script should be enabled
by prefixing it to all compiler and link calls. This can be done easily in
CMake by using the RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK global properties.

This script will allow us to do whatever bookeeping, timing, logging, etc that
we want in our build system.

We want this script to be super-lean, so we do not load any of the standard CIME
stuff.
é    Nc                 C   s¢   t   ¡ }t | ¡}t   ¡ }t| ƒ}d }t| ƒD ]D\}}|dkrZ|d |k rZ| |d  } qt| d¡r.| d¡r.|}q.|d kr†d | ¡}tj	 
d ||| ¡¡ |S )Nz-oé   Úlibz.aú z Target {} built in {:f} seconds
)ÚtimeÚ
subprocessÚcallÚlenÚ	enumerateÚ
startswithÚendswithÚjoinÚsysÚstderrÚwriteÚformat)ÚargsÚt1ÚresultÚt2ZarglenÚtargetÚidxÚarg© r   úS/global/u1/q/qinyi/eagles_code/eaglesrrm/cime_config/customize/e3sm_compile_wrap.pyÚrun_cmd   s$    
ý
r   c                 C   s   | dd … S )Nr   r   )r   Ú_r   r   r   Úparse_command_line.   s    r   c                 C   s"   t tj| ƒ}t|ƒ}t |¡ d S )N)r   r   Úargvr   Úexit)ÚdescriptionZcmd_argsr   r   r   r   Ú
_main_func4   s    r    Ú__main__)Ú__doc__r   r   r   r   r   r    Ú__name__r   r   r   r   Ú<module>   s   