o
    ldu                     @  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 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m/Z/ ddl&m0Z0 ej1e+e,f Z2d dl3m4Z4 G dd de4Z5G dd de4Z6G dd de4Z7G dd de4Z8G dd de.j9Z:G d d! d!e4Z;G d"d# d#eZ<dS )$    )annotationsN   )ModuleReturnValueExtensionModule   )build)coredata)mlog)find_external_dependency
DependencyExternalLibrary)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__ r3   r3   thome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/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-   r3   r3   r3   r4   r5   6   s
   
 r5   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-   r3   r3   r3   r4   r6   >   s   
 r6   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_argumentsr8   r9   r:   r;   r+   r,   Nr.   r/   r0   r2   r3   r3   r3   r4   r<   I   s   
 r<   c                   @  s   e Zd ZU ded< dS )HasToolKwArgsr+   r,   NrD   r3   r3   r3   r4   rE   W   s   
 rE   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)   rB   z\T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]ts_filesNrD   r3   r3   r3   r4   rF   [   s   
 rF   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)rS   rT   rU   rV   )	has_tools
preprocesscompile_translationscompile_resources
compile_uicompile_moc)r   __init__rQ   r   toolsmethodsupdaterW   rX   rY   rZ   r[   r\   )selfrO   rQ   r3   r3   r4   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== rf   *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)rd   ra   r3   r4   gen_bins   s   
z/QtBaseModule.compilers_detect.<locals>.gen_binsrV   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 )	NrV   4 r   )maxsplit) )r   get_commandversion
startswithrsplitreplacestrip)ro   _outerrZcare)argr&   rd   r3   r4   get_version   s
   z2QtBaseModule.compilers_detect.<locals>.get_versionF)requiredZversion_funcwantedN)rf   rh   )ro   rp   rf   r+   )rx   r^   foundr   Zfind_program)ra   rb   rd   r   rn   rm   r   ro   r3   )r   r&   rd   ra   r4   compilers_detect~   s&   
zQtBaseModule.compilers_detectTr,   r+   r   rG   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-45460ri   rS   r&   rT   rU   rV   )_tools_detectedr	   logrQ   Tcastr
   environmentr   r   r   rx   _moc_supports_depfileswarning_rcc_supports_depfilesboldr   r^   )ra   rb   r,   r   r    r   suffixr3   r3   r4   _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+   rj   rk   rl   r   
source_dirsubdirZabsolute_path	build_dirdirnameETparseZgetroottagr	   r   textr   append	Exception)rb   r   abspathrcc_dirnametreerootresultchildr3   r3   r4   
_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 )NTrv   )Zis_builtr   fnameF)r   r+   r   get_outputsr   rj   rk   isabsry   r   r   r   relpathr   r   normpathrl   )ra   rb   r   r   inputsr   r   nodesresource_pathZresource_relpathZpath_from_rccr3   r3   r4   _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   )	ra   rb   r   r    r,   r   r   Zfeaturetoolr3   r3   r4   rW     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sr3   r3   r4   	<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   ra   rb   r   r    r~   r3   r3   r4   rZ     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	}|
| |S |D ]V}| ||}
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	}|
| q|S )Nr,   rU   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.d)Zdepend_filesdepfiler   -.r}   )r   z
@BASENAME@r   r   )r   r^   r   r   formatrQ   r   r   r+   r   r   extendr   r   r   r   r   r   r   rw   rj   rk   basenamer   r{   )ra   rb   r    err_msgtargetsDEPFILE_ARGSr&   r(   r   r*   Zqrc_depsZ
res_targetr   r   r3   r3   r4   r   7  sb   &


"
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   r3   r3   r4   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   r3   r3   r4   r[   x  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,   rT   r   ZUICuic-qtr*   )r   r   r   zui_@BASENAME@.hQtz uir   r(   )	r   r^   r   r   r   rQ   r   	Generatorprocess_files)ra   rb   r    r   genr3   r3   r4   r     s   zQtBaseModule._compile_ui_implzqt.compile_mocr7   r9   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   r3   r3   r4   r     r   z+QtBaseModule.compile_moc.<locals>.<genexpr>r7   zIqt.compile_moc: custom_target or generator for "headers" keyword argumentr   r   c                 s  r   r   r   r   r3   r3   r4   r     r   r(   zIqt.compile_moc: custom_target or generator for "sources" keyword argument)r   r   r   r   r   _compile_moc_implr   r   r3   r3   r4   r\     s   

zQtBaseModule.compile_mocT.List[build.GeneratedList]c                 C  sN  |  ||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  q:g }| jrQd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,   rS   r   ZMOCr   r7   r(   z[At least one of the "headers" or "sources" keyword arguments must be provided and not emptyr9   )include_dirsr;   c                 S  s   g | ]	}| d r|qS ))z-Iz-D)ry   )r   ar3   r3   r4   
<listcomp>  s    z2QtBaseModule._compile_moc_impl.<locals>.<listcomp>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.d@z moc source)r   r^   r   r   r   rQ   r   InvalidArgumentsZget_include_argsr   Zget_all_compile_argsr   r   r   r   )ra   rb   r    r   ZincZcompile_argsdepoutputr   	argumentsZmoc_genr3   r3   r4   r     s8   
zQtBaseModule._compile_moc_implzqt.preprocess)r   r   Z
deprecatedr?   r@   r=   r>   rA   z0.44.0)r   r   sincerB   z0.49.0rC   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?   rv   rB   )r&   r(   r*   r,   r   z0First argument to qt.preprocess must be a stringr&   r@   rC   )r(   r*   r,   r>   r=   rA   r9   r;   )r*   r(   r7   r9   r;   r,   )r   r   r   r   r   r   r   r+   r   r   r   r   r   r   r   r   r   )ra   rb   r   r    Z_sourcesr(   r   r,   Z
rcc_kwargsr&   Z	ui_kwargsZ
moc_kwargsr3   r3   r4   rX     s@   



zQtBaseModule.preprocesszqt.compile_translationsrH   rK   z0.56.0)r   rL   'CompileTranslationsKwArgs'c                 C  sV  |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 ]k}| 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"}|| q|r%t&|j'd# |j(|gS t&||gS )$NrL   c                 s  r   r   r   r   r3   r3   r4   r   %  r   z4QtBaseModule.compile_translations.<locals>.<genexpr>zSqt.compile_translations: custom_target or generator for "ts_files" keyword argumentr   r   rI   rJ   z[qt.compile_translations: "install_dir" keyword argument must be set when "install" is true.rK   zCqt.compile_translations: Cannot specify both ts_files and qresourcerv   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 rB   )r?   rB   r,   rV   zqt.compile_translations: z
 not foundzfor mypyr   z-qmr   r   z	-compile-z@BASENAME@.qmZi18nrH   )rI   rJ   Zinstall_tagrH   r   ))r   r   r   r   r   r   rj   rk   r   r   Zfrom_built_filer   rl   r   r   Zrelative_namer   makedirsshutilcopy2rO   Zadd_build_def_filer   endswithr   rstriprX   r   r^   r   r&   r   r+   r   r   r   r   rQ   r   return_valueZnew_objects)ra   rb   r   r    rL   rK   Zqresource_fileZ
infile_absZoutfile_absr}   r   cresultsZtranslationstsoutdircmdZlrelease_targetr3   r3   r4   rY     sr   


 z!QtBaseModule.compile_translationsN)rN   )rO   rP   rQ   rR   )rb   rc   rd   re   rf   rg   )T)rb   rc   r,   r+   r   rG   rf   rg   )rb   rc   r   r   rf   r   )rb   rc   r   r   rf   r   )rb   rc   r   r   r    r   rf   rG   )rb   rc   r   r   r    r   rf   r   )rb   rc   r    r   rf   r   )rb   rc   r   r   r    r   rf   r   )rb   rc   r    r   rf   r   )rb   rc   r   r   r    r   rf   r   )rb   rc   r    r   rf   r   )rb   rc   r   r   r    r   rf   r   )rb   rc   r   r   r    r   rf   r   )*r.   r/   r0   r   r   r   r]   r   r   staticmethodr   r   r   r   r   r   rG   r   ZUserFeatureOptionr+   rW   r   r   listr   r   r   r   r   rZ   r   r[   r   ZIncludeDirsr   r   r\   r   rX   r   r   rY   r3   r3   r3   r4   rM   e   s    
+
%
A


&'$
rM   )=
__future__r   rj   r   typingr   Zxml.etree.ElementTreeetreeZElementTreer   rv   r   r   r   r   r	   r;   r
   r   r   Zmesonlibr   r   r   r   rO   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$   r5   r6   r<   ZExtractRequiredrE   rF   rM   r3   r3   r3   r4   <module>   s>    	
