ctdb: Accept the key in hex format for the pstore command
[Samba.git] / buildtools / wafsamba / samba_python.py
blob7546bbd6d2e7c28aad06c42e8e9068e473e52941
1 # waf build tool for building IDL files with pidl
3 import Build
4 from samba_utils import *
5 from samba_autoconf import *
7 from Configure import conf
9 @conf
10 def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
11 # enable tool to build python extensions
12 interpreters = []
14 if conf.env['EXTRA_PYTHON']:
15 conf.all_envs['extrapython'] = conf.env.copy()
16 conf.setenv('extrapython')
17 conf.env['PYTHON'] = conf.env['EXTRA_PYTHON']
18 conf.env['IS_EXTRA_PYTHON'] = 'yes'
19 conf.find_program('python', var='PYTHON', mandatory=True)
20 conf.check_tool('python')
21 try:
22 conf.check_python_version((3, 3, 0))
23 except Exception:
24 warn('extra-python needs to be Python 3.3 or later')
25 raise
26 interpreters.append(conf.env['PYTHON'])
27 conf.setenv('default')
29 conf.find_program('python', var='PYTHON', mandatory=mandatory)
30 conf.check_tool('python')
31 path_python = conf.find_program('python')
32 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
33 conf.check_python_version(version)
35 interpreters.append(conf.env['PYTHON'])
36 conf.env.python_interpreters = interpreters
39 @conf
40 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
41 if conf.env["python_headers_checked"] == []:
42 if conf.env['EXTRA_PYTHON']:
43 conf.setenv('extrapython')
44 _check_python_headers(conf, mandatory=True)
45 conf.setenv('default')
47 _check_python_headers(conf, mandatory)
48 conf.env["python_headers_checked"] = "yes"
50 if conf.env['EXTRA_PYTHON']:
51 extraversion = conf.all_envs['extrapython']['PYTHON_VERSION']
52 if extraversion == conf.env['PYTHON_VERSION']:
53 raise Utils.WafError("extrapython %s is same as main python %s" % (
54 extraversion, conf.env['PYTHON_VERSION']))
55 else:
56 conf.msg("python headers", "using cache")
58 # we don't want PYTHONDIR in config.h, as otherwise changing
59 # --prefix causes a complete rebuild
60 del(conf.env.defines['PYTHONDIR'])
61 del(conf.env.defines['PYTHONARCHDIR'])
63 def _check_python_headers(conf, mandatory):
64 conf.check_python_headers(mandatory=mandatory)
66 if conf.env['PYTHON_VERSION'] > '3':
67 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
68 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
69 else:
70 conf.env['PYTHON_SO_ABI_FLAG'] = ''
73 def SAMBA_PYTHON(bld, name,
74 source='',
75 deps='',
76 public_deps='',
77 realname=None,
78 cflags='',
79 includes='',
80 init_function_sentinel=None,
81 local_include=True,
82 vars=None,
83 install=True,
84 enabled=True):
85 '''build a python extension for Samba'''
87 if bld.env['IS_EXTRA_PYTHON']:
88 name = 'extra-' + name
90 # when we support static python modules we'll need to gather
91 # the list from all the SAMBA_PYTHON() targets
92 if init_function_sentinel is not None:
93 cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
95 source = bld.EXPAND_VARIABLES(source, vars=vars)
97 if realname is not None:
98 link_name = 'python_modules/%s' % realname
99 else:
100 link_name = None
102 bld.SAMBA_LIBRARY(name,
103 source=source,
104 deps=deps,
105 public_deps=public_deps,
106 includes=includes,
107 cflags=cflags,
108 local_include=local_include,
109 vars=vars,
110 realname=realname,
111 link_name=link_name,
112 pyext=True,
113 target_type='PYTHON',
114 install_path='${PYTHONARCHDIR}',
115 allow_undefined_symbols=True,
116 install=install,
117 enabled=enabled)
119 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
122 def pyembed_libname(bld, name, extrapython=False):
123 return name + bld.env['PYTHON_SO_ABI_FLAG']
125 Build.BuildContext.pyembed_libname = pyembed_libname
128 def gen_python_environments(bld, extra_env_vars=()):
129 """Generate all Python environments
131 To be used in a for loop. Normally, the loop body will be executed once.
133 When --extra-python is used, the body will additionaly be executed
134 with the extra-python environment active.
136 yield
138 if bld.env['EXTRA_PYTHON']:
139 copied = ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars)
140 for name in copied:
141 bld.all_envs['extrapython'][name] = bld.all_envs['default'][name]
142 default_env = bld.all_envs['default']
143 bld.all_envs['default'] = bld.all_envs['extrapython']
144 yield
145 bld.all_envs['default'] = default_env
147 Build.BuildContext.gen_python_environments = gen_python_environments