o
    p.a`%  ã                   @   s`   d Z ddlZddlZdddd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S )z8Utility functions shared amongst the Windows generators.é    NÚexeZdllÚlibÚsys)Ú
executableZloadable_moduleZshared_libraryÚstatic_libraryZwindows_driverc                  C   sN   t j t j t¡¡} t j t j | dd¡¡}t j |dd¡}t j |d¡}|S )z/Returns the path of the large_pdb_shim.cc file.z..ÚdataÚwinzlarge-pdb-shim.cc)ÚosÚpathÚabspathÚdirnameÚ__file__Újoin)Zthis_dirZsrc_dirZwin_data_dirÚlarge_pdb_shim_cc© r   ú./usr/lib/python3/dist-packages/gyp/MSVSUtil.pyÚ_GetLargePdbShimCcPath   s
   r   c                 C   s.   i }|D ]}|| vrqt  | | ¡||< q|S )a-  Performs a partial deep-copy on |in_dict|, only copying the keys in |keys|.

  Arguments:
    in_dict: The dictionary to copy.
    keys: The keys to be copied. If a key is in this list and doesn't exist in
        |in_dict| this is not an error.
  Returns:
    The partially deep-copied dictionary.
  )ÚcopyÚdeepcopy)Zin_dictÚkeysÚdÚkeyr   r   r   Ú_DeepCopySomeKeys   s   
r   c                 C   s*   |   dd¡}d|d |f |d< d |¡S )zÃAdd a suffix to the end of a target.

  Arguments:
    name: name of the target (foo#target)
    suffix: the suffix to be added
  Returns:
    Target name with suffix added (foo_suffix#target)
  ú#é   z%s_%sr   )Úrsplitr   )ÚnameÚsuffixÚpartsr   r   r   Ú_SuffixName0   s   	
r   c                 C   s   t | t|ƒƒS )z¹Add a shard number to the end of a target.

  Arguments:
    name: name of the target (foo#target)
    number: shard number
  Returns:
    Target name with shard added (foo_1#target)
  )r   Ústr)r   Znumberr   r   r   Ú
_ShardName>   s   	r!   c              	   C   s¬  i }|D ]}t ||  dd¡ƒ}|r|||< qg }| D ]}||v r3t|| ƒD ]
}| t||ƒ¡ q'q| |¡ qi }|D ]U}||v rŒt|| ƒD ]A}t||ƒ}t || ¡||< t|| d |ƒ|| d< ||  dg ¡}	g }
t|t|	ƒ|| ƒD ]	}|
 |	| ¡ qz|
|| d< qIq=|| ||< q=t|ƒD ]:}dD ]5}t ||  |g ¡¡}g }|D ]}||v rÄt|| ƒD ]
}| t||ƒ¡ q¸q¬| |¡ q¬||| |< q›q—||fS )a  Shard some targets apart to work around the linkers limits.

  Arguments:
    target_list: List of target pairs: 'base/base.gyp:base'.
    target_dicts: Dict of target properties keyed on target pair.
  Returns:
    Tuple of the new sharded versions of the inputs.
  Z
msvs_shardr   Útarget_nameÚsources)ÚdependenciesZdependencies_original)ÚintÚgetÚrangeÚappendr!   r   ÚlenÚsorted)Útarget_listÚtarget_dictsZtargets_to_shardÚtZshardsZnew_target_listÚiZnew_target_dictsr   r#   Znew_sourcesÚposZdeptyper$   Znew_dependenciesr   r   r   r   ÚShardTargetsJ   sT   
€ÿ
ÿ÷ÿ÷r0   c           	      C   sŽ   | d | }|  di ¡}| di ¡}| d¡}|r|S |  di ¡}| dd¡}|r+|S |  d| d	 ¡}d
|t| d  f }|d d | }|S )a“  Returns the path to the PDB file that will be generated by a given
  configuration.

  The lookup proceeds as follows:
    - Look for an explicit path in the VCLinkerTool configuration block.
    - Look for an 'msvs_large_pdb_path' variable.
    - Use '<(PRODUCT_DIR)/<(product_name).(exe|dll).pdb' if 'product_name' is
      specified.
    - Use '<(PRODUCT_DIR)/<(target_name).(exe|dll).pdb'.

  Arguments:
    target_dict: The target dictionary to be searched.
    config_name: The name of the configuration of interest.
    vars: A dictionary of common GYP variables with generator-specific values.
  Returns:
    The path of the corresponding PDB file.
  ÚconfigurationsÚmsvs_settingsÚVCLinkerToolÚProgramDatabaseFileÚ	variablesZmsvs_large_pdb_pathNZproduct_namer"   z	%s.%s.pdbÚtypeZPRODUCT_DIRú/)Ú
setdefaultr&   ÚTARGET_TYPE_EXT)	Útarget_dictÚconfig_nameÚvarsÚconfigÚmsvsÚlinkerÚpdb_pathr5   Zpdb_baser   r   r   Ú_GetPdbPath   s   
rA   c                 C   sú  g }|D ]}|| }t | dd¡ƒsq| |¡ qtƒ }|D ]Ú}|| }| d¡}t|g d¢ƒ}d}	|d |	 }
t||	ƒ}tj |¡}|d d |
 }|d | }t	 
|¡}|
|d< d	|d
< |g|d< ||gdœg|d< d}|d | }t||ƒ}t	 
|¡}||d< d|d
< |g|d< |g|d< | d¡ ¡ D ]C\}}t|||ƒ}dD ]}| |d¡ q£| di ¡}| di ¡}d|d< ||d< |d | }| di ¡}| di ¡}d|d< ||d< q—|  d|¡ |  d|¡ |||< |||< | dg ¡ |¡ q| |fS )aï  Insert a shim target that forces the linker to use 4KB pagesize PDBs.

  This is a workaround for targets with PDBs greater than 1GB in size, the
  limit for the 1KB pagesize PDBs created by the linker by default.

  Arguments:
    target_list: List of target pairs: 'base/base.gyp:base'.
    target_dicts: Dict of target properties keyed on target pair.
    vars: A dictionary of common GYP variables with generator-specific values.
  Returns:
    Tuple of the shimmed version of the inputs.
  Zmsvs_large_pdbr   r"   )r1   Zdefault_configurationZtoolsetZlarge_pdb_copyÚ_ZSHARED_INTERMEDIATE_DIRr7   Znoner6   r#   )ZdestinationÚfilesZcopiesZlarge_pdb_shimr   r$   r1   )Zmsvs_precompiled_headerZmsvs_precompiled_sourceÚtestNr2   ZVCCLCompilerToolÚ3ZDebugInformationFormatZProgramDataBaseFileNamer3   ÚtrueZGenerateDebugInformationr4   )r%   r&   r(   r   r   r   r	   r
   Úbasenamer   r   ÚitemsrA   Úpopr8   Úinsert)r+   r,   r<   Ztargets_to_shimr-   r:   r   r"   Z	base_dictZcopy_suffixZcopy_target_nameZfull_copy_target_nameZshim_cc_basenameZshim_cc_dirZshim_cc_pathZ	copy_dictZshim_suffixZshim_target_nameZfull_shim_target_nameZ	shim_dictr;   r=   r@   r   r>   Zcompilerr?   r   r   r   ÚInsertLargePdbShims©   sj   
ÿ	


þ




rK   )Ú__doc__r   r	   r9   r   r   r   r!   r0   rA   rK   r   r   r   r   Ú<module>   s    û		7(