From 6f490000c6b233f275598a4680b2c49fcb69d35a Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 6 May 2015 17:50:57 +0200 Subject: [PATCH] buildtools: Add a helper to iterate through Python environments This prevents code duplication to ensure the "extrapython" build is the same as the normal one. Signed-off-by: Petr Viktorin Reviewed-by: Andrew Bartlett Reviewed-by: Jelmer Vernooij --- buildtools/wafsamba/samba_python.py | 25 +++++++++ buildtools/wafsamba/wafsamba.py | 3 + lib/talloc/wscript | 85 +++++++++-------------------- 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index d12fe95a465..a0e0ffa9f6b 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -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 diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 12bf2311cf0..64382da4e43 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -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 diff --git a/lib/talloc/wscript b/lib/talloc/wscript index 0b62d405c69..c520294fa26 100644 --- a/lib/talloc/wscript +++ b/lib/talloc/wscript @@ -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') + 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_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 + bld.SAMBA_PYTHON('test_pytalloc', + 'test_pytalloc.c', + deps='pytalloc', + enabled=True, + realname='_test_pytalloc.so', + install=False) def test(ctx):