
    ea4                        d dl mZ ddlmZ d dlZeej
                  d<   d dlZd dlZd dl	Z	d dl
Z
ddlmZmZ ddlmZ d Z G d	 d
      Zd Zd Zd Zd Zd Zedk(  r ej.                   e              yy)    )annotations   )_pathlibNpathlib)MesonExceptionMesonBugException)mlogc                    dd l }t         t              rvt        j                          t        j
                         }|)t        j                  dt        j                  |             t        j                  j                  d      r yt        j                  j                  d      r |j                          |dk(  ryt         t              r!t        j                  d        j                  S d}t         fd	d
D              r-t        | j                    j"                   j$                         nt        |       t        j                          y)Nr   z
A full log can be found atMESON_FORCE_BACKTRACEr   	runpython   zeUnhandled python OSError. This is probably not a Meson bug, but an issue with your build environment.zUnhandled python exceptionc              3  <   K   | ]  }t        |d       d u  y wN)getattr).0aes     6/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py	<genexpr>zerrorhandler.<locals>.<genexpr>=   s     Xq71a&d2Xs   )filelinenocolno)	traceback
isinstancer   r	   	exceptionshutdownlogboldosenvironget	print_excOSErrorerrnoallr   r   r   r   )r   commandr   logfilemsgs   `    r   errorhandlerr)       s    !^$q--/HH3TYYw5GH::>>12G ::>>12Gk!7#NN G H77N.CX<WXX%c166188QWWE%c*NN1    c                  :    e Zd Zd Zd	dZd
dZd Zd Zd Zd Z	y)CommandLineParserc                    ddl m}m}m}m}m}m}m}mm	}m
}	m}
m} ddlm} ddlm} dd l}|j%                         j&                   _         fd _        i  _        g  _        t1        j2                  d j*                         _         j4                  j7                  d	d
d       _         j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d|j<                  |j>                  d        j;                  d  fd!j>                  d"        j;                  d#|
j<                  |
j>                  d$        j;                  d%|j<                  |j>                  d&        j;                  d'|j<                  |j>                  d(        j;                  d) j@                   jB                  d*        j;                  d+ jD                   jF                  t0        jH                          j;                  d,|	j<                  |	j>                  t0        jH                         y )-Nr   )mconfmdistminitminstallmintromsetupmtestrewritermsubprojectsmunstable_coredatamcompilemdevenv)	env2mfile)wraptoolr   c                t    t        j                  | t        j                  dz        j                        S )Nr   )max_help_positionwidth)argparseHelpFormatterint
term_width)progselfs    r   <lambda>z,CommandLineParser.__init__.<locals>.<lambda>O   s;    h&<&<TUXY]YhYhklYlUmuy  vE  vE  'F r*   mesonrC   formatter_classCommandsr&   z8If no command is specified it defaults to setup command.)titledestdescriptionsetupzConfigure the project)help_msg	configurezChange project optionsdistzGenerate release archiveinstallzInstall the project
introspectzIntrospect projectinitzCreate a new projecttestz	Run testswrapz
Wrap toolssubprojectszManage subprojectsrewritec                <    j                  | j                        S r   )add_arguments	formatter)parserr5   rD   s    r   rE   z,CommandLineParser.__init__.<locals>.<lambda>h   s    83I3I&RVR`R`3a r*   zModify the project definitioncompilezBuild the projectdevenvz%Run commands in developer environmentr:   z5Convert current environment to a cross or native filehelpzPrint help of a subcommandr   zunstable-coredata)% r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   scriptsr:   rU   r;   shutilget_terminal_sizecolumnsrB   rZ   commandshidden_commandsr?   ArgumentParserr[   add_subparsers
subparsersadd_commandrY   runadd_help_argumentsrun_help_commandadd_runpython_argumentsrun_runpython_commandSUPPRESS)rD   r.   r/   r0   r1   r2   r3   r4   r6   r7   r8   r9   r:   r;   ra   r5   s   `              @r   __init__zCommandLineParser.__init__G   s    	J  	J  	J  	J&" 224<< F!--7DNN[++44:IA{ 5 }&"6"6

"9 	 	;e&9&9599": 	 	=!4!4eii"< 	 	?H$:$:HLL"7 	 	9v';';VZZ"6 	 	8!4!4eii"8 	 	:!4!4eii"- 	 	/!7!7". 	 	0(B(BLDTDT"6 	 	8$ackcoco"A 	 	CH$:$:HLL"5 	 	77#8#8'++"I 	 	Ki&=&=y}}"Y 	 	[ 	!8!8$:O:O"> 	 	@ 	d&B&BDD^D^"*"3"3 	 	5,.@.N.NPbPfPf"*"3"3 	 	5r*   Nc                p   |xs g }|t         j                  k(  r@t        j                  d|z   | j                        }| j                  j                  |       n)| j                  j                  |||| j                        } ||       |j                  |       |g|z   D ]  }|| j                  |<    y )Nzmeson rG   )r^   aliasesrH   )run_func)
r?   ro   rf   rZ   re   appendrh   
add_parserset_defaultsrd   )rD   nameadd_arguments_funcrs   rN   rr   pis           r   ri   zCommandLineParser.add_commandz   s    -R x(((''X_dnn]A  ''-**4haeaoao*pA1	)'! 	!A DMM!	!r*   c                    |j                  dddd       |j                  ddt        j                                |j                  d	       |j                  d
t        j                         y )Nz-c
store_trueeval_argF)actionrK   defaultz	--versionversion)r~   r   script_filescript_args)nargs)add_argumentplatformpython_versionr?   	REMAINDERrD   r[   s     r   rm   z)CommandLineParser.add_runpython_arguments   s_    DJPUVK	8CZCZC\]M*M1C1CDr*   c                R   |j                   t        j                  dd  |j                  rt	        |j
                         ydd l}t        j                  j                  dt        j                  j                  |j
                               |j                  |j
                  d       y)Nr   r   __main__)run_name)r   sysargvr}   execr   runpypathinsertr   dirnamerun_path)rD   optionsr   s      r   rn   z'CommandLineParser.run_runpython_command   sv    **$$%
  HHOOArwww/B/BCDNN7..NDr*   c                n    |j                  ddt        | j                  j                                      y )Nr&   ?)r   choices)r   listrd   keysr   s     r   rk   z$CommandLineParser.add_help_arguments   s)    IS$t}}?Q?Q?S:TUr*   c                    |j                   r(| j                  |j                      j                          y| j                  j                          y)Nr   )r&   rd   
print_helpr[   )rD   r   s     r   rl   z"CommandLineParser.run_help_command   s<    ??MM'//*557  KK""$r*   c                   d}t        | j                  j                               ddgz   }|r|d   |vrd}dg|z   }|d   | j                  v r|d   }| j                  |   }|dd  }n| j                  }d }ddlm} |j                  |      }|j                  |      }||j                  }|d	v xr t        j                  d
k  }	 |j                  |      |rt        j                  dd       |rt        j                  dd       t        j                           S # t"        $ r\}	t%        |	|      cY d }	~	|rt        j                  dd       |rt        j                  dd       t        j                           S d }	~	ww xY w# |rt        j                  dd       |rt        j                  dd       t        j                           w xY w)NFz-hz--helpr   TrM   r   mesonlib>   rT   rM   r\   rQ   )      znRunning the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.)fatalzdYou are using Python 3.6 which is EOL. Starting with v0.62.0, Meson will require Python 3.7 or newer)r   rd   r   re   r[   r_   r   expand_arguments
parse_argsr&   r   version_infors   r	   warningnoticer   	Exceptionr)   )
rD   argsimplicit_setup_command_noticeknown_commandsr&   r[   r   r   !pending_python_deprecation_noticer   s
             r   rj   zCommandLineParser.run   s   (-% dmm0023tX6FFtAwn4,0)9t#D 7d***1gG]]7+F8D[[FG((.##D)?ooG >>\3CSCSV\C\ 	*	##G, - T[`b0 ELQSMMO  	,7++, T[`b0 ELQSMMO	, - T[`b0 ELQSMMOs1   D 	F%E<0F1F <FF AGr   )r[   zargparse.ArgumentParser)
__name__
__module____qualname__rp   ri   rm   rn   rk   rl   rj    r*   r   r,   r,   F   s(    15f!EV*r*   r,   c                l   ddddddd}|j                  | |       }	 t        j                  d|z         }	 |j                  |      S # t        $ r}t	        j
                  |       Y d }~y	d }~ww xY w# t        $ r8}t	        j                  d
|  d       t	        j
                  |       Y d }~y	d }~ww xY w)N	meson_exemeson_installdelwithsuffixgtkdochelperhotdochelperregen_checker)exerQ   	delsuffixgtkdochotdoc
regencheckzmesonbuild.scripts.r   z	Error in z helper script:)	r!   	importlibimport_moduleModuleNotFoundErrorr	   r   rj   r   error)script_namer   
script_mapmodule_namemoduler   s         r   run_script_commandr      s    $,.** /1J ..k:K(()>)LM
zz+&&  q  

Y{m?;<qs.   A A2 	A/A**A/2	B3;.B..B3c                     t         j                  j                  rYt         j                  j                  j                         j	                  d      s!t         j                  j                  d       y y y )NzUTF-surrogateescape)errors)r   stdoutencodingupper
startswithreconfigurer   r*   r   ensure_stdout_accepts_unicoder      sN    
zz3::#6#6#<#<#>#I#I&#Q

&78 $Rr*   c                2    ddl m} |j                  |        y )Nr   r   )r_   r   set_meson_command)mainfiler   s     r   r   r      s    x(r*   c                   t         j                  j                  d      rFdd l}t        t
        t        t        fD ]  }|j                  d|d        |j                  dd       t        j                  d	k\  rSt         j                  j                  d
      r4dd l}|j                  dt        d       |j                  ddt               t                t        j                  dk(  rMt         j                  j                  dd      dvr+t        j                  d       t        j                  d       y| d d  }t!        |      dk\  rL|d   dk(  rD|d   dk(  r*t#        |       ddlm} 	 |j)                  dg|dd  z         S t/        |d   |dd        S t#        |       t1               j)                  |      S # t*        $ r}t-        |d      cY d }~S d }~ww xY w)NMESON_SHOW_DEPRECATIONSr   r   
mesonbuild)categoryr   ignorez.*importlib-resources.*)message)r   
   MESON_RUNNING_IN_PROJECT_TESTSz)UTF-8 Mode affects .*getpreferredencoding)r   r   cygwinMSYSTEMr_   )MSYSr_   zYThis python3 seems to be msys/python on MSYS2 Windows, but you are in a MinGW environmentzYPlease install and use mingw-w64-x86_64-python3 and/or mingw-w64-x86_64-meson with Pacmanr   z
--internalr   
regenerate)r3   z--reconfigurerM   )r   r    r!   warningsDeprecationWarningSyntaxWarningFutureWarningPendingDeprecationWarningfilterwarningsr   r   EncodingWarningr   r   r	   r   lenr   r_   r3   rj   r   r)   r   r,   )original_argsr   r   typr   r3   r   s          r   rj   rj      s   	zz~~/0&}F_` 	PC##Gc,#O	P2KL
7"rzz~~6V'W/,W 	2]hwx
 "# ||xBJJNN9b$A$U

no

noD 4yA~$q'\17l"h' 0zz?"3d12h">?? &d1gtABx88h""4((  0#Aw//0s   +F9 9	GGGGc                 @   dt         j                  v r@t        j                  j	                  t         j                        sJ t         j                  } n0t        j                  j                  t         j                  d         } t        t         j                  dd  |       S )Nz	meson.exer   r   )r   
executabler   r   isabsabspathr   rj   )launchers    r   mainr     sb    cnn$ww}}S^^,,,>>77??388A;/sxx|X&&r*   r   )
__future__r   r_   r   r   modulesos.pathr   r   r   r?   
utils.corer   r   r	   r)   r,   r   r   r   rj   r   r   exitr   r*   r   <module>r      s    #  
!I      9 "LF FP.9)
/)b' zCHHTV r*   