summaryrefslogtreecommitdiffstats
path: root/python/wscript
blob: 3e6439930e9daaed4388a3c5ff610c3c80d2fe49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python

import os
from waflib import Options, Errors

# work out what python external libraries we need to be successful
selftest_pkgs = {
    'cryptography': 'python3-cryptography',
    'pyasn1': 'python3-pyasn1'
}

ad_dc_pkgs = {
    'markdown': 'python3-markdown',
    'dns': 'python3-dnspython (python3-dns on some systems)'
}


def find_third_party_module(conf, module, package, required=True):
    conf.COMPOUND_START("Checking for system installation of Python module %s" % module)
    try:
        __import__(module)
    except ImportError:
        conf.COMPOUND_END(False)
        if not required:
            return False
        raise Errors.WafError("""\
        Unable to find Python module '%s'. Please install the system package: %s'.
""" % (module, package))
    else:
        # Installed on the system
        conf.COMPOUND_END("system")

    return True


def configure(conf):
    if conf.env.disable_python:
        return

    kerberos_py = conf.srcnode.abspath() + "/python/samba/provision/kerberos_implementation.py"

    f = open(kerberos_py, 'w')
    try:
        header = """#
# Copyright (c) 2016      Andreas Schneider <asn@samba.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
        f.write(header)

        data = """kdb_modules_dir = "{0}"
"""

        if conf.env.HEIMDAL_KRB5_CONFIG:
            f.write(data.format(""))
        else:
            modulesdir = "%s/krb5/plugins/kdb" % conf.env.LIBDIR

            f.write(data.format(modulesdir))
    finally:
        f.close()

    if conf.CONFIG_GET('ENABLE_SELFTEST'):
        for module, package in selftest_pkgs.items():
            find_third_party_module(conf, module, package)

        # Prefer dateutil.parser which is much more widely used.
        if not find_third_party_module(conf,
                                       'dateutil.parser',
                                       'python3-dateutilis',
                                       required=False):
            if not find_third_party_module(conf,
                                           'iso8601',
                                           'python3-iso8601',
                                           required=False):
                raise Errors.WafError("Could not find Python package "
                                      "'python3-dateutils' nor "
                                      "'python3-iso8601'. Please install "
                                      "one of the packages.")

    if not Options.options.without_ad_dc:
        for module, package in ad_dc_pkgs.items():
            find_third_party_module(conf, module, package)


def build(bld):


    pytalloc_util = bld.pyembed_libname('pytalloc-util')
    pyparam_util = bld.pyembed_libname('pyparam_util')
    libpython = bld.pyembed_libname('LIBPYTHON')
    pyrpc_util = bld.pyembed_libname('pyrpc_util')
    samba_python = bld.pyembed_libname('samba_python')
    bld.SAMBA_LIBRARY(samba_python,
                      source=[],
                      deps='%s %s %s' % (libpython, pytalloc_util, pyrpc_util),
                      grouping_library=True,
                      private_library=True,
                      pyembed=True,
                      enabled=bld.PYTHON_BUILD_IS_ENABLED())
    bld.SAMBA_PYTHON('python_glue',
                     source='pyglue.c',
                     deps='''
                              %s
                              samba-util
                              netif
                              ndr
                              cmdline
                              gkdi
                              %s
                              ''' % (pyparam_util, pytalloc_util),
                     realname='samba/_glue.so')

    bld.SAMBA_SUBSYSTEM(libpython,
                        source='modules.c',
                        public_deps='',
                        init_function_sentinel='{NULL,NULL}',
                        deps='talloc',
                        pyext=True,
                        enabled=bld.PYTHON_BUILD_IS_ENABLED())

    if bld.PYTHON_BUILD_IS_ENABLED():
        # install out various python scripts for use by make test
        bld.SAMBA_SCRIPT('samba_python_files',
                         pattern='samba/**/*.py',
                         installdir='python')

        bld.INSTALL_WILDCARD('${PYTHONARCHDIR}', 'samba/**/*.py', flat=False)