a
    ”$aÿJ  ã                   @   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ZddlZddlm	Z	m
Z
mZmZmZmZmZ dZdZdZG dd„ dejƒZd	d
„ Zeddd„ƒZedd„ ƒZed dd„ƒZeg fdd„ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )!a$  
Configuration system

A :py:class:`waflib.Configure.ConfigurationContext` instance is created when ``waf configure`` is called, it is used to:

* create data dictionaries (ConfigSet instances)
* store the list of modules to import
* hold configuration routines such as ``find_program``, etc
é    N)Ú	ConfigSetÚUtilsÚOptionsÚLogsÚContextÚBuildÚErrorsz
config.logFz}# project %(app)s configured on %(now)s by
# waf %(wafver)s (abi %(abi)s, python %(pyver)x on %(systype)s)
# using %(args)s
#c                       sŽ   e Zd ZdZdZg Z‡ fdd„Zddd„Zdd	„ Zd
d„ Z	e
ee	ƒZdd„ Z‡ fdd„Zdd„ Zdd„ Zddd„Z‡ fdd„Zdd„ Z‡  ZS )ÚConfigurationContextzconfigures the projectÚ	configurec                    sZ   t t| ƒjf i |¤Ž ttjƒ| _i | _d | _d | _g | _	d| _
g | _g | _|  d¡ d S )Nr   Ú )Úsuperr	   Ú__init__ÚdictÚosÚenvironÚall_envsÚtop_dirÚout_dirÚtoolsÚhashÚfilesÚ
tool_cacheÚsetenv)ÚselfÚkw©Ú	__class__© úk/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/third_party/waf/waflib/Configure.pyr   '   s    zConfigurationContext.__init__Nc                 C   sB   || j vs|r8|s&t ¡ }|  |¡ n| ¡ }|| j |< || _dS )a–  
		Set a new config set for conf.env. If a config set of that name already exists,
		recall it without modification.

		The name is the filename prefix to save to ``c4che/NAME_cache.py``, and it
		is also used as *variants* by the build commands.
		Though related to variants, whatever kind of data may be stored in the config set::

			def configure(cfg):
				cfg.env.ONE = 1
				cfg.setenv('foo')
				cfg.env.ONE = 2

			def build(bld):
				2 == bld.env_of_name('foo').ONE

		:param name: name of the configuration set
		:type name: string
		:param env: ConfigSet to copy, or an empty ConfigSet is created
		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		N)r   r   Úprepare_envÚderiveÚvariant)r   ÚnameÚenvr   r   r   r   8   s    
zConfigurationContext.setenvc                 C   s   | j | j S )zGetter for the env property©r   r!   )r   r   r   r   Úget_envW   s    zConfigurationContext.get_envc                 C   s   || j | j< dS )zSetter for the env propertyNr$   )r   Úvalr   r   r   Úset_envZ   s    zConfigurationContext.set_envc                 C   s  | j }|stjj}|s&ttjtjdƒ}|s4| j 	¡ }t
j 	|¡}t
j |¡rR| jpV| j |¡| _| jsjJ ‚| j}|s|tjj}|sttjtjdƒ}|s°tj dtj d¡ dd¡}t
j |¡}t
j |¡rÎ| jpÒ| j |¡| _| j ¡  t
j | j 	¡ ¡s|  d| j 	¡  ¡ dS )z>
		Initialize the project directory and the build directory
		Nz.lock-waf_%s_r   z	.lock-wafz'Could not create the build directory %s)r   r   ÚoptionsÚtopÚgetattrr   Úg_moduleZTOPÚpathÚabspathr   ÚisabsÚrootÚfind_dirÚsrcnoder   ÚoutZOUTÚlockfileÚreplaceÚsysÚplatformÚrealpathÚ	make_nodeÚbldnodeÚmkdirÚisdirÚfatal)r   r)   r2   r   r   r   Ú	init_dirs`   s,    
 
 
zConfigurationContext.init_dirsc                    sh  |   ¡  | j tj¡| _| j ¡  tj 	| j 
¡ t¡}t |d¡| _ttjddƒ}|rtttjddƒ}|rtd||f }t ¡ tjtjd 	tj¡tjtj|dœ}|  t| ¡ |  d| j 
¡ ¡ |  d	| j 
¡ ¡ t| jƒt| jƒkrît d
¡ n0t| jƒt| jƒkr| j  | j¡rt d¡ t!t"| ƒ #¡  |  $¡  | j 
¡ t_%| j 
¡ t_&t' '¡ }tj|_t(j)j*|_)| j+|_,tj-|_-tj%|_%tj&|_&| j.|_.| j/|_/t0| j1ƒ|_1tj2|_2| j3j4sè|j1 5d¡sètt(j)dƒsè| $tj 	tj-t(j6¡¡ | j3j7s&|j1 5d¡s&tt(j)dƒs&| $tj 	tj%t(j6¡¡ | j3j8sd|j1 5d¡sdtt(j)dƒsd| $tj 	tj&t(j6¡¡ dS )z3
		See :py:func:`waflib.Context.Context.execute`
		ZcfgZAPPNAMEr   ÚVERSIONz%s (%s)ú )ÚnowZpyverZsystypeÚargsZwafverZabiÚappzSetting top tozSetting out tozSetting top == outz5Are you certain that you do not want to set top="." ?ÚNO_LOCK_IN_RUNZno_lock_in_runÚNO_LOCK_IN_TOPZno_lock_in_topÚNO_LOCK_IN_OUTZno_lock_in_outN)9r=   r9   r8   r   Z	CACHE_DIRÚcachedirr:   r   r,   Újoinr-   ÚWAF_CONFIG_LOGr   Úmake_loggerÚloggerr*   r   r+   ÚtimeÚctimer5   Ú
hexversionr6   ÚargvZ
WAFVERSIONZABIÚto_logÚconf_templateÚmsgr1   ÚidÚwarnÚis_child_ofr   r	   ÚexecuteÚstorer   r   r   r   r(   Ú__dict__ÚcmdZ
config_cmdZrun_dirr   r   r   r   Z
launch_dirr#   rC   Úgetr3   rD   rE   )r   r,   rB   ÚverÚparamsr#   r   r   r   rU   ‚   sP    
(

&&&zConfigurationContext.executec                 C   s‚   |j s&tjjstjr tjj|_ nd|_ |jsNtjjr@tjj|_nt d|¡|_|j	s~tjj
rhtjj
|_	nt dt ¡  |¡|_	dS )z¥
		Insert *PREFIX*, *BINDIR* and *LIBDIR* values into ``env``

		:type env: :py:class:`waflib.ConfigSet.ConfigSet`
		:param env: a ConfigSet, usually ``conf.env``
		ú/z${PREFIX}/binz${PREFIX}/lib%sN)ZPREFIXr   r(   Úprefixr   Úis_win32ZBINDIRZbindirÚ
subst_varsÚLIBDIRÚlibdirÚlib64)r   r#   r   r   r   r   À   s    z ConfigurationContext.prepare_envc                 C   sl   | j  d¡}| dtj| jf ¡ | js2|  d¡ | jD ].}| j| }| t	j
 | j  ¡ |tj ¡¡ q8dS )z+Save the config results into the cache filezbuild.config.pyzversion = 0x%x
tools = %r
z.nothing to store in the configuration context!N)rF   r8   Úwriter   Ú
HEXVERSIONr   r   r<   rV   r   r,   rG   r-   r   ZCACHE_SUFFIX)r   ÚnÚkeyZtmpenvr   r   r   rV   ×   s    


zConfigurationContext.storeTFc                 C   sn  t  |¡}|rt  |¡}|D ]J}|r^|t| jƒ||f}|| jv rR|  d| ¡ q| j |¡ d}	ztj||| |d}	W nŠ t	yº }
 z*|  
d|t|
dtjƒ|
f ¡ W Y d}
~
nRd}
~
0  ty }
 z0|  d|||f ¡ |  t ¡ ¡ ‚ W Y d}
~
n
d}
~
0 0 |dur|  |¡ n:t|	ddƒ}|rTt|ƒtt jƒu rJ|| ƒ n
|  |¡ | j |||dœ¡ qdS )	aƒ  
		Load Waf tools, which will be imported whenever a build is started.

		:param tool_list: waf tools to import
		:type tool_list: list of string
		:param tooldir: paths for the imports
		:type tooldir: list of string
		:param funs: functions to execute from the waf tools
		:type funs: list of string
		:param cache: whether to prevent the tool from running twice
		:type cache: bool
		z%(tool %s is already loaded, skipping)N)ÚctxÚwith_sys_pathz)Could not load the Waf tool %r from %r
%sZwaf_sys_pathzimp %r (%r & %r)r
   )ÚtoolÚtooldirÚfuns)r   Úto_listrR   r#   r   rO   Úappendr   Z	load_toolÚImportErrorr<   r*   r5   r,   Ú	ExceptionÚ	tracebackÚ
format_excÚ
eval_rulesÚtypeÚreadfr   )r   Z	tool_listrj   rk   rh   Úcacher   ri   ZmagÚmoduleÚeÚfuncr   r   r   Úloadã   s6    



2


zConfigurationContext.loadc                    s<   t t| ƒ |¡ t | j| d¡f¡| _| j | 	¡ ¡ dS )z®
		Records the path and a hash of the scripts visited, see :py:meth:`waflib.Context.Context.post_recurse`

		:param node: script
		:type node: :py:class:`waflib.Node.Node`
		ÚrbN)
r   r	   Úpost_recurser   Úh_listr   Úreadr   rm   r-   )r   Únoder   r   r   r{     s    z!ConfigurationContext.post_recursec                 C   s>   t  |¡| _| jD ]&}t| |ƒ}|s2|  d| ¡ |ƒ  qdS )z˜
		Execute configuration tests provided as list of functions to run

		:param rules: list of configuration method names
		:type rules: list of string
		z!No such configuration function %rN)r   rl   Úrulesr*   r<   )r   r   ÚxÚfr   r   r   rr      s    

zConfigurationContext.eval_rules)N)NNTF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rX   Zerror_handlersr   r   r%   r'   Úpropertyr#   r=   rU   r   rV   ry   r{   rr   Ú__classcell__r   r   r   r   r	      s   

">
2r	   c                    s6   ‡ fdd„}ˆ j |_ ttˆ j |ƒ ttjˆ j |ƒ ˆ S )ah  
	Decorator: attach new configuration functions to :py:class:`waflib.Build.BuildContext` and
	:py:class:`waflib.Configure.ConfigurationContext`. The methods bound will accept a parameter
	named 'mandatory' to disable the configuration errors::

		def configure(conf):
			conf.find_program('abc', mandatory=False)

	:param f: method to bind
	:type f: function
	c                     s<   |  dd¡}zˆ | i |¤ŽW S  tjy6   |r2‚ Y n0 d S )NÚ	mandatoryT)Úpopr   ÚConfigurationError)Úkr   rˆ   ©r   r   r   Úfun:  s    zconf.<locals>.fun)r‚   Úsetattrr	   r   ZBuildContext)r   r   r   rŒ   r   Úconf.  s
    r   c                 C   sh   zt  | j| ¡}W n ty(   Y dS 0 |sRd |¡d t | j|pH| ¡¡vrd| j |p^||¡ dS )a@  
	Import operating system environment values into ``conf.env`` dict::

		def configure(conf):
			conf.add_os_flags('CFLAGS')

	:param var: variable to use
	:type var: string
	:param dest: destination variable, by default the same as var
	:type dest: string
	:param dup: add the same set of flags again
	:type dup: bool
	Nr   )	ÚshlexÚsplitr   ÚKeyErrorrG   r   rl   r#   Úappend_value)r   ÚvarÚdestÚdupÚflagsr   r   r   Úadd_os_flagsG  s    (r˜   c                 C   sb   t |tƒr^tj |¡r|gS tjdkr0t |¡S ztj|ddW S  ty\   t |¡ Y S 0 |S )z˜
	Detect if a command is written in pseudo shell like ``ccache g++`` and return a list.

	:param cmd: command
	:type cmd: a string or a list of string
	r\   F)Úposix)	Ú
isinstanceÚstrr   r,   ÚisfileÚsepr   r‘   Ú	TypeError)r   rX   r   r   r   Úcmd_to_list]  s    


rŸ   ú1.9.99ú2.1.0c                 K   sˆ   | j dt|ƒt|ƒf fi |¤Ž tj}t |¡|krN|  dt |¡|f ¡ t |¡|k rt|  dt |¡|f ¡ | jdi |¤Ž dS )a.  
	Raise a Configuration error if the Waf version does not strictly match the given bounds::

		conf.check_waf_version(mini='1.9.99', maxi='2.1.0')

	:type  mini: number, tuple or string
	:param mini: Minimum required version
	:type  maxi: number, tuple or string
	:param maxi: Maximum allowed version
	z!Checking for waf version in %s-%sz,waf version should be at least %r (%r found)z+waf version should be at most %r (%r found)ÚokN)r¢   )Ú	start_msgr›   r   rd   r   Únum2verr<   Úend_msg)r   ZminiÚmaxir   rZ   r   r   r   Úcheck_waf_versions  s    "r§   c                 C   s`   t  |¡D ]B}t  |¡D ]2}tj tj ||¡¡}tj |¡r|    S qq
|  d| ¡ dS )zÕ
	Find a file in a list of paths

	:param filename: name of the file to search for
	:param path_list: list of directories to search
	:return: the first matching filename; else a configuration exception is raised
	zCould not find %rN)r   rl   r   r,   Ú
expanduserrG   Úexistsr<   )r   ÚfilenameÚ	path_listre   ÚdÚpr   r   r   Ú	find_file‡  s    	r®   c                 K   s0  |  dtjrdpd¡}|  dt| dtjƒ¡}d}t |¡}|  dd |¡¡}|  dd¡}|srt 	d	d
|d  
¡ ¡}|  dd¡}|rŽt |¡}n|  dd¡ tj¡}|  d¡r¼|  |d ¡}n–|  |¡rÖ|  || ¡}n|| j| rò|  | j| ¡}n`|s|  || d¡|¡}|s*tjr*t tjj|¡}|sHtjrHt tjj|¡}|  |¡}|rvt|ƒdkrp|d }	n|}	nd}	| jd| |	fi |¤Ž |  d¡s´|  d||||f ¡ |sÖ|  |  dd¡pÒd| ¡ |  d¡}
|
du rtj|d |ds|  d| ¡ || j|< n| j|
 | | j|< |S )a…  
	Search for a program on the operating system

	When var is used, you may set os.environ[var] to help find a specific program version, for example::

		$ CC='ccache gcc' waf configure

	:param path_list: paths to use for searching
	:type param_list: list of string
	:param var: store the result to conf.env[var] where var defaults to filename.upper() if not provided; the result is stored as a list of strings
	:type var: string
	:param value: obtain the program from the value passed exclusively
	:type value: list or string (list is preferred)
	:param exts: list of extensions for the binary (do not add an extension for portability)
	:type exts: list of string
	:param msg: name to display in the log, by default filename is used
	:type msg: string
	:param interpreter: interpreter for the program
	:type interpreter: ConfigSet variable key
	:raises: :py:class:`waflib.Errors.ConfigurationError`
	Úextsz.exe,.com,.bat,.cmdz,.sh,.pl,.pyr   r   rQ   z, r”   z[-.]Ú_r   r«   ÚPATHÚvalueú,é   FzChecking for program %rÚquietz%find program=%r paths=%r var=%r -> %rÚerrmsgzCould not find the program %rÚinterpreterN)r#   zProgram %r is not executable)rY   r   r^   r*   r   r   rl   rG   ÚreÚsubÚupperr‘   ÚpathseprŸ   r#   Úfind_binaryÚwinregÚget_registry_app_pathÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEÚlenrQ   rO   r<   Ú	check_exe)r   rª   r   r¯   r   ÚretrQ   r”   r«   Zretmsgr·   r   r   r   Úfind_program—  sT    







rÄ   c           	   	   C   s‚   |D ]x}|D ]n}|| }t j |¡r>t j |¡rz|    S q|D ]6}t j t j ||¡¡}t j |¡rB|      S qBqqd S ©N)r   r,   r.   rœ   r¨   rG   )	r   Ú	filenamesr¯   Úpathsr   ÚextZexe_namer,   r€   r   r   r   r¼   í  s    r¼   c                 O   sÜ  g }t | ¡ ƒD ]F}|| }t|tjƒr,qqt|dƒrH| t |¡¡ q| t|ƒ¡ qt 	|¡}| j
 ¡ tj tj r|dp~d d t |¡ }| dttjddƒ¡}|sÀtj |¡rÀt |¡ zt |¡ W n tyà   Y n0 zt |¡ W n" ty   |  d| ¡ Y n0 |dkrzzt tj |d	¡¡}	W n tyJ   Y n00 |	d	 }
t|
tƒrv|
 d
¡rv|  |
¡ |
S tj |d¡}tj |¡s t |¡ | d¡p¶t| ddƒ}tj |||d | _!}| "¡  d|_#d|_$| j%|_%|j& '| j&¡ |d |_(||_)| |_*|d |ƒ d}
z€z| +¡  W n, t,j-yX   dt. /¡  }
|  |
¡ Y n0 t|ddƒ}
W |r”t ¡ }	|
|	d	< |	 0tj |d	¡¡ n
t |¡ n8|rÌt ¡ }	|
|	d	< |	 0tj |d	¡¡ n
t |¡ 0 |
S )aq  
	Create a temporary build context to execute a build. A temporary reference to that build
	context is kept on self.test_bld for debugging purposes.
	The arguments to this function are passed to a single task generator for that build.
	Only three parameters are mandatory:

	:param features: features to pass to a task generator created in the build
	:type features: list of string
	:param compile_filename: file to create for the compilation (default: *test.c*)
	:type compile_filename: string
	:param code: input file contents
	:type code: string

	Though this function returns *0* by default, the build may bind attribute named *retval* on the
	build context object to return a particular value. See :py:func:`waflib.Tools.c_config.test_exec_fun` for example.

	The temporary builds creates a temporary folder; the name of that folder is calculated
	by hashing input arguments to this function, with the exception of :py:class:`waflib.ConfigSet.ConfigSet`
	objects which are used for both reading and writing values.

	This function also features a cache which is disabled by default; that cache relies
	on the hash value calculated as indicated above::

		def options(opt):
			opt.add_option('--confcache', dest='confcache', default=0,
				action='count', help='Use a configuration cache')

	And execute the configuration with the following command-line::

		$ waf configure --confcache

	Ú__call__Ú.r   Zconf_check_Z	confcacheNz+cannot use the configuration test folder %rr´   Zcache_run_buildzTest does not buildZ	testbuildZrun_build_clsÚbuild)r   r   r   Ú*r#   Z	build_funéÿÿÿÿzTest does not build: %sZretval)1ÚsortedÚkeysrš   r   Úhasattrrm   r   Úh_funr›   r|   r9   r-   r   r   r^   Úto_hexrY   r*   r   r(   r,   r©   ÚshutilÚrmtreeÚmakedirsÚOSErrorÚstatr<   rG   ÚEnvironmentErrorÚ
startswithr   Zcreate_contextZtest_bldr=   Úprogress_barÚtargetsrJ   r   Úupdater#   r   r   Úcompiler   ÚWafErrorrp   rq   rV   )r   r‹   r   Úbufrf   ÚvÚhÚdirZ	cachemodeZprojrÃ   ZbdirÚcls_nameÚbldr   r   r   Ú	run_buildü  s~    "

.




úrå   c                 C   s   t |tƒr|S ||ƒS rÅ   )rš   r›   )r   rQ   rA   r   r   r   Úret_msgj  s    
ræ   c                 O   s  d|vr| j  ¡ |d< | d¡r,|d |ƒ | j|d fi |¤Ž d }z| j|i |¤Ž}W nF | jjy    | j|d dfi |¤Ž tj	dkr’‚ n
|  
d¡ Y n
0 ||d< | d	¡rÀ|d	 |ƒ}|rì| j|d dfi |¤Ž |  
d
| ¡ n| j|  |d |¡fi |¤Ž |S )Nr#   ÚvalidaterQ   r¶   ÚYELLOWr´   zThe configuration failedZsuccessZ
post_checkzThe configuration failed %rZokmsg)r#   r    rY   r£   rå   ÚerrorsrŠ   r¥   r   Úverboser<   ræ   )r   r‹   r   rÃ   r   r   r   Útestp  s*    


rë   )NF)r    r¡   )r…   r   r¸   r   rÓ   r5   rK   rp   Úwaflibr   r   r   r   r   r   r   rH   Z
autoconfigrP   r	   r   r˜   rŸ   r§   r®   rÄ   r¼   rå   ræ   rë   r   r   r   r   Ú<module>   s6   
8$  

U

m
