s3:smb2_create: #if 0 unused variable
[Samba.git] / buildtools / wafsamba / samba_python.py
bloba8f780f9f5d3f5f048de1f36826f2a196d912e73
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 if conf.env.HAVE_PYTHON_H:
13 conf.check_python_version(version)
14 return
16 interpreters = []
18 if conf.env['EXTRA_PYTHON']:
19 conf.all_envs['extrapython'] = conf.env.copy()
20 conf.setenv('extrapython')
21 conf.env['PYTHON'] = conf.env['EXTRA_PYTHON']
22 conf.env['IS_EXTRA_PYTHON'] = 'yes'
23 conf.find_program('python', var='PYTHON', mandatory=True)
24 conf.check_tool('python')
25 try:
26 conf.check_python_version((3, 3, 0))
27 except Exception:
28 Logs.warn('extra-python needs to be Python 3.3 or later')
29 raise
30 interpreters.append(conf.env['PYTHON'])
31 conf.setenv('default')
33 conf.find_program('python', var='PYTHON', mandatory=mandatory)
34 conf.check_tool('python')
35 path_python = conf.find_program('python')
36 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
37 conf.check_python_version(version)
39 interpreters.append(conf.env['PYTHON'])
40 conf.env.python_interpreters = interpreters
43 @conf
44 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
45 if conf.env["python_headers_checked"] == []:
46 if conf.env['EXTRA_PYTHON']:
47 conf.setenv('extrapython')
48 _check_python_headers(conf, mandatory=True)
49 conf.setenv('default')
51 _check_python_headers(conf, mandatory)
52 conf.env["python_headers_checked"] = "yes"
54 if conf.env['EXTRA_PYTHON']:
55 extraversion = conf.all_envs['extrapython']['PYTHON_VERSION']
56 if extraversion == conf.env['PYTHON_VERSION']:
57 raise Utils.WafError("extrapython %s is same as main python %s" % (
58 extraversion, conf.env['PYTHON_VERSION']))
59 else:
60 conf.msg("python headers", "using cache")
62 # we don't want PYTHONDIR in config.h, as otherwise changing
63 # --prefix causes a complete rebuild
64 del(conf.env.defines['PYTHONDIR'])
65 del(conf.env.defines['PYTHONARCHDIR'])
67 def _check_python_headers(conf, mandatory):
68 conf.check_python_headers(mandatory=mandatory)
70 if conf.env['PYTHON_VERSION'] > '3':
71 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
72 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
73 else:
74 conf.env['PYTHON_SO_ABI_FLAG'] = ''
77 def SAMBA_PYTHON(bld, name,
78 source='',
79 deps='',
80 public_deps='',
81 realname=None,
82 cflags='',
83 includes='',
84 init_function_sentinel=None,
85 local_include=True,
86 vars=None,
87 install=True,
88 enabled=True):
89 '''build a python extension for Samba'''
91 if bld.env['IS_EXTRA_PYTHON']:
92 name = 'extra-' + name
94 # when we support static python modules we'll need to gather
95 # the list from all the SAMBA_PYTHON() targets
96 if init_function_sentinel is not None:
97 cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
99 source = bld.EXPAND_VARIABLES(source, vars=vars)
101 if realname is not None:
102 link_name = 'python_modules/%s' % realname
103 else:
104 link_name = None
106 bld.SAMBA_LIBRARY(name,
107 source=source,
108 deps=deps,
109 public_deps=public_deps,
110 includes=includes,
111 cflags=cflags,
112 local_include=local_include,
113 vars=vars,
114 realname=realname,
115 link_name=link_name,
116 pyext=True,
117 target_type='PYTHON',
118 install_path='${PYTHONARCHDIR}',
119 allow_undefined_symbols=True,
120 install=install,
121 enabled=enabled)
123 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
126 def pyembed_libname(bld, name, extrapython=False):
127 return name + bld.env['PYTHON_SO_ABI_FLAG']
129 Build.BuildContext.pyembed_libname = pyembed_libname
132 def gen_python_environments(bld, extra_env_vars=()):
133 """Generate all Python environments
135 To be used in a for loop. Normally, the loop body will be executed once.
137 When --extra-python is used, the body will additionaly be executed
138 with the extra-python environment active.
140 yield
142 if bld.env['EXTRA_PYTHON']:
143 copied = ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars)
144 for name in copied:
145 bld.all_envs['extrapython'][name] = bld.all_envs['default'][name]
146 default_env = bld.all_envs['default']
147 bld.all_envs['default'] = bld.all_envs['extrapython']
148 yield
149 bld.all_envs['default'] = default_env
151 Build.BuildContext.gen_python_environments = gen_python_environments