o
    WªodJC  ã                   @  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mZm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ dd	l
mZmZ dd
lmZmZmZmZmZmZm Z  ddl!m"Z" ej#rwddlm$Z$ ddlm%Z% ddl&m'Z' g d¢Z(G dd„ dej)ƒZ*G dd„ de"ƒZ+dS )é    )ÚannotationsNé   )Ú	compilersÚenvironmentÚmesonlibÚoptinterpreter)Úcoredata)Ú
ExecutableÚJarÚSharedLibraryÚSharedModuleÚStaticLibrary)Údetect_compiler_for)ÚInvalidArguments)ÚMachineChoiceÚ	OptionKey)ÚBaseNodeÚArithmeticNodeÚ	ArrayNodeÚElementaryNodeÚIdNodeÚFunctionNodeÚ
StringNodeé   )ÚAstInterpreter)ÚBuildTarget)Ú	TYPE_nvar)Ú
AstVisitor)Ú
executableÚjarÚlibraryÚshared_libraryÚshared_moduleÚstatic_libraryÚboth_librariesc                      s(   e Zd Zd‡ fdd„Zdd	d
„Z‡  ZS )ÚIntrospectionHelperÚ
cross_fileÚstrc                   s    t ƒ  ¡  || _d | _i | _d S ©N)ÚsuperÚ__init__r&   Znative_fileZcmd_line_options)Úselfr&   ©Ú	__class__© ú{home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/ast/introspection.pyr*   /   s   

zIntrospectionHelper.__init__ÚotherÚobjectÚreturnÚboolc                 C  s   t S r(   )ÚNotImplemented)r+   r0   r.   r.   r/   Ú__eq__5   s   zIntrospectionHelper.__eq__)r&   r'   )r0   r1   r2   r3   )Ú__name__Ú
__module__Ú__qualname__r*   r5   Ú__classcell__r.   r.   r,   r/   r%   -   s    r%   c                      sÔ   e Zd Z					dFdG‡ fdd„ZdHdd„ZdIdd„ZdHdd „ZdJd&d'„ZdHd(d)„ZdKd.d/„Z	dLd0d1„Z
dLd2d3„ZdLd4d5„ZdLd6d7„ZdLd8d9„ZdLd:d;„ZdLd<d=„ZdLd>d?„ZdLd@dA„ZdMdBdC„ZdNdDdE„Z‡  ZS )OÚIntrospectionInterpreterNÚ ÚsubprojectsÚsource_rootr'   ÚsubdirÚbackendÚvisitorsúT.Optional[T.List[AstVisitor]]r&   úT.Optional[str]Ú
subprojectÚsubproject_dirÚenvú#T.Optional[environment.Environment]c	           
        sÌ   |d ur|ng }t ƒ j||||d t|ƒ}	|| _|d u r&t |d |	¡| _n|| _|| _| j ¡ | _|| _	t
dƒ| j	i| _i | _g | _g | _d | _| j | j| j| j| j| j| j| j| j| j| jdœ
¡ d S )N)r@   r?   )
Zadd_languagesZ
dependencyr   r   r    Úprojectr!   r"   r#   r$   )r)   r*   r%   r&   r   ÚEnvironmentrD   Zget_coredatar   r?   r   Údefault_optionsÚproject_dataÚtargetsÚdependenciesÚproject_nodeÚfuncsÚupdateÚfunc_add_languagesÚfunc_dependencyÚfunc_executableÚfunc_jarÚfunc_libraryÚfunc_projectÚfunc_shared_libÚfunc_shared_moduleÚfunc_static_libÚfunc_both_lib)
r+   r=   r>   r?   r@   r&   rC   rD   rE   Úoptionsr,   r.   r/   r*   ;   s6   	öz!IntrospectionInterpreter.__init__Únoder   ÚargsúT.List[TYPE_nvar]ÚkwargsúT.Dict[str, TYPE_nvar]r2   ÚNonec                 C  s  | j rtdƒ‚|| _ t|ƒdk rtdƒ‚|d }| dd¡}|  |dd … ¡}t|tƒr/|j}t|tƒs6d}||dœ| _	t
j | j| jd¡}t
j |¡sVt
j | j| jd	¡}t
j |¡rnt | j¡}| |¡ | j |j¡ |  | d
g ¡¡}	t |	¡}
t |
| j¡| _| j | j¡ | j | j| j| j¡ |   ¡ s³d|v r³|d }t|t!ƒr³t|jtƒs¯J ‚|j| _"|   ¡ sãg | j	d< t
j | j| j"¡}t
j #|¡rãt
 $|¡D ]}t
j #t
j ||¡¡râ|  %|¡ qÐ| j &| j'¡ dd„ | jj (¡ D ƒ}| j )|¡ |  *|dt+j,¡ |  *|dt+j-¡ d S )NzSecond call to project()r   zCNot enough arguments to project(). Needs at least the project name.r   ÚversionZ	undefined)Zdescriptive_namera   zmeson.optionszmeson_options.txtrI   rD   r<   c                 S  s   i | ]\}}|  ¡ r||“qS r.   )Z
is_backend©Ú.0ÚkÚvr.   r.   r/   Ú
<dictcomp>   ó    z9IntrospectionInterpreter.func_project.<locals>.<dictcomp>T).rM   r   ÚlenÚgetÚflatten_argsÚ
isinstancer   Úvaluer'   rJ   ÚosÚpathÚjoinr=   r>   Úexistsr   ZOptionInterpreterrC   Úprocessr   Zupdate_project_optionsrZ   r   ZstringlistifyÚcdataZcreate_options_dictZproject_default_optionsrI   rO   Zset_default_optionsr   Úis_subprojectr   rD   ÚisdirÚlistdirÚdo_subprojectZinit_backend_optionsr?   ÚitemsÚset_optionsÚ_add_languagesr   ÚHOSTÚBUILD)r+   r[   r\   r^   Z	proj_nameZ	proj_versZ
proj_langsZoptfileZoiZdef_optsZ_project_default_optionsZ	spdirnameZsubprojects_dirÚirZ   r.   r.   r/   rU   c   sV   






€z%IntrospectionInterpreter.func_projectÚdirnamec              
   C  s   t j | j ¡ | j¡}t j ||¡}z(t|d| j| j|| j| j| j	d}| 
¡  ||jd< | jd  |jg7  < W d S  tjtfyG   Y d S w )Nr;   )r&   rC   rD   rE   r@   Únamer<   )rm   rn   ro   r   Zget_source_dirrD   r:   r?   r&   r@   ÚanalyzerJ   r   ÚMesonExceptionÚRuntimeError)r+   r}   Zsubproject_dir_absZsubprZsubir.   r.   r/   rv   •   s   "
ÿz&IntrospectionInterpreter.do_subprojectc                 C  s†   |   |¡}| dd¡}t|tjƒr| ¡ }d|v r1| dd¡}|  |||r+tj¡ d S tj	¡ d S tjtj	fD ]	}|  |||¡ q7d S )NÚrequiredTÚnativeF)
Úflatten_kwargsri   rk   rr   ZUserFeatureOptionÚ
is_enabledry   r   r{   rz   )r+   r[   r\   r^   r‚   rƒ   Úfor_machiner.   r.   r/   rP       s   
$ÿz+IntrospectionInterpreter.func_add_languagesÚ	raw_langsr‚   r3   r†   r   c              	   C  sò   g }|   |¡D ]}t|tƒr| |¡ qt|tƒr| |j¡ qt|tjdD ]O}| 	¡ }|| j
j| vrvz	t| j||ƒ}W n tjyK   |rI‚ Y q'w | jrvi }| ¡ D ]}	t | j
j|	 ¡}
|	j| jd}	|
||	< qU| j
 |||| j¡ q'd S )N)Úkey©rC   )rj   rk   r'   Úappendr   rl   Úsortedr   Z
sort_clinkÚlowerr   r   r   r   r€   rC   Zget_optionsÚcopyrZ   ZevolveZadd_compiler_options)r+   r‡   r‚   r†   ZlangsÚlÚlangÚcomprZ   rd   re   r.   r.   r/   ry   ¬   s4   

€û
€ïz'IntrospectionInterpreter._add_languagesc              	   C  sš   |   |¡}|  |¡}|sd S |d }d|v }| dd¡}| dg ¡}t|tƒs*|g}t|tƒr2|j}t|tƒs9d}|  j|||||j	dk|dœg7  _d S )Nr   Úfallbackr‚   Tra   F)r~   r‚   ra   Úhas_fallbackZconditionalr[   )
rj   r„   ri   rk   Úlistr   rl   r3   rL   Zcondition_level)r+   r[   r\   r^   r~   r’   r‚   ra   r.   r.   r/   rQ   Ç   s,   




úz(IntrospectionInterpreter.func_dependencyÚ
kwargs_rawÚtargetclassúT.Type[BuildTarget]úT.Optional[T.Dict[str, T.Any]]c                   s~  ˆ   |¡}|rt|d tƒsd S |d }|g}g }d|v r&|t |d ¡7 }d|v r3|t |d ¡7 }ˆ  |d¡}d‡ fdd	„}	|	|ƒ}
|	|ƒ}‡fd
d„| ¡ D ƒ}dd„ | ¡ D ƒ}dd„ | ¡ D ƒ}tj}g }g }d|d< ˆ|ˆ j	ˆ j
||g |ˆ jˆ jj| |ƒ
}| ¡  | g ¡ | ¡ | ¡ | ¡ tj tj ˆ jˆ j	tj¡¡ˆ j	|j| ¡ | ¡ |
|||dœ}ˆ  j|g7  _|S )Nr   ÚsourcesÚextra_filesTÚinqueueúT.List[BaseNode]r2   c                   s  g }| r‹|   d¡}d }t|tƒsJ ‚t|tƒr|j}n>t|tƒr$|j}n5t|tƒrLt|jtƒs1J ‚|j}|ˆ j	v rKˆ j	| }t|tttfƒrK| |g7 } nt|t
ƒrY| |j|jg7 } |d u r^q|j ¡ }t|tƒrr|jtv rr|  d¡ dd„ |D ƒ}| dd„ |D ƒ7 } |r‰||g7 }| s|S )Nr   c                 S  s   g | ]}t |ttfƒr|‘qS r.   )rk   r'   r   ©rc   Úxr.   r.   r/   Ú
<listcomp>
  rg   zQIntrospectionInterpreter.build_target.<locals>.traverse_nodes.<locals>.<listcomp>c                 S  s"   g | ]}t |ttttfƒr|‘qS r.   )rk   r   r   r   r   rœ   r.   r.   r/   rž     s   " )Úpoprk   r   r   r\   r   r   rl   r'   Zassignmentsr   ÚleftÚrightÚ	argumentsr   Ú	func_nameÚBUILD_TARGET_FUNCTIONS)rš   ÚresÚcurrZarg_nodeÚvar_nameZtmp_nodeZ	arg_nodesZelementary_nodes©r+   r.   r/   Útraverse_nodesð   s<   






€



åz=IntrospectionInterpreter.build_target.<locals>.traverse_nodesc                   s(   i | ]\}}|ˆ j v r|d v r||“qS )>   Zbuild_alwaysÚinstallÚbuild_by_default)Zknown_kwargsrb   )r•   r.   r/   rf     s   ( z9IntrospectionInterpreter.build_target.<locals>.<dictcomp>c                 S  s&   i | ]\}}|t |tƒr|jn|“qS r.   )rk   r   rl   rb   r.   r.   r/   rf     s   & c                 S  s    i | ]\}}t |tƒs||“qS r.   )rk   r   rb   r.   r.   r/   rf     s     Z_allow_no_sources)r~   ÚidÚtypeZ
defined_inr>   r«   Z	installedÚoutputsr˜   r™   r^   r[   )rš   r›   r2   r›   )rj   rk   r'   r   Zlistifyr„   rw   r   rz   r>   rC   r   r   r   Zprocess_compilersZprocess_compilers_lateZget_basenameZget_idZget_typenamerm   rn   Únormpathro   r=   Zbuild_filenamer«   Zshould_installÚget_outputsrK   )r+   r[   r\   r”   r•   r~   ZsrcqueueZextra_queuer^   r©   Zsource_nodesZextraf_nodesZkwargs_reducedr†   ÚobjectsZempty_sourcesÚtargetÚ
new_targetr.   )r+   r•   r/   Úbuild_targetß   sR   
 ÿ
ôz%IntrospectionInterpreter.build_targetc                 C  s\   | j  tdƒ¡}|dkr|  |||t¡S |dkr |  |||t¡S |dkr,|  |||t¡S d S )NÚdefault_libraryÚsharedÚstaticZboth)r   Z
get_optionr   r´   r   r   )r+   r[   r\   r^   rµ   r.   r.   r/   Úbuild_library3  s   z&IntrospectionInterpreter.build_libraryc                 C  ó   |   |||t¡S r(   )r´   r	   ©r+   r[   r\   r^   r.   r.   r/   rR   =  ó   z(IntrospectionInterpreter.func_executablec                 C  r¹   r(   )r´   r   rº   r.   r.   r/   rX   @  r»   z(IntrospectionInterpreter.func_static_libc                 C  r¹   r(   ©r´   r   rº   r.   r.   r/   rV   C  r»   z(IntrospectionInterpreter.func_shared_libc                 C  r¹   r(   r¼   rº   r.   r.   r/   rY   F  r»   z&IntrospectionInterpreter.func_both_libc                 C  r¹   r(   )r´   r   rº   r.   r.   r/   rW   I  r»   z+IntrospectionInterpreter.func_shared_modulec                 C  s   |   |||¡S r(   )r¸   rº   r.   r.   r/   rT   L  s   z%IntrospectionInterpreter.func_libraryc                 C  r¹   r(   )r´   r
   rº   r.   r.   r/   rS   O  r»   z!IntrospectionInterpreter.func_jarc                 C  s¸   d|vrd S |  d¡}t|tƒr|j}|dkr|  |||t¡S |dkr+|  |||t¡S |dkr7|  |||t¡S |dkrC|  |||t¡S |dkrN|  |||¡S |dkrZ|  |||t	¡S d S )NÚtarget_typer   r!   r#   r$   r    r   )
rŸ   rk   r   rl   r´   r	   r   r   r¸   r
   )r+   r[   r\   r^   r½   r.   r.   r/   Úfunc_build_targetR  s$   

z*IntrospectionInterpreter.func_build_targetc                 C  s
   | j dkS )Nr;   r‰   r¨   r.   r.   r/   rs   f  s   
z&IntrospectionInterpreter.is_subprojectc                 C  s$   |   ¡  |  ¡  |  ¡  |  ¡  d S r(   )Zload_root_meson_fileZsanity_check_astZparse_projectÚrunr¨   r.   r.   r/   r   i  s   z IntrospectionInterpreter.analyze)NNr;   r<   N)r=   r'   r>   r'   r?   r'   r@   rA   r&   rB   rC   r'   rD   r'   rE   rF   )r[   r   r\   r]   r^   r_   r2   r`   )r}   r'   r2   r`   )r‡   r]   r‚   r3   r†   r   r2   r`   )
r[   r   r\   r]   r”   r_   r•   r–   r2   r—   )r[   r   r\   r]   r^   r_   r2   r—   )r2   r3   )r2   r`   )r6   r7   r8   r*   rU   rv   rP   ry   rQ   r´   r¸   rR   rX   rV   rY   rW   rT   rS   r¾   rs   r   r9   r.   r.   r,   r/   r:   8   s0    ø
(
2




T









r:   ),Ú
__future__r   Úargparser   rm   ÚtypingÚTr;   r   r   r   r   r   rr   Úbuildr	   r
   r   r   r   r   Zinterpreterbaser   r   r   Zmparserr   r   r   r   r   r   r   Úinterpreterr   ÚTYPE_CHECKINGr   r   Úvisitorr   r¤   Z	Namespacer%   r:   r.   r.   r.   r/   Ú<module>   s(   $