o
    uJAf&                     @  s6  d dl mZ d dlZd dlZd dlZd dlZddlmZm	Z	 ddlm
Z
 ddlmZmZ ddlmZ dd	lmZmZmZ dd
lmZmZmZmZmZ ddlmZmZ ddlmZ ejrddlmZ ddlmZ ddl m!Z! d dl"m#Z# G dd de#Z$G dd de#Z%G dd dej&Z'G dd deZ(dddZ)dS )    )annotationsN   )ExtensionModule
ModuleInfo)ModuleReturnValue   )mesonlibbuild)mlog)DEPEND_FILES_KW
DEPENDS_KWINCLUDE_DIRECTORIES)ContainerTypeInfo
FeatureNew	KwargInfotyped_kwargstyped_pos_args)MachineChoiceMesonException)ExternalProgram)ModuleState)Compiler)Interpreter)	TypedDictc                   @  s.   e Zd ZU ded< ded< ded< ded< d	S )
CompileResourcesT.List[mesonlib.FileOrString]depend_files6T.List[T.Union[build.BuildTarget, build.CustomTarget]]dependsz'T.List[T.Union[str, build.IncludeDirs]]include_directorieszT.List[str]argsN__name__
__module____qualname____annotations__ r&   r&   ?/usr/lib/python3.10/site-packages/mesonbuild/modules/windows.pyr   &   s
   
 r   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S )RcKwargsstroutputz?T.List[T.Union[mesonlib.FileOrString, build.CustomTargetIndex]]inputzT.Optional[str]depfiler   r   r   r   z%T.List[T.Union[str, ExternalProgram]]commandNr!   r&   r&   r&   r'   r(   -   s   
 r(   c                   @  s   e Zd ZdZdZdZdS )ResourceCompilerTyper   r      N)r"   r#   r$   windresrcwrcr&   r&   r&   r'   r.   5   s    r.   c                      s   e Zd ZedZd fddZd d
dZd!ddZede	e
jejejfddedejddejddeedeee	g ddd"ddZ  ZS )#WindowsModulewindowsinterpreter'Interpreter'c                   s(   t  | d | _| jd| ji d S )Ncompile_resources)super__init___rescompmethodsupdater7   )selfr5   	__class__r&   r'   r9   >   s
   
zWindowsModule.__init__	compilersT.Dict[str, 'Compiler']return
'Compiler'c                 C  s&   dD ]}||v r||   S qt d)N)ccppz2Resource compilation requires a C or C++ compiler.)r   )r=   r@   lr&   r&   r'   detect_compilerE   s
   zWindowsModule.detect_compilerstate'ModuleState'.T.Tuple[ExternalProgram, ResourceCompilerType]c                 C  s  t j}| jr	| jS t|j|d}|r| s<| |jjj	| }|j
dv s/|jr6|jj
dv r6tddd}ntddd}| sDtddd	tjfdd
tjfddtjfddtjffD ].\}}}t| |g \}}	}
t||	tj}|rtd|   ||f| _ | jS qZtd)Nr0   >   zintel-clmsvczclang-cl>   zlld-linklinkr1   T)silentz(Could not find Windows resource compilerz/?z"^.*Microsoft.*Resource Compiler.*$zLLVM Resource Converter.*$z	--versionz^.*GNU windres.*$z^.*Wine Resource Compiler.*$zWindows resource compiler: %sz5Could not determine type of Windows resource compiler)r   HOSTr:   r   from_bin_listenvironmentfoundrG   coredatar@   idlinkerr   r.   r1   r0   r2   r   
Popen_safeget_commandresearch	MULTILINEr
   loggroup)r=   rH   for_machinerescompcompargmatchZrc_typepoemr&   r&   r'   _find_resource_compilerK   s2   




z%WindowsModule._find_resource_compilerzwindows.compile_resourcesr   )varargsmin_varargsz0.47.0)sincer    T)defaultlistifyYT.Tuple[T.List[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex]]]kwargs'CompileResources'r   c                   s  |d   }|d }|d }|D ]!}t|tjr1|tdg dtjd| j	j
|gg7 }q||d 7 }| \}}	|	tjkrPd}
|g d	 }n+|	tjkrsd
}
|ddg }d}|D ]}d|v rqtj||dd qand
}
|g d }g }d fdd}| D ]_\}}}|dddddd}|dddddd}| d|
 }g }|| || d }|	tjkr| d}|g d |tj|jjj||g|g|||dd qt||gS )Nr    r   r    Fz@BUILD_ROOT@r   res)z/nologoz/fo@OUTPUT@@INPUT@rb   rp   @OUTPUT@zArgument {!r} has a space which may not work with windres due to a MinGW bug: https://sourceware.org/bugzilla/show_bug.cgi?id=4933 )fatal)rp   z-orq   rB   ST.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, build.CustomTargetIndex]]]c                  3  s    d D ]} t | trtjj| | | fV  qt | tjr)|  | j	| fV  qt | t
jrTtjddjjd |   d| j | j d|   | fV  qt|  dkrgtjddjjd t|  D ]\}}|   d| d| d| | | fV  qmqd S )	Nr   zBwindows.compile_resource CustomTargetIndex in positional argumentsz0.61.0)location_Zwindows_compile_resources_r   zSwindows.compile_resource CustomTarget with multiple outputs in positional arguments)
isinstancer)   ospathjoinsubdirr   Filerelative_namefnamer	   CustomTargetIndexr   
single_use
subprojectcurrent_nodeget_idtargetget_outputsindexr*   get_filenamelen	enumerate)srcioutr    rH   r&   r'   	get_names   s*   

,z2WindowsModule.compile_resources.<locals>.get_names/rv   \:z_@BASENAME@.z.d)z--preprocessor-arg=-MDz--preprocessor-arg=-MQ@OUTPUT@z--preprocessor-arg=-MF@DEPFILE@zCompiling Windows resource {})r,   r   extra_dependsdescription)rB   rt   )copyrw   r	   CustomTargetget_include_argsIncludeDirsrx   ry   rz   r5   backendget_target_dirre   r.   r1   r0   r
   warningformatreplaceappendextendr{   r   rP   r   )r=   rH   r    rl   
extra_argsZwrc_depend_filesZwrc_dependsdr]   Zrescomp_typesuffixZres_argsrd   r_   Zres_targetsr   nameZname_formattedr   r*   r-   r,   r&   r   r'   r7   s   sh   $






zWindowsModule.compile_resources)r5   r6   )r@   rA   rB   rC   )rH   rI   rB   rJ   )rH   rI   r    rk   rl   rm   rB   r   )r"   r#   r$   r   INFOr9   rG   re   r   r)   r   r|   r	   r   r   r   r   evolver   r   r   r   listr7   __classcell__r&   r&   r>   r'   r3   :   s    

(

r3   interpr6   rB   c                 C  s   t | S )N)r3   )r   r&   r&   r'   
initialize   s   r   )r   r6   rB   r3   )*
__future__r   enumrx   rW   typingTrn   r   r   r   r   r	   r
   Zinterpreter.type_checkingr   r   r   interpreterbase.decoratorsr   r   r   r   r   r   r   programsr   TYPE_CHECKINGr   r@   r   r5   r   Ztyping_extensionsr   r   r(   Enumr.   r3   r   r&   r&   r&   r'   <module>   s0    