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\-]+$ZDRIVER_PREFIX ZDRIVER_SUFFIX.sysZEXECUTABLE_PREFIXZEXECUTABLE_SUFFIX.exeZSTATIC_LIB_PREFIXZSHARED_LIB_PREFIXZSTATIC_LIB_SUFFIX.libZSHARED_LIB_SUFFIX.dllZINTERMEDIATE_DIR	$(IntDir)SHARED_INTERMEDIATE_DIRz $(OutDir)obj/global_intermediateZOSwinZPRODUCT_DIR	$(OutDir)ZLIB_DIRz$(OutDir)libZRULE_INPUT_ROOT$(InputName)ZRULE_INPUT_DIRNAME$(InputDir)ZRULE_INPUT_EXT$(InputExt)ZRULE_INPUT_NAME$(InputFileName)$(InputPath)z$(ConfigurationName))ZRULE_INPUT_PATHZCONFIGURATION_NAMEmsvs_cygwin_dirs
msvs_props)r   msvs_cygwin_shellZmsvs_large_pdbZ
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)ZDOMAINUSERNAMEZ
USERDOMAINr%   )ZnetconfigZWorkstation)stdoutr   z^User name\s+(\S+)   z^Logon domain\s+(\S+))sysplatformcached_domaincached_usernameosenvironget
subprocessPopenPIPEZcommunicaterecompile	MULTILINEsearchgroup)domainusernamecallr&   Zusername_reZusername_matchZ	domain_reZdomain_match r;   4/usr/lib/python3/dist-packages/gyp/generator/msvs.py_GetDomainAndUserNamel   s*   





r=   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.
  $)r-   pathnormpathcount)sourceZ
normalizedr;   r;   r<   _NormalizedSource   s   rC   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_prefixr-   r?   isabsjoinreplacerC   r?   r;   r;   r<   _FixPath   s    rL   c                 C   s   dd | D S )z"Fix each of the paths of the list.c                 S      g | ]}t |qS r;   rL   .0ir;   r;   r<   
<listcomp>       z_FixPaths.<locals>.<listcomp>r;   )pathsr;   r;   r<   	_FixPaths   s   rU   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(   rE   r   Nexcludedlist_excludedmsvs_versioncontentsZ_excluded_files)prefixrW   rX   rY   )collectionsOrderedDictlenrC   rI   appendUsesVcxprojr/    _ConvertSourcesToFilterHierarchyMSVSProjectFilter)sourcesr\   rW   rX   rY   resultZexcluded_resultZfolderssfilenamer[   Zexcluded_folderfr;   r;   r<   rb      sJ   
rb   Fc                 C   s   |sd S t | |||| d S N)_ToolSetOrAppend)tools	tool_namesettingvalueonly_if_unsetr;   r;   r<   _ToolAppend   s   rq   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DirectoriesZDependenciesrD   rE   c                 S      g | ]}| d dqS )rD   rE   rJ   rO   r;   r;   r<   rR          z$_ToolSetOrAppend.<locals>.<listcomp>CompileAsWinRTzZAppending "%s" to a non-list setting "%s" for tool "%s" is not allowed, previous value: %s)typestrrJ   r/   dictlist	TypeError)rl   rm   rn   ro   rp   toolr;   r;   r<   rk      s(   


rk   c                 C      |  ddS )NZmsvs_target_versionZWindows7r/   config_datar;   r;   r<   _ConfigTargetVersion     r   c                 C   r}   )Nmsvs_configuration_platformWin32r~   r   r;   r;   r<   _ConfigPlatform  r   r   c                 C   s(   |  d| r| dt| d  S | S )N_r   r(   )endswithr_   )config_nameplatform_namer;   r;   r<   _ConfigBaseName  s   r   c                 C   s   t |}dt| ||f S )N%s|%s)r   r   )r   r   r   r;   r;   r<   _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\%sZInstallationFolderZProductVersionr   z
%s\includec                    s   g | ]	}|  r|qS r;   )
startswithrP   xversionr;   r<   rR   /  s    
z7_ConfigWindowsTargetPlatformVersion.<locals>.<listcomp>T)reverser   zCWarning: No include files found for detected Windows SDK version %s)
r/   compatible_sdksMSVSVersionZ_RegistryGetValuesortedr-   r?   isdirlistdirprint)	r   r   Z
config_verZversZverkeyZsdk_dirZexpected_sdk_dirnamesr;   r   r<   #_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   r;   r   r;   r;   r<   rR   >  ru   z/_BuildCommandLineForRuleRaw.<locals>.<listcomp>z_set INPUTDIR=$(InputDir)
if NOT DEFINED INPUTDIR set INPUTDIR=.\
set INPUTDIR=%INPUTDIR:~0,-1%
r   r   .r   c                 S   rs   )r
   z`cygpath -m "${INTDIR}"`rt   rO   r;   r;   r<   rR   L  
    c                 S   rs   )r   z`cygpath -m "${OUTDIR}"`rt   rO   r;   r;   r<   rR   N  r   c                 S   rs   )r   z`cygpath -m "${INPUTDIR}"`rt   rO   r;   r;   r<   rR   P  r   c                 S   rs   )r   z`cygpath -m "${INPUTPATH}"`rt   rO   r;   r;   r<   rR   S  s
    c                 S   s   g | ]
}d | dd qS )z\"%s\""z\\\"rt   rO   r;   r;   r<   rR   V       z4call "$(ProjectDir)%(cygwin_dir)s\setup_env.bat" && zset CYGWIN=nontsec&& ZNUMBER_OF_PROCESSORSz@set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& ZINTDIRzset INTDIR=$(IntDir)&& ZOUTDIRzset OUTDIR=$(OutDir)&& Z	INPUTPATHzset INPUTPATH=$(InputPath) && zbash -c "%(cmd)s")
cygwin_dircmdcatrw   rD   rE   r:   c                 S   s(   g | ]}|d d dv r|nt |qS )Nr(   z/-rN   rO   r;   r;   r<   rR   z  s   ( r(   c                 S   rs   )r   z
%INPUTDIR%rt   rO   r;   r;   r<   rR   {  ru   c                 S      g | ]}t |qS r;   )MSVSSettingsFixVCMacroSlashesrO   r;   r;   r<   rR   |      c                 S      g | ]}d | qS z"%s"r;   rO   r;   r;   r<   rR     rS   )rL   r/   rI   findrJ   insert)specr   Zcygwin_shellhas_input_path	quote_cmddo_setup_envZinput_dir_preambler   Z
direct_cmdcommand	argumentsr;   r;   r<   _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(   Zmsvs_quote_cmdaction)r   )r/   int
isinstancerx   r   )r   ruler   r   Zmcsr   r;   r;   r<   _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   Zchosen_inputr;   r;   r<   _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
  ZVCCustomBuildTool;)ZDescriptionAdditionalDependenciesOutputsCommandLineconfigurationsrl   N)rU   rc   ToolrI   itemsAddFileConfigrL   r   )
pr   primary_inputr   r   r   r   r|   r   c_datar;   r;   r<   _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`   rI   r   )r   r   r   r   r   r   descriptionscommandsr   r   r   r;   r;   r<   _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   )rJ   r-   r?   splitextsplitdirname)r?   Z
input_filer;   r;   r<   _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   re   r;   r;   r<   _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   )rU   r/   r   addr   )r   trigger_fileZ
raw_inputsZraw_outputsr   r   rQ   or;   r;   r<   _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Writerr-   r?   rI   rU   r/   r   ZAddCustomBuildRuleWriteIfChangedAddToolFile)r   rules
output_dirr   optionsZrules_filenameZ
rules_filerr   Zrule_extr   r   r   r;   r;   r<   _GenerateNativeRulesForMSVS&  s2   

r   c                 C   s   |  dd} |  dd} | S )Nr   z$(OutDirCygwin)r
   z$(IntDirCygwin)rt   rK   r;   r;   r<   
_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   )r-   r?   r   rO   r;   r;   r<   rR   r  r   z*_GenerateExternalRules.<locals>.<listcomp>c                 S   rM   r;   r   rO   r;   r;   r<   rR   u  rS   zall: %s
r   z	mkdir -p `cygpath -u "%s"`

c                 S   rM   r;   r   rO   r;   r;   r<   rR     rS   c                 S   rM   r;   r   rO   r;   r;   r<   rR     rS   c                    s   g | ]}t | qS r;   )r   rP   cZtfr;   r<   rR     r   r   c                 S   r   r   r;   rO   r;   r;   r<   rR     rS   z%s: %s
z	%s

ZmakezOutDir=$(OutDir)zIntDir=$(IntDir)z-jz${NUMBER_OF_PROCESSORS_PLUS_1}z-fTFzRunning external rules for %sr   N)r   gypcommonZWriteOnDiffr-   r?   rI   writer   r   r   r   r`   rz   r   closer   r   r   rU   )r   r   r   re   r   actions_to_addrh   Zmk_fileZ
all_inputsZall_outputsZall_output_dirsZfirst_outputsr   trigger_filesr   r   Zoutput_dirsZodZfirst_outputs_cygr   r;   r   r<   _GenerateExternalRulesR  st   







r   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%%rt   rg   r;   r;   r<   #_EscapeEnvironmentVariableExpansion  s   r   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(   \"r7   matchr;   r;   r<   _Replace  s   z3_EscapeCommandLineArgumentForMSVS.<locals>._Replacer   )quote_replacer_regexsubrg   r  r;   r;   r<   !_EscapeCommandLineArgumentForMSVS  s   r	  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 )Nr   r(   r   r  r  r;   r;   r<   r    s    z5_EscapeVCProjCommandLineArgListItem.<locals>._Replacer   r   r   z;Warning: MSVS may misinterpret the odd number of quotes in )file)	r   ranger_   delimiters_replacer_regexr  rI   r   r)   stderr)rg   r  ZsegmentsrQ   r;   r;   r<   #_EscapeVCProjCommandLineArgListItem  s   

r  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)r   r	  r  rJ   ordr   r;   r;   r<   _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(   r      rE   r  )r_   r7   r  r;   r;   r<   r    s   z6_EscapeCommandLineArgumentForMSBuild.<locals>._Replace)quote_replacer_regex2r  r  r;   r;   r<   $_EscapeCommandLineArgumentForMSBuild  s   r  c                    s0   dddddddd d	  fd
d| D }|S )Nz%25z%24z%40z%27z%3Bz%3Fz%2A)r   r>   @'r   ?*r   c                    s   g | ]}  ||qS r;   r~   r   Zescape_dictionaryr;   r<   rR   )  ru   z3_EscapeMSBuildSpecialCharacters.<locals>.<listcomp>)rI   )rg   rf   r;   r  r<   _EscapeMSBuildSpecialCharacters  s   	r  c                 C   r  r  )r   r  r  rJ   r  r   r;   r;   r<   _EscapeCppDefineForMSBuild-  r  r  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   r/   rP   r   r;   r;   r<   rR   G       z)_GenerateRulesForMSVS.<locals>.<listcomp>c                 S       g | ]}t |d dr|qS r   r"  r#  r;   r;   r<   rR   H  r$  FN)r/   r   r   _AdjustSourcesForRules)
r   r   r   r   re   excluded_sourcesr   r   rules_nativerules_externalr;   r;   r<   _GenerateRulesForMSVS8  s   r*  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   discardrL   r   r/   r   r   rU   remover   )	r   re   r'  Z
is_msbuildr   r   r   r   r   r;   r;   r<   r&  U  s    



r&  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 r;   r;   rP   rg   Z	must_keepr;   r<   rR   u  ru   z._FilterActionsFromExcluded.<locals>.<listcomp>)r   rU   keys)r'  r   r;   r0  r<   _FilterActionsFromExcludedk  s   	r2  c                 C   s   | d | d  S )Nr   Zdefault_configurationr;   )r   r;   r;   r<   _GetDefaultConfigurationx  s   r3  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.
  Z	msvs_guidNz1Invalid MSVS guid: "%s".  Must match regex: "%s".z{%s})r3  r/   VALID_MSVS_GUID_CHARSr  
ValueErrorpatternMSVSNewMakeGuid)	proj_pathr   default_configguidr;   r;   r<   _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_toolsetrw   windows_driverzWindowsKernelModeDriver10.0)r3  r/   ZDefaultToolset)r9  r   r   r:  toolsetr;   r;   r<   _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)r3  r   r/   ra   _GenerateMSBuildProject_GenerateMSVSProject)projectr   r   generator_flagsr:  r;   r;   r<   _GenerateProject  s   

rF  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.
  rw   N)static_libraryshared_libraryre   ).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)ra   r/   r-   r?   r   basename
setdefaultr`   r   r_   rI   r   r   )r   r   re   Z	basenamesrB   r   extZis_compiled_filerM  errorfilesr;   r;   r<   _ValidateSourcesForMSVSProject  s6   rR  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   r   r   EnsureDirExistsr?   _GetUniquePlatformsrc   r   r;  r-   r   rC   
build_fileRelativePath_GetMSVSConfigurationTyper   _AddConfigurationToMSVSProjectrR  _PrepareListOfSourcesr*  r/   )_AdjustSourcesAndConvertToFilterHierarchy_VerifySourcesExistZAddFiles_AddToolFilesToMSVS_HandlePreCompiledHeaders_AddActions
_AddCopies_WriteMSVSUserFiler2  _ExcludeFilesFromBeingBuiltr   r   )rD  r   r   rE  r   	platformsr   project_dirgyp_pathrelative_path_of_gyp_fileconfig_typer   r&   gyp_filere   r'  r   rX   excluded_idlmissing_sourcesr;   r;   r<   rC    sX   	







rC  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   rz   )r   rc  configurationr;   r;   r<   rU  )  s
   	rU  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   )r=   rI   MSVSUserFiler   )r9  r   r   r8   r9   Zvcuser_filename	user_filer;   r;   r<   _CreateMSVSUserFile9  s   
ro  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)
executablerH  loadable_modulerG  r>  nonerw   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.)KeyErrorr/   r   )r   rV  rg  r;   r;   r<   rX  K  s(   

rX  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   rM   r;   )r  rP   dr;   r;   r<   rR     rS   z2_AddConfigurationToMSVSProject.<locals>.<listcomp>msvs_prebuildmsvs_postbuildr!   msvs_settingsVCLinkerToolr   $(NOINHERIT)VCCLCompilerToolAdditionalIncludeDirectoriesZ
VCMIDLToolZVCResourceCompilerToolAdditionalLibraryDirectories
OutputFileTrp   PreprocessorDefinitionsZProgramDataBaseFileNamez $(IntDir)$(ProjectName)\vc80.pdbDisableSpecificWarningsZVCPreBuildEventToolr   ZVCPostBuildEventToolr(   UsePrecompiledHeaderrq  ZPrecompiledHeaderThroughForcedIncludeFilesrw   rv  IgnoreImportLibrarytrueModuleDefinitionFileN)_GetIncludeDirs_GetLibraries_GetLibraryDirs_GetOutputFilePathAndTool_GetDefines_GetDisabledWarningsr/   _GetModuleDefinitionry   r   ZValidateMSVSSettingsrq   r-   r?   r   _AddConfigurationToMSVS)r   r   rg  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_headerrl   r  r|   settingsrn   r;   r;   r<   rY  j  s|   



rY  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  Zmsvs_system_include_dirsr  r  r/   rU   )r&   r  r  r  r;   r;   r<   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  r;   r;   r<   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   )r/   r   reversedr3   r  r-   r?   r   r   r`   r   )r   r  foundZunique_libraries_listentryZlibraryr;   r;   r<   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   )ZVCLibrarianToolLibz$(OutDir)lib\r   ru  rH  rv  r>  rG  rw   Zmsvs_auto_output_filer(   Zstandalone_static_libraryr   r   Zproduct_dirproduct_extensionr   z$(TargetExt)product_prefixproduct_name$(ProjectName))r/   r   ntpathrI   )r   rz  r  r  msbuild_toolZoutput_file_mapZoutput_file_propsZout_dirr   r  r\   r  r;   r;   r<   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   Ztarget_extensionr;   r;   r<   _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   rM   r;   rx   )rP   Zdpartr;   r;   r<   rR   G  rS   z_GetDefines.<locals>.<listcomp>)r/   rw   rz   rI   rx   r`   )r&   r  r|  fdr;   r;   r<   r  ;  s   	r  c                 C   s   dd |  dg D S )Nc                 S   rM   r;   r  rO   r;   r;   r<   rR   O  rS   z(_GetDisabledWarnings.<locals>.<listcomp>Zmsvs_disabled_warningsr~   r&   r;   r;   r<   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   rw   )rH  rv  ru  r>  c                 S      g | ]	}| d r|qS )z.defr   r/  r;   r;   r<   rR   V      z(_GetModuleDefinition.<locals>.<listcomp>re   r(   r   zWMultiple module definition files in one target, target %s lists multiple .def files: %sr   r   )r/   r_   rL   r5  rI   )r   r  Z	def_filesr;   r;   r<   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   rw   rz   rI   r`   rc   r   )rl   	tool_listr|   r  Zsettings_fixedrn   ro   r;   r;   r<   _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.
  )Zattrsrl   N)_GetMSVSAttributesr  Z	AddConfigr   )r   r   rl   r&   rg  r   
attributesr  r;   r;   r<   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 )NZmsvs_configuration_attributesr   r   ZInheritedPropertySheetsConfigurationTypeOutputDirectoryz"$(SolutionDir)$(ConfigurationName)rE   IntermediateDirectoryz'$(ConfigurationName)\obj\$(ProjectName))r/   rU   rI   rL   r   r   )	r   r&   rg  Zprepared_attrsZsource_attrsaZvsprops_dirsr   intermediater;   r;   r<   r    s*   
r  c                 C   s   |  dd |D  d S )Nc                 s   s    | ]}t |V  qd S rj   rC   r/  r;   r;   r<   	<genexpr>  s    z(_AddNormalizedSources.<locals>.<genexpr>)r   )Zsources_setZsources_arrayr;   r;   r<   _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.
  re   Z
standaloneactionsr   c                 S   rM   r;   r  rO   r;   r;   r<   rR     rS   z)_PrepareListOfSources.<locals>.<listcomp>r   r+  Fr   copiesrQ  )r   r  r/   r   r   r   )r   rE  rh  re   r'  r  r   cpyr;   r;   r<   rZ    s$   




rZ  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)
  Zsources_excludedc                    r.  r;   r;   rO   precompiled_relatedr;   r<   rR     ru   z=_AdjustSourcesAndConvertToFilterHierarchy.<locals>.<listcomp>c                 S   s   g | ]}| d qS )rE   )r   rO   r;   r;   r<   rR     r   rV   c                 S   s   g | ]}t |tjqS r;   )r   rc   rd   r/  r;   r;   r<   rR     ru   c                 S   s   g | ]}|j qS r;   )r   r/  r;   r;   r<   rR      s    r(   c                 S   s   g | ]	}t |jd kqS )r(   )r_   r[   r/  r;   r;   r<   rR     r  c                 S   s   g | ]}|j d  qS r   rZ   r/  r;   r;   r<   rR     r   r   )r   r   r/   rU   _IdlFilesHandledNonNatively_GetPrecompileRelatedFilesrb   ra   allr_   setr   rc   rd   r[   )	r   r   gyp_dirre   r'  rX   r   ri  Zfully_excludedr;   r  r<   r[    s4   



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   Zidlr!  r   Tc                 S   r  ).idlr  rO   r;   r;   r<   rR     r  z/_IdlFilesHandledNonNatively.<locals>.<listcomp>)r/   r   )r   re   Z	using_idlr   ri  r;   r;   r<   r  
  s   r  c                 C   sD   g }| d   D ]\}}tD ]}||}|r|t| qq|S )Nr   )r   precomp_keysr/   r`   rL   )r   r  r   r&   kri   r;   r;   r<   r    s   
r  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   r'  ri  rX   
exclusions	file_nameexcluded_configsr   r&   r;   r;   r<   rb  $  s   rb  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   )rL   r/   rO   r  r;   r<   rR   9  r   z._GetExcludedFilesFromBuild.<locals>.<listcomp>)r   r  r`   )r   r'  ri  r  ri   r  r   Z	precompedr;   r  r<   r  3  s   

r  c                 C   sP   t  }|d  D ]\}}|dg D ]}|| qq	|D ]}| | qd S )Nr   msvs_tool_files)r   r   r/   r   r   )r   r   Z
tool_filesr   r&   ri   r;   r;   r<   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   r"   r  r  rp  r   rI  rJ  rK  rL  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   rc   rd   r[   r-   r?   r   r   r   r   rL   r   )Zsource_treerB   rM  r   r   r&   r|   DisableForSourceTree#extensions_excluded_from_precompiler   r   r;   r<   r  f  s"   
z7_HandlePreCompiledHeaders.<locals>.DisableForSourceTree)
r   r/   rL   rc   r   r   r   r-   r?   r   )	r   re   r   r   r&   rB   r|   rM  r   r;   r  r<   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   )r/   r  r   r   r   )
r   r   rf  r  Zhave_setup_envr  r   Zattached_toZneed_setup_envr   r;   r;   r<   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   )r/   r   ro  r   ZAddDebugSettingsr   r   )
Zproject_pathr   r   r  r   r  r  rn  r   r   r;   r;   r<   ra    s    ra  c                 C   s0   t |}|D ]\}}}}t| ||||d qd S )Nr   )
_GetCopiesr   )r   r   r  r   r   r   r   r;   r;   r<   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  rQ  ZdestinationrD   rF   r   r(   z"%s\%s\"z2mkdir %s 2>nul & cd "%s" && xcopy /e /f /y "%s" %sZdummy_copieszCopying %s to %sz7mkdir "%s" 2>nul & set ERRORLEVEL=0 & copy /Y "%s" "%s")
r/   r-   r?   rI   rM  r   	posixpathr   rL   r`   )r   r  r  srcdstZsrc_barebase_dirZ	outer_dirZ	fixed_dstZfull_dstr   Zfix_dstr;   r;   r<   r    s.   

 r  c                 C   sH   |r| tjr
| S tj|\}}t| |}||vr t ||< || S rj   )r   r-   sepr?   r   _GetPathDictry   )rootr?   parentfolderZparent_dictr;   r;   r<   r    s   

r  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   rw   ry   _DictsToFoldersr-   r?   rI   r7  Z
MSVSFolderr`   )	base_pathZbucketflatchildrenr  r[   Zfolder_childrenr;   r;   r<   r    s   

r  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)rw   ry   r_   nextiter_CollapseSingles)r  nodechildr;   r;   r<   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   r   r  r(   r   )r   r   ParseQualifiedTargetr-   r?   r   r  r_   rw   r  r  ry   r  r  )	sln_projectsproject_objectsr  r  r   rh  targetr  Z	path_dictr;   r;   r<   _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 )NrA  r   )r3  r/   r   ZProjectExtensionr   r   	BuildFiler-   r?   rI   r   generator_outputabspathrW  )
qualified_targetr   r   rY   r:  Zproj_filenamerV  r9  Z
fix_prefixZproject_dir_pathr;   r;   r<   _GetPathOfProject  s    

r  c                 C   sV   i }| d   D ] \}}t||}|dt|}dt|t||f }|||< q|S )Nr   Zmsvs_target_platformr   )r   r   r/   r   r   )r   config_platform_overridesr   r   Zconfig_fullnamer*   Zfixed_config_fullnamer;   r;   r<   _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   rV  r  rG   r   dependenciesc                    s   g | ]} | qS r;   r;   r{  Zprojectsr;   r<   rR   S  rS   z)_CreateProjectObjects.<locals>.<listcomp>)r   r  rG   r<  r  r   r   r  r7  rc   ra   Zset_msbuild_toolsetr@  valuesr   r/   Zset_dependencies)target_listtarget_dictsr   rY   r  r   r9  r;  Z	overridesrV  objrD  Zdepsr;   r  r<   _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   Zmsvs_path_to_ninjaz	ninja.exeninjar   $(Configuration)Ztarget_archx64Z_x64r   r   z-Cr   r  r   z-tcleanN)r/   r   r   r  r-   r?   r   rI   rW  toplevel_dirninja_generatorComputeOutputDir)
paramsr	  r
  r  r   Zpath_to_ninjarh  r   r  rk  r;   r;   r<   _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.rE  rY   autoZMSVS_VERSIONPROCESSOR_ARCHITECTUREr   Z64r   PROCESSOR_ARCHITEW6432@   ZMSVS_OS_BITS    r  z$(OutDir)genr   N)
r/   r   ZSelectVisualStudioVersionZ	ShortNamer-   r.   r   r   r   Z	GetFlavor)Zdefault_variablesr  rE  rY   r;   r;   r<   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   rY   ZCommon7ZIDEz
devenv.com.gyp.slnz/BuildzBuilding [%s]: %s)
r-   r?   rI   r   r   r   r   r   r0   Z
check_call)datar   r  r   rY   ZdevenvrV  Zbuild_file_dictZbuild_file_rootZbuild_file_extsln_pathr&   r   Zrtnr;   r;   r<   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)	r/   r  r-   r?   r@   rI   r  r  generator_filelist_paths)r  r!  r"  r;   r;   r<   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   rY   rE  r   r  r   Nr  r   r  )r  F)r  ZvariantsZwebsitePropertiesr   zMissing input files:
r   Zmsvs_error_on_missing_sourcesz	Warning: )"r/   MSVSUtilZShardTargetsZInsertLargePdbShimsgenerator_default_variablesr  r  r   r   r   rz   r  r  rG   extendrF  r   r-   r?   r   r   r   rI   r   r   ZBuildFileTargetsZDeepDependencyTargetsr  ZFlatSolutionr7  ZMSVSSolutionZWriter   r   )r	  r
  r  r  r   rY   rE  Zconfigsr  r   r   r&   r  rj  rD  rV  r  r  Zroot_entriesZslnZerror_messager;   r;   r<   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Zprettyr#   N)_AppendFiltersForMSBuildeasy_xmlWriteXmlIfChangedr-   r?   existsunlink)Zfilters_pathZsource_filesrule_dependenciesextension_to_rule_namefilter_groupsource_groupcontentr;   r;   r<   _GenerateMSBuildFiltersFile  s"   r9  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\%srd   IncludeZUniqueIdentifierN)
r   rc   rd   r   r`   r7  r8  r/  r[   _MapFileToMsBuildSourceType)Zparent_filter_namere   r4  r5  r6  r7  rB   Zfilter_namer   elementZsource_entryr;   r;   r<   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   )rJ  rK  rI  rL  r4   	ClCompile)z.hz.hxxincludeZ	ClIncludez.rcresourceResourceCompilez.asmmasmZMASMr  midlMidlrule_dependencyCustomBuildrw  None)r-   r?   r   )rB   r4  r5  r   rO  r7   r<  r;   r;   r<   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   r  r   r"  r#  r;   r;   r<   rR     r$  z,_GenerateRulesForMSBuild.<locals>.<listcomp>c                 S   r%  r   r"  r#  r;   r;   r<   rR     r$  r   r   r   r   z.propsz.targetsz.xmlT)r/   MSBuildRuler`   r   r   r   r   r   r   r   r-   r?   rI   _GenerateMSBuildRulePropsFile_GenerateMSBuildRuleTargetsFile_GenerateMSBuildRuleXmlFiler   r&  )r   r   r   re   r'  props_files_of_rulestargets_files_of_rulesr   r4  r5  r   r(  r)  msbuild_rulesr   Zmsbuild_rulebaseZ
props_nameZtargets_nameZxml_name
props_pathtargets_pathxml_pathr;   r;   r<   _GenerateRulesForMSBuild  s:   	






rR  c                   @   s   e Zd ZdZdd ZdS )rG  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BeforeTargetsZ	DependsOnzCompute%sOutputZ
DirsToMakeZ_inputsZ_tlogr   r   r   r   r   c                 S   r   r;   r   ConvertVCMacrosToMSBuildrO   r;   r;   r<   rR         z(MSBuildRule.__init__.<locals>.<listcomp>r   c                 S   r   r;   rU  rO   r;   r;   r<   rR     rW  Tr   )display_namer3   r  r   r   after_targetsbefore_targets
depends_oncompute_outputdirs_to_maker   tlogr   r   r   rV  r/   r   rU   rI   r   r   r   r   )selfr   r   Zold_additional_dependenciesZold_outputsZold_commandr;   r;   r<   __init__  s:   




zMSBuildRule.__init__N)__name__
__module____qualname____doc__r`  r;   r;   r;   r<   rG    s    rG  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'rC  rE  z$'$(ConfigurationType)' != 'Makefile'z_SelectedFiles;$(%s)ItemDefinitionGroupCommandLineTemplater   ExecutionDescriptionr   Tr.  N)r'  rZ  rY  r[  r   r   r   r   r   r0  r1  )rO  rM  r8  r   r;   r;   r<   rH    s<   rH  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-  ZPropertyPageSchemar:  z5$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xmlZAvailableItemNameTargetsZ	UsingTaskZXamlTaskFactoryzMicrosoft.Build.Tasks.v4.0)ZTaskNameZTaskFactoryZAssemblyNameZTaskz%%(%s.Outputs)zC%%(%s.Identity);%%(%s.AdditionalDependencies);$(MSBuildProjectFile)z%%(%s.Identity)zd'%(Extension)'=='.obj' or '%(Extension)'=='.res' or '%(Extension)'=='.rsc' or '%(Extension)'=='.lib'rf  z'@(SelectedFiles)' != ''z@(%s)z#'%(Identity)' != '@(SelectedFiles)')ZRemoverf  z%%(%s.AdditionalDependencies)z?'%%(%s.Outputs)' != '' and '%%(%s.ExcludedFromBuild)' != 'true')r:  rf  ZSourcez
@(%s, '|')Inputsz@(%s -> '%%(Fullpath)', ';')MessageZHighz%%(%s.ExecutionDescription))Z
ImportanceZTextZWriteLinesToFilez6'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != 'true'z$$(IntDir)$(ProjectName).write.1.tlogz$^%%(%s.Source);@(%s->'%%(Fullpath)'))rf  ZFileZLinesz#$(IntDir)$(ProjectName).read.1.tlogz^%%(%s.Source);%%(%s.Inputs)r  z%%(%s.CommandLineTemplate)z%%(%s.AdditionalOptions))rf  ZEchoOffZStandardOutputImportanceZStandardErrorImportancerh  r  rk  Targetz$(%s)z'@(%s)' != ''z$(%s);%s)NamerT  rS  rf  ZDependsOnTargetsr   rk  re  ZComputeLinkInputsTargetsz$(ComputeLinkInputsTargets);z%s;ZComputeLibInputsTargetsz$(ComputeLibInputsTargets);)rn  rf  )rf  r:  r  r  ZImpLibZMakeDirrr   z!@(%s->'%%(RootDir)%%(Directory)')Tr.  N)r`   r   r   r   r^  r'  rZ  rY  r[  r\  r]  r0  r1  )rP  rM  r8  Z
item_groupr   r   Ztarget_outputsZtarget_inputsZrule_inputsZextension_conditionZremove_sectionZinputs_sectionZlogging_sectionZmessage_sectionZwrite_tlog_sectionZread_tlog_sectionZcommand_and_input_sectionr;   r;   r<   rI  	  s:  





		
?rI  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 )KNZ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:transformCallbackZRuler|   Z200)rn  ZPageTemplateDisplayNameZOrderzRule.DataSourceZ
DataSourceZProjectFile)PersistenceItemTypezRule.CategoriesCategoryrn  ZGeneralzCategory.DisplayNamez
sys:StringzCommand Liner   )rn  SubtypeZStringListPropertyrk  r  r   )rn  rr  Z
IsRequiredZSwitchzStringListProperty.DataSourceZItem)rp  rq  Z
SourceTypeZStringPropertyrh  False)rn  ro  VisibleIncludeInCommandLineZDynamicEnumPropertyrj  )rn  rr  ZEnumProviderrv  zDynamicEnumProperty.DisplayNamezExecute BeforezDynamicEnumProperty.Descriptionz@Specifies the targets for the build customization to run before.z$DynamicEnumProperty.ProviderSettingsZNameValuePairZExcludez^%s|^Compute)rn  ZValuezDynamicEnumProperty.DataSource)rp  HasConfigurationConditionzExecute Afterz?Specifies the targets for the build customization to run after.r   )rp  rq  rw  r   ri  zExecution Descriptionr   zAdditional Dependenciesfalse)rn  ro  rv  ru  r  )rs  rn  rr  zStringProperty.DisplayNamezAdditional OptionszStringProperty.Descriptionrq  )rn  ro  ZFileExtensionr  )rn  ContentTypery  )rn  ro  rq  Tr.  )r'  r   rX  rZ  rY  r   r0  r1  )rQ  rM  r8  r   r;   r;   r<   rJ  	  sV  
    #rJ  c                 C   s$   |  ddd }|dd}||fS )Nr   r(   r   r   r   )rsplitr/   )r   r  rk  r*   r;   r;   r<   _GetConfigurationAndPlatformZ
  s   r{  c                 C   s   dt | | S )Nz''$(Configuration)|$(Platform)'=='%s|%s')r{  )r   r  r;   r;   r<   _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-  LabelZProjectConfigurationsr   ZProjectConfigurationr:  ConfigurationZPlatform)r   r   r{  r`   )r   r7   r   r  rk  r*   Zdesignationr;   r;   r<    _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   re  r}  ZGlobalsZProjectGuidZKeywordZ	Win32ProjZRootNamespaceZ#IgnoreWarnCompileDuplicatedFilenamer  r  ZAMD64r  ZPreferredToolArchitecturer  r   ZWindowsTargetPlatformVersionr    ZWindowsTargetPlatformMinVersionr   ZDefaultLanguagezen-USZAppContainerApplicationr   ZApplicationTypeRevisionz8.1r   ZApplicationTypezWindows PhonezWindows Storer   z6%s requires any SDK of %s version, but none were foundZARMZWindowsSDKDesktopARMSupport)r-   r?   r   r.   r/   r`   r  r   r   rx   r   r   r   )r   r   r;  Zgyp_file_name	namespace
propertiesZtarget_platform_versionZtarget_platform_minversionZapp_type_revisionr   r   rk  r;   r;   r<   _GetMSBuildGlobalPropertiesq
  sp   	












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  DriverZ
DriverTypeZWDMZTargetVersionr   r~  )r   _GetMSBuildAttributesr|  r/   _AddConditionalPropertyr   _GetMSBuildPropertyGroup)	r   rV  r  r   r  msbuild_attributes	conditionZcharacter_setrg  r;   r;   r<   _GetMSBuildConfigurationDetails
  s*   


r  c                 C   s    i }| rdddid| ggg}|S )Nre  r}  ZLocalsZPlatformToolsetr;   )r=  r  r;   r;   r<   _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.propsFZmsbuild_propsTr   ImportGroupr}  ZPropertySheetsImportzexists('%s')ZLocalAppDataPlatform)r)  rf  r}  )r}  rf  r)  )r   r   r|  rU   r`   )r   Z
user_propsZadditional_propsZprops_specifiedr   r  rk  Zsheetsr  ZpropsZimport_group
props_filer;   r;   r<   _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)r  r  rE   r  r  z3Warning: Do not know how to convert MSVS attribute )rX  r  r   rV  r   _ConvertMSVSCharacterSet_ConvertMSVSConfigurationTyper   )r   r&   rV  rg  Zmsvs_attributesr  r  Z	directoryr;   r;   r<   _ConvertMSVSBuildAttributes
  s   


r  c                 C   s   |   rdddd|  } | S )NZ	MultiByteZUnicode)r  rp  rq  isdigit)Zchar_setr;   r;   r<   r    s   r  c                 C   s    |   rdddddd|  } | S )NZApplicationZDynamicLibraryZStaticLibraryr  ZUtility)rp  rq  rr  rs  rt  r  )rg  r;   r;   r<   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 )NZ msbuild_configuration_attributesr  r  z$(SolutionDir)$(Configuration)rE   r  r  r  
TargetNamer  r   r  r  	TargetExtr  r   r   r   r  r  r  rw   finalized_msbuild_settingsr  
TargetPath)r  rX  r  r/   rN  rL   r  )r   r&   rV  r  rg  r   r  r\   r  r   rO  Zexternal_out_dirZmsbuild_tool_mapr  msbuild_settingsr  
target_extr;   r;   r<   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\binZ	python_26z$(ExecutablePath);r   r  ZIntDirr  ZOutDirr  r  r  r  ExecutablePathr   )r/   rL   r`   rJ   rI   r   r   r|  r  r  _GetValueFormattedForMSBuildr  )r   r   rV  Z	new_pathsZcygwin_dirsZcyg_pathZpython_pathr  r   rk  r  r  r  tool_settingsro   formatted_valuer;   r;   r<   (_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   ro   r  
conditionsr;   r;   r<   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.
  re  r}  r   c                    sD   t  }t   D ]}|t  fddt|D  q|S )Nc                    s    g | ]}|v r| kr|qS r;   r;   )rP   v)r  r  r;   r<   rR     s
    
z>_GetMSBuildPropertyGroup.<locals>.GetEdges.<locals>.<listcomp>)r  r   r1  r   MSVS_VARIABLE_REFERENCEfindall)r  Zedgesro   r  )r  r<   GetEdges  s   &	z*_GetMSBuildPropertyGroup.<locals>.GetEdgesrf  )	r`   r_   r   r   ZTopologicallySortedr1  r  r   r   )r   Zlabelr  r7   Znum_configurationsr  Zproperties_orderedr   r  ro   r  r  r;   r  r<   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  rg  rf  )r   r   r|  r  r`   )r   r   groupsr   rk  r  r7   rm   r  r|   ro   r  r;   r;   r<   _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  ry  c                 S   s   g | ]}|d kr|qS )z
_HAS_TR1=0r;   r{  r;   r;   r<   rR     ru   z,_FinalizeMSBuildSettings.<locals>.<listcomp>r  zXWarning: The automatic conversion to MSBuild does not handle %s.  Ignoring setting of %sc                 S   rM   r;   )r  r{  r;   r;   r<   rR     rS   r}  r~  r!   r=  r  rC  r@  r  r   r  r  r  r  r  r  r(   PrecompiledHeaderZUseZPrecompiledHeaderFiler  ZNotUsingrv   rx  r   r   r  rw   rv  r  r  r  ZPreBuildEventCommandZPostBuildEvent)r   ZValidateMSBuildSettingsr/   ZConvertToMSBuildSettingsr  r  r  r  r  r  r   rx   r  r  rq   rk   r-   r?   r   )r   rk  Z	convertedr  r  r  r  r  r  r  r  r   r  r  r  Zignored_settingsZignored_settingro   r  r  r  r  r  r;   r;   r<   _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  ZDelayLoadDLLsr  r  z%%(%s)r  )r=  r  r  r   r   c                 S   r   r;   rU  rO   r;   r;   r<   rR   [  r   z0_GetValueFormattedForMSBuild.<locals>.<listcomp>)rw   rz   r`   rI   r   rV  )rm   r   ro   
exceptionscharr  r;   r;   r<   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   rc   rd   r'  r\  r[   r-   r?   rI   r2  r`   )re   root_dirrj  rB   	full_pathr;   r;   r<   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)rw  rA  rB  r>  r4   r?  r   rD  r-  )_AddSources2r`   )r   re   r  r4  r5  actions_specsources_handled_by_actionrX   r  grouped_sourcesgr;   r;   r<   _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   r  r  rf  r"   r   rI  r  r  ZCreater  r:  )r   rc   rd   r  r[   r/   r_   r`   r   r|  r   rL   r-   r?   r   r   r;  )r   re   r  r  r4  r5  r  rX   r  rB   ZdetailZexcluded_configurationsr   rk  r  Zprecompiled_sourcerM  r   r7   r<  r;   r;   r<   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   ZProjectReferencer:  r)  ZReferenceOutputAssemblyrx  r   Z"msvs_use_library_dependency_inputsZUseLibraryDependencyInputsr  Z&msvs_2010_disable_uldi_when_referenced)r  r;  r-   r?   r   r   r   rW  r   r/   r  r`   )	rD  Z
referencesr7   Z
dependencyr;  rd  Zrelative_pathZproject_refr&   r;   r;   r<   _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(   rS  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.targetsre  r}  Z
UserMacrosr*  Build)r,  r+  ZDefaultTargetsr   Z	v120_wp81r.  )*r   r-   r?   r   r   r   rT  rC   rV  rW  rZ  r  r/   rR  r&  r[  r_  r`  r2  r  _GenerateActionsForMSBuildr9  r\  r  r  ZProjectVersionr  r  r;  r  r  r=  _GetMSBuildExtensionsr  r  r  r  r  _GetMSBuildExtensionTargets!_GetMSBuildExternalBuilderTargetsr0  r1  )!rD  r   r   rE  r   r   rd  Zproject_file_namere  rf  rh  re   r'  r   rK  rL  r4  r5  rX   r   ri  r  r  r  rj  rk  Zimport_default_sectionZimport_cpp_props_sectionZimport_cpp_targets_sectionZimport_masm_props_sectionZimport_masm_targets_sectionZmacro_sectionr8  r;   r;   r<   rB    s   








rB  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   Frm  rn  r  Execr  r   ZCleanr   r=  )r   r`   r/   )r   Z	build_cmdZbuild_targetZ	clean_cmdZclean_targettargetsZclcompile_cmdZclcompile_targetr;   r;   r<   r  X  s,   

r  c                 C   s.   dddig}| D ]}| dd|ig q|gS )Nr  r}  ZExtensionSettingsr  r)  r   )rK  r   r  r;   r;   r<   r  }  s   r  c                 C   s2   dddig}t | D ]}|dd|ig q
|gS )Nr  r}  ZExtensionTargetsr  r)  )r   r`   )rL  Ztargets_nodeZtargets_filer;   r;   r<   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   Zmsbuild_use_callTzcall r   r   c                 S   s   g | ]}|d  qS )z,
if %errorlevel% neq 0 exit /b %errorlevel%r;   r   r;   r;   r<   rR     s    z._GenerateActionsForMSBuild.<locals>.<listcomp>)r   r   r   r`   r/   rI   _AddMSBuildAction)r   r   r  r  r   r  r   r   r   r   r   r   r   r   r;   r;   r<   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 r;   r;   rO   r   r;   r<   rR     s    
z%_AddMSBuildAction.<locals>.<listcomp>rE  r:  FileTypeZDocumentr  rl  r   ZAdditionalInputs)r   rV  rL   rU   rI   r   r'  r`   )r   r   r   r   r   r   r  r  r   Zinputs_arrayZoutputs_arrayZadditional_inputsZaction_specr;   r  r<   r    s$   


r  )NNTN)F)Z
__future__r   r]   copyr  r-   r  r3   r0   r)   Z
gyp.commonr   Zgyp.easy_xmlr0  Zgyp.generator.ninja	generatorr  r  Zgyp.MSVSNewr7  Zgyp.MSVSProjectrc   Zgyp.MSVSSettingsr   Zgyp.MSVSToolFiler   Zgyp.MSVSUserFilerm  Zgyp.MSVSUtilr%  Zgyp.MSVSVersionr   r   r   r4   r4  r&  Z"generator_additional_path_sectionsZ+generator_additional_non_configuration_keysr#  r  r,   r+   r=   rG   rC   rL   rU   rb   rq   rk   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  r3  r<  r@  rF  rR  rC  rU  ro  rX  rY  r  r  r  r  r  r  r  r  r  r  r  r  rZ  r[  r  r  rb  r  r]  r^  r_  ra  r`  r  r  r  r  r  r  r  r  r  r  r  r$  r(  r9  r/  r;  rR  objectrG  rH  rI  rJ  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r\  r  r  r  rB  r  r  r  r  r  r;   r;   r;   r<   <module>   s  
	
AK#&Q

/
#FW''6
'10Q''-5  & 3=,
50
2
]9v%2