o
    uJAf                    @  s  d dl mZ d dlmZmZ d dlmZ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Zd dlZd dlZd dlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ej;rd dl<m=Z=m>Z> ddlm?Z? ddl@mAZA ddlBmCZC ddl/mDZD ddlEmFZFmGZG ddlHmIZI ddl8mJZJ ddlKmLZL ddlmMZMmNZNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU ejVd ZWejVd ZXejVd ZYejVeZddd f Z[G d!d" d"e>Z\d#d$hZ]d%d& e5D Z^e^h d'O Z^h d(Z_d)d*hZ`d+d,hZah d-Zbebe^B e]B e_B e`B eaB Zcech d.B Zdech d/B Zeecd0d1hB Zfech d2B Zgedd3d4hB Zhdd;d<Zie
dd=dd?d@ZjG dAdB dBeZkedCdDG dEdF dFeZledCdDG dGdH dHeZmedCdDG dIdJ dJeZnedCdDG dKdL dLeZoedCdDG dMdN dNeZpedCdDG dOdP dPZqG dQdR dRZredCdDG dSdT dTeZsedCdDG dUd deZtedCdCdVG dWdX dXeZuedCdDG dYdZ dZeejvd[ZwG d\d] d]ewZxG d^d_ d_ZyG d`da daZzG dbdc dceZ{edCdDG ddde deeZ|G dfdg dgexZ}G dhdi diexZ~G djdk dkexZG dldm dmeZG dndo doeZG dpdq dqZG drds dsZG dtdu dueweeZG dvdw dwexZG dxdy dyeweZG dzd{ d{eZG d|d} d}exZedCdDG d~d deeZG dd deZedCdDG dd deZedCdDG dd deZedCdDG dd dZdd ZdddZdddZdS )    )annotations)defaultdictOrderedDict)	dataclassfieldInitVar)	lru_cacheN   )coredatadependencies)mlog)programs)HoldableObjectSecondLevelHolderFileMesonExceptionMachineChoice
PerMachine
OrderedSetlistifyextract_as_listtypeslistifystringlistifyclassify_unity_sourcesget_filenames_templates_dictsubstitute_valueshas_path_sep	OptionKeyPerMachineDefaultableMesonBugExceptionEnvironmentVariablespickle_load)	is_header	is_object	is_sourceclink_langs
sort_clinkall_languagesis_known_suffixdetect_static_linker)
FeatureNewFeatureDeprecated)Literal	TypedDict)environment)ImmutableListProtocol)Backend)Compiler)SourceOutputsInterpreter)Test)
SubProject)StaticLinker)ExecutableSerialisationFileModeFileOrString)ModuleState)BaseNode)WrapMode)CustomTargetCustomTargetIndexGeneratedList)SharedLibraryStaticLibraryr>   r?   )BuildTargetr>   r?   r   ExtractedObjectsGeneratedTypesc                   @  s.   e Zd ZU ded< ded< ded< ded< dS )		DFeaturesboolunittestzT.List[T.Union[str, int]]debugT.List[IncludeDirs]import_dirsversionsN__name__
__module____qualname____annotations__ rR   rR   5/usr/lib/python3.10/site-packages/mesonbuild/build.pyrF   C   s
   
 rF   c_pchcpp_pchc                 C  s   h | ]}| d qS )_argsrR   .0langrR   rR   rS   	<setcomp>L   s    rZ   >   d_import_dirsd_module_versions
d_unittestd_debug>   	vala_vapivala_girvala_headerrust_crate_typerust_dependency_map	resourcesZcs_args>   gui_appinstallname_prefixextra_filesbuild_rpathname_suffixsourceslink_languageinstall_tagbuild_by_default	link_withZnativeoverride_optionsimplicit_include_directoriesobjects	link_argsgnu_symbol_visibilityr   install_dirwin_subsysteminclude_directories
link_wholeinstall_modeinstall_rpathlink_depends>   export_dynamicimplibpievs_module_defs>   rust_abi	soversiondarwin_versionsr   versionr   r   >   picr   prelink
main_classjava_resourcesrm   #T.Optional[T.List[T.Optional[str]]]num_outputsintreturnT.List[T.Optional[str]]c                 C  s2   | s	d g| }|S t | dkr| | }|S | }|S )Nr	   )len)rm   r   Z_install_tagrR   rR   rS   _process_install_tag   s   
r   maxsizestrc                 C  s<   d| j | jg}| jd ur|d| j  |d d|S )Nz@rpath/..dylib )prefixnamer   appendjoin)Zldr   rR   rR   rS   #get_target_macos_dylib_install_name   s
   


r   c                   @  s   e Zd ZdS )InvalidArgumentsN)rN   rO   rP   rR   rR   rR   rS   r      s    r   F)eqc                   @  s*   e Zd ZU ded< ded< dZded< dS )	DependencyOverridezdependencies.Dependencydepz
'BaseNode'nodeTrG   explicitN)rN   rO   rP   rQ   r   rR   rR   rR   rS   r      s   
 r   c                   @  st   e Zd ZU ded< ded< ded< ded< ded	< d
Zded< dddZdddZdddZdddZdddZ	d
S )HeadersT.List[File]rk   T.Optional[str]install_subdircustom_install_dir
'FileMode'custom_install_moder   
subprojectNT.Optional[bool]follow_symlinkssubdirr   Nonec                 C  
   || _ d S Nr   )selfr   rR   rR   rS   set_install_subdir      
zHeaders.set_install_subdirc                 C     | j S r   r   r   rR   rR   rS   get_install_subdir      zHeaders.get_install_subdirc                 C  r   r   rk   r   rR   rR   rS   get_sources   r   zHeaders.get_sourcesc                 C  r   r   r   r   rR   rR   rS   get_custom_install_dir   r   zHeaders.get_custom_install_dirc                 C  r   r   r   r   rR   rR   rS   get_custom_install_mode   r   zHeaders.get_custom_install_mode)r   r   r   r   r   r   r   r   r   r   )
rN   rO   rP   rQ   r   r   r   r   r   r   rR   rR   rR   rS   r      s   
 



r   c                   @  sT   e Zd ZU ded< ded< ded< ded< ded	< dddZdddZdddZdS )Manr   rk   r   r   r   r   r   r   localer   c                 C  r   r   r   r   rR   rR   rS   r      r   zMan.get_custom_install_dirc                 C  r   r   r   r   rR   rR   rS   r      r   zMan.get_custom_install_modeT.List['File']c                 C  r   r   r   r   rR   rR   rS   r      r   zMan.get_sourcesNr   r   )r   r   )rN   rO   rP   rQ   r   r   r   rR   rR   rR   rS   r      s   
 

r   c                   @  s2   e Zd ZU ded< ded< ded< dZded< dS )	EmptyDirr   pathr   ry   r   Nr   rm   )rN   rO   rP   rQ   rm   rR   rR   rR   rS   r      s
   
 r   c                   @  sr   e Zd ZU ded< ded< ded< ded< ded< ded	< d
ed< ded< dZd
ed< dZded< dZded< dS )
InstallDirr   Zsource_subdirZinstallable_subdirru   install_dir_namer   ry   zT.Tuple[T.Set[str], T.Set[str]]ZexcluderG   Zstrip_directoryr   Tfrom_source_dirNr   rm   r   r   )rN   rO   rP   rQ   r   rm   r   rR   rR   rR   rS   r      s   
 r   c                   @  s8   e Zd ZU ded< ded< ded< ded< dd
dZdS )DepManifestr   r   T.List[str]licensezT.List[T.Tuple[str, File]]license_filesr   r   &T.Dict[str, T.Union[str, T.List[str]]]c                 C  s   | j | jdd | jD dS )Nc                 S  s   g | ]}|d    qS )r	   )relative_namerX   lrR   rR   rS   
<listcomp>       z'DepManifest.to_json.<locals>.<listcomp>r   r   r   r   r   rR   rR   rS   to_json   s   zDepManifest.to_jsonN)r   r   )rN   rO   rP   rQ   r   rR   rR   rR   rS   r      s   
 r   c                   @  s   e Zd ZdZdBddZdd Zdd	 ZdCddZdDddZdEddZ	dd Z
dd ZdFddZdGddZdGdd ZdHd"d#ZdId%d&ZdJd(d)ZdKd+d,ZdLd.d/ZdMd1d2ZdNd7d8ZdOd;d<ZdNd=d>ZdOd?d@ZdAS )PBuildzYA class that holds the status of one build including
    all dependencies and so on.
    r/   environment.Environmentc                 C  s  t j| _d| _d | _|| _i | _t | _t | _	t
i i | _t
i i | _t
i i | _t
i i | _g | _g | _g | _g | _g | _g | _g | _t
d d | _i | _d| _g | _g | _g | _g | _d | _i | _t
i i | _i | _ d | _!i | _"t | _#t$%|& i i | _'g | _(g | _)d S )Nzname of master projectr   )*r
   r   Zproject_nameZproject_versionr/   projectsr   targetssetZtargetnamesr   global_argsglobal_link_argsprojects_argsprojects_link_argstests
benchmarksheadersmanemptydirdatasymlinksstatic_linkersubprojectssubproject_dirZinstall_scriptsZpostconf_scriptsZdist_scriptsinstall_dirsZdep_manifest_nameZdep_manifestZstdlibsZtest_setupsZtest_setup_default_nameZfind_overridesZsearched_programsr   defaultis_cross_buildZdependency_overridesdevenvmodules)r   r/   rR   rR   rS   __init__   sJ   

zBuild.__init__c                 C  0   t  }| j D ]\}}t|tr|||< q|S r   )r   r   items
isinstancerC   )r   Zbuild_targetsr   trR   rR   rS   get_build_targets!     
zBuild.get_build_targetsc                 C  r   r   )r   r   r   r   r>   )r   Zcustom_targetsr   r   rR   rR   rS   get_custom_targets(  r   zBuild.get_custom_targetsr   c                 C  sN   t | j}| j D ]\}}t|ttttfr|	 |j|< q
||j|< q
|S r   )
r   r/   __dict__r   r   listdictr   r   copyr   otherkvrR   rR   rS   r   /  s   
z
Build.copyr   r   c                 C  s"   |j  D ]	\}}|| j |< qd S r   )r   r   r   rR   rR   rS   merge8  s   zBuild.mergecompilerr2   c                 C  s8   | j |j d u r| rt| j|| j |j< d S d S d S r   )r   for_machineZneeds_static_linkerr*   r/   )r   r   rR   rR   rS   ensure_static_linker<  s   zBuild.ensure_static_linkerc                 C  
   | j d S )Nr   )r   r   rR   rR   rS   get_project@  r   zBuild.get_projectc                 C  r   r   )r   r   rR   rR   rS   get_subproject_dirC  r   zBuild.get_subproject_dir8'T.OrderedDict[str, T.Union[CustomTarget, BuildTarget]]'c                 C  r   r   )r   r   rR   rR   rS   get_targetsF  r   zBuild.get_targetsT.List['Test']c                 C  r   r   )r   r   rR   rR   rS   	get_testsI  r   zBuild.get_testsc                 C  r   r   )r   r   rR   rR   rS   get_benchmarksL  r   zBuild.get_benchmarksT.List['Headers']c                 C  r   r   )r   r   rR   rR   rS   get_headersO  r   zBuild.get_headersT.List['Man']c                 C  r   r   )r   r   rR   rR   rS   get_manR  r   zBuild.get_manT.List['Data']c                 C  r   r   )r   r   rR   rR   rS   get_dataU  r   zBuild.get_dataT.List['SymlinkData']c                 C  r   r   )r   r   rR   rR   rS   get_symlinksX  r   zBuild.get_symlinksT.List['EmptyDir']c                 C  r   r   )r   r   rR   rR   rS   get_emptydir[  r   zBuild.get_emptydirT.List['InstallDir']c                 C  r   r   )r   r   rR   rR   rS   get_install_subdirs^  r   zBuild.get_install_subdirs
'Compiler'r   'MachineChoice'r   c                 C     | j | }|| g S r   )r   getget_languager   r   r   drR   rR   rS   get_global_argsa     
zBuild.get_global_argsprojectr   c                 C  ,   | j | }||}|sg S || g S r   )r   r  r  )r   r   r  r   r  argsrR   rR   rS   get_project_argse  s
   

zBuild.get_project_argsc                 C  r  r   )r   r  r  r  rR   rR   rS   get_global_link_argsl  r  zBuild.get_global_link_argsc                 C  r  r   )r   r  r  )r   r   r  r   r  rs   rR   rR   rS   get_project_link_argsp  s
   

zBuild.get_project_link_argsN)r/   r   )r   r   )r   r   r   r   )r   r2   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   )rN   rO   rP   __doc__r   r   r   r   r   r   r   r  r  r  r  r  r
  r  r  r  r  r  r  r   r!  rR   rR   rR   rS   r      s.    
)

	












r   c                   @  sn   e Zd ZU dZded< ded< ded< eedZded	< dddZdddZ	dddZ
dddZdddZdS )IncludeDirsz7Internal representation of an include_directories call.r   curdirr   incdirsrG   	is_systemdefault_factoryextra_build_dirsr   c                 C  s   d}| | jj| j| jS )Nz
<{} {}/{}>)format	__class__rN   r$  r%  r   rrR   rR   rS   __repr__  s   zIncludeDirs.__repr__c                 C  r   r   )r$  r   rR   rR   rS   
get_curdir  r   zIncludeDirs.get_curdirc                 C  r   r   )r%  r   rR   rR   rS   get_incdirs  r   zIncludeDirs.get_incdirsc                 C  r   r   )r)  r   rR   rR   rS   get_extra_build_dirs  r   z IncludeDirs.get_extra_build_dirs	sourcedirbuilddirc                 C  sD   g }| j D ]}|tj|| j| |tj|| j| q|S )a*  Convert IncludeDirs object to a list of strings.

        :param sourcedir: The absolute source directory
        :param builddir: The absolute build directory, option, build dir will not
            be added if this is unset
        :returns: A list of strings (without compiler argument)
        )r%  r   osr   r   r$  )r   r2  r3  strlistZidirrR   rR   rS   to_string_list  s
   
zIncludeDirs.to_string_listNr   r   r   r   )r2  r   r3  r   r   r   )rN   rO   rP   r"  rQ   r   r   r)  r.  r/  r0  r1  r6  rR   rR   rR   rS   r#  y  s   
 



r#  c                   @  s   e Zd ZU dZded< eedZded< eedZded< eedZ	d	ed
< dZ
ded< dZded< d%ddZd&ddZed'ddZd(d d!Zd%d"d#Zd$S ))rD   zI
    Holds a list of sources for which the objects must be extracted
    z'BuildTarget'targetr'  r   srclistT.List['GeneratedTypes']genlist0T.List[T.Union[str, 'File', 'ExtractedObjects']]objlistTrG   	recursiveFpchr   r   c                 C  s   | j jr
|   d S d S r   )r9  is_unitycheck_unity_compatibler   rR   rR   rS   __post_init__  s   zExtractedObjects.__post_init__r   c                 C  s   d}| | jj| jj| jS )Nz<{0} {1!r}: {2}>)r*  r+  rN   r9  r   r:  r,  rR   rR   rS   r.       zExtractedObjects.__repr__rk   T.Sequence['FileOrString']generated_sourcesT.Sequence['GeneratedTypes']T.List['FileOrString']c                 C  s8   t | } |D ]}| D ]}| | qqdd | D S )Nc                 S  s   g | ]}t |r|qS rR   )r%   )rX   srR   rR   rS   r     r   z0ExtractedObjects.get_sources.<locals>.<listcomp>)r   get_outputsr   )rk   rF  gensrcrI  rR   rR   rS   r     s   zExtractedObjects.get_sourcesT.List[FileOrString]*T.Dict['Compiler', T.List['FileOrString']]c                 C  s   |  ||}t| jj |S r   )r   r   r9  	compilersvalues)r   rk   rF  Zsources_rR   rR   rS   classify_all_sources  s   z%ExtractedObjects.classify_all_sourcesc                 C  sV   |  | jj| jj}|  | j| j}| D ]\}}t|t|| kr(tdqd S )Nz}Single object files cannot be extracted in Unity builds. You can only extract all the object files for each compiler at once.)	rP  r9  rk   	generatedr:  r<  r   r   r   )r   ZcmpsrcsZextracted_cmpsrcscompZsrcsrR   rR   rS   rB    s   z'ExtractedObjects.check_unity_compatibleNr   r   r7  )rk   rE  rF  rG  r   rH  )rk   rL  rF  rG  r   rM  )rN   rO   rP   r"  rQ   r   r   r:  r<  r>  r?  r@  rC  r.  staticmethodr   rP  rB  rR   rR   rR   rS   rD     s   
 


)r   orderc                   @  sZ   e Zd ZU dZedd dZded< dd	d
ZdddZdddZ	dddZ
dddZdS )StructuredSourcesa  A container for sources in languages that use filesystem hierarchy.

    Languages like Rust and Cython rely on the layout of files in the filesystem
    as part of the compiler implementation. This structure allows us to
    represent the required filesystem layout.
    c                   C  s   t tS r   )r   r   rR   rR   rR   rS   <lambda>  s    zStructuredSources.<lambda>r'  zYT.DefaultDict[str, T.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]]rk   r   r   c                 C  s4   | j  }|j  D ]\}}|| | q
t|S r   )rk   r   r   extendrV  )r   r   rk   r   r   rR   rR   rS   __add__  s   
zStructuredSources.__add__rG   c                 C  
   t | jS r   )rG   rk   r   rR   rR   rS   __bool__  r   zStructuredSources.__bool__=T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]c                 C  s   | j d d S )zXGet the first source in the root

        :return: The first source in the root
        r   r   r   r   rR   rR   rS   
first_file  s   zStructuredSources.first_fileET.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]c                 C  s   t tj| j S r   )r   	itertoolschainfrom_iterablerk   rO  r   rR   rR   rS   as_list  s   zStructuredSources.as_listc                 C  s>   | j  D ]}|D ]}t|tr|jr  dS q	  dS qdS )a	  Do we need to create a structure in the build directory.

        This allows us to avoid making copies if the structures exists in the
        source dir. Which could happen in situations where a generated source
        only exists in some configurations
        TF)rk   rO  r   r   is_built)r   filesfrR   rR   rS   
needs_copy  s   
zStructuredSources.needs_copyN)r   rV  r   rV  r   rG   )r   r\  )r   r^  )rN   rO   rP   r"  r   rk   rQ   rY  r[  r]  rb  rf  rR   rR   rR   rS   rV    s   
 



rV  c                   @  s|  e Zd ZU ded< ded< ded< ded< ded	< d
ed< dZded< dZded< eedZded< dZ	ded< e
jdYddZe
jdYddZdZddZd[d!d"Zd[d#d$Zd[d%d&Zd[d'd(Zd\d*d+Zd]d-d.Zd^d0d1ZdYd2d3ZdYd4d5ZdYd6d7Zed_d9d:Zed`d<d=ZdYd>d?ZdadBdCZdbdFdGZdcdIdJZ dddNdOZ!ededPdQZ"dfdRdSZ#dgdUdVZ$dfdWdXZ%dS )hTargetr   r   r   z'SubProject'r   rG   rn   r   r   r   r/   Frf   build_always_staler'  r   rh   Nz+InitVar[T.Optional[T.Dict[OptionKey, str]]]rp   r   c                 C     d S r   rR   r   rR   rR   rS   typename     zTarget.typenamec                 C  rj  r   rR   r   rR   rR   rS   type_suffix  rl  zTarget.type_suffix	overrides"T.Optional[T.Dict[OptionKey, str]]r   c                   sd   |r fdd|  D }ni }t jjj j| _t jr0t	t
d j d d S d S )Nc                   s*   i | ]\}}|j r|j jd n||qS )machine)rY   evolver   rX   r   r   r   rR   rS   
<dictcomp>   s    z(Target.__post_init__.<locals>.<dictcomp>z                Target "z" has a path separator in its name.
                This is not supported, it can cause unexpected failures and will become
                a hard error in the future.)r   r
   ZOptionsViewr/   optionsr   r   r   r   warningtextwrapdedent)r   rn  ZovrrR   r   rS   rC    s   


zTarget.__post_init__r   objectc                 C  s   t |tstS |  | k S r   r   rh  NotImplementedget_idr   r   rR   rR   rS   __lt__.     
zTarget.__lt__c                 C  s   t |tstS |  | kS r   rz  r}  rR   rR   rS   __le__3  r  zTarget.__le__c                 C  s   t |tstS |  | kS r   rz  r}  rR   rR   rS   __gt__8  r  zTarget.__gt__c                 C  s   t |tstS |  | kS r   rz  r}  rR   rR   rS   __ge__=  r  zTarget.__ge__T.Tuple[str, str]c                 C     t r   NotImplementedErrorr   rR   rR   rS   get_default_install_dirB     zTarget.get_default_install_dir$T.List[T.Union[str, Literal[False]]]c                 C  r  r   r  r   rR   rR   rS   r   E  r  zTarget.get_custom_install_dirBT.Tuple[T.List[T.Union[str, Literal[False]]], str, Literal[False]]c                 C  st   |   \}}|  }|r"|d |kr"|d dur"d}dd |D }nd}|r+||d< n|g}|gt| }|||fS )Nr   Tc                 S  s   g | ]}t |d dqS )ZoptnameN)getattr)rX   irR   rR   rS   r   Q  r   z*Target.get_install_dir.<locals>.<listcomp>F)r  r   r   )r   Zdefault_install_dirZdefault_install_dir_nameoutdirsr   Zinstall_dir_namesrR   rR   rS   get_install_dirH  s   

zTarget.get_install_dirc                 C  r   r   r   r   rR   rR   rS   get_basename^  r   zTarget.get_basenamec                 C  r   r   r   r   rR   rR   rS   
get_subdira  r   zTarget.get_subdirc                 C  r   r   )rk  r   rR   rR   rS   get_typenamed  r   zTarget.get_typename	target_idc                 C  s,   t  }|| jddd | d d S )Nzutf-8replace)encodingerrors   )hashlibZsha256updateencode	hexdigest)r  hrR   rR   rS   _get_id_hashg  s   zTarget._get_id_hashrm  c                 C  sF   | dd dd}t|rJ || }| r!t| }|d | S |S )zuConstruct target ID from subdir, name and type suffix.

        This helper function is made public mostly for tests./@\z@@)r  r   rh  r  )r   r   rm  Z	name_partZmy_idZsubdir_partrR   rR   rS   construct_id_from_pathq  s   

zTarget.construct_id_from_pathc                 C  s4   | j }t| ddr|d| j 7 }| | j||  S )Nname_suffix_setFr   )r   r  suffixr  r   rm  r   r   rR   rR   rS   r|    s   zTarget.get_idkwargsT.Dict[str, T.Any]c                 C  sR   d|v r|d | _ t| j tstd| j s|ddrd| _ | | | d S )Nrn   z)build_by_default must be a boolean value.rf   FT)rn   r   rG   r   r  set_option_overridesparse_overridesr   r  rR   rR   rS   process_kwargs_base  s   
zTarget.process_kwargs_baseoption_overridesT.Dict[OptionKey, str]c                 C  sH   i | j _| D ]\}}|jr|| j j|j| jd< q|| j j|< qd S )Nrp  )ru  rn  r   rY   rr  r   )r   r  r   r   rR   rR   rS   r    s   zTarget.set_option_overridescoredata.OptionsViewc                 C  r   r   )ru  r   rR   rR   rS   get_options  r   zTarget.get_optionskey'OptionKey'#T.Union[str, int, bool, 'WrapMode']c                 C  s   t d| j| jS )Nz!T.Union[str, int, bool, WrapMode])Tcastru  value)r   r  rR   rR   rS   
get_option  s   zTarget.get_optionc                 C  sz   |  dg }t|trtd|S i }t|}|D ]!}d|vr#td|dd\}}t	|
 }|
 }|||< q|S )Nrp   r  =z%Overrides must be of form "key=value"r	   )r  r   r   r  r  r   r   splitr   from_stringstrip)r  optsresultrn  or   r   r  rR   rR   rS   r    s   

zTarget.parse_overridesc                 C     dS NFrR   r   rR   rR   rS   is_linkable_target  r  zTarget.is_linkable_targetr   c                 C     g S r   rR   r   rR   rR   rS   rJ    r  zTarget.get_outputsc                 C  r  r  rR   r   rR   rR   rS   should_install  r  zTarget.should_installr7  )rn  ro  r   r   )r   ry  r   rG   r   r  r   r  )r   r  )r  r   r   r   )r   r   r   r   rm  r   r   r   r  r  r   r   )r  r  r   r   )r   r  )r  r  r   r  )r  r  r   r  rg  r8  )&rN   rO   rP   rQ   rf   ri  r   r   rh   rp   abcabstractpropertyrk  abstractmethodrm  rC  r~  r  r  r  r  r   r  r  r  r  rT  r  r  r|  r  r  r  r  r  r  rJ  r  rR   rR   rR   rS   rh    sP   
 










	






rh  )	metaclassc                      s  e Zd ZU eZded< edgZded< dć fddZdddZ	dd  Z
d!d" Zedd$d%Zd&d' Zd(d) Zd*d+ Zd,d- Zdd.d/Zedd3d4Zd5d6 Zdd8d9Zd:d; Zd<d= ZddAdBZdddEdFZddHdIZedJdKddLdMZddPdQZedJdKddRdSZedJdKddUdVZ ddXdYZ!ddZd[Z"dd]d^Z#d_d` Z$ddcddZ%ddedfZ&ddhdiZ'ddjdkZ(ddmdnZ)edJdKddpdqZ*dddtduZ+dvdw Z,dxdy Z-dd{d|Z.dd~dZ/dddZ0dddZ1dddZ2dddZ3dd Z4dddZ5dddZ6dddZ7ddddZ8edJdKdddZ9dddZ:ddddZ;dddZ<dddZ=ddddZ>dddZ?dddZ@dd ZAdddZBdddZCdddZDdddZEdddZFdddZGdd ZHdddÄZI  ZJS )rC   r  ru   )cppZcudazT.FrozenSet[T.Tuple[str, str]]_MASK_LANGSr   r   r   r   r6   r   r   rk   T.List['SourceOutputs']structured_sourcesT.Optional[StructuredSources]rr   T.List[ObjectTypes]r/   r   rN  T.Dict[str, 'Compiler']r  r  c                   s  t  j|||d|||
ddd |	| _t | _g | _|| _g | _g | _	|
d| _
g | _g | _g | _g | _t | _d| _d| _d| _d | _| jg| _i | _|
dtt| _g | _g | _g | _|
dg |
d	g |
d
g |
ddd| _d| _d| _t | _ | !| | "| | #|
 | $ | _%t&|
d| j }t&|
d| j }| j'  | j'  | (| | )| t*| j| j| j| j| j|
+ddgst,-d| d | .|
 | /  | 0  d S )NTrf   Frf   rl   Zno_namelanguage_argsr^   r[   r\   r]   )rI   rK   rL   rH   ro   rx   Z_allow_no_sourceszBuild target z has no sources. This was never supposed to be allowed but did because of a bug, support will be removed in a future release of Meson)1superr   r  all_compilersr   rN  rr   r  external_depsinclude_dirsrl   link_targetslink_whole_targetsdepend_filesr{   r   
added_depsname_prefix_setr  filenamedebug_filenameoutputsr@  r   r   
extra_argsrk   rQ  rh   
d_featuresr   r~   Zrpath_dirs_to_removeprocess_sourcelistprocess_objectlistprocess_kwargsprocess_compilersmissing_languagesr   clearlinkrx   anypopr   rv  check_unknown_kwargsvalidate_installcheck_module_linking)r   r   r   r   r   rk   r  rr   r/   rN  r  r  r  r+  rR   rS   r     s`   "














zBuildTarget.__init__r   r   c                 C  s   |    | jrt| j| jgrtd| jrd| jvrtd|  r&d| _d| jv rU| 	 rW|  j
| j| jg7  _
|  jddg7  _| jrY| j
| j | jd dS dS dS dS )zV Initialisations and checks requiring the final list of compilers to be known
        z6cannot mix structured sources and unstructured sourcesrustz5structured sources are only supported in Rust targetsTvaladevelN)validate_sourcesr  r  rk   rQ  r   rN  	uses_rustr   r  r  ra   r_   rm   r`   r   r   rR   rR   rS   	post_init"  s   zBuildTarget.post_initc                 C     d}| | jj|  | jS N<{0} {1}: {2}>)r*  r+  rN   r|  r  r   repr_strrR   rR   rS   r.  5  rD  zBuildTarget.__repr__c                 C  s   | j  S r   r  r   rR   rR   rS   __str__9     zBuildTarget.__str__rG   c                 C  s(   |  td}|dkp|dko| jdkS )Nunityonr   r   )r  r   r   )r   Z	unity_optrR   rR   rS   rA  <  s   zBuildTarget.is_unityc                 C  s:   | j tju r| jr| j rtdtd d S d S d S )NzATried to install a target for the build machine in a cross build.zOInstalling target build for the build machine. This will fail in a cross build.)	r   r   BUILDrf   r/   r   r   r   rv  r   rR   rR   rS   r  A  s
   
zBuildTarget.validate_installc                 C  s   |  || j d S r   )check_unknown_kwargs_intknown_kwargsr  rR   rR   rS   r  H  s   z BuildTarget.check_unknown_kwargsc                 C  sX   g }|D ]}|dkrq||vr| | qt|dkr*td| jd| d S d S )Nr  r   z-Unknown keyword argument(s) in target {}: {}., )r   r   r   rv  r*  r   r   )r   r  r  Zunknownsr   rR   rR   rS   r  M  s   
z$BuildTarget.check_unknown_kwargs_intc                 C  s   t |tsJ g }|D ]Q}t |tttfr*| j| t |ts)t|s)|| qt |tt	t
frNdd | D }|rGtd|d  d| j| qtdt|jd| jd|rotd	|d  dd
| j d S d S )Nc                 S  s   g | ]}t |s|qS rR   )r$   )rX   r  rR   rR   rS   r   `  r   z2BuildTarget.process_objectlist.<locals>.<listcomp>zGenerated file r   z) in the 'objects' kwarg is not an object.zBad object of type  in target r   zSource file z1.3.0)r   r   r   r   rD   rr   r   r$   r>   r?   r@   rJ  r   rQ  typerN   r   r,   
single_user   )r   rr   Zdeprecated_non_objectsrI  Znon_objectsrR   rR   rS   r  W  s&   
zBuildTarget.process_objectlistc                 C  sZ   t  }|D ]%}t|tr||vr| j| || qt|tttfr*| j	| qdS )a  Split sources into generated and static sources.

        Sources can be:
        1. Preexisting source files in the source tree (static)
        2. Preexisting sources generated by configure_file in the build tree.
           (static as they are only regenerated if meson itself is regenerated)
        3. Sources files generated by another target or a Generator (generated)
        N)
r   r   r   rk   r   addr>   r?   r@   rQ  )r   rk   Zadded_sourcesrI  rR   rR   rS   r  j  s   	

zBuildTarget.process_sourcelistr   r  rH  c                 C  s2   d}|d d  D ]}|  |r|| d}q|S )NFT)can_compileremove)r   rk   ZremovedrI  rR   rR   rS   can_compile_remove_sources|  s   

z&BuildTarget.can_compile_remove_sourcesc                 C  s   | j D ]
}| j| | j|< q| jr| jgnt}| js| jrHt| j| jD ]"}t	|t
tfr/q%|j D ]\}}||v rF|| jvrF|| j|< q4q%| js_|D ]}|| jv r^| j| | j|<  nqMtt| j dd d| _|   dS )a$  Processes additional compilers after kwargs have been evaluated.

        This can add extra compilers that might be required by keyword
        arguments, such as link_with or dependencies. It will also try to guess
        which compiler to use if one hasn't been selected already.
        c                 S  s   t | d S Nr   )r'   )r   rR   rR   rS   rW    s    z4BuildTarget.process_compilers_late.<locals>.<lambda>)r  N)r  r  rN  rl   r&   r  r  r_  r`  r   r>   r?   r   r   sortedr  )r   rY   Z
link_langsr   r   r   rR   rR   rS   process_compilers_late  s,   



z"BuildTarget.process_compilers_later   c                 C  s*  g }t | j| j| j| jgs|S t| j}| j }| jr=| jj D ]}|D ]}t|t	t
fr6|| q'|| q'q#|D ]}| D ]}t|sP|| qEq?| jD ]}|jD ]}t|t	t
frh|| qZqU| jD ]&}	t|	tsuqm|	|	jg }
|
D ]}|jdkrq~|j| jvr|| j|j< q~qm|r|D ]9}| j D ]\}}||r|| jvr|| j|<  nqt|rtt	| }d| j  d|}t|qd| jv rd| jvr| jd | jd< d| jv rtd| jdd}| |}z| j| | j|< W |S  t y   || Y |S w |S )aq  
        Populate self.compilers, which is the list of compilers that this
        target will use for compiling all its sources.
        We also add compilers that were used by extracted objects to simplify
        dynamic linker determination.
        Returns a list of missing languages that we can add implicitly, such as
        C/C++ compiler for cython.
        r  zNo z machine compiler for cZcythonlanguage)rq  rY   )!r  rk   rQ  rr   r  r   r   rO  r   r   r   r   rJ  r$   r  rD   rP  r:  r  rN  r  r   r  r)   pathlibPathas_posixr   get_lower_case_namer   r   r  KeyError)r   r  rk   rQ  r   srcrK  rI  r  r  ZcompsrcsrR  rY   r   r   mr  r  rR   rR   rS   r    sz   	








	



zBuildTarget.process_compilersc                   sJ   t  jdkr!t fdddD r#d j }td| d S d S )Nr	   c                 3      | ]}| j v V  qd S r   rN  rW   r   rR   rS   	<genexpr>      z/BuildTarget.validate_sources.<locals>.<genexpr>)csjavar   z*Cannot mix those languages into a target: )r   rN  r  r   keysr   )r   langsrR   r   rS   r    s   $zBuildTarget.validate_sourcesc                 C  st   t |}|D ]1}t|tr| j| qt|tr(| jt| jj| j	| qt
|dr4| j| qtddS )a}  Process the link_depends keyword argument.

        This is designed to handle strings, Files, and the output of Custom
        Targets. Notably it doesn't handle generator() returned objects, since
        adding them as a link depends would inherently cause them to be
        generated twice, since the output needs to be passed to the ld_args and
        link_depends.
        rJ  zTLink_depends arguments must be strings, Files, or a Custom Target, or lists thereof.N)r   r   r   r{   r   r   from_source_filer/   
source_dirr   hasattrr   )r   rk   rI  rR   rR   rS   process_link_depends  s   	


z BuildTarget.process_link_dependsr:  1T.List[T.Union['FileOrString', 'GeneratedTypes']]rD   c                 C  s  t | j}t | j}g }g }|D ]l}t|ttfr@t|tr&td| j|}ntdd| j	 ||vr:t
d| d|| qt|tttfrrtdd| j	 t|trX|jn|}||vrl||vrlt
d|  d|| qt
dt|j d	t| ||S )
NFz!File argument for extract_objects0.50.0z Tried to extract unknown source r   z%Generated sources for extract_objectsz0.61.0zCObject extraction arguments must be strings, Files or targets (got z).)r   rk   rQ  r   r   r   r   r+   r  r   r   r   r>   r?   r@   r9  r  r  rN   rD   )r   r:  Zsources_setZgenerated_setZobj_srcZobj_genr  r9  rR   rR   rS   extract_objects  s(   


zBuildTarget.extract_objectsTr?  c                 C  s   t | | j| j| j|ddS )NT)r@  )rD   rk   rQ  rr   )r   r?  rR   rR   rS   extract_all_objects7  s   zBuildTarget.extract_all_objects'ImmutableListProtocol[BuildTargetTypes]c                 C     |   S r   get_transitive_link_depsr   rR   rR   rS   get_all_link_deps;  r  zBuildTarget.get_all_link_depsNr   c                 C  s    g }| j D ]}|| 7 }q|S r   )r  r(  r   r  r  rR   rR   rS   r'  >  s   
z$BuildTarget.get_transitive_link_depsr   T.Mapping[str, str]c                 C  s
   |  |S r   ) get_transitive_link_deps_mappingr   r   rR   rR   rS   get_link_deps_mappingE  r   z!BuildTarget.get_link_deps_mappingc                 C  s4   i }| j D ]}||}| }|| |}q|S r   )r  r-  r   r  )r   r   r  r  mappingZ
result_tmprR   rR   rS   r+  H  s   


z,BuildTarget.get_transitive_link_deps_mappingT.AbstractSet[str]c                 C  s<   t  }| jD ]}t|ts||  ||  q|S r   )r   r  r   rB   r  r  r  get_link_dep_subdirsr)  rR   rR   rS   r0  S  s   

z BuildTarget.get_link_dep_subdirsr  c                 C     | j  dfS )Nz{libdir})r/   Z
get_libdirr   rR   rR   rS   r  \     z#BuildTarget.get_default_install_dirc                 C  r   r   ru   r   rR   rR   rS   r   _  r   z"BuildTarget.get_custom_install_dirT.Optional['FileMode']c                 C  r   r   ry   r   rR   rR   rS   r   b  r   z#BuildTarget.get_custom_install_modec                 C  s  |  | || _| dt|d | dt|d t| tr%|ddr@|d| jd | _|d	| jd
 | _	|dd | _
t|d| _| jD ]}t|tsTtdqI| jD ]}d|v sc|drkttd qX| |dg  t|d}| | t|d}| | t|dg ttf| _|dd | _t|dd g| _t| ts|dd urtd|dd urtdt|d}|D ]0}t|tsJ || jv rqtj | j!" |j#|j$}tj%|std| d| j&| q|dd| _'t| j'tstd |d!d| _(t| j(tstd"t|d#}|D ](}	t|	ts0td$tj | j!" | j#|	}tj%|sKtd%|	 dq$|| _)|d&d urz|d& }
t|
t*rj|
ritd'nt|
tsttd(|
| _+d)| _,|d*d ur|d* }t|t*r|rtd+nt|tstd,|dkrtd-|| _-d)| _.t| t/r| j!j0| j1 }|2 s|3 rd)| _4n| 5|d.d/| _4t| tst| t/r| j4s| j!j0| j1 6 rd)| _7n| 5|d0d1| _7|d2d)| _8t| j8tstd3|d4d| _9t| j9tstd5| j9dkr6g d6}| j9|vr6td7:| j9d8 ||d9i }t|t;sJtd:| d;t<d<d= |= D r^td:| d>|| _>d S )?Nr  rT   r  rU   r|   Fra   z.hr_   z.vapir`   rs   z$Link_args arguments must be strings.z
-Wl,-rpathz-rpathz                    Please do not define rpath with a linker argument, use install_rpath
                    or build_rpath properties instead.
                    This will become a hard error in a future Meson release.
                r{   rw   r   ru   ry   rm   re   z1Argument gui_app can only be used on executables.rv   z7Argument win_subsystem can only be used on executables.rh   z%Tried to add non-existing extra file r   rz   r   zInstall_rpath is not a string.ri   zBuild_rpath is not a string.rd   z"Resource argument is not a string.z#Tried to add non-existing resource rg   z3name_prefix array must be empty to signify default.zname_prefix must be a string.Trj   z3name_suffix array must be empty to signify default.zname_suffix must be a string.zname_suffix should not be an empty string. If you want meson to use the default behaviour for each platform pass `[]` (empty array)r   Zb_staticpicr~   b_pierq   z/Implicit_include_directories must be a boolean.rt   z'GNU symbol visibility must be a string.)r   ZinternalZhiddenZ	protectedZinlineshiddenz+GNU symbol visibility arg {} not one of: {}r   rc   zInvalid rust_dependency_map "z": must be a dictionary.c                 s  s    | ]	}t |t V  qd S r   )r   r   )rX   r   rR   rR   rS   r    s    z-BuildTarget.process_kwargs.<locals>.<genexpr>z+": must be a dictionary with string values.)?r  Zoriginal_kwargsadd_pchr   r   
Executabler  r   ra   r_   r`   rs   r   r   
startswithr   rv  rw  rx  r  add_include_dirsadd_depsr   rG   ru   ry   r   rm   r   rh   r4  r   r   r/   get_source_dirr   fnameisfiler   rz   ri   rd   r   r   r  r  r  rB   machinesr   	is_darwin
is_windowsr   _extract_pic_pie
is_androidr~   rq   rt   r*  r   r  rO  rc   )r   r  r  r   ZinclistZdeplistrh   trialrd   r-  rg   rj   r  Z	permittedrc   rR   rR   rS   r  e  s   












 
zBuildTarget.process_kwargsargoptionc                 C  s   | j d | j d  }d|  |v sd|  |v r+td| d| d| j dS t|}||d ur?t	d|| }n|| j
jjv rO| j
jj| j}nd	}t|tsbtd
| d| jd|S )Nr  r  z-fz	Use the 'z' kwarg instead of passing '-fz' manually to TrG   F	Argument z to z must be boolean)r  lowerupperr   rv  r   r   r  r  r  r/   r
   ru  r  r   rG   r   )r   r  rE  rF  Z	all_flagsr   valrR   rR   rS   rB    s    
zBuildTarget._extract_pic_piec                 C  r   r   )r  r   rR   rR   rS   get_filename  r   zBuildTarget.get_filenamer   c                 C  r   z
        The name of debuginfo file that will be created by the compiler

        Returns None if the build won't create any debuginfo file
        r  r   rR   rR   rS   get_debug_filename     zBuildTarget.get_debug_filenamec                 C  r   r   r  r   rR   rR   rS   rJ    r   zBuildTarget.get_outputsr  c                 C  
   | j | S r   r  r   r  rR   rR   rS   get_extra_args  r   zBuildTarget.get_extra_argsOrderedSet[BuildTargetTypes]c                 C  sF   t  }t| j| jD ]}||vr || t|tr || q|S r   )	r   r_  r`  r  r  r  r   rB   get_dependencies_recurser   r  r   rR   rR   rS   get_dependencies  s   


zBuildTarget.get_dependenciesr  include_internalsc                 C  sv   |o|   }| jD ]#}||v rq	|jdkrq	|s|  s!|| t|tr,||| q	| jD ]}||| q0d S )N
proc-macro)is_internalr  rb   r  r   rB   rV  r  )r   r  rY  r   rR   rR   rS   rV    s   




z$BuildTarget.get_dependencies_recursec                 C  r   r   r  r   rR   rR   rS   get_source_subdir%  r   zBuildTarget.get_source_subdirc                 C  r   r   r   r   rR   rR   rS   r   (  r   zBuildTarget.get_sourcesr=  c                 C  r   r   )rr   r   rR   rR   rS   get_objects+  r   zBuildTarget.get_objectsr;  c                 C  r   r   )rQ  r   rR   rR   rS   get_generated_sources.  r   z!BuildTarget.get_generated_sourcesc                 C  r   r   r  r   rR   rR   rS   r  1  r   zBuildTarget.should_installc                 C  rZ  r   )rG   r@  r   rR   rR   rS   has_pch4  r   zBuildTarget.has_pchc                 C  s   | j |g S r   )r@  r  rS  rR   rR   rS   get_pch7  r2  zBuildTarget.get_pchT.List['IncludeDirs']c                 C  r   r   )r  r   rR   rR   rS   get_include_dirs:  r   zBuildTarget.get_include_dirsc                   s  t |}|D ]}| jv rqt|tjrp |j  j fdd|jD   	|j
|   j|j  j|j  j|j | sN| ritdg | | g g g g g i g g g } j|  |j nRt|tjr| jvr j|  |   |j n3t|trtd|j d j dt|dr|j}t|dst|d	rtd
tdt|jd|j }dD ]}||v r׈ j | ||  qǈ j!| qd S )Nc                 3  s    | ]
}| j vr|V  qd S r   )rh   rX   re  r   rR   rS   r  F  s    z'BuildTarget.add_deps.<locals>.<genexpr>	undefinedzTried to use a build target z as a dependency of target z2.
You probably should put it in link_with instead.held_objectZproject_args_frozenZglobal_args_frozenzTried to use subproject object as a dependency.
You probably wanted to use a dependency declared in it instead.
Access it by calling get_variable() on the subproject object.z$Argument is of an unacceptable type z.
Must be either an external dependency (returned by find_library() or dependency()) or an internal dependency (returned by declare_dependency()).)rL   rK   )"r   r  r   r   InternalDependencyr  rk   rh   rX  r:  rw   Zget_include_typerr   r  Z	librariesr  Zwhole_librariesZget_compile_argsZget_link_argsr  r   r;  Zext_depsZ
Dependencyr   rC   r   r   r  re  r  rN   r  r  )r   depsr   ZextpartZdep_d_featuresZfeaturerR   r   rS   r;  =  sN   



zBuildTarget.add_depsT.List[dependencies.Dependency]c                 C  r   r   )r  r   rR   rR   rS   get_external_depsu  r   zBuildTarget.get_external_depsc                 C  r  r  rR   r   rR   rR   rS   r[  x  r  zBuildTarget.is_internalr   T.List[BuildTargetTypes]c                 C  s   |D ]i}t |ttfst |tjrttdt|d|	 s+td|dt | t
r@| jr@| r@| j|gdd qt | tr`t |t
r`|js`d|jd| jd	}|d
7 }t|| | | j| qd S )Na                          An external library was used in link_with keyword argument, which
                        is reserved for libraries built as part of this project. External
                        libraries must be passed using the dependencies keyword argument
                        instead, because they are conceptually "external dependencies",
                        just like those detected with the dependency() function.
                    z is not a target.zLink target 'z' is not linkable.T)promoted"Can't link non-PIC static library  into shared library . 9Use the 'pic' option to static_library to build with PIC.)r   rh  r?   r   ZExternalLibraryr   rw  rx  r   r  rB   rf   r[  rx   rA   r   r   check_can_link_togetherr  r   )r   r   r   msgrR   rR   rS   r  {  s"   
zBuildTarget.linkFrk  c                 C  s   |D ]k}t |ttfr | std|d| rtdn't |ts,t|dt | trG|jsGd|j	d| j	d}|d7 }t|| 
| t | trg| || | jrg| D ]}| |d	 q^| j| qd S )
NzCustom target z is not linkable.z<Can only link_whole custom targets that are static archives.z is not a static library.rl  rm  rn  ro  T)r   r>   r?   r  r   links_dynamicallyrB   rA   r   r   rp  _bundle_static_libraryrf   get_internal_static_librariesr  r   )r   r   rk  r   rq  librR   rR   rS   rx     s*   


zBuildTarget.link_wholec                 C  s   t  }| | |S r   )r   %get_internal_static_libraries_recurser   r  rR   rR   rS   rt    s   
z)BuildTarget.get_internal_static_librariesc                 C  sR   | j D ]}| r||vr|| || q| jD ]}| r&|| qd S r   )r  r[  r  rv  r  rW  rR   rR   rS   rv    s   




z1BuildTarget.get_internal_static_libraries_recurser   T.Union[BuildTargetTypes]c                 C  s   |   r| j| d S t|ttfs|  r9d|jd| jd}|r5|d| jd|jd|jd7 }t|| j|	  d S )Nz*Cannot link_whole a custom or Rust target z into a static library zY. Instead, pass individual object files with the "objects:" keyword argument if possible.z1 Meson had to promote link to link_whole because z is installed but not z', and thus has to include objects from z to be usable.)
r  r  r   r   r>   r?   r   r   rr   r#  )r   r   rk  r  rR   rR   rS   rs    s   	
z"BuildTarget._bundle_static_libraryBuildTargetTypesc                 C  s   t |to| }|  s|rtd|jd| j| j|jurJ|r(|jdkrLd| j d|j d| j}| j	 rAt|d t
|d  d S d S d S )	NzTry to link Rust ABI library z with a non-Rust target rZ  z$Tried to mix libraries for machines z and r  z' This is not possible in a cross build.z This will fail in cross build.)r   rC   uses_rust_abir  r   r   r   rb   r/   r   r   rv  )r   r   Zlinks_with_rust_abirq  rR   rR   rS   rp    s   
z#BuildTarget.check_can_link_togetherpchlistc                 C  sR  |sd S t |dkrt|d std|d  dnbt |dkrst|d r2t|d s1tdn#t|d rKt|d sBtd|d |d g}n
td|d  dtj|d tj|d kritdtd	d
| j	d n
t |dkr}td|D ]"}t
|tstdtjtj| jj| j|std| dq|| j|< d S )Nr	   r   zPCH argument z is not a header.   z>PCH definition must contain one header and at most one source.z is of unknown type.z,PCH files must be stored in the same folder.zPCH source filesr!  z)Only a single header file should be used.z-PCH definition may have a maximum of 2 files.zPCH arguments must be strings.zFile z does not exist.)r   r#   r   r%   r4  r   dirnamer,   r  r   r   r   r   r>  r   r/   r  r   r@  )r   r  r{  re  rR   rR   rS   r7    s<    
zBuildTarget.add_pchr  T.Sequence['IncludeDirs']set_is_systemc                   sj   g }|D ]}t |tstd|| q|d u rd}|dkr,|dk  fdd|D }|  j|7  _d S )NzAInclude directory to be added is not an include directory object.Zpreservesystemc                   s&   g | ]}t | |  | qS rR   )r#  r/  r0  r1  rX   xr&  rR   rS   r     s   & z0BuildTarget.add_include_dirs.<locals>.<listcomp>)r   r#  r   r   r  )r   r  r  ZidsarR   r  rS   r:    s   
zBuildTarget.add_include_dirsT.List[T.Tuple[str, str, str]]c                 C  r  r   rR   r   rR   rR   rS   get_aliases
  r  zBuildTarget.get_aliasesc                 C  sz   g }| j D ]}|jdu rq|j|vr||j qt| j| jD ]}t|tt	fr+q!|j
D ]}||vr9|| q.q!|S )ar  
        Sometimes you want to link to a C++ library that exports C API, which
        means the linker must link in the C++ stdlib, and we must use a C++
        compiler for linking. The same is also applicable for objc/objc++, etc,
        so we can keep using clink_langs for the priority order.

        See: https://github.com/mesonbuild/meson/issues/1653
        N)r  r  r   r_  r`  r  r  r   r>   r?   rN  )r   r  r   link_targetr  rR   rR   rS   get_langs_used_by_deps  s    	




z"BuildTarget.get_langs_used_by_depsc              
   C  sx   | j r| j| j  }|S tD ]%}|| jv r2z
| j| }W |  S  ty1   td| jd| dw qtd| jd)Nz2Could not get a prelinker linker for build target z$. Requires a compiler for language "&", but that is not a project language.z"Could not determine prelinker for r   )rl   r  r&   rN  r  r   r   )r   rR  r   Z	prelinkerrR   rR   rS   get_prelinker)  s"   

	zBuildTarget.get_prelinker T.Tuple['Compiler', T.List[str]]c              
   C  s   | j r| j| j  }||| jfS | jjj| j }|  }tD ]1}|| jv s*||v rPz|| }W n t	yC   t
d| jd| dw | |j}||f  S qtD ]}z| j| }||| jfW   S  t	yn   Y qSw td| j)a  
        We use the order of languages in `clink_langs` to determine which
        linker to use in case the target has sources compiled with multiple
        compilers. All languages other than those in this list have their own
        linker.
        Note that Vala outputs C code, so Vala sources can use any linker
        that can link compiled C. We don't actually need to add an exception
        for Vala here because of that.
        z0Could not get a dynamic linker for build target z". Requires a linker for language "r  )rl   r  language_stdlib_only_link_flagsr/   r
   rN  r   r  r&   r  r   r   get_used_stdlib_argsr  AssertionError)r   rR  r  Z	dep_langsr   Zlinkerstdlib_argsrR   rR   rS   $get_clink_dynamic_linker_and_stdlibs9  s6   

z0BuildTarget.get_clink_dynamic_linker_and_stdlibsrl   c                 C  sb   | j jj| j }t| j|  }g }|D ]}||kr.||f| jvr.||| 	| j  q|S r   )
r/   r
   rN  r   r   unionr  r  rX  r  )r   rl   r  Z	all_langsr  ZdlrR   rR   rS   r  j  s   z BuildTarget.get_used_stdlib_argsc                 C  
   d| j v S )Nr  r  r   rR   rR   rS   r  v  r   zBuildTarget.uses_rustc                 C  s   |   o| jdv S )N>   rlibdylibrZ  )r  rb   r   rR   rR   rS   rz  y  s   zBuildTarget.uses_rust_abic                 C  r  )NZfortranr  r   rR   rR   rS   uses_fortran|  r   zBuildTarget.uses_fortranc                 C  s0   |   r
| jd }n|  \}}|o| dv S )a&  
        Check if the dynamic linker is MSVC. Used by Executable, StaticLibrary,
        and SharedLibrary for deciding when to use MSVC-specific file naming
        and debug filenames.

        If at least some code is built with MSVC and the final library is
        linked with MSVC, we can be sure that some debug info will be
        generated. We only check the dynamic linker here because the static
        linker is guaranteed to be of the same type.

        Interesting cases:
        1. The Vala compiler outputs C code to be compiled by whatever
           C compiler we're using, so all objects will still be created by the
           MSVC compiler.
        2. If the target contains only objects, process_compilers guesses and
           picks the first compiler that smells right.
        r  >   r  zlld-linkZoptlinkZxilink)r  r  r  Zget_linker_id)r   r   _rR   rR   rS   get_using_msvc  s   zBuildTarget.get_using_msvcc                 C  s   | j D ]K}t|trN|jsN| jj| j  r#td| j	 d|j	 d| jj| j 
 r5t| tr5d|_qtd| j	 d|j	 d|j	 d|j	 d	 d|_qdS )	zR
        Warn if shared modules are linked with target: (link_with) #2865
        ztarget z links against shared module z. This is not permitted on OSXTzk, which is incorrect.
             This will be an error in the future, so please use shared_library() for z7 instead.
             If shared_module() was used for z because it has references to undefined symbols,
             use shared_library() with `override_options: ['b_lundef=false']` instead.N)r  r   SharedModuleforce_sonamer/   r?  r   r@  r   r   rC  r   deprecation)r   r  rR   rR   rS   r    s    

z BuildTarget.check_module_linkingc                 C  s   | dd u r	d S |d }t|tr+tj|rt|| _n,t	| j
j| j|| _n t|tr4|| _nt|ttfrGt| | | _ntd| | d S )Nr   z`vs_module_defs must be either a string, a file object, a Custom Target, or a Custom Target Index)r  r   r   r4  r   isabsr   from_absolute_filer   r  r/   r  r   r>   r?   from_built_filer  rK  r   r  )r   r  r   rR   rR   rS   process_vs_module_defs_kw  s   

z%BuildTarget.process_vs_module_defs_kw)r   r   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  r  r  rS  rg  )rk   r  r   r   )r   r  rk   rH  r   rG   r8  )r:  r   r   rD   T)r?  rG   r   rD   )r   r$  r   r   r   r*  r   r/  r  r  r   r4  )r  r  rE  r   rF  r   r   rG   r7  r   )r  r   r   r   r   rU  r  rU  rY  rG   r   r   )r   r=  r   r;  )r   ra  )r   rh  )r   rj  r   r   )F)r   rj  rk  rG   r   r   r  rU  r   r   )r   rx  rk  rG   r   r   )r   ry  r   r   )r  r   r{  r   r   r   r   )r  r~  r  r   r   r   r   r  )r   r  )rl   r   r   r   r  )KrN   rO   rP   known_build_target_kwargsr  rQ   	frozensetr  r   r  r.  r  propertyrA  r  r  r  r  r  rT  r  r
  r  r  r  r"  r#  r(  r   r'  r-  r+  r0  r  r   r   r  rB  rK  rN  rJ  rT  rX  rV  r\  r   r]  r^  r  r_  r`  rb  r;  ri  r[  r  rx   rt  rv  rs  rp  r7  r:  r  r  r  r  r  r  rz  r  r  r  r  __classcell__rR   rR   r  rS   rC     s   
 
M


&W







{










8


	





1



rC   c                   @  s$   e Zd ZdZd
ddZdddZd	S )FileInTargetPrivateDirzRepresents a file with the path '/path/to/build/target_private_dir/fname'.
       target_private_dir is the return value of get_target_private_dir which is e.g. 'subdir/target.p'.
    r=  r   c                 C  r   r   r=  )r   r=  rR   rR   rS   r     r   zFileInTargetPrivateDir.__init__r   c                 C  r   r   r  r   rR   rR   rS   r    r   zFileInTargetPrivateDir.__str__N)r=  r   r7  )rN   rO   rP   r"  r   r  rR   rR   rR   rS   r    s    
r  c                   @  sF   e Zd ZdZdddZeddd	ZdddZdddZdddZ	dS )FileMaybeInTargetPrivateDirz1Union between 'File' and 'FileInTargetPrivateDir'inner%T.Union[File, FileInTargetPrivateDir]c                 C  r   r   )r  )r   r  rR   rR   rS   r     r   z$FileMaybeInTargetPrivateDir.__init__r   r   c                 C  s   | j jS r   )r  r=  r   rR   rR   rS   r=    s   z!FileMaybeInTargetPrivateDir.fnamebuild_to_srctarget_private_dirc                 C  s*   t | jtrtj|| jjS | j|S r   )r   r  r  r4  r   r   r=  rel_to_builddir)r   r  r  rR   rR   rS   r    s   z+FileMaybeInTargetPrivateDir.rel_to_builddirsrcdirr3  c                 C  s"   t | jtr
td| j||S )NzUnreachable code)r   r  r  RuntimeErrorabsolute_path)r   r  r3  rR   rR   rS   r    s   z)FileMaybeInTargetPrivateDir.absolute_pathc                 C  r   r   r  r   rR   rR   rS   r    r   z#FileMaybeInTargetPrivateDir.__str__N)r  r  r7  )r  r   r  r   r   r   )r  r   r3  r   r   r   )
rN   rO   rP   r"  r   r  r=  r  r  r  rR   rR   rR   rS   r    s    


r  c                   @  st   e Zd Zdddd dd/ddZd0ddZd1ddZd2ddZd2ddZd2ddZe	d3d!d"Z
			d4d5d-d.ZdS )6	GeneratorNF)depfilecapturedependsr   exe/T.Union['Executable', programs.ExternalProgram]	argumentsr   outputr  r   r  rG   r  8T.Optional[T.List[T.Union[BuildTarget, 'CustomTarget']]]r   r   c                C  s2   || _ || _|| _|pg | _|| _|| _|| _d S r   )r  r  r  r  arglistr  r   )r   r  r  r  r  r  r  r   rR   rR   rS   r     s   	

zGenerator.__init__r   c                 C  s   d}| | jj| jS )Nz
<{0}: {1}>)r*  r+  rN   r  r  rR   rR   rS   r.    s   zGenerator.__repr__c                 C  r   r   )r  r   rR   rR   rS   get_exe  r   zGenerator.get_exeinnamec                   s6   t j|t jd   fdd| jD }|S )Nr   c                       g | ]}| d   dqS 
@BASENAME@@PLAINNAME@r  r  basename	plainnamerR   rS   r          z/Generator.get_base_outnames.<locals>.<listcomp>)r4  r   r  splitextr  )r   r  basesrR   r  rS   get_base_outnames  s   zGenerator.get_base_outnamesc                 C  sD   | j d u r	tdtj|}tj|d }| j d|d|S )NzJTried to get dep name for rule that does not have dependency file defined.r   r  r  r  r   r4  r   r  r  r  )r   r  r  r  rR   rR   rS   get_dep_outname  s
   
zGenerator.get_dep_outnamec                   s2   t j|t jd   fdd| jD S )Nr   c                   r  r  r  r  r  rR   rS   r     r  z)Generator.get_arglist.<locals>.<listcomp>)r4  r   r  r  r  )r   r  rR   r  rS   get_arglist  s   zGenerator.get_arglistparentrD  c                 C  s   t || }|jd dkS )Nr   z..)r  PurePathrelative_toparts)r  rD  relpathrR   rR   rS   is_parent_path  s   zGenerator.is_parent_pathrd  TT.Iterable[T.Union[str, File, 'CustomTarget', 'CustomTargetIndex', 'GeneratedList']]state%T.Union['Interpreter', 'ModuleState']preserve_path_fromr  T.Optional[T.List[str]]env T.Optional[EnvironmentVariables]'GeneratedList'c                   sD  t |  j||d ur|ng |d ur|nt d}|D ]}t|tr&|j| t|tr2|j|j t|ttfrK|j|  fdd|	 D }n/t|t rf|rVt
d|j| dd |	 D }nt|trwt jj j|g}n|g}|D ]"}	|r|	 jj jj}
| ||
st
dt|	}	||	  q|q|S )N)r  r  c                   s   g | ]	}t  j|qS rR   )r   r  r   rc  r  rR   rS   r   ,      z+Generator.process_files.<locals>.<listcomp>zZgenerator.process: 'preserve_path_from' is not allowed if one input is a 'generated_list'.c                 S  s   g | ]}t |qS rR   )r  rc  rR   rR   rS   r   1  s    zmgenerator.process: When using preserve_path_from, all input files must be in a subdirectory of the given dir.)r@   r   r!   r   r>   r  r  r?   r9  rJ  r   r   r   r  r/   r  r  	build_dirr  r  add_file)r   rd  r  r  r  r  r  eZfsre  Zabs_frR   r  rS   process_files  s@   



zGenerator.process_files)r  r  r  r   r  r   r  r   r  rG   r  r  r   r   r7  )r   r  )r  r   r   r   )r  r   rD  r   r   rG   )NNN)rd  r  r  r  r  r   r  r  r  r  r   r  )rN   rO   rP   r   r.  r  r  r  r  rT  r  r  rR   rR   rR   rS   r    s"    




r  c                   @  s   e Zd ZU dZded< ded< ded< ded	< d
ed< d*ddZd+ddZd,ddZd-ddZd.ddZ	d/d d!Z
d0d#d$Zd.d%d&Zd1d'd(Zd)S )2r@   z The output of generator.process.r  	generatorr   r   r   r  r   r  r  r  r   r   c                 C  s   | j j| _t | _g | _g | _i | _g | _g | _	| j
d u r g | _
| jd u r)t | _t| j jtjrR| j j s;td| j j }tj|rT| j	t| d S d S d S )Nz4Tried to use not-found external program as generator)r  r  r   r   r  
infilelistoutfilelistoutmapextra_dependsr  r  r  r!   r   r   ExternalProgramfoundr   get_pathr4  r   r  r   r   r  )r   r   rR   rR   rS   rC  L  s&   


zGeneratedList.__post_init__infiler  outfilesr  r  c           	      C  sh   g }| |jj|jj}tj| jsJ tj|| j}tj	|}|D ]}|
tj|| q%|S r   )r  r/   r  r  r4  r   r  r  r  r}  r   r   )	r   r  r  r  r  Zin_absrelZpath_segmentZofrR   rR   rS   add_preserved_path_segmentd  s   z(GeneratedList.add_preserved_path_segmentnewfilec                 C  sJ   | j | | j|j}| jr| |||}|  j|7  _|| j|< d S r   )	r  r   r  r  r=  r  r  r  r  )r   r  r  r  rR   rR   rS   r  n  s   zGeneratedList.add_file#T.List[FileMaybeInTargetPrivateDir]c                 C  r   r   )r  r   rR   rR   rS   
get_inputsv  r   zGeneratedList.get_inputsc                 C  r   r   )r  r   rR   rR   rS   rJ  y  r   zGeneratedList.get_outputsr  c                 C  rQ  r   )r  )r   r  rR   rR   rS   get_outputs_for|  r   zGeneratedList.get_outputs_for'Generator'c                 C  r   r   )r  r   rR   rR   rS   get_generator  r   zGeneratedList.get_generatorc                 C  r   r   rR  r   rR   rR   rS   rT    r   zGeneratedList.get_extra_argsc                 C  r   r   r  r   rR   rR   rS   r    r   zGeneratedList.get_subdirNrS  )r  r  r  r   r  r  r   r   )r  r  r  r  r   r   )r   r  r8  )r  r  r   r   )r   r  r7  )rN   rO   rP   r"  rQ   rC  r  r  r  rJ  r  r  rT  r  rR   rR   rR   rS   r@   A  s    
 








r@   c                      s   e Zd ZeZdZd1 fddZd2 fddZ fddZd3ddZ	dd Z
d d! Zd4d#d$Zd4d%d&Zd'd( Zd5d*d+Zd6d,d-Zd7d/d0Z  ZS )8r8  
executabler   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  c                   s   t d}d|
vr||jjv r|jj| j|
d< t |||||||||	|

 |
dp,d| _|
dd| _t	| jt
s?td|
d| _t	| jt
ttd fsTtd	| j| _d| _d | _| |
 d S )
Nr6  r~   rv   consoler|   Fz3"export_dynamic" keyword argument must be a booleanr}   z="export_dynamic" keyword argument must be a boolean or string)r   r
   ru  r  r  r   r  rv   r|   r   rG   r   r}   r   r  is_linkwithableZwas_returned_by_find_programr   r  )r   r   r   r   r   rk   r  rr   r/   rN  r  r  r  rR   rS   r     s"   zExecutable.__init__r   r   c                   s  t    | jj| j }t| dsd| _t| ds| s&| s&d| j	v r*d| _
n|jds5|jdkr9d| _
nd	| j	v rH| j	d	  d
sWd| j	v r[| j	d  d
r[d| _
nzd	| j	v rj| j	d	  dsyd| j	v r}| j	d  dr}d| _
nXd	| j	v r| j	d	  drd| _
nEd	| j	v r| j	d	  dv sd| j	v r| j	d  dv rd| _
n%d	| j	v r| j	d	  dv sd| j	v r| j	d  dv rd| _
n| | _
| j| _| j
r|  jd| j
 7  _| j| jd< d | _d | _| jr"| jd }t| jtr| j}| s| r"|  r| d| _nd| d| _| o?d| j	v p5|  p5|  o?| jjtd}|r]| j}t| dddkrV|d| j
 7 }|d | _d S d S )Nr   r   r  r  r  ZwasmZ
emscriptenZjsr  Zarmclangr  ZaxfZccrxabsZxc16Zelf>   ZtiZc2000out>   ZmwcceppcZmwccarmZnefr   r   z.exe.libru  .arI   r  .pdb)r  r  r/   r?  r   r  r   rA  	is_cygwinrN  r  r  r9  r|  Zget_exe_suffixr   r  r  import_filenamer  r|   r   r}   r   r  r  r
   r  r   r  )r   rq  Zimplib_basenamecreate_debug_filer   r  rR   rS   r    sb   






zExecutable.post_initc                   s2   t  | |dpd| _| jdkrtdd S )Nrb   binz7Invalid rust_crate_type: must be "bin" for executables.)r  r  r  rb   r   r  r  rR   rS   r    s
   
zExecutable.process_kwargsr  c                 C  r1  )Nz{bindir})r/   Z
get_bindirr   rR   rR   rS   r    r2  z"Executable.get_default_install_dirc                 C  r   )z,Human friendly description of the executabler  r   rR   rR   rS   description  s   zExecutable.descriptionc                 C  r  )Nz@exerR   r   rR   rR   rS   rm    r  zExecutable.type_suffixr   c                 C  r   z
        The name of the import library that will be outputted by the compiler

        Returns None if there is no import library required for this platform
        r  r   rR   rR   rS   get_import_filename  rO  zExecutable.get_import_filenamec                 C  r   rL  rM  r   rR   rR   rS   rN  
  rO  zExecutable.get_debug_filenamec                 C  r   r   )r  r   rR   rR   rS   r    r   zExecutable.is_linkable_target'ImmutableListProtocol[str]'c                 C  r   )zProvides compatibility with ExternalProgram.

        Since you can override ExternalProgram instances with Executables.
        rP  r   rR   rR   rS   get_command  s   zExecutable.get_commandc                 C  s   t j| j| jS ),Provides compatibility with ExternalProgram.)r4  r   r   r   r  r   rR   rR   rS   r    s   zExecutable.get_pathrG   c                 C  r  )r
  TrR   r   rR   rR   rS   r     rl  zExecutable.foundr   r   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  rS  r  r   )r   r  r7  rg  )rN   rO   rP   known_exe_kwargsr  rk  r   r  r  r  r  rm  r  rN  r  r	  r  r  r  rR   rR   r  rS   r8    s    !B




r8  c                      sn   e Zd ZeZdZd) fddZd* fddZd+ddZd,ddZ	d d! Z
 fd"d#Zd$d% Zd-d'd(Z  ZS ).rB   zstatic libraryr   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  c                   s8   t d|
dd| _t |||||||||	|

 d S )NrG   r   F)r  r  r  r   r  r   r   r   r   r   r   rk   r  rr   r/   rN  r  r  rR   rS   r   *  s   zStaticLibrary.__init__r   r   c                   s  t    d jv rtd  rQ jdkr/t fdddD r/td j d j d	 jd
krQ jd }t	dg g |j
g g g g g i g g g } j| t dsYd _t dsw  rt jdkrkd _n jd
krsd _nd _ j j d  j  _ j jd< d S )Nr  z&Static libraries not supported for C#.r  c                 3  r  r   r  rX   r  r   rR   rS   r  @  r  z*StaticLibrary.post_init.<locals>.<genexpr>- r   Rust crate  type  does not allow spaces, periods or dashes in the library name due to a limitation of rustc. Replace them with underscores, for example	staticlibr  rd  r   ru  r  r  r   r   )r  r  rN  r   r  rb   r  r   r   rf  Znative_static_libsr  r   r  r   r  r  r  )r   Zrustcr  r  r   rS   r  :  s2   

 






zStaticLibrary.post_initr   r*  c                 C     i S r   rR   r,  rR   rR   rS   r-  d  r  z#StaticLibrary.get_link_deps_mappingr  c                 C  r1  )Nz{libdir_static})r/   Zget_static_lib_dirr   rR   rR   rS   r  g  r2  z%StaticLibrary.get_default_install_dirc                 C  r  )Nz@starR   r   rR   rR   rS   rm  j  r  zStaticLibrary.type_suffixc                   sz   t  | |d}|d}|r2|rtd|dkr!d| _d S |dv r*|| _d S td|d|d	kr8d
nd| _d S )Nr   rb   4rust_abi and rust_crate_type are mutually exclusive.ru  r  >   r  r  Crate type z< invalid for static libraries; must be "rlib" or "staticlib"r  r  )r  r  r  r   rb   r   r  r   rb   r  rR   rS   r  m  s   



zStaticLibrary.process_kwargsc                 C  r  NTrR   r   rR   rR   rS   r  ~  r  z StaticLibrary.is_linkable_targetrG   c                 C  s   | j  S r   r  r   rR   rR   rS   r[    r  zStaticLibrary.is_internalr  rS  r  r  rg  )rN   rO   rP   known_stlib_kwargsr  rk  r   r  r-  r  rm  r  r  r[  r  rR   rR   r  rS   rB   %  s    
*
rB   c                      s   e Zd ZeZdZdZd3 fddZd4 fddZd5ddZ	d6dd Z
d!d" Z fd#d$Zd7d&d'Zd7d(d)Zd*d+ Zd8d-d.Zd/d0 Zd1d2 Z  ZS )9rA   zshared libraryTr   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  c                   sL   d | _ d | _d | _d | _d | _d | _d| _t |||||||||	|

 d S r  )	r   	ltversionr   r   r  r  Zshared_library_onlyr  r   r  r  rR   rS   r     s   zSharedLibrary.__init__r   r   c                   s~   t      r& jdkr&t fdddD r&td j d j dt ds.d  _t d	s6d  _	d
 _
   d S )Ncdylibc                 3  r  r   r  r  r   rR   rS   r    r  z*SharedLibrary.post_init.<locals>.<genexpr>r  r  r  r  r   r  {0.prefix}{0.name}.{0.suffix})r  r  r  rb   r  r   r   r  r   r  basic_filename_tpldetermine_filenamesr   r  r   rS   r    s   
 

zSharedLibrary.post_initr   r*  c           	      C  sd   i }|  |}t| }||vr+|  }|  \}}}tj||d |}|||i || |S r  )r+  r   rK  r  r4  r   r   r  )	r   r   r  Zmappingsoldr=  r  r  newrR   rR   rS   r-    s   

z#SharedLibrary.get_link_deps_mappingr  c                 C  r1  )Nz{libdir_shared})r/   Zget_shared_lib_dirr   rR   rR   rS   r    r2  z%SharedLibrary.get_default_install_dirc                 C  s  d}d}d}| j | _d}d| jv rd}d}d| _d}n| jj| j  rYd}|  r8d}d}| jj	t
d	}n|  rJd}d
}| jj	t
d	}nd}d}| jrUd| _nhd| _nd| jj| j  rd}d}| jdurn| jnd}|d }| jr{d| _nBd| _n>| jj| j  rd}d}| jrd| _n*d| _n&| jj| j  rd}d}d| _nd}d}| jrd| _n
| jrd| _nd| _| jdu r|| _| jdu r|| _| j| | _|r|| | _| j| jd< |rtj| jd d | _dS dS )ax  
        See https://github.com/mesonbuild/meson/pull/417 for details.

        First we determine the filename template (self.filename_tpl), then we
        set the output filename (self.filename).

        The template is needed while creating aliases (self.get_aliases),
        which are needed while generating .so shared libraries for Linux.

        Besides this, there's also the import library name (self.import_filename),
        which is only used on Windows since on that platform the linker uses a
        separate library called the "import library" during linking instead of
        the shared library (DLL).
        r   FNr  Zdllr  Tz{0.prefix}{0.name}.dll.librI   z{0.prefix}{0.name}.libru  z{0.prefix}{0.name}.dll.az+{0.prefix}{0.name}-{0.soversion}.{0.suffix}Zcygz{0.name}.dll.ar  z+{0.prefix}{0.name}.{0.soversion}.{0.suffix}soz+{0.prefix}{0.name}.{0.suffix}.{0.ltversion}z+{0.prefix}{0.name}.{0.suffix}.{0.soversion}r   r  )r  filename_tplrN  r/   r?  r   rA  r  r
   r  r   r  r   r   r   r@  rC  r  r  r*  r  r  r  r4  r   r  r  )r   r   r  r  Zimport_filename_tplZimport_prefixrR   rR   rS   r     sz   


z!SharedLibrary.determine_filenamesc                   s  t  | | jj| j  sQtd|d| _	td|d| _
| j
d u r6| j	d ur6| j	dd | _
td|d| _| jd u rQ| j
d urQ| j
| j
f| _| | |d}|d	}|r|rhtd
|dkrqd| _d S |dv rz|| _d S td|d|dkrdnd| _d S )Nr   r   r   r   r   zT.Optional[T.Tuple[str, str]]r   r   rb   r  ru  r  >   r  r  rZ  r  zH invalid for shared libraries; must be "dylib", "cdylib" or "proc-macro"r  r  )r  r  r/   r?  r   rC  r  r  r  r  r   r  r   r  r   rb   r  r  rR   rS   r  2	  s*   




zSharedLibrary.process_kwargsr   c                 C  r   r  r  r   rR   rR   rS   r  U	  rO  z!SharedLibrary.get_import_filenamec                 C  r   rL  rM  r   rR   rR   rS   rN  ]	  rO  z SharedLibrary.get_debug_filenamec                 C  s   | g|    S r   r&  r   rR   rR   rS   r(  e	  r2  zSharedLibrary.get_all_link_depsr  c                 C  s   g }| j dvs
| js|S | j dkr7| jr7| j| jkr7| jdd}|| }| jd p,d}||| j|f n| j}| jd p@d}|| j	| ||f |S )a#  
        If the versioned library name is libfoo.so.0.100.0, aliases are:
        * libfoo.so.0 (soversion) -> libfoo.so.0.100.0
        * libfoo.so (unversioned; for linking) -> libfoo.so.0
        Same for dylib:
        * libfoo.dylib (unversioned; for linking) -> libfoo.0.dylib
        )r#  r  r#  r  r   r   Zruntimer  )
r  r   r  r$  r  r*  rm   r   r  r  )r   aliasesZ	alias_tplZltversion_filenametagrR   rR   rS   r  h	  s   
zSharedLibrary.get_aliasesc                 C  r  )Nz@sharR   r   rR   rR   rS   rm  	  r  zSharedLibrary.type_suffixc                 C  r  r  rR   r   rR   rR   rS   r  	  r  z SharedLibrary.is_linkable_targetr  rS  r  r  r   r  )rN   rO   rP   known_shlib_kwargsr  rk  aix_so_archiver   r  r-  r  r   r  r  rN  r(  r  rm  r  r  rR   rR   r  rS   rA     s     

m
#

 rA   c                      s4   e Zd ZeZdZdZd fddZdddZ  Z	S )r  zshared moduleFr   r   r   r   r6   r   r   rk   r  r  r  rr   r  r/   r   rN  r  c                   sH   d|
v rt dd|
v rt dt |||||||||	|

 d| _d S )Nr   z2Shared modules must not specify the version kwarg.r   z4Shared modules must not specify the soversion kwarg.F)r   r  r   r  r  r  rR   rS   r   	  s   

zSharedModule.__init__r   r  c                 C  r1  )Nz{moduledir_shared})r/   Zget_shared_module_dirr   rR   rR   rS   r  	  r2  z$SharedModule.get_default_install_dirr  r  )
rN   rO   rP   known_shmod_kwargsr  rk  r(  r   r  r  rR   rR   r  rS   r  	  s    r  c                   @  s*   e Zd ZdddZdd
dZdddZdS )BothLibrariessharedrA   staticrB   r   r   c                 C  s    d| _ || _|| _| jj| _d S )Nr+  )_preferred_libraryr+  r,  r   )r   r+  r,  rR   rR   rS   r   	  s   zBothLibraries.__init__r   c                 C  s   dt | j dt | j dS )Nz<BothLibraries: static=z	; shared=>)reprr,  r+  r   rR   rR   rS   r.  	  s   zBothLibraries.__repr__rC   c                 C  s2   | j dkr| jS | j dkr| jS td| j  d)Nr+  r,  zself._preferred_library == "z#" is neither "shared" nor "static".)r-  r+  r,  r    r   rR   rR   rS   get_default_object	  s
   

z BothLibraries.get_default_objectN)r+  rA   r,  rB   r   r   r7  )r   rC   )rN   rO   rP   r   r.  r0  rR   rR   rR   rS   r*  	  s    

r*  c                   @  s0   e Zd ZU ded< ded< ded< dddZdS )CommandBaser   r  ,T.List[T.Union[BuildTarget, 'CustomTarget']]r   r   r   cmdJT.Sequence[T.Union[str, File, programs.ExternalProgram, BuildTargetTypes]]r   7T.List[T.Union[str, File, BuildTarget, 'CustomTarget']]c              	   C  s8  t |}g }|D ]}t|tr|| qt|tr&| j| || qt|tjrN| s4t	d|
 }tj|rG| jt| || 7 }qt|ttfra| j| || qt|trtdd| j | j|j || t| | 7 }qt|tr|| |7 }qt	d|d|S )Nz4Tried to use not-found external program in "command"z&CustomTargetIndex for command argumentz0.60rG  z in "command" is invalid)r   r   r   r   r   r  r   r  r  r   r  r4  r   r  r  r	  rC   r>   r   r?   r+   r  r   r9  flatten_commandr  r  rK  r   )r   r3  Z	final_cmdr  r   rR   rR   rS   r6  	  s4   


 
zCommandBase.flatten_commandN)r3  r4  r   r5  )rN   rO   rP   rQ   r6  rR   rR   rR   rS   r1  	  s
   
 r1  c                   @  s4   e Zd ZdZdZddd
dZdddZdddZdS )CustomTargetBasez Base class for CustomTarget and CustomTargetIndex

    This base class can be used to provide a dummy implementation of some
    private methods to avoid repeating `isinstance(t, BuildTarget)` when dealing
    with custom targets.
    r   Tr  rU  rY  rG   r   r   c                 C  rj  r   rR   )r   r  rY  rR   rR   rS   rV  	  r  z)CustomTargetBase.get_dependencies_recursec                 C     t  S r   r   r   rR   rR   rS   rt  	  r   z.CustomTargetBase.get_internal_static_librariesc                 C  rj  r   rR   rw  rR   rR   rS   rv  	  r  z6CustomTargetBase.get_internal_static_libraries_recurseNr  r  r  r  )rN   rO   rP   r"  rb   rV  rt  rv  rR   rR   rR   rS   r7  	  s    
r7  c                      sN  e Zd ZdZddddddddddddddddddv fd,d-Zdwd0d1Zd2d3 Zdxd5d6Zdyd8d9Zd:d; Z	dzd<d=Z
d{d?d@Zd|dBdCZd}dDdEZd~dFdGZddIdJZddLdMZddNdOZdPdQ ZddSdTZdzdUdVZdzdWdXZdd[d\Zdd^d_Zd`da ZdzdbdcZddedfZdgdh ZddldmZdndo Zdpdq Zdrds ZddtduZ   Z!S )r>   customFNz#Generating {} with a custom command)ri  rn   r  r  r  r  r  r  feedrf   ru   ry   rm   absolute_pathsbackendr  r   r   r   r   r   r/   r   commandYT.Sequence[T.Union[str, BuildTargetTypes, GeneratedList, programs.ExternalProgram, File]]rk   kT.Sequence[T.Union[str, File, BuildTargetTypes, ExtractedObjects, GeneratedList, programs.ExternalProgram]]r  r   ri  rG   rn   r   r  r  r  $T.Optional[T.Sequence[FileOrString]]r  3T.Optional[T.Sequence[T.Union[str, SourceOutputs]]]r  r  r  r;  rf   ru   0T.Optional[T.List[T.Union[str, Literal[False]]]]ry   T.Optional[FileMode]rm   r   r<  r=  T.Optional['Backend']r  c             
     s   t  |||dtj||| t|| _t|tt||g | _	|	d ur%|	n|| _
|
| _|| _t|p2g | _g | _| || _|| _|pEt | _t|pKg | _|| _t|pUg | _|| _t|t| j	| _|rh|n| j	d | _|| _|| _d S )NFr   )r  r   r   HOSTr   rk   r   r   get_sources_string_namesr  rn   r  r  r  r   r6  r>  r  r!   r  r  r;  ru   ry   r   r   rm   r   r  r<  )r   r   r   r   r/   r>  rk   r  ri  rn   r  r  r  r  r  r  r;  rf   ru   ry   rm   r<  r=  r  r  rR   rS   r   	  s4   

zCustomTarget.__init__r   r  c                 C  r  )N)NNrR   r   rR   rR   rS   r  9
  r  z$CustomTarget.get_default_install_dirc                 C  r  r  r*  r+  rN   r|  r>  r  rR   rR   rS   r.  <
  rD  zCustomTarget.__repr__#T.List[T.Union[SourceOutputs, str]]c                 C  sZ   g }| | j | | j | jD ]}t|tr||j qt|tj	s*|| q|S r   )
rX  r   r  rk   r   r?   r   r9  r   r  )r   rg  r  rR   rR   rS   get_target_dependencies@
  s   


z$CustomTarget.get_target_dependencies+T.Set[T.Union[BuildTarget, 'CustomTarget']]c                 C  sJ   t  }|  }|D ]}t|tr|| q	t|tr"||  q	|S )a  
        Recursively fetch the build targets that this custom target depends on,
        whether through `command:`, `depends:`, or `sources:` The recursion is
        only performed on custom targets.
        This is useful for setting PATH on Windows for finding required DLLs.
        F.ex, if you have a python script that loads a C module that links to
        other DLLs in your project.
        )r   rJ  r   rC   r  r>   r   get_transitive_build_target_deps)r   Zbdepsrg  r  rR   rR   rS   rL  K
  s   	

z-CustomTarget.get_transitive_build_target_depsc                 C  r   r   r   r   rR   rR   rS   rX  ]
  r   zCustomTarget.get_dependenciesc                 C  r   r   r  r   rR   rR   rS   r  `
  r   zCustomTarget.should_installr  c                 C  r   r   r3  r   rR   rR   rS   r   c
  r   z#CustomTarget.get_custom_install_dirr4  c                 C  r   r   r5  r   rR   rR   rS   r   f
  r   z$CustomTarget.get_custom_install_modec                 C  r   r   rP  r   rR   rR   rS   rJ  i
  r   zCustomTarget.get_outputsc                 C  r   r  rP  r   rR   rR   rS   rK  l
  r   zCustomTarget.get_filenamecT.List[T.Union[str, File, BuildTarget, GeneratedTypes, ExtractedObjects, programs.ExternalProgram]]c                 C  r   r   r   r   rR   rR   rS   r   o
  r   zCustomTarget.get_sourcesT.List[GeneratedList]c                 C  s(   g }| j D ]}t|tr|| q|S r   )rk   r   r@   r   )r   Zgenlistsr  rR   rR   rS   get_generated_listsr
  s   


z CustomTarget.get_generated_listsc                 C  r%  r   )rO  r   rR   rR   rS   r^  y
  r  z"CustomTarget.get_generated_sourcesc                 C  sn   | j d u r	td|r&tj|d }tj|d }| j d|d|S d| j v s0d| j v r4td| j S )NzOTried to get depfile name for custom_target that does not have depfile defined.r   r  r  zKSubstitution in depfile for custom_target that does not have an input file.r  )r   Zinfilenamesr  r  rR   rR   rS   r  |
  s   
zCustomTarget.get_dep_outnamer  c                 C  s"   | drdS td|rdS dS )N)r  z.dllr  z.sor   Tz\.so(\.\d+)*$F)endswithresearch)r   r  rR   rR   rS   is_linkable_output
  s
   
zCustomTarget.is_linkable_outputc                 C  s"   t | jdkr	dS | | jd S )Nr	   Fr   )r   r  rS  r   rR   rR   rS   r  
  s   zCustomTarget.is_linkable_targetc                 C  s   t j| jd d }|dvS )Whether this target links dynamically or statically

        Does not assert the target is linkable, just that it is not shared

        :return: True if is dynamically linked, otherwise False
        r      r  r  )r4  r   r  r  r   sufrR   rR   rS   rr  
  s   zCustomTarget.links_dynamicallyr   r*  c                 C  r  r   rR   r,  rR   rR   rS   r-  
  r  z"CustomTarget.get_link_deps_mappingr/  c                 C  r8  r   r9  r   rR   rR   rS   r0  
  r   z!CustomTarget.get_link_dep_subdirsc                 C  r  r   rR   r   rR   rR   rS   r(  
  r  zCustomTarget.get_all_link_depsc                 C  s&   t | jdkr	dS t| | jd  S )zI
        Returns True if this is a not installed static library.
        r	   Fr   )r   r  r?   r[  r   rR   rR   rS   r[  
  s   zCustomTarget.is_internal(T.List[T.Union[str, 'ExtractedObjects']]c                 C  r%  r   )rJ  r   rR   rR   rS   r#  
  r  z CustomTarget.extract_all_objectsc                 C  r  )Nz@cusrR   r   rR   rR   rS   rm  
  r  zCustomTarget.type_suffixindexr   'CustomTargetIndex'c                 C  s   t | | j| S r   )r?   r  r   rZ  rR   rR   rS   __getitem__
     zCustomTarget.__getitem__c                 C  r  r   r  )r   rZ  r  rR   rR   rS   __setitem__
  r  zCustomTarget.__setitem__c                 C  r  r   r  r\  rR   rR   rS   __delitem__
  r  zCustomTarget.__delitem__c                 c  s    | j D ]}t| |V  qd S r   )r  r?   )r   r  rR   rR   rS   __iter__
  s   
zCustomTarget.__iter__c                 C  rZ  r   )r   r  r   rR   rR   rS   __len__
  r   zCustomTarget.__len__).r   r   r   r   r   r   r/   r   r>  r?  rk   r@  r  r   ri  rG   rn   r   r  rG   r  rG   r  rA  r  rB  r  r   r  r  r;  rG   rf   rG   ru   rC  ry   rD  rm   r   r<  rG   r=  rE  r  r   r  )r   rI  )r   rK  rg  r  r  r8  r7  )r   rM  )r   rN  )r  r   r   rG   r  r  r   rY  )rZ  r   r   r[  )r   r   )"rN   rO   rP   rk  r   r  r.  rJ  rL  rX  r  r   r   rJ  rK  r   rO  r^  r  rS  r  rr  r-  r0  r(  r[  r#  rm  r]  r_  r`  ra  rb  r  rR   rR   r  rS   r>   	  s^    
:


















r>   c                      sH   e Zd ZdZdZd# fddZd$ddZed%ddZd&d!d"Z	  Z
S )'CompileTargetz|
    Target that only compile sources without linking them together.
    It can be used as preprocessor, or transpiler.
    compiler   r   r   r   r/   r   rk   r  output_templr   r2   r=  r1   compile_argsr   rw   rJ   r   rh  c                   s   |  |i}dd|j d|	d|
d|i}t ||||j|d g |||
 || _|| _|| _g | _i | _	| j
D ]}| | q6| jD ]}| D ]}|| ||}| t| qGqAd S )Nrn   FrV   rw   r   )r  r  r  r   r   r  r   rf  r  sources_maprk   _add_outputrQ  rJ  Zget_target_generated_dirr   from_built_relative)r   r   r   r   r/   rk   rf  r   r=  rg  rw   r   rN  r  re  rK  rI  Zrel_srcr  rR   rS   r   
  s,   

zCompileTarget.__init__r   c                 C  r  )Nz@compilerR   r   rR   rR   rS   rm  
  r  zCompileTarget.type_suffixrG   c                 C  r  r  rR   r   rR   rR   rS   rA  
  rl  zCompileTarget.is_unityre  r   r   c                 C  sN   t j|j}t j|d }| jd|d|}| j| || j	|< d S )Nr   r  r  )
r4  r   r  r=  r  rf  r  r  r   rh  )r   re  r  r  r  rR   rR   rS   ri  
  s
   zCompileTarget._add_output)r   r   r   r   r   r   r/   r   rk   r  rf  r   r   r2   r=  r1   rg  r   rw   rJ   r   rh  r7  rg  )re  r   r   r   )rN   rO   rP   r"  rk  r   rm  r  rA  ri  r  rR   rR   r  rS   rd  
  s    
!rd  c                      sx   e Zd ZdZ		d)d* fddZd+ddZd,ddZd-ddZd.ddZd/d d!Z	d+d"d#Z
d0d%d&Zd+d'd(Z  ZS )1	RunTargetrunNTr   r   r>  JT.Sequence[T.Union[str, File, BuildTargetTypes, programs.ExternalProgram]]r   T.Sequence[Target]r   r   r/   r   r  "T.Optional['EnvironmentVariables']default_envrG   c	           	        sF   t  |||dtj| || _g | _| || _d| _|| _	|| _
d S r  )r  r   r   r  r   r  r6  r>  r<  r  rp  )	r   r   r>  r   r   r   r/   r  rp  r  rR   rS   r     s   	
zRunTarget.__init__r   c                 C  s    d}| | jj|  | jd S )Nr  r   rH  r  rR   rR   rS   r.    s   zRunTarget.__repr__r2  c                 C  r   r   r   r   rR   rR   rS   rX    r   zRunTarget.get_dependenciesr;  c                 C  r  r   rR   r   rR   rR   rS   r^    r  zRunTarget.get_generated_sourcesr   c                 C  r  r   rR   r   rR   rR   rS   r     r  zRunTarget.get_sourcesc                 C  r  r  rR   r   rR   rR   rS   r     r  zRunTarget.should_installc                 C  r   r   r  r   rR   rR   rS   rK  #  r   zRunTarget.get_filenamer   c                 C  s.   t | jtr
| jgS t | jtr| jS td)NzBRunTarget: self.name is neither a list nor a string. This is a bug)r   r   r   r   r  r   rR   rR   rS   rJ  &  s
   zRunTarget.get_outputsc                 C  r  )Nz@runrR   r   rR   rR   rS   rm  .  r  zRunTarget.type_suffixr  )r   r   r>  rm  r   rn  r   r   r   r   r/   r   r  ro  rp  rG   r7  )r   r2  r  r   rg  r8  )rN   rO   rP   rk  r   r.  rX  r^  r   r  rK  rJ  rm  r  rR   rR   r  rS   rk  
  s    






rk  c                      s*   e Zd ZdZd fd
dZdd Z  ZS )AliasTargetaliasr   r   r   T.Sequence['Target']r   r   r/   r   c                   s   t  |g |||| d S r   )r  r   )r   r   r   r   r   r/   r  rR   rS   r   5  s   zAliasTarget.__init__c                 C  s   d}| | jj|  S )Nz	<{0} {1}>)r*  r+  rN   r|  r  rR   rR   rS   r.  9  s   zAliasTarget.__repr__)
r   r   r   rs  r   r   r   r   r/   r   )rN   rO   rP   rk  r   r.  r  rR   rR   r  rS   rq  1  s    rq  c                      sj   e Zd ZeZdZd% fddZdd Zdd Zdd Z	d&ddZ
dd Zdd Zd d! Zd'd#d$Z  ZS )(JarZjarr   r   r   r   r   r   rk   T.List[SourceOutputs]r  T.Optional['StructuredSources']r/   r   rN  r  c                   s   t  |||||||||	|

 | jD ]}|ds!td| dq| jD ]}t|ts4td| dq%| jr<td| j	d | _
| j
g| _| jd | _|
d	d
| _|
dd | _d S )Nz.javazJar source z is not a java file.zLink target z is not a jar target.z5structured sources are not supported in Java targets.z.jarr  r   r   r   )r  r   rk   rP  r   r  r   rt  r  r   r  r  r  	java_argsr  r   r   )r   r   r   r   r   rk   r  rr   r/   rN  r  rI  r   r  rR   rS   r   B  s$   




zJar.__init__c                 C  r   r   )r   r   rR   rR   rS   get_main_classV  r   zJar.get_main_classc                 C  r  )Nz@jarrR   r   rR   rR   rS   rm  Y  r  zJar.type_suffixc                 C  r   r   )rw  r   rR   rR   rS   get_java_args\  r   zJar.get_java_argsr   r  c                 C  r   r   )r   r   rR   rR   rS   get_java_resources_  r   zJar.get_java_resourcesc                 C  rj  r   rR   r   rR   rR   rS   r  b  rl  zJar.validate_installc                 C  r  r  rR   r   rR   rR   rS   r  f  r  zJar.is_linkable_targetc                 C  s4   dd | j D }tj|}|rdtj|gS g S )Nc                 S  s"   g | ]}t j| | qS rR   )r4  r   r   r  rK  r   rR   rR   rS   r   j  s   " z*Jar.get_classpath_args.<locals>.<listcomp>z-cp)r  r4  pathsepr   )r   Zcp_pathsZ	cp_stringrR   rR   rS   get_classpath_argsi  s
   zJar.get_classpath_argsr  c                 C  r1  )Nz{jardir})r/   Zget_jar_dirr   rR   rR   rS   r  p  r2  zJar.get_default_install_dir)r   r   r   r   r   r   r   r   rk   ru  r  rv  r/   r   rN  r  )r   r  r  )rN   rO   rP   known_jar_kwargsr  rk  r   rx  rm  ry  rz  r  r  r|  r  r  rR   rR   r  rS   rt  =  s    
rt  c                   @  s   e Zd ZU dZdZded< ded< ded< d3ddZed4ddZdd Z	d5ddZ
d4ddZd4ddZd4ddZdd Zd6ddZd7d!d"Zd8d$d%Zd8d&d'Zd8d(d)Zd8d*d+Zd9d-d.Zd:d0d1Zd2S );r?   zA special opaque object returned by indexing a CustomTarget. This object
    exists in Meson, but acts as a proxy in the backends, making targets depend
    on the CustomTarget it's derived from, but only adding one source file to
    the sources.
    r:  zT.ClassVar[str]rk  z$T.Union[CustomTarget, CompileTarget]r9  r   r  r   r   c                 C  s   | j j| _d S r   )r9  r   r   rR   rR   rS   rC    r2  zCustomTargetIndex.__post_init__c                 C  s   | j j d| j dS )N[])r9  r   r  r   rR   rR   rS   r     s   zCustomTargetIndex.namec                 C  s   d | j| jS )Nz<CustomTargetIndex: {!r}[{}]>)r*  r9  r  r   rR   rR   rS   r.    r^  zCustomTargetIndex.__repr__r   c                 C  s   | j gS r   r  r   rR   rR   rS   rJ    r  zCustomTargetIndex.get_outputsc                 C  
   | j  S r   )r9  r  r   rR   rR   rS   r    r   zCustomTargetIndex.get_subdirc                 C  r   r   r  r   rR   rR   rS   rK    r   zCustomTargetIndex.get_filenamec                 C  r  r   )r9  r|  r   rR   rR   rS   r|    r   zCustomTargetIndex.get_idc                 C  r  r   )r9  r(  r   rR   rR   rS   r(    r   z#CustomTargetIndex.get_all_link_depsr   r*  c                 C  s   | j |S r   )r9  r-  r,  rR   rR   rS   r-    s   z'CustomTargetIndex.get_link_deps_mappingr/  c                 C  r  r   )r9  r0  r   rR   rR   rS   r0    r   z&CustomTargetIndex.get_link_dep_subdirsrG   c                 C  s   | j | jS r   )r9  rS  r  r   rR   rR   rS   r    r2  z$CustomTargetIndex.is_linkable_targetc                 C  s   t j| jd }|dvS )rT  rU  rV  )r4  r   r  r  rW  rR   rR   rS   rr    s   z#CustomTargetIndex.links_dynamicallyc                 C  r  r   )r9  r  r   rR   rR   rS   r    r   z CustomTargetIndex.should_installc                 C  s$   t j| jd }|dv o|   S )zH
        Returns True if this is a not installed static library
        rU  rV  )r4  r   r  r  r  rW  rR   rR   rS   r[    s   zCustomTargetIndex.is_internalrY  c                 C  r  r   )r9  r#  r   rR   rR   rS   r#    r   z%CustomTargetIndex.extract_all_objectsr  c                 C  r  r   )r9  r   r   rR   rR   rS   r     r   z(CustomTargetIndex.get_custom_install_dirNrS  r7  r8  r  r  rg  rc  r  )rN   rO   rP   r"  rk  rQ   rC  r  r   r.  rJ  r  rK  r|  r(  r-  r0  r  rr  r  r[  r#  r   rR   rR   rR   rS   r?   s  s,   
 












r?   c                      sT   e Zd Z	dd fddZddd	ZdddZdddZdddZdddZ  Z	S )ConfigurationDataNinitial_valuesyT.Optional[T.Union[T.Dict[str, T.Tuple[T.Union[str, int, bool], T.Optional[str]]], T.Dict[str, T.Union[str, int, bool]]]]c                   s0   t    |rdd | D ni | _d| _d S )Nc                 S  s(   i | ]\}}|t |tr|n|d fqS r   )r   tuplers  rR   rR   rS   rt    s   ( z.ConfigurationData.__init__.<locals>.<dictcomp>F)r  r   r   rO  used)r   r  r  rR   rS   r     s   

zConfigurationData.__init__r   r   c                 C  rZ  r   )r/  rO  r   rR   rR   rS   r.    r   zConfigurationData.__repr__r  rG   c                 C  s
   || j v S r   rO  )r   r  rR   rR   rS   __contains__  r   zConfigurationData.__contains__c                 C  rZ  r   )rG   rO  r   rR   rR   rS   r[    r   zConfigurationData.__bool__r   1T.Tuple[T.Union[str, int, bool], T.Optional[str]]c                 C  rQ  r   r  r  rR   rR   rS   r    r   zConfigurationData.getT.Iterator[str]c                 C  r  r   )rO  r  r   rR   rR   rS   r    r   zConfigurationData.keysr   )r  r  r7  )r  r   r   rG   rg  )r   r   r   r  )r   r  )
rN   rO   rP   r   r.  r  r[  r  r  r  rR   rR   r  rS   r    s    
	


r  c                   @  sp   e Zd ZU ded< ded< ded< ded< ded< d	Zd
ed< d	Zded< d	Zded< d	Zded< dddZd	S )Datar   rk   r   ru   r   r   ry   r   Nr   renamer   rm   	data_typer   r   r   r   c                 C  s$   | j d u rdd | jD | _ d S d S )Nc                 S  s   g | ]	}t j|jqS rR   )r4  r   r  r=  rc  rR   rR   rS   r     r  z&Data.__post_init__.<locals>.<listcomp>)r  rk   r   rR   rR   rS   rC    s   
zData.__post_init__rS  )	rN   rO   rP   rQ   r  rm   r  r   rC  rR   rR   rR   rS   r    s   
 r  c                   @  sD   e Zd ZU ded< ded< ded< ded< dZded< dddZdS )SymlinkDatar   r9  r   ru   r   Nr   rm   r   r   c                 C  s*   | j tj| j krtd| j  dd S )NzLink name is "zX", but link names cannot contain path separators. The dir part should be in install_dir.)r   r4  r   r  r   r   rR   rR   rS   rC    s   zSymlinkData.__post_init__rS  )rN   rO   rP   rQ   rm   rC  rR   rR   rR   rS   r    s   
 r  c                   @  s6   e Zd ZU ded< ded< ded< ded< ded	< d
S )	TestSetupr   exe_wrapperrG   Zgdbr   Ztimeout_multiplierr!   r  Zexclude_suitesNrM   rR   rR   rR   rS   r    s   
 r  c                 C  s   g }| D ]<}t |tr|| qt |ttttfr!|| 7 }qt |tr.||	|7 }qt |t
r:||j qtd||S )zw
    For the specified list of @sources which can be strings, Files, or targets,
    get all the output basenames.
    zUnknown source type: )r   r   r   rC   r>   r?   r@   rJ  rD   Zdetermine_ext_objsr   r=  r  )rk   r=  namesrI  rR   rR   rS   rG    s   


rG  r  c                 C  sP   t j| dd}zt|dt}t| |j_|W S  ty'   t	d|dw )Nzmeson-privatez	build.datz
Build datazNo such build data file as r   )
r4  r   r   r"   r   r
   loadr/   FileNotFoundErrorr   )r  r  brR   rR   rS   r    s   r  objr  r   c                 C  sn   | j j}d | j _z)t|d}t| | W d    n1 sw   Y  W || j _d S W || j _d S || j _w )Nwb)r/   r
   openpickledump)r  r  cdatare  rR   rR   rS   save  s   r  )rm   r   r   r   r   r   r7  )r  r   r   r   )r  r   r  r   r   r   )
__future__r   collectionsr   r   dataclassesr   r   r   	functoolsr   r  r  r_  r  r4  r  rQ  rw  typingr  r   r
   r   r   r   mesonlibr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   rN  r#   r$   r%   r&   r'   r(   r)   r*   Zinterpreterbaser+   r,   TYPE_CHECKINGZtyping_extensionsr-   r.   r/   Z_typingr0   Zbackend.backendsr1   r2   Zinterpreter.interpreterr3   r4   Zinterpreter.interpreterobjectsr5   r6   Zlinkers.linkersr7   r8   r9   r:   r   r;   Zmparserr<   wrapr=   UnionrE   ZLibTypesry  r   ZObjectTypesrF   Z
pch_kwargsZlang_arg_kwargsZvala_kwargsZrust_kwargsZ	cs_kwargsZbuildtarget_kwargsr  r  r'  r)  r  r}  r   r   r   r   r   r   r   r   r   r   r#  rD   rV  ABCMetarh  rC   r  r  r  r@   r8  rB   rA   r  r*  r1  r7  r>   rd  rk  rq  rt  r?   r  r  r  r  rG  r  r  rR   rR   rR   rS   <module>   s  X(



 &
60 ?        XG _  !& L836I
