From 239cdb53f4e994c8fd4afe1233e69b93ad632230 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 Mar 2010 16:23:10 -0600 Subject: 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 --- buildtools/wafsamba/samba_python.py | 3 +++ buildtools/wafsamba/samba_utils.py | 34 ++++++++++++++++++++++++++++++++++ buildtools/wafsamba/wafsamba.py | 17 +++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'buildtools/wafsamba') diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index 7536250d0d..9a887a80a5 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -14,6 +14,7 @@ def SAMBA_PYTHON(bld, name, includes='', init_function_sentinal=None, local_include=True, + vars=None, enabled=True): '''build a python extension for Samba''' @@ -22,6 +23,8 @@ def SAMBA_PYTHON(bld, name, if init_function_sentinal is not None: cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinal + source = bld.EXPAND_VARIABLES(source, vars=vars) + if realname is None: # a SAMBA_PYTHON target without a realname is just a # subsystem with needs_python=True 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, diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 9e7c39581b..ad104a2e89 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -66,6 +66,7 @@ def SAMBA_LIBRARY(bld, libname, source, group='main', depends_on='', local_include=True, + vars=None, install_path=None, install=True, enabled=True): @@ -74,6 +75,8 @@ def SAMBA_LIBRARY(bld, libname, source, SET_TARGET_TYPE(bld, libname, 'DISABLED') return + source = bld.EXPAND_VARIABLES(source, vars=vars) + # remember empty libraries, so we can strip the dependencies if (source == '') or (source == []): SET_TARGET_TYPE(bld, libname, 'EMPTY') @@ -193,6 +196,7 @@ def SAMBA_BINARY(bld, binname, source, local_include=True, subsystem_name=None, needs_python=False, + vars=None, install=True, install_path=None): @@ -207,6 +211,8 @@ def SAMBA_BINARY(bld, binname, source, obj_target = binname + '.objlist' + source = bld.EXPAND_VARIABLES(source, vars=vars) + # first create a target for building the object files for this binary # by separating in this way, we avoid recompiling the C files # separately for the install binary and the build binary @@ -299,6 +305,7 @@ def SAMBA_MODULE(bld, modname, source, cflags='', internal_module=True, local_include=True, + vars=None, enabled=True): # we add the init function regardless of whether the module @@ -322,6 +329,8 @@ def SAMBA_MODULE(bld, modname, source, SET_TARGET_TYPE(bld, modname, 'DISABLED') return + source = bld.EXPAND_VARIABLES(source, vars=vars) + # remember empty modules, so we can strip the dependencies if (source == '') or (source == []): SET_TARGET_TYPE(bld, modname, 'EMPTY') @@ -371,6 +380,7 @@ def SAMBA_SUBSYSTEM(bld, modname, source, local_include_first=True, subsystem_name=None, enabled=True, + vars=None, needs_python=False): if not enabled: @@ -385,6 +395,8 @@ def SAMBA_SUBSYSTEM(bld, modname, source, if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'): return + source = bld.EXPAND_VARIABLES(source, vars=vars) + deps += ' ' + public_deps bld.SET_BUILD_GROUP(group) @@ -421,7 +433,8 @@ Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM def SAMBA_GENERATOR(bld, name, rule, source, target, - group='build_source', enabled=True): + group='build_source', enabled=True, + vars=None): '''A generic source generator target''' if not SET_TARGET_TYPE(bld, name, 'GENERATOR'): @@ -433,7 +446,7 @@ def SAMBA_GENERATOR(bld, name, rule, source, target, bld.SET_BUILD_GROUP(group) bld( rule=rule, - source=source, + source=bld.EXPAND_VARIABLES(source, vars=vars), target=target, shell=True, on_results=True, -- cgit