
    e&                    p   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j8                  r.ddlmZ ddlmZ ddl m!Z! d dl"m#Z#  G d de#      Z$ G d de#      Z% G d dejL                        Z' G d de      Z(ddZ)y)    )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                  6    e Zd ZU ded<   ded<   ded<   ded<   y	)
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__     </usr/lib/python3/dist-packages/mesonbuild/modules/windows.pyr   r   &   s    33GGDDr)   r   c                  J    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   y)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%    NN  33GG66r)   r,   c                      e Zd ZdZdZdZy)ResourceCompilerTyper   r      N)r$   r%   r&   windresrcwrcr(   r)   r*   r3   r3   5   s    G	
B
Cr)   r3   c                  8    e Zd Z ed      Zd fdZddZddZ ede	e
j                  ej                  ej                  fd       ed ej"                  d	       ej"                  d	      e ed
 eee	      g d            	 	 	 	 	 	 dd              Z xZS )WindowsModulewindowsc                    t         |   |       d | _        | j                  j	                  d| j
                  i       y )Ncompile_resources)super__init___rescompmethodsupdater<   )selfinterpreter	__class__s     r*   r>   zWindowsModule.__init__>   s9    %TX!7!7
 	r)   c                <    dD ]  }||v s||   c S  t        d      )N)ccppz2Resource compilation requires a C or C++ compiler.)r   )rB   	compilersls      r*   detect_compilerzWindowsModule.detect_compilerE   s0     	$AI~ |#	$ QRRr)   c                   t         j                  }| j                  r| j                  S t        j                  |j
                  |d      }|r|j                         s| j                  |j
                  j                  j                  |         }|j                  dv s$|j                  r&|j                  j                  dv rt        dd      }nt        dd      }|j                         st        d      dd	t        j                  fdd
t        j                  fddt        j                  fddt        j                   ffD ]  \  }}}t#        j$                  |j'                         |gz         \  }}	}
t)        j*                  ||	t(        j,                        }|sZt/        j0                  d|j3                         z         ||f| _         | j                  S  t        d      )Nr5   >   clang-clintel-clmsvc>   lld-linklinkr6   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foundrJ   coredatarH   idlinkerr   r3   r6   r5   r7   r	   
Popen_safeget_commandresearch	MULTILINEr   loggroup)rB   statefor_machinerescompcompargmatchrc_typepoems               r*   _find_resource_compilerz%WindowsModule._find_resource_compilerK   s    $((====  "//0A0A;PYZgmmo''(9(9(B(B(L(L[(YZDww::t{{t{{~~auOu)$t<))DA}} !KLL ;=Q=T=TU35I5L5LM13G3O3OP<>R>V>VW	&
 	Z!S% ))'*=*=*?3%*GHGAq!		%BLL1A81779DE!(' 2 }}	Z !!XYYr)   zwindows.compile_resourcesr   )varargsmin_varargsz0.47.0)sincer"   T)defaultlistifyc                   |d   j                         }|d   }|d   }|D ]  }t        |t        j                        s|j	                  t        j
                  dg dt        j                  j                  d| j                  j                  j                  |            g      g      z  } |j	                  |d         z  }| j                        \  }}	|	t        j                  k(  r
d}
|g d	z   }nZ|	t        j                  k(  r>d
}
|ddgz   }d}|D ]-  }d|v st!        j"                  |j%                  |      d       / n	d
}
|g dz   }g }dfd} |       D ]  \  }}}|j'                  dd      j'                  dd      j'                  dd      }|j'                  dd      j'                  dd      j'                  dd      }| d|
 }g }|j)                  |       |j+                  |       d }|	t        j                  k(  r| d}|j+                  g d       |j)                  t        j                  |j,                  j.                  j0                  ||g|g|||d              t3        ||g      S )Nr"   r   r     Fz@BUILD_ROOT@r!   res)z/nologoz/fo@OUTPUT@@INPUT@rh   rt   @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)rt   z-oru   c               3  ~  K   d   D ]  } t        | t              r0t        j                  j	                  j
                  |       | | f Dt        | t        j                        r | j                         | j                  | f ~t        | t        j                        rt        j                  ddj                  j                         | j!                          d| j"                  j%                         j'                  | j(                         d| j+                          | f #t-        | j%                               dkD  r-t        j                  ddj                  j                         t/        | j%                               D ](  \  }}| j!                          d| d| d| | |   f *  y w)	Nr   zBwindows.compile_resource CustomTargetIndex in positional argumentsz0.61.0)location_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outr"   r`   s      r*   	get_namesz2WindowsModule.compile_resources.<locals>.get_names   s    Aw dc3''',,u||S93CCX]]3++-syy#==U%<%<=))*npx*/*:*:UEWEWY "jjl^1SZZ-C-C-E-K-KCJJ-W,XY78H8H8J7KLcS S 3??,-1"--  /D.68H8HSXSeSeg"+COO,="> d3 "%as37QRSQTTUVYUZ5[]`ab]cccd!ds   F:F=/rz   \:z_@BASENAME@.z.d)z--preprocessor-arg=-MDz--preprocessor-arg=-MQ@OUTPUT@z--preprocessor-arg=-MF@DEPFILE@zCompiling Windows resource {})r0   r   extra_dependsdescription)returnzST.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, build.CustomTargetIndex]]])copyr|   r
   CustomTargetget_include_argsIncludeDirsr}   r~   r   rC   backendget_target_dirrk   r3   r6   r5   r   warningformatreplaceappendextendr   r   rT   r   )rB   r`   r"   kwargs
extra_argswrc_depend_fileswrc_dependsdrb   rescomp_typesuffixres_argsrj   rd   res_targetsr   namename_formattedr   r.   r1   r0   s    ``                   r*   r<   zWindowsModule.compile_resourcess   s    F^((*
!.1Y' 	A!U//0e44%%b"ebggll>SWScScSkSkSzSz{|S}6~5  A6  
	
 	e,,V4I-JKK
 $ < <U C/222 F!$IIH1999 F!Y
$;;HTA! =#:LL#e<= F!$AAH24	d, *3 	%D.#<<S)11$<DDS#ND+33C=EEdCPXXY\^abNv\&2F=?GNN7#NN8$'+G3;;;#HB-  C D u11  !!-);  !	< !{m<<r)   )rC   'Interpreter')rH   zT.Dict[str, 'Compiler']r   z
'Compiler')r`   'ModuleState'r   z.T.Tuple[ExternalProgram, ResourceCompilerType])r`   r   r"   zYT.Tuple[T.List[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex]]]r   z'CompileResources'r   r   )r$   r%   r&   r   INFOr>   rJ   rk   r   r-   r	   r   r
   r   r   r   r   evolver   r   r   r   listr<   __classcell__)rD   s   @r*   r9   r9   :   s    i DS&P /#x}}eN`N`bgbyby9z  IJ  K#X.
)&+D#6DQY= yY="4Y=9JY= KY=r)   r9   c                    t        |       S )N)r9   )interps    r*   
initializer      s      r)   )r   r   r   r9   )*
__future__r   enumr}   r[   typingTrr   r   r   r   r	   r
   r   interpreter.type_checkingr   r   r   interpreterbase.decoratorsr   r   r   r   r   r   r   programsr   TYPE_CHECKINGr   rH   r   rC   r   typing_extensionsr   r   r,   Enumr3   r9   r   r(   r)   r*   <module>r      s    #  	 	  *    X X o o 4 &??$)+9 79 7499 
Z=O Z=x!r)   