Fix a few "might be uninitialized" errors
[Samba.git] / python / wscript
blob3e6439930e9daaed4388a3c5ff610c3c80d2fe49
1 #!/usr/bin/env python
3 import os
4 from waflib import Options, Errors
6 # work out what python external libraries we need to be successful
7 selftest_pkgs = {
8 'cryptography': 'python3-cryptography',
9 'pyasn1': 'python3-pyasn1'
12 ad_dc_pkgs = {
13 'markdown': 'python3-markdown',
14 'dns': 'python3-dnspython (python3-dns on some systems)'
18 def find_third_party_module(conf, module, package, required=True):
19 conf.COMPOUND_START("Checking for system installation of Python module %s" % module)
20 try:
21 __import__(module)
22 except ImportError:
23 conf.COMPOUND_END(False)
24 if not required:
25 return False
26 raise Errors.WafError("""\
27 Unable to find Python module '%s'. Please install the system package: %s'.
28 """ % (module, package))
29 else:
30 # Installed on the system
31 conf.COMPOUND_END("system")
33 return True
36 def configure(conf):
37 if conf.env.disable_python:
38 return
40 kerberos_py = conf.srcnode.abspath() + "/python/samba/provision/kerberos_implementation.py"
42 f = open(kerberos_py, 'w')
43 try:
44 header = """#
45 # Copyright (c) 2016 Andreas Schneider <asn@samba.org>
47 # This program is free software; you can redistribute it and/or modify
48 # it under the terms of the GNU General Public License as published by
49 # the Free Software Foundation; either version 3 of the License, or
50 # (at your option) any later version.
52 # This program is distributed in the hope that it will be useful,
53 # but WITHOUT ANY WARRANTY; without even the implied warranty of
54 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 # GNU General Public License for more details.
57 # You should have received a copy of the GNU General Public License
58 # along with this program. If not, see <http://www.gnu.org/licenses/>.
60 """
61 f.write(header)
63 data = """kdb_modules_dir = "{0}"
64 """
66 if conf.env.HEIMDAL_KRB5_CONFIG:
67 f.write(data.format(""))
68 else:
69 modulesdir = "%s/krb5/plugins/kdb" % conf.env.LIBDIR
71 f.write(data.format(modulesdir))
72 finally:
73 f.close()
75 if conf.CONFIG_GET('ENABLE_SELFTEST'):
76 for module, package in selftest_pkgs.items():
77 find_third_party_module(conf, module, package)
79 # Prefer dateutil.parser which is much more widely used.
80 if not find_third_party_module(conf,
81 'dateutil.parser',
82 'python3-dateutilis',
83 required=False):
84 if not find_third_party_module(conf,
85 'iso8601',
86 'python3-iso8601',
87 required=False):
88 raise Errors.WafError("Could not find Python package "
89 "'python3-dateutils' nor "
90 "'python3-iso8601'. Please install "
91 "one of the packages.")
93 if not Options.options.without_ad_dc:
94 for module, package in ad_dc_pkgs.items():
95 find_third_party_module(conf, module, package)
98 def build(bld):
101 pytalloc_util = bld.pyembed_libname('pytalloc-util')
102 pyparam_util = bld.pyembed_libname('pyparam_util')
103 libpython = bld.pyembed_libname('LIBPYTHON')
104 pyrpc_util = bld.pyembed_libname('pyrpc_util')
105 samba_python = bld.pyembed_libname('samba_python')
106 bld.SAMBA_LIBRARY(samba_python,
107 source=[],
108 deps='%s %s %s' % (libpython, pytalloc_util, pyrpc_util),
109 grouping_library=True,
110 private_library=True,
111 pyembed=True,
112 enabled=bld.PYTHON_BUILD_IS_ENABLED())
113 bld.SAMBA_PYTHON('python_glue',
114 source='pyglue.c',
115 deps='''
117 samba-util
118 netif
120 cmdline
121 gkdi
123 ''' % (pyparam_util, pytalloc_util),
124 realname='samba/_glue.so')
126 bld.SAMBA_SUBSYSTEM(libpython,
127 source='modules.c',
128 public_deps='',
129 init_function_sentinel='{NULL,NULL}',
130 deps='talloc',
131 pyext=True,
132 enabled=bld.PYTHON_BUILD_IS_ENABLED())
134 if bld.PYTHON_BUILD_IS_ENABLED():
135 # install out various python scripts for use by make test
136 bld.SAMBA_SCRIPT('samba_python_files',
137 pattern='samba/**/*.py',
138 installdir='python')
140 bld.INSTALL_WILDCARD('${PYTHONARCHDIR}', 'samba/**/*.py', flat=False)