o
    e.                     @  s   U d dl mZ d dlZd dlZd dlZddlmZ ddl	m
Z
mZmZ ejr>ddlmZ ddlmZ dd	lmZ dd
lmZ g g g dgdgdgdgdZded< G dd de
ZdS )    )annotationsN   )EnvironmentException   )Compilerswift_buildtype_argsclike_debug_args)MachineInfo)Environment)DynamicLinker)MachineChoicez-O)plain0g123szT.Dict[str, T.List[str]]swift_optimization_argsc                      s   e Zd ZdgZdZdZ		dLdM fddZdNddZdOddZdPddZ	dQdd Z
dRd!d"ZdSd$d%ZdTd'd(ZdUd*d+ZdVd-d.ZdOd/d0ZdWd2d3ZdOd4d5ZdXd8d9ZdOd:d;ZdYd>d?ZdZdDdEZd[dGdHZd\dJdKZ  ZS )]SwiftCompilerz-XlinkerZswiftZllvmNexelistT.List[str]versionstrfor_machiner   is_crossboolinfo'MachineInfo'full_versionT.Optional[str]linkerT.Optional['DynamicLinker']c              
     s&   t  jg |||||||d || _d S )N)r   r   r!   )super__init__r   )selfr   r   r   r   r   r   r!   	__class__ ?/usr/lib/python3.10/site-packages/mesonbuild/compilers/swift.pyr$   -   s
   
zSwiftCompiler.__init__returnc                 C     dS )NTr(   r%   r(   r(   r)   needs_static_linker5      z!SwiftCompiler.needs_static_linkerc                 C     dgS )Nz--fatal-warningsr(   r,   r(   r(   r)   get_werror_args8      zSwiftCompiler.get_werror_args	outtargetoutfilec                 C  r/   )Nz-emit-dependenciesr(   )r%   r2   r3   r(   r(   r)   get_dependency_gen_args;   r1   z%SwiftCompiler.get_dependency_gen_argsobjfilec                 C  s   t j|d d |   S )Nr   .)ospathsplitextget_depfile_suffix)r%   r5   r(   r(   r)   depfile_for_object>   s   z SwiftCompiler.depfile_for_objectc                 C  r+   )Ndr(   r,   r(   r(   r)   r:   A   r.   z SwiftCompiler.get_depfile_suffixtargetc                 C     d|gS )N-or(   )r%   r=   r(   r(   r)   get_output_argsD      zSwiftCompiler.get_output_args
headernamec                 C  r>   )Nz-import-objc-headerr(   )r%   rB   r(   r(   r)   get_header_import_argsG   rA   z$SwiftCompiler.get_header_import_argslevelc                 C  s   g S Nr(   )r%   rD   r(   r(   r)   get_warn_argsJ   r.   zSwiftCompiler.get_warn_args	buildtypec                 C     t | S rE   )r   )r%   rG   r(   r(   r)   get_buildtype_argsM   rA   z SwiftCompiler.get_buildtype_argsc                 C  r/   )N-emit-executabler(   r,   r(   r(   r)   get_std_exe_link_argsP   r1   z#SwiftCompiler.get_std_exe_link_argsmodnamec                 C  r>   )Nz-module-namer(   )r%   rL   r(   r(   r)   get_module_argsS   rA   zSwiftCompiler.get_module_argsc                 C  r/   )Nz-emit-moduler(   r,   r(   r(   r)   get_mod_gen_argsV   r1   zSwiftCompiler.get_mod_gen_argsr8   	is_systemc                 C  s
   d| gS )N-Ir(   )r%   r8   rO   r(   r(   r)   get_include_argsY   s   
zSwiftCompiler.get_include_argsc                 C  r/   )Nz-cr(   r,   r(   r(   r)   get_compile_only_args\   r1   z#SwiftCompiler.get_compile_only_argsparameter_list	build_dirc              
   C  sd   t |D ]+\}}|d d dks|d d dkr/|d d tjtj||dd   ||< q|S )Nr   rP   z-L)	enumerater7   r8   normpathjoin)r%   rS   rT   idxir(   r(   r)   &compute_parameters_with_absolute_paths_   s
    .z4SwiftCompiler.compute_parameters_with_absolute_pathswork_direnvironment'Environment'Nonec           	      C  s
  d}t j||}t j|d}g }||j| j| j7 }| jr'||  7 }n||j	| j| j7 }t
|ddd}|d W d    n1 sIw   Y  tj| j| dd||g |d	}|  |jd
krotd|   | jrtd S t|d
krtd|   d S )Nzswifttest.swiftZ	swifttestwzutf-8)encodingz'print("Swift compilation is working.")
rJ   r?   )cwdr   z*Swift compiler %s cannot compile programs.z:Executables created by Swift compiler %s are not runnable.)r7   r8   rW   ZcoredataZget_external_argsr   languager   rR   Zget_external_link_argsopenwrite
subprocessPopenr   wait
returncoder   Zname_stringcall)	r%   r[   r\   srcZsource_nameZoutput_nameextra_flagsZofileZpcr(   r(   r)   sanity_checkg   s(    
zSwiftCompiler.sanity_checkis_debugc                 C  rH   rE   )r   )r%   rm   r(   r(   r)   get_debug_args~   rA   zSwiftCompiler.get_debug_argsoptimization_levelc                 C  rH   rE   )r   )r%   ro   r(   r(   r)   get_optimization_args   rA   z#SwiftCompiler.get_optimization_args)NN)r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   )r*   r   )r*   r   )r2   r   r3   r   r*   r   )r5   r   r*   r    )r*   r   )r=   r   r*   r   )rB   r   r*   r   )rD   r   r*   r   )rG   r   r*   r   )rL   r   r*   r   )r8   r   rO   r   r*   r   )rS   r   rT   r   r*   r   )r[   r   r\   r]   r*   r^   )rm   r   r*   r   )ro   r   r*   r   )__name__
__module____qualname__ZLINKER_PREFIXrb   idr$   r-   r0   r4   r;   r:   r@   rC   rF   rI   rK   rM   rN   rQ   rR   rZ   rl   rn   rp   __classcell__r(   r(   r&   r)   r   '   s2    
















r   )
__future__r   re   os.pathr7   typingTZmesonlibr   	compilersr   r   r   TYPE_CHECKINGZ	envconfigr	   r\   r
   Zlinkers.linkersr   r   r   __annotations__r   r(   r(   r(   r)   <module>   s&   
