o
    ld                      @  s  d dl mZ 	 d dlmZ d dlmZ d dlZd dl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 d dlmZ d dlmZ d d	lmZ d dlZejrTd dlZ	 d d
lmZ h dZh deB Zh dZdZdZ G dd deZ!dZ"d%ddZ#d&d'ddZ$d(d d!Z%d)d#d$Z&dS )*    )annotationsPath)EnumN)glob)buildmesonlibmlog)FORBIDDEN_TARGET_NAMES)detect_ninja)sameple_generator)create_meson_build>   z.Fz.fz.forz.F90z.f90>   .cu.d.cs.mm.c.rs.cpp.m.java.vala.cc>   cfortrancudavalaobjccppcsobjcpprustjavad
executablez0.1c                   @  s   e Zd ZdZdZdS )DEFAULT_TYPESr$   libraryN)__name__
__module____qualname__EXELIB r,   r,   ohome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/minit.pyr%   .   s    r%   zpSample project created. To build it run the
following commands:

meson setup builddir
meson compile -C builddir
options'argparse.Namespace'returnNonec                 C  sP   t | }| jtd jkr|  n| jtd jkr|  ntdtt dS )z
    Based on what arguments are passed we check for a match in language
    then check for project type and create new Meson samples project.
    r*   r+   zUnreachable codeN)	r   typer%   valueZcreate_executableZcreate_libraryRuntimeErrorprintINFO_MESSAGE)r.   Z
sample_genr,   r,   r-   create_sample:   s   

r7   Fsampleboolc                 C  s  | j s%t  j| _ td| j s|rtd| j  dtd| j  d | js5| j | _td| j d | jt	v rDt
d| jd|rHd	S | js{g }d
d t  D D ]}|jtv rc|| qW|sjtd|| _tdddd |D   dd | jD | _| js| jD ]p}|jdkrd| _ ne|jdv rd| _ n[|jdkrd| _ nQ|jdkrd| _ nG|jdkrd| _ n=|jtv rd| _ n3|jdkrd| _ n)|jdkrd | _ n|jd!krd"| _ n|jd#krd$| _ n|jd%krd&| _ nq| jstd'td(| j  d	S d	S ))z`
    Here we autodetect options for args not passed in so don't have to
    think about it.
    z[a-zA-Z_][a-zA-Z0-9]*zName of current directory "zM" is not usable as a sample project name.
Specify a project name with --name.zUsing "z." (name of current directory) as project name.z0" (project name) as name of executable to build.zExecutable name zI is reserved for Meson internal use. Refusing to init an invalid project.Nc                 s  s    | ]	}|  r|V  qd S N)is_file.0fr,   r,   r-   	<genexpr>^   s    z%autodetect_options.<locals>.<genexpr>zdNo recognizable source files found.
Run meson init in an empty directory to create a sample project.zDetected source files:  c                 s  s    | ]}t |V  qd S r:   )str)r=   sr,   r,   r-   r?   e   s    c                 S  s   g | ]}t |qS r,   r   r<   r,   r,   r-   
<listcomp>f   s    z&autodetect_options.<locals>.<listcomp>r   r   >   r   r   r   r   r   r   r   r   r#   r   r   r!   r   r   r   r    r   r"   r   r   z5Can't autodetect language, please specify it with -l.zDetected language: )namer   resolvestemrematch
SystemExitr5   r$   r
   r   ZMesonExceptionsrcfilesiterdirsuffixLANG_SUFFIXESappendjoinlanguageFORTRAN_SUFFIXES)r.   r8   rJ   r>   r,   r,   r-   autodetect_optionsH   s~   














rR   parser'argparse.ArgumentParser'c                 C  s   | j ddddd | j ddtjdd	 | j d
ddd | j dddd | j dddd | j ddttdd | j ddddd | j dddd  | j d!d"dd#d | j d$td%d&t d'd( | j d)td*t d  d+S ),z\
    Here we add args for that the user can passed when making a new
    Meson project.
    rJ   Z
sourcefile*z@source files. default: all recognized files in current directory)metavarnargshelp-Cwdz#directory to cd into before running)destactionrX   z-nz--namez0project name. default: name of current directory)rX   z-ez--executablez&executable name. default: project namez-dz--depszdependencies, comma-separatedz-lz
--languagez=project language. default: autodetected based on source files)choicesrX   z-bz--build
store_truezbuild after generation)r\   rX   z
--builddirr   zdirectory for build)defaultrX   z-fz--forcez2force overwrite of existing files and directories.z--type)r$   r&   zproject type. default: z based project)r_   r]   rX   z	--versionzproject version. default: N)add_argumentr   ZRealPathActionsortedLANG_SUPPORTEDDEFAULT_PROJECTDEFAULT_VERSION)rS   r,   r,   r-   add_arguments   s   re   intc                 C  sL  t | j std t| j tds+t| dd | j	s&t
d d| _	t|  nt|  t d r<| js<tdt|  | jrt | j rW| jrWt
d	 t| j t
d
 t d| jg }t|}|jrntt| j}td|jjt d}t!|}|rt"#t"$dd t% d| jg }t|}|jrtdS )z8
    Here we generate the new Meson sample project.
    zSProject source root directory not found. Run this command in source directory root.rU   T)r8   z.Defaulting to generating a C language project.r   zmeson.buildz5meson.build already exists. Use --force to overwrite.z,Build directory already exists, deleting it.zBuilding...setupr9   ZvsenvzINFO:z1automatically activated MSVC compiler environmentrY   r   )&r   rZ   existssysexitoschdirr   rR   rP   r5   r7   r;   forcerI   r   r   Zbuilddiris_dirshutilrmtreer   Zget_meson_command
subprocessrun
returncodeloadTcastenvironmentZcoredataZ
get_optionZ	OptionKeyZsetup_vsenvr	   logZgreenr   )r.   cmdretbZ
need_vsenvZvsenv_activer,   r,   r-   rr      s@   




rr   )r.   r/   r0   r1   )F)r.   r/   r8   r9   r0   r1   )rS   rT   r0   r1   )r.   r/   r0   rf   )'
__future__r   pathlibr   enumr   rq   ro   ri   rk   rG   r   Z
mesonbuildr   r   r	   Zmesonbuild.coredatar
   Zmesonbuild.environmentr   Z"mesonbuild.templates.samplefactoryr   typingru   TYPE_CHECKINGargparseZ#mesonbuild.templates.mesontemplatesr   rQ   rM   rb   rc   rd   r%   r6   r7   rR   re   rr   r,   r,   r,   r-   <module>   s<   

F