a
    ”$a¶.  ã                   @   s   d 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mZm	Z	m
Z
 e ¡ Zg Zg Zej ddej ¡ZG dd„ dejƒZG dd	„ d	e	j	ƒZdS )
z“
Support for waf command-line options

Provides default and command-line options, as well the command
that reads the ``options`` wscript function.
é    N)ÚLogsÚUtilsÚContextÚErrorsÚWAFLOCKz.lock-waf_%s_buildc                   @   s<   e Zd ZdZddd„Zdd„ Zdd„ Zdd
d„Zdd„ Zd	S )Ú
opt_parserz 
	Command-line options parser.
	Fc                 C   s@   t jj| dddtjtjtjf d t ¡ | j	_
|| _|| _d S )NZresolveFz
%s %s (%s))Zconflict_handlerZadd_help_optionÚversion)ÚoptparseÚOptionParserÚ__init__r   ÚWAFNAMEÚ
WAFVERSIONZWAFREVISIONr   Úget_term_colsÚ	formatterÚwidthÚctxÚallow_unknown)Úselfr   r   © r   úi/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/third_party/waf/waflib/Options.pyr   -   s    ÿzopt_parser.__init__c              
   C   sp   |rlzt j | |||¡ W q  t jt jfyh } z.| jrF| |j¡ n|  t	|ƒ¡ W Y d}~q d}~0 0 q dS )zY
		Custom _process_args to allow unknown options according to the allow_unknown status
		N)
r	   r
   Ú_process_argsÚBadOptionErrorZAmbiguousOptionErrorr   ÚappendÚopt_strÚerrorÚstr)r   ZlargsÚrargsÚvaluesÚer   r   r   r   4   s    zopt_parser._process_argsc                 C   sr   | j r^g | }ztj | ||¡ W qn tjyZ   |r@| ¡  q2| |¡ | d¡ ‚ Y qn0 ntj | ||¡ d S )Nr   )r   r	   r
   Ú_process_long_optr   ÚpopÚextend)r   r   r   Zbackr   r   r   r   A   s    



zopt_parser._process_long_optNc                 C   s
   |   |¡S ©N)Z
print_help)r   Úfiler   r   r   Úprint_usageP   s    zopt_parser.print_usagec                    sê   i }t jD ]6}|jr
|jdks
|j d¡r,q
|jp4d}|||j< q
t jr”t jj ¡ D ]>\}}|dv rfqTt|ƒtt j	ƒu rT|jrT| d¡sT|j||< qTd‰ |D ]}t
ˆ t|ƒƒ‰ qœ‡ fdd„| ¡ D ƒ}| ¡  d |¡}d	t jt j|f S )
zE
		Builds the message to print on ``waf --help``

		:rtype: string
		ÚoptionsÚ_Ú )r%   ÚinitÚshutdownr   c                    s"   g | ]\}}d |  ˆ ¡|f ‘qS )z  %s: %s)Úljust)Ú.0ÚkÚv©Zjustr   r   Ú
<listcomp>n   ó    z(opt_parser.get_usage.<locals>.<listcomp>Ú
zD%s [commands] [options]

Main commands (example: ./%s build -j4)
%s
)r   ÚclassesÚcmdÚ
startswithÚ__doc__Úg_moduleÚ__dict__ÚitemsÚtypeÚcreate_contextÚmaxÚlenÚsortÚjoinr   )r   Zcmds_strÚclsÚsr,   r-   ÚlstÚretr   r.   r   Ú	get_usageS   s,    


üzopt_parser.get_usage)F)N)	Ú__name__Ú
__module__Ú__qualname__r5   r   r   r   r$   rC   r   r   r   r   r   )   s   

r   c                       s‚   e Zd ZdZdZdZ‡ fdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
ddd„Zddd„Zdd„ Zdd„ Zddd„Z‡ fdd„Z‡  ZS )ÚOptionsContextz¯
	Collects custom options from wscript files and parses the command line.
	Sets the global :py:const:`waflib.Options.commands` and :py:const:`waflib.Options.options` values.
	r%   c           	   	      s  t t| ƒjf i |¤Ž t| ƒ| _i | _|  ¡ }| j}tj	 
dd¡rFdpHd}tj	 
dd¡dkrbd}ntj	 
dd¡dkrxd	}|d
dd|dddd |ddd|dd| d |ddddddd |ddd ddd!d |d"d#ddd$d |d%d&dd'tjd |d(d)dd'tjd |d*d+d,dd'd-d |  d.¡}|| jd/< |jd0d1ddd2d3d4 |jd5d6ddd7d8d4 |jd9d'tj	 
d:d¡tjd;d4 |jd<d'tj	 
d=d¡tjd>d4 |jd?d'tj	 
d@d¡tjdAd4 ttjdBtj	 
dC¡ƒ}|st ¡ dDkrt ¡ }|d  ¡ |dEd …  }ndF}|jdGdH|dI| dJ |jdKdLdLdM |jdNdOdOdM |  dP¡}|| jdQ< |jdRdSdTdddUd |jdVdWdddXd |  dY¡}|| jdZ< |jd[d\ddd]d tj	 
d^d¡}|  d_¡}|| jd`< |jdadb| |dcdd |jdedfdgdhd'did |jdjdkdld ddm d S )nNZNOCOLORr'   ÚnoÚautoZCLICOLORÚ0ZCLICOLOR_FORCEÚ1Úyesz-cz--colorÚcolorsÚstorez3whether to use colors (yes/no/auto) [default: auto])rL   rH   rI   )ÚdestÚdefaultÚactionÚhelpÚchoicesz-jz--jobsÚjobsÚintzamount of parallel jobs (%r))rO   rP   r9   rR   z-kz--keepZkeepr   Úcountz+continue despite errors (-kk to try harder))rO   rP   rQ   rR   z-vz	--verboseÚverbosez+verbosity level -v -vv or -vvv [default: 0]z--zonesÚzonesz,debugging zones (task_gen, deps, tasks, etc)z	--profileZprofileÚ
store_truez--pdbZpdbz-hz--helpZwhelpzshow this help message and exitzConfiguration optionszconfigure optionsz-oz--outzbuild dir for the projectÚout)rQ   rP   rR   rO   z-tz--topzsrc dir for the projectÚtopz--no-lock-in-runÚNO_LOCK_IN_RUNÚno_lock_in_runz--no-lock-in-outÚNO_LOCK_IN_OUTÚno_lock_in_outz--no-lock-in-topÚNO_LOCK_IN_TOPÚno_lock_in_topÚdefault_prefixÚPREFIXÚwin32é   z/usr/local/z--prefixÚprefixz!installation prefix [default: %r])rO   rP   rR   z--bindirÚbindir)rO   rR   z--libdirÚlibdirzBuild and installation optionszbuild and install optionsz-pz
--progressÚprogress_barz!-p: progress bar; -pp: ide outputz	--targetsÚtargetsz'task generators, e.g. "target1,target2"zStep optionszstep optionsz--filesÚfilesz:files to process, by regexp, e.g. "*/main.c,*/test/main.o"ZDESTDIRz'Installation and uninstallation optionszinstall/uninstall optionsz	--destdirzinstallation root [default: %r]Zdestdir)rR   rP   rO   z-fz--forceÚforceFzforce file installationz--distcheck-argsZARGSzarguments to pass to distcheck)ÚmetavarrR   rP   rQ   )ÚsuperrG   r   r   ÚparserÚoption_groupsrT   Ú
add_optionÚosÚenvironÚgetr	   ZSUPPRESS_HELPÚadd_option_groupÚgetattrr   r6   r   Úunversioned_sys_platformÚtempfileÚ
gettempdirÚupper)	r   ÚkwrT   ÚpÚcolorÚgrrb   ÚdZdefault_destdir©Ú	__class__r   r   r      s^    


   





zOptionsContext.__init__c                 C   sà   t tj dd¡ƒ}|dk rÂdtjv r8t tj dd¡ƒ}nŠttdƒrtdtjv r\t t d¡ƒ}ndtjv rtt t d¡ƒ}|sÂtjdvrÂz| jg d	¢dd
}W n t	j
y¬   Y n0 t d|¡rÂt |ƒ}|dk rÐd}n|dkrÜd}|S )a
  
		Finds the optimal amount of cpu cores to use for parallel jobs.
		At runtime the options can be obtained from :py:const:`waflib.Options.options` ::

			from waflib.Options import options
			njobs = options.jobs

		:return: the amount of cpu cores
		:rtype: int
		ZJOBSr   re   ZNUMBER_OF_PROCESSORSÚsysconf_namesÚSC_NPROCESSORS_ONLNÚSC_NPROCESSORS_CONF)ÚntÚjava)Zsysctlz-nzhw.ncpu)Úquietz^[0-9]+$i   )rU   rr   rs   rt   Úhasattrr‚   ÚsysconfÚnameZcmd_and_logr   ÚWafErrorÚreÚmatch)r   rV   Útmpr   r   r   rT   À   s*    



zOptionsContext.jobsc                 O   s   | j j|i |¤ŽS )zÍ
		Wraps ``optparse.add_option``::

			def options(ctx):
				ctx.add_option('-u', '--use', dest='use', default=False,
					action='store_true', help='a boolean option')

		:rtype: optparse option object
		)ro   rq   )r   r,   r{   r   r   r   rq   å   s    
zOptionsContext.add_optionc                 O   sJ   z| j |d  }W n$ ty6   | jj|i |¤Ž}Y n0 || j |d < |S )zè
		Wraps ``optparse.add_option_group``::

			def options(ctx):
				gr = ctx.add_option_group('some options')
				gr.add_option('-u', '--use', dest='use', default=False, action='store_true')

		:rtype: optparse option group object
		r   )rp   ÚKeyErrorro   ru   )r   r,   r{   r~   r   r   r   ru   ñ   s    
zOptionsContext.add_option_groupc                 C   sJ   z| j | W S  tyD   | jj D ]}|j|kr"|   Y S q"Y dS 0 dS )a  
		Wraps ``optparse.get_option_group``::

			def options(ctx):
				gr = ctx.get_option_group('configure options')
				gr.add_option('-o', '--out', action='store', default='',
					help='build dir for the project', dest='out')

		:rtype: optparse option group object
		N)rp   r   ro   Útitle)r   r   Úgroupr   r   r   Úget_option_group  s    
zOptionsContext.get_option_groupNc                 C   s@   |s
t j}tj |¡}tj ||¡}tj |¡}tj |¡}|S r"   )r   Ú
launch_dirrr   ÚpathÚ
expanduserr>   ÚnormpathÚabspath)r   r”   Úcwdr|   r   r   r   Úsanitize_path  s    zOptionsContext.sanitize_pathFc                 C   s¤   || j _| j j|d\}}g }g }|D ]*}d|v r>| |¡ q&|dkr&| |¡ q&|jdk rbd|_d ¡ D ].}	t||	dƒrj|  t||	ƒ|¡}
t||	|
ƒ qj|||fS )z
		Just parse the arguments
		)Úargsú=r%   re   z$top out destdir prefix bindir libdirN)	ro   r   Ú
parse_argsr   rT   Úsplitrv   r™   Úsetattr)r   Ú_argsr˜   r   r%   Zleftover_argsÚenvvarsÚcommandsÚargrŠ   r”   r   r   r   Úparse_cmd_args  s     
zOptionsContext.parse_cmd_argsc                 C   sl   t j ¡  td d …= td d …= t j |j¡ t |¡ t |¡ tD ]"}| dd¡\}}|tj	| 
¡ < qDd S )Nr›   re   )r%   r7   Úclearr¡   r    Úupdater!   r   rr   rs   Ústrip)r   Zarg_optionsZarg_commandsZarg_envvarsÚvarrŠ   Úvaluer   r   r   Úinit_module_vars5  s    




zOptionsContext.init_module_varsc                 C   s‚   |j t_ |j dkr|  d¡ ddddœ|j }t |¡ |jrZ|j d¡t_tj sldt_ ntj dkrldgt_tj dkr~dgt_d S )	Nre   Úerrchecké   r   )rL   rI   rH   ú,ZrunnerÚ*)rW   r   ÚloadrM   Úenable_colorsrX   r   )r   r%   r¡   r    rM   r   r   r   Ú	init_logsB  s    




zOptionsContext.init_logsc                 C   s.   |   ¡ \}}}|  |||¡ |  |||¡ dS )a  
		Parses arguments from a list which is not necessarily the command-line.
		Initializes the module variables options, commands and envvars
		If help is requested, prints it and exit the application

		:param _args: arguments
		:type _args: list of strings
		N)r£   r°   r©   )r   rŸ   r%   r¡   r    r   r   r   rœ   S  s    	zOptionsContext.parse_argsc                    s&   t t| ƒ ¡  |  ¡  t tj¡ dS )z3
		See :py:func:`waflib.Context.Context.execute`
		N)rn   rG   Úexecuterœ   r   Úalloc_process_poolr%   rT   )r   r€   r   r   r±   `  s    zOptionsContext.execute)N)NNF)N)rD   rE   rF   r5   r3   Úfunr   rT   rq   ru   r’   r™   r£   r©   r°   rœ   r±   Ú__classcell__r   r   r€   r   rG   y   s   ?%
	

rG   )r5   rr   rx   r	   ÚsysrŒ   Úwaflibr   r   r   r   ZValuesr%   r¡   r    rs   rt   ÚplatformÚlockfiler
   r   rG   r   r   r   r   Ú<module>   s   (P