
    "Kb|R                         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 Z	 G d de
      Zd ZddZd	 Zd
 ZddZd Zd ZddZy)z3Handle version information related to Visual Stuio.    Nc                  t    t         j                  j                  t        j                  j                  |        S Nospathnormpathjoin)argss    1/usr/lib/python3/dist-packages/gyp/MSVSVersion.pyJoinPathr      s$    			"'',,-	..    c                 D    t        d | j                  d      D              S )Nc              3   2   K   | ]  }t        |        y wr   )int).0xs     r   	<genexpr>z#version_to_tuple.<locals>.<genexpr>   s     6!s1v6s   .)tuplesplit)version_strs    r   version_to_tupler      s    	6{0056	66r   c                   b    e Zd ZdZ	 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y)VisualStudioVersionz1Information regarding a version of Visual Studio.Nc                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
xs g }
|
j                  d d       |
| _
        y )Nc                 8    t        | j                  dd            S )Nv )floatreplace)r   s    r   <lambda>z.VisualStudioVersion.__init__.<locals>.<lambda>(   s    uQYYsB-?'@ r   T)keyreverse)
short_namedescriptionsolution_versionproject_versionflat_slnuses_vcxprojr   	sdk_baseddefault_toolsetsortcompatible_sdks)selfr$   r%   r&   r'   r(   r)   r   r*   r+   r-   s              r   __init__zVisualStudioVersion.__init__   sn     !DO"D,D*DDM$DDIDN*D%+O@$O*Dr   c                     | j                   S r   )r$   r.   s    r   	ShortNamezVisualStudioVersion.ShortName+   s    ??r   c                     | j                   S )z(Get the full description of the version.)r%   r1   s    r   DescriptionzVisualStudioVersion.Description.   s    r   c                     | j                   S )z(Get the version number of the sln files.)r&   r1   s    r   SolutionVersionz#VisualStudioVersion.SolutionVersion2   s       r   c                     | j                   S )z6Get the version number of the vcproj or vcxproj files.)r'   r1   s    r   ProjectVersionz"VisualStudioVersion.ProjectVersion6   s    r   c                     | j                   S r   )r(   r1   s    r   FlatSolutionz VisualStudioVersion.FlatSolution:   s    ==r   c                     | j                   S )z1Returns true if this version uses a vcxproj file.r)   r1   s    r   UsesVcxprojzVisualStudioVersion.UsesVcxproj=   s    r   c                 *    | j                   xr dxs dS )z+Returns the file extension for the project.z.vcxprojz.vcprojr<   r1   s    r   ProjectExtensionz$VisualStudioVersion.ProjectExtensionA   s    +8y8r   c                     | j                   S )z/Returns the path to Visual Studio installation.)r   r1   s    r   PathzVisualStudioVersion.PathE   s    99r   c                     t         j                  j                  t         j                  j                  | j                  d|            S )z+Returns the path to a given compiler tool. zVC/binr   )r.   tools     r   ToolPathzVisualStudioVersion.ToolPathI   s,    77BGGLLHdCDDr   c                     | j                   S )z\Returns the msbuild toolset version that will be used in the absence
    of a user override.)r+   r1   s    r   DefaultToolsetz"VisualStudioVersion.DefaultToolsetM   s     r   c                    |dv sJ d       t         j                  j                  dd      }t        |dd      }| j                  r(|r&t         j
                  j                  |      r|d|z   gS t         j                  j                  d      d	k(  xs" 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}|}||k7  r|d|z   z  }||gS t        | j
                  dd      }	|dk(  r@| j                  dk\  r| j                  d   dk7  r|r|	dgS t        | j
                  ddd      gS |dk(  rd}| j                  d   dk7  r|rd}|	|gS y)zLReturns a command (with arguments) to be used to set up the
    environment.)x86x64ztarget_arch not supportedWindowsSDKDirr   Binz
SetEnv.Cmd/PROCESSOR_ARCHITECTUREAMD64PROCESSOR_ARCHITEW64322017VC	AuxiliaryBuildzvcvarsall.batamd64rH   rI   _2013e	amd64_x86Common7Toolszvsvars32.bat	x86_amd64N)r   environgetr   r*   r   existsr$   )
r.   target_archsdk_dir
setup_pathis_host_arch_x64script_path	host_archmsvc_target_archarg	vcvarsalls
             r   _SetupScriptInternalz(VisualStudioVersion._SetupScriptInternalS   s    .(E*EE(
 jjnn_b1G'5,7J~~'bggnnZ&@#+,, 	jjnn-.'9 :jjnn-.'9  & TYY!;Jk .'5i$/5$8ec	&	&s%%%3 D/:Ie	F	"tr':c'A	 ;''
 IwGHH		c 
		#(8 
r   c                     | j                  |      }|d   }t        j                  j                  |      st	        d|z        |S )Nr   z3%s is missing - make sure VC++ tools are installed.)ri   r   r   r_   	Exception)r.   r`   script_datard   s       r   SetupScriptzVisualStudioVersion.SetupScript   sI    ++K8Ka.K77>>+&K!" # #r   )NN)__name__
__module____qualname____doc__r/   r2   r4   r6   r8   r:   r=   r?   rA   rD   rF   ri   rm    r   r   r   r      sO    9 GK+ ! 9E 3jr   r   c                    t         j                  dvryt        j                  j	                  t        j
                  j                  dd      | d      d|g}|r|j                  d|g       t        j                  |t        j                  t        j                        }|j                         d	   }|j                  ry|S )
a  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.
  )win32cygwinNWINDIRr   zreg.exequeryz/v)stdoutstderrr   )sysplatformr   r   r	   r]   r^   extend
subprocessPopenPIPEcommunicate
returncode)sysdirr"   valuecmdptexts         r   _RegistryQueryBaser      s     	\\,,	bjjnnXr2FI	F	#	#
JJe}s:??:??K! 
	$\\	+r   c                     d}	 t        d| |      }|S # t        $ r7}|j                  t        j                  k(  rt        d| |      }n Y d}~|S d}~ww xY w)a  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.
  N	SysnativeSystem32)r   OSErrorerrnoENOENT)r"   r   r   rX   s       r   _RegistryQueryr      sb    " 
$k36D 
+ 
 ww%,,
C7d  
+s    	A,AAc                    	 ddl }	 | j                  dd      \  }}|dk(  sJ |j	                  |j
                  |      5 }|j                  ||      d   cddd       S # t        $ r ddl}Y gw xY w# 1 sw Y   yxY w# t        $ r Y yw xY w)a  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.
  r   N\   HKLM)_winregImportErrorwinregr   OpenKeyHKEY_LOCAL_MACHINEQueryValueExWindowsError)r"   r   r   rootsubkeyhkeys         r   _RegistryGetValueUsingWinRegr      s    99T1%LD&6>>	116	: 1d  u-a01 1 
 
1 1	 s?   A 8A= A1	A= A.-A.1A:6A= :A= =	B	B	c                     	 t        | |      S # t        $ r Y nw xY wt        | |      }|syt        j                  d|      }|sy|j                  d      S )a  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.
  NzREG_\w+\s+([^\r]+)\r\nr   )r   r   r   researchgroup)r"   r   r   matchs       r   _RegistryGetValuer      s_    	'U33	 		 
U	#$	
))-t
4%		Qs    	c                    |rt         j                  j                  |      }t        dddddd||ddd	g

      t        dddddd||ddd	g

      t        dddddd||ddd	g

      t        dddddd||d	      t        dddddd||d	      t        dddddd||d	      t        dddddd||d 	      t        d!ddddd||d 	      t        d"d#d$ddd||%      t        d&d'd$ddd||%      t        d(d)d*d+dd||%      t        d,d)d*d+dd||%      t        d-d.d+d/dd||%      t        d0d.d+d/dd||%      d1}|t	        |          S )2a  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.
  2022zVisual Studio 2022z12.0017.0FTv143zv8.1zv10.0)r&   r'   r(   r)   r   r*   r+   r-   2019zVisual Studio 201916.0v141rP   zVisual Studio 201715.02015zVisual Studio 201514.0v140)r&   r'   r(   r)   r   r*   r+   rV   zVisual Studio 2013z13.0012.0v1202013e2012zVisual Studio 2012z4.0v1102012e2010zVisual Studio 2010z11.00)r&   r'   r(   r)   r   r*   2010ezVisual C++ Express 20102008zVisual Studio 2008z10.00z9.002008e2005zVisual Studio 2005z8.002005e)r   r   rP   r   rV   r   r   r   r   r   r   r   r   r   )r   r   r   r   str)namer   r*   versionss       r   _CreateVersionr     s5    
77D!D!&"63:28+0/3'+,5283972C	E "&"63:28+0/3'+,5283972C	E "&"63:28+0/3'+,5283972C	E "&"63:28+0/3'+,528: "&"63:28+0/3'+,528: #7#74;39,004(,-639; "&"63:27+0/3'+,528: #7#74;38,004(,-639; "&"63:27+0/3'+,57 #7#<4;38,004(,-68 "&"63:28+0/4'+,57 #7#74;39,005(,-68 "&"63928+0/4'+,57 #7#74:39,005(,-68i|(z 
#d)	r   c                     t         j                  dk(  rHt        j                  d| gt        j                        }|j                         d   j                         } | S )z.Convert to cygwin path if we are using cygwin.ru   cygpath)rx   r   )rz   r{   r}   r~   r   r   strip)r   r   s     r   _ConvertToCygpathr     sG    \\X)T*:??CA==?1##%D	+r   c                    ddddddddd	d
	}g }t        j                  d      }t        j                  d      }| D ]=  }d|z  d|z  d|z  d|z  g}t        t        |            D ]  }t	        ||   d      }	|	st        |	      }	t         j                  j                  |	d      }
t         j                  j                  |	d      }|s]t         j                  j                  |
      r>|j                  t        ||   t         j                  j                  |	dd                   t        j                  |      s|j                  t        ||   dz   t         j                  j                  |	dd                    g d}t        t        |            D ]  }t	        ||   |      }	|	st        |	      }	t        |      dk\  r?t         j                  j                  |	      sN|j                  t        ||   |	             m|dk7  ss|j                  t        ||   dz   t         j                  j                  |	d      d              |s|s||k(  s |j                  t        ||   |             @ |S )a  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)
      2019    - Visual Studio 2019 (16)
      2022    - Visual Studio 2022 (17)
    Where (e) is e for express editions of MSVS and blank otherwise.
  r   r   r   r   rV   r   rP   r   r   )	8.09.010.011.0r   r   r   r   r   VSINSTALLDIRr   z'HKLM\Software\Microsoft\VisualStudio\%sz3HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%sz$HKLM\Software\Microsoft\VCExpress\%sz0HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s
InstallDirz
devenv.exez*express.exez..rX   )z,HKLM\Software\Microsoft\VisualStudio\SxS\VC7z8HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7z,HKLM\Software\Microsoft\VisualStudio\SxS\VS7z8HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7)   r   r   Tr*   )r   getenvrangelenr   r   r   r	   r_   appendr   globr   )versions_to_checkforce_expressversion_to_yearr   env_vs_pathenv_vs_versionversionkeysindexr   	full_pathexpress_paths               r   _DetectVisualStudioVersionsr     sN   ( 
/ (
 		.)+9923." -3g 7@BWL3g=?'IKD s4y! -tE{L9dt$d'',,t\2iWW\\$7lrww~~i8w'?GGLLtT*, 	- 99\"w'?#'EGGLLtT*, 	--&ID s4y! 
7tE{G4dt$d	'	"g	-77>>$
//.)A4H
Ifw'?#'EGGLLt$6 	7
7 +.G*Coon_^%D%02 3Y-3^ 
/r   c                    | dk(  r t         j                  j                  dd      } dddddddddddd	d
ddd}t         j                  j                  d      }|r:t         j                  j                  d      }|st        d      t	        ||d      S t        |       } t        ||    d| v       }|s*|st        d      | dk(  rt	        dd      S t	        | d      S |d   S )zSelect 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.
  autoGYP_MSVS_VERSION)	r   r   r   r   r   r   r   r   r   )r   )r   )r   )r   )r   )r   )r   )r   )r   )r   r   r   r   r   r   r   r   r   rV   r   r   rP   r   r   GYP_MSVS_OVERRIDE_PATHz`GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be set to a particular version (e.g. 2010e).Tr   rX   z,Could not locate Visual Studio installation.r   Nr   )r   r]   r^   
ValueErrorr   r   r   )r   allow_fallbackversion_mapoverride_pathmsvs_versionr   s         r   SelectVisualStudioVersionr     s    jjnn/8G!+$ **..!9:-::>>"45L C D D,FFL'(W)=sg~N(	EFF&FD))GT**	!r   r   )F)r   T)rq   r   r   r   r}   rz   gypr   r   r   objectr   r   r   r   r   r   r   r   r   rr   r   r   <module>r      sd   
 :  	 	  
 
 /7v& vr>8.<FRVr.r   