o
    ¢Ùld«9  ã                   @  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 ddlmZmZ ejrWd dlZddd„Zddd„ZG dd„ dejƒZG dd„ dƒZdd„ ZdS )é    )ÚannotationsNé   )Úbuild)Úcoredata)Úenvironment)Úmesonlib)Úmintro)Úmlog)ÚAstIDGenerator)Ú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   úohome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/mconf.pyÚadd_arguments#   s   

ÿ

ÿr   ÚvalúT.AnyúT.Union[str, T.List[T.Any]]c                 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>/   s   € zstringify.<locals>.<genexpr>ú[ú]Ú )Ú
isinstanceÚboolÚstrÚlowerÚlistÚjoin)r    Úsr   r   r   r$   +   s   

r$   c                   @  s   e Zd ZdS )ÚConfExceptionN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r3   7   s    r3   c                   @  s€   e Zd Zdd„ Zdd„ Zd%dd„Zd	d
„ Zd&dd„Zd'dd„Zd&dd„Z	dd„ Z
dd„ Zdd„ Zd(dd„Zd)d d!„Zd"d#„ Zd$S )*ÚConfc                 C  s8  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| jddtƒ gd}| ¡  t ¡  |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ÚrealpathÚ	build_dirÚ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	   Údisabler   ZIntrospectionInterpreterr
   ZanalyzeÚenabler3   )Úselfr=   Zintrr   r   r   Ú__init__<   s0   

zConf.__init__c                 C  s   | j  ¡  d S r#   )r   Zclear_deps_cache©rM   r   r   r   Úclear_cacheZ   s   zConf.clear_cacher   r-   c                 C  s   | j  |¡S r#   )r   Úset_options)rM   Úoptionsr   r   r   rQ   ]   s   zConf.set_optionsc                 C  s   | j rd S t | j| j¡ d S r#   )rI   r   Úsaver=   rO   r   r   r   rS   `   s   z	Conf.saver   c                   s.  t jddd }t|d dƒ}|d|  d }||||dkr |n|f‰ t| j| j| j| jƒD ]f}t|ƒs:t	 
d¡ q.|d rNt|dd	… ƒsNt	 
|d ¡ q.d
d„ }||d ˆ d ƒ}||d ˆ d ƒ}||d ˆ d ƒ}||d ˆ d ƒ}	tj||||	ddD ]‰‡ ‡fdd„tdƒD ƒ}
t	j
|
Ž  q€q.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+   Nc                   sh   t ˆ tjƒr	ˆ jnˆ }| d¡rdnd}tj|ˆ|d}t ˆ tjƒr+‡ fdd„|D ƒ}‡fdd„|D ƒS )Nr)   ú r+   )Úsubsequent_indentc                   s   g | ]	}t  |ˆ j¡‘qS r   )r	   ÚAnsiDecoratorÚcoder%   )Útextr   r   Ú
<listcomp>‰   s    z9Conf.print_aligned.<locals>.wrap_text.<locals>.<listcomp>c                   s$   g | ]}t |ƒd ˆ t|ƒ   ‘qS ©rY   )r.   Úlenr%   )Úwidthr   r   r^   Œ   s   $ )r,   r	   r[   r]   Ú
startswithÚtextwrapÚwrap)r]   ra   ÚrawÚindentÚwrappedr   )r]   ra   r   Ú	wrap_text„   s   z%Conf.print_aligned.<locals>.wrap_texté   )Ú	fillvaluec                   s(   g | ]}ˆ| rˆ| nd ˆ |  ‘qS r_   r   r%   ©Zfour_columnÚlr   r   r^   —   s   ( z&Conf.print_aligned.<locals>.<listcomp>é   )ÚshutilÚget_terminal_sizeÚmaxÚzipr@   rA   rB   rC   Úanyr	   ÚlogÚ	itertoolsÚzip_longestÚrange)rM   Ztotal_widthZ_colZlast_columnÚlinerh   Únamer    ÚchoiceÚdescÚitemsr   rk   r   Úprint_alignedi   s*   
þãzConf.print_alignedrR   ú'coredata.KeyedOptionDictType'ú+T.Dict[str, 'coredata.KeyedOptionDictType']c                 C  s@   i }|  ¡ D ]\}}|jr| j |j¡ || |ji ¡|< q|S r#   )r{   Ú
subprojectrE   ÚaddÚ
setdefault)rM   rR   ÚresultÚkÚor   r   r   Úsplit_options_per_subprojectš   s   z!Conf.split_options_per_subprojectc                 C  sb   t |tjƒrd| j |j |_nd| j | }| j |¡ | j |¡ | j |¡ | j	 |¡ d S )NrY   )
r,   r	   r[   Úprint_marginr]   r@   ÚappendrA   rB   rC   )rM   rx   ÚvalueÚchoicesÚdescrr   r   r   Ú	_add_line¢   s   zConf._add_linec                 C  s6   t |ƒ}t |ƒ}|  t |¡t |¡t |¡|¡ d S r#   )r$   r‹   r	   ZgreenZyellowZblue)rM   rx   rŠ   rˆ   r‰   r   r   r   Ú
add_option¬   s   &zConf.add_optionc                 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	   ZcyanrI   r‹   r`   )rM   ÚtitlerŠ   rˆ   r‰   r   r   r   Ú	add_title±   s   


4zConf.add_titlec                 C  s:   d| _ |  dddd¡ |  t |d ¡ddd¡ d| _ d S )Nr   r+   ú:ri   )r†   r‹   r	   Znormal_yellow)rM   Úsectionr   r   r   Úadd_sectionº   s   
zConf.add_sectionr   r.   c                 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.UserFeatureOptionZauto_featuresz<inherited from main project>)r   ÚTÚcastr   rR   r   Úsortedr{   Úprintable_valueZas_rootZyieldingr   r,   ZUserFeatureOptionZis_autorŒ   r.   Údescriptionr‰   )rM   r   rR   Úautorƒ   r„   r—   Úrootr   r   r   Úprint_optionsÀ   s   
ùzConf.print_optionsr   c                 C  sd  |rt  ¡  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 rV|
||	< qI|	|v r_|
||	< qI|	jru| jrm|	j| jjvrmqI|
||	j |	< qI|	 ¡ r}|
||	< qI|  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rLqC|  d| ¡ ||v r`|  d|| ¡ ||v rp|rp|  d|| ¡ ||v r}|  d|| ¡ ||v r|r|  d|| ¡ ||v rš|  d|| ¡ qC|  ¡  | jr¬t  d¡ |ƒ  |  ¡  d S )Nc                   S  s   t  d¡ t  d¡ d S )NzBThe source directory instead of the build directory was specified.zaOnly the default values for the project are printed, and all command line parameters are ignored.)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 Z	errorlogsZ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   )Z
is_projectr¡   r   r   r   r£   ú   ó    zMain project optionszCore optionszBackend optionsc                 S  r©   r   )Z
is_backendr¡   r   r   r   r£     rª   zBase optionsc                 S  r©   r   )Zis_baser¡   r   r   r   r£     rª   zCompiler optionsz module optionsZDirectorieszTesting optionszProject optionszSubproject )r	   Zstart_pagerrI   rs   rH   r=   rD   r   ZBUILTIN_DIR_OPTIONSr   ÚcollectionsÚdefaultdictÚdictrR   r{   Úmoduler   ÚmodulesÚ
is_builtinr…   r   Zis_cross_buildr“   r›   Úgetr–   rE   r|   Ú"print_nondefault_buildtype_options)rM   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   Ú10ri   )r   Zget_nondefault_buildtype_argsr	   rs   )rM   ZmismatchingÚmr   r   r   r²   "  s   


*ÿz'Conf.print_nondefault_buildtype_optionsN)r   r-   )r   r   )rR   r}   r   r~   )r   r.   rR   r}   r   r   )r   r-   )r4   r5   r6   rN   rP   rQ   rS   r|   r…   r‹   rŒ   r   r“   r›   r´   r²   r   r   r   r   r7   ;   s    

	
1

	

Sr7   c              
   C  s  t  | ¡ tj tj | j¡¡}d }zOt|ƒ}|jr#| 	| j
¡ W dS d}| jr5| | j¡}t  || ¡ n| jr?| ¡  d}n| 	| j
¡ |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 )Nr   FTz(Meson configurator encountered an error:)r   Zparse_cmd_line_optionsr9   r:   r;   r<   r   r7   rI   r´   r   Zcmd_line_optionsrQ   Zupdate_cmd_line_fileÚ
clearcacherP   rS   r   Zupdate_build_optionsr   r   Zinfo_dirZwrite_meson_info_filer3   r	   rs   ÚBrokenPipeError)rR   r   ÚcrS   Úer   r   r   Úrun+  sB   
	ôø
€ýr»   )r   r   r   r   )r    r!   r   r"   )Ú
__future__r   rt   rn   r9   rc   Útypingr”   r«   r+   r   r   r   r   r   r	   Úastr
   r   r   ÚTYPE_CHECKINGÚargparser   r$   ZMesonExceptionr3   r7   r»   r   r   r   r   Ú<module>   s.   

 q