From a6b467d73e7f8342c8fed63750a5a7a94dea338d Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sat, 3 Oct 2015 09:12:08 +0200 Subject: [PATCH] Moved the command hashing logic into a utility function --- waflib/Task.py | 8 ++------ waflib/Utils.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/waflib/Task.py b/waflib/Task.py index 74b187ca..05141a0e 100644 --- a/waflib/Task.py +++ b/waflib/Task.py @@ -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 diff --git a/waflib/Utils.py b/waflib/Utils.py index 25f91c70..78bcdd9b 100644 --- a/waflib/Utils.py +++ b/waflib/Utils.py @@ -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): """