o
    p.a                    @   s  d dl m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 dl	Z	d dl
Zd dlmZ d dlm  mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl
m Z  d dl
m!Z! e"dZ#i dddd	d
ddddddddddddddddddddddddd d!d"d#d$d%d&d'Z$d(d)gZ%g d*Z&da'd+d,gZ(da)da*d-d. Z+da,d/d0 Z-d1d2 Z.d3d4 Z/		dd6d7Z0dd9d:Z1dd;d<Z2d=d> Z3d?d@ Z4dAdB Z5dCdD Z6dEdF Z7dGdH Z8dIdJ Z9dKdL Z:dMdN Z;dOdP Z<dQdR Z=dSdT Z>dUdV Z?dWdX Z@dYdZ ZAd[d\ ZBd]d^ ZCe"d_ZDd`da ZEe"dbZFdcdd ZGdedf ZHe"dgZIdhdi ZJdjdk ZKdldm ZLdndo ZMdpdq ZNdrds ZOdtdu ZPdvdw ZQdxdy ZRdzd{ ZSd|d} ZTd~d ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd Zkdd Zldd Zmdd Zndd Zodd Zpdd Zqdd Zrdd Zsdd Ztdd Zudd ZvddÄ Zwddń ZxddǄ ZyddɄ Zzdd˄ Z{dd̈́ Z|ddτ Z}ddф Z~ddӄ ZddՄ Zddׄ ZG ddل deZddۄ Zdd݄ Zdd߄ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Ze"dZdd Zdd Zdd  Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zdd ZdS (      )print_functionN)GypError)
OrderedSetz^[A-F0-9\-]+$DRIVER_PREFIX DRIVER_SUFFIX.sysEXECUTABLE_PREFIXEXECUTABLE_SUFFIX.exeSTATIC_LIB_PREFIXSHARED_LIB_PREFIXSTATIC_LIB_SUFFIX.libSHARED_LIB_SUFFIX.dllINTERMEDIATE_DIR	$(IntDir)SHARED_INTERMEDIATE_DIRz $(OutDir)obj/global_intermediateOSwinPRODUCT_DIR	$(OutDir)LIB_DIRz$(OutDir)libRULE_INPUT_ROOT$(InputName)RULE_INPUT_DIRNAME$(InputDir)RULE_INPUT_EXT$(InputExt)RULE_INPUT_NAME$(InputFileName)$(InputPath)z$(ConfigurationName))RULE_INPUT_PATHCONFIGURATION_NAMEmsvs_cygwin_dirs
msvs_props)r%   msvs_cygwin_shellmsvs_large_pdb
msvs_shardmsvs_external_buildermsvs_external_builder_out_dirmsvs_external_builder_build_cmdmsvs_external_builder_clean_cmd#msvs_external_builder_clcompile_cmdmsvs_enable_winrtmsvs_requires_importlibrarymsvs_enable_winphonemsvs_application_type_revisionmsvs_target_platform_versionmsvs_target_platform_minversionmsvs_precompiled_headermsvs_precompiled_sourcec                  C   s   t jdvrdS trtsUtjd} tjd}| r|sQtjg dtj	d}|
 d }tdtj}||}|r>|d	}td
tj}||}|rQ|d	} | a|attfS )N)win32cygwin)DOMAINUSERNAME
USERDOMAINr:   )netconfigWorkstation)stdoutr   z^User name\s+(\S+)   z^Logon domain\s+(\S+))sysplatformcached_domaincached_usernameosenvironget
subprocessPopenPIPEcommunicaterecompile	MULTILINEsearchgroup)domainusernamecallr=   username_reusername_match	domain_redomain_match rX   4/usr/lib/python3/dist-packages/gyp/generator/msvs.py_GetDomainAndUserNamel   s*   





rZ   c                 C   s(   t j| }| d|dkr|} | S )zNormalize the path.

  But not if that gets rid of a variable, as this may expand to something
  larger than one directory.

  Arguments:
      source: The path to be normalize.d

  Returns:
      The normalized path.
  $)rE   pathnormpathcount)source
normalizedrX   rX   rY   _NormalizedSource   s   ra   c                 C   sb   t r| rtj| s| d dkstjt | } | dd} t| } | r/| d dkr/| dd } | S )zConvert paths to a form that will make sense in a vcproj file.

  Arguments:
    path: The path to convert, may contain / etc.
  Returns:
    The path with all slashes made into backslashes.
  r   r[   /\N)fixpath_prefixrE   r\   isabsjoinreplacera   r\   rX   rX   rY   _FixPath   s    rj   c                 C   s   dd | D S )z"Fix each of the paths of the list.c                 S      g | ]}t |qS rX   rj   .0irX   rX   rY   
<listcomp>       z_FixPaths.<locals>.<listcomp>rX   )pathsrX   rX   rY   	_FixPaths   s   rs   Tc                 C   sV  |sg }g }g }t  }| D ]c}t|dkr/td|| }	|	|v r)||	 q||	 q|rP| sP||d sBg ||d < ||d  |dd  qt|dd g||d g |||d}
t	j
|d |
d}
||
 q|r|rt	j
d|d}|| |r| r|S |D ]}t|| ||g |||d}
t	j
||
d}
||
 q|S )	a  Converts a list split source file paths into a vcproj folder hierarchy.

  Arguments:
    sources: A list of source file paths split.
    prefix: A list of source file path layers meant to apply to each of sources.
    excluded: A set of excluded files.
    msvs_version: A MSVSVersion object.

  Returns:
    A hierarchy of filenames and MSVSProject.Filter objects that matches the
    layout of the source tree.
    For example:
    _ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']],
                                     prefix=['joe'])
    -->
    [MSVSProject.Filter('a', contents=['joe\a\bob1.c']),
     MSVSProject.Filter('b', contents=['joe\b\bob2.c'])]
  r@   rc   r   Nexcludedlist_excludedmsvs_versioncontents_excluded_files)prefixru   rv   rw   )collectionsOrderedDictlenra   rg   appendUsesVcxprojrG    _ConvertSourcesToFilterHierarchyMSVSProjectFilter)sourcesr{   ru   rv   rw   resultexcluded_resultfolderssfilenamery   excluded_folderfrX   rX   rY   r      sJ   
r   Fc                 C   s   |sd S t | |||| d S N)_ToolSetOrAppend)tools	tool_namesettingvalueonly_if_unsetrX   rX   rY   _ToolAppend   s   r   c                 C   s   d|v sd|v rt |tkr|dd}ndd |D }| |s&t | |< | | }d|kr0d S ||r_|r9d S t || tkrQt |tkrQ||  |7  < d S td|||t|| f |||< d S )	NDirectoriesDependenciesrb   rc   c                 S      g | ]}| d dqS )rb   rc   rh   rm   rX   rX   rY   rp          z$_ToolSetOrAppend.<locals>.<listcomp>CompileAsWinRTzZAppending "%s" to a non-list setting "%s" for tool "%s" is not allowed, previous value: %s)typestrrh   rG   dictlist	TypeError)r   r   r   r   r   toolrX   rX   rY   r      s(   


r   c                 C      |  ddS )Nmsvs_target_versionWindows7rG   config_datarX   rX   rY   _ConfigTargetVersion     r   c                 C   r   )Nmsvs_configuration_platformWin32r   r   rX   rX   rY   _ConfigPlatform  r   r   c                 C   s(   |  d| r| dt| d  S | S )N_r   r@   )endswithr~   )config_nameplatform_namerX   rX   rY   _ConfigBaseName  s   r   c                 C   s   t |}dt| ||f S )N%s|%s)r   r   )r   r   r   rX   rX   rY   _ConfigFullName  s   r   c           	         s   |  d}|r
|gn j}|D ]H}dD ]C}t|| d}|s qt|| dp)d d| }t fddtj|r?t|ng D d	d
}|rP|d     S t	d   qqd S )Nmsvs_windows_sdk_version)z1HKLM\Software\Microsoft\Microsoft SDKs\Windows\%sz=HKLM\Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows\%sInstallationFolderProductVersionr   z
%s\includec                    s   g | ]	}|  r|qS rX   )
startswithrn   xversionrX   rY   rp   /  s    
z7_ConfigWindowsTargetPlatformVersion.<locals>.<listcomp>T)reverser   zCWarning: No include files found for detected Windows SDK version %s)
rG   compatible_sdksMSVSVersion_RegistryGetValuesortedrE   r\   isdirlistdirprint)	r   r   
config_verversverkeysdk_direxpected_sdk_dirnamesrX   r   rY   #_ConfigWindowsTargetPlatformVersion"  s.   

r   c                 C   s  dd |D r
d}nd}|rt | ddgd }|}dd |D }d	d |D }d
d |D }|r9dd |D }dd |D }d|}d}|rM|d7 }|d7 }|ddkr\|d7 }|ddkrg|d7 }|ddkrr|d7 }|r|ddkr|d7 }|d7 }|||d }|| S |d dkrdg}	n	|d ddg}	|	dd dd |d d  D }
d!d |
D }
d"d |
D }
|rd#d |
D }
|d|	|
  S )$Nc                 S   s   g | ]}d |v r|qS )r   rX   r   rX   rX   rY   rp   >  r   z/_BuildCommandLineForRuleRaw.<locals>.<listcomp>z_set INPUTDIR=$(InputDir)
if NOT DEFINED INPUTDIR set INPUTDIR=.\
set INPUTDIR=%INPUTDIR:~0,-1%
r   r%   .r   c                 S   r   )r   z`cygpath -m "${INTDIR}"`r   rm   rX   rX   rY   rp   L  
    c                 S   r   )r   z`cygpath -m "${OUTDIR}"`r   rm   rX   rX   rY   rp   N  r   c                 S   r   )r   z`cygpath -m "${INPUTDIR}"`r   rm   rX   rX   rY   rp   P  r   c                 S   r   )r"   z`cygpath -m "${INPUTPATH}"`r   rm   rX   rX   rY   rp   S  s
    c                 S   s   g | ]
}d | dd qS )z\"%s\""z\\\"r   rm   rX   rX   rY   rp   V       z4call "$(ProjectDir)%(cygwin_dir)s\setup_env.bat" && zset CYGWIN=nontsec&& NUMBER_OF_PROCESSORSz@set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& INTDIRzset INTDIR=$(IntDir)&& OUTDIRzset OUTDIR=$(OutDir)&& 	INPUTPATHzset INPUTPATH=$(InputPath) && zbash -c "%(cmd)s")
cygwin_dircmdcatr   rb   rc   rS   c                 S   s(   g | ]}|d d dv r|nt |qS )Nr@   z/-rl   rm   rX   rX   rY   rp   z  s   ( r@   c                 S   r   )r   z
%INPUTDIR%r   rm   rX   rX   rY   rp   {  r   c                 S      g | ]}t |qS rX   )MSVSSettingsFixVCMacroSlashesrm   rX   rX   rY   rp   |      c                 S      g | ]}d | qS z"%s"rX   rm   rX   rX   rY   rp     rq   )rj   rG   rg   findrh   insert)specr   cygwin_shellhas_input_path	quote_cmddo_setup_envinput_dir_preambler   
direct_cmdcommand	argumentsrX   rX   rY   _BuildCommandLineForRuleRaw;  sb   
r   c                 C   s^   | d}|d u rt|  dd}n	t|trt|}t| dd}t| |d ||||dS )Nr'   r@   msvs_quote_cmdaction)r   )rG   int
isinstancer   r   )r   ruler   r   mcsr   rX   rX   rY   _BuildCommandLineForRule  s   

r   c                 C   s@   |sJ ||||d}|d }|| vrg | |< | |  | dS )a  Merge action into an existing list of actions.

  Care must be taken so that actions which have overlapping inputs either don't
  get assigned to the same input, or get collapsed into one.

  Arguments:
    actions_dict: dictionary keyed on input name, which maps to a list of
      dicts describing the actions attached to that input file.
    inputs: list of inputs
    outputs: list of outputs
    description: description of the action
    command: command line to execute
  inputsoutputsdescriptionr   r   Nr   )actions_dictr   r   r   r   r   chosen_inputrX   rX   rY   _AddActionStep  s   
r   c           
      C   sh   t |}t |}td|d|d||d}|d  D ]\}}	| jt|t||	|gd qdS )a8  Add a custom build tool to execute something.

  Arguments:
    p: the target project
    spec: the target project dict
    primary_input: input file to attach the build tool to
    inputs: list of inputs
    outputs: list of outputs
    description: description of the action
    cmd: command line to execute
  VCCustomBuildTool;)DescriptionAdditionalDependenciesOutputsCommandLineconfigurationsr   N)rs   r   Toolrg   itemsAddFileConfigrj   r   )
pr   primary_inputr   r   r   r   r   r   c_datarX   rX   rY   _AddCustomBuildToolForMSVS  s   
r  c              
   C   s   |D ]H}t  }t  }g }g }|| D ]"}|t |d  |t |d  ||d  ||d  qd|}	d|}
t| |||||	|
d qdS )	a  Add actions accumulated into an actions_dict, merging as needed.

  Arguments:
    p: the target project
    spec: the target project dict
    actions_dict: dictionary keyed on input name, which maps to a list of
        dicts describing the actions attached to that input file.
  r   r   r   r   , and also 
)r  r   r   r   r   N)r   updater   rg   r  )r  r   r   r  r   r   descriptionscommandsr   r   r   rX   rX   rY   _AddAccumulatedActionsToMSVS  s(   	

r  c                 C   s   |  dtjtj|d d } |  dtj|} |  dtjtj|d d } |  dtj|d } |  d|} | S )zGiven the input file to which a rule applied, string substitute a path.

  Arguments:
    path: a path to string expand
    input_file: the file to which the rule applied.
  Returns:
    The string substituted path.
  r   r@   r   r   r   r!   r"   )rh   rE   r\   splitextsplitdirname)r\   
input_filerX   rX   rY   _RuleExpandPath  s   	r  c                 C   s   |  dg S )zFind the list of files which a particular rule applies to.

  Arguments:
    rule: the rule in question
    sources: the set of all known source files for this project
  Returns:
    The list of sources that trigger a particular rule.
  rule_sourcesr   )r   r   rX   rX   rY   _FindRuleTriggerFiles  s   	r  c                 C   sr   t | dg }t | dg }t }t }|| |D ]
}|t|| q|D ]
}|t|| q*||fS )zFind the inputs and outputs generated by a rule.

  Arguments:
    rule: the rule in question.
    trigger_file: the main trigger for this rule.
  Returns:
    The pair of (inputs, outputs) involved in this rule.
  r   r   )rs   rG   r   addr  )r   trigger_file
raw_inputsraw_outputsr   r   ro   orX   rX   rY   _RuleInputsAndOutputs  s   	
r  c              	   C   s   d|d |j f }ttj|||d }|D ]=}|d }|d }	t|dg }
t|dg }d|vr=|dg s=qt||d	d	d
}|j	||d||	g|
||d q|
  | | dS )zGenerate a native rules file.

  Arguments:
    p: the target project
    rules: the set of rules to include
    output_dir: the directory in which the project/gyp resides
    spec: the project dict
    options: global generator options
  z
%s%s.rulestarget_name	rule_name	extensionr   r   r   r  Tr   r   message)namer   
extensionsadditional_dependenciesr   r   N)suffixMSVSToolFileWriterrE   r\   rg   rs   rG   r   AddCustomBuildRuleWriteIfChangedAddToolFile)r  rules
output_dirr   optionsrules_filename
rules_filerr  rule_extr   r   r   rX   rX   rY   _GenerateNativeRulesForMSVS&  s2   

r.  c                 C   s   |  dd} |  dd} | S )Nr   z$(OutDirCygwin)r   z$(IntDirCygwin)r   ri   rX   rX   rY   
_CygwinifyL  s   r/  c              	      s(  d|d |j f }tjtj||}|d |d t }t }	t }
g }| D ];}t	||}|D ]1 t
| \}}|t| |	t| |t|d  dd |D }|D ]}|
| q]q4q+dd |D }|d	d
|  |
D ]}|r|d|  qz|d | D ]N}t	||}|D ]D t
| \}}dd |D }dd |D } fdd|d D }dd |D }d
|}|dd
|d
|f  |d|  qq|  || dddddd|g}t||dddd}t|}|d| t|t|t|	d|d  |d dS )aG  Generate an external makefile to do a set of rules.

  Arguments:
    rules: the list of rules to include
    output_dir: path containing project and gyp files
    spec: project specification data
    sources: set of sources known
    options: global generator options
    actions_to_add: The list of actions we will add to.
  z%s_rules%s.mkr  z.OutDirCygwin:=$(shell cygpath -u "$(OutDir)")
z.IntDirCygwin:=$(shell cygpath -u "$(IntDir)")
r   c                 S   s   g | ]
}t j|d  qS r   )rE   r\   r  rm   rX   rX   rY   rp   r  r   z*_GenerateExternalRules.<locals>.<listcomp>c                 S   rk   rX   r/  rm   rX   rX   rY   rp   u  rq   zall: %s
r   z	mkdir -p `cygpath -u "%s"`

c                 S   rk   rX   r1  rm   rX   rX   rY   rp     rq   c                 S   rk   rX   r1  rm   rX   rX   rY   rp     rq   c                    s   g | ]}t | qS rX   )r  rn   ctfrX   rY   rp     r   r   c                 S   r   r   rX   rm   rX   rX   rY   rp     rq   z%s: %s
z	%s

makezOutDir=$(OutDir)zIntDir=$(IntDir)z-jz${NUMBER_OF_PROCESSORS_PLUS_1}z-fTFzRunning external rules for %sr   N)r!  gypcommonWriteOnDiffrE   r\   rg   writer   r  r  r  r   r   r  closer   r   r   rs   )r'  r(  r   r   r)  actions_to_addr   mk_file
all_inputsall_outputsall_output_dirsfirst_outputsr   trigger_filesr   r   output_dirsodfirst_outputs_cygr   rX   r5  rY   _GenerateExternalRulesR  st   







rG  c                 C   s   |  dd} | S )a  Escapes % characters.

  Escapes any % characters so that Windows-style environment variable
  expansions will leave them alone.
  See http://connect.microsoft.com/VisualStudio/feedback/details/106127/cl-d-name-text-containing-percentage-characters-doesnt-compile
  to understand why we have to do this.

  Args:
      s: The string to be escaped.

  Returns:
      The escaped string.
  %z%%r   r   rX   rX   rY   #_EscapeEnvironmentVariableExpansion  s   rJ  z(\\*)"c                 C   s$   dd }t || } d|  d } | S )aw  Escapes a Windows command-line argument.

  So that the Win32 CommandLineToArgv function will turn the escaped result back
  into the original string.
  See http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
  ("Parsing C++ Command-Line Arguments") to understand why we have to do
  this.

  Args:
      s: the string to be escaped.
  Returns:
      the escaped string.
  c                 S   s   d|  d d S )N   r@   \"rP   matchrX   rX   rY   _Replace  s   z3_EscapeCommandLineArgumentForMSVS.<locals>._Replacer   )quote_replacer_regexsubr   rP  rX   rX   rY   !_EscapeCommandLineArgumentForMSVS  s   rT  z(\\*)([,;]+)c                 C   sl   dd }|  d}tdt|dD ]}t||| ||< qd|} t|d dkr4td|  tjd | S )a  Escapes command line arguments for MSVS.

  The VCProj format stores string lists in a single string using commas and
  semi-colons as separators, which must be quoted if they are to be
  interpreted literally. However, command-line arguments may already have
  quotes, and the VCProj parser is ignorant of the backslash escaping
  convention used by CommandLineToArgv, so the command-line quotes and the
  VCProj quotes may not be the same quotes. So to store a general
  command-line argument in a VCProj list, we need to parse the existing
  quoting according to VCProj's convention and quote any delimiters that are
  not already quoted by that convention. The quotes that we add will also be
  seen by CommandLineToArgv, so if backslashes precede them then we also have
  to escape those backslashes according to the CommandLineToArgv
  convention.

  Args:
      s: the string to be escaped.
  Returns:
      the escaped string.
  c                 S   s    d|  d d |  d d S )NrK  r@   r   rM  rN  rX   rX   rY   rP    s    z5_EscapeVCProjCommandLineArgListItem.<locals>._Replacer   r   rK  z;Warning: MSVS may misinterpret the odd number of quotes in )file)	r  ranger~   delimiters_replacer_regexrR  rg   r   rA   stderr)r   rP  segmentsro   rX   rX   rY   #_EscapeVCProjCommandLineArgListItem  s   

rZ  c                 C   0   t | } t| } t| } | ddtd } | S zBEscapes a CPP define so that it will reach the compiler unaltered.#z\%03o)rJ  rT  rZ  rh   ordrI  rX   rX   rY   _EscapeCppDefineForMSVS  
   r_  z(\\+)"c                 C   s   dd }t || } | S )z;Escapes a Windows command-line argument for use by MSBuild.c                 S   s   t | dd d d d S )Nr@   rK     rc   rL  )r~   rP   rN  rX   rX   rY   rP    s   z6_EscapeCommandLineArgumentForMSBuild.<locals>._Replace)quote_replacer_regex2rR  rS  rX   rX   rY   $_EscapeCommandLineArgumentForMSBuild  s   rc  c                    s0   dddddddd d	  fd
d| D }|S )Nz%25z%24z%40z%27z%3Bz%3Fz%2A)rH  r[   @'r   ?*r   c                    s   g | ]}  ||qS rX   r   r3  escape_dictionaryrX   rY   rp   )  r   z3_EscapeMSBuildSpecialCharacters.<locals>.<listcomp>)rg   )r   r   rX   rh  rY   _EscapeMSBuildSpecialCharacters  s   	rj  c                 C   r[  r\  )rJ  rc  rj  rh   r^  rI  rX   rX   rY   _EscapeCppDefineForMSBuild-  r`  rk  c           
      C   sd   | dg }dd |D }dd |D }	|rt| |||| |	r)t|	||||| t|||d dS )a  Generate all the rules for a particular project.

  Arguments:
    p: the project
    output_dir: directory to emit rules to
    options: global options passed to the generator
    spec: the specification for this project
    sources: the set of all known source files in this project
    excluded_sources: the set of sources excluded from normal processing
    actions_to_add: deferred list of actions to add in
  r'  c                 S       g | ]}t |d ds|qS msvs_external_ruler   r   rG   rn   r,  rX   rX   rY   rp   G       z)_GenerateRulesForMSVS.<locals>.<listcomp>c                 S       g | ]}t |d dr|qS rm  ro  rp  rX   rX   rY   rp   H  rq  FN)rG   r.  rG  _AdjustSourcesForRules)
r  r(  r)  r   r   excluded_sourcesr=  r'  rules_nativerules_externalrX   rX   rY   _GenerateRulesForMSVS8  s   rw  c           	      C   s   | D ]F}t ||}|D ]<}|t| t|ddrGt||\}}tt|}tt|}|t| |	| |sB|	| |	| qqd S )Nprocess_outputs_as_sourcesF)
r  discardrj   r   rG   r  r   rs   remover  )	r'  r   rt  
is_msbuildr   rC  r  r   r   rX   rX   rY   rs  U  s    



rs  c                    s"   t t|   fdd| D S )a*  Take inputs with actions attached out of the list of exclusions.

  Arguments:
    excluded_sources: list of source files not to be built.
    actions_to_add: dict of actions keyed on source file they're attached to.
  Returns:
    excluded_sources with files that have actions attached removed.
  c                       g | ]}| vr|qS rX   rX   rn   r   	must_keeprX   rY   rp   u  r   z._FilterActionsFromExcluded.<locals>.<listcomp>)r   rs   keys)rt  r=  rX   r~  rY   _FilterActionsFromExcludedk  s   	r  c                 C   s   | d | d  S )Nr   default_configurationrX   )r   rX   rX   rY   _GetDefaultConfigurationx  s   r  c                 C   sP   t |}|d}|rt|du rtd|tjf d| }|p%t| }|S )a  Get the guid for the project.

  Arguments:
    proj_path: Path of the vcproj or vcxproj file to generate.
    spec: The target dictionary containing the properties of the target.
  Returns:
    the guid.
  Raises:
    ValueError: if the specified GUID is invalid.
  	msvs_guidNz1Invalid MSVS guid: "%s".  Must match regex: "%s".z{%s})r  rG   VALID_MSVS_GUID_CHARSrO  
ValueErrorpatternMSVSNewMakeGuid)	proj_pathr   default_configguidrX   rX   rY   _GetGuidOfProject|  s   
r  c                 C   s:   t |}|d}|s| r| }|d dkrd}|S )a  Get the platform toolset for the project.

  Arguments:
    proj_path: Path of the vcproj or vcxproj file to generate.
    spec: The target dictionary containing the properties of the target.
    version: The MSVSVersion object.
  Returns:
    the platform toolset string or None.
  msbuild_toolsetr   windows_driverzWindowsKernelModeDriver10.0)r  rG   DefaultToolset)r  r   r   r  toolsetrX   rX   rY   _GetMsbuildToolsetOfProject  s   
r  c                 C   s<   t | j}|drg S | rt| |||S t| |||S )a  Generates a vcproj file.

  Arguments:
    project: the MSVSProject object.
    options: global generator options.
    version: the MSVSVersion object.
    generator_flags: dict of generator-specific flags.
  Returns:
    A list of source files that cannot be found on disk.
  msvs_existing_vcproj)r  r   rG   r   _GenerateMSBuildProject_GenerateMSVSProject)projectr)  r   generator_flagsr  rX   rX   rY   _GenerateProject  s   

r  c                 C   s   |  rJ | dddvrdS | dg }i }|D ] }tj|\}}|dv }|s+qtj|}||g | qd}	| D ]\}}
t	|
dkrV|	d|d	
|
f 7 }	qA|	ritd
| d  |	 d  tddS )zMakes sure if duplicate basenames are not specified in the source list.

  Arguments:
    spec: The target dictionary containing the properties of the target.
    version: The VisualStudioVersion object.
  r   N)static_libraryshared_libraryr   ).c.cc.cpp.cxxz.mz.mmz.sz.Sr   r@   z	  %s: %s
r   z<static library %s has several files with the same basename:
r  zMSVC08 cannot handle that.z6Duplicate basenames in sources section, see list above)r   rG   rE   r\   r  basename
setdefaultr   r   r~   rg   r   r   )r   r   r   	basenamesr_   r  extis_compiled_filer  errorfilesrX   rX   rY   _ValidateSourcesForMSVSProject  s6   r  c                 C   s|  | j }tj| j t|}t| j||d | j|}t	j
| jd }t| j}tj||}	t|| j}
|d  D ]\}}t|||
|| q<t|| t	j
| jd }t|||\}}i }t||||||| |dd}t|||||||\}}}t||}|| t|| t||| t|||	 t|| t| j|| t||}t||||| t||| |   |S )a-  Generates a .vcproj file.  It may create .rules and .user files too.

  Arguments:
    project: The project object we will generate the file for.
    options: Global options passed to the generator.
    version: The VisualStudioVersion object.
    generator_flags: dict of generator-specific flags.
  r  r   r   r@   msvs_list_excluded_filesT)!r   r8  r9  EnsureDirExistsr\   _GetUniquePlatformsr   r#  r  rE   r  ra   
build_fileRelativePath_GetMSVSConfigurationTyper   _AddConfigurationToMSVSProjectr  _PrepareListOfSourcesrw  rG   )_AdjustSourcesAndConvertToFilterHierarchy_VerifySourcesExistAddFiles_AddToolFilesToMSVS_HandlePreCompiledHeaders_AddActions
_AddCopies_WriteMSVSUserFiler  _ExcludeFilesFromBeingBuiltr  r%  )r  r)  r   r  r   	platformsr  project_dirgyp_pathrelative_path_of_gyp_fileconfig_typer   r=   gyp_filer   rt  r=  rv   excluded_idlmissing_sourcesrX   rX   rY   r    sX   	







r  c                 C   s6   t  }| d D ]}|t| d |  qt|}|S )zReturns the list of unique platforms for this spec, e.g ['win32', ...].

  Arguments:
    spec: The target dictionary containing the properties of the target.
  Returns:
    The MSVSUserFile object created.
  r   )r   r  r   r   )r   r  configurationrX   rX   rY   r  )  s
   	r  c                 C   s2   t  \}}d| ||dg}t|||d }|S )a  Generates a .user file for the user running this Gyp program.

  Arguments:
    proj_path: The path of the project file being created.  The .user file
               shares the same path (with an appropriate suffix).
    version: The VisualStudioVersion object.
    spec: The target dictionary containing the properties of the target.
  Returns:
    The MSVSUserFile object created.
  r   userr  )rZ   rg   MSVSUserFiler#  )r  r   r   rQ   rR   vcuser_filename	user_filerX   rX   rY   _CreateMSVSUserFile9  s   
r  c                 C   sh   zddddddd| d  }W |S  t y3   | dr)td| d | d	 |f td
| d	 |f w )a(  Returns the configuration type for this project.

  It's a number defined by Microsoft.  May raise an exception.

  Args:
      spec: The target dictionary containing the properties of the target.
      build_file: The path of the gyp file.
  Returns:
      An integer, the configuration type.
  124510)
executabler  loadable_moduler  r  noner   z>Target type %s is not a valid target type for target %s in %s.r  z'Missing type field for target %s in %s.)KeyErrorrG   r   )r   r  r  rX   rX   rY   r  K  s(   

r  c                 C   s  t |\}}}t|}t|}	t|dd\}
}}t|}dd |D }t|}|d}|d}t|}|d}t }|di }t	
| t|d	d
dg |D ]}|d | }|D ]}t|||||  q\qRt|dd| t|dd| t|dd| t|d	d
| t|d	d|	 |
rt||d|
dd t|dd| t|dd| t|ddddd t|dd| t|dd| t|dd| |rtj|d }t|ddd t|dd| t|dd| |d  d!krt|d	d"d# |rt|d	d$| t| ||||| d%S )&a+  Adds a configuration to the MSVS project.

  Many settings in a vcproj file are specific to a configuration.  This
  function the main part of the vcproj file that's configuration specific.

  Arguments:
    p: The target project being generated.
    spec: The target dictionary containing the properties of the target.
    config_type: The configuration type, a number as defined by Microsoft.
    config_name: The name of the configuration.
    config: The dictionary that defines the special processing to be done
            for this configuration.
  Fmsbuildc                 S   rk   rX   )r_  rn   drX   rX   rY   rp     rq   z2_AddConfigurationToMSVSProject.<locals>.<listcomp>msvs_prebuildmsvs_postbuildr5   msvs_settingsVCLinkerToolr   $(NOINHERIT)VCCLCompilerToolAdditionalIncludeDirectories
VCMIDLToolVCResourceCompilerToolAdditionalLibraryDirectories
OutputFileTr   PreprocessorDefinitionsProgramDataBaseFileNamez $(IntDir)$(ProjectName)\vc80.pdbDisableSpecificWarningsVCPreBuildEventToolr   VCPostBuildEventToolr@   UsePrecompiledHeaderr  PrecompiledHeaderThroughForcedIncludeFilesr   r  IgnoreImportLibrarytrueModuleDefinitionFileN)_GetIncludeDirs_GetLibraries_GetLibraryDirs_GetOutputFilePathAndTool_GetDefines_GetDisabledWarningsrG   _GetModuleDefinitionr   r   ValidateMSVSSettingsr   rE   r\   r  _AddConfigurationToMSVS)r  r   r  r   r=   include_dirsmidl_include_dirsresource_include_dirs	librarieslibrary_dirsout_filevc_toolr   definesdisabled_warningsprebuild	postbuilddef_fileprecompiled_headerr   r  r   settingsr   rX   rX   rY   r  j  s|   



r  c                 C   s^   |  dg |  dg  }|  dg |  dg  }|  d|}t|}t|}t|}|||fS )zReturns the list of directories to be used for #include directives.

  Arguments:
    config: The dictionary that defines the special processing to be done
            for this configuration.
  Returns:
    The list of directory paths.
  r  msvs_system_include_dirsr  r  rG   rs   )r=   r  r  r  rX   rX   rY   r    s   




r  c                 C   s   |  dg }t|}|S )zReturns the list of directories to be used for library search paths.

  Arguments:
    config: The dictionary that defines the special processing to be done
            for this configuration.
  Returns:
    The list of directory paths.
  r  r  )r=   r  rX   rX   rY   r    s   
r  c                 C   sr   |  dg }t }g }t|D ]#}tdd|}tj|d s$|d7 }||vr2|| |	| q|
  |S )zReturns the list of libraries for this configuration.

  Arguments:
    spec: The target dictionary containing the properties of the target.
  Returns:
    The list of directory paths.
  r  z^\-lr   r@   r   )rG   r   reversedrL   rR  rE   r\   r  r  r   r   )r   r  foundunique_libraries_listentrylibraryrX   rX   rY   r    s   

r  c                 C   s   d}d}d}dddddd}| | d }|rYt|  dd	rY|\}}}}|  d
dr-d}|  d|}|  d}	|	r?d|	 }n|rCd}|  dd}
|  dd}t||
| | }|||fS )aN  Returns the path and tool to use for this target.

  Figures out the path of the file this spec will create and the name of
  the VC tool that will create it.

  Arguments:
    spec: The target dictionary containing the properties of the target.
  Returns:
    A triple of (file path, name of the vc tool, name of the msbuild tool)
  r   )r  Linkr   r   )r  r  r   r   )r  r  r   r   )VCLibrarianToolLibz$(OutDir)lib\r   r  r  r  r  r  r   msvs_auto_output_filer@   standalone_static_libraryr   r   product_dirproduct_extensionr   z$(TargetExt)product_prefixproduct_name$(ProjectName))rG   r   ntpathrg   )r   r  r  r  msbuild_tooloutput_file_mapoutput_file_propsout_dirr!  r  r{   r  rX   rX   rY   r    s0   


r  c                 C   s   |  d}|rd| S dS )aq  Returns the extension for this target, including the dot

  If product_extension is specified, set target_extension to this to avoid
  MSB8012, returns None otherwise. Ignores any target_extension settings in
  the input files.

  Arguments:
    spec: The target dictionary containing the properties of the target.
  Returns:
    A string with the extension, or None
  r  r   Nr   )r   target_extensionrX   rX   rY   _GetOutputTargetExt)  s   
r  c                 C   sN   g }|  dg D ]}t|tkrddd |D }nt|}|| q|S )zReturns the list of preprocessor definitions for this configuation.

  Arguments:
    config: The dictionary that defines the special processing to be done
            for this configuration.
  Returns:
    The list of preprocessor definitions.
  r  =c                 S   rk   rX   r   )rn   dpartrX   rX   rY   rp   G  rq   z_GetDefines.<locals>.<listcomp>)rG   r   r   rg   r   r   )r=   r  r  fdrX   rX   rY   r  ;  s   	r  c                 C   s   dd |  dg D S )Nc                 S   rk   rX   r  rm   rX   rX   rY   rp   O  rq   z(_GetDisabledWarnings.<locals>.<listcomp>msvs_disabled_warningsr   r=   rX   rX   rY   r  N  s   r  c                 C   sd   d}| d dv r0dd |  dg D }t|dkr!t|d }|S |r0td	| d
 d|f |S )Nr   r   )r  r  r  r  c                 S      g | ]	}| d r|qS )z.defr   r}  rX   rX   rY   rp   V      z(_GetModuleDefinition.<locals>.<listcomp>r   r@   r   zWMultiple module definition files in one target, target %s lists multiple .def files: %sr  r   )rG   r~   rj   r  rg   )r   r  	def_filesrX   rX   rY   r  R  s   r  c                 C   s   g }|   D ]>\}}i }|  D ]*\}}t|tkr6|dkr"|dks&|dkr.d|||< qd|||< q|||< q|t|| q|S )zConvert tools to a form expected by Visual Studio.

  Arguments:
    tools: A dictionary of settings; the tool name is the key.
  Returns:
    A list of Tool objects.
  r  r   AdditionalOptionsr   r   )r   r   r   rg   r   r   r   )r   	tool_listr   r   settings_fixedr   r   rX   rX   rY   _ConvertToolsToExpectedForma  s   
r'  c                 C   s.   t |||}t|}| jt||||d dS )a  Add to the project file the configuration specified by config.

  Arguments:
    p: The target project being generated.
    spec: the target project dict.
    tools: A dictionary of settings; the tool name is the key.
    config: The dictionary that defines the special processing to be done
            for this configuration.
    config_type: The configuration type, a number as defined by Microsoft.
    config_name: The name of the configuration.
  )attrsr   N)_GetMSVSAttributesr'  	AddConfigr   )r  r   r   r=   r  r   
attributesr%  rX   rX   rY   r  |  s
   
r  c           	      C   s   i }| di }|D ]}|| ||< q
| dg }t|}|r&d||d< ||d< | dd}t|d |d< d	|vrHd
}t|d |d	< |S t|d	 d }t|}||d	< |S )Nmsvs_configuration_attributesr&   r   InheritedPropertySheetsConfigurationTypeOutputDirectoryz"$(SolutionDir)$(ConfigurationName)rc   IntermediateDirectoryz'$(ConfigurationName)\obj\$(ProjectName))rG   rs   rg   rj   r   r   )	r   r=   r  prepared_attrssource_attrsavsprops_dirsr(  intermediaterX   rX   rY   r)    s*   
r)  c                 C   s   |  dd |D  d S )Nc                 s   s    | ]}t |V  qd S r   ra   r}  rX   rX   rY   	<genexpr>  s    z(_AddNormalizedSources.<locals>.<genexpr>)r  )sources_setsources_arrayrX   rX   rY   _AddNormalizedSources  s   r:  c                 C   s   t  }t|| dg  t  }|ds|| | dg D ]1}|d }dd |D }t |}|| | ds?|| t|dd	rPt||d
g  q| dg D ]}t||dg  qW||fS )a.  Prepare list of sources and excluded sources.

  Besides the sources specified directly in the spec, adds the gyp file so
  that a change to it will cause a re-compile. Also adds appropriate sources
  for actions and copies. Assumes later stage will un-exclude files which
  have custom build steps attached.

  Arguments:
    spec: The target dictionary containing the properties of the target.
    gyp_file: The name of the gyp file.
  Returns:
    A pair of (list of sources, list of excluded sources).
    The sources will be relative to the gyp file.
  r   
standaloneactionsr   c                 S   rk   rX   r6  rm   rX   rX   rY   rp     rq   z)_PrepareListOfSources.<locals>.<listcomp>r*   rx  Fr   copiesr  )r   r:  rG   r  r  r   )r   r  r  r   rt  r3  r   cpyrX   rX   rY   r    s$   




r  c           	         sD  | t| dg  | | t|}t|}t| |}t|   fdd|D }dd |D }t||||d}| r|tdd |D r{t	t
dd |D dkr{td	d |D s^J d
d |D }tdd |D r{t	t
dd |D dksSn!t	|dkrt|d tjr|d j}t	|dkrt|d tjs|||fS )a&  Adjusts the list of sources and excluded sources.

  Also converts the sets to lists.

  Arguments:
    spec: The target dictionary containing the properties of the target.
    options: Global generator options.
    gyp_dir: The path to the gyp file being processed.
    sources: A set of sources to be included for this project.
    excluded_sources: A set of sources to be excluded for this project.
    version: A MSVSVersion object.
  Returns:
    A trio of (list of sources, list of excluded sources,
               path of excluded IDL file)
  sources_excludedc                    r|  rX   rX   rm   precompiled_relatedrX   rY   rp     r   z=_AdjustSourcesAndConvertToFilterHierarchy.<locals>.<listcomp>c                 S   s   g | ]}| d qS )rc   )r  rm   rX   rX   rY   rp     r   rt   c                 S   s   g | ]}t |tjqS rX   )r   r   r   r}  rX   rX   rY   rp     r   c                 S   s   g | ]}|j qS rX   )r  r}  rX   rX   rY   rp      s    r@   c                 S   s   g | ]	}t |jd kqS )r@   )r~   ry   r}  rX   rX   rY   rp     r"  c                 S   s   g | ]}|j d  qS r0  rx   r}  rX   rX   rY   rp     r   r   )r  r   rG   rs   _IdlFilesHandledNonNatively_GetPrecompileRelatedFilesr   r   allr~   setr   r   r   ry   )	r   r)  gyp_dirr   rt  rv   r   r  fully_excludedrX   r@  rY   r    s0   



r  c                 C   sX   d}|  dg D ]}|d dkrt| ddrd} nq|r(dd	 |D }|S g }|S )
NFr'  r  idlrn  r   Tc                 S   r   ).idlr!  rm   rX   rX   rY   rp     r"  z/_IdlFilesHandledNonNatively.<locals>.<listcomp>)rG   r   )r   r   	using_idlr   r  rX   rX   rY   rB  
  s   rB  c                 C   sD   g }| d   D ]\}}tD ]}||}|r|t| qq|S )Nr   )r   precomp_keysrG   r   rj   )r   rA  r   r=   kr   rX   rX   rY   rC    s   
rC  c           
      C   sb   t |||}| D ]$\}}|st|t|d krq
|D ]\}}	| |t||	ddi qq
d S )Nr   ExcludedFromBuildr  )_GetExcludedFilesFromBuildr   r~   r  r   )
r  r   rt  r  rv   
exclusions	file_nameexcluded_configsr   r=   rX   rX   rY   r  $  s   r  c                    s   i }|D ]'}g }| d   D ]\}  fddtD }||vr&|| f q|||< q|D ]}g }| d   D ]\} || f q8|||< q.|S )Nr   c                    s   g | ]
}t  |d qS )r   )rj   rG   rm   r  rX   rY   rp   9  r   z._GetExcludedFilesFromBuild.<locals>.<listcomp>)r   rK  r   )r   rt  r  rO  r   rQ  r   	precompedrX   r  rY   rN  3  s   

rN  c                 C   sP   t  }|d  D ]\}}|dg D ]}|| qq	|D ]}| | qd S )Nr   msvs_tool_files)r   r   rG   r  r&  )r  r   
tool_filesr   r=   r   rX   rX   rY   r  H  s   r  c           	         s   g d   D ]8\}}|d}|r@t|}tdddi}j|t||i |gd tj	|\}}|dkr=g dqdgq fd	d
 rR | d S d S )Nr   r6   r  r  r  r   r  r  r  r  c                    s   | D ]=}t |tjr |j qtj|\}}|v r?d  D ]\}}tdddd}j	t
|t||i |gd q"qd S )Nr   r  0r  )r  r  r   )r   r   r   ry   rE   r\   r  r   r   r  rj   r   )source_treer_   r  r  r   r=   r   DisableForSourceTree#extensions_excluded_from_precompiler  r   rX   rY   rY  f  s"   
z7_HandlePreCompiledHeaders.<locals>.DisableForSourceTree)
r   rG   rj   r   r   r  r   rE   r\   r  )	r  r   r   r   r=   r_   r   r  r  rX   rX  rY   r  R  s(   

r  c           
   
   C   s   | dg }t }|D ]2}| dp|g}|d }||v}t||d|d}	|| t| || dg | d|d |	d	 qd S )
Nr<  r   r   Fr  r   r  action_namer   )rG   rE  r   r  r   )
r=  r   r  r<  have_setup_envr3  r   attached_toneed_setup_envr   rX   rX   rY   r  y  s"   

r  c           
      C   s   d|v r|d }| dg }| dg }| dd}nt| ddr,dd	g}g }d}nd S t| ||}|d
  D ]\}}	|t||	||| q:|  d S )Nrun_asr   environmentworking_directoryr   testr   z$(TargetPath)z--gtest_print_timer   )rG   r   r  r   AddDebugSettingsr   r%  )
project_pathr   r   r_  r   r`  ra  r  r   r  rX   rX   rY   r    s    r  c                 C   s0   t |}|D ]\}}}}t| ||||d qd S )Nr   )
_GetCopiesr   )r=  r   r=  r   r   r   r   rX   rX   rY   r    s   r  c              
   C   s  g }|  dg D ]v}| dg D ]m}tj|d tj|}|dr]|d d }t|d }t|d }t|}d||f }	d	|	t|||	f }
|	|gd
|g|
d||f f qt|d }d|t|t|f }
|	|g|g|
d||f f qq|S )Nr=  r  destinationrb   rd   r   r@   z"%s\%s\"z2mkdir %s 2>nul & cd "%s" && xcopy /e /f /y "%s" %sdummy_copieszCopying %s to %sz7mkdir "%s" 2>nul & set ERRORLEVEL=0 & copy /Y "%s" "%s")
rG   rE   r\   rg   r  r   	posixpathr  rj   r   )r   r=  r>  srcdstsrc_barebase_dir	outer_dir	fixed_dstfull_dstr   fix_dstrX   rX   rY   re    s.   

 re  c                 C   sH   |r| tjr
| S tj|\}}t| |}||vr t ||< || S r   )r   rE   sepr\   r  _GetPathDictr   )rootr\   parentfolderparent_dictrX   rX   rY   rr    s   

rr  c                 C   s   g }|  D ]8\}}t|tkr9ttj| |||}|r"||7 }qtjtj| |d| d |d}|	| q|	| q|S )N())r  entries)
r   r   r   _DictsToFoldersrE   r\   rg   r  
MSVSFolderr   )	base_pathbucketflatchildrenru  ry   folder_childrenrX   rX   rY   rz    s   

rz  c                 C   sl   t |tkrt|dkrtt|| d kr|tt| S t |tkr&|S |D ]}t||| ||< q(|S )Nr@   .vcproj)r   r   r~   nextiter_CollapseSingles)rt  nodechildrX   rX   rY   r    s   r  c           	      C   s   i }| D ]!}t j|dd \}}tj|}t||}|| ||d < qt|dkrRt|t	t
| tkrR|t	t
| }t|dkrRt|t	t
| tks8td|}td||S )Nr   rK  r  r@   r   )r8  r9  ParseQualifiedTargetrE   r\   r  rr  r~   r   r  r  r   r  rz  )	sln_projectsproject_objectsr~  rs  r  r  targetrF  	path_dictrX   rX   rY   _GatherSolutionFolders  s   
$$
r  c           
      C   s   t |}|d}|s|d |j |  }tj| }tj	tj
||}d }|jrItj
tj|}	tj	|j|}tj|	tj
|}||fS )Nr  r  )r  rG   r!  ProjectExtensionr8  r9  	BuildFilerE   r\   rg   r  generator_outputabspathr  )
qualified_targetr   r)  rw   r  proj_filenamer  r  
fix_prefixproject_dir_pathrX   rX   rY   _GetPathOfProject  s    

r  c                 C   sV   i }| d   D ] \}}t||}|dt|}dt|t||f }|||< q|S )Nr   msvs_target_platformr   )r   r   rG   r   r   )r   config_platform_overridesr   r4  config_fullnamerB   fixed_config_fullnamerX   rX   rY   _GetPlatformOverridesOfProject  s   

r  c              
      s   i  | D ]I}|| }|d dkrt d| t||||\}at||}t|}tj|}	tj	||d |||	|td}
|
 rI|
t||| |
 |< q  D ]}|jdso|jdg } fdd	|D }|| qR S )
aX  Create a MSVSProject object for the targets found in target list.

  Arguments:
    target_list: the list of targets to generate project objects for.
    target_dicts: the dictionary of specifications.
    options: global generator options.
    msvs_version: the MSVSVersion object.
  Returns:
    A set of created projects, keyed by target.
  r  r  z9Multiple toolsets not supported in msvs build (target %s)r  )r  r  r   r  r  re   r*   dependenciesc                    s   g | ]} | qS rX   rX   r  projectsrX   rY   rp   S  rq   z)_CreateProjectObjects.<locals>.<listcomp>)r   r  re   r  r  r8  r9  r  r  r   r   set_msbuild_toolsetr  valuesr   rG   set_dependencies)target_listtarget_dictsr)  rw   r  r   r  r  	overridesr  objr  depsrX   r  rY   _CreateProjectObjects'  sH   
	


r  c           
      C   s   |D ]g}|| }| drq| dd}d|d< | dsNtj|\}}}tj|}d}	|  ddkr9|	d	7 }	tjtj| d
 j	|t
| |	|d< | ds[|dddg|d< | dsi|ddddg|d< qdS )a  Initialize targets for the ninja flavor.

  This sets up the necessary variables in the targets to generate msvs projects
  that use ninja as an external builder. The variables in the spec are only set
  if they have not been set. This allows individual specs to override the
  default values initialized here.
  Arguments:
    params: Params provided to the generator.
    target_list: List of target pairs: 'base/base.gyp:base'.
    target_dicts: Dict of target properties keyed on target pair.
  r*   msvs_path_to_ninjaz	ninja.exeninjar+   $(Configuration)target_archx64_x64r)  r,   z-Cr   r  r-   z-tcleanN)rG   r8  r9  r  rE   r\   r  rg   r  toplevel_dirninja_generatorComputeOutputDir)
paramsr  r  r  r   path_to_ninjar  r   rF  r  rX   rX   rY   _InitNinjaFlavorX  s@   



r  c                 C   s   | di }t| dd}||d< | | d< tj ddddks1tj d	dddkr6d
| d< nd| d< tj	|dkrHd| d< dS dS )z4Generated variables that require params to be known.r  rw   autoMSVS_VERSIONPROCESSOR_ARCHITECTUREr   64r   PROCESSOR_ARCHITEW6432@   MSVS_OS_BITS    r  z$(OutDir)genr   N)
rG   r   SelectVisualStudioVersion	ShortNamerE   rF   r   r8  r9  	GetFlavor)default_variablesr  r  rw   rX   rX   rY   CalculateVariables  s   

r  c                 C   s   |d }|d }t j|jddd}|  D ]#\}}t j|\}}	|	dkr'q||j d }
|jr9t j|j|
}
q|D ]}||
d|g}td	||f  t	|}q<d S )
Nr)  rw   Common7IDEz
devenv.com.gyp.slnz/BuildzBuilding [%s]: %s)
rE   r\   rg   r   r  r!  r  r   rH   
check_call)datar   r  r)  rw   devenvr  build_file_dictbuild_file_rootbuild_file_extsln_pathr=   r   rtnrX   rX   rY   PerformBuild  s    r  c                 C   sH   |  ddkr"| d j}tjtj|t| d}||dad S d S )Nflavorr  r)  zgypfiles-msvs-ninja)toplevelqualified_out_dir)	rG   r  rE   r\   r]   rg   r  r  generator_filelist_paths)r  r  r  rX   rX   rY   CalculateGeneratorInputInfo  s   


r  c                 C   s  |d }|d }| di }t| |\} }t| |t\} }| ddkr,t|| | t }| D ]}|| }	|	d  D ]\}
}|t	|
| q=q1t
|}t| |||}g }| D ]}|ja|t|||| q\da|D ]G}|dsxqptj|d	 |j d
 }|jrtj|j|}tj| |}|tj||7 }t||| d}tj|||d|d}|  qp|rddt| }| ddrt |t!d|  dS dS )a  Generate .sln and .vcproj files.

  This is the entry point for this generator.
  Arguments:
    target_list: List of target pairs: 'base/base.gyp:base'.
    target_dicts: Dict of target properties keyed on target pair.
    data: Dictionary containing per .gyp data.
  r)  rw   r  r  r  r   Nr  r   r  )r~  F)ry  variantswebsitePropertiesr   zMissing input files:
r2  msvs_error_on_missing_sourcesz	Warning: )"rG   MSVSUtilShardTargetsInsertLargePdbShimsgenerator_default_variablesr  rE  r   r  r   r   r  r  re   extendr  r   rE   r\   r  r!  r  rg   r8  r9  BuildFileTargetsDeepDependencyTargetsr  FlatSolutionr  MSVSSolutionWriter   r   )r  r  r  r  r)  rw   r  configsr  r   r   r=   r  r  r  r  r  r  root_entriesslnerror_messagerX   rX   rY   GenerateOutput  sh   


r  c                 C   sp   g }g }t d||||| |r)dddddg| dg| g}tj|| ddd d	S tj| r6t|  d	S d	S )
aV  Generate the filters file.

  This file is used by Visual Studio to organize the presentation of source
  files into folders.

  Arguments:
      filters_path: The path of the file to be created.
      source_files: The hierarchical structure of all the sources.
      extension_to_rule_name: A dictionary mapping file extensions to rules.
  r   Projectz4.03http://schemas.microsoft.com/developer/msbuild/2003)ToolsVersionxmlns	ItemGroupTprettyr7   N)_AppendFiltersForMSBuildeasy_xmlWriteXmlIfChangedrE   r\   existsunlink)filters_pathsource_filesrule_dependenciesextension_to_rule_namefilter_groupsource_groupcontentrX   rX   rY   _GenerateMSBuildFiltersFile  s"   r  c              	   C   s   |D ]L}t |tjr2| s|j}nd| |jf }|dd|idt|jgg t||j|||| qt	|||\}}	|	d|ig}
| rI|
d| g ||
 qdS )a  Creates the list of filters and sources to be added in the filter file.

  Args:
      parent_filter_name: The name of the filter under which the sources are
          found.
      sources: The hierarchy of filters and sources to process.
      extension_to_rule_name: A dictionary mapping file extensions to rules.
      filter_group: The list to which filter entries will be appended.
      source_group: The list to which source entries will be appeneded.
  z%s\%sr   IncludeUniqueIdentifierN)
r   r   r   r  r   r  r  r  ry   _MapFileToMsBuildSourceType)parent_filter_namer   r  r  r  r  r_   filter_namer   elementsource_entryrX   rX   rY   r  3  s,   r  c                 C   s   t j| \}}||v rd}|| }||fS |dv r"d}d}||fS |dv r.d}d}||fS |dkr:d	}d
}||fS |dkrFd}d}||fS |dkrRd}d}||fS | |v r^d}d}||fS d}d}||fS )a  Returns the group and element type of the source file.

  Arguments:
      source: The source file name.
      extension_to_rule_name: A dictionary mapping file extensions to rules.

  Returns:
      A pair of (group this file should be part of, the label of element)
  r   )r  r  r  r  rM   	ClCompile)z.hz.hxxinclude	ClIncludez.rcresourceResourceCompilez.asmmasmMASMrI  midlMidlrule_dependencyCustomBuildr  None)rE   r\   r  )r_   r  r  r   r  rP   r  rX   rX   rY   r  Z  s@   
r  c
                 C   s,  | dg }
dd |
D }dd |
D }g }|D ]&}d|vr%| dg s%qt||}|| ||jd |j|	|j< q|r|d |j }|d	 }|d
 }|d }|	| |	| t
j| |}t
j| |}t
j| |}t|| t|| t|| |rt|| |||| t|
||d d S )Nr'  c                 S   rl  rm  ro  rp  rX   rX   rY   rp     rq  z,_GenerateRulesForMSBuild.<locals>.<listcomp>c                 S   rr  rm  ro  rp  rX   rX   rY   rp     rq  r   r  r   r  z.propsz.targetsz.xmlT)rG   MSBuildRuler   r  r   r  r  r  r!  r  rE   r\   rg   _GenerateMSBuildRulePropsFile_GenerateMSBuildRuleTargetsFile_GenerateMSBuildRuleXmlFilerG  rs  )r(  r)  r   r   rt  props_files_of_rulestargets_files_of_rulesr=  r  r  r'  ru  rv  msbuild_rulesr   msbuild_rulebase
props_nametargets_namexml_name
props_pathtargets_pathxml_pathrX   rX   rY   _GenerateRulesForMSBuild  s:   	






r  c                   @   s   e Zd ZdZdd ZdS )r  a-  Used to store information used to generate an MSBuild rule.

  Attributes:
    rule_name: The rule name, sanitized to use in XML.
    target_name: The name of the target.
    after_targets: The name of the AfterTargets element.
    before_targets: The name of the BeforeTargets element.
    depends_on: The name of the DependsOn element.
    compute_output: The name of the ComputeOutput element.
    dirs_to_make: The name of the DirsToMake element.
    inputs: The name of the _inputs element.
    tlog: The name of the _tlog element.
    extension: The extension this rule applies to.
    description: The message displayed when this rule is invoked.
    additional_dependencies: A string listing additional dependencies.
    outputs: The outputs of this rule.
    command: The command used to run the rule.
  c                 C   s   |d | _ tdd| j | _d| j | _| jd | _| jd | _| jd | _d| j | _| jd | _	| jd	 | _
| jd
 | _|d | _| jdsOd| j | _t|d| j| _t|dg }ddd |D | _t|dg }ddd |D | _t||ddd}t|| _d S )Nr  z\Wr   AfterTargetsBeforeTargets	DependsOnzCompute%sOutput
DirsToMake_inputs_tlogr  r   r  r   r   c                 S   r   rX   r   ConvertVCMacrosToMSBuildrm   rX   rX   rY   rp         z(MSBuildRule.__init__.<locals>.<listcomp>r   c                 S   r   rX   r!  rm   rX   rX   rY   rp     r#  Tr  )display_namerL   rR  r  r  after_targetsbefore_targets
depends_oncompute_outputdirs_to_maker   tlogr  r   r   r"  rG   r   rs   rg   r   r   r   r   )selfr   r   old_additional_dependenciesold_outputsold_commandrX   rX   rY   __init__  s:   




zMSBuildRule.__init__N)__name__
__module____qualname____doc__r/  rX   rX   rX   rY   r    s    r  c                 C   s   dddig}|D ];}| ddd|j|jf i|jdg|jdggd|jdd	id
|j ggd|jd|jgd|jgd|jgd|jgggg qt	j
|| ddd dS )zGenerate the .props file.r  r  r  PropertyGroup	ConditionzH'$(%s)' == '' and '$(%s)' == '' and '$(ConfigurationType)' != 'Makefile'r  r	  z$'$(ConfigurationType)' != 'Makefile'z_SelectedFiles;$(%s)ItemDefinitionGroupCommandLineTemplater   ExecutionDescriptionr   Tr  N)r  r&  r%  r'  r  r   r   r   r   r  r  )r  r  r  r   rX   rX   rY   r    s<   r  c                 C   s  dddig}ddddigg}|D ]}| dd|jid	|jgg q| | |D ]}| d
|jdddddgg q(|D ]}|j}d| }d||f }d| }d}	dddi|d| ddgg}
d|jdd| igg}d|jd| d||f ddd| gdd|j ggg}dd d!| d"g}d#d$|j|jf d%d&|j|jf d'g}d#d$|j|jf d(d)|j|jf d'g}|d$||f d*d d d+| d,| |d-g}|d.|jd/|j d/|j d0| d1|j|j	f ||d2|
||||||g	d3d4d5d6|j	 gd7d8d6|j	 ggd.|j	d0| d9d|j
d$||f d| d:gd;d|j
 |	dgd<d|j
 |	dgd=d|j
 |	dggd>d?d@|j
 iggg q<tj|| dAdAdB dCS )DzGenerate the .targets file.r  r  r  r  PropertyPageSchemar  z5$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xmlAvailableItemNameTargets	UsingTaskXamlTaskFactoryzMicrosoft.Build.Tasks.v4.0)TaskNameTaskFactoryAssemblyNameTaskz%%(%s.Outputs)zC%%(%s.Identity);%%(%s.AdditionalDependencies);$(MSBuildProjectFile)z%%(%s.Identity)zd'%(Extension)'=='.obj' or '%(Extension)'=='.res' or '%(Extension)'=='.rsc' or '%(Extension)'=='.lib'r5  z'@(SelectedFiles)' != ''z@(%s)z#'%(Identity)' != '@(SelectedFiles)')Remover5  z%%(%s.AdditionalDependencies)z?'%%(%s.Outputs)' != '' and '%%(%s.ExcludedFromBuild)' != 'true')r  r5  Sourcez
@(%s, '|')Inputsz@(%s -> '%%(Fullpath)', ';')MessageHighz%%(%s.ExecutionDescription))
ImportanceTextWriteLinesToFilez6'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != 'true'z$$(IntDir)$(ProjectName).write.1.tlogz$^%%(%s.Source);@(%s->'%%(Fullpath)'))r5  FileLinesz#$(IntDir)$(ProjectName).read.1.tlogz^%%(%s.Source);%%(%s.Inputs)r  z%%(%s.CommandLineTemplate)z%%(%s.AdditionalOptions))r5  EchoOffStandardOutputImportanceStandardErrorImportancer7  r$  rD  Targetz$(%s)z'@(%s)' != ''z$(%s);%s)Namer  r  r5  DependsOnTargetsr   rD  r4  ComputeLinkInputsTargetsz$(ComputeLinkInputsTargets);z%s;ComputeLibInputsTargetsz$(ComputeLibInputsTargets);)rP  r5  )r5  r  r  r
  ImpLibMakeDirr   z!@(%s->'%%(RootDir)%%(Directory)')Tr  N)r   r  r  r   r*  r  r&  r%  r'  r(  r)  r  r  )r  r  r  
item_groupr   r  target_outputstarget_inputsrule_inputsextension_conditionremove_sectioninputs_sectionlogging_sectionmessage_sectionwrite_tlog_sectionread_tlog_sectioncommand_and_input_sectionrX   rX   rY   r  	  s:  





		
?r  c                 C   s  ddddddg}|D ]}| d|jd|jd	d
ddd|jdggddddidddgggdddddddggggddddddddd|jddgggd d!dd"d"d#gd$|jdd%d"d&d'dd(ggd)dd*ggd+d,d-d.|j d/ggd0dddd1gggd$|jdd%d"d&d'dd2ggd)dd3ggd+d,d-d.|j d/ggd0ddd4dd5gggdd6d6d"d"d#gd d7d8d"d"d#gdd9d:d"d;d<gd d=d=dd>d?dd@ggdAdd@ggggdB|j|jdCgdDdE|j |jdFgdG|jd4|jdHgg qtj|| dIdIdJ d S )KNProjectSchemaDefinitionszTclr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Frameworkz,http://schemas.microsoft.com/winfx/2006/xamlz&clr-namespace:System;assembly=mscorlibz+Microsoft.Cpp.Dev10.ConvertPropertyCallback)r  zxmlns:xz	xmlns:syszxmlns:transformCallbackRuler   200)rP  PageTemplateDisplayNameOrderzRule.DataSource
DataSourceProjectFile)PersistenceItemTypezRule.CategoriesCategoryrP  GeneralzCategory.DisplayNamez
sys:StringzCommand Liner   )rP  SubtypeStringListPropertyrD  r  r   )rP  rl  
IsRequiredSwitchzStringListProperty.DataSourceItem)rj  rk  
SourceTypeStringPropertyr7  False)rP  rf  VisibleIncludeInCommandLineDynamicEnumPropertyr;  )rP  rl  EnumProviderrw  zDynamicEnumProperty.DisplayNamezExecute BeforezDynamicEnumProperty.Descriptionz@Specifies the targets for the build customization to run before.z$DynamicEnumProperty.ProviderSettingsNameValuePairExcludez^%s|^Compute)rP  ValuezDynamicEnumProperty.DataSource)rj  HasConfigurationConditionzExecute Afterz?Specifies the targets for the build customization to run after.r   )rj  rk  r}  r   r8  zExecution Descriptionr   zAdditional Dependenciesfalse)rP  rf  rw  rv  r$  )rn  rP  rl  zStringProperty.DisplayNamezAdditional OptionszStringProperty.Descriptionrk  )rP  rf  FileExtensionrg  )rP  ContentTyper  )rP  rf  rk  Tr  )r  r  r$  r&  r%  r  r  r  )r  r  r  r   rX   rX   rY   r  	  sV  
    #r  c                 C   s$   |  ddd }|dd}||fS )Nr   r@   r   r   r   )rsplitrG   )r  r   r  rB   rX   rX   rY   _GetConfigurationAndPlatformZ
  s   r  c                 C   s   dt | | S )Nz''$(Configuration)|$(Platform)'=='%s|%s')r  )r  r   rX   rX   rY   _GetConfigurationCondition`
  s   r  c                 C   s`   dddig}t |  D ] \}}t||\}}d||f }|dd|id|gd|gg q|gS )	Nr  LabelProjectConfigurationsr   ProjectConfigurationr  ConfigurationPlatform)r   r   r  r   )r   rP   r  r   r  rB   designationrX   rX   rY    _GetMSBuildProjectConfigurationse
  s   r  c                 C   s  t j|d }dddid|gddgd|gd	d
ggg}t jddks+t jddkr4|d ddg | drd| d}|d d|g | dr[| d}|d d|g n	|d d|g | dr|d ddg |d dd
g | dr| d}|d d|g n	|d ddg | dr|d ddg n	|d ddg d }	d }
| d  D ]}|	pt|}	|
pt||}
|	r|
r nq|
r|d dt	|
g n|j
rtd |j|j
f |	d!kr|d d"d
g |S )#Nr   r4  r  GlobalsProjectGuidKeyword	Win32ProjRootNamespace#IgnoreWarnCompileDuplicatedFilenamer  r  AMD64r  PreferredToolArchitecturer  r3   WindowsTargetPlatformVersionr4   WindowsTargetPlatformMinVersionr/   DefaultLanguagezen-USAppContainerApplicationr2   ApplicationTypeRevisionz8.1r1   ApplicationTypezWindows PhonezWindows Storer   z6%s requires any SDK of %s version, but none were foundARMWindowsSDKDesktopARMSupport)rE   r\   r  rF   rG   r   r  r   r   r   r   r   r   )r   r   r  gyp_file_name	namespace
propertiestarget_platform_versiontarget_platform_minversionapp_type_revisionr   r   r  rX   rX   rY   _GetMSBuildGlobalPropertiesq
  sn   	












r  c           	      C   s   i }| d   D ]A\}}t| ||}t||}|d}|d}t||d| |dkr<t||dd t||dt| |rId| vrIt||d| qt| d	|S )
Nr   CharacterSetr.  Driver
DriverTypeWDMTargetVersionr/   r  )r   _GetMSBuildAttributesr  rG   _AddConditionalPropertyr   _GetMSBuildPropertyGroup)	r   r  r  r  r   msbuild_attributes	conditioncharacter_setr  rX   rX   rY   _GetMSBuildConfigurationDetails
  s*   


r  c                 C   s    i }| rdddid| ggg}|S )Nr4  r  LocalsPlatformToolsetrX   )r  r  rX   rX   rY   _GetMSBuildLocalProperties
  s   r  c                 C   s   d}i }d}t |  D ]\}}t||}d|v r$t|d ||< d}qd||< q|s;dddid	|d
| ddgggS g }| D ]'\}}	dd|dd	|d
| ddgg}
|	D ]}|
d	d|ig qW||
 qA|S )Nz3$(UserRootDir)\Microsoft.Cpp.$(Platform).user.propsFmsbuild_propsTr   ImportGroupr  PropertySheetsImportzexists('%s')LocalAppDataPlatform)r  r5  r  )r  r5  r  )r   r   r  rs   r   )r   
user_propsadditional_propsprops_specifiedr  r   r  sheetsr  propsimport_group
props_filerX   rX   rY   _GetMSBuildPropertySheets
  sJ   

r  c                 C   s   t | |}t| ||}i }|D ];}|dv r*t|| }|ds%|d7 }|||< q|dkr7t|| ||< q|dkrDt|| ||< qtd|  q|S )N)r0  r/  rc   r  r.  z3Warning: Do not know how to convert MSVS attribute )r  r)  r   r"  r   _ConvertMSVSCharacterSet_ConvertMSVSConfigurationTyper   )r   r=   r  r  msvs_attributesr  r3  	directoryrX   rX   rY   _ConvertMSVSBuildAttributes
  s   


r  c                 C   s   |   rdddd|  } | S )N	MultiByteUnicode)rV  r  r  isdigit)char_setrX   rX   rY   r    s   r  c                 C   s    |   rdddddd|  } | S )NApplicationDynamicLibraryStaticLibraryr  Utility)r  r  r  r  r  r  )r  rX   rX   rY   r    s   r  c                 C   sr  d|vrt | ||}n=t| |}t|}|di }|d| |dd}t|d |d< d|vr<tdd }||d< d|v rHt|d |d< d	|vr`| d
d}| dd}|| }	|	|d	< d|vrsd| v rs| d}
d|
 |d< | dr| dd}t|d |d< dddddd}|| d }|r|d }|| d}|rt||d< || d}|r||d< |S )N msbuild_configuration_attributesr.  r/  z$(SolutionDir)$(Configuration)rc   r0  r  r  
TargetNamer  r   r  r  	TargetExtr  r   r*   r+   r  r
  r  r   finalized_msbuild_settingsr  
TargetPath)r  r  r  rG   r  rj   r  )r   r=   r  r  r  r(  r5  r{   r  r  r  external_out_dirmsbuild_tool_mapr  msbuild_settingsr  
target_extrX   rX   rY   r  #  sX   


r  c                 C   sr  g }|  ddgd }|r,dt| }|| |dd}|| |r,dd| }i }t| D ]~\}}	t||	}
t| |	|}|	d	 }t	||
d
|d  t	||
d|d  t	||
d|d  d|v rot	||
d|d  | dr}t	||
d|d  | drt	||
d|d  |rt	||
d| | di }t| D ]\}}t
d||}t	||
|| qq4t| d |S )Nr%   r   r   z"$(MSBuildProjectDirectory)\%s\bin\z
cygwin\bin	python_26z$(ExecutablePath);r   r  IntDirr0  OutDirr/  r  r  r  ExecutablePathr   )rG   rj   r   rh   rg   r   r   r  r  r  _GetValueFormattedForMSBuildr  )r   r   r  	new_pathscygwin_dirscyg_pathpython_pathr  r  r  r  r+  r  tool_settingsr   formatted_valuerX   rX   rY   (_GetMSBuildConfigurationGlobalPropertiesX  sZ   




r  c                 C   s>   || vri | |< | | }||vrg ||< || }| | dS )a  Adds a property / conditional value pair to a dictionary.

  Arguments:
    properties: The dictionary to be modified.  The key is the name of the
        property.  The value is itself a dictionary; its key is the value and
        the value a list of condition for which this value is true.
    condition: The condition under which the named property has the value.
    name: The name of the property.
    value: The value of the property.
  Nr   )r  r  r  r   r  
conditionsrX   rX   rY   r    s   r  z\$\(([a-zA-Z_][a-zA-Z0-9_]*)\)c                    s   dg}|r| d|i t| d } fdd}tj  |}t|D ].} | }t| D ]!\}	}
t|
|krC| ||	g q1|
D ]}| |d|i|	g qEq1q%|gS )a  Returns a PropertyGroup definition for the specified properties.

  Arguments:
    spec: The target project dict.
    label: An optional label for the PropertyGroup.
    properties: The dictionary to be converted.  The key is the name of the
        property.  The value is itself a dictionary; its key is the value and
        the value a list of condition for which this value is true.
  r4  r  r   c                    sD   t  }t   D ]}|t  fddt|D  q|S )Nc                    s    g | ]}|v r| kr|qS rX   rX   )rn   v)r  r  rX   rY   rp     s    z>_GetMSBuildPropertyGroup.<locals>.GetEdges.<locals>.<listcomp>)rE  r   r  r  MSVS_VARIABLE_REFERENCEfindall)r  edgesr   r  )r  rY   GetEdges  s   &	z*_GetMSBuildPropertyGroup.<locals>.GetEdgesr5  )	r   r~   r8  r9  TopologicallySortedr  r  r   r   )r   labelr  rP   num_configurationsr  properties_orderedr  r  r   r  r  rX   r  rY   r    s$   
r  c                 C   s   g }t | D ]E\}}|d }ddt||ig}t | D ](\}}|rG|rG|g}	t | D ]\}}
t|||
}|	||g q0||	 q|| q|S )Nr  r6  r5  )r   r   r  r  r   )r   r   groupsr  r  r  rP   r   r  r   r   r  rX   rX   rY   _GetMSBuildToolSettingsSections  s&   
r  c                 C   sv  d|v rd}|d }t | nd}|di }t |}t|\}}}t| }t|}	t| dd\}
}}t| }t	|}|r_dd |D }dg}|D ]}||}|r^t
d	|t|f  qKd
d |D }t|}|d}|d}t| }|d}t|dd| t|dd| t|dd| t|dd| t|dd|	 |
rt||d|
dd |rt||d|dd t|dd| t|dd| t|dd| |rtj|d }t|ddd t|dd| t|dd|g nt|ddd t|dd d! | d"rt|d#d$d! | d% d&krt|d#d$d' |rt|dd(| ||d)< |r-t|d*d+| |r9t|d,d+| d S d S )-Nr  FTr  r  c                 S   s   g | ]}|d kr|qS )z
_HAS_TR1=0rX   r  rX   rX   rY   rp     r   z,_FinalizeMSBuildSettings.<locals>.<listcomp>rS  zXWarning: The automatic conversion to MSBuild does not handle %s.  Ignoring setting of %sc                 S   rk   rX   )rk  r  rX   rX   rY   rp     rq   r  r  r5   r  r  r  r  r  r   r  r  r  r  r  r  r@   PrecompiledHeaderUsePrecompiledHeaderFiler  NotUsingr   r~  r0   r   r  r   r  r  r  r  PreBuildEventCommandPostBuildEvent)r   ValidateMSBuildSettingsrG   ConvertToMSBuildSettingsr  r  r  r  r  r  r   r   r  r  r   r   rE   r\   r  )r   r  	convertedr  r  r  r  r  r  r  r  r   r  r  r  ignored_settingsignored_settingr   r  r  r  r  r  rX   rX   rY   _FinalizeMSBuildSettings  s   







r  c                 C   sx   t |tkr5|dv r|d|  dgdgdgd}| |v r'|||  v r'd}nd}|dd |D }|S t|}|S )	N)r  r  r$  DelayLoadDLLsr  r  z%%(%s)r$  )r  r  r
  r   r   c                 S   r   rX   r!  rm   rX   rX   rY   rp   [  r   z0_GetValueFormattedForMSBuild.<locals>.<listcomp>)r   r   r   rg   r   r"  )r   r  r   
exceptionscharr  rX   rX   rY   r  E  s    
r  c                 C   s^   g }| D ](}t |tjr|t|j| qd|vr,tj||}tj	|s,|
| q|S )a  Verifies that all source files exist on disk.

  Checks that all regular source files, i.e. not created at run time,
  exist on disk.  Missing files cause needless recompilation but no otherwise
  visible errors.

  Arguments:
    sources: A recursive list of Filter/file names.
    root_dir: The root directory for the relative path names.
  Returns:
    A list of source files that cannot be found on disk.
  r[   )r   r   r   r  r  ry   rE   r\   rg   r  r   )r   root_dirr  r_   	full_pathrX   rX   rY   r  a  s   
r  c              	   C   sv   g d}i }	|D ]}
g |	|
< qt | |||	|||| g }|D ]}
|	|
 r.|dg|	|
   q|r9|dg|  |S )N)r  r  r  r   rM   r  r   r  r  )_AddSources2r   )r   r   rO  r  r  actions_specsources_handled_by_actionrv   r  grouped_sourcesgrX   rX   rY   _GetMSBuildSourcesz  s    

r  c              
   C   s  g }|D ]}	t |	tjrt| |	j|||||| q|	|vrg }
||	g }t|t| d kr7|
ddg nt|D ]\}}t	||}|
dd|idg q;| d 
 D ]T\}}|dd}|dkr}t|}|s}tj|\}}|dkrzg d}ndg}||	krt	||}|
d	d|id
g qU|D ]}|	|r|
d	dg |
ddg qqUt|	||\}}|| |d|	ig|
  qd S )Nr   rM  r  r5  r6   r   r  rU  r  Creater  r  )r   r   r   r   ry   rG   r~   r   r   r  r   rj   rE   r\   r  r   r  )r   r   rO  r  r  r  r  rv   rZ  r_   detailexcluded_configurationsr   r  r  precompiled_sourcer  r  rP   r  rX   rX   rY   r     s\   



r   c           	      C   s   g }| j rbdg}| j D ]Q}|j}tj| jd }tj|j|}dd|id|gddgg}|j	di 
 D ] }|	d	drG|d
dg  n|	ddrV|d
dg  nq6|| q|| |S )Nr  r   ProjectReferencer  r  ReferenceOutputAssemblyr~  r   "msvs_use_library_dependency_inputsUseLibraryDependencyInputsr  &msvs_2010_disable_uldi_when_referenced)r  r  rE   r\   r  r8  r9  r  r   rG   r  r   )	r  
referencesrP   
dependencyr  r  relative_pathproject_refr=   rX   rX   rY   _GetMSBuildProjectReferences  s.   

r  c           !      C   s  | j }|d }tj| j\}}tj| j t| j}tj	||}	tj| jd }
t
|||
\}}i }t }t }t }i }|dd}|dsZt||||||||||
 n|dg }t|||d t|||||||\}}}|dst||| j t|| t||}t|||}t||\}}t| jd ||| t||}| D ]}t|| qdd	d
igg}dd	digg}dd	digg}dd	digg}dd	digg}dddigg}d	d| ddg} | t|7 } | t||| j|7 } | |7 } | t|| j7 } |dr| td7 } n| t| j7 } | |7 } | |7 } | t |7 } | t!|7 } | |7 } | t"||| j7 } | t#||7 } | t$||||||||7 } | t%| 7 } | |7 } | |7 } | t&|7 } |drk| t'|7 } t(j)| | jddd |S )Nr   r@   r  Tr*   r'  z.filtersr  r  z,$(VCTargetsPath)\Microsoft.Cpp.Default.propsz$$(VCTargetsPath)\Microsoft.Cpp.propsz&$(VCTargetsPath)\Microsoft.Cpp.targetsz/$(VCTargetsPath)\BuildCustomizations\masm.propsz1$(VCTargetsPath)\BuildCustomizations\masm.targetsr4  r  
UserMacrosr  Build)r  r  DefaultTargetsr1   	v120_wp81r  )*r   rE   r\   r  r8  r9  r  ra   r  r  r  rE  rG   r  rs  r  r  r  r  rN  _GenerateActionsForMSBuildr  r  r  r  ProjectVersionr  r  r  r  r  r  _GetMSBuildExtensionsr  r  r  r  r  _GetMSBuildExtensionTargets!_GetMSBuildExternalBuilderTargetsr  r  )!r  r)  r   r  r   r   r  project_file_namer  r  r  r   rt  r=  r  r  r  r  rv   r'  r  rO  r  r  r  r  import_default_sectionimport_cpp_props_sectionimport_cpp_targets_sectionimport_masm_props_sectionimport_masm_targets_sectionmacro_sectionr  rX   rX   rY   r    s   








r  c                 C   s   t | | d dddd}dddig}|dd|ig t | | d dddd}ddd	ig}|dd|ig ||g}| d
r\t | | d
 dddd}dddig}|dd|ig || |S )an  Return a list of MSBuild targets for external builders.

  The "Build" and "Clean" targets are always generated.  If the spec contains
  'msvs_external_builder_clcompile_cmd', then the "ClCompile" target will also
  be generated, to support building selected C/C++ files.

  Arguments:
    spec: The gyp target spec.
  Returns:
    List of MSBuild 'Target' specs.
  r,   FrO  rP  r  Execr  r-   Cleanr.   r  )r   r   rG   )r   	build_cmdbuild_target	clean_cmdclean_targettargetsclcompile_cmdclcompile_targetrX   rX   rY   r  X  s,   

r  c                 C   s.   dddig}| D ]}| dd|ig q|gS )Nr  r  ExtensionSettingsr  r  r   )r  r  r  rX   rX   rY   r  }  s   r  c                 C   s2   dddig}t | D ]}|dd|ig q
|gS )Nr  r  ExtensionTargetsr  r  )r   r   )r  targets_nodetargets_filerX   rX   rY   r    s   r  c              
   C   s   t  }g }| D ]Y\}}t  }t  }g }g }	|D ].}
|t |
d  |t |
d  ||
d  |
d }|
ddrBd| }|	| qd|}d	d
d |	D }t| ||||||| q	||fS )aY  Add actions accumulated into an actions_to_add, merging as needed.

  Arguments:
    spec: the target project dict
    actions_to_add: dictionary keyed on input name, which maps to a list of
        dicts describing the actions attached to that input file.

  Returns:
    A pair of (action specification, the sources handled by this action).
  r   r   r   r   msbuild_use_callTzcall r  r  c                 S   s   g | ]}|d  qS )z,
if %errorlevel% neq 0 exit /b %errorlevel%rX   r3  rX   rX   rY   rp     s    z._GenerateActionsForMSBuild.<locals>.<listcomp>)r   r   r  r   rG   rg   _AddMSBuildAction)r   r=  r  r  r  r<  r   r   r	  r
  r   r   r   r   rX   rX   rY   r    s:   

r  c                    s   t |}t  t|}	t|}
d fdd|	D }d|
}|  dd ig}|ddgd|gd	|gd
|gg |rG|d|g || d S )Nr   c                    s   g | ]}| kr|qS rX   rX   rm   r  rX   rY   rp     s    z%_AddMSBuildAction.<locals>.<listcomp>r	  r  FileTypeDocumentr  rE  r   AdditionalInputs)r   r"  rj   rs   rg   r  r  r   )r   r  r   r   r   r   r  r  r   inputs_arrayoutputs_arrayadditional_inputsaction_specrX   r3  rY   r2    s$   


r2  )NNTN)F)
__future__r   r|   copyr  rE   rh  rL   rH   rA   
gyp.commonr8  gyp.easy_xmlr  gyp.generator.ninja	generatorr  r  gyp.MSVSNewr  gyp.MSVSProjectr   gyp.MSVSSettingsr   gyp.MSVSToolFiler"  gyp.MSVSUserFiler  gyp.MSVSUtilr  gyp.MSVSVersionr   r   r   rM   r  r  "generator_additional_path_sections+generator_additional_non_configuration_keysr  rK  rD   rC   rZ   re   ra   rj   rs   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r.  r/  rG  rJ  rQ  rT  rW  rZ  r_  rb  rc  rj  rk  rw  rs  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  rB  rC  r  rN  r  r  r  r  r  re  rr  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  objectr  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  r  r  r  r2  rX   rX   rX   rY   <module>   s  
	
AK#&Q

/
#FW''6
'10Q''-5  & 3=,
50
2
]9v%2