
Y                @   s  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 d  d	 l	 m	 Z	 m
 Z
 d  d
 l  m Z d  d l m Z m Z m Z d  d l m Z d  d l 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 m Z m Z d  d l m Z m Z 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& m' Z' d d l( Z( d a) d d   Z* Gd d   d e  Z+ Gd d   d e  Z, Gd d   d e  Z- Gd d    d  e  Z. Gd! d"   d" e  Z/ Gd# d$   d$ e  Z0 Gd% d&   d& e  Z1 Gd' d(   d( e  Z2 Gd) d*   d* e  Z3 Gd+ d,   d, e  Z4 Gd- d.   d. e  Z5 Gd/ d0   d0 e  Z6 Gd1 d2   d2 e  Z7 Gd3 d4   d4 e  Z8 Gd5 d6   d6 e  Z9 Gd7 d8   d8 e  Z: Gd9 d:   d: e  Z; Gd; d<   d< e  Z< Gd= d>   d> e  Z= Gd? d@   d@ e  Z> GdA dB   dB e>  Z? GdC dD   dD e?  Z@ GdE dF   dF e?  ZA GdG dH   dH e?  ZB GdI dJ   dJ e?  ZC GdK dL   dL e?  ZD GdM dN   dN e>  ZE GdO dP   dP e  ZF GdQ dR   dR e  ZG GdS dT   dT e  ZH GdU dV   dV e  ZI e' dW dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de df dg dh g  ZJ Gdi dj   dj e  ZK Gdk dl   dl e  ZL eM dm dn g  ZN eM do dp dq dr ds dt du dv dw g	  ZO eM dx dy dz g  ZP eM d{ g  ZQ eM d| g  ZR eM d} d~ d d d d d d d d d d d d d d d d d d d d g  ZS eS eO BeN BeP BeQ BeR BZT eT d h BZU eT d d h BZV eV ZW eV ZX eU jY   ZZ eZ j[ d g  eU jY   Z\ e\ j[ d g  i d h d 6d h d 6d h d 6d h d 6d h d 6d d d d h d 6d d d d d d h d 6e\ d 6d d d d d d d h d 6d d d d d d d d d d d} h d 6d d d d d d d h d 6eU d 6d h d 6d d d h d 6d h d 6d d d h d 6d dY h d 6d h d 6d d d d h d 6eZ d 6d d d d d h d 6d d h d 6eV d 6eW d 6eX d 6d d h d 6d d d d d d d h d 6d d d d d h d 6Z] Gd d   d e  Z^ d S)   )mparser)environment)coredata)dependencies)mlog)build)optinterpreter)	compilers)wrapWrapMode)mesonlib)FileMode
Popen_safeget_meson_script)ExternalProgram)InternalDependency
DependencyDependencyException)InterpreterBase)check_stringlist	noPosargsnoKwargs
stringArgspermittedKwargs)InterpreterExceptionInvalidArgumentsInvalidCode)InterpreterObjectMutableInterpreterObject)ModuleReturnValue    N)
namedtupleFc             C   sm   t  |  t  r- d d j d d   |  D  St  |  t  rF t |   St  |  t  r] d |  St d   d  S)Nz[%s]z, c             S   s   g  |  ] } t  |   q S )stringifyUserArguments).0xr"   r"   R/mnt/raid6/a/bak/reczko/tools/protein/utils/meson-0.42.1/mesonbuild/interpreter.py
<listcomp>+   s   	 z*stringifyUserArguments.<locals>.<listcomp>z'%s'zAFunction accepts only strings, integers, lists and lists thereof.)
isinstancelistjoinintstrr   )argsr"   r"   r&   r#   )   s    
r#   c                   sR   e  Z d  Z   f d d   Z d d   Z d d   Z d d   Z d	 d
   Z   S)TryRunResultHolderc                sR   t    j   | |  _ |  j j i |  j d 6|  j d 6|  j d 6|  j d 6 d  S)N
returncodecompiledstdoutstderr)	super__init__resmethodsupdatereturncode_methodcompiled_methodstdout_methodstderr_method)selfr5   )	__class__r"   r&   r4   4   s    	

zTryRunResultHolder.__init__c             C   s
   |  j  j S)N)r5   r/   )r<   r-   kwargsr"   r"   r&   r8   =   s    z$TryRunResultHolder.returncode_methodc             C   s
   |  j  j S)N)r5   r0   )r<   r-   r>   r"   r"   r&   r9   @   s    z"TryRunResultHolder.compiled_methodc             C   s
   |  j  j S)N)r5   r1   )r<   r-   r>   r"   r"   r&   r:   C   s    z TryRunResultHolder.stdout_methodc             C   s
   |  j  j S)N)r5   r2   )r<   r-   r>   r"   r"   r&   r;   F   s    z TryRunResultHolder.stderr_method)__name__
__module____qualname__r4   r8   r9   r:   r;   r"   r"   )r=   r&   r.   3   s
   	r.   c                   sU   e  Z d  Z d   f d d  Z d d   Z d d   Z d d	   Z d
 d   Z   S)
RunProcessFc       	         s   t    j   t | t  s+ t d   n  |  j | | | | | | |  \ } |  _ |  _ | j |  _ |  j	 j
 i |  j d 6|  j d 6|  j d 6 d  S)Nz1BUG: RunProcess must be passed an ExternalProgramr/   r1   r2   )r3   r4   r(   r   AssertionErrorrun_commandr1   r2   r/   r6   r7   r8   r:   r;   )	r<   cmdr-   
source_dir	build_dirsubdirmesonintrospectin_builddirpc)r=   r"   r&   r4   K   s    0
zRunProcess.__init__c             C   s   | j    | } i | d 6| d 6| d 6| d 6}	 | rP t j j | |  }
 n t j j | |  }
 t j j   } | j |	  t j d d j |   y t	 | d | d |
 SWn+ t
 k
 r t d	 d j |    Yn Xd  S)
NZMESON_SOURCE_ROOTZMESON_BUILD_ROOTZMESON_SUBDIRZMESONINTROSPECTzRunning command: envcwdzCould not execute command "%s".)get_commandospathr*   environcopyr7   r   debugr   FileNotFoundErrorr   )r<   rE   r-   rF   rG   rH   rI   rJ   Zcommand_arrayrM   rN   Z	child_envr"   r"   r&   rD   V   s    

zRunProcess.run_commandc             C   s   |  j  S)N)r/   )r<   r-   r>   r"   r"   r&   r8   h   s    zRunProcess.returncode_methodc             C   s   |  j  S)N)r1   )r<   r-   r>   r"   r"   r&   r:   k   s    zRunProcess.stdout_methodc             C   s   |  j  S)N)r2   )r<   r-   r>   r"   r"   r&   r;   n   s    zRunProcess.stderr_method)r?   r@   rA   r4   rD   r8   r:   r;   r"   r"   )r=   r&   rB   I   s
   rB   c               @   s   e  Z d  Z d d   Z d S)ConfigureFileHolderc             C   s,   t  j |   t j | | | |  |  _ d  S)N)r   r4   r   ZConfigureFileheld_object)r<   rH   Z
sourcenameZ
targetnameconfiguration_datar"   r"   r&   r4   s   s    zConfigureFileHolder.__init__N)r?   r@   rA   r4   r"   r"   r"   r&   rV   q   s   rV   c                   sd   e  Z d  Z   f d d   Z d d   Z e d d    Z d d   Z d	 d
   Z d d   Z	   S)EnvironmentVariablesHolderc                sN   t    j   t j   |  _ |  j j i |  j d 6|  j d 6|  j	 d 6 d  S)Nsetappendprepend)
r3   r4   r   ZEnvironmentVariablesrW   r6   r7   
set_methodappend_methodprepend_method)r<   )r=   r"   r&   r4   y   s
    
z#EnvironmentVariablesHolder.__init__c             C   s"   d } | j  |  j j |  j j  S)Nz
<{0}: {1}>)formatr=   r?   rW   envvars)r<   repr_strr"   r"   r&   __repr__   s    z#EnvironmentVariablesHolder.__repr__c             C   s|   t  | j d d  t  s* t d   n  t |  d k  rK t d   n  |  j j j | | d | d d   | f  d  S)NZ	separator zMEnvironmentVariablesHolder methods 'separator' argument needs to be a string.   z~EnvironmentVariablesHolder methods require at least2 arguments, first is the name of the variable and following one are valuesr    r   )r(   getr,   r   lenrW   ra   r[   )r<   methodr-   r>   r"   r"   r&   add_var   s
    z"EnvironmentVariablesHolder.add_varc             C   s   |  j  |  j j | |  d  S)N)ri   rW   rZ   )r<   r-   r>   r"   r"   r&   r]      s    z%EnvironmentVariablesHolder.set_methodc             C   s   |  j  |  j j | |  d  S)N)ri   rW   r[   )r<   r-   r>   r"   r"   r&   r^      s    z(EnvironmentVariablesHolder.append_methodc             C   s   |  j  |  j j | |  d  S)N)ri   rW   r\   )r<   r-   r>   r"   r"   r&   r_      s    z)EnvironmentVariablesHolder.prepend_method)
r?   r@   rA   r4   rc   r   ri   r]   r^   r_   r"   r"   )r=   r&   rY   x   s   rY   c                   s   e  Z d  Z   f 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   S)ConfigurationDataHolderc                su   t    j   d |  _ t j   |  _ |  j j i |  j d 6|  j	 d 6|  j
 d 6|  j d 6|  j d 6|  j d 6 d  S)NFrZ   Zset10Z
set_quotedZhasrf   Z
merge_from)r3   r4   usedr   ZConfigurationDatarW   r6   r7   r]   set10_methodset_quoted_method
has_method
get_methodmerge_from_method)r<   )r=   r"   r&   r4      s    	



z ConfigurationDataHolder.__init__c             C   s   |  j  S)N)rk   )r<   r"   r"   r&   is_used   s    zConfigurationDataHolder.is_usedc             C   s   d |  _  d  S)NT)rk   )r<   r"   r"   r&   	mark_used   s    z!ConfigurationDataHolder.mark_usedc             C   s   t  |  d k r! t d   n  |  j r9 t d   n  | d } | d } | j d d   } t | t  s} t d   n  | d  k	 r t | t  r t d   n  | | | f S)	Nre   z'Configuration set requires 2 arguments.z>Can not set values on configuration object that has been used.r    r   descriptionz'First argument to set must be a string.zDescription must be a string.)rg   r   rk   rf   r(   r,   )r<   r-   r>   namevaldescr"   r"   r&   validate_args   s    	

z%ConfigurationDataHolder.validate_argsc             C   s5   |  j  | |  \ } } } | | f |  j j | <d  S)N)rw   rW   values)r<   r-   r>   rt   ru   rv   r"   r"   r&   r]      s    z"ConfigurationDataHolder.set_methodc             C   ss   |  j  | |  \ } } } t | t  s9 t d   n  d j | j d   } d | d | f |  j j | <d  S)Nz/Second argument to set_quoted must be a string.z\"")rw   r(   r,   r   r*   splitrW   rx   )r<   r-   r>   rt   ru   rv   Zescaped_valr"   r"   r&   rm      s
    z)ConfigurationDataHolder.set_quoted_methodc             C   sT   |  j  | |  \ } } } | r: d | f |  j j | <n d | f |  j j | <d  S)Nr   r    )rw   rW   rx   )r<   r-   r>   rt   ru   rv   r"   r"   r&   rl      s    z$ConfigurationDataHolder.set10_methodc             C   s   | d |  j  j k S)Nr    )rW   rx   )r<   r-   r>   r"   r"   r&   rn      s    z"ConfigurationDataHolder.has_methodc             C   s   t  |  d k  s$ t  |  d k r3 t d   n  | d } | |  j k r` |  j j |  d St  |  d k rz | d St d |   d  S)Nr   re   z&Get method takes one or two arguments.r    z#Entry %s not in configuration data.)rg   r   rW   rf   )r<   r-   r>   rt   r"   r"   r&   ro      s    $
z"ConfigurationDataHolder.get_methodc             C   s   |  j  j | S)N)rW   rx   )r<   rt   r"   r"   r&   rf      s    zConfigurationDataHolder.getc             C   s   |  j  j j   S)N)rW   rx   keys)r<   r"   r"   r&   r{      s    zConfigurationDataHolder.keysc             C   s   t  |  d k r! t d   n  | d } t | t  sI t d   n  | j } x- | j j   D] \ } } | |  j j | <qb Wd  S)Nr   z)Merge_from takes one positional argument.r    z8Merge_from argument must be a configuration data object.)rg   r   r(   rj   rW   rx   items)r<   r-   r>   Zfrom_objectkvr"   r"   r&   rp      s    
	z)ConfigurationDataHolder.merge_from_method)r?   r@   rA   r4   rq   rr   rw   r]   rm   rl   rn   ro   rf   r{   rp   r"   r"   )r=   r&   rj      s   
rj   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)DependencyHolderc             C   sR   t  j |   | |  _ |  j j i |  j d 6|  j d 6|  j d 6|  j d 6 d  S)Nfound	type_nameversionget_pkgconfig_variable)	r   r4   rW   r6   r7   found_methodtype_name_methodversion_methodpkgconfig_method)r<   depr"   r"   r&   r4      s    	

zDependencyHolder.__init__c             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r      s    z!DependencyHolder.type_name_methodc             C   s#   |  j  j d k r d S|  j  j   S)NZinternalT)rW   r   r   )r<   r-   r>   r"   r"   r&   r      s    zDependencyHolder.found_methodc             C   s   |  j  j   S)N)rW   get_version)r<   r-   r>   r"   r"   r&   r      s    zDependencyHolder.version_methodc             C   st   t  | t  s | g } n  t |  d k r< t d   n  | d } t  | t  sd t d   n  |  j j |  S)Nr   z2get_pkgconfig_variable takes exactly one argument.r    zVariable name must be a string.)r(   r)   rg   r   r,   rW   r   )r<   r-   r>   varnamer"   r"   r&   r     s    
z!DependencyHolder.pkgconfig_methodN)r?   r@   rA   r4   r   r   r   r   r"   r"   r"   r&   r      s
   	r   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)InternalDependencyHolderc             C   s>   t  j |   | |  _ |  j j i |  j d 6|  j d 6 d  S)Nr   r   )r   r4   rW   r6   r7   r   r   )r<   r   r"   r"   r&   r4     s    	z!InternalDependencyHolder.__init__c             C   s   d S)NTr"   )r<   r-   r>   r"   r"   r&   r     s    z%InternalDependencyHolder.found_methodc             C   s   |  j  j   S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    z'InternalDependencyHolder.version_methodN)r?   r@   rA   r4   r   r   r"   r"   r"   r&   r     s   r   c               @   sX   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d S)ExternalProgramHolderc             C   s>   t  j |   | |  _ |  j j i |  j d 6|  j d 6 d  S)Nr   rQ   )r   r4   rW   r6   r7   r   path_method)r<   Zepr"   r"   r&   r4     s    	zExternalProgramHolder.__init__c             C   s
   |  j    S)N)r   )r<   r-   r>   r"   r"   r&   r   "  s    z"ExternalProgramHolder.found_methodc             C   s   |  j  j   S)N)rW   get_path)r<   r-   r>   r"   r"   r&   r   %  s    z!ExternalProgramHolder.path_methodc             C   s   |  j  j   S)N)rW   r   )r<   r"   r"   r&   r   (  s    zExternalProgramHolder.foundc             C   s   |  j  j   S)N)rW   rO   )r<   r"   r"   r&   rO   +  s    z!ExternalProgramHolder.get_commandc             C   s   |  j  j   S)N)rW   get_name)r<   r"   r"   r&   r   .  s    zExternalProgramHolder.get_nameN)	r?   r@   rA   r4   r   r   r   rO   r   r"   r"   r"   r&   r     s   r   c               @   sd   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 S)ExternalLibraryHolderc             C   s4   t  j |   | |  _ |  j j i |  j d 6 d  S)Nr   )r   r4   rW   r6   r7   r   )r<   elr"   r"   r&   r4   2  s    	zExternalLibraryHolder.__init__c             C   s   |  j  j   S)N)rW   r   )r<   r"   r"   r&   r   7  s    zExternalLibraryHolder.foundc             C   s
   |  j    S)N)r   )r<   r-   r>   r"   r"   r&   r   :  s    z"ExternalLibraryHolder.found_methodc             C   s
   |  j  j S)N)rW   rt   )r<   r"   r"   r&   r   =  s    zExternalLibraryHolder.get_namec             C   s   |  j  j   S)N)rW   get_compile_args)r<   r"   r"   r&   r   @  s    z&ExternalLibraryHolder.get_compile_argsc             C   s   |  j  j   S)N)rW   get_link_args)r<   r"   r"   r&   r   C  s    z#ExternalLibraryHolder.get_link_argsc             C   s   |  j  j   S)N)rW   get_exe_args)r<   r"   r"   r&   r   F  s    z"ExternalLibraryHolder.get_exe_argsN)
r?   r@   rA   r4   r   r   r   r   r   r   r"   r"   r"   r&   r   1  s   r   c                   s.   e  Z d  Z   f d d   Z d d   Z   S)GeneratorHolderc                sI   t    j   | |  _ t j | |  |  _ |  j j i |  j d 6 d  S)Nprocess)	r3   r4   interpreterr   	GeneratorrW   r6   r7   process_method)r<   r   r-   r>   )r=   r"   r&   r4   J  s    	zGeneratorHolder.__init__c             C   sF   t  j | j d g    } |  j j d | |  j d | } t |  S)N
extra_argsr   )r   stringlistifyrf   rW   Zprocess_filesr   GeneratedListHolder)r<   r-   r>   extrasglr"   r"   r&   r   P  s    !zGeneratorHolder.process_method)r?   r@   rA   r4   r   r"   r"   )r=   r&   r   I  s   r   c                   s=   e  Z d  Z g    f d d  Z d d   Z d d   Z   S)r   c                sD   t    j   t | t  r7 t j | j |  |  _ n	 | |  _ d  S)N)r3   r4   r(   r   r   GeneratedListrW   )r<   Zarg1r   )r=   r"   r&   r4   W  s    zGeneratedListHolder.__init__c             C   s%   d } | j  |  j j |  j j    S)Nz
<{}: {!r}>)r`   r=   r?   rW   Zget_outputs)r<   rr"   r"   r&   rc   ^  s    zGeneratedListHolder.__repr__c             C   s   |  j  j |  d  S)N)rW   add_file)r<   ar"   r"   r&   r   b  s    zGeneratedListHolder.add_file)r?   r@   rA   r4   rc   r   r"   r"   )r=   r&   r   V  s   r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)BuildMachinec             C   s   | |  _  t j |   t j t j   t j |  j   t j |  j   t j	  |  _
 |  j j i |  j d 6|  j d 6|  j d 6|  j d 6 d  S)Nsystem
cpu_familycpuendian)r	   r   r4   r   MachineInfodetect_systemdetect_cpu_family
detect_cpusys	byteorderrW   r6   r7   system_methodcpu_family_method
cpu_methodendian_method)r<   r	   r"   r"   r&   r4   f  s    	

zBuildMachine.__init__c             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r   s  s    zBuildMachine.cpu_family_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r   v  s    zBuildMachine.cpu_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r   y  s    zBuildMachine.system_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r   |  s    zBuildMachine.endian_methodN)r?   r@   rA   r4   r   r   r   r   r"   r"   r"   r&   r   e  s
   r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)CrossMachineInfoc             C   s   t  j |   d d d d h } t |  | k  r` t d j |  d j | t |     n  | |  _ t j | d | d | d | d  |  _ |  j	 j
 i |  j d 6|  j d 6|  j d 6|  j d 6 d  S)Nr   r   r   r   zMachine info is currently {}
zbut is missing {}.)r   r4   rZ   r   r`   infor   r   rW   r6   r7   r   r   r   r   )r<   
cross_infoZminimum_cross_infor"   r"   r&   r4     s     	

zCrossMachineInfo.__init__c             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    z"CrossMachineInfo.cpu_family_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    zCrossMachineInfo.cpu_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    zCrossMachineInfo.system_methodc             C   s
   |  j  j S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    zCrossMachineInfo.endian_methodN)r?   r@   rA   r4   r   r   r   r   r"   r"   r"   r&   r     s
   r   c                   s"   e  Z d  Z   f d d   Z   S)IncludeDirsHolderc                s   t    j   | |  _ d  S)N)r3   r4   rW   )r<   Zidobj)r=   r"   r&   r4     s    zIncludeDirsHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r     s   r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)Headersc             C   sw   t  j |   | |  _ | j d d  |  _ | j d d   |  _ |  j d  k	 rs t |  j t  ss t d   qs n  d  S)NrH   rd   install_dirz$Custom_install_dir must be a string.)	r   r4   sourcesrf   install_subdircustom_install_dirr(   r,   r   )r<   r   r>   r"   r"   r&   r4     s    	zHeaders.__init__c             C   s   | |  _  d  S)N)r   )r<   rH   r"   r"   r&   set_install_subdir  s    zHeaders.set_install_subdirc             C   s   |  j  S)N)r   )r<   r"   r"   r&   get_install_subdir  s    zHeaders.get_install_subdirc             C   s   |  j  S)N)r   )r<   r"   r"   r&   get_sources  s    zHeaders.get_sourcesc             C   s   |  j  S)N)r   )r<   r"   r"   r&   get_custom_install_dir  s    zHeaders.get_custom_install_dirN)r?   r@   rA   r4   r   r   r   r   r"   r"   r"   r&   r     s
   	r   c                   sF   e  Z d  Z   f d d   Z d d   Z d d   Z d d   Z   S)	
DataHolderc                s   t    j   | |  _ d  S)N)r3   r4   rW   )r<   data)r=   r"   r&   r4     s    zDataHolder.__init__c             C   s
   |  j  j S)N)rW   source_subdir)r<   r"   r"   r&   get_source_subdir  s    zDataHolder.get_source_subdirc             C   s
   |  j  j S)N)rW   r   )r<   r"   r"   r&   r     s    zDataHolder.get_sourcesc             C   s
   |  j  j S)N)rW   r   )r<   r"   r"   r&   get_install_dir  s    zDataHolder.get_install_dir)r?   r@   rA   r4   r   r   r   r"   r"   )r=   r&   r     s   r   c               @   s   e  Z d  Z d d   Z d S)
InstallDirc             C   s>   t  j |   | |  _ | |  _ | |  _ | |  _ | |  _ d  S)N)r   r4   r   Zinstallable_subdirr   install_modeexclude)r<   Z
src_subdirZinst_subdirr   r   r   r"   r"   r&   r4     s    				zInstallDir.__init__N)r?   r@   rA   r4   r"   r"   r"   r&   r     s   r   c               @   s@   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 S)
Manc             C   sj   t  j |   | |  _ |  j   | j d d   |  _ |  j d  k	 rf t |  j t  rf t d   n  d  S)Nr   z$Custom_install_dir must be a string.)	r   r4   r   validate_sourcesrf   r   r(   r,   r   )r<   r   r>   r"   r"   r&   r4     s    	
"zMan.__init__c             C   s}   xv |  j  D]k } y t | j d  d  } Wn t t f k
 rM d } Yn X| d k  sf | d k r
 t d   q
 q
 Wd  S)N.r   r       z?Man file must have a file extension of a number between 1 and 8)r   r+   rz   
IndexError
ValueErrorr   )r<   sZnumr"   r"   r&   r     s    zMan.validate_sourcesc             C   s   |  j  S)N)r   )r<   r"   r"   r&   r     s    zMan.get_custom_install_dirc             C   s   |  j  S)N)r   )r<   r"   r"   r&   r     s    zMan.get_sourcesN)r?   r@   rA   r4   r   r   r   r"   r"   r"   r&   r     s   	r   c                   s"   e  Z d  Z   f d d   Z   S)GeneratedObjectsHolderc                s   t    j   | |  _ d  S)N)r3   r4   rW   )r<   rW   )r=   r"   r&   r4     s    zGeneratedObjectsHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r     s   r   c                   s"   e  Z d  Z   f d d   Z   S)TargetHolderc                s   t    j   d  S)N)r3   r4   )r<   )r=   r"   r&   r4     s    zTargetHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r     s   r   c                   s   e  Z d  Z   f 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   S)BuildTargetHolderc                so   t    j   | |  _ | |  _ |  j j i |  j d 6|  j d 6|  j d 6|  j	 d 6|  j
 d 6|  j d 6 d  S)Nextract_objectsextract_all_objectsget_idZoutdir	full_pathZprivate_dir_include)r3   r4   rW   r   r6   r7   extract_objects_methodextract_all_objects_methodget_id_methodoutdir_methodfull_path_methodprivate_dir_include_method)r<   targetinterp)r=   r"   r&   r4     s    		



zBuildTargetHolder.__init__c             C   s1   d } |  j  } | j |  j j | j   | j  S)Nz<{} {}: {}>)rW   r`   r=   r?   r   filename)r<   r   hr"   r"   r&   rc     s    	zBuildTargetHolder.__repr__c             C   s   |  j  j   S)N)rW   is_cross)r<   r"   r"   r&   r     s    zBuildTargetHolder.is_crossc             C   s1   t  t j d g  d |  j j j |  j  g   S)Nrd   F)r   r   IncludeDirsr   backendZget_target_private_dirrW   )r<   r-   r>   r"   r"   r&   r   
  s    z,BuildTargetHolder.private_dir_include_methodc             C   s   |  j  j j |  j  S)N)r   r   get_target_filename_absrW   )r<   r-   r>   r"   r"   r&   r     s    z"BuildTargetHolder.full_path_methodc             C   s   |  j  j j |  j  S)N)r   r   Zget_target_dirrW   )r<   r-   r>   r"   r"   r&   r     s    zBuildTargetHolder.outdir_methodc             C   s   |  j  j |  } t |  S)N)rW   r   r   )r<   r-   r>   gobjsr"   r"   r&   r     s    z(BuildTargetHolder.extract_objects_methodc             C   s   |  j  j   } t |  S)N)rW   r   r   )r<   r-   r>   r   r"   r"   r&   r     s    z,BuildTargetHolder.extract_all_objects_methodc             C   s   |  j  j   S)N)rW   r   )r<   r-   r>   r"   r"   r&   r     s    zBuildTargetHolder.get_id_method)r?   r@   rA   r4   rc   r   r   r   r   r   r   r   r"   r"   )r=   r&   r     s   r   c                   s"   e  Z d  Z   f d d   Z   S)ExecutableHolderc                s   t    j | |  d  S)N)r3   r4   )r<   r   r   )r=   r"   r&   r4      s    zExecutableHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r     s   r   c                   s"   e  Z d  Z   f d d   Z   S)StaticLibraryHolderc                s   t    j | |  d  S)N)r3   r4   )r<   r   r   )r=   r"   r&   r4   $  s    zStaticLibraryHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r   #  s   r   c                   s"   e  Z d  Z   f d d   Z   S)SharedLibraryHolderc                s   t    j | |  d  S)N)r3   r4   )r<   r   r   )r=   r"   r&   r4   (  s    zSharedLibraryHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r   '  s   r   c                   s"   e  Z d  Z   f d d   Z   S)SharedModuleHolderc                s   t    j | |  d  S)N)r3   r4   )r<   r   r   )r=   r"   r&   r4   ,  s    zSharedModuleHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r   +  s   r   c                   s"   e  Z d  Z   f d d   Z   S)	JarHolderc                s   t    j | |  d  S)N)r3   r4   )r<   r   r   )r=   r"   r&   r4   0  s    zJarHolder.__init__)r?   r@   rA   r4   r"   r"   )r=   r&   r   /  s   r   c                   s:   e  Z d  Z   f d d   Z d d   Z d d   Z   S)CustomTargetHolderc                s=   t    j   | |  _ | |  _ |  j j i |  j d 6 d  S)Nr   )r3   r4   rW   r   r6   r7   r   )r<   Zobject_to_holdr   )r=   r"   r&   r4   4  s    		zCustomTargetHolder.__init__c             C   s1   d } |  j  } | j |  j j | j   | j  S)Nz<{} {}: {}>)rW   r`   r=   r?   r   command)r<   r   r   r"   r"   r&   rc   ;  s    	zCustomTargetHolder.__repr__c             C   s   |  j  j j |  j  S)N)r   r   r   rW   )r<   r-   r>   r"   r"   r&   r   @  s    z#CustomTargetHolder.full_path_method)r?   r@   rA   r4   rc   r   r"   r"   )r=   r&   r   3  s   r   c                   s.   e  Z d  Z   f d d   Z d d   Z   S)RunTargetHolderc                s/   t    j   t j | | | | |  |  _ d  S)N)r3   r4   r   	RunTargetrW   )r<   rt   r   r-   r   rH   )r=   r"   r&   r4   D  s    zRunTargetHolder.__init__c             C   s1   d } |  j  } | j |  j j | j   | j  S)Nz<{} {}: {}>)rW   r`   r=   r?   r   r   )r<   r   r   r"   r"   r&   rc   H  s    	zRunTargetHolder.__repr__)r?   r@   rA   r4   rc   r"   r"   )r=   r&   r   C  s   r   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)Testc
       
      C   sb   t  j |   | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 |	 |  _
 d  S)N)r   r4   rt   suiteexeis_parallelcmd_argsrM   should_failtimeoutworkdir)
r<   rt   r   r   r   r   rM   r   r   r   r"   r"   r&   r4   N  s    								zTest.__init__c             C   s   |  j  S)N)r   )r<   r"   r"   r&   get_exeZ  s    zTest.get_exec             C   s   |  j  S)N)rt   )r<   r"   r"   r&   r   ]  s    zTest.get_nameN)r?   r@   rA   r4   r   r   r"   r"   r"   r&   r   M  s   r   c                   s.   e  Z d  Z   f d d   Z d d   Z   S)SubprojectHolderc                s4   t    j   | |  _ |  j j i |  j d 6 d  S)Nget_variable)r3   r4   rW   r6   r7   get_variable_method)r<   Zsubinterpreter)r=   r"   r&   r4   b  s    	zSubprojectHolder.__init__c             C   sW   t  |  d k r! t d   n  | d } t | t  sI t d   n  |  j j | S)Nr   z Get_variable takes one argument.r    z%Get_variable takes a string argument.)rg   r   r(   r,   rW   	variables)r<   r-   r>   r   r"   r"   r&   r   h  s    
z$SubprojectHolder.get_variable_method)r?   r@   rA   r4   r   r"   r"   )r=   r&   r   `  s   r   c               @   s<  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 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/ d0   Z d1 d2   Z d3 S)4CompilerHolderc             C   s  t  j |   | |  _ | |  _ |  j j i |  j d 6|  j d 6|  j d 6|  j	 d 6|  j
 d 6|  j d 6|  j d 6|  j d 6|  j d	 6|  j d
 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6 d  S)Ncompileslinksr   compute_intsizeof
get_define
has_headerhas_header_symbolrunhas_functionZ
has_memberhas_membershas_type	alignmentr   Z	cmd_arrayfind_libraryhas_argumenthas_multi_argumentsZfirst_supported_argumentZunittest_argssymbols_have_underscore_prefix)r   r4   compilerr   r6   r7   compiles_methodlinks_methodr   compute_int_methodsizeof_methodget_define_methodhas_header_methodhas_header_symbol_method
run_methodhas_function_methodhas_member_methodhas_members_methodhas_type_methodalignment_methodr   cmd_array_methodfind_library_methodhas_argument_methodhas_multi_arguments_methodfirst_supported_argument_methodunittest_args_method%symbols_have_underscore_prefix_method)r<   r  rM   r"   r"   r&   r4   q  s2    		



















zCompilerHolder.__init__c             C   s
   |  j  j S)N)r  r   )r<   r-   r>   r"   r"   r&   r     s    zCompilerHolder.version_methodc             C   s
   |  j  j S)N)r  exelist)r<   r-   r>   r"   r"   r&   r    s    zCompilerHolder.cmd_array_methodc             C   sJ  | j  d d  } t | t  s0 t d   n  g  } | j  d g   } t | t  sc | g } n  x} | D]u } t | t  s t d   n  xN | j j   D]= } t j	 j
 |  j j   |  } | |  j j | d  7} q Wqj W| s'|  j j j } | |  j j |  7} | |  j j |  7} n  | t j | j  d g    7} | S)NZno_builtin_argsFz&Type of no_builtin_args not a boolean.include_directorieszCInclude directories argument must be an include_directories object.r-   )rf   r(   boolr   r)   r   rW   Zget_incdirsrP   rQ   r*   r   get_source_dirr  get_include_argsr   compiler_optionsget_option_compile_argsget_option_link_argsr   r   )r<   r>   Z
nobuiltinsr-   Zincdirsiidiroptsr"   r"   r&   determine_args  s&    !zCompilerHolder.determine_argsc             C   s   | j  d d   } | d  k	 r t | t  s9 | g } n  g  } xk | D]c } y | j } Wn t k
 rm Yn Xt | t  s t | t  r t d   n  | j |  qF W| } n  | S)Nr   z*Dependencies must be external dependencies)	rf   r(   r)   rW   	Exceptionr   r   r   r[   )r<   r>   deps
final_depsdr"   r"   r&   determine_dependencies  s    	z%CompilerHolder.determine_dependenciesc             C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  t j | j d g    } |  j |  } |  j	 j
 | | |  j | |  } t j d t j |  d	 | d
 d | S)Nr   z7Alignment method takes exactly one positional argument.r    prefixrd   z+Prefix argument of sizeof must be a string.r-   zChecking for alignment of "z": sep)rg   r   r   rf   r(   r,   r   r   r1  r  r  r   r   logbold)r<   r-   r>   typenamer2  r   r.  resultr"   r"   r&   r    s    

!%zCompilerHolder.alignment_methodc       	      C   s  t  |  d k r! t d   n  | d } t | t j  ra t j j | j |  j j   } n t | t	  s t
 d   n  | j d d  } t | t	  s t d   n  |  j |  } |  j |  } |  j j | |  j | |  } t  |  d k rw| j st j d  } n7 | j d k r9t j d	  } n t j d
 | j  } t j d t j |  d | d d n  t |  S)Nr   z1Run method takes exactly one positional argument.r    z Argument must be string or file.rt   rd   z#Testname argument must be a string.zDID NOT COMPILEYESzNO (%d)zChecking if "z" runs: r3  )rg   r   r(   r   Filefrom_absolute_filerel_to_builddirr   rF   r,   r   rf   r,  r1  r  r  r0   r   redr/   greenr4  r5  r.   )	r<   r-   r>   codetestnamer   r.  r7  r   r"   r"   r&   r    s,    
		(zCompilerHolder.run_methodc             C   s   |  j  j   S)N)r  r   )r<   r-   r>   r"   r"   r&   r     s    zCompilerHolder.get_id_methodc             C   s   |  j  j |  j  S)z
        Check if the compiler prefixes _ (underscore) to global C symbols
        See: https://en.wikipedia.org/wiki/Name_mangling#C
        )r  r  r   )r<   r-   r>   r"   r"   r&   r     s    z4CompilerHolder.symbols_have_underscore_prefix_methodc             C   s@   t  |  j d  s3 t d j |  j j      n  |  j j   S)Nget_unittest_argsz+This {} compiler has no unittest arguments.)hasattrr  r   r`   get_display_languager@  )r<   r-   r>   r"   r"   r&   r    s    !z#CompilerHolder.unittest_args_methodc       
   	   C   s  t  |  d k r! t d   n  t |  | d } | d } | j d d  } t | t  so t d   n  |  j |  } |  j |  } |  j j	 | | g | |  j
 | |  } | r t j d  }	 n t j d	  }	 t j d
 t j |  d t j |  d |	 d d | S)Nre   z'Has_member takes exactly two arguments.r    r   r2  rd   z/Prefix argument of has_member must be a string.r8  NOzChecking whether type "z" has member "z": r3  )rg   r   r   rf   r(   r,   r,  r1  r  r  r   r   r=  r<  r4  r5  )
r<   r-   r>   r6  Z
membernamer2  r   r.  hadhadtxtr"   r"   r&   r    s$    


z CompilerHolder.has_member_methodc          	   C   s  t  |  | d } | d d   } | j d d  } t | t  sT t d   n  |  j |  } |  j |  } |  j j | | | |  j	 | |  } | r t
 j d  }	 n t
 j d  }	 t
 j d j d	 d
   | D   }
 t
 j d t
 j |  d |
 d |	 d d | S)Nr    r   r2  rd   z0Prefix argument of has_members must be a string.r8  rC  z, c             S   s   g  |  ] } d  j  |   q S)z"{}")r`   )r$   mr"   r"   r&   r'     s   	 z5CompilerHolder.has_members_method.<locals>.<listcomp>zChecking whether type "z" has members z: r3  )r   rf   r(   r,   r   r,  r1  r  r  r   r   r=  r<  r5  r*   r4  )r<   r-   r>   r6  membernamesr2  r   r.  rD  rE  membersr"   r"   r&   r    s"    

%z!CompilerHolder.has_members_methodc       	      C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  |  j |  } |  j |  } |  j j	 | | |  j
 | |  } | r t j d  } n t j d  } t j d	 t j |  d
 | d d | S)Nr   z(Has_function takes exactly one argument.r    r2  rd   z1Prefix argument of has_function must be a string.r8  rC  zChecking for function "z": r3  )rg   r   r   rf   r(   r,   r,  r1  r  r  r   r   r=  r<  r4  r5  )	r<   r-   r>   funcnamer2  r   r.  rD  rE  r"   r"   r&   r    s    

!%z"CompilerHolder.has_function_methodc       	      C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  |  j |  } |  j |  } |  j j	 | | |  j
 | |  } | r t j d  } n t j d  } t j d	 t j |  d
 | d d | S)Nr   z$Has_type takes exactly one argument.r    r2  rd   z-Prefix argument of has_type must be a string.r8  rC  zChecking for type "z": r3  )rg   r   r   rf   r(   r,   r,  r1  r  r  r   r   r=  r<  r4  r5  )	r<   r-   r>   r6  r2  r   r.  rD  rE  r"   r"   r&   r  +  s    

!%zCompilerHolder.has_type_methodc          	   C   se  t  |  d k r! t d   n  t |  | d } | j d d  } | j d d  } | j d d  } | j d	 d   } t | t  s t d
   n  t | t  s t d   n  t | t  s t d   n  | d  k	 rt | t  rt d   n  |  j |  } |  j |  }	 |  j	 j
 | | | | | |  j | |	  }
 t j d | |
 f  |
 S)Nr   z'Compute_int takes exactly one argument.r    r2  rd   lowi   highguessz0Prefix argument of compute_int must be a string.z+Low argument of compute_int must be an int.z,High argument of compute_int must be an int.z-Guess argument of compute_int must be an int.zComputing int of "%s": %di )rg   r   r   rf   r(   r,   r+   r,  r1  r  r   r   r   r4  )r<   r-   r>   
expressionr2  lr   rL  r   r.  r5   r"   r"   r&   r  =  s*    

*z!CompilerHolder.compute_int_methodc             C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  |  j |  } |  j |  } |  j j	 | | |  j
 | |  } t j d | | f  | S)Nr   z"Sizeof takes exactly one argument.r    r2  rd   z+Prefix argument of sizeof must be a string.zChecking for size of "%s": %d)rg   r   r   rf   r(   r,   r,  r1  r  r   r   r   r4  )r<   r-   r>   elementr2  r   r.  Zesizer"   r"   r&   r  T  s    

!zCompilerHolder.sizeof_methodc             C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  |  j |  } |  j |  } |  j j	 | | |  j
 | |  } t j d | | f  | S)Nr   z(get_define() takes exactly one argument.r    r2  rd   z1Prefix argument of get_define() must be a string.z%Checking for value of define "%s": %s)rg   r   r   rf   r(   r,   r,  r1  r  r   r   r   r4  )r<   r-   r>   rO  r2  r   r.  valuer"   r"   r&   r  b  s    

!z CompilerHolder.get_define_methodc       	      C   sP  t  |  d k r! t d   n  | d } t | t j  ra t j j | j |  j j   } n t | t	  s t
 d   n  | j d d  } t | t	  s t d   n  |  j |  } |  j |  } |  j j | |  j | |  } t  |  d k rL| rt j d  } n t j d	  } t j d
 t j |  d | d d n  | S)Nr   z+compiles method takes exactly one argument.r    z Argument must be string or file.rt   rd   z#Testname argument must be a string.r8  rC  zChecking if "z" compiles: r3  )rg   r   r(   r   r9  r:  r;  r   rF   r,   r   rf   r,  r1  r  r   r   r=  r<  r4  r5  )	r<   r-   r>   r>  r?  r   r.  r7  r   r"   r"   r&   r  p  s(    
	(zCompilerHolder.compiles_methodc       	      C   sP  t  |  d k r! t d   n  | d } t | t j  ra t j j | j |  j j   } n t | t	  s t
 d   n  | j d d  } t | t	  s t d   n  |  j |  } |  j |  } |  j j | |  j | |  } t  |  d k rL| rt j d  } n t j d	  } t j d
 t j |  d | d d n  | S)Nr   z(links method takes exactly one argument.r    z Argument must be string or file.rt   rd   z#Testname argument must be a string.r8  rC  zChecking if "z	" links: r3  )rg   r   r(   r   r9  r:  r;  r   rF   r,   r   rf   r,  r1  r  r   r   r=  r<  r4  r5  )	r<   r-   r>   r>  r?  r   r.  r7  r   r"   r"   r&   r    s(    
	(zCompilerHolder.links_methodc       	      C   s   t  |  d k r! t d   n  t |  | d } | j d d  } t | t  se t d   n  |  j |  } |  j |  } |  j j	 | | |  j
 | |  } | r t j d  } n t j d  } t j d	 | |  | S)
Nr   z-has_header method takes exactly one argument.r    r2  rd   z/Prefix argument of has_header must be a string.r8  rC  zHas header "%s":)rg   r   r   rf   r(   r,   r,  r1  r  r  r   r   r=  r<  r4  )	r<   r-   r>   hnamer2  r   r.  hazr   r"   r"   r&   r    s    

!z CompilerHolder.has_header_methodc       
      C   s   t  |  d k r! t d   n  t |  | d } | d } | j d d  } t | t  so t d   n  |  j |  } |  j |  } |  j j	 | | | |  j
 | |  } | r t j d  }	 n t j d	  }	 t j d
 j | |  |	  | S)Nre   z5has_header_symbol method takes exactly two arguments.r    r   r2  rd   z6Prefix argument of has_header_symbol must be a string.r8  rC  zHeader <{0}> has symbol "{1}":)rg   r   r   rf   r(   r,   r,  r1  r  r  r   r   r=  r<  r4  r`   )
r<   r-   r>   rQ  symbolr2  r   r.  rR  r   r"   r"   r&   r    s     


$z'CompilerHolder.has_header_symbol_methodc       	      C   sA  t  |  d k r! t d   n  | d } t | t  sI t d   n  | j d d  } t | t  sy t d   n  t j | j d g    } x3 | D]+ } t j	 j
 |  s t d	 |   q q W|  j j | |  j |  } | r| rt d
 j |  j j   |    n  t j | | |  j |  j j  } t |  S)Nr   z'find_library method takes one argument.r    zLibrary name not a string.requiredTzrequired must be boolean.dirsz,Search directory %s is not an absolute path.z{} library {!r} not found)rg   r   r(   r,   rf   r#  r   r   rP   rQ   isabsr   r  r  r   r`   rB  r   ExternalLibrarylanguager   )	r<   r-   r>   libnamerT  Zsearch_dirsr)  linkargslibr"   r"   r&   r    s$    
$z"CompilerHolder.find_library_methodc             C   s   t  j |  } t |  d k r0 t d   n  |  j j | d |  j  } | rd t j d  } n t j	 d  } t j
 d j |  j j   | d  |  | S)Nr   z#Has_arg takes exactly one argument.r    r8  rC  z%Compiler for {} supports argument {}:)r   r   rg   r   r  r	  r   r   r=  r<  r4  r`   rB  )r<   r-   r>   r7  r   r"   r"   r&   r    s    )z"CompilerHolder.has_argument_methodc             C   s   t  j |  } |  j j | |  j  } | r? t j d  } n t j d  } t j d j	 |  j j
   d j |   |  | S)Nr8  rC  z&Compiler for {} supports arguments {}:rL   )r   r   r  r
  r   r   r=  r<  r4  r`   rB  r*   )r<   r-   r>   r7  r   r"   r"   r&   r    s    z)CompilerHolder.has_multi_arguments_methodc             C   so   xO t  j |  D]> } |  j j | |  j  r t j d t j |   | g Sq Wt j d t j d   g  S)NzFirst supported argument:None)	r   r   r  r	  r   r   r4  r5  r<  )r<   r-   r>   r)  r"   r"   r&   r    s    z.CompilerHolder.first_supported_argument_methodN)r?   r@   rA   r4   r   r  r,  r1  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"   r"   r"   r&   r   p  s2   r   ModuleStatebuild_to_srcrH   current_linenor   project_nameproject_versionr   r	   targetsr   headersmanglobal_argsproject_argsbuild_machinehost_machinetarget_machinec               @   s(   e  Z d  Z d d   Z d d   Z d S)ModuleHolderc             C   s,   t  j |   | |  _ | |  _ | |  _ d  S)N)r   r4   modnamerW   r   )r<   rk  moduler   r"   r"   r&   r4      s    		zModuleHolder.__init__c          ,   C   sX  y t  |  j |  } Wn+ t k
 rC t d |  j | f   Yn X| j d  rq t d j | |  j    n  t |  j j	 j
  } t d t j j |  j j j   |  j j j    d |  j j d |  j j d |  j j d |  j j	 j d	 |  j j	 j |  j j d
 |  j j d |  j j	 j d |  j j	 j
 d |  j j	 j d |  j j	 j   d |  j j	 j   d |  j j	 j d |  j j	 j j |  j j i   d |  j j  d j d |  j j  d j d |  j j  d j  } |  j j! |  r| |  j | | |  } |  j j" |  S| | | |  } | t |  j j	 j
  k rDt# d   n  |  j j$ |  Sd  S)Nz"Module %s does not have method %s._z(Function {!r} in module {!r} is private.r^  rH   r_  r   r`  ra  r   r	   rb  r   rc  rd  re  rf  rg  rh  ri  z2Extension module altered internal state illegally.)%getattrrW   AttributeErrorr   rk  
startswithr`   rg   r   r   rb  r]  rP   rQ   relpathr   r$  get_build_dirrH   r_  r`  dep_manifestactive_projectnamer   r	   r   Zget_headersZget_manre  projects_argsrf   
subprojectbuiltinZ
is_snippet	holderifyr   module_method_callback)r<   Zmethod_namer-   r>   fnZnum_targetsstaterP  r"   r"   r&   method_call  sB    !zModuleHolder.method_callN)r?   r@   rA   r4   r|  r"   r"   r"   r&   rj    s   rj  c               @   s   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 d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' S)(	MesonMainc             C   s   t  j |   | |  _ | |  _ i  |  _ |  j j i |  j d 6|  j d 6|  j	 d 6|  j
 d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d	 6|  j d
 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6 d  S)NZget_compileris_cross_buildZhas_exe_wrapperZis_unityis_subprojectZcurrent_source_dirZcurrent_build_dirsource_root
build_rootZadd_install_scriptZadd_postconf_scriptZinstall_dependency_manifestra  r   r`  Zget_cross_propertyr   )r   r4   r   r   _found_source_scriptsr6   r7   get_compiler_methodis_cross_build_methodhas_exe_wrapper_methodis_unity_methodis_subproject_methodcurrent_source_dir_methodcurrent_build_dir_methodsource_root_methodbuild_root_methodadd_install_script_methodadd_postconf_script_method"install_dependency_manifest_methodproject_version_methodr   project_name_methodget_cross_property_methodbackend_method)r<   r   r   r"   r"   r&   r4   0  s*    			














zMesonMain.__init__c             C   s   t  j j |  j j j |  j j  } | | f } | |  j k rO |  j | } nL t j	 | d | } | j
   r | |  j | <n d } t | j |    t j | j   |  S)N
search_dirz2Script or command {!r} not found or not executable)rP   rQ   r*   r   r   rF   rH   r  r   r   r   r   r`   r   	RunScriptrO   )r<   rt   r-   r  keyr   rF  r"   r"   r&   _find_source_scriptH  s    zMesonMain._find_source_scriptc             C   se   t  |  d k  r! t d   n  t | d  |  j | d | d d    } |  j j j |  d  S)Nr   z.add_install_script takes one or more argumentsz'add_install_script args must be stringsr    )rg   r   r   r  r   install_scriptsr[   )r<   r-   r>   scriptr"   r"   r&   r  X  s
     z#MesonMain.add_install_script_methodc             C   se   t  |  d k  r! t d   n  t | d  |  j | d | d d    } |  j j j |  d  S)Nr   z/add_postconf_script takes one or more argumentsz-add_postconf_script arguments must be stringsr    )rg   r   r   r  r   Zpostconf_scriptsr[   )r<   r-   r>   r  r"   r"   r&   r  _  s
     z$MesonMain.add_postconf_script_methodc             C   s>   |  j  j j } |  j  j } | d k r+ | St j j | |  S)Nrd   )r   r   rF   rH   rP   rQ   r*   )r<   r-   r>   srcsubr"   r"   r&   r  f  s
    z#MesonMain.current_source_dir_methodc             C   s>   |  j  j j } |  j  j } | d k r+ | St j j | |  S)Nrd   )r   r   rG   rH   rP   rQ   r*   )r<   r-   r>   r  r  r"   r"   r&   r  m  s
    z"MesonMain.current_build_dir_methodc             C   s   |  j  j j S)N)r   r   rt   )r<   r-   r>   r"   r"   r&   r  t  s    zMesonMain.backend_methodc             C   s   |  j  j j S)N)r   r   rF   )r<   r-   r>   r"   r"   r&   r  w  s    zMesonMain.source_root_methodc             C   s   |  j  j j S)N)r   r   rG   )r<   r-   r>   r"   r"   r&   r  z  s    zMesonMain.build_root_methodc             C   sx   |  j  d  d   rt d |  j j j j k rt |  j j j j   rt |  j j j j d j d d   } | d  k rt d Sn  d S)Nbinariesexe_wrapperFT)r  r   r   r   configneed_exe_wrapperrf   )r<   r-   r>   exe_wrapr"   r"   r&   r  }  s    "z MesonMain.has_exe_wrapper_methodc             C   s   |  j  j j   S)N)r   r   r~  )r<   r-   r>   r"   r"   r&   r    s    zMesonMain.is_cross_build_methodc             C   s   t  |  d k r! t d   n  | d } | j d d   } | d  k rm |  j j j   rd d } qm d } n  t | t  s t d   n  | r |  j j } n |  j j	 } | | k r t
 | | |  j j  St d |   d  S)	Nr   z8get_compiler_method must have one and only one argument.r    nativeFTz#Type of "native" must be a boolean.z7Tried to access compiler for unspecified language "%s".)rg   r   rf   r   r   r~  r(   r#  r	   cross_compilersr   )r<   r-   r>   Zcnamer  Zclistr"   r"   r&   r    s     
		zMesonMain.get_compiler_methodc             C   sJ   |  j  j j j d  } | d k sB | d k rF |  j  j d k rF d Sd S)Nunityonsubprojectsrd   TF)r   r   r   get_builtin_optionrv  )r<   r-   r>   optvalr"   r"   r&   r    s    *zMesonMain.is_unity_methodc             C   s   |  j  j   S)N)r   r  )r<   r-   r>   r"   r"   r&   r    s    zMesonMain.is_subproject_methodc             C   sW   t  |  d k r! t d   n  t | d t  sC t d   n  | d |  j _ d  S)Nr   z'Must specify manifest install file namer    zArgument must be a string.)rg   r   r(   r,   r   Zdep_manifest_name)r<   r-   r>   r"   r"   r&   r    s
    z,MesonMain.install_dependency_manifest_methodc             C   s   |  j  j |  j j d S)Nr   )r   rs  r   rt  )r<   r-   r>   r"   r"   r&   r    s    z MesonMain.project_version_methodc             C   s   t  j S)N)r   r   )r<   r-   r>   r"   r"   r&   r     s    zMesonMain.version_methodc             C   s
   |  j  j S)N)r   rt  )r<   r-   r>   r"   r"   r&   r    s    zMesonMain.project_name_methodc             C   s   t  |  d k  s$ t  |  d k r3 t d   n  | d } t | t  s[ t d   n  y! |  j j j j   } | | SWn< t k
 r t  |  d k r | d St d |   Yn Xd  S)Nr   re   zMust have one or two arguments.r    zProperty name must be string.zUnknown cross property: %s.)	rg   r   r(   r,   r   r   r   get_propertiesr-  )r<   r-   r>   Zpropnamepropsr"   r"   r&   r    s    $
z#MesonMain.get_cross_property_methodN)r?   r@   rA   r4   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r"   r"   r"   r&   r}  /  s&   r}  Zc_pchZcpp_pchZc_argsZcpp_argsZd_argsZfortran_argsZ	java_argsZ	objc_argsZobjcpp_argsZ	rust_argsZ	vala_argsZvala_headerZvala_girZ	vala_vapiZrust_crate_typeZ	resourcesZbuild_by_defaultbuild_rpathr   extra_filesZgui_app	link_withZ
link_whole	link_argsZlink_dependsZimplicit_include_directoriesr"  installinstall_rpathr   Zname_prefixZname_suffixr  objectsZoverride_optionsZpicr   Zvs_module_defsZimplibr   	soversionZ
main_classtarget_typerX  add_global_argumentsadd_global_link_argumentsadd_project_link_argumentsrT  add_languagesadd_project_argumentsr  gdbtimeout_multiplierrM   add_test_setupr-   r   r   r   r   	benchmarkbuild_targetinputoutputconfigurationr   captureconfigure_filebuild_alwaysdependsZdepend_filesZdepfilecustom_targetcompile_argsdeclare_dependency
executablefind_program	arguments	generator	is_systemr   install_datainstall_headersinstall_manexclude_filesexclude_directoriesr   jarmeson_versiondefault_optionslicensesubproject_dirproject
run_targetshared_libraryshared_modulestatic_libraryrv  r   testfallbackreplace_stringvcs_tagc                   s  e  Z d  Z d d d g    f d d  Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z d d   Z	 d d   Z
 e e d d     Z e e d d     Z e e d  e d d     Z e d d    Z d d   Z e d d    Z d  d! d"  Z e d# d$    Z d% d&   Z e e d'  e d( d)     Z d* d+   Z e e d, d-     Z e d. d/    Z d0 d1   Z e e e d2  d3 d4     Z e e d5  e d6 d7     Z e d8 d9    Z  e d: d;    Z! d< d=   Z" d> d?   Z# d@ dA   Z$ e e dB  dC dD    Z% dE dF   Z& dG dH   Z' dI dJ   Z( dK dL   Z) dM dN   Z* e e dO  dP dQ    Z+ e e dR  dS dT    Z, e e dU  dV dW    Z- e e dX  dY dZ    Z. d[ d\   Z/ e e d]  d^ d_    Z0 e e d`  da db    Z1 e e dc  dd de    Z2 e e e df  dg dh     Z3 e e di  dj dk    Z4 e e dl  dm dn    Z5 e e do  dp dq    Z6 e e dr  ds dt    Z7 du dv   Z8 dw dx   Z9 e e dy  dz d{    Z: e e d|  d} d~    Z; e d d    Z< d d   Z= e e d  d d    Z> e e d  e d d     Z? e e d  d d    Z@ e e d  e d d     ZA e e d  e d d     ZB e e d  e d d     ZC e e d  e d d     ZD e e d  e d d     ZE e e d  e d d     ZF d d   ZG d d   ZH d d   ZI e e d d     ZJ e e d d     ZK   f d d   ZL d d   ZM d d   ZN d d   ZO d d   ZP d d   ZQ d d   ZR d d   ZS d d   ZT d d   ZU d d   ZV e d d    ZW e d d    ZX e e d d     ZY   S)Interpreterrd   r  c                s   t    j | j j   |  t j |  _ | |  _ | j |  _ |  j j   |  _ | |  _	 | |  _
 | |  _ t j j |  j |  j d  |  _ |  j   |  j   |  j j i t | |   d 6 g  |  _ i  |  _ d |  _ d |  _ i  |  _ g  |  _ | d  d   |  _ |  j   |  j   t  |  j j!  |  j d <|  j j j"   sr|  j d |  j d <|  j d |  j d <n |  j j j# } | j$   rt% | j& d  |  j d <n |  j d |  j d <| j'   rt% | j& d  |  j d <n |  j d |  j d <t j j |  j t j(  g |  _) d  S)Nzmeson_options.txtZmesonFrg  rh  ri  )*r3   r4   r   r$  r   an_unpicklable_objectr   get_coredatar   r   rv  r  rP   rQ   r*   r  rH   option_fileZload_root_meson_fileZsanity_check_astrw  r7   r}  
generatorsvisited_subdirsproject_args_frozenglobal_args_frozenr  subproject_stackdefault_project_optionsbuild_func_dictZparse_projectr   r	   r~  r   has_hostr   r  
has_targetbuild_filenamebuild_def_files)r<   r   r   rv  rH   r  r  r   )r=   r"   r&   r4   $  sB    				!

 						

zInterpreter.__init__c             C   s  |  j  j i/ |  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j	 d 6|  j
 d	 6|  j d
 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j  d 6|  j! d  6|  j" d! 6|  j# d" 6|  j$ d# 6|  j% d$ 6|  j& d% 6|  j' d& 6|  j( d' 6|  j) d( 6|  j* d) 6|  j+ d* 6|  j, d+ 6|  j- d, 6|  j. d- 6|  j/ d. 6|  j0 d/ 6 d  S)0Nr  r  r  r  r  r  assertr  r  rX   r  r  r  
dependencyr   errorr  r  gettextZ
get_optionr   filesr  r  r"  importr  r  r  r   Zis_variabler  Z
join_pathslibrarymessageoptionr  r  rD   set_variablerH   rv  r  r  r  r  r  )1Zfuncsr7   func_add_global_argumentsfunc_add_project_argumentsfunc_add_global_link_argumentsfunc_add_project_link_argumentsfunc_add_test_setupfunc_add_languagesfunc_assertfunc_benchmarkfunc_build_targetfunc_configuration_datafunc_configure_filefunc_custom_targetfunc_declare_dependencyfunc_dependencyfunc_environment
func_errorfunc_executablefunc_generatorfunc_gettextfunc_get_optionfunc_get_variable
func_filesfunc_find_libraryfunc_find_programfunc_include_directoriesfunc_importfunc_install_datafunc_install_headersfunc_install_manfunc_install_subdirfunc_is_variablefunc_jarfunc_join_pathsfunc_libraryfunc_messagefunc_optionfunc_projectfunc_run_targetfunc_run_commandfunc_set_variablefunc_subdirfunc_subprojectfunc_shared_libfunc_shared_modulefunc_static_lib	func_testfunc_vcs_tag)r<   r"   r"   r&   r  K  s^    












































zInterpreter.build_func_dictc                s^  t  | t  r&   f d d   | D St  | t j  rE t |    St  | t t f  sf | d  k rj | St  | t j  r t |    St  | t j	  r t
 |  St  | t j  r t d   n t  | t j  r t d   ns t  | t j  rt |  St  | t j  rt |  St  | t j  r;t |  St | d  rN| St d   d  S)Nc                s   g  |  ] }   j  |   q Sr"   )rx  )r$   r%   )r<   r"   r&   r'     s   	 z)Interpreter.holderify.<locals>.<listcomp>zThis is not a pipe.zDo not do this.rW   z(Module returned a value of unknown type.)r(   r)   r   CustomTargetr   r+   r,   
Executabler   r   r   r   RuntimeErrorr  Datar   r   r   r   r   r   rA  r   )r<   itemr"   )r<   r&   rx  }  s.    !



zInterpreter.holderifyc             C   sN  t  | t  s | g } n  x,| D]$} t  | t j t j t j f  r_ |  j | j |  q" t  | t  r~ |  j |  q" t  | t j	  r q" t  | t j
  r |  j j j |  q" t  | t j  r |  j j j |  q" t  | t j  r t |  St  | t j  r(|  j | j d  q" t | d  r:q" t d   q" Wd  S)Nr    rW   z(Module returned a value of unknown type.)r(   r)   r   BuildTargetr&  r   
add_targetrt   ry  r   r  r  r[   r)  r   r   r   r   r   process_new_valuesr   rA  r   )r<   invaluesr~   r"   r"   r&   r-    s(    !
zInterpreter.process_new_valuesc             C   sD   t  | t  s t d   n  | j } |  j |  |  j | j  S)Nz,Bug in module, it returned an invalid object)r(   r   r   Znew_objectsr-  rx  Zreturn_value)r<   Zreturn_objectr.  r"   r"   r&   ry    s
    	z"Interpreter.module_method_callbackc             C   s   |  j  S)N)r  )r<   r"   r"   r&   get_build_def_files  s    zInterpreter.get_build_def_filesc             C   s   |  j  S)N)r   )r<   r"   r"   r&   get_variables  s    zInterpreter.get_variablesc             C   s   |  j  j j   r |  j  j j } x |  j  j j   D] \ } } y~ t j | j |   } t	 |  d k r t
 d |   n  | \ } } |  j | i   } | j | g i   |  j  j | <Wq4 t k
 r Yq4 Xq4 Wn  d  S)Nre   z:Stdlib definition for %s should have exactly two elements.)r   r   r~  r   r  r|   r   r   
get_stdlibrg   r   do_subprojectr   cross_stdlibsKeyError)r<   r   rN  cdiZprojnameZdepnameZsubprojr"   r"   r&   check_cross_stdlibs  s    #zInterpreter.check_cross_stdlibsc             C   s   t  |  d k r! t d   n  | d } | j d  rn | j d d  d } t j d |  d | } n  | |  j j j k r y t	 j
 d |  } Wn% t k
 r t d	 | f   Yn X| j   |  j j j | <n  t | |  j j j | |   S)
Nr   zImport takes one argument.r    z	unstable--z\Module %s has no backwards or forwards compatibility and might not exist in future releases.Z	unstable_zmesonbuild.modules.zModule "%s" does not exist)rg   r   rp  rz   r   warningr   r   modules	importlibZimport_moduleImportErrorr   
initializerj  )r<   noder-   r>   rk  Z	plainnamerl  r"   r"   r&   r    s    
zInterpreter.func_importc                s     f d d   | D S)Nc                s1   g  |  ]' } t  j j   j j   j |   q Sr"   )r   r9  from_source_filer   rF   rH   )r$   fname)r<   r"   r&   r'     s   	 z*Interpreter.func_files.<locals>.<listcomp>r"   )r<   r>  r-   r>   r"   )r<   r&   r    s    zInterpreter.func_filesr  c             C   s  | j  d |  j  } t | t  s3 t d   n  | j  d g   } t | t  s` | g } n  | j  d g   } t | t  s | g } n  | j  d g   } t | t  s | g } n  |  j |  j |   } |  j | j  d g    } t | t  s| g } n  t j	 | j  d g    }	 t j	 | j  d g    }
 g  } xm | D]e } y | j
 } Wn t k
 rrYn Xt | t j t j t j f  st d	   n  | j |  qKWt j | t j |  |	 |
 t j |  t j |  |  } t |  S)
Nr   zVersion must be a string.r"  r  r   r   r  r  z"Dependencies must be external deps)rf   ra  r(   r,   r   r)   source_strings_to_filesflattenr   r   rW   r-  r   r   rW  r   r[   unholder_arrayr   )r<   r>  r-   r>   r   ZincsZlibsr   r.  r  r  r/  r0  r   r"   r"   r&   r    sF    !		z#Interpreter.func_declare_dependencyc             C   s   t  |  d k r! t d   n  | \ } } t | t  sK t d   n  t | t  si t d   n  | s t d |   n  d  S)Nre   z"Assert takes exactly two argumentszAssert value not bool.zAssert message not a string.zAssert failed: )rg   r   r(   r#  r,   )r<   r>  r-   r>   rP  r  r"   r"   r&   r  
  s    zInterpreter.func_assertc             C   s   | d  k	 r@ | t  |  k r@ t d | t  |  f   q@ n  xj t t t  |  t  |    D]G } | | } | | } | d  k	 rb t | |  s t d   q qb qb Wd  S)NzExpected %d arguments, got %d.zIncorrect argument type.)rg   r   rangeminr(   )r<   r-   ZargcountZ	arg_typesr)  wantedactualr"   r"   r&   validate_arguments  s    (

zInterpreter.validate_argumentsc             C   s   |  j  | | |  S)N)run_command_impl)r<   r>  r-   r>   r"   r"   r&   r  "  s    zInterpreter.func_run_commandFc          	   C   s  t  |  d k  r! t d   n  | d } | d d   } |  j j   } |  j j   } d }	 t | t  rz | j } n t | t j	  r | j
 | |  } n+ t | t  s t d |	 j |    n  t j j | |  j  }
 t | d d d |
 } | j   s t d	 j |    n  | } g  } x t j |  D] } t | t  ra| j |  q<t | t j	  r| j | j
 | |   q<t | t  r| j | j j    q<t d
 |	 j |    q<Wt | | | | |  j t |  j d  |  S)Nr   zNot enough argumentsr    zYmust be a string, or the output of find_program(), files(), or configure_file(); not {!r}zFirst argument ZsilentTr  z2Program or command {!r} not foundor not executablez
Arguments rI   )rg   r   r   r$  rr  r(   r   rW   r   r9  absolute_pathr,   r`   rP   rQ   r*   rH   r   r   rB  r[   r   rB   r   )r<   r>  r-   r>   rJ   rE   cargssrcdirbuilddirrF  r  progZexpanded_argsr   r"   r"   r&   rI  &  s<    
zInterpreter.run_command_implc             C   s   t  d   d  S)NzZGettext() function has been moved to module i18n. Import it and use i18n.gettext() instead)r   )r<   nodesr-   r>   r"   r"   r&   r	  J  s    zInterpreter.func_gettextc             C   s   t  d   d  S)NzYTried to call option() in build description file. All options must be in the option file.)r   )r<   rO  r-   r>   r"   r"   r&   r  N  s    zInterpreter.func_optionrv  c             C   s;   t  |  d k r! t d   n  | d } |  j | |  S)Nr   z%Subproject takes exactly one argumentr    )rg   r   r2  )r<   rO  r-   r>   dirnamer"   r"   r&   r   Q  s    
zInterpreter.func_subprojectc             C   s  | |  j  k rA |  j  | g } d j |  } t d |   n  | |  j k r[ |  j | St j j |  j j   |  j  } t	 j
 | |  j j  } y | j |  } WnU t k
 r } z5 d }	 t |	 j t j j |  j |  |    WYd  d  } ~ Xn Xt j j |  j |  }
 t j t j j |  j j j   |
  d d d |  _ t j d t j |  d d d	 t |  j |  j | |
 |  j t j | j d
 g     } |  j | _ |  j  | g | _  |  j } | j   d | k r8| j } | d } | d k st j  | |  r8t d | | | f   q8n  | |  _ t j d t j |  d  | j |  j j | <|  j j! | j  t" |  |  j | <|  j# | j# 7_# |  j | S)Nz => z%Recursive include of subprojects: %s.zESubproject directory {!r} does not exist and cannot be downloaded:
{}exist_okTz
Executing subproject z.
r3  rd   r  r   	undefinedz,Subproject %s version is %s but %s required.z
Subprojectz	finished.)$r  r*   r   r  rP   rQ   r   r$  r  r
   ZResolverr   	wrap_moderesolver(  r   r`   makedirsr   rr  r  r   r4  r5  r  r   r   r   rf   rt  r  ra  version_comparer7   r   r  )r<   rP  r>   Z	fullstackZincpathZsubproject_dir_absr   ZresolvedemsgrH   ZsubiZcurrent_activepvrF  r"   r"   r&   r2  Y  sF    !=.	"	
	
	zInterpreter.do_subprojectc          3   C   s  t  |  d k r! t d   n  | d } y t j | j SWn t k
 rQ Yn Xy |  j j   j |  SWn t	 k
 r Yn Xy |  j j
 j | j SWn t k
 r Yn Xt
 j |  r |  j   r |  j d | } n  y |  j j
 j | j SWn t k
 r
Yn X| j d  rTy" | d  d
  } |  j
 j | SWqTt k
 rPYqTXn  | j d  ry" | d  d  } |  j
 j | SWqt k
 rYqXn  t d	 |   d  S)Nr   z!Argument required for get_option.r    :
_link_args
   _args   z$Tried to access unknown option "%s".i)rg   r   r	   base_optionsrP  r4  r   r  r  r(  r   r&  is_builtin_optionr  rv  user_optionsendswithexternal_link_argsexternal_args)r<   rO  r-   r>   optnamelangr"   r"   r&   r
    sD    
zInterpreter.func_get_optionc             C   s   | r t  d   n  t   S)Nz%configuration_data takes no arguments)r   rj   )r<   r>  r-   r>   r"   r"   r&   r     s    z#Interpreter.func_configuration_datac       	      C   s  t  | t  s | g } n  x:| D]2} t  | t  sS t j |  t d   n  d | k rn t d   n  | j d d  \ } } t j |  r |  j	 d k r q" n  |  j
 j |  sT|  j j | |  qTq" | d } x* |  j D] } | j |  r | } Pq q W|  j	 d k r/|  j	 d | } n  | g |  j
 j j } | |  j
 j _ q" Wx |  j D] } | j d  \ } } | d } xW | D] } | j |  rPqqW|  j	 d | } | g |  j
 j j } | |  j
 j _ qbWd  S)NzDefault options must be strings=z.All default options must be of type key=value.r   rd   rZ  )r(   r)   r,   r   rT   r   rz   r   ra  rv  r   had_argument_forset_builtin_optionr  rp  cmd_line_optionsprojectoptions)	r<   r  r  r  rP  Zprefr)  Z
newoptionsZdefoptr"   r"   r&   parse_default_options  s@    

z!Interpreter.parse_default_optionsr  c             C   s  t  |  d k  r! t d   n  | d } | d d   } d | k r_ t d j |    n  | j d g   } |  j j r t  |  d k s t  |  j  d k r |  j |  n  |  j   s | |  j	 _
 n  t j j |  j  r.t j |  j |  j	 j j j  } | j |  j  |  j	 j j | j  n  | |  _ | j d d  |  _ |  j	 j d  k rp|  j |  j	 _ n  t j | j d	 d
   } i |  j d 6| d	 6|  j	 j | <|  j |  j	 j k rt d   n  |  j   rd | k r| d |  _ n  d | k rFt j  }	 | d }
 t j! |	 |
  sFt" d |	 |
 f   qFn  | |  j	 j |  j <t# j$ d t# j% |  d d |  j& | d  |  j j' j(   } d | k rd | k rt" d   qn  |  j   s|  j)   n  d  S)Nr   zCNot enough arguments to project(). Needs at least the project name.r    rZ  z&Project name {!r} must not contain ':'r  r   rR  r  unknownzSecond call to project().r  r  z,Meson version is %s but project requires %s.zProject name: r3  rd   Tvalar5  zKCompiling Vala requires C. Add C to your project languages and rerun Meson.)*rg   r   r`   rf   r   first_invocationr  rm  r  r   r`  rP   rQ   existsr  r   ZOptionInterpreterrv  rk  rl  r   merge_optionsoptionsrt  ra  r   r   rs  Zprojectsr   r  r   r   rV  r   r   r4  r5  r  r	   r{   r7  )r<   r>  r-   r>   Z	proj_nameZ
proj_langsr  ZoiZproj_licenseZcvrY  Zlangsr"   r"   r&   r    sT    
		
zInterpreter.func_projectr  c             C   s   |  j  | | j d d   S)NrT  T)r  rf   )r<   r>  r-   r>   r"   r"   r&   r    s    zInterpreter.func_add_languagesc             C   s   |  j  | j  \ } } t |  d k rC t d t |    n  | d } t | t  rk t |  } nB t | t  r | } n* t | t  r t |  } n t d   t	 j
 t	 j d  |  d  S)Nr   zExpected 1 argument, got %dr    zAFunction accepts only strings, integers, lists and lists thereof.zMessage:)Zreduce_argumentsr-   rg   r   r(   r)   r#   r,   r+   r   r4  r5  )r<   r>  r-   r>   Zposargsrm  argZargstrr"   r"   r&   r  
  s    
	zInterpreter.func_messagec             C   s.   |  j  | d t g  t d | d   d  S)Nr   zError encountered: r    )rH  r,   r   )r<   r>  r-   r>   r"   r"   r&   r    s    zInterpreter.func_errorc             C   s  d  } | d k rB |  j  j d  } | re|  j  j d  } qen#| d k r~ |  j  j d  } | re|  j  j d  } qen| d k r |  j  j d  } | re|  j  j d  } qen| d k r |  j  j d  } | re|  j  j d  } qeno| d k r#|  j  j   } | re| } qenB| d k rP|  j  j   } | re| } qen| d	 k r}|  j  j   } | re| } qen | d
 k r|  j  j d  } | re|  j  j d  } qen | d k r|  j  j	   } | re| } qen | d k r"|  j  j
 d  } | re|  j  j
 d  } qenC | d k rU|  j  j   } | ret d   qen t d |   | j |  j  j   |  j   | |  j j | <| j   } | d  k	 r| j |  j  j   |  j   | |  j j | <| j | j    n  | d } x | D] } | j |  s$t d |   n  | d } xP |  j  j j D]? }	 |	 j |  r>|	 j d d  d }
 | | j |
  q>q>WqW| j |  j j  | |  j _ | | f S)Nr5  FTcppobjcobjcppjavacsro  r0  rustfortranswiftz0Cross compilation with Swift is not working yet.z#Tried to use unknown language "%s".rm  z(Internal error, %s has incorrect prefix.rh  r   )r   detect_c_compilerdetect_cpp_compilerdetect_objc_compilerdetect_objcpp_compilerdetect_java_compilerdetect_cs_compilerdetect_vala_compilerdetect_d_compilerdetect_rust_compilerdetect_fortran_compilerdetect_swift_compilerr   r   sanity_checkget_scratch_dirr   r	   get_optionsr  r7   rp  rk  rl  rz   	set_valuer&  )r<   rg  need_cross_compiler
cross_compcompZnew_optionsZ	optprefixr)  Z
cmd_prefixZcmd_argrP  r"   r"   r&   detect_compilers"  s    

zInterpreter.detect_compilersc             C   s`  d } |  j  j   o$ |  j  j j   } x2t | d t j D]} | j   } | |  j j k r |  j j | } |  j j	 j
 | d   } nb y |  j | |  \ } } WnC t k
 r | s t j d t j |  d  d } w= n   Yn Xt j d | j   t j d j | j     d | j | j f d	 d
 | j   |  j j k rt  j |  \ } }	 }
 | |  j j | j   <|	 |  j j | j   <|
 |  j j | j   <n  |  j j |  | r"t j d | j   t j d j | j     d | j | j f d	 d
 |  j j |  n  |  j  j   rK| rK|  j j |  n  |  j |  q= W| S)NTr  zCompiler for languagez
not found.FzNative %s compiler: rL   z (%s %s)r3  rd   zCross %s compiler: )r   r~  r   r  sortedr	   
sort_clikelowerr   r  rf   r  r-  r   r4  r5  rB  r*   get_exelistidr   get_languagere  get_args_from_envvarsexternal_preprocess_argsrd  r   Zadd_compilerZadd_cross_compileradd_base_options)r<   r-   rT  successr  rg  r  r  Zpreproc_argsr  r  r"   r"   r&   r  h  s:    !KKzInterpreter.add_languagesc             C   s   |  j  j j } x | j D] } | |  j j k r7 q n  t j | } xB | D]: } | j | d  rK | j | j d d  d  PqK qK W| |  j j | <q Wd  S)Nrh  r   )	r   rk  rl  r`  r   r	   rp  r  rz   )r<   r  Zproj_optrf  ZoobjZpor"   r"   r&   r    s    zInterpreter.add_base_optionsr  c       
      C   sk  | s t  d   n  | j d d  } t | t  sE t d   n  t j j |  j j	   |  j
  } x | D] } t | t j  r | j r t j j |  j j   | j
  } n! t j j |  j j	   | j
  } | j } n- t | t  r | } n t d j |    t j | d | } t |  }	 |	 j   rm |	 Sqm W| rg|	 j   rgt d |   n  |	 S)NzNo program name specified.rT  Tz&"required" argument must be a boolean.z5find_program only accepts strings and files, not {!r}r  z(Program "%s" not found or not executable)r   rf   r(   r#  r   rP   rQ   r*   r   r$  rH   r   r9  is_builtrr  r@  r,   r`   r   r   r   r   )
r<   r>  r-   r>   rT  rF   Zexenamer  ZextprogZprogobjr"   r"   r&   r    s2    !		zInterpreter.func_find_programc             C   s   t  j t  j d  d  d  S)NzDEPRECATION:zSfind_library() is removed, use the corresponding method in compiler object instead.)r   r4  r<  )r<   r>  r-   r>   r"   r"   r&   r    s    zInterpreter.func_find_libraryc             C   s  |  j  j   } d | k r/ | r/ | d } n | } t j | | |  } d  } | |  j j k ru |  j j | } n | d } x |  j j j   D]y \ } }	 | d | d k s | d d   | d d   k r q n  |	 j   }
 | st j	 |
 |  d r |	 } Pq q W| | f S)Nr  r   r    re   )
r   r~  r   Zget_dep_identifierr   r.  r|   r   r   version_compare_many)r<   rt   r>   r   
want_cross
identifier
cached_deprF  trialZ	trial_depr   r"   r"   r&   _find_cached_dep  s"    
4zInterpreter._find_cached_depc             C   s  |  j  | d t g  | d } d | k sD d | k sD d | k rS t d   n  |  j | |  \ } } | r | j d d  r | j   r d	 } t | j |    n  | } n(d
 | k r&|  j |  \ }	 }
 |	 |  j	 k r&|  j	 |	 } y | j
 |
 g i   SWq#t k
 rYq#Xq&n  d  } d  } y t j | |  j |  } Wn+ t k
 r{} z | } WYd  d  } ~ Xn X| s| j   rd
 | k r|  j | |  } | r| Sn  | s| d  k	 st  |  qn  | j   r| |  j j | <n  t |  S)Nr   r    <>rh  zCharacters <, > and = are forbidden in dependency names. To specifyversion
 requirements use the 'version' keyword argument instead.rT  Tz5Dependency {!r} was already checked and was not foundr  )rH  r,   r   r  rf   r   r   r`   get_subproject_infosr  r   r4  r   Zfind_external_dependencyr   dependency_fallbackrC   r   r.  r   )r<   r>  r-   r>   rt   r  r  rF  r   rP  r   rv  	exceptionrW  Zfallback_depr"   r"   r&   r    sF    
$	zInterpreter.func_dependencyc             C   s9   | d } t  |  t |  d k r5 t d   n  | S)Nr  re   z*Fallback info must have exactly two items.)r   rg   r   )r<   r>   Zfbinfor"   r"   r&   r    s
    

z Interpreter.get_subproject_infosc       
       C   s  |  j  j t j t j f k r> t j d t j |  d  d  S|  j |  \ } } yA i  } y | d | d <Wn t	 k
 r Yn X|  j
 | |  WnZ t k
 r   YnF t j d t j t j j |  j |   d t j |   d  SYn Xy  |  j | j | g i   } Wn t	 k
 r| j d d  rTd } t | j | |    n  t j d	 t j |  d
 t j t j j |  j |    d  SYn Xt | t  st d j | |    n  d | k rX| d } | j g  i   }	 |	 d k st j |	 |  rXt j d t j |  d t j |  d t j |	  d t j |  d 	 d  Sn  t j d t j d  d t j t j j |  j |   d t j |   | S)Nz8Not looking for a fallback subproject for the dependencyzJbecause:
Automatic wrap-based fallback dependency downloading is disabled.r  z+Also couldn't find a fallback subproject inzfor the dependencyrT  Tz<Fallback variable {!r} in the subproject {!r} does not existz!Also couldn't find the dependencyzin the fallback subprojectzIFallback variable {!r} in the subproject {!r} is not a dependency object.r   rR  Z
Subprojectr  z
version isZbutzis required.zFound ar  rv  for)r   rS  r   Z
nofallbackZ
nodownloadr   r4  r5  r  r4  r2  r   rP   rQ   r*   r  r  r   rf   r   r`   r(   r   r   r   rV  r=  )
r<   rt   r>   rP  r   Z	sp_kwargsr   rF  rF  r   r"   r"   r&   r    sX    			 "	
!zInterpreter.dependency_fallbackr  c             C   s   |  j  | | | t  S)N)r  r   )r<   r>  r-   r>   r"   r"   r&   r  J  s    zInterpreter.func_executabler  c             C   s   |  j  | | | t  S)N)r  r   )r<   r>  r-   r>   r"   r"   r&   r#  N  s    zInterpreter.func_static_libr  c             C   s   |  j  | | | t  S)N)r  r   )r<   r>  r-   r>   r"   r"   r&   r!  R  s    zInterpreter.func_shared_libr  c             C   s   |  j  | | | t  S)N)r  r   )r<   r>  r-   r>   r"   r"   r&   r"  V  s    zInterpreter.func_shared_modulec             C   s>   |  j  j d  d k r+ |  j | | |  S|  j | | |  S)Ndefault_libraryshared)r   r  r!  r#  )r<   r>  r-   r>   r"   r"   r&   r  Z  s    zInterpreter.func_libraryr  c             C   s    d | d <|  j  | | | t  S)Nr  r  )r  r   )r<   r>  r-   r>   r"   r"   r&   r  _  s    
zInterpreter.func_jarr  c             C   s   d | k r t  d   n  | j d  } | d k rI |  j | | |  S| d k rh |  j | | |  S| d k r |  j | | |  S| d k r |  j | | |  S| d k r |  j | | |  St  d   d  S)	Nr  z$Missing target_type keyword argumentr  r  r  r  r  zUnknown target_type.)r   popr  r!  r#  r  r  )r<   r>  r-   r>   r  r"   r"   r&   r  d  s    zInterpreter.func_build_targetr  c       
   
   C   s  d | k s d | k r' t  d   n  | j d |  j  } t | t  sZ t  d   n  | j d d  } d } | j d	 d   } | r t | t  r | g } n  t j j	 t j j
 |  j j   |  j   } | rt j | d
  pt j j
 | | d
  | d
 <nZ t j |  }	 |	 r]t j d |	 d |	 d f  |	 d j   } |	 d } n	 d g } t j |  j j   d d d d | | | | g
 | | d	 <| j d d  |  j | | d g |  S)Nr  r  z-Keyword arguments input and output must existr  z+Keyword argument fallback must be a string.r  z	@VCS_TAG@z(.*)r   r    zFound %s repository at %srt   wc_dirget_rev	rev_regexrL   z
--internal	vcstaggerz@INPUT0@z	@OUTPUT0@r  T)r   r  ra  r(   r,   rf   r)   rP   rQ   normpathr*   r   r$  rH   shutilwhichr   
detect_vcsr   r4  rz   r   r  get_build_command
setdefaultr  )
r<   r>  r-   r>   r  r  Zregex_selectorZvcs_cmdrF   vcsr"   r"   r&   r%  v  s>    -3	zInterpreter.func_vcs_tagr  c             C   sc   t  |  d k r! t d   n  | d } t t j | |  j |  |   } |  j | | j  | S)Nr   zTcustom_target: Only one positional argument is allowed, and it must be a string namer    )rg   r   r   r   r&  rH   r,  rW   )r<   r>  r-   r>   rt   tgr"   r"   r&   r    s    
!zInterpreter.func_custom_targetr  c             C   s~  t  |  d k rn t s: t j t j d  d  d a n  d | k rU t d   n  | d d   } g  } n t  |  d k r d | k r t d   n  | d } t | t  s | g } n  | j d g   } t | t  s | g } q n t d	   g  } x t	 j
 |  D] } y | j } Wn t k
 r9Yn Xt | t t j t j t j t	 j f  st j d
 t |   t d   n  | j |  qW| d } t | t  st d   n  g  }	 xg | D]_ }
 y |
 j }
 Wn t k
 rYn Xt |
 t j t j f  s!t d   n  |	 j |
  qW| d } | d d   } t | | | |	 |  j  } |  j | | j  | S)Nr   ZDEPRECATIONzPpositional version of run_target is deprecated, use the keyword version instead.Tr   z>Can not have command both in positional and keyword arguments.z"Missing "command" keyword argumentr  z2Run_target needs at least one positional argument.zWrong type:zInvalid argument to run_target.r    z First argument must be a string.z$Depends items must be build targets.)rg   run_depr_printedr   r4  r<  r   r(   r)   rf   r   rB  rW   ro  r,   r   r+  r&  r   r   r9  rT   r[   r   rH   r,  )r<   r>  r-   r>   Zall_argsr.  Zcleaned_argsr)  rt   Zcleaned_depsr0  r   r   r  r"   r"   r&   r    sZ    		
*

zInterpreter.func_run_targetr  c             C   s&   t  |  | |  } |  j j |  | S)N)r   r  r[   )r<   r>  r-   r>   genr"   r"   r&   r    s    zInterpreter.func_generatorr  c             C   s   |  j  | | | d  d  S)NF)add_test)r<   r>  r-   r>   r"   r"   r&   r    s    zInterpreter.func_benchmarkr  c             C   s   |  j  | | | d  d  S)NT)r  )r<   r>  r-   r>   r"   r"   r&   r$    s    zInterpreter.func_testc             C   s   | j  d t    } t | t  r0 | j } n t | t  sK | g } n  t   } x | D] } d | k r| t d   n  | j d d  \ } } | j   } | j   } d | k r t d   n  | j | | g i   q[ W| j } | S)NrM   rh  z+Env var definition must be of type key=val.r   rL   z'Env var key must not have spaces in it.)	rf   rY   r(   rW   r)   r   rz   stripr]   )r<   r>   ZenvlistrM   rW  r}   ru   r"   r"   r&   unpack_env_kwarg  s"    		zInterpreter.unpack_env_kwargc          
   C   sx  t  |  d k r! t d   n  t | d t  sC t d   n  | d } t | t t t f  s t | t j  r |  j	 | | d f i   } q t d   n  | j
 d d  } t | t  s t d	   n  | j
 d
 g   } t | t  s| g } n  x8 | D]0 } t | t t j t f  s	t d   q	q	Wt j |  } |  j |  }	 | j
 d d  }
 t |
 t  st d   n  | j
 d d  } d | k r| d } t | t  st d   n  t j j |  st d   qn d  } t | t  st d   n  g  } x t j | j
 d d   D] } t  |  d k r`d | } n  |  j   r| j |  j j d d  j d d  |  q;| j |  j j j d d  j d d  |  q;Wt | d | | j | | |	 |
 | | 	 } | r;|  j j j |  t j d t j  | d  d d d n9 |  j j! j |  t j d t j  | d  d d d d  S)Nre   zIncorrect number of argumentsr    z(First argument of test must be a string.r   z#Second argument must be executable.r   Tz/Keyword argument is_parallel must be a boolean.r-   z9Command line arguments must be strings, files or targets.r   Fz/Keyword argument should_fail must be a boolean.r      r   z*Workdir keyword argument must be a string.z2Workdir keyword argument must be an absolute path.zTimeout must be an integer.r   rd   rZ  rL   rm  zAdding test "z".r3  zAdding benchmark ")"rg   r   r(   r,   r   r   r   r   r9  r  rf   r#  r)   r   rC  r  rP   rQ   rV  r+   r   r  r[   rv  replacer   r`  r   rW   Ztestsr   rT   r5  Z
benchmarks)r<   r>  r-   r>   Zis_base_testr   Zparr   r)  rM   r   r   r   r   r   tr"   r"   r&   r    s\    

"/3+)zInterpreter.add_testr  c             C   s5   |  j  |  } t | |  } |  j j j |  | S)N)rA  r   r   rc  r[   )r<   r>  r-   r>   Zsource_filesr   r"   r"   r&   r  0	  s    z Interpreter.func_install_headersr  c             C   s5   |  j  |  } t | |  } |  j j j |  | S)N)rA  r   r   rd  r[   )r<   r>  r-   r>   fargsrF  r"   r"   r&   r  7	  s    zInterpreter.func_install_manc             C   s  |  j  | d t g  d | d k r5 t d   n  |  j d k rf | d |  j k rf t d   n  |  j d k r | d j d  r t d   n  |  j } t j j | | d  } t j j	 |  r t d	   n  t j j |  j
 j   |  } t j j |  } | |  j k r,t d
 |   n  d |  j | <| |  _ t j t j j |  j
 j |  d d t j j |  j t
 j  } |  j j |  t j j |  j
 j   |  }	 t j j |	  s| |  _ t d j |    n  t |	 d d  }
 |
 j   } Wd  QXt | t  s"t  y t j | |  j  j   } Wn7 t j k
 rz} z | | _ |  WYd  d  } ~ Xn X|  j  |  | |  _ d  S)Nr   z..r    zSubdir contains ..rd   zIMust not go into subprojects dir with subdir(), use subproject() instead.zmeson-zJThe "meson-" prefix is reserved and cannot be used for top-level subdir().z(Subdir argument must be a relative path.z>Tried to enter directory "%s", which has already been visited.TrQ  zNon-existent build file {!r}encodingutf8)!rH  r,   r   rH   r  rp  rP   rQ   r*   rV  r   r$  realpathr  rU  rG   r  r  r[   isfiler   r`   openreadr(   rC   r   ZParserparser   MesonExceptionfileZevaluate_codeblock)r<   r>  r-   r>   Zprev_subdirrH   absdirZsymlinkless_dirZbuildfilenameZabsnamefr>  Z	codeblockmer"   r"   r&   r  >	  sF    ""		(		zInterpreter.func_subdirc             C   s   d | k r d  Sg  } t  j | j d g   t t f  } x0 | D]( } | d k r\ d  } n  | j |  qA Wt |  d k r t d   n  t |  d k r | d d  k	 r t | d t  r t d   n  t	 |   S)Nr   F   z8Keyword argument install_mode takes at most 3 arguments.r    zRKeyword argument install_mode requires the permissions arg to be a string or false)
r   typeslistifyrf   r,   r+   r[   rg   r   r(   r   )r<   r>   r   moderF  r"   r"   r&   _get_kwarg_install_moded	  s    $	"z#Interpreter._get_kwarg_install_moder  c             C   s  t  j | j d g    } | | } g  } g  } x= | D]5 } t | t  j  r` | j |  q8 | j |  q8 W| |  j |  7} | j d d   }	 t |	 t t d   f  s t	 d   n  |  j
 |  }
 t t j | |	 |
   } |  j j j | j  | S)Nr   r   z*Keyword argument install_dir not a string.)r   r   rf   r(   r9  r[   rA  r,   typer   r  r   r   r)  r   rW   )r<   r>  r-   r>   ZkwsourceZraw_sourcesr   Zsource_stringsr   r   r   r   r"   r"   r&   r  w	  s     
zInterpreter.func_install_datar   c                s  t  |  d k r! t d   n  | d   d | k rF t d   n  | d } t | t  sn t d   n  d | k r| d } t | t  s | g } n  xM | D]E } t | t  s t d   q t j j |  r t d	   q q W  f d
 d   | D } n	 t   } d | k r| d } t | t  sE| g } n  xM | D]E } t | t  spt d   qLt j j |  rLt d	   qLqLW  f d d   | D }	 n	 t   }	 | |	 f } |  j	 |  }
 t
 |  j   | |
 |  } |  j j j |  | S)Nr   z-Install_subdir requires exactly one argument.r    r   z$Missing keyword argument install_dirz*Keyword argument install_dir not a string.r  zExclude argument not a string.z$Exclude argument cannot be absolute.c                s%   h  |  ] } t  j j   |   q Sr"   )rP   rQ   r*   )r$   r  )rH   r"   r&   	<setcomp>	  s   	 z2Interpreter.func_install_subdir.<locals>.<setcomp>r  c                s%   h  |  ] } t  j j   |   q Sr"   )rP   rQ   r*   )r$   r  )rH   r"   r&   r  	  s   	 )rg   r   r(   r,   r)   rP   rQ   rV  rZ   r  r   rH   r   Zinstall_dirsr[   )r<   r>  r-   r>   r   r   r  r  r0  r  r   r*  r"   )rH   r&   r  	  sF    


	
	zInterpreter.func_install_subdirr  c          
   C   s  t  |  d k r! t d   n  d | k r< t d   n  d | k rc d | k rc t d   n  d | k r t | d t  s t d	   n  d | k r t d
   q n  d  } d  } d | k r| d } t | t  rt  |  d k rd } t |   n  | d } n  t | t t j f  s;t d   n  t | t  rt j	 j
 |  j |  } t j	 j
 |  j j |  } q| j |  j j |  j j  } | j   } n+ d | k rd | d k rt d   n  | d } t | t  s t d   n  | r=t j | g d   } t j | g |  }	 |	 d } n  t j	 j |  d d k rht d   n  t j	 j t j	 j
 |  j |   \ }
 } t j	 j
 |  j j |
 |  } d | k r| d } t | t  st d   n  t j d t j |  d  | d  k	 rt j	 j |  } | |  j k r@|  j j |  n  t j t j	 j
 |  j j |  j  d d t j | | | j  } | rd j
 t t t  |    } t j! d | | f  qn t j" | | j  | j#   nCd | k r| rt j | g | g  } n t j d  | g  } t j | d |  } t j d t j |  d  |  j$ | | i  d  } | j% d k rt d | j& | j' f   n  d | k r'| d r'| d } t( | d d d   } | j) | j&  Wd  QX| rt* j+ | |  n  t j, | |  q'n t d!   | j- d" d   } t | t  rt j j. |
 |  } |  j/ j0 j t/ j1 | g |   n  t j j. |  j |  S)#Nr    z,configure_file takes only keyword arguments.r  z/Required keyword argument "output" not defined.r  r   zhMust not specify both "configuration" and "command" keyword arguments since they are mutually exclusive.r  z$"capture" keyword must be a boolean.z-"capture" keyword requires "command" keyword.r  r   z2Keyword argument 'input' requires exactly one filez Input must be a string or a filez@INPUT@z>@INPUT@ used as command argument, but no input file specified.z!Output file name must be a stringrd   z1Output file name must not contain a subdirectory.z:Argument "configuration" is not of type configuration_dataZConfiguringzusing configurationrQ  Tz, zWThe variable(s) %s in the input file %r are not present in the given configuration datazwith commandz'Running configure command failed.
%s
%s~wr  zutf-8z=Configure_file must have either "configuration" or "command".r   )2rg   r   r(   r#  r)   r,   r   r9  rP   rQ   r*   rH   r   rF   rJ  rG   relative_nameget_filenames_templates_dictsubstitute_valuesrz   rj   r   r4  r5  r  r  r[   rU  do_conf_filerW   mapreprr  r9  dump_conf_headerrr   rI  r/   r1   r2   r  
writelinesr  copymodereplace_if_differentrf   from_built_filer   r   r)  )r<   r>  r-   r>   Z	inputfileZ	ifile_absrF  r  rx   outputsZ
ofile_pathZofile_fnameZ	ofile_absZconfconffilemissing_variablesZvar_listrE   r5   dst_tmpr  r*  Zcfiler"   r"   r&   r  	  s    

*
+
%zInterpreter.func_configure_filer"  c             C   s2  |  j  j   } |  j  j   } t j j | |  j  } t j j | |  j  } x | D] } | j |  ry t d   n  t j j | |  }	 t j j | |  }
 t j j	 |	  rU t j j	 |
  rU t d |   qU qU W| j
 d d  } t | t  st d   n  t t j |  j | |   } | S)Na  Tried to form an absolute path to a source dir. You should not do that but use
relative paths instead.

To get include path to any directory relative to the current dir do

incdir = include_directories(dirname)

After this incdir will contain both the current source dir as well as the
corresponding build dir. It can then be used in any subdirectory and
Meson will take care of all the busywork to make paths work.

Dirname can even be '.' to mark the current directory. Though you should
remember that the current source and build directories are always
put in the include directories by default so you only need to do
include_directories('.') if you intend to use the result in a
different subdirectory.
zInclude dir %s does not exist.r  FzIs_system must be boolean.)r   r$  rr  rP   rQ   r*   rH   rp  r   isdirrf   r(   r#  r   r   r   )r<   r>  r-   r>   Zsrc_rootr  Zabsbase_srcZabsbase_buildr   Z
absdir_srcZabsdir_buildr  r)  r"   r"   r&   r  
  s"    &z$Interpreter.func_include_directoriesr  c             C   s  t  |  d k r! t d   n  | d } t j d |  d  k rR t d   n  y | j d g   } t | t  s | g } n  g  } x | D] } t | d  r | j } n  t | t	  r | j
 |  q t | t j  r| j   s t d   n  | | j   7} q t d	   q WWn t k
 r:d  } Yn X| j d
 d  } t | t  skt d   n  | j d d  }	 t |	 t  st d   n  |  j |  }
 t j d | d
 | d |	 d |
  } |  j d k r| |  j j | <n  d  S)Nr   z5Add_test_setup needs one argument for the setup name.r    z[_a-zA-Z][_0-9a-zA-Z]*z4Setup name may only contain alphanumeric characters.r  rW   z"Tried to use non-found executable.z:Exe wrapper can only contain strings or external binaries.r  FzGdb option must be a booleanr  z$Timeout multiplier must be a number.rM   rd   )rg   r   re	fullmatchrf   r(   r)   rA  rW   r,   r[   r   r   r   rO   r4  r#  r+   r  r   Z	TestSetuprv  Ztest_setups)r<   r>  r-   r>   Z
setup_nameZinpr  r)  r  r  rM   Zsetupobjr"   r"   r&   r  ?
  sF    
	zInterpreter.func_add_test_setupr  c             C   s    |  j  | |  j j | |  d  S)N)r  r   re  )r<   r>  r-   r>   r"   r"   r&   r  i
  s    z%Interpreter.func_add_global_argumentsr  c             C   s    |  j  | |  j j | |  d  S)N)r  r   Zglobal_link_args)r<   r>  r-   r>   r"   r"   r&   r  n
  s    z*Interpreter.func_add_global_link_argumentsr  c             C   s    |  j  | |  j j | |  d  S)N)r  r   ru  )r<   r>  r-   r>   r"   r"   r&   r  s
  s    z&Interpreter.func_add_project_argumentsr  c             C   s    |  j  | |  j j | |  d  S)N)r  r   Zprojects_link_args)r<   r>  r-   r>   r"   r"   r&   r  x
  s    z+Interpreter.func_add_project_link_argumentsc             C   s_   |  j  d k r0 d j | j  } t |   n  |  j p? |  j } |  j | | | | |  d  S)Nrd   a  Function '{}' cannot be used in subprojects because there is no way to make that reliable.
Please only call this if is_subproject() returns false. Alternatively, define a variable that
contains your language-specific arguments and add it to the appropriate *_args kwarg in each target.)rv  r`   	func_namer   r  r  add_arguments)r<   r>  argsdictr-   r>   rX  frozenr"   r"   r&   r  }
  s
    z Interpreter.add_global_argumentsc             C   sF   |  j  | k r i  | |  j  <n  |  j | | |  j  |  j | |  d  S)N)rv  r  r  )r<   r>  r  r-   r>   r"   r"   r&   r  
  s    z!Interpreter.add_project_argumentsc             C   s   | r' d j  | j  } t |   n  d | k rN t d j  | j    n  xA t j | d  D], } | j   } | j | g   | | | <qb Wd  S)NzTried to use '{}' after a build target has been declared.
This is not permitted. Please declare all arguments before your targets.rX  z!Missing language definition in {})r`   r  r   r   r   r  rf   )r<   r>  r  Zargs_frozenr-   r>   rX  rg  r"   r"   r&   r  
  s    zInterpreter.add_argumentsc             C   s   t    S)N)rY   )r<   r>  r-   r>   r"   r"   r&   r  
  s    zInterpreter.func_environmentc             C   s   t  j j |   j d d  S)N\/)rP   rQ   r*   r  )r<   r>  r-   r>   r"   r"   r&   r  
  s    zInterpreter.func_join_pathsc                s<   t    j   t j d t j t t |  j j     d  S)NzBuild targets in project:)	r3   r  r   r4  r5  r,   rg   r   rb  )r<   )r=   r"   r&   r  
  s    zInterpreter.runc             C   s   g  } xx | D]p } t  | t j t t f  r1 n? t  | t  rd t j j |  j j |  j	 |  } n t
 d   | j |  q W| S)Nz.Source item is not string or File-type object.)r(   r   r9  r   r   r,   r?  r   rF   rH   r   r[   )r<   r   resultsr   r"   r"   r&   rA  
  s    $z#Interpreter.source_strings_to_filesc             C   s   | d k r t  d   n  | j d  r9 t d   n  | t j k r[ t d |   n  | j   } | |  j j k r t d |   n  | |  j j | <| |  j j	 k r t
 t j    j   |  j j	 | <n  d  S)Nrd   zTarget name must not be empty.zmeson-zYTarget names starting with 'meson-' are reserved for Meson's internal use. Please rename.zETarget name '%s' is reserved for Meson's internal use. Please rename.zFTried to create target "%s", but a target of that name already exists.)r   rp  r   r   forbidden_target_namesr   r   rb  r   target_guidsr,   uuiduuid4upper)r<   rt   ZtobjZidnamer"   r"   r&   r,  
  s    zInterpreter.add_targetc             C   s  | s t  d   n  | d } | d d   } |  j j   rb | j d d  rY d } qh d } n d } y2 |  j | d  } t | t  s | g } n  Wn t k
 r g  } Yn X| | 7} |  j |  } |  j | j d g    }	 |  j | j d	 g    | d	 <d
 | k rO| d
 }
 t |
 t  s9|
 g }
 n  |  j |
  | d
 <n  t |	 t  sj|	 g }	 n  |  j	 t
 j j |  j |  j  |  | t k rt j } n | t k rt j } nj | t k rt j } nR | t k rt j } n: | t k rt j } n" t j d t |   t d   | | |  j |  j | | |	 |  j |  } | ri|  j |  n  | | |   } |  j  | | j!  d |  _" | S)NzTarget does not have a name.r    r   r  FTr   r  r   r  zUnknown target type:zUnreachable code)#r   r   r~  rf   rB  r(   r)   r4  rA  check_sources_existrP   rQ   r*   r  rH   r   r   r'  r   ZSharedLibraryr   ZSharedModuler   ZStaticLibraryr   ZJarr   rT   r,   r(  rv  add_cross_stdlib_infor,  rW   r  )r<   r>  r-   r>   Ztargetholderrt   r   r   Zkw_srcZobjsZefZtargetclassr   rN  r"   r"   r&   r  
  s\    
		

%*	zInterpreter.build_targetc             C   s^   i  } xQ | j  D]F } x= |  j j j   D]) \ } } | j |  r) d | | <Pq) q) Wq W| S)NT)r   r   r	   r|   can_compile)r<   r   r7  r)  rg  r5  r"   r"   r&   get_used_languages
  s    
zInterpreter.get_used_languagesc             C   so   xh |  j  |  D]W } |  j j j |  r |  j |  j j j |  d k r | j |  j j |  q q Wd  S)Nr    )	r  r   r   
has_stdlibrv  r1  Zadd_depsr   r3  )r<   r   rN  r"   r"   r&   r    s    "z!Interpreter.add_cross_stdlib_infoc             C   sd   x] | D]U } t  | t  s" q n  t j j | |  } t j j |  s t d |   q q Wd  S)Nz)Tried to add non-existing source file %s.)r(   r,   rP   rQ   r*   r  r   )r<   rH   r   r   r@  r"   r"   r&   r    s    zInterpreter.check_sources_existc             C   s   t  | t j  r | j } n  xn t |  D]` \ } } |  j |  } t  | t  rj t |  j   } n  | j	 d j
 |  t |   } q+ W| S)Nz@{}@)r(   r   ZArgumentNoder  	enumerateZevaluate_statementr#  r,   r  r  r`   )r<   templr-   r)  rt  r"   r"   r&   format_string  s    %zInterpreter.format_stringc             C   s   |  j  j |  j  s< | j  j |  j  r t d   q n_ | j  j |  j  s` t d   n  |  j  j d  d | j  j d  d k r t d   n  d  S)Nz2Tried to extract objects from a subproject target.zATried to extract objects from the main project from a subproject.r  r   z5Tried to extract objects from a different subproject.)rH   rp  r  r   rz   )r<   Zbuildtargetr"   r"   r&   validate_extraction  s    ,zInterpreter.validate_extractionc             C   s~   t  |  d k r! t d   n  | d } xL | D]D } t | t  rf |  j | |  } | rf d Sn  | | k r2 d Sq2 Wd S)Nr   z+Contains method takes exactly one argument.r    TF)rg   r   r(   r)   check_contains)r<   objr-   r*  rO  r   r"   r"   r&   r  )  s    
zInterpreter.check_containsc             C   s   |  j  d k S)Nrd   )rv  )r<   r"   r"   r&   r  6  s    zInterpreter.is_subprojectc             C   sI   t  |  d k r! t d   n  | d } | d } |  j | |  d  S)Nre   z!Set_variable takes two arguments.r    r   )rg   r   r  )r<   r>  r-   r>   r   rP  r"   r"   r&   r  9  s
    

zInterpreter.func_set_variablec             C   s   t  |  d k  s$ t  |  d k r3 t d   n  | d } t | t  s[ t d   n  y |  j | SWn t k
 r~ Yn Xt  |  d k r | d St d |   d  S)Nr   re   z(Get_variable takes one or two arguments.r    z First argument must be a string.z#Tried to get unknown variable "%s".)rg   r   r(   r,   r   r   r4  )r<   r>  r-   r>   r   r"   r"   r&   r  A  s    $
zInterpreter.func_get_variablec             C   s8   t  |  d k r! t d   n  | d } | |  j k S)Nr   z Is_variable takes two arguments.r    )rg   r   r   )r<   r>  r-   r>   r   r"   r"   r&   r  P  s    
zInterpreter.func_is_variable)Zr?   r@   rA   r4   r  rx  r-  ry  r/  r0  r7  r   r   r  r  r   permitted_kwargsr   r  r  rH  r  rI  r	  r  r   r2  r
  r   rm  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  r!  r"  r  r  r  r%  r  r  r  r  r$  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rA  r,  r  r  r  r  r  r  r  r  r  r  r  r"   r"   )r=   r&   r  "  s   	&2&$&%*/F!!65&	34&(f$)3	
r  )_rd   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Zinterpreterbaser   r   r   r   r   r   r   r   r   r   r   r:  r   rP   r   r  r  r  collectionsr!   r;  r  r#   r.   rB   rV   rY   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r]  rj  r}  rZ   Z
pch_kwargsZlang_arg_kwargsZvala_kwargsZrust_kwargsZ	cs_kwargsZbuildtarget_kwargsZbuild_target_common_kwargsZ
exe_kwargsZshlib_kwargsZshmod_kwargsZstlib_kwargsrS   Z
jar_kwargsr7   Zbuild_target_kwargsr  r  r"   r"   r"   r&   <module>   s  (0
("T	*
 0



(


