diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-03-24 16:23:10 -0600 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-04-06 20:27:06 +1000 |
commit | 239cdb53f4e994c8fd4afe1233e69b93ad632230 (patch) | |
tree | 5cd73c6fe5e79f34a9a37c12696ef492ba9b2894 /buildtools/wafsamba/samba_utils.py | |
parent | b2f01b54d21a464fa7fadb784b58909748f80ab3 (diff) | |
download | samba-239cdb53f4e994c8fd4afe1233e69b93ad632230.tar.gz samba-239cdb53f4e994c8fd4afe1233e69b93ad632230.tar.bz2 samba-239cdb53f4e994c8fd4afe1233e69b93ad632230.zip |
build: support variable expansion in source= arguments to build rules
This makes it much easier to follow the s3 approach to lists of
source files in the top level wscript
Pair-Programmed-With: Kai Blin <kai@samba.org>
Diffstat (limited to 'buildtools/wafsamba/samba_utils.py')
-rw-r--r-- | buildtools/wafsamba/samba_utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py index 814a5771a4..1b21d7308c 100644 --- a/buildtools/wafsamba/samba_utils.py +++ b/buildtools/wafsamba/samba_utils.py @@ -337,6 +337,40 @@ def SUBST_VARS_RECURSIVE(string, env): limit -= 1 return string +@conf +def EXPAND_VARIABLES(ctx, varstr, vars=None): + '''expand variables from a user supplied dictionary + + This is most useful when you pass vars=locals() to expand + all your local variables in strings + ''' + + if isinstance(varstr, list): + ret = [] + for s in varstr: + ret.append(EXPAND_VARIABLES(ctx, s, vars=vars)) + return ret + + import Environment + env = Environment.Environment() + ret = varstr + # substitute on user supplied dict if avaiilable + if vars is not None: + for v in vars.keys(): + env[v] = vars[v] + ret = SUBST_VARS_RECURSIVE(ret, env) + + # if anything left, subst on the environment as well + if ret.find('${'): + ret = SUBST_VARS_RECURSIVE(ret, ctx.env) + # make sure there is nothing left. Also check for the common + # typo of $( instead of ${ + if ret.find('${') != -1 or ret.find('$(') != -1: + print('Failed to substitute all variables in varstr=%s' % ret) + raise + return ret +Build.BuildContext.EXPAND_VARIABLES = EXPAND_VARIABLES + def RUN_COMMAND(cmd, env=None, |