mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-25 11:19:52 +01:00
Moved the command hashing logic into a utility function
This commit is contained in:
parent
c9d68d9ff0
commit
a6b467d73e
@ -81,11 +81,10 @@ class store_task_type(type):
|
||||
name = name.replace('_task', '')
|
||||
if name != 'evil' and name != 'TaskBase':
|
||||
global classes
|
||||
|
||||
if getattr(cls, 'run_str', None):
|
||||
# if a string is provided, convert it to a method
|
||||
(f, dvars) = compile_fun(cls.run_str, cls.shell)
|
||||
cls.hcode = str(cls.run_str)
|
||||
cls.hcode = Utils.h_cmd(cls.run_str)
|
||||
cls.orig_run_str = cls.run_str
|
||||
# change the name of run_str or it is impossible to subclass with a function
|
||||
cls.run_str = None
|
||||
@ -94,10 +93,7 @@ class store_task_type(type):
|
||||
cls.vars.sort()
|
||||
elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
|
||||
# getattr(cls, 'hcode') would look in the upper classes
|
||||
cls.hcode = Utils.h_fun(cls.run)
|
||||
|
||||
if sys.hexversion > 0x3000000:
|
||||
cls.hcode = cls.hcode.encode('iso8859-1', 'xmlcharrefreplace')
|
||||
cls.hcode = Utils.h_cmd(cls.run)
|
||||
|
||||
# be creative
|
||||
getattr(cls, 'register', classes)[name] = cls
|
||||
|
@ -441,6 +441,7 @@ def check_dir(path):
|
||||
def check_exe(name, env=None):
|
||||
"""
|
||||
Ensure that a program exists
|
||||
|
||||
:type name: string
|
||||
:param name: name or path to program
|
||||
:return: path of the program or None
|
||||
@ -523,6 +524,25 @@ def h_fun(fun):
|
||||
pass
|
||||
return h
|
||||
|
||||
def h_cmd(ins):
|
||||
"""
|
||||
Task command hashes are calculated by calling this function. The inputs can be
|
||||
strings, functions, tuples/lists containing strings/functions
|
||||
"""
|
||||
# this function is not meant to be particularly fast
|
||||
if isinstance(ins, str):
|
||||
# a command is either a string
|
||||
ret = ins
|
||||
elif isinstance(ins, list) or isinstance(ins, tuple):
|
||||
# or a list of functions/strings
|
||||
ret = str([h_cmd(x) for x in ins])
|
||||
else:
|
||||
# or just a python function
|
||||
ret = str(h_fun(ins))
|
||||
if sys.hexversion > 0x3000000:
|
||||
ret = ret.encode('iso8859-1', 'xmlcharrefreplace')
|
||||
return ret
|
||||
|
||||
reg_subst = re.compile(r"(\\\\)|(\$\$)|\$\{([^}]+)\}")
|
||||
def subst_vars(expr, params):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user