build: support variable expansion in source= arguments to build rules
authorAndrew Tridgell <tridge@samba.org>
Wed, 24 Mar 2010 22:23:10 +0000 (16:23 -0600)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:06 +0000 (20:27 +1000)
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>

buildtools/wafsamba/samba_python.py
buildtools/wafsamba/samba_utils.py
buildtools/wafsamba/wafsamba.py

index 7536250d0d6bf537cce916ee0cf879dd068e7c3d..9a887a80a55a8c06830ec588114928b7af83cdc3 100644 (file)
@@ -14,6 +14,7 @@ def SAMBA_PYTHON(bld, name,
                  includes='',
                  init_function_sentinal=None,
                  local_include=True,
                  includes='',
                  init_function_sentinal=None,
                  local_include=True,
+                 vars=None,
                  enabled=True):
     '''build a python extension for Samba'''
 
                  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
 
     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
     if realname is None:
         # a SAMBA_PYTHON target without a realname is just a
         # subsystem with needs_python=True
index 814a5771a4cb5997a706d75d8aefdc21640f1f02..1b21d7308c2006f0f0c99022a6423e2a1323bf9d 100644 (file)
@@ -337,6 +337,40 @@ def SUBST_VARS_RECURSIVE(string, env):
         limit -= 1
     return string
 
         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,
 
 def RUN_COMMAND(cmd,
                 env=None,
index 9e7c39581b2c5f7996d11dba194ed003c28acfee..ad104a2e89820aeb21e3bd818f25b0151ee89e38 100644 (file)
@@ -66,6 +66,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                   group='main',
                   depends_on='',
                   local_include=True,
                   group='main',
                   depends_on='',
                   local_include=True,
+                  vars=None,
                   install_path=None,
                   install=True,
                   enabled=True):
                   install_path=None,
                   install=True,
                   enabled=True):
@@ -74,6 +75,8 @@ def SAMBA_LIBRARY(bld, libname, source,
         SET_TARGET_TYPE(bld, libname, 'DISABLED')
         return
 
         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')
     # 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,
                  local_include=True,
                  subsystem_name=None,
                  needs_python=False,
+                 vars=None,
                  install=True,
                  install_path=None):
 
                  install=True,
                  install_path=None):
 
@@ -207,6 +211,8 @@ def SAMBA_BINARY(bld, binname, source,
 
     obj_target = binname + '.objlist'
 
 
     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
     # 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,
                  cflags='',
                  internal_module=True,
                  local_include=True,
+                 vars=None,
                  enabled=True):
 
     # we add the init function regardless of whether the module
                  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
 
         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')
     # 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,
                     local_include_first=True,
                     subsystem_name=None,
                     enabled=True,
+                    vars=None,
                     needs_python=False):
 
     if not enabled:
                     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
 
     if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
         return
 
+    source = bld.EXPAND_VARIABLES(source, vars=vars)
+
     deps += ' ' + public_deps
 
     bld.SET_BUILD_GROUP(group)
     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,
 
 
 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'):
     '''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,
     bld.SET_BUILD_GROUP(group)
     bld(
         rule=rule,
-        source=source,
+        source=bld.EXPAND_VARIABLES(source, vars=vars),
         target=target,
         shell=True,
         on_results=True,
         target=target,
         shell=True,
         on_results=True,