summaryrefslogtreecommitdiff
path: root/third_party/wscript
blob: ad4d6245bbd429820719cac1ce935d1c0d69eb8f (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
#!/usr/bin/env python

import samba_git
import Utils
import os
import sys

# work out what python external libraries we need to install
external_pkgs = {
    "dns.resolver": "dnspython/dns",
    "iso8601": "pyiso8601/iso8601",
    }


def find_third_party_module(conf, module, package):
    conf.COMPOUND_START("Checking for third party Python module %s" % module)
    try:
        __import__(module)
    except ImportError:
        pass
    else:
        # Installed on the system
        conf.COMPOUND_END("system")

    old_path = sys.path
    try:
        sys.path.append(os.path.join(conf.curdir, os.path.dirname(package)))
        try:
            __import__(module)
        except ImportError:
            if samba_git.has_submodules(conf.srcdir):
                raise Utils.WafError("""\
Unable to find Python module '%s'. Please install the system package or check \
out the relevant submodule by running 'git submodule update --init'.
""" % module)
            else:
                raise Utils.WafError("""\
Unable to find Python module '%s'. Please install the system package or place a copy in
%s.
""" % (module, package))
        else:
            conf.COMPOUND_END("bundled")
    finally:
        sys.path = old_path


def configure(conf):
    for module, package in external_pkgs.items():
        find_third_party_module(conf, module, package)
    conf.RECURSE('cmocka')
    conf.RECURSE('popt')
    conf.RECURSE('zlib')


def build(bld):
    list = []

    for module, package in external_pkgs.items():
        try:
            __import__(module)
        except ImportError:
            list.append(package)

    for e in list:
        bld.INSTALL_WILDCARD('${PYTHONARCHDIR}/samba/third_party', e + '/**/*', flat=False,
                             exclude='*.pyc', trim_path=os.path.dirname(e))

    bld.SAMBA_GENERATOR('third_party_init_py',
                        rule='touch ${TGT}',
                        target='empty_file')

    bld.INSTALL_FILES('${PYTHONARCHDIR}/samba/third_party', 'empty_file', destname='__init__.py')
    bld.RECURSE('cmocka')
    bld.RECURSE('zlib')
    bld.RECURSE('popt')