o
    uJAf¬=  ã                   @  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	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mZ ddlmZmZ ejrad dlZejeejf Zd#dd„Zd$dd„ZG dd„ dejƒZG dd„ dƒZd%dd „Z d&d!d"„Z!dS )'é    )ÚannotationsNé   )Úbuild)Úcoredata)Úenvironment)Úmesonlib)Úmintro)Úmlog)ÚAstIDGeneratorÚIntrospectionInterpreter)ÚMachineChoiceÚ	OptionKeyÚparserú'argparse.ArgumentParser'ÚreturnÚNonec                 C  sB   t  | ¡ | jdddd | jddddd	 | jd
dddd d S )NÚbuilddirú?Ú.)ÚnargsÚdefaultz--clearcacheÚ
store_trueFz,Clear cached state (e.g. found dependencies))Úactionr   Úhelpz
--no-pagerÚstore_falseÚpagerz!Do not redirect output to a pager)r   Údestr   )r   Zregister_builtin_argumentsÚadd_argument)r   © r   ú5/usr/lib/python3.10/site-packages/mesonbuild/mconf.pyÚadd_arguments(   s   

ÿ

ÿr    ÚvalúT.AnyÚstrc                 C  sT   t | tƒrt| ƒ ¡ S t | tƒr d dd„ | D ƒ¡}d|› dS | d u r&dS t| ƒS )Nz, c                 s  s    | ]}t |ƒV  qd S ©N)Ú	stringify©Ú.0Úir   r   r   Ú	<genexpr>4   s   € zstringify.<locals>.<genexpr>ú[ú]Ú )Ú
isinstanceÚboolr#   ÚlowerÚlistÚjoin)r!   Úsr   r   r   r%   0   s   

r%   c                   @  s   e Zd ZdS )ÚConfExceptionN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r3   <   s    r3   c                   @  sŽ   e Zd Zd.dd„Zd/dd„Zd0dd„Zd/dd„Zd/dd„Zd1dd„Zd2dd„Z	d3dd„Z
d4d!d"„Zd5d$d%„Zd6d&d'„Zd7d)d*„Zd/d+d,„Zd-S )8ÚConfÚ	build_dirr#   c                 C  sN  t j t j |¡¡| _dt j | j¡| jfv rt j | j¡| _d | _d| _g | _	g | _
g | _g | _tƒ | _t j t j | jd¡¡rZt | j¡| _| jj ¡ | _| jjj| _d| _d S t j t j | jtj¡¡rŸt ¡ # t j t j | j¡¡| _t| jddtƒ gd}| ¡  W d   ƒ n1 s‘w   Y  |j| _d| _d S td	|› d
ƒ‚)Nzmeson.buildé<   zmeson-privateFr,   Zninja)ZvisitorsTz
Directory zC is neither a Meson build directory nor a project source directory.)ÚosÚpathÚabspathÚrealpathr8   ÚbasenameÚdirnamer   Zmax_choices_line_lengthÚname_colÚ	value_colÚchoices_colÚ	descr_colÚsetÚall_subprojectsÚisdirr1   Úloadr   Zget_source_dirÚ
source_dirr   Údefault_values_onlyÚisfileZbuild_filenamer	   Ú
no_loggingr   r
   Zanalyzer3   )Úselfr8   Zintrr   r   r   Ú__init__A   s0   


ý
zConf.__init__r   r   c                 C  s   | j  ¡  d S r$   )r   Úclear_cache©rL   r   r   r   rN   ]   s   zConf.clear_cacheÚoptionsúT.Dict[OptionKey, str]r.   c                 C  s   | j  |¡S r$   )r   Úset_options)rL   rP   r   r   r   rR   `   s   zConf.set_optionsc                 C  s   | j rd S t | j| j¡ d S r$   )rI   r   Úsaver8   rO   r   r   r   rS   c   s   z	Conf.savec                   s0  t jddd }t|d dƒ}|d|  d }||||dkr |n|f‰ t| j| j| j| jƒD ]g}t|ƒs:t	 
d¡ q.|d rNt|dd	… ƒsNt	 
|d ¡ q.ddd„}||d ˆ d ƒ}||d ˆ d ƒ}||d ˆ d ƒ}||d ˆ d ƒ}	tj||||	ddD ]‰‡ ‡fdd„tdƒD ƒ}
t	j
|
Ž  qq.d	S )aÚ  Do the actual printing.

        This prints the generated output in an aligned, pretty form. it aims
        for a total width of 160 characters, but will use whatever the tty
        reports it's value to be. Though this is much wider than the standard
        80 characters of terminals, and even than the newer 120, compressing
        it to those lengths makes the output hard to read.

        Each column will have a specific width, and will be line wrapped.
        )é    r   )Úfallbackr   é   é   é   r   r,   NÚtextÚLOGLINEÚwidthÚintr   úmlog.TV_LoggableListc                   s~   t ˆ tjƒr	ˆ jnˆ }| d¡rdnd}tj|ˆ|d}t ˆ tjƒr0t d‡ fdd„|D ƒ¡}nt d|¡}‡fdd„|D ƒS )	Nr*   ú r,   )Úsubsequent_indentzT.List[LOGLINE]c                   s   g | ]	}t  |ˆ j¡‘qS r   )r	   ÚAnsiDecoratorÚcoder&   )rY   r   r   Ú
<listcomp>Ž   s    z9Conf.print_aligned.<locals>.wrap_text.<locals>.<listcomp>c                   s$   g | ]}t |ƒd ˆ t|ƒ   ‘qS ©r^   )r#   Úlenr&   )r[   r   r   rb   “   s   $ )	r-   r	   r`   rY   Ú
startswithÚtextwrapÚwrapÚTÚcast)rY   r[   ÚrawÚindentZwrapped_Úwrappedr   )rY   r[   r   Ú	wrap_text‡   s   z%Conf.print_aligned.<locals>.wrap_texté   )Ú	fillvaluec                   s(   g | ]}ˆ| rˆ| nd ˆ |  ‘qS rc   r   r&   ©Zfour_columnÚlr   r   rb   ž   s   ( z&Conf.print_aligned.<locals>.<listcomp>é   )rY   rZ   r[   r\   r   r]   )ÚshutilÚget_terminal_sizeÚmaxÚzipr@   rA   rB   rC   Úanyr	   ÚlogÚ	itertoolsÚzip_longestÚrange)rL   Ztotal_widthZ_colZlast_columnÚlinerm   Únamer!   ÚchoiceÚdescÚitemsr   rp   r   Úprint_alignedl   s*   

þßzConf.print_alignedú'coredata.KeyedOptionDictType'ú2T.Dict[str, 'coredata.MutableKeyedOptionDictType']c                 C  s@   i }|  ¡ D ]\}}|jr| j |j¡ || |ji ¡|< q|S r$   )r€   Ú
subprojectrE   ÚaddÚ
setdefault)rL   rP   ÚresultÚkÚor   r   r   Úsplit_options_per_subproject¡   s   z!Conf.split_options_per_subprojectr}   rZ   ÚvalueÚchoicesÚdescrc                 C  sb   t |tjƒrd| j |j |_nd| j | }| j |¡ | j |¡ | j |¡ | j	 |¡ d S )Nr^   )
r-   r	   r`   Úprint_marginrY   r@   ÚappendrA   rB   rC   )rL   r}   r‹   rŒ   r   r   r   r   Ú	_add_line©   s   zConf._add_liner"   c                 C  s6   t |ƒ}t |ƒ}|  t |¡t |¡t |¡|¡ d S r$   )r%   r   r	   ÚgreenÚyellowÚblue)rL   r}   r   r‹   rŒ   r   r   r   Ú
add_option³   s   &zConf.add_optionÚtitlec                 C  s†   t  |¡}t  d¡}t  | jrdnd¡}t  d¡}|  dddd¡ |  ||||¡ |  dt|ƒ dt|ƒ dt|ƒ dt|ƒ ¡ d S )NÚDescriptionzDefault ValuezCurrent ValuezPossible Valuesr,   ú-)r	   ÚcyanrI   r   rd   )rL   r•   Znewtitler   r‹   rŒ   r   r   r   Ú	add_title¸   s   


4zConf.add_titleÚsectionc                 C  s:   d| _ |  dddd¡ |  t |d ¡ddd¡ d| _ d S )Nr   r,   ú:rn   )rŽ   r   r	   Únormal_yellow)rL   rš   r   r   r   Úadd_sectionÁ   s   
zConf.add_sectionc                 C  s¨   |sd S |r|   |¡ t d| jjtdƒ ¡}t| ¡ ƒD ]4\}}| ¡ }| 	¡ }|j
r7|jr7|| jjv r7d}t|tjƒrE| ¡ rE| ¡ }|  t|ƒ|j||j¡ qd S )Nzcoredata.UserFeatureOptionÚauto_featuresz<inherited from main project>)r™   rh   ri   r   rP   r   Úsortedr€   Úprintable_valueÚas_rootZyieldingr„   r-   ZUserFeatureOptionZis_autor”   r#   ÚdescriptionrŒ   )rL   r•   rP   Úautorˆ   r‰   r    Úrootr   r   r   Úprint_optionsÇ   s   
ùzConf.print_optionsr   c                 C  sf  |rt  ¡  ddd„}| jr|ƒ  t  d¡ t  d¡ t  d| j¡ | js,t  d| j¡ ttjƒ}t	d	ƒt	d
ƒh}i }i }i }t
 t¡}| jj ¡ D ]4\}	}
|	|v rW|
||	< qJ|	|v r`|
||	< qJ|	jrv| jrn|	j| jjvrnqJ|
||	j |	< qJ|	 ¡ r~|
||	< qJ|  dd„ | ¡ D ƒ¡}|  dd„ | ¡ D ƒ¡}|  dd„ | jj ¡ D ƒ¡}|  dd„ | jj ¡ D ƒ¡}|  dd„ | jj ¡ D ƒ¡}| jpÉ| jj ¡ }|  d¡ |  d|d ¡ |rá|  d|d ¡ |  ddd„ | jj ¡ D ƒ¡ |  ddd„ | jj ¡ D ƒ¡ |  d| di ¡¡ |r|  d| di ¡¡ | ¡ D ]\}}|  |› d|¡ q|  d|¡ |  d|¡ |  d| di ¡¡ t| jƒD ]X}|dkrMqD|  d| ¡ ||v ra|  d|| ¡ ||v rq|rq|  d|| ¡ ||v r~|  d|| ¡ ||v rŽ|rŽ|  d|| ¡ ||v r›|  d|| ¡ qD|  ¡  | jr­t  d¡ |ƒ  |  ¡  d S )Nr   r   c                   S  s   t  d¡ t  d¡ d S )NzBThe source directory instead of the build directory was specified.z4Only the default values for the project are printed.)r	   Úwarningr   r   r   r   Úprint_default_values_warningÚ   s   
z5Conf.print_conf.<locals>.print_default_values_warningr,   zCore properties:z  Source dirz  Build dir Ú	errorlogsÚstdsplitc                 S  ó"   i | ]\}}|j tju r||“qS r   )Úmachiner   ÚHOST©r'   rˆ   Úvr   r   r   Ú
<dictcomp>ý   ó   " z#Conf.print_conf.<locals>.<dictcomp>c                 S  rª   r   )r«   r   ÚBUILDr­   r   r   r   r¯   þ   r°   c                 S  ó*   i | ]\}}|  ¡ r|jtju r||“qS r   )Úis_compilerr«   r   r¬   r­   r   r   r   r¯   ÿ   ó   * c                 S  r²   r   )r³   r«   r   r±   r­   r   r   r   r¯      r´   c                 S  ó   i | ]\}}|  ¡ r||“qS r   )Ú
is_projectr­   r   r   r   r¯     ó    zMain project optionszCore optionszBackend optionsc                 S  rµ   r   )Ú
is_backendr­   r   r   r   r¯     r·   zBase optionsc                 S  rµ   r   )Úis_baser­   r   r   r   r¯   	  r·   zCompiler optionsz module optionsZDirectorieszTesting optionszProject optionszSubproject ©r   r   )r	   Ústart_pagerrI   rx   rH   r8   rD   r   ZBUILTIN_DIR_OPTIONSr   ÚcollectionsÚdefaultdictÚdictrP   r€   Úmoduler   ÚmodulesÚ
is_builtinrŠ   r   Zis_cross_buildr   r¥   ÚgetrŸ   rE   r   Ú"print_nondefault_buildtype_options)rL   r   r§   Zdir_option_namesZtest_option_namesZdir_optionsZtest_optionsZcore_optionsZmodule_optionsrˆ   r®   Zhost_core_optionsZbuild_core_optionsZhost_compiler_optionsZbuild_compiler_optionsZproject_optionsZshow_build_optionsÚmodZmod_optionsr„   r   r   r   Ú
print_confÖ   sŒ   



ÿ


€




€
zConf.print_confc                 C  s\   | j  ¡ }|s	d S t d¡ t d¡ |D ]}t |d d›|d d›|d d›¡ qd S )NzL
The following option(s) have a different value than the build type default
z                current   defaultr   Z21r   Ú10rn   )r   Zget_nondefault_buildtype_argsr	   rx   )rL   ZmismatchingÚmr   r   r   rÃ   )  s   


*ÿz'Conf.print_nondefault_buildtype_optionsN)r8   r#   rº   )rP   rQ   r   r.   )rP   r‚   r   rƒ   )
r}   rZ   r‹   rZ   rŒ   rZ   r   rZ   r   r   )
r}   r#   r   r#   r‹   r"   rŒ   r"   r   r   )r•   r#   r   r   )rš   r#   r   r   )r•   r#   rP   r‚   r   r   )r   r.   r   r   )r4   r5   r6   rM   rN   rR   rS   r   rŠ   r   r”   r™   r   r¥   rÅ   rÃ   r   r   r   r   r7   @   s    




	
5




	

Sr7   rP   úargparse.Namespacer   r\   c              
   C  s  | j  o| j }d }zSt|ƒ}|jr|st d¡‚|js|r'| | j¡ W dS d}| j r8| | j ¡}t	 
|| ¡ | jrA| ¡  d}|r[| ¡  t |j	|jjj¡ t |jg ¡ W dS W dS  ty } zt d¡ |d ur{|jd ur{t |j|g¡ |‚d }~w tyŠ   Y dS w )Nz6No valid build directory found, cannot modify options.r   FTz(Meson configurator encountered an error:)Zcmd_line_optionsÚ
clearcacher7   rI   r   ÚMesonExceptionrÅ   r   rR   r   Zupdate_cmd_line_filerN   rS   r   Zupdate_build_optionsr   r   Zinfo_dirZwrite_meson_info_filer3   r	   rx   ÚBrokenPipeError)rP   r   Z
print_onlyÚcrS   Úer   r   r   Úrun_impl2  sB   


	ôø
€ýrÎ   c                 C  s*   t  | ¡ tj tj | j¡¡}t| |ƒS r$   )r   Zparse_cmd_line_optionsr:   r;   r<   r=   r   rÎ   )rP   r   r   r   r   ÚrunR  s   

rÏ   )r   r   r   r   )r!   r"   r   r#   )rP   rÈ   r   r#   r   r\   )rP   rÈ   r   r\   )"Ú
__future__r   ry   rs   r:   rf   Útypingrh   r¼   r,   r   r   r   r   r   r	   Úastr
   r   r   r   ÚTYPE_CHECKINGÚargparseÚUnionr#   r`   rZ   r    r%   rÊ   r3   r7   rÎ   rÏ   r   r   r   r   Ú<module>   s2   

 
s 