
    eE                    L   d dl mZ d dlZd dlZd dlZd dlZddlmZ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 ddlmZ dd	l
mZmZ dd
lmZmZmZmZmZmZm Z  ddl!m"Z" ejF                  rddlm$Z$ ddlm%Z% ddl&m'Z' g dZ( G d dejR                        Z* G d de"      Z+y)    )annotationsN   )	compilersenvironmentmesonliboptinterpreter)coredata)
ExecutableJarSharedLibrarySharedModuleStaticLibrary)detect_compiler_for)InvalidArguments)MachineChoice	OptionKey)BaseNodeArithmeticNode	ArrayNodeElementaryNodeIdNodeFunctionNodeBaseStringNode   )AstInterpreter)BuildTarget)	TYPE_nvar)
AstVisitor)
executablejarlibraryshared_libraryshared_modulestatic_libraryboth_librariesc                  (     e Zd Zd fdZddZ xZS )IntrospectionHelperc                L    t         |           || _        d | _        i | _        y N)super__init__
cross_filenative_filecmd_line_options)selfr,   	__class__s     >/usr/lib/python3/dist-packages/mesonbuild/ast/introspection.pyr+   zIntrospectionHelper.__init__/   s%    $ $24    c                    t         S r)   )NotImplemented)r/   others     r1   __eq__zIntrospectionHelper.__eq__5   s    r2   )r,   str)r5   objectreturnbool)__name__
__module____qualname__r+   r6   __classcell__r0   s   @r1   r'   r'   -   s    5r2   r'   c                       e Zd Z	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d f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 xZS )IntrospectionInterpreterc	                   ||ng }t         
|   ||||       t        |      }	|| _        |t	        j
                  |d |	      | _        n|| _        || _        | j                  j                         | _        || _	        t        d      | j                  i| _        i | _        g | _        g | _        d | _        | j                   j#                  | j$                  | j&                  | j(                  | j*                  | j,                  | j.                  | j0                  | j2                  | j4                  | j6                  d
       y )N)visitorsbackend)
add_languages
dependencyr   r    r!   projectr"   r#   r$   r%   )r*   r+   r'   r,   r   Environmentsubproject_dirget_coredatar	   rD   r   default_optionsproject_datatargetsdependenciesproject_nodefuncsupdatefunc_add_languagesfunc_dependencyfunc_executablefunc_jarfunc_libraryfunc_projectfunc_shared_libfunc_shared_modulefunc_static_libfunc_both_lib)r/   source_rootsubdirrD   rC   r,   
subprojectrI   envoptionsr0   s             r1   r+   z!IntrospectionInterpreter.__init__;   s%     (38fj8L%j1$;*66{D'RD"D,((557 )) 4dllC02358:&*

!44....==(((("22!44"22"00
 	r2   c                   | j                   rt        d      || _         t        |      dk  rt        d      |d   }|j                  dd      }| j	                  |dd        }t        |t              r|j                  }t        |t              sd}||d| _	        t        j                  j                  | j                  | j                  d      }t        j                  j                  |      s5t        j                  j                  | j                  | j                  d	      }t        j                  j                  |      rUt!        j"                  | j$                        }|j'                  |       | j(                  j+                  |j,                         | j	                  |j                  d
g             }	t/        j0                  |	      }
t3        j4                  |
| j$                        | _        | j8                  j;                  | j6                         | j(                  j=                  | j8                  | j$                  | j>                         | jA                         sFd|v rB|d   }t        |tB              r-t        |j                  t              sJ |j                  | _"        | jA                         sg | j                  d<   t        j                  j                  | j                  | jD                        }t        j                  jG                  |      rit        jH                  |      D ]Q  }t        j                  jG                  t        j                  j                  ||            sA| jK                  |       S | j(                  jM                  | jN                         | j>                  j,                  jQ                         D ci c]  \  }}|jS                         s|| }}}| j(                  jU                  |       | jW                  |dtX        jZ                         | jW                  |dtX        j\                         y c c}}w )NzSecond call to project()r   zCNot enough arguments to project(). Needs at least the project name.r   version	undefined)descriptive_namerb   zmeson.optionszmeson_options.txtrK   rI   subprojectsT)/rO   r   lengetflatten_args
isinstancer   valuer7   rL   ospathjoinr\   r]   existsr   OptionInterpreterr^   processr	   update_project_optionsr`   r   stringlistifycdatacreate_options_dictproject_default_optionsrK   rQ   set_default_optionsr   is_subprojectr   rI   isdirlistdirdo_subprojectinit_backend_optionsrD   items
is_backendset_options_add_languagesr   HOSTBUILD)r/   nodeargskwargs	proj_name	proj_vers
proj_langsoptfileoidef_opts_project_default_options	spdirnamesubprojects_dirikvr`   s                    r1   rW   z%IntrospectionInterpreter.func_projectc   s(   "#=>> t9q="#hiiG	JJy+6	&&tABx0
i0!I)S)#I1:yQ'',,t//oNww~~g&ggll4#3#3T[[BUVG77>>'"11$//BBJJwMM00<$$VZZ0A2%FG#+#9#9(#C ','@'@AY[_[j[j'k$##D$@$@A))$*>*>QUQaQab!!#(8F(B/0I)^4!)//3777&/oo#!!#/1Dm, ggll4+;+;T=P=PQOww}}_-O4 .Aww}}RWW\\/1%EF**1-. 	**4<<8$($4$4$<$<$B$B$DWDAq1a4WW!!'*Jm.@.@AJm.A.AB	 Xs   Q)Qc           
        t         j                  j                  | j                  j	                         | j
                        }t         j                  j                  ||      }	 t        |d| j                  | j                  || j
                  | j                  | j                        }|j                          ||j                  d<   | j                  dxx   |j                  gz  cc<   y # t        j                  t        f$ r Y y w xY w)N )r,   r^   rI   r_   rC   namere   )rk   rl   rm   r   get_source_dirrI   rA   rD   r,   rC   analyzerL   r   MesonExceptionRuntimeError)r/   dirnamesubproject_dir_abssubprsubis        r1   rz   z&IntrospectionInterpreter.do_subproject   s    WW\\$*:*:*I*I*KTM`M`a/9	+E2t||PTP_P_ls  EI  EX  EX  ^b  ^n  ^n  y}  yF  yF  GDLLN(/Df%m,1B1B0CC,''6 		s   $BC+ +DDc                   | j                  |      }|j                  dd      }t        |t        j                        r|j                         }d|v rK|j                  dd      }| j                  |||rt        j                         y t        j                         y t        j                  t        j                  fD ]  }| j                  |||        y )NrequiredTnativeF)
flatten_kwargsrg   ri   rs   UserFeatureOption
is_enabledr   r   r   r   )r/   r   r   r   r   r   for_machines          r1   rR   z+IntrospectionInterpreter.func_add_languages   s    $$V,::j$/h 7 78**,HvZZ%0Fhv0C0CfS`SeSef - 3 3]5G5GH A##D(K@Ar2   c                   g }| j                  |      D ]P  }t        |t              r|j                  |       %t        |t              s6|j                  |j
                         R t        |t        j                        D ]  }|j                         }|| j                  j                  |   vs/	 t        | j                  ||d      }| j                  sUi }|j!                         D ]O  }	t#        j"                  | j                  j$                  |	         }
|	j'                  | j                        }	|
||	<   Q | j                  j)                  |||| j                          y # t        j                  $ r |r Y w xY w)N)keyTr^   )rh   ri   r7   appendr   rj   sortedr   
sort_clinklowerr	   r   r   r   r   r^   get_optionscopyr`   evolveadd_compiler_options)r/   	raw_langsr   r   langsllangcompr`   r   r   s              r1   r   z'IntrospectionInterpreter._add_languages   sO   ""9- 	&A!S!QA~.QWW%		& 5i&:&:; 	eD::<D4==22;??!.t/?/?{TXYD ?? G!--/ ' IIdmm&;&;A&>?HHH@%&
' MM66wkSWScScd#	e
  .. ! !s   2E&&E?>E?c           	     ~   | j                  |      }| j                  |      }|sy |d   }d|v }|j                  dd      }|j                  dg       }t        |t              s|g}t        |t
              r|j                  }t        |t              sd}| xj                  |||||j                  dkD  |dgz  c_        y )Nr   fallbackr   Trb   F)r   r   rb   has_fallbackconditionalr   )
rh   r   rg   ri   listr   rj   r:   rN   condition_level)r/   r   r   r   r   r   r   rb   s           r1   rS   z(IntrospectionInterpreter.func_dependency   s      &$$V,Aw!V+::j$/**Y+'4(iGh/~~H(D)H (//!3
  	r2   c                F     j                  |      }|rt        |d   t              sy |d   }|g}g }d|v r|t        j                  |d         z  }d|v r|t        j                  |d         z  } j                  |d      }d	 fd}	 |	|      }
 |	|      }|j                         D ci c]  \  }}||j                  v s|dv s|| }}}|j                         D ci c]$  \  }}|t        |t              r|j                  n|& }}}|j                         D ci c]  \  }}t        |t              r|| }}}t        j                  }g }g }d|d<    || j                   j                  ||g | j                   j                   j"                  |   |
      }|j%                          |j'                         |j)                         |j+                         t,        j.                  j1                  t,        j.                  j3                   j4                   j                  t        j6                               j                  |j8                  |j;                         |j=                         |
|||d} xj>                  |gz  c_        |S c c}}w c c}}w c c}}w )
Nr   sourcesextra_filesTc                   g }| r| j                  d      }d }t        |t              sJ t        |t              r|j                  }nt        |t
              r|j                  }nt        |t              rgt        |j                  t              sJ |j                  }|	j                  v r\	j                  |   }t        |t
        t        t        f      r2| |gz  } n+t        |t              r| |j                  |j                  gz  } ||j                  j                         }t        |t              r-|j                  j                  t         v r|j                  d       |D cg c]  }t        |t        t"        f      s| }}| |D cg c]%  }t        |t        t
        t        t        f      s$|' c}z  } |r||gz  }| r|S c c}w c c}w )Nr   )popri   r   r   r   r   r   rj   r7   assignmentsr   leftright	argumentsr   	func_nameBUILD_TARGET_FUNCTIONSr   )
inqueuerescurrarg_nodevar_nametmp_node	arg_nodesxelementary_nodesr/   s
            r1   traverse_nodesz=IntrospectionInterpreter.build_target.<locals>.traverse_nodes   s   $&C{{1~!$111dL1#yyHi0#yyHf-%djj#666#zzH4#3#33#'#3#3H#=%hFL0QR#z1Gn5		4::66G#$..335	dL1dnn6J6JNd6dMM!$/8#a!Jq3P^J_<`A#a #ayu!Jq<QZ\bdrBs4tAuu#D6MC7 8 J	 $bus   'GG%G4G>   installbuild_alwaysbuild_by_default_allow_no_sources)r   idtype
defined_inr]   r   	installedoutputsr   r   r   r   )r   T.List[BaseNode]r9   r   ) rh   ri   r7   r   listifyr   r|   known_kwargsr   rj   r   r   r   r]   r^   r   r	   r   process_compilers_lateget_basenameget_idget_typenamerk   rl   normpathrm   r\   build_filenamer   should_installget_outputsrM   )r/   r   r   
kwargs_rawtargetclassr   srcqueueextra_queuer   r   source_nodesextraf_nodesr   r   kwargs_reducedr   objectsempty_sourcestarget
new_targets   `                   r1   build_targetz%IntrospectionInterpreter.build_target   s     &:d1gs3Aw6 
"((I)>??HJ&8++J},EFFK$$Z6	@ &h/%k2 ,2<<>  U41aQ+BZBZ=Z_`  eT  `T!Q$  U  UYgYmYmYopQUQRTU!
1n(EQWW1Lpp+9+?+?+Aa41aTUW_I`!Q$aa#((!#').2*+T4;;m]_ah!--t}}/F/F{/SUce%%' '')--/'')''**277<<8H8H$++WbWqWq+rskk & 7 7..0))+#'

 	$9 Upas$   ,JJJ#)J"J;Jc                    | j                   j                  t        d            }|dk(  r| j                  |||t              S |dk(  r| j                  |||t
              S |dk(  r| j                  |||t              S y )Ndefault_librarysharedstaticboth)r	   
get_optionr   r   r   r   )r/   r   r   r   r   s        r1   build_libraryz&IntrospectionInterpreter.build_library2  s|    --229=N3OPh&$$T4GG($$T4GG&$$T4GGr2   c                2    | j                  |||t              S r)   )r   r
   r/   r   r   r   s       r1   rT   z(IntrospectionInterpreter.func_executable<  s      tVZ@@r2   c                2    | j                  |||t              S r)   )r   r   r   s       r1   rZ   z(IntrospectionInterpreter.func_static_lib?        tV]CCr2   c                2    | j                  |||t              S r)   r   r   r   s       r1   rX   z(IntrospectionInterpreter.func_shared_libB  r   r2   c                2    | j                  |||t              S r)   r   r   s       r1   r[   z&IntrospectionInterpreter.func_both_libE  r   r2   c                2    | j                  |||t              S r)   )r   r   r   s       r1   rY   z+IntrospectionInterpreter.func_shared_moduleH  s      tV\BBr2   c                (    | j                  |||      S r)   )r   r   s       r1   rV   z%IntrospectionInterpreter.func_libraryK  s    !!$f55r2   c                2    | j                  |||t              S r)   )r   r   r   s       r1   rU   z!IntrospectionInterpreter.func_jarN  s      tVS99r2   c                   d|vry |j                  d      }t        |t              r|j                  }|dk(  r| j	                  |||t
              S |dk(  r| j	                  |||t              S |dk(  r| j	                  |||t              S |dk(  r| j	                  |||t              S |dk(  r| j                  |||      S |dk(  r| j	                  |||t              S y )Ntarget_typer   r"   r$   r%   r!   r    )
r   ri   r   rj   r   r
   r   r   r   r   )r/   r   r   r   r   s        r1   func_build_targetz*IntrospectionInterpreter.func_build_targetQ  s    &jj/k>2%++K,&$$T4DD,,$$T4GG,,$$T4GG,,$$T4GGI%%%dD&99E!$$T4==r2   c                     | j                   dk7  S )Nr   r   r/   s    r1   rw   z&IntrospectionInterpreter.is_subprojecte  s    "$$r2   c                    | j                          | j                          | j                          | j                          y r)   )load_root_meson_filesanity_check_astparse_projectrunr  s    r1   r   z IntrospectionInterpreter.analyzeh  s/    !!#
r2   c                h   | j                   j                  sy| j                   j                  d   }t        |t              sy|j                  j
                  j                         D ]J  \  }}t        |t              sJ d       |j                  dk(  s-t        |t              s>|j                  c S  y)zFast path to extract subproject_dir kwarg.
           This is faster than self.parse_project() which also initialize options
           and also calls parse_project() on every subproject.
        Nr   zfor mypyrI   )
astlinesri   r   r   r   r|   r   rj   r   )r/   rG   kwvals       r1   extract_subproject_dirz/IntrospectionInterpreter.extract_subproject_dirn  s    
 xx~~((..#'<0||**002 	%GBb&)5:5)xx++c>299$	% r2   )NNr   re   N)r\   r7   r]   r7   rD   r7   rC   zT.Optional[T.List[AstVisitor]]r,   T.Optional[str]r^   r7   rI   r7   r_   z#T.Optional[environment.Environment])r   r   r   T.List[TYPE_nvar]r   T.Dict[str, TYPE_nvar]r9   None)r   r7   r9   r  )r   r  r   r:   r   r   r9   r  )
r   r   r   r  r   r  r   zT.Type[BuildTarget]r9   T.Optional[T.Dict[str, T.Any]])r   r   r   r  r   r  r9   r  )r9   r:   )r9   r  )r9   r  )r;   r<   r=   r+   rW   rz   rR   r   rS   r   r   rT   rZ   rX   r[   rY   rV   rU   r  rw   r   r  r>   r?   s   @r1   rA   rA   8   s     =A/3#%'4<@&!&& & :	&
 -& !& "%& :&P0Cd	
Ae60QfADDDC6:(%r2   rA   ),
__future__r   argparser   rk   typingTr   r   r   r   r   r	   rs   buildr
   r   r   r   r   r   interpreterbaser   r   r   mparserr   r   r   r   r   r   r   interpreterr   TYPE_CHECKINGr   r   visitorr   r   	Namespacer'   rA    r2   r1   <module>r      sr   $ #   	  ? ?   O O + . / o o o '??#+# 
	(,, 	G~ Gr2   