
    e=                    \   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*                  rd dlZej.                  eej2                  f   ZddZddZ G d dej:                        Z G d d      ZddZ ddZ!y)    )annotationsN   )build)coredata)environment)mesonlib)mintro)mlog)AstIDGeneratorIntrospectionInterpreter)MachineChoice	OptionKeyc                    t        j                  |        | j                  ddd       | j                  dddd	       | j                  d
ddd       y )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   register_builtin_argumentsadd_argument)parsers    2/usr/lib/python3/dist-packages/mesonbuild/mconf.pyadd_argumentsr   (   s_    ''/

#s;
|UK  M
]@  B    c                    t        | t              rt        |       j                         S t        | t              rdj                  d | D              }d| dS | yt        |       S )Nz, c              3  2   K   | ]  }t        |        y wN)	stringify).0is     r   	<genexpr>zstringify.<locals>.<genexpr>4   s     0qil0s   [] )
isinstanceboolstrlowerlistjoin)valss     r   r$   r$   0   sY    #t3x~~	C	II0C001#Qx	3xr    c                      e Zd Zy)ConfExceptionN)__name__
__module____qualname__ r    r   r4   r4   <   s    r    r4   c                  t    e Z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dZy)Confc                   t         j                  j                  t         j                  j                  |            | _        dt         j                  j                  | j                        | j                  fv r.t         j                  j                  | j                        | _        d | _        d| _        g | _	        g | _
        g | _        g | _        t               | _        t         j                  j                  t         j                  j!                  | j                  d            rzt        j"                  | j                        | _        | j                  j$                  j'                         | _        | j                  j$                  j*                  | _        d| _        y t         j                  j/                  t         j                  j!                  | j                  t$        j0                              rt3        j4                         5  t         j                  j                  t         j                  j                  | j                              | _        t7        | j(                  ddt9               g      }|j;                          d d d        j*                  | _        d| _        y t=        d	| d
      # 1 sw Y   1xY w)Nzmeson.build<   zmeson-privateFr*   ninja)visitorsTz
Directory zC is neither a Meson build directory nor a project source directory.)ospathabspathrealpath	build_dirbasenamedirnamer   max_choices_line_lengthname_col	value_colchoices_col	descr_colsetall_subprojectsisdirr0   loadr   get_source_dir
source_dirr   default_values_onlyisfilebuild_filenamer
   
no_loggingr   r   analyzer4   )selfrC   intrs      r   __init__zConf.__init__A   s   )9)9))DERWW--dnn=t~~NNWW__T^^<DN
')$)+*,,.*,+.577==dnnoFGDNN3DJ"jj44CCEDO JJ22;;DM',D$WW^^BGGLL9S9STU" "$''//"''2B2B4>>2R"S/WZhZjYkl !MMDM'+D$*YK7z {|| s   
A>J88Kc                8    | j                   j                          y r#   )r   clear_cacherV   s    r   rZ   zConf.clear_cache]   s    !!#r    c                8    | j                   j                  |      S r#   )r   set_options)rV   optionss     r   r]   zConf.set_options`   s    }}((11r    c                r    | j                   ry t        j                  | j                  | j                         y r#   )rQ   r   saverC   r[   s    r   r`   z	Conf.savec   s$    ##dmmT^^4r    c                   t        j                  d      d   }t        |dz  d      }|d|z  z
  dz
  }||||dkD  r|n|f}t        | j                  | j
                  | j                  | j                        D ]  }t        |      st        j                  d       $|d   r't        |dd	       st        j                  |d          Pdd
} ||d   |d         } ||d   |d         } ||d   |d         }	 ||d   |d         }
t        j                  |||	|
d      D ]<  }t        d      D cg c]  }||   r||   nd||   z   }}t        j                  |  >  y	c c}w )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           
        t        | t        j                        r| j                  n| }|j	                  d      rdnd}t        j                  |||      }t        | t        j                        rCt        j                  d|D cg c]"  }t        j                  || j                        $ c}      }nt        j                  d|      }|D cg c]  }t        |      d|t        |      z
  z  z   ! c}S c c}w c c}w )Nr(    r*   )subsequent_indentzT.List[LOGLINE])r+   r
   AnsiDecoratortext
startswithtextwrapwrapTcastcoder-   len)rk   widthrawindentwrapped_r&   wrappeds          r   	wrap_textz%Conf.print_aligned.<locals>.wrap_text   s    #-dD4F4F#GdiiT #s 3#==evN dD$6$67ff%6ck8l^_9K9KAtyy9Y8lmGff%6AG BIIAAA!77II 9m
 Js   'C4
$C9   )	fillvalue   rh   )rk   LOGLINErs   intreturnzmlog.TV_LoggableList)shutilget_terminal_sizemaxziprG   rH   rI   rJ   anyr
   log	itertoolszip_longestrange)rV   total_width_collast_columnfour_columnlinerx   namer1   choicedesclr&   itemss                 r   print_alignedzConf.print_alignedl   sy    ..A!D;!#R(!QX.2T4aTRt~~t7G7GX #	!Dt9 Aws48}a!J$ T!Wk!n5DDG[^4CtAwA7FT!Wk!n5D**4fdbQ !INqRA113Q+??RR% !C#	!D Ss   1E#c                    i }|j                         D ]U  \  }}|j                  r%| j                  j                  |j                         ||j	                  |j                  i       |<   W |S r#   )r   
subprojectrL   add
setdefault)rV   r^   resultkos        r   split_options_per_subprojectz!Conf.split_options_per_subproject   sa    EGMMO 	7DAq||$$((656FallB/2	7 r    c                x   t        |t        j                        r"d| j                  z  |j                  z   |_        nd| j                  z  |z   }| j
                  j                  |       | j                  j                  |       | j                  j                  |       | j                  j                  |       y )Nrh   )
r+   r
   rj   print_marginrk   rG   appendrH   rI   rJ   )rV   r   valuechoicesdescrs        r   	_add_linezConf._add_line   s    dD../d///$));DI***T1DT"e$(e$r    c                    t        |      }t        |      }| j                  t        j                  |      t        j                  |      t        j
                  |      |       y r#   )r$   r   r
   greenyellowblue)rV   r   r   r   r   s        r   
add_optionzConf.add_option   sD    % G$tzz$'U);TYYw=OQVWr    c           	        t        j                  |      }t        j                  d      }t        j                  | j                  rdnd      }t        j                  d      }| j                  dddd       | j                  ||||       | j                  dt	        |      z  dt	        |      z  dt	        |      z  dt	        |      z         y )NDescriptionzDefault ValuezCurrent ValuezPossible Valuesr*   -)r
   cyanrQ   r   rr   )rV   titlenewtitler   r   r   s         r   	add_titlezConf.add_title   s    99U#		-(		T-E-E/?[))-.r2r2&x7sS]*C#e*,<cCL>PRUX[\aXbRbcr    c                    d| _         | j                  dddd       | j                  t        j                  |dz         ddd       d| _         y )Nr   r*   :ry   )r   r   r
   normal_yellow)rV   sections     r   add_sectionzConf.add_section   sE    r2r2&t))'C-8"b"Er    c                X   |sy |r| j                  |       t        j                  d| j                  j                  t        d               }t        |j                               D ]  \  }}|j                         }|j                         }|j                  r&|j                  r|| j                  j                  v rd}t        |t        j                        r |j                         r|j                         }| j                  t!        |      |j"                  ||j$                          y )Nzcoredata.UserFeatureOptionauto_featuresz<inherited from main project>)r   ro   rp   r   r^   r   sortedr   printable_valueas_rootyieldingr   r+   UserFeatureOptionis_autor   r-   descriptionr   )rV   r   r^   autor   r   r   roots           r   print_optionszConf.print_options   s    NN5!vv2DMM4I4I)TcJd4ef7==?+ 	RDAq//1O99;Dzzalltt}}7L7L/L"A!X778QYY["&"6"6"8OOCIq}}oqyyQ	Rr    c           	        |rt        j                          dd}| j                  r |        t        j                  d       t        j                  d       t        j                  d| j                         | j                  s t        j                  d| j
                         t        t        j                        }t        d      t        d      h}i }i }i }t        j                  t              }| j                  j                  j                         D ]}  \  }	}
|	|v r|
||	<   |	|v r|
||	<   |	j                  rB| j                   r#|	j                  | j                   j"                  vrU|
||	j                     |	<   h|	j%                         sy|
||	<    | j'                  |j                         D 	
ci c]%  \  }	}
|	j(                  t*        j,                  u s#|	|
' c}
}	      }| j'                  |j                         D 	
ci c]%  \  }	}
|	j(                  t*        j.                  u s#|	|
' c}
}	      }| j'                  | j                  j                  j                         D 	
ci c]6  \  }	}
|	j1                         s|	j(                  t*        j,                  u s4|	|
8 c}
}	      }| j'                  | j                  j                  j                         D 	
ci c]6  \  }	}
|	j1                         s|	j(                  t*        j.                  u s4|	|
8 c}
}	      }| j'                  | j                  j                  j                         D 	
ci c]  \  }	}
|	j3                         s|	|
 c}
}	      }| j                  xs$ | j                   j4                  j7                         }| j9                  d       | j;                  d	|d          |r| j;                  d|d          | j;                  d
| j                  j                  j                         D 	
ci c]  \  }	}
|	j=                         s|	|
 c}
}	       | j;                  d| j                  j                  j                         D 	
ci c]  \  }	}
|	j?                         s|	|
 c}
}	       | j;                  d|jA                  di              |r"| j;                  d|jA                  di              |j                         D ]  \  }}| j;                  | d|        | j;                  d|       | j;                  d|       | j;                  d|jA                  di              tC        | jD                        D ]  }|dk(  r	| j9                  d|z          ||v r| j;                  d	||          ||v r|r| j;                  d||          ||v r| j;                  d||          ||v r|r| j;                  d||          ||v s| j;                  d||           | jG                          | j                  rt        j                  d        |        | jI                          y c c}
}	w c c}
}	w c c}
}	w c c}
}	w c c}
}	w c c}
}	w c c}
}	w )Nc                 X    t        j                  d       t        j                  d       y )NzBThe source directory instead of the build directory was specified.z4Only the default values for the project are printed.)r
   warningr8   r    r   print_default_values_warningz5Conf.print_conf.<locals>.print_default_values_warning   s    LL]^LLOPr    r*   zCore properties:z  Source dirz  Build dir 	errorlogsstdsplitzMain project optionszCore optionszBackend optionszBase optionszCompiler optionsz module optionsDirectorieszTesting optionszProject optionszSubproject r~   None)%r
   start_pagerrQ   r   rP   rC   rK   r   BUILTIN_DIR_OPTIONSr   collectionsdefaultdictdictr^   r   moduler   modules
is_builtinr   machiner   HOSTBUILDis_compiler
is_projectr   is_cross_buildr   r   
is_backendis_basegetr   rL   r   "print_nondefault_buildtype_options)rV   r   r   dir_option_namestest_option_namesdir_optionstest_optionscore_optionsmodule_optionsr   vhost_core_optionsbuild_core_optionshost_compiler_optionsbuild_compiler_optionsproject_optionsshow_build_optionsmodmod_optionsr   s                       r   
print_confzConf.print_conf   s@   	Q ##(*HHRL#$1''HH^T^^4x;;<&{3&z24 >@>@>@MXMdMdeiMjMM))//1 	$DAq$$!"A''"#Q ::!(($**2D2D"D./qxx(+"#Q	$ !==P\PbPbPd  ?I1hihqhq  vC  vH  vH  iHq!t  ?I  J!>>Q]QcQcQe  @KAijirir  wD  wJ  wJ  jJ1  @K  L $ A ATXTaTaTiTiToToTq  CjDAquv  vC  vC  vE  JK  JS  JS  Wd  Wi  Wi  Ji1a4  Cj  !k!%!B!BUYUbUbUjUjUpUpUr  DlTQPQvw  wD  wD  wF  KL  KT  KT  Xe  Xk  Xk  KkAqD  Dl  "m;;dmmNcNcNiNiNk<~daopo{o{o}QT<~!55`9O9O9^9^9`/0>+<R+@Ar#5b#9:,@U@U@[@[@].p1abamamaoq!t.pq>T]]=R=R=X=X=Z+jTQ^_^g^g^iAqD+jk-/D/H/HR/PQr#9#=#=b"#EF . 4 4 6 	EC#o6D	E=+6,l;,o.A.A"b.IJ !5!56 	SJR]Z78.."">3DZ3PQ//4F""2'9*'EF22""#57LZ7XY338J""2'=j'IJ_,""#4oj6QR	S 	 ##HHRL(*//1U ?I @K Cj Dl<~ /q+js`   4$Y
Y
$Y
)Y
(Y
Y
Y
Y#
6Y#
Y#
Y)
+Y)
Y/3Y/3Y5Y5c                    | j                   j                         }|sy t        j                  d       t        j                  d       |D ])  }t        j                  |d   d|d   d|d   d       + y )NzL
The following option(s) have a different value than the build type default
z                current   defaultr   21r   10ry   )r   get_nondefault_buildtype_argsr
   r   )rV   mismatchingms      r   r   z'Conf.print_nondefault_buildtype_options)  sn    mmAACab34 	5AHH!Ry1b	!A$r34	5r    N)rC   r-   r   )r^   zT.Dict[OptionKey, str]r~   r,   )r^   'coredata.KeyedOptionDictType'r~   z2T.Dict[str, 'coredata.MutableKeyedOptionDictType'])
r   r|   r   r|   r   r|   r   r|   r~   r   )
r   r-   r   r-   r   T.Anyr   r   r~   r   )r   r-   r~   r   )r   r-   r~   r   )r   r-   r^   r   r~   r   )r   r,   r~   r   )r5   r6   r7   rX   rZ   r]   r`   r   r   r   r   r   r   r   r   r   r8   r    r   r:   r:   @   sJ    }8$253!j%X
dRQ2f5r    r:   c                N   | j                    xr | j                   }d }	 t        |      }|j                  r|st	        j
                  d      |j                  s|r|j                  | j                         yd}| j                   r1|j                  | j                         }t        j                  ||        | j                  r|j                          d}|rn|j                          t        j                  |j                  |j                  j                   j"                         t        j$                  |j                  g        y# t&        $ rK}t)        j*                  d       |-|j                  !t        j$                  |j                  |g       |d }~wt,        $ r Y yw xY w)Nz6No valid build directory found, cannot modify options.r   FTz(Meson configurator encountered an error:)cmd_line_options
clearcacher:   rQ   r   MesonExceptionr   r   r]   r   update_cmd_line_filerZ   r`   r	   update_build_optionsr   r   info_dirwrite_meson_info_filer4   r
   r   BrokenPipeError)r^   r   
print_onlycr`   es         r   run_implr   2  sT   ---Hg6H6H2HJAN  ))*bcc  JLL'##==!9!9:D))(G<MMODFFH''

AGG4G4G4P4PQ(("5   ;<=QWW0((1#6 s&   AE 8CE 	F$AFF$#F$c                    t        j                  |        t        j                  j	                  t        j                  j                  | j                              }t        | |      S r#   )r   parse_cmd_line_optionsr?   r@   rA   rB   r   r   )r^   r   s     r   runr  R  sD    ##G,wwrww//0@0@ABHGX&&r    )r   z'argparse.ArgumentParser'r~   r   )r1   r   r~   r-   )r^   argparse.Namespacer   r-   r~   r}   )r^   r  r~   r}   )"
__future__r   r   r   r?   rm   typingro   r   r*   r   r   r   r   r	   r
   astr   r   r   r   TYPE_CHECKINGargparseUnionr-   rj   r|   r   r$   r   r4   r:   r   r  r8   r    r   <module>r	     s    #   	          9 .?? ggc4---.GB		H++ 	p5 p5d@'r    