Debian Codegraph @

python/wscript

raw
1 #!/usr/bin/env python
2
3 import os
4 from waflib import Options, Errors
5
6 # work out what python external libraries we need to be successful
7 selftest_pkgs = {
8 'cryptography': 'python3-cryptography',
9 'pyasn1': 'python3-pyasn1'
10 }
11
12 ad_dc_pkgs = {
13 'markdown': 'python3-markdown',
14 'dns': 'python3-dnspython (python3-dns on some systems)'
15 }
16
17
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")
32
33 return True
34
35
36 def configure(conf):
37 if conf.env.disable_python:
38 return
39
40 kerberos_py = conf.srcnode.abspath() + "/python/samba/provision/kerberos_implementation.py"
41
42 f = open(kerberos_py, 'w')
43 try:
44 header = """#
45 # Copyright (c) 2016 Andreas Schneider <[email protected]>
46 #
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.
51 #
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.
56 #
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/>.
59 #
60 """
61 f.write(header)
62
63 data = """kdb_modules_dir = "{0}"
64 """
65
66 if conf.env.HEIMDAL_KRB5_CONFIG:
67 f.write(data.format(""))
68 else:
69 modulesdir = "%s/krb5/plugins/kdb" % conf.env.LIBDIR
70
71 f.write(data.format(modulesdir))
72 finally:
73 f.close()
74
75 # In many places we fill in a uint32_t with an unsigned int, using
76 # PyArg_ParseTuple("I"), which will overwrite memory if the size
77 # of the int is not 4. There are no systems on which Samba will
78 # compile where int is not 32 bit, but we are testing in case this
79 # changes.
80 if 'SIZEOF_INT' not in conf.env:
81 conf.CHECK_SIZEOF('int uint32_t')
82 sizeof_int = conf.env['SIZEOF_INT']
83 sizeof_uint32 = conf.env['SIZEOF_UINT32_T']
84 if sizeof_int != sizeof_uint32:
85 conf.fatal("Samba python bindings won't work with int bigger than uint32_t "
86 f"(int: {sizeof_int}, uint32_t: {sizeof_uint32}).")
87
88 if conf.CONFIG_GET('ENABLE_SELFTEST'):
89 for module, package in selftest_pkgs.items():
90 find_third_party_module(conf, module, package)
91
92 # Prefer dateutil.parser which is much more widely used.
93 if not find_third_party_module(conf,
94 'dateutil.parser',
95 'python3-dateutilis',
96 required=False):
97 if not find_third_party_module(conf,
98 'iso8601',
99 'python3-iso8601',
100 required=False):
101 raise Errors.WafError("Could not find Python package "
102 "'python3-dateutils' nor "
103 "'python3-iso8601'. Please install "
104 "one of the packages.")
105
106 if not Options.options.without_ad_dc:
107 for module, package in ad_dc_pkgs.items():
108 find_third_party_module(conf, module, package)
109
110
111 def build(bld):
112
113
114 pytalloc_util = bld.pyembed_libname('pytalloc-util')
115 pyparam_util = bld.pyembed_libname('pyparam_util')
116 libpython = bld.pyembed_libname('LIBPYTHON')
117 pyrpc_util = bld.pyembed_libname('pyrpc_util')
118 samba_python = bld.pyembed_libname('samba_python')
119 bld.SAMBA_LIBRARY(samba_python,
120 source=[],
121 deps='%s %s %s' % (libpython, pytalloc_util, pyrpc_util),
122 grouping_library=True,
123 private_library=True,
124 pyembed=True,
125 enabled=bld.PYTHON_BUILD_IS_ENABLED())
126 bld.SAMBA_PYTHON('python_glue',
127 source='pyglue.c',
128 deps='''
129 %s
130 samba-util
131 netif
132 ndr
133 cmdline
134 gkdi
135 util_crypt
136 %s
137 ''' % (pyparam_util, pytalloc_util),
138 realname='samba/_glue.so')
139
140 bld.SAMBA_SUBSYSTEM(libpython,
141 source='modules.c',
142 public_deps='',
143 init_function_sentinel='{NULL,NULL}',
144 deps='talloc',
145 pyext=True,
146 enabled=bld.PYTHON_BUILD_IS_ENABLED())
147
148 if bld.PYTHON_BUILD_IS_ENABLED():
149 # install out various python scripts for use by make test
150 bld.SAMBA_SCRIPT('samba_python_files',
151 pattern='samba/**/*.py',
152 installdir='python')
153
154 bld.INSTALL_WILDCARD('${PYTHONARCHDIR}', 'samba/**/*.py', flat=False)