a
    	$a                     @   s~   d dl Z d dlZd dl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 dd Zdd Zd	d
 Zdd ZdddZdS )    N)	ScriptingUtilsOptionsLogsErrors)	ConfigSetContext)LOCAL_CACHEc                 C   s"   |   }|rtd||f dS )zrun a single build taskzFailed to build %s: %uN)runr   WafError)tkret r   o/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/./buildtools/wafsamba/samba_wildcard.pyrun_task   s    r   c                 C   s  t dd}d}|jt }|j|j }tj| } tj	| r`tj
t| t } | dd dkr|| dd } |jjD ]}dD ]v}|jD ]j}t||g }|D ]T}	|	|}
|	|}t|
| st|| rddg|_t|  t||	 d}qqqq|std	|  dS )
zwrun a named build task, matching the cmd name using fnmatch
    wildcards against inputs and outputs of all build tasksFinfor      zbin/default/N)outputsinputsTz'Unable to find build target matching %s)fake_build_environmentrootfind_dirosgetcwdsrcnodeabspathpathnormpathislinkrelpathreadlinktask_managergroupstasksgetattrZrelpath_genfnmatchpositionprintdisplayr   r   r   )cmdbldfoundZcwd_nodeZtop_nodegattrr   sr   relpath1relpath2r   r   r   run_named_build_task   s2    






r3   c                  C   s   t jjsdS tdd} t| d}g }t jjdD ]d}tj|sN|	| q2t
|}|d}|d d|dd fD ]}||v r||	| q|q|q2d|t j_dS )	z)cope with the bin/ form of compile targetNFr   TARGET_TYPE,/)r   optionsZcompile_targetsr   r	   splitr   r   r    appendr"   join)r,   targetsZtlistr   linklistnamer   r   r   rewrite_compile_targets3   s     





rA   c                 C   s  t jdd t_t  tjrtjd}tj }|dkrDtj}n|dkrTtj	}nt
tj|d}|sr| | qt
tj|d tj }|dv rz|| W q ty   |  Y q0 n|| d}t jjsdt| }|d	kr|d
krtd||f  tjs|d
krtjd
 qdS )zthis replaces main from Scripting, allowing us to override the
       behaviour for unknown commands

       If a unknown command is found, then missing_cmd_fn() is called with
       the name of the requested command
       Nr   	configurebuildZ_context)initshutdowndist	distclean	distcheck z (%s)rD   rE   z%r finished successfully%s)r   Zarg_liner   commandsrA   popdatetimenowrB   rC   r&   r   g_moduler   	TypeErrorr9   progress_barZget_elapsed_timer   r   r;   )Zmissing_cmd_fnxZinifunctxelar   r   r   wildcard_mainJ   s6    
rU   TFc                 C   s   t tjdtj }t|}dtjd< dtjd< d|_zt		tj
}W n tyb   tdY n0 |  | rtd|j   |tjtjjd g |  |r|  |S )zbcreate all the tasks for the project, but do not run the build
    return the build context in useZbuild_contextFinstall	uninstallr   z2Project not configured (run 'waf configure' first)zWaf: Entering directory `%s')r&   r   rN   r   r   check_configuredr   rJ   
is_installr   lockfileIOErrorr   r   	load_envsr   r   bldnoder   Zadd_subdirsr   r   r:   	root_path	pre_buildflush)r   r`   r,   projr   r   r   r   }   s"    


r   )TF)r   rL   r'   waflibr   r   r   r   r   r   r   samba_utilsr	   r   r3   rA   rU   r   r   r   r   r   <module>   s   $3