diff options
Diffstat (limited to 'src/engine/SCons/Defaults.py')
-rw-r--r-- | src/engine/SCons/Defaults.py | 104 |
1 files changed, 60 insertions, 44 deletions
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 3cd47ef..aebef39 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -40,6 +40,7 @@ import os import os.path import shutil import stat +import string import time import types import sys @@ -157,19 +158,34 @@ LdModuleLinkAction = SCons.Action.Action("$LDMODULECOM", "$LDMODULECOMSTR") # ways by creating ActionFactory instances. ActionFactory = SCons.Action.ActionFactory -def chmod_func(path, mode): - return os.chmod(str(path), mode) +def get_paths_str(dest): + # If dest is a list, we need to manually call str() on each element + if SCons.Util.is_List(dest): + elem_strs = [] + for element in dest: + elem_strs.append('"' + str(element) + '"') + return '[' + string.join(elem_strs, ', ') + ']' + else: + return '"' + str(dest) + '"' + +def chmod_func(dest, mode): + if not SCons.Util.is_List(dest): + dest = [dest] + for element in dest: + os.chmod(str(element), mode) + +def chmod_strfunc(dest, mode): + return 'Chmod(%s, 0%o)' % (get_paths_str(dest), mode) -Chmod = ActionFactory(chmod_func, - lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode)) +Chmod = ActionFactory(chmod_func, chmod_strfunc) def copy_func(dest, src): if SCons.Util.is_List(src) and os.path.isdir(dest): for file in src: - shutil.copy(file, dest) + shutil.copy2(file, dest) return 0 elif os.path.isfile(src): - return shutil.copy(src, dest) + return shutil.copy2(src, dest) else: return shutil.copytree(src, dest, 1) @@ -177,40 +193,53 @@ Copy = ActionFactory(copy_func, lambda dest, src: 'Copy("%s", "%s")' % (dest, src), convert=str) -def delete_func(entry, must_exist=0): - entry = str(entry) - if not must_exist and not os.path.exists(entry): - return None - if not os.path.exists(entry) or os.path.isfile(entry): - return os.unlink(entry) - else: - return shutil.rmtree(entry, 1) +def delete_func(dest, must_exist=0): + if not SCons.Util.is_List(dest): + dest = [dest] + for entry in dest: + entry = str(entry) + if not must_exist and not os.path.exists(entry): + continue + if not os.path.exists(entry) or os.path.isfile(entry): + os.unlink(entry) + continue + else: + shutil.rmtree(entry, 1) + continue -def delete_strfunc(entry, must_exist=0): - return 'Delete("%s")' % entry +def delete_strfunc(dest, must_exist=0): + return 'Delete(%s)' % get_paths_str(dest) Delete = ActionFactory(delete_func, delete_strfunc) -Mkdir = ActionFactory(os.makedirs, - lambda dir: 'Mkdir("%s")' % dir, - convert=str) +def mkdir_func(dest): + if not SCons.Util.is_List(dest): + dest = [dest] + for entry in dest: + os.makedirs(str(entry)) + +Mkdir = ActionFactory(mkdir_func, + lambda dir: 'Mkdir(%s)' % get_paths_str(dir)) Move = ActionFactory(lambda dest, src: os.rename(src, dest), lambda dest, src: 'Move("%s", "%s")' % (dest, src), convert=str) -def touch_func(file): - file = str(file) - mtime = int(time.time()) - if os.path.exists(file): - atime = os.path.getatime(file) - else: - open(file, 'w') - atime = mtime - return os.utime(file, (atime, mtime)) +def touch_func(dest): + if not SCons.Util.is_List(dest): + dest = [dest] + for file in dest: + file = str(file) + mtime = int(time.time()) + if os.path.exists(file): + atime = os.path.getatime(file) + else: + open(file, 'w') + atime = mtime + os.utime(file, (atime, mtime)) Touch = ActionFactory(touch_func, - lambda file: 'Touch("%s")' % file) + lambda file: 'Touch(%s)' % get_paths_str(file)) # Internal utility functions @@ -224,9 +253,6 @@ def _concat(prefix, list, suffix, env, f=lambda x: x, target=None, source=None): if not list: return list - if SCons.Util.is_List(list): - list = SCons.Util.flatten(list) - l = f(SCons.PathList.PathList(list).subst_path(env, target, source)) if not l is None: list = l @@ -292,18 +318,8 @@ def _stripixes(prefix, list, suffix, stripprefixes, stripsuffixes, env, c=None): else: c = _concat_ixes - if SCons.Util.is_List(list): - list = SCons.Util.flatten(list) - - if SCons.Util.is_List(stripprefixes): - stripprefixes = map(env.subst, SCons.Util.flatten(stripprefixes)) - else: - stripprefixes = [env.subst(stripprefixes)] - - if SCons.Util.is_List(stripsuffixes): - stripsuffixes = map(env.subst, SCons.Util.flatten(stripsuffixes)) - else: - stripsuffixes = [stripsuffixes] + stripprefixes = map(env.subst, SCons.Util.flatten(stripprefixes)) + stripsuffixes = map(env.subst, SCons.Util.flatten(stripsuffixes)) stripped = [] for l in SCons.PathList.PathList(list).subst_path(env, None, None): |