B
    ›³ëbâd  ã               @   s:  d Z ddlZddlZddlZddlZddlZejdkZeo^ej	d dkp^dej	ko^ej	d dkZ
ej d¡ZejdkZer„ddlZner’ddlZneržddlZddlZddlZG d	d
„ d
ejjƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ Zdd„ Zdd„ Zd!dd„Zdd„ Zdd„ Zd"dd„Zdd „ Z dS )#a  Tool-specific initialization for the Intel C/C++ compiler.

Supports Linux and Windows compilers, v7 and up.

There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
é    NZwin32ZPROCESSOR_ARCHITECTUREZAMD64ZPROCESSOR_ARCHITEW6432ZlinuxÚdarwinc               @   s   e Zd ZdS )ÚIntelCErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú0lib/python3.7/site-packages/SCons/Tool/intelc.pyr   8   s   r   c               @   s   e Zd ZdS )ÚMissingRegistryErrorN)r   r   r   r   r   r   r   r	   :   s   r	   c               @   s   e Zd ZdS )ÚMissingDirErrorN)r   r   r   r   r   r   r   r
   <   s   r
   c               @   s   e Zd ZdS )ÚNoRegistryModuleErrorN)r   r   r   r   r   r   r   r   >   s   r   c             C   sf   t  d| ¡}|r>| ¡ \}}}t|ƒd t|ƒ t|ƒd  S t| ƒ}trN|S |dk r^|d S |S dS )a#  Normalize a Linux compiler version number.
    Intel changed from "80" to "9.0" in 2005, so we assume if the number
    is greater than 60 it's an old-style number and otherwise new-style.
    Always returns an old-style float like 80 or 90 for compatibility with Windows.
    Shades of Y2K!z([0-9]+)\.([0-9]+)\.([0-9]+)g      $@g     @@é<   N)ÚreÚmatchÚgroupsÚfloatÚ
is_windows)ZvstrÚmZvmajZvminZbuildÚfr   r   r   Úlinux_ver_normalizeA   s      r   c          
   C   sŒ   | sdS |   ¡ } tr$ddddddœ}tr8ddddddœ}trJdddddœ}y||  } W n0 tk
r†   tj d	| t| 	¡ ƒf ¡‚Y nX | S )
zWCheck for valid ABI (application binary interface) name,
    and map into canonical oneNÚia32Úia64Úem64t)r   Úx86r   r   Úamd64Úx86_64)r   r   r   r   r   )r   r   r   r   z3Intel compiler: Invalid ABI %s, valid values are %s)
Úlowerr   Úis_linuxÚis_macÚKeyErrorÚSConsÚErrorsÚ	UserErrorÚlistÚkeys)ÚabiZ
valid_abisr   r   r   Ú	check_abiU   s4    r%   c             C   sN   t r| |kr| S dS n4d}x*|D ]"}t t|ƒt| ƒ ¡|k r |S q W dS dS )z`See if we can match v (string) in vlist (list of strings)
    Linux has to match in a fuzzy way.Ngü©ñÒMbP?)r   ÚmathZfabsr   )ÚvÚvlistZfuzzZvir   r   r   Úget_version_from_listt   s     
r)   c             C   sL  t rd| d | ¡  }nd| d | ¡  }ytj tjj|¡}W n¾ tjjk
r   t rvd| d | ¡  }nd| d | ¡  }yBtj tjj|¡}tj |d¡d }t rÌd| d | d	 }nd| d | d	 }tj tjj|¡}ytj || ¡d }|S  tjjk
r†   | ¡ d
kr0d}t rTd| d | d | ¡  }nd| d | d | ¡  }tj tjj|¡}Y nX ytj || ¡d }|S  tjjk
rÊ   td|||f ƒ‚Y nX W n0 tjjt	fk
rþ   td|||f ƒ‚Y nX Y nX ytj || ¡d }|S  tjjk
rF   td|| f ƒ‚Y nX dS )zN
    Return a value from the Intel compiler registry tree. (Windows only)
    z)Software\Wow6432Node\Intel\Compilers\C++\ú\zSoftware\Intel\Compilers\C++\z"Software\Wow6432Node\Intel\Suites\z\Defaults\C++\zSoftware\Intel\Suites\ZSubKeyr   z\C++ÚEM64TZem64t_nativez\C++\zI%s was not found in the registry, for Intel compiler version %s, abi='%s'z$%s\%s was not found in the registry.N)
Úis_win64Úupperr   ÚUtilÚRegOpenKeyExÚHKEY_LOCAL_MACHINEÚRegErrorÚRegQueryValueExr	   ÚOSError)Z	valuenameÚversionr$   ÚKÚkZuuidr'   r   r   r   Úget_intel_registry_value…   sL    r7   c              C   s"  g } t rŒtrd}nd}ytj tjj|¡}W nN tk
r|   trHd}nd}ytj tjj|¡}W n tk
rv   g S X Y nX d}g } yêxä|dk rltj ||¡}|dkr´|d }qŠd	}xDd
D ]<}ytd||ƒ}W n t	k
rè   w¾Y nX t
j |¡r¾d}q¾W |r|  |¡ nRytd|dƒ}W n0 t	k
rP }	 ztd| ƒ W dd}	~	X Y nX tdt|ƒ ƒ |d }qŠW W n tk
r†   Y nX nxts˜trx6t d¡D ](}t d|¡}
|
r¤|  |
 d¡¡ q¤W x6t d¡D ](}t d|¡}
|
rÜ|  |
 d¡¡ qÜW x6t d¡D ](}t d|¡}
|
r|  |
 d¡¡ qW x6t d¡D ](}t d|¡}
|
rL|  |
 d¡¡ qLW xDt d¡D ]6}t d|¡}
|
r„|  d|
 d¡|
 d¡f ¡ q„W xDt d¡D ]6}t d|¡}
|
rÊ|  d|
 d¡|
 d¡f ¡ qÊW dd„ }ttj | ¡|ddS )znReturns a sorted list of strings, like "70" or "80" or "9.0"
    with most recent compiler version first.
    z(Software\WoW6432Node\Intel\Compilers\C++zSoftware\Intel\Compilers\C++z!Software\WoW6432Node\Intel\SuiteszSoftware\Intel\Suitesr   éd   ZDefaultsé   F)ÚIA32ZIA32eZIA64r+   Ú
ProductDirTr:   z¼scons: *** Ignoring the registry key for the Intel compiler version %s.
scons: *** It seems that the compiler was uninstalled and that the registry
scons: *** was not cleaned up properly.
Nzscons: *** Ignoring z/opt/intel_cc_*zcc_(.*)$z/opt/intel/cc*/*z([0-9][0-9.]*)$z/opt/intel/Compiler/*z/opt/intel/composerxe-*z/opt/intel/composer_xe_*z(([0-9]{0,4})(?:_sp\d*)?\.([0-9][0-9.]*)$z%s.%sé   z$/opt/intel/compilers_and_libraries_*c             S   s   dd„ |   d¡D ƒS )zMGiven a dot-separated version string, return a tuple of ints representing it.c             S   s   g | ]}t |ƒ‘qS r   )Úint)Ú.0Úxr   r   r   ú
<listcomp>$  s    z>get_all_compiler_versions.<locals>.keyfunc.<locals>.<listcomp>Ú.)Úsplit)Ústrr   r   r   Úkeyfunc"  s    z*get_all_compiler_versions.<locals>.keyfunc)ÚkeyÚreverse)r   r,   r   r.   r/   r0   r3   Z
RegEnumKeyr7   r	   ÚosÚpathÚexistsÚappendÚprintrC   ÚEnvironmentErrorr   r   Úglobr   ÚsearchÚgroupÚsortedÚunique)ÚversionsZkeynamer6   ÚiZsubkeyÚokZtry_abiÚdÚvalueÚer   rD   r   r   r   Úget_all_compiler_versions½   sŽ    


 
$$rX   c                sö   t rtjjstdƒ‚td| ˆ ƒ}dddddddœˆ  }tj tj 	|dd¡¡sòtj tj 	|dˆ d¡¡sòtj tj 	|d|d¡¡sòt
d| ƒ‚nbts˜trò‡ fd	d
„}dd„ }dd„ }dd„ }|| ƒpÚ|| ƒpÚ|| ƒpÚ|| ƒ}|sòt
d| |ˆ f ƒ‚|S )zÐ
    Return the main path to the top-level dir of the Intel compiler,
    using the given version.
    The compiler will be in <top>/bin/icl.exe (icc on linux),
    the include dir is <top>/include, etc.
    z$No Windows registry module was foundr;   Úintel64r   )r   r   r   r   Úi386r   ÚBinzicl.exezCan't find Intel compiler in %sc                sL   d}ˆ dkrd}d }x2|D ]*}t j t j ||  dd¡¡r||  }P qW |S )N)z/opt/intel/cc/%sz/opt/intel_cc_%sr   )z/opt/intel/cce/%sÚbinÚicc)rG   rH   rI   Újoin)r4   ÚdirsÚtoprU   )r$   r   r   Úfind_in_2008style_dirA  s    
z5get_intel_compiler_top.<locals>.find_in_2008style_dirc          	   S   sr   d|  }t   |¡}| ¡  | ¡  d }xF|D ]>}tj tj |ddd¡¡sdtj tj |ddd¡¡r,|}P q,W |S )Nz/opt/intel/Compiler/%s/*r\   r   r]   rY   )rM   ÚsortrF   rG   rH   rI   r^   )r4   r_   r`   rU   r   r   r   Úfind_in_2010style_dirL  s    

z5get_intel_compiler_top.<locals>.find_in_2010style_dirc          	   S   sö   d }x|t   d¡D ]n}t d|¡}|rd| d¡| d¡f }|| krtj tj |ddd¡¡sxtj tj |dd	d¡¡r|}P qW |sòxjt   d
¡D ]\}t d|¡}|r’| d¡| kr’tj tj |ddd¡¡sètj tj |dd	d¡¡r’|}P q’W |S )Nz/opt/intel/composer_xe_*z(([0-9]{0,4})(?:_sp\d*)?\.([0-9][0-9.]*)$z%s.%sr9   r<   r\   r   r]   rY   z/opt/intel/composerxe-*z([0-9][0-9.]*)$)rM   r   rN   rO   rG   rH   rI   r^   )r4   r`   rU   r   Zcur_verr   r   r   Úfind_in_2011style_dirZ  s&    z5get_intel_compiler_top.<locals>.find_in_2011style_dirc          	   S   sZ   d }xPt   d|  ¡D ]>}tj tj |ddd¡¡sLtj tj |ddd¡¡r|}P qW |S )Nz+/opt/intel/compilers_and_libraries_%s/linuxr\   r   r]   rY   )rM   rG   rH   rI   r^   )r4   r`   rU   r   r   r   Úfind_in_2016style_dirs  s    4z5get_intel_compiler_top.<locals>.find_in_2016style_dirz5Can't find version %s Intel compiler in %s (abi='%s'))r   r   r.   Zcan_read_regr   r7   rG   rH   rI   r^   r
   r   r   )r4   r$   r`   Úarchdirra   rc   rd   re   r   )r$   r   Úget_intel_compiler_top(  s0    	 rg   c             C   sØ  t ststsdS tr$tjj | ¡ n&tr8tjj | ¡ nt rJtjj | ¡ tƒ }|sb|r’|d }n0t	||ƒ}|sŽtj
 d| dd |¡  ¡‚|}t|ƒ}|dkrØt sªtrÊt ¡ d }|dkrÄd}qØd}ntrÔd	}nd}|r|syt||ƒ}W n" tjjtfk
r   d}Y nX |s°G d
d„ dtjjƒ}t s<trH|  d¡rZtr†|  d¡s†tj |¡ tj |dt|ƒt|ƒf ¡ n*tj |¡ tj |dt|ƒt|ƒf ¡ |r|dddddddœ| }	tj tj |d|	¡¡rød|	 }
d|	 }nd}
d}|rTtdt|ƒt|ƒ|||
f ƒ tr<t  d||
f ¡ t rTt  d||
f ¡ || d< tržd||
|dœ}x,| !¡ D ] \}}|  "|tj ||¡¡ qzW t ràd||
|dœ}x,| !¡ D ] \}}|  "|tj ||¡¡ q¼W tr|d}|dkrød}x‚|D ]z}y&t#|d ||ƒ}| $d|tj% ¡}W n4 tk
r\   |  "|d tj ||d ¡¡ Y nX |  "|d | &tj'¡¡ qþW trœd| d < d| d!< d"| d#< n d| d < d$| d!< d%| d&< d'| d(< |rÎt|ƒ| d)< trÔtj( )d*d¡}d+}y(tj *tjj+|¡}tj ,|d,¡d }W n" t-tjjfk
r0   d}Y nX d-}d}x<||gD ]0}|rD| .d.¡d/ksltj |¡rD|}P qDW |sÈ|}tj |¡sÈG d0d1„ d1tjjƒ}tj |¡ tj |d2|||f ¡ || d3 d*< dS )4aº  Add Builders and construction variables for Intel C/C++ compiler
    to an Environment.

    Args:
      version (str): compiler version to use, like "80"
      abi (str): 'win32' or whatever Itanium version wants
      topdir (str): directory containing compiler tree, e.g.
        "c:\\Program Files\\Intel\\Compiler70".
        If `topdir` is used, `version` and `abi` are ignored.
      verbose: if >0, prints compiler version used.

    Nr   z#Invalid Intel compiler version %s: zinstalled versions are %sz, é   r   r   r   c               @   s   e Zd ZdS )z"generate.<locals>.ICLTopDirWarningN)r   r   r   r   r   r   r   ÚICLTopDirWarningÃ  s   ri   r]   Úiclz8Failed to find Intel compiler for version='%s', abi='%s'z<Can't find Intel compiler top dir for version='%s', abi='%s'rY   )r   r   r   r   rZ   r   r\   zbin/%szlib/%sÚlibz;Intel C compiler: using version %s (%g), abi %s, in '%s/%s'z%s/%s/icc --versionZINTEL_C_COMPILER_TOPZinclude)ÚINCLUDEÚLIBÚPATHZLD_LIBRARY_PATH))rl   Z
IncludeDirZInclude)rm   ZLibDirZLib)rn   ZBinDirr[   Ú r9   z$(ICInstallDir)r<   ZCCZCXXZxilinkZLINKZicpcZxiarZARZxildZLDZINTEL_C_COMPILER_VERSIONZINTEL_LICENSE_FILEzSOFTWARE\Intel\LicensesZw_cppz,C:\Program Files\Common Files\Intel\Licensesú@éÿÿÿÿc               @   s   e Zd ZdS )z&generate.<locals>.ICLLicenseDirWarningN)r   r   r   r   r   r   r   ÚICLLicenseDirWarningB  s   rr   z¶Intel license dir was not found.  Tried using the INTEL_LICENSE_FILE environment variable (%s), the registry (%s) and the default path (%s).  Using the default path as a last resort.ZENV)/r   r   r   r   ZToolZmsvcÚgenerateZgccrX   r)   r    r!   r^   r%   rG   Úunamer,   rg   r.   r1   r   ZWarningsZSConsWarningÚDetectZenableWarningClassÚwarnrC   rH   rI   rK   Úreprr   ÚsystemÚitemsZPrependENVPathr7   ÚreplaceÚseprB   ÚpathsepÚenvironÚgetr/   r0   r2   ÚAttributeErrorÚfind)Úenvr4   r$   ZtopdirÚverboser(   r'   Zuname_mri   rf   ZbindirZlibdirÚpathsÚprH   Z	envlicdirr5   r6   Z	reglicdirZdefaultlicdirZlicdirZldrr   r   r   r   rs   ƒ  sü    





$

$rs   c          	   C   s‚   t ststsdS y
tƒ }W n  tjjtfk
r:   d }Y nX |d k	oNt|ƒdk}|s~trb|  	d¡S trp|  	d¡S t r~|  	d¡S |S )Nr   rj   r]   )
r   r   r   rX   r   r.   r1   r   Úlenru   )r   rR   Zdetectedr   r   r   rI   O  s    




rI   )NN)NNNr   )!Ú__doc__rM   r&   Úos.pathrG   r   ÚsysÚplatformr   r}   r,   Ú
startswithr   r   ZSCons.Tool.msvcr   ZSCons.Tool.gccZ
SCons.UtilZSCons.Warningsr    ZInternalErrorr   r	   r
   r   r   r%   r)   r7   rX   rg   rs   rI   r   r   r   r   Ú<module>   s@   





8k[
 M