talloc: Use libraries from build dir for testsuite
[samba.git] / lib / talloc / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'talloc'
4 VERSION = '2.1.9'
5
6
7 blddir = 'bin'
8
9 import Logs
10 import os, sys
11
12 # find the buildtools directory
13 srcdir = '.'
14 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
15     srcdir = srcdir + '/..'
16 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
17
18 import sys
19 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
20 import wafsamba, samba_dist, Options
21
22 # setup what directories to put in a tarball
23 samba_dist.DIST_DIRS("""lib/talloc:. lib/replace:lib/replace
24 buildtools:buildtools third_party/waf:third_party/waf""")
25
26
27 def set_options(opt):
28     opt.BUILTIN_DEFAULT('replace')
29     opt.PRIVATE_EXTENSION_DEFAULT('talloc', noextension='talloc')
30     opt.RECURSE('lib/replace')
31     if opt.IN_LAUNCH_DIR():
32         opt.add_option('--enable-talloc-compat1',
33                        help=("Build talloc 1.x.x compat library [False]"),
34                        action="store_true", dest='TALLOC_COMPAT1', default=False)
35
36
37 def configure(conf):
38     conf.RECURSE('lib/replace')
39
40     conf.env.standalone_talloc = conf.IN_LAUNCH_DIR()
41
42     conf.define('TALLOC_BUILD_VERSION_MAJOR', int(VERSION.split('.')[0]))
43     conf.define('TALLOC_BUILD_VERSION_MINOR', int(VERSION.split('.')[1]))
44     conf.define('TALLOC_BUILD_VERSION_RELEASE', int(VERSION.split('.')[2]))
45
46     conf.env.TALLOC_COMPAT1 = False
47     if conf.env.standalone_talloc:
48         conf.env.TALLOC_COMPAT1 = Options.options.TALLOC_COMPAT1
49         conf.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
50         conf.env.TALLOC_VERSION = VERSION
51
52     conf.CHECK_XSLTPROC_MANPAGES()
53
54     conf.CHECK_HEADERS('sys/auxv.h')
55     conf.CHECK_FUNCS('getauxval')
56
57     conf.SAMBA_CONFIG_H()
58
59     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
60
61     # We need to set everything non-python up before here, because
62     # SAMBA_CHECK_PYTHON makes a copy of conf and we need it set up correctly
63
64     if not conf.env.disable_python:
65         # also disable if we don't have the python libs installed
66         conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,4,2))
67         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
68         if not conf.env.HAVE_PYTHON_H:
69             Logs.warn('Disabling pytalloc-util as python devel libs not found')
70             conf.env.disable_python = True
71
72     if not conf.env.standalone_talloc:
73         if conf.CHECK_BUNDLED_SYSTEM_PKG('talloc', minversion=VERSION,
74                                      implied_deps='replace'):
75             conf.define('USING_SYSTEM_TALLOC', 1)
76
77         using_system_pytalloc_util = True
78         if not conf.CHECK_BUNDLED_SYSTEM_PKG('pytalloc-util', minversion=VERSION,
79                                              implied_deps='talloc replace'):
80             using_system_pytalloc_util = False
81
82         # We need to get a pytalloc-util for all the python versions
83         # we are building for
84         if conf.env['EXTRA_PYTHON']:
85             name = 'pytalloc-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
86             if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
87                                                  implied_deps='talloc replace'):
88                 using_system_pytalloc_util = False
89
90         if using_system_pytalloc_util:
91             conf.define('USING_SYSTEM_PYTALLOC_UTIL', 1)
92
93
94 def build(bld):
95     bld.RECURSE('lib/replace')
96
97     if bld.env.standalone_talloc:
98         private_library = False
99
100         # should we also install the symlink to libtalloc1.so here?
101         bld.SAMBA_LIBRARY('talloc-compat1-%s' % (VERSION),
102                           'compat/talloc_compat1.c',
103                           public_deps='talloc',
104                           soname='libtalloc.so.1',
105                           pc_files=[],
106                           public_headers=[],
107                           enabled=bld.env.TALLOC_COMPAT1)
108
109         testsuite_deps = 'talloc'
110         if bld.CONFIG_SET('HAVE_PTHREAD'):
111             testsuite_deps += ' pthread'
112
113         bld.SAMBA_BINARY('talloc_testsuite',
114                          'testsuite_main.c testsuite.c',
115                          testsuite_deps,
116                          install=False)
117
118         bld.SAMBA_BINARY('talloc_test_magic_differs_helper',
119                          'test_magic_differs_helper.c',
120                          'talloc', install=False)
121
122     else:
123         private_library = True
124
125     if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
126
127         bld.SAMBA_LIBRARY('talloc',
128                           'talloc.c',
129                           deps='replace',
130                           abi_directory='ABI',
131                           abi_match='talloc* _talloc*',
132                           hide_symbols=True,
133                           vnum=VERSION,
134                           public_headers=('' if private_library else 'talloc.h'),
135                           pc_files='talloc.pc',
136                           public_headers_install=not private_library,
137                           private_library=private_library,
138                           manpages='man/talloc.3')
139
140     if not bld.CONFIG_SET('USING_SYSTEM_PYTALLOC_UTIL'):
141         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
142             name = bld.pyembed_libname('pytalloc-util')
143
144             bld.SAMBA_LIBRARY(name,
145                 source='pytalloc_util.c',
146                 public_deps='talloc',
147                 pyembed=True,
148                 vnum=VERSION,
149                 hide_symbols=True,
150                 abi_directory='ABI',
151                 abi_match='pytalloc_* _pytalloc_*',
152                 private_library=private_library,
153                 public_headers=('' if private_library else 'pytalloc.h'),
154                 pc_files='pytalloc-util.pc',
155                 enabled=bld.PYTHON_BUILD_IS_ENABLED()
156                 )
157             bld.SAMBA_PYTHON('pytalloc',
158                             'pytalloc.c',
159                             deps='talloc ' + name,
160                             enabled=bld.PYTHON_BUILD_IS_ENABLED(),
161                             realname='talloc.so')
162
163             bld.SAMBA_PYTHON('test_pytalloc',
164                             'test_pytalloc.c',
165                             deps='pytalloc',
166                             enabled=bld.PYTHON_BUILD_IS_ENABLED(),
167                             realname='_test_pytalloc.so',
168                             install=False)
169
170
171 def test(ctx):
172     '''run talloc testsuite'''
173     import Utils, samba_utils
174
175     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
176     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
177
178     cmd = os.path.join(Utils.g_module.blddir, 'talloc_testsuite')
179     ret = samba_utils.RUN_COMMAND(cmd)
180     print("testsuite returned %d" % ret)
181     magic_helper_cmd = os.path.join(Utils.g_module.blddir, 'talloc_test_magic_differs_helper')
182     magic_cmd = os.path.join(srcdir, 'lib', 'talloc',
183                              'test_magic_differs.sh')
184
185     magic_ret = samba_utils.RUN_COMMAND(magic_cmd + " " +  magic_helper_cmd)
186     print("magic differs test returned %d" % magic_ret)
187     pyret = samba_utils.RUN_PYTHON_TESTS(['test_pytalloc.py'])
188     print("python testsuite returned %d" % pyret)
189     sys.exit(ret or magic_ret or pyret)
190
191 def dist():
192     '''makes a tarball for distribution'''
193     samba_dist.dist()
194
195 def reconfigure(ctx):
196     '''reconfigure if config scripts have changed'''
197     import samba_utils
198     samba_utils.reconfigure(ctx)
199
200
201 def pydoctor(ctx):
202     '''build python apidocs'''
203     cmd='PYTHONPATH=bin/python pydoctor --project-name=talloc --project-url=http://talloc.samba.org/ --make-html --docformat=restructuredtext --introspect-c-modules --add-module bin/python/talloc.*'
204     print("Running: %s" % cmd)
205     os.system(cmd)