buildtools: Add a helper to iterate through Python environments
authorPetr Viktorin <pviktori@redhat.com>
Wed, 6 May 2015 15:50:57 +0000 (17:50 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 19 May 2015 17:28:19 +0000 (19:28 +0200)
This prevents code duplication to ensure the "extrapython" build
is the same as the normal one.

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
buildtools/wafsamba/samba_python.py
buildtools/wafsamba/wafsamba.py
lib/talloc/wscript

index d12fe95a465478a22d818e4e7d9f0b372da55dc4..a0e0ffa9f6b749f5267bca35b2af71d12128b29e 100644 (file)
@@ -74,6 +74,9 @@ def SAMBA_PYTHON(bld, name,
                  enabled=True):
     '''build a python extension for Samba'''
 
+    if bld.env['IS_EXTRA_PYTHON']:
+        name = 'extra-' + name
+
     # when we support static python modules we'll need to gather
     # the list from all the SAMBA_PYTHON() targets
     if init_function_sentinel is not None:
@@ -111,3 +114,25 @@ def pyembed_libname(bld, name, extrapython=False):
     return name + bld.env['PYTHON_SO_ABI_FLAG']
 
 Build.BuildContext.pyembed_libname = pyembed_libname
+
+
+def gen_python_environments(bld, extra_env_vars=()):
+    """Generate all Python environments
+
+    To be used in a for loop. Normally, the loop body will be executed once.
+
+    When --extra-python is used, the body will additionaly be executed
+    with the extra-python environment active.
+    """
+    yield
+
+    if bld.env['EXTRA_PYTHON']:
+        copied = ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars)
+        for name in copied:
+            bld.all_envs['extrapython'][name] = bld.all_envs['default'][name]
+        default_env = bld.all_envs['default']
+        bld.all_envs['default'] = bld.all_envs['extrapython']
+        yield
+        bld.all_envs['default'] = default_env
+
+Build.BuildContext.gen_python_environments = gen_python_environments
index 12bf2311cf071b23e201bb087952dc5b8364cc93..64382da4e43a7a15a1f00117c171d45be57fc289 100644 (file)
@@ -143,6 +143,9 @@ def SAMBA_LIBRARY(bld, libname, source,
                   enabled=True):
     '''define a Samba library'''
 
+    if pyembed and bld.env['IS_EXTRA_PYTHON']:
+        public_headers = pc_files = None
+
     if LIB_MUST_BE_PRIVATE(bld, libname):
         private_library=True
 
index 0b62d405c695c64d18794a5d55358538d9dcc442..c520294fa264bbcd2c5bc1b2a3ca0e6bc9ee28b7 100644 (file)
@@ -116,68 +116,33 @@ def build(bld):
                           manpages='man/talloc.3')
 
     if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL') and not bld.env.disable_python:
-        name = bld.pyembed_libname('pytalloc-util')
-
-        bld.SAMBA_LIBRARY(name,
-            source='pytalloc_util.c',
-            public_deps='talloc',
-            pyembed=True,
-            vnum=VERSION,
-            hide_symbols=True,
-            abi_directory='ABI',
-            abi_match='pytalloc_*',
-            private_library=private_library,
-            public_headers='pytalloc.h',
-            pc_files='pytalloc-util.pc'
-            )
-        bld.SAMBA_PYTHON('pytalloc',
-                         'pytalloc.c',
-                         deps='talloc ' + name,
-                         enabled=True,
-                         realname='talloc.so')
-
-        bld.SAMBA_PYTHON('test_pytalloc',
-                         'test_pytalloc.c',
-                         deps='pytalloc',
-                         enabled=True,
-                         realname='_test_pytalloc.so',
-                         install=False)
-
-    if bld.env['EXTRA_PYTHON']:
-        for var_name in ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE', 'PKGCONFIGDIR'):
-            bld.all_envs['extrapython'][var_name] = bld.all_envs['default'][var_name]
-        bak = bld.all_envs['default']
-        bld.all_envs['default'] = bld.all_envs['extrapython']
-
-        name = bld.pyembed_libname('pytalloc-util')
-
-        bld.SAMBA_LIBRARY(name,
-            source='pytalloc_util.c',
-            public_deps='talloc',
-            pyembed=True,
-            vnum=VERSION,
-            hide_symbols=True,
-            abi_directory='ABI',
-            abi_match='pytalloc_*',
-            private_library=private_library,
-            #public_headers='pytalloc.h',
-            #pc_files='pytalloc-util.pc'
-            )
-
-        bld.SAMBA_PYTHON('extra-pytalloc',
-                         'pytalloc.c',
-                         deps='talloc ' + name,
-                         enabled=True,
-                         realname='talloc.so')
-
-        bld.SAMBA_PYTHON('extra-test_pytalloc',
-                         'test_pytalloc.c',
-                         deps='pytalloc',
-                         enabled=True,
-                         realname='_test_pytalloc.so',
-                         install=False)
-
-        bld.all_envs['default'] = bak
+        for env in bld.gen_python_environments(['PKGCONFIGDIR']):
+            name = bld.pyembed_libname('pytalloc-util')
+
+            bld.SAMBA_LIBRARY(name,
+                source='pytalloc_util.c',
+                public_deps='talloc',
+                pyembed=True,
+                vnum=VERSION,
+                hide_symbols=True,
+                abi_directory='ABI',
+                abi_match='pytalloc_*',
+                private_library=private_library,
+                public_headers='pytalloc.h',
+                pc_files='pytalloc-util.pc'
+                )
+            bld.SAMBA_PYTHON('pytalloc',
+                            'pytalloc.c',
+                            deps='talloc ' + name,
+                            enabled=True,
+                            realname='talloc.so')
+
+            bld.SAMBA_PYTHON('test_pytalloc',
+                            'test_pytalloc.c',
+                            deps='pytalloc',
+                            enabled=True,
+                            realname='_test_pytalloc.so',
+                            install=False)
 
 
 def test(ctx):