o
    e}w                     @  s  d dl mZ d dlZd dlZd dlZd dlm  mZ	 ddl
mZ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 dd
lmZmZmZmZ ddlmZ ddlmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( ej)rddl
m*Z* ddl+m,Z,m-Z- ddlm.Z. ddlm/Z/ ddlm0Z0 ddl'm1Z1 ej2e,e-f Z3d dl4m5Z5 G dd de5Z6G dd de5Z7G dd de5Z8G dd de5Z9G dd de/j:Z;G d d! d!e5Z<G d"d# d#eZ=dS )$    )annotationsN   )ModuleReturnValueExtensionModule   )build)coredata)mlog)find_external_dependency
DependencyExternalLibraryInternalDependency)MesonExceptionFileversion_compare
Popen_safe)extract_required_kwarg)INSTALL_DIR_KW
INSTALL_KWNoneType)ContainerTypeInfoFeatureDeprecated	KwargInfo	noPosargs
FeatureNewtyped_kwargs)NonExistingExternalProgram)ModuleState)QtPkgConfigDependencyQmakeQtDependency)Interpreter)kwargs)FileOrString)ExternalProgram)	TypedDictc                   @  s2   e Zd ZU dZded< ded< ded< ded	< d
S )ResourceCompilerKwArgsz3Keyword arguments for the Resource Compiler method.T.Optional[str]namecT.Sequence[T.Union[FileOrString, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]sourcesT.List[str]
extra_argsstrmethodN__name__
__module____qualname____doc____annotations__ r4   r4   :/usr/lib/python3.10/site-packages/mesonbuild/modules/qt.pyr%   -   s   
 r%   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	UICompilerKwArgsz-Keyword arguments for the Ui Compiler method.r(   r)   r*   r+   r,   r-   Nr.   r4   r4   r4   r5   r6   6   s
   
 r6   c                   @  sB   e Zd ZU dZded< ded< ded< ded< d	ed
< ded< dS )MocCompilerKwArgsz.Keyword arguments for the Moc Compiler method.r(   r)   headersr*   r+   r,   r-   'T.List[T.Union[str, build.IncludeDirs]]include_directories,T.List[T.Union[Dependency, ExternalLibrary]]dependenciesNr.   r4   r4   r4   r5   r7   >   s   
 r7   c                   @  sf   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ed< ded< ded< dS )PreprocessKwArgszT.List[FileOrString]r)   z1T.List[T.Union[FileOrString, build.CustomTarget]]moc_sourcesmoc_headers
qresourcesui_filesr*   moc_extra_argumentsrcc_extra_argumentsuic_extra_argumentsr9   r:   r;   r<   r,   r-   Nr/   r0   r1   r3   r4   r4   r4   r5   r=   I   s   
 r=   c                   @  s   e Zd ZU ded< dS )HasToolKwArgsr,   r-   NrE   r4   r4   r4   r5   rF   W   s   
 rF   c                   @  sF   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S )CompileTranslationsKwArgsboolbuild_by_defaultinstallr&   install_dirr,   r-   	qresourcer*   rC   z\T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]ts_filesNrE   r4   r4   r4   r5   rG   [   s   
 rG   c                   @  s  e Zd ZdZdZdZdfdgddZdhddZdidjddZe	dkddZ
dld d!Zed"d#eed"edeejfdd$eded%d$dmd*d+Zed,d-eed,ed.eefed/eeeeejejejfdd0ddd1ed2eeedg d3eded%d$dnd6d7Zdod9d:Zed;d-eed;ed/eeeeejejejfdd0ddd1ed2eeedg d3eded%d$dpd=d>Zdqd@dAZ edBd-eedBed/eeeeejejejfdg d3edCeeeeejejejfdg d3ed2eeedg d3eded%d$edDeeej!efdg d3edEeee"e#fdg d3drdGdHZ$dsdJdKZ%edLed/eeeefdg d-dMedNeeeefdg d3edOeeeeejfdg d3edPeeeeejfdg d3edQeeeeejfdg d3edReeedg dSdTedUeeedg dVdTedWeeedg dVdTeded%d$edDeeej!efdg d3edEeee"e#fdg d3dtdZd[Z&ed\dSeed\ed]edd$e'e(eded%d$ed^eefd_d`edUeeedg d_dTedaeeeeejejejfdg d3dudcddZ)deS )vQtBaseModuleF   interpreter'Interpreter'
qt_versionintc              	   C  s\   t | | || _tdtdtdtdd| _| j| j| j| j	| j
| j| jd d S )Nmocuicrcclrelease)rT   rU   rV   rW   )	has_tools
preprocesscompile_translationscompile_resources
compile_uicompile_moc)r   __init__rR   r   toolsmethodsupdaterX   rY   rZ   r[   r\   r]   )selfrP   rR   r4   r4   r5   r^   j   s   zQtBaseModule.__init__state'ModuleState'qt_dep'QtDependencyType'returnNonec                   s   dj  }dfdd}| D ]<\}j  rqdkr%dg ntj dr/d	g nd
g d fdd}|j|d||d}| rM|j< qdS )zCDetect Qt (4 or 5) moc, uic, rcc in the specified bindir or in PATHz== rg   *T.Generator[T.Tuple[str, str], None, None]c                  3  s~    j D ]8}  jrtj j| | fV   jr"tj j| | fV  |   j | fV  |  d j | fV  | | fV  qd S )N-qt)r_   ZbindirospathjoinZ
libexecdirZqtver)b)re   rb   r4   r5   gen_bins   s   
z/QtBaseModule.compilers_detect.<locals>.gen_binsrW   z-versionz>= 5z	--versionz-vp*T.Union[ExternalProgram, build.Executable]r,   c                   sR   t |    \}}}dksjds|}n|}|jdddd dd S )	NrW   4 r   )maxsplit) )r   get_commandversion
startswithrsplitreplacestrip)rp   _outerrZcare)argr'   re   r4   r5   get_version   s
   z2QtBaseModule.compilers_detect.<locals>.get_versionF)requiredZversion_funcwantedN)rg   ri   )rp   rq   rg   r,   )ry   r_   foundr   Zfind_program)rb   rc   re   r   ro   rn   r   rp   r4   )r   r'   re   rb   r5   compilers_detect~   s&   
zQtBaseModule.compilers_detectTr-   r,   r   rH   c                 C  s  | j rd S d| _ td| j d |d|d}tdtd| j |j|}| rZ| 	|| t
|jdr;d| _ntjd	d
d t
|jdrMd| _d S tjdtdd
d d S d| j }td| d| jd< td| d| jd< td| d| jd< td| d| jd< d S )NTzDetecting Qtz toolsZCore)r   modulesr-   r   qtz>=5.15.0zDmoc dependencies will not work properly until you move to Qt >= 5.15F)fatalz>=5.14.0zErcc dependencies will not work properly until you move to Qt >= 5.14:z+https://bugreports.qt.io/browse/QTBUG-45460rj   rT   r'   rU   rV   rW   )_tools_detectedr	   logrR   Tcastr
   environmentr   r   r   ry   _moc_supports_depfileswarning_rcc_supports_depfilesboldr   r_   )rb   rc   r-   r   r!   r   suffixr4   r4   r5   _detect_tools   s*   


zQtBaseModule._detect_toolsrcc_file'FileOrString'T.Tuple[str, T.List[str]]c              	   C  s   t |trtj| jj| j|}n
|| jj| jj	}tj
|}zFt|}| }g }|d D ]1}|jdkrHtdtj| jt|  n|jd u r\tdtj| jt| ||j q1||fW S  tyo     ty|   td| w )Nr   filezmalformed rcc file: z!<file> element without a path in zUnable to parse resource file )
isinstancer,   rk   rl   rm   r   
source_dirsubdirZabsolute_path	build_dirdirnameETparseZgetroottagr	   r   textr   append	Exception)rc   r   abspathrcc_dirnametreerootresultchildr4   r4   r5   
_qrc_nodes   s*   




zQtBaseModule._qrc_nodes	rcc_file_YT.Union['FileOrString', build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]T.List[File]c              	   C  s  g }g }t |ttfr|g}n| }|D ]i}| ||\}}|D ]\}tj|rT|tj	|j
jrHtj||j
j}	|tdd|	d q!|td|j|d q!tjtj||}
|
|j
jrr|td|j|d q!|td|j|
d q!q|S )NTrw   )Zis_builtr   fnameF)r   r,   r   get_outputsr   rk   rl   isabsrz   r   r   r   relpathr   r   normpathrm   )rb   rc   r   r   inputsr   r   nodesresource_pathZresource_relpathZpath_from_rccr4   r4   r5   _parse_qrc_deps   s&   zQtBaseModule._parse_qrc_depszqt.has_toolsz0.54.0defaultautoargsT.Tupler!   'HasToolKwArgs'c           	      C  s|   | dd}t||jdd\}}}|rtdt|d dS | j||dd | j D ]}|	 s;|r8t
d dS q,d	S )
Nr-   r   Fr   zqt.has_tools skipped: featuredisabled)r   zQt tools not foundT)getr   
subprojectr	   r   r   r   r_   valuesr   r   )	rb   rc   r   r!   r-   r   r   Zfeaturetoolr4   r4   r5   rX     s   zQtBaseModule.has_toolszqt.compile_resourcesz0.59.0r'   r)   )Zallow_empty)listifyr   r+   )r   r   'ResourceCompilerKwArgs'r   c                 C  D   t dd |d D rtjdd|j|jd | ||}t||gS )zhCompile Qt resources files.

        Uses CustomTargets to generate .cpp files from .qrc files.
        c                 s  &    | ]}t |tjtjtjfV  qd S Nr   r   CustomTargetCustomTargetIndexGeneratedList.0sr4   r4   r5   	<genexpr>1     $ z1QtBaseModule.compile_resources.<locals>.<genexpr>r)   zOqt.compile_resources: custom_target or generator for "sources" keyword argument0.60.0location)anyr   
single_user   current_node_compile_resources_implr   rb   rc   r   r!   r   r4   r4   r5   r[     s   
zQtBaseModule.compile_resourcesT.List[build.CustomTarget]c                 C  s  |  ||d  | jd  sd}t|dd| j | jg }| jr(ddgng }|d }g }|d	 D ]}t|tt	frC|
| q4||  q4|d
 }	|rg }
|D ]}|
| || qUtj||j|j|j| jd  d|ddg |	 dg | || dg|
| ddd
}|
| |S |D ]W}| ||}
t|trtj|}ntj|j}d| j d|dd }tj||j|j|j| jd  g d |	 dg | |g| dg|
| ddd
}|
| q|S )Nr-   rV   Q{0} sources specified and couldn't find {1}, please check your qt{2} installationZRCCzrcc-qtz	--depfilez	@DEPFILE@r'   r)   r+   -name-o@OUTPUT@@INPUT@z.cppz.dzCompiling Qt resources {})Zdepend_filesdepfiledescriptionr   -.r~   )r   z
@BASENAME@r   r   )r   r_   r   r   formatrR   r   r   r,   r   r   extendr   r   r   r   r   r   r   rx   rk   rl   basenamer   r|   )rb   rc   r!   err_msgtargetsDEPFILE_ARGSr'   r)   r   r+   Zqrc_depsZ
res_targetr   r   r4   r4   r5   r   7  sf   &


"
z$QtBaseModule._compile_resources_implzqt.compile_ui'UICompilerKwArgs'c                 C  r   )z&Compile UI resources into cpp headers.c                 s  r   r   r   r   r4   r4   r5   r     r   z*QtBaseModule.compile_ui.<locals>.<genexpr>r)   zHqt.compile_ui: custom_target or generator for "sources" keyword argumentr   r   )r   r   r   r   r   _compile_ui_implr   r   r4   r4   r5   r\   z  s   
zQtBaseModule.compile_uibuild.GeneratedListc                 C  s~   |  ||d  | jd  sd}t|dd| j | jtj| jd |d g d dgd	| j d
d}||d |S )Nr-   rU   r   ZUICuic-qtr+   )r   r   r   zui_@BASENAME@.hQtz uir   r)   )	r   r_   r   r   r   rR   r   	Generatorprocess_files)rb   rc   r!   r   genr4   r4   r5   r     s   zQtBaseModule._compile_ui_implzqt.compile_mocr8   r:   r<   'MocCompilerKwArgs'c                 C  sp   t dd |d D rtjdd|j|jd t dd |d D r,tjd	d|j|jd | ||}t||gS )
Nc                 s  r   r   r   r   r4   r4   r5   r     r   z+QtBaseModule.compile_moc.<locals>.<genexpr>r8   zIqt.compile_moc: custom_target or generator for "headers" keyword argumentr   r   c                 s  r   r   r   r   r4   r4   r5   r     r   r)   zIqt.compile_moc: custom_target or generator for "sources" keyword argument)r   r   r   r   r   _compile_moc_implr   r   r4   r4   r5   r]     s   

zQtBaseModule.compile_mocT.List[build.GeneratedList]c              	   C  s  |  ||d  | jd  sd}t|dd| j | j|d s,|d s,td|j|d	 d
}g }|d D ],}|	dd |
 D  t|trf|jD ]}|	dd || jj| jjjD  qPq:g }| jrodgng }	|d |	 | | g d }
|d rtj| jd |
dgdd| j dd}|||d | |d rtj| jd |
dgdd| j dd}|||d | |S )Nr-   rT   r   ZMOCr   r8   r)   z[At least one of the "headers" or "sources" keyword arguments must be provided and not emptyr:   )include_dirsr<   c                 s  s    | ]
}| d r|V  qdS ))-Iz-DN)rz   )r   ar4   r4   r5   r     s    z1QtBaseModule._compile_moc_impl.<locals>.<genexpr>c                 s  s    | ]}d | V  qdS )r   Nr4   )r   ir4   r4   r5   r     s    z--output-dep-filer+   )r   r   r   zmoc_@BASENAME@.cppzmoc_@BASENAME@.cpp.dr   z moc header)r   r'   z@BASENAME@.mocz@BASENAME@.moc.dz moc source)r   r_   r   r   r   rR   r   InvalidArgumentsZget_include_argsr   Zget_all_compile_argsr   r   r:   Zto_string_listrP   Zsource_rootr   r   r   r   r   r   )rb   rc   r!   r   ZincZcompile_argsdepincloutputr   	argumentsZmoc_genr4   r4   r5   r     s@   


(zQtBaseModule._compile_moc_implzqt.preprocess)r   r   Z
deprecatedr@   rA   r>   r?   rB   z0.44.0)r   r   sincerC   z0.49.0rD   T.List[T.Union[str, File]]'PreprocessKwArgs'c                 C  s>  |dd  }|rt jdd|j|jd td||d  }|D ]}t|ttfs-t	
dq|d }|d	 r^d
|d	 |d |d}|rU|d }	t|	tsQt	
d|	|d< || || |d ru|d |d |d}
|| ||
 |d s}|d r|d |d |d |d |d |d}|| || t||gS )Nr   z qt.preprocess positional sourcesz0.59r   zCT.List[T.Union[str, File, build.GeneratedList, build.CustomTarget]]r)   z<Variadic arguments to qt.preprocess must be Strings or Filesr-   r@   rw   rC   )r'   r)   r+   r-   r   z0First argument to qt.preprocess must be a stringr'   rA   rD   )r)   r+   r-   r?   r>   rB   r:   r<   )r+   r)   r8   r:   r<   r-   )r   r   r   r   r   r   r   r,   r   r   r   r   r   r   r   r   r   )rb   rc   r   r!   Z_sourcesr)   r   r-   Z
rcc_kwargsr'   Z	ui_kwargsZ
moc_kwargsr4   r4   r5   rY     s@   



zQtBaseModule.preprocesszqt.compile_translationsrI   rL   z0.56.0)r   rM   'CompileTranslationsKwArgs'c                 C  sX  |d }t dd |D rtjdd|j|jd |d r$|d s$td	|d
 }|r|r0tdtj|dkr<tdt	
|j|}tj|jj| }tj|jj| }tjtj|dd t|| | j| | ||\}	}
|
D ]}|dr||dd  qztd| | |g ||d d}| ||d  g }|D ]l}| jd  std| jd j d |rt|t sJ dtjtj!tj|j|}tj"|}n|j}| jd dddg}t#j$d| j% d| ||j|j||gdg|d |d gd g|d! d"d#}|| q|r&t&|j'd$ |j(|gS t&||gS )%NrM   c                 s  r   r   r   r   r4   r4   r5   r   *  r   z4QtBaseModule.compile_translations.<locals>.<genexpr>zSqt.compile_translations: custom_target or generator for "ts_files" keyword argumentr   r   rJ   rK   z[qt.compile_translations: "install_dir" keyword argument must be set when "install" is true.rL   zCqt.compile_translations: Cannot specify both ts_files and qresourcerw   zMqt.compile_translations: qresource file name must not contain a subdirectory.T)exist_okz.qmz.tszDqt.compile_translations: qresource can only contain qm files, found rC   )r@   rC   r-   rW   zqt.compile_translations: z
 not foundzfor mypyr   z-qmr   r   z	-compile-z@BASENAME@.qmZi18nrI   zCompiling Qt translations {})rJ   rK   Zinstall_tagrI   r   r   ))r   r   r   r   r   r   rk   rl   r   r   Zfrom_built_filer   rm   r   r   Zrelative_namer   makedirsshutilcopy2rP   Zadd_build_def_filer   endswithr   rstriprY   r   r_   r   r'   r   r,   r   r   r   r   rR   r   return_valueZnew_objects)rb   rc   r   r!   rM   rL   Zqresource_fileZ
infile_absZoutfile_absr~   r   cresultsZtranslationstsoutdircmdZlrelease_targetr4   r4   r5   rZ     st   


 z!QtBaseModule.compile_translationsN)rO   )rP   rQ   rR   rS   )rc   rd   re   rf   rg   rh   )T)rc   rd   r-   r,   r   rH   rg   rh   )rc   rd   r   r   rg   r   )rc   rd   r   r   rg   r   )rc   rd   r   r   r!   r   rg   rH   )rc   rd   r   r   r!   r   rg   r   )rc   rd   r!   r   rg   r   )rc   rd   r   r   r!   r   rg   r   )rc   rd   r!   r   rg   r   )rc   rd   r   r   r!   r   rg   r   )rc   rd   r!   r   rg   r   )rc   rd   r   r   r!   r   rg   r   )rc   rd   r   r   r!   r   rg   r   )*r/   r0   r1   r   r   r   r^   r   r   staticmethodr   r   r   r   r   r   rH   r   ZUserFeatureOptionr,   rX   r   r   listr   r   r   r   r   r[   r   r\   r   ZIncludeDirsr   r   r]   r   rY   r   r   rZ   r4   r4   r4   r5   rN   e   s    
+
%
C


)'$
rN   )>
__future__r   rk   r  typingr   Zxml.etree.ElementTreeetreeZElementTreer   rw   r   r   r   r   r	   r<   r
   r   r   r   Zmesonlibr   r   r   r   rP   r   Zinterpreter.type_checkingr   r   r   Zinterpreterbaser   r   r   r   r   r   Zprogramsr   TYPE_CHECKINGr   Zdependencies.qtr   r   r    r!   r"   r#   UnionZQtDependencyTypetyping_extensionsr$   r%   r6   r7   r=   ZExtractRequiredrF   rG   rN   r4   r4   r4   r5   <module>   s>    	
