
nZc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d   Z d e	 f d     YZ
 d   Z d d  Z d   Z d	   Z e d
  Z d   Z d   Z d e d  Z d S(   s3   Handle version information related to Visual Stuio.iNc          G   s   t  j j t  j j |     S(   N(   t   ost   patht   normpatht   join(   t   args(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   JoinPath   s    t   VisualStudioVersionc           B   s   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   s1   Information regarding a version of Visual Studio.c         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 pZ g  }
 |
 j	 d d   d t
  |
 |  _ d  S(   Nt   keyc         S   s   t  |  j d d   S(   Nt   vt    (   t   floatt   replace(   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   <lambda>$   R	   t   reverse(   t
   short_namet   descriptiont   solution_versiont   project_versiont   flat_slnt   uses_vcxprojR   t	   sdk_basedt   default_toolsett   sortt   Truet   compatible_sdks(   t   selfR   R   R   R   R   R   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   __init__   s    									c         C   s   |  j  S(   N(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt	   ShortName'   s    c         C   s   |  j  S(   s(   Get the full description of the version.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   Description*   s    c         C   s   |  j  S(   s(   Get the version number of the sln files.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   SolutionVersion.   s    c         C   s   |  j  S(   s6   Get the version number of the vcproj or vcxproj files.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   ProjectVersion2   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   FlatSolution6   s    c         C   s   |  j  S(   s1   Returns true if this version uses a vcxproj file.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   UsesVcxproj9   s    c         C   s   |  j  r d p d S(   s+   Returns the file extension for the project.s   .vcxprojs   .vcproj(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   ProjectExtension=   s    c         C   s   |  j  S(   s/   Returns the path to Visual Studio installation.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   PathA   s    c         C   s%   t  j j t  j j |  j d |   S(   s+   Returns the path to a given compiler tool. s   VC/bin(   R    R   R   R   (   R   t   tool(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   ToolPathE   s    c         C   s   |  j  S(   s\   Returns the msbuild toolset version that will be used in the absence
    of a user override.(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   DefaultToolsetI   s    c   
      C   s  | d k s t  d   t j j d d  } t | d d  } |  j rn | rn t j j |  rn | d | g St j j d	  d
 k p t j j d  d
 k } |  j d k rt |  j d d d d  } | r d n d } | d k r d n d } | } | | k r| d | 7} n  | | g St |  j d d  }	 | d k r|  j d k rr|  j d d k rr| rr|	 d g St |  j d d d  g Sn> | d k rd } |  j d d k r| rd } n  |	 | g Sd S(   sL   Returns a command (with arguments) to be used to set up the
    environment.t   x86t   x64s   target_arch not supportedt   WindowsSDKDirR	   t   Bins
   SetEnv.Cmdt   /t   PROCESSOR_ARCHITECTUREt   AMD64t   PROCESSOR_ARCHITEW6432t   2017t   VCt	   Auxiliaryt   Builds   vcvarsall.batt   amd64t   _t   2013it   et	   amd64_x86t   Common7t   Toolss   vsvars32.batt	   x86_amd64N(   R&   R'   (	   t   AssertionErrorR    t   environt   getR   R   R   t   existsR   (
   R   t   target_archt   sdk_dirt
   setup_patht   is_host_arch_x64t   script_patht	   host_archt   msvc_target_archt   argt	   vcvarsall(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _SetupScriptInternalO   s6    !	
"
	c         C   sB   |  j  |  } | d } t j j |  s> t d |   n  | S(   Ni    s3   %s is missing - make sure VC++ tools are installed.(   RG   R    R   R=   t	   Exception(   R   R>   t   script_dataRB   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   SetupScript   s    
N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R   R   R   R   R    R!   R"   R$   R%   RG   RJ   (    (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyR      s   											5c         C   s   t  j d k r d St j j t j j d d  |  d  d | g } | r_ | j d | g  n  t	 j
 | d t	 j d	 t	 j } | j   d
 } | j r d S| S(   s  Use reg.exe to read a particular key.

  While ideally we might use the win32 module, we would like gyp to be
  python neutral, so for instance cygwin python lacks this module.

  Arguments:
    sysdir: The system subdirectory to attempt to launch reg.exe from.
    key: The registry key to read from.
    value: The particular value to read.
  Return:
    stdout from reg.exe, or None for failure.
  t   win32t   cygwint   WINDIRR	   s   reg.exet   querys   /vt   stdoutt   stderri    (   RO   RP   N(   t   syst   platformRN   R    R   R   R;   R<   t   extendt
   subprocesst   Popent   PIPEt   communicatet
   returncode(   t   sysdirR   t   valuet   cmdt   pt   text(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _RegistryQueryBase   s    $!	c         C   s`   d } y t d |  |  } Wn= t k
 r[ } | j t j k rU t d |  |  } q\   n X| S(   s  Use reg.exe to read a particular key through _RegistryQueryBase.

  First tries to launch from %WinDir%\Sysnative to avoid WoW64 redirection. If
  that fails, it falls back to System32.  Sysnative is available on Vista and
  up and available on Windows Server 2003 and XP through KB patch 942589. Note
  that Sysnative will always fail if using 64-bit python due to it being a
  virtual directory and System32 will work correctly in the first place.

  KB 942589 - http://support.microsoft.com/kb/942589/en-us.

  Arguments:
    key: The registry key.
    value: The particular registry value to read (optional).
  Return:
    stdout from reg.exe, or None for failure.
  t	   Sysnativet   System32N(   RN   Rb   t   OSErrort   errnot   ENOENT(   R   R^   Ra   R5   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _RegistryQuery   s    c         C   s   d d l  } y` |  j d d  \ } } | d k s9 t  | j | j |   } | j | |  d SWd QXWn t k
 r d SXd S(   s  Use the _winreg module to obtain the value of a registry key.

  Args:
    key: The registry key.
    value: The particular registry value to read.
  Return:
    contents of the registry key's value, or None on failure.  Throws
    ImportError if _winreg is unavailable.
  iNs   \i   t   HKLMi    (   t   _winregt   splitR:   t   OpenKeyt   HKEY_LOCAL_MACHINEt   QueryValueExt   WindowsErrorRN   (   R   R^   Rj   t   roott   subkeyt   hkey(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _RegistryGetValueUsingWinReg   s    
c         C   sg   y t  |  |  SWn t k
 r$ n Xt |  |  } | s> d St j d |  } | sZ d S| j d  S(   s  Use _winreg or reg.exe to obtain the value of a registry key.

  Using _winreg is preferable because it solves an issue on some corporate
  environments where access to reg.exe is locked down. However, we still need
  to fallback to reg.exe for the case where the _winreg module is not available
  (for example in cygwin python).

  Args:
    key: The registry key.
    value: The particular registry value to read.
  Return:
    contents of the registry key's value, or None on failure.
  s   REG_\w+\s+([^\r]+)\r\ni   N(   Rs   t   ImportErrorRh   RN   t   ret   searcht   group(   R   R^   Ra   t   match(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _RegistryGetValue   s    c         C   s  | r t  j j |  } n  i t d d d d d d d t d t d	 | d
 | d d d d d g d 6t d d d d d d d t d t d	 | d
 | d d d 6t d d d d d d d t d t d	 | d
 | d d d 6t d d d d d d d t d t d	 | d
 | d d d 6t d d d d d d d t d t d	 | d
 | d d d 6t d d d d d d d t d t d	 | d
 | d d d 6t d d  d d! d d d t d t d	 | d
 | d 6t d" d# d d! d d d t d t d	 | d
 | d" 6t d$ d% d d& d d' d t d t d	 | d
 | d$ 6t d( d% d d& d d' d t d t d	 | d
 | d( 6t d) d* d d' d d+ d t d t d	 | d
 | d) 6t d, d* d d' d d+ d t d t d	 | d
 | d, 6} | t |   S(-   s  Sets up MSVS project generation.

  Setup is based off the GYP_MSVS_VERSION environment variable or whatever is
  autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is
  passed in that doesn't match a value in versions python will throw a error.
  R.   s   Visual Studio 2017R   s   12.00R   s   15.0R   R   R   R   R   t   v141R   s   v8.1s   v10.0t   2015s   Visual Studio 2015s   14.0t   v140R4   s   Visual Studio 2013s   13.00s   12.0t   v120t   2013et   2012s   Visual Studio 2012s   4.0t   v110t   2012et   2010s   Visual Studio 2010s   11.00t   2010es   Visual C++ Express 2010t   2008s   Visual Studio 2008s   10.00s   9.00t   2008et   2005s   Visual Studio 2005s   8.00t   2005e(   R    R   R   R   t   FalseR   t   str(   t   nameR   R   t   versions(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _CreateVersion   s    









c         C   sJ   t  j d k rF t j d |  g d t j } | j   d j   }  n  |  S(   s.   Convert to cygwin path if we are using cygwin.RP   t   cygpathRS   i    (   RU   RV   RX   RY   RZ   R[   t   strip(   R   R`   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _ConvertToCygpatho  s    c   
   	   C   sF  i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6} g  } x|  D]} d | d | d | d | g } x t  t |   D] } t | | d  } | s q n  t |  } t j j | d  } t j j | d  }	 | r"t j j |  r"| j t	 | | t j j | d d    q t
 j
 |	  r | j t	 | | d t j j | d d    q q Wd d d d g } x t  t |   D] } t | | |  } | sqn  t |  } | d k rt j j |  r:| j t	 d |   q:q| d k r| j t	 | | d t j j | d  d t  qqWqD W| S(   sX  Collect the list of installed visual studio versions.

  Returns:
    A list of visual studio versions installed in descending order of
    usage preference.
    Base this on the registry and a quick check if devenv.exe exists.
    Possibilities are:
      2005(e) - Visual Studio 2005 (8)
      2008(e) - Visual Studio 2008 (9)
      2010(e) - Visual Studio 2010 (10)
      2012(e) - Visual Studio 2012 (11)
      2013(e) - Visual Studio 2013 (12)
      2015    - Visual Studio 2015 (14)
      2017    - Visual Studio 2017 (15)
    Where (e) is e for express editions of MSVS and blank otherwise.
  R   s   8.0R   s   9.0R   s   10.0R   s   11.0R4   s   12.0R{   s   14.0R.   s   15.0s'   HKLM\Software\Microsoft\VisualStudio\%ss3   HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%ss$   HKLM\Software\Microsoft\VCExpress\%ss0   HKLM\Software\Wow6432Node\Microsoft\VCExpress\%st
   InstallDirs
   devenv.exes   *express.exes   ..R5   s,   HKLM\Software\Microsoft\VisualStudio\SxS\VC7s8   HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7s,   HKLM\Software\Microsoft\VisualStudio\SxS\VS7s8   HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7R   (   t   ranget   lenRy   R   R    R   R   R=   t   appendR   t   globR   (
   t   versions_to_checkt   force_expresst   version_to_yearR   t   versiont   keyst   indexR   t	   full_patht   express_path(    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   _DetectVisualStudioVersionsw  sV    
#	*t   autoc         C   sH  |  d k r$ t  j j d d  }  n  i d d 6d d
 6d d 6d d 6d  d 6d! d 6d" d 6d# d 6d$ d 6d% d 6d& d 6d' d 6d( d 6} t  j j d  } | r t  j j d  } | s t d   n  t | | d t St |   }  t | |  d |  k  } | s@| st d   n  |  d k r0t d
 d)  St |  d)  Sn  | d S(*   s   Select which version of Visual Studio projects to generate.

  Arguments:
    version: Hook to allow caller to force a particular version (vs auto).
  Returns:
    An object representing a visual studio project format version.
  R   t   GYP_MSVS_VERSIONs   15.0s   14.0s   12.0s   10.0s   9.0s   8.0s   11.0R   R   R   R   R   R   R   R   R4   R~   R{   R.   t   GYP_MSVS_OVERRIDE_PATHs`   GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be set to a particular version (e.g. 2010e).R   R5   s,   Could not locate Visual Studio installation.i    (   s   15.0s   14.0s   12.0s   10.0s   9.0s   8.0s   11.0(   s   8.0(   s   8.0(   s   9.0(   s   9.0(   s   10.0(   s   10.0(   s   11.0(   s   11.0(   s   12.0(   s   12.0(   s   14.0(   s   15.0N(	   R    R;   R<   t
   ValueErrorR   R   R   R   RN   (   R   t   allow_fallbackt   version_mapt   override_patht   msvs_versionR   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   SelectVisualStudioVersion  s>    	
(   RM   Rf   R    Ru   RX   RU   t   gypR   R   t   objectR   Rb   RN   Rh   Rs   Ry   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/gyp/MSVSVersion.pyt   <module>   s"   	y			u		I