o
    p.aeB  ã                   @   sö   d Z 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
m  mZ dai ZdD ]Zde ee< q/dD ]Zdee< q:d	e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d„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ ZdS )%a¹  GYP backend that generates Eclipse CDT settings files.

This backend DOES NOT generate Eclipse CDT projects. Instead, it generates XML
files that can be imported into an Eclipse CDT project. The XML file contains a
list of include paths and symbols (i.e. defines).

Because a full .cproject definition is not created by this generator, it's not
possible to properly define the include dirs and symbols for each file
individually.  Instead, one set of includes/symbols is generated for the entire
project.  This works fairly well (and is a vast improvement in general), but may
still result in a few indexer issues here and there.

This generator has no automated tests, so expect it to be broken.
é    )ÚescapeNF)ÚINTERMEDIATE_DIRÚPRODUCT_DIRÚLIB_DIRÚSHARED_LIB_DIRú$)ÚRULE_INPUT_PATHÚRULE_INPUT_ROOTÚRULE_INPUT_NAMEÚRULE_INPUT_DIRNAMEÚRULE_INPUT_EXTÚEXECUTABLE_PREFIXÚEXECUTABLE_SUFFIXÚSTATIC_LIB_PREFIXÚSTATIC_LIB_SUFFIXÚSHARED_LIB_PREFIXÚSHARED_LIB_SUFFIXÚCONFIGURATION_NAMEÚ ú$SHARED_INTERMEDIATE_DIRÚSHARED_INTERMEDIATE_DIRc           	      C   sŠ   |  di ¡}| ¡ D ]
\}}|  ||¡ q
tj |¡}|  d|¡ |dkrCdd lm  m} t	|dg ƒ}t	|dg ƒ}tj
 | |¡ d S d S )NÚgenerator_flagsÚOSÚwinr   Ú+generator_additional_non_configuration_keysÚ"generator_additional_path_sections)ÚgetÚitemsÚ
setdefaultÚgypÚcommonÚ	GetFlavorÚgyp.generator.msvsÚ	generatorÚmsvsÚgetattrÚmsvs_emulationÚCalculateCommonVariables)	Údefault_variablesÚparamsr   ÚkeyÚvalÚflavorÚmsvs_generatorr   r   © r.   ú7/usr/lib/python3/dist-packages/gyp/generator/eclipse.pyÚCalculateVariables5   s   ÿÿ÷r0   c                 C   s$   |   di ¡}|  dd¡rdadS dS )zOCalculate the generator specific info that gets fed to input (called by
  gyp).r   Úadjust_static_librariesFTN)r   Ú4generator_wants_static_library_dependencies_adjusted)r)   r   r.   r.   r/   ÚCalculateGeneratorInputInfoG   s   þr3   c                 C   sØ  t ƒ }g }|rLt |¡}| g d¢¡ tj|tjtjtjd}	|	 ¡ d }
d}|
 ¡ D ] }| 	d¡r5d}q+| 	d¡r< n|rK| 
¡ }||vrK| |¡ q+tj |¡}|dkr\| d	i ¡}| D ]u}|| }||d
 v rÓ|d
 | }|dkrtj ||¡}| |¡}n|d }|D ]}| 	d¡r|dd… }||vr| |¡ q‡d|v rÓ|d }|D ]*}|D ]%}| d|¡}tj |¡sÌtj |¡}|d | }tj |¡}| |¡ q¬q¨q^t|ƒ}| ¡  |D ]}||vré| |¡ qÞ|S )zÜCalculate the set of include directories to be used.

  Returns:
    A list including all the include_dir's specified for every target followed
    by any include directories that were added as cflag compiler options.
  )ú-Ez-xc++z-vú-)ÚargsÚstdinÚstdoutÚstderré   Fz#includeTzEnd of search list.r   r   ÚconfigurationsÚcflagsz-Ié   NÚinclude_dirsr   ú/)ÚsetÚshlexÚsplitÚextendÚ
subprocessÚPopenÚPIPEÚcommunicateÚ
splitlinesÚ
startswithÚstripÚappendr   r    r!   r   r&   ÚMsvsSettingsÚ	GetCflagsÚreplaceÚosÚpathÚisabsÚdirnameÚabspathÚaddÚlistÚsort)Útarget_listÚtarget_dictsÚshared_intermediate_dirsÚconfig_namer)   Úcompiler_pathÚgyp_includes_setÚcompiler_includes_listÚcommandÚprocÚoutputÚin_include_listÚlineÚinclude_dirr,   r   Útarget_nameÚtargetÚconfigÚmsvs_settingsr<   Úcflagr>   Úshared_intermediate_dirÚbase_dirÚall_includes_listÚcompiler_includer.   r.   r/   ÚGetAllIncludeDirectoriesP   sv   


ÿ	


€

€ÿ÷€
€rm   c           	      C   sv   t j | d ¡\}}}||  di ¡}|D ]\}}|dv r'tj |j|¡  S qdD ]}tj |¡}|r8|  S q*dS )a  Determine a command that can be used to invoke the compiler.

  Returns:
    If this is a gyp project that has explicit make settings, try to determine
    the compiler from that.  Otherwise, see if a compiler was specified via the
    CC_target environment variable.
  r   Úmake_global_settings)ÚCCÚCXX)Ú	CC_targetro   rp   Úgcc)	r   r    ÚParseQualifiedTargetr   rO   rP   ÚjoinÚtoplevel_dirÚenviron)	rW   ÚdataÚoptionsÚ
build_fileÚ_Úmake_global_settings_dictr*   ÚvalueÚcompilerr.   r.   r/   ÚGetCompilerPath©   s   	ÿÿr~   c                 C   s~  i }t j |¡}|dkr| di ¡}| D ]Y}	||	 }
|dkr+t j |
|¡}| |¡}ng }||
d v r>|
d | }|d }ng }|| D ](}| dd¡}t|ƒdkrW| 	d¡ |d  
¡ |v r`qD|d  
¡ ||d  
¡ < qDq|dkrt|S |r½t |¡}| g d	¢¡ tj|d
tjtjd}| ¡ d }| d¡}|D ]"}| 
¡ s¡qš| dd¡}|d }t|ƒdkr¶|d }nd}|||< qš|S )z´Calculate the defines for a project.

  Returns:
    A dict that includes explict defines declared in gyp files along with all of
    the default defines that the compiler uses.
  r   r   r;   Údefinesú=r:   Ú1r   )r4   z-dMr5   Ú.)r6   Úcwdr7   r8   Ú
ú r=   é   )r   r    r!   r   r&   rL   ÚGetComputedDefinesrB   ÚlenrK   rJ   rA   rC   rD   rE   rF   rG   )rW   rX   rw   rZ   r)   r[   Úall_definesr,   r   rd   re   rg   Úextra_definesrf   Útarget_definesÚdefineÚsplit_definer^   Úcpp_procÚ
cpp_outputÚ	cpp_linesÚcpp_lineÚcpp_line_partsr*   r+   r.   r.   r/   ÚGetAllDefinesÁ   sT   


ù	
ÿ


r“   c                 C   s\   |   d¡ |   d¡ |D ]}|   d| ¡ |D ]	}|   d| ¡ q|   d¡ q|   d¡ dS )z9Write the includes section of a CDT settings export file.zT  <section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePaths">
ú=    <language name="holder for library settings"></language>
ú    <language name="%s">
z;      <includepath workspace_path="false">%s</includepath>
ú    </language>
ú  </section>
N)Úwrite)ÚoutÚeclipse_langsr>   Úlangrc   r.   r.   r/   ÚWriteIncludePathsü   s   

ÿrœ   c              	   C   st   |   d¡ |   d¡ |D ]&}|   d| ¡ t| ¡ ƒD ]}|   dt|ƒt|| ƒf ¡ q|   d¡ q|   d¡ dS )z7Write the macros section of a CDT settings export file.zN  <section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros">
r”   r•   z6      <macro><name>%s</name><value>%s</value></macro>
r–   r—   N)r˜   ÚsortedÚkeysr   )r™   rš   r   r›   r*   r.   r.   r/   ÚWriteMacros  s   

ÿrŸ   c           
   
   C   s˜   |d }|  di ¡}tj |  dd¡|¡}tj |j|¡}tj |dd¡tj |d¡g}	t| ||||tj |d¡||	ƒ t| ||j|tj |d¡ƒ d S )	Nrx   r   Ú
output_dirr™   ÚobjÚgenzeclipse-cdt-settings.xmlzeclipse-classpath.xml)r   rO   rP   rt   ru   ÚGenerateCdtSettingsFileÚGenerateClasspathFile)
rW   rX   rw   r)   rZ   rx   r   Ú	build_dirÚtoplevel_buildrY   r.   r.   r/   ÚGenerateOutputForConfig  s8   ÿÿÿø	ÿür§   c                 C   sª   t j |¡ t|dƒ@}| d¡ | d¡ g d¢}	t| ||ƒ}
t| |||||
ƒ}t||	|ƒ t| |||||
ƒ}t	||	|ƒ | d¡ W d   ƒ d S 1 sNw   Y  d S )NÚwz'<?xml version="1.0" encoding="UTF-8"?>
z<cdtprojectproperties>
)zC++ Source FilezC Source FilezAssembly Source FilezGNU C++zGNU CÚAssemblyz</cdtprojectproperties>
)
r   r    ÚEnsureDirExistsÚopenr˜   r~   rm   rœ   r“   rŸ   )rW   rX   rw   r)   rZ   Úout_namerx   rY   r™   rš   r[   r>   r   r.   r.   r/   r£   ;  s"   

þ
ÿ"ñr£   c                    s~   t j |¡ t d¡‰ ‡ ‡fdd„}|dt| |ˆƒƒ |dt| |ˆƒƒ |ddgƒ |dtj 	|d	¡gƒ t 
ˆ ¡ |¡ d
S )z·Generates a classpath file suitable for symbol navigation and code
  completion of Java code (such as in Android projects) by finding all
  .java and .jar files used as action inputs.Ú	classpathc                    sr   t ƒ }|D ]}tj |¡r| tj |ˆ¡¡ q| |¡ qt|ƒD ]}t ˆ d¡}|  d| ¡ |  d|¡ q"d S )NÚclasspathentryÚkindrP   )	r@   rO   rP   rQ   rT   Úrelpathr   ÚETÚ
SubElement)r¯   ÚpathsÚ	rel_pathsrP   Úentry_element©Úresultru   r.   r/   ÚAddElementsY  s   ýz*GenerateClasspathFile.<locals>.AddElementsÚlibÚsrcÚconz'org.eclipse.jdt.launching.JRE_CONTAINERr`   z.eclipse-java-buildN)r   r    rª   r±   ÚElementÚGetJavaJarsÚGetJavaSourceDirsrO   rP   rt   ÚElementTreer˜   )rW   rX   ru   r¦   r¬   r¸   r.   r¶   r/   r¤   Q  s   
r¤   c                 c   s‚    | D ];}|| }|  dg ¡D ].}|d D ]'}tj |¡d dkr<| d¡s<tj |¡r0|V  qtj tj |¡|¡V  qqqdS )z1Generates a sequence of all .jars used as inputs.ÚactionsÚinputsr:   z.jarr   N)r   rO   rP   ÚsplitextrI   rQ   rt   rR   )rW   rX   ru   rd   re   ÚactionÚinput_r.   r.   r/   r½   s  s   €€ûÿþr½   c           
   
   c   sÂ    | D ][}|| }|  dg ¡D ]N}|d D ]G}tj |¡d dkr\| d¡s\tj tj tj |¡|¡¡}|}tj |¡dvrYtj |¡\}}	|rM||krQ|V  ntj |¡dvs?|V  qqqdS )zAGenerates a sequence of all likely java package root directories.rÀ   rÁ   r:   z.javar   )rº   ÚjavaN)	r   rO   rP   rÂ   rI   rR   rt   ÚbasenamerB   )
rW   rX   ru   rd   re   rÃ   rÄ   Údir_Úparent_searchrz   r.   r.   r/   r¾   €  s.   €ÿÿû€îÿþr¾   c                 C   sl   |d j r	tdƒ‚| di ¡ dd¡}|rt| ||||ƒ dS || d  d }|D ]
}t| ||||ƒ q)dS )zFGenerate an XML settings file that can be imported into a CDT project.rx   z.--generator_output not implemented for eclipser   rf   Nr   r;   )Úgenerator_outputÚNotImplementedErrorr   r§   )rW   rX   rw   r)   Úuser_configÚconfig_namesrZ   r.   r.   r/   ÚGenerateOutputš  s   

ÿ
ÿÿrÍ   )Ú__doc__Úxml.sax.saxutilsr   Úos.pathrO   rD   r   Ú
gyp.commonÚgyp.msvs_emulationrA   Úxml.etree.cElementTreeÚetreeÚcElementTreer±   r2   Úgenerator_default_variablesrR   Úunusedr0   r3   rm   r~   r“   rœ   rŸ   r§   r£   r¤   r½   r¾   rÍ   r.   r.   r.   r/   Ú<module>   s<   
ÿ	Y;!"