author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Mon, 12 Sep 2011 14:54:27 +0100 | |
changeset 7488 | 72d0c878f3c7 |
parent 7487 | 82cd20da9650 |
child 7489 | 994360413f55 |
permissions | -rw-r--r-- |
3408 | 1 |
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
2 |
import types |
3408 | 3 |
import re |
4 |
import os |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
5 |
import subprocess |
3408 | 6 |
import shutil |
3619
a97d3ed04035
Disable Python support on the CygWin platform, at least until/if the problems are fixed.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3612
diff
changeset
|
7 |
import sys |
3408 | 8 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
9 |
import Task |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
10 |
import Options |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
11 |
import Configure |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
12 |
import TaskGen |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
13 |
import Logs |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
14 |
import Build |
4066
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
15 |
import Utils |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
16 |
|
3408 | 17 |
## https://launchpad.net/pybindgen/ |
7408
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
18 |
REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 795) |
3408 | 19 |
REQUIRED_PYGCCXML_VERSION = (0, 9, 5) |
20 |
||
21 |
||
6137
86045031f03a
Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6134
diff
changeset
|
22 |
|
86045031f03a
Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6134
diff
changeset
|
23 |
from TaskGen import feature, after |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
24 |
import Task |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
25 |
#from python import _get_python_variables # this comes from wafadmin/Tools/python.py |
6137
86045031f03a
Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6134
diff
changeset
|
26 |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
27 |
if 0: |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
28 |
# Patch a bug in waf-1.5.16's python detection, see |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
29 |
# https://www.nsnam.org/bugzilla/show_bug.cgi?id=1250 |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
30 |
import python |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
31 |
python.FRAG_2 = """ |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
32 |
#include <Python.h> |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
33 |
""" + python.FRAG_2 |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
34 |
del python |
7462
287082f2be5c
Bug 1250 - waf configure do not check for Python.h (python-dev)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7451
diff
changeset
|
35 |
|
287082f2be5c
Bug 1250 - waf configure do not check for Python.h (python-dev)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7451
diff
changeset
|
36 |
|
6137
86045031f03a
Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6134
diff
changeset
|
37 |
|
3873
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
38 |
def add_to_python_path(path): |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
39 |
if os.environ.get('PYTHONPATH', ''): |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
40 |
os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH') |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
41 |
else: |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
42 |
os.environ['PYTHONPATH'] = path |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
43 |
|
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
44 |
def set_pybindgen_pythonpath(env): |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
45 |
if env['WITH_PYBINDGEN']: |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
46 |
add_to_python_path(env['WITH_PYBINDGEN']) |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
47 |
|
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
48 |
|
7488
72d0c878f3c7
More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7487
diff
changeset
|
49 |
def options(opt): |
3408 | 50 |
opt.tool_options('python') |
3637
a6d8bf62a61d
For better consistency, option --nsc becomes --enable-nsc, --python-disable becomes --disable-python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3625
diff
changeset
|
51 |
opt.add_option('--disable-python', |
3408 | 52 |
help=("Don't build Python bindings."), |
53 |
action="store_true", default=False, |
|
54 |
dest='python_disable') |
|
55 |
opt.add_option('--python-scan', |
|
56 |
help=("Rescan Python bindings. Needs working GCCXML / pygccxml environment."), |
|
57 |
action="store_true", default=False, |
|
58 |
dest='python_scan') |
|
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
59 |
opt.add_option('--apiscan', |
6923
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
60 |
help=("EXPERIMENTAL: Rescan the API for the indicated module(s), for Python bindings. " |
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
61 |
"Needs working GCCXML / pygccxml environment. " |
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
62 |
"The metamodule 'all' expands to all available ns-3 modules."), |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
63 |
default=None, dest='apiscan', metavar="MODULE[,MODULE...]") |
3873
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
64 |
opt.add_option('--with-pybindgen', |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
65 |
help=('Path to an existing pybindgen source tree to use.'), |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
66 |
default=None, |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
67 |
dest='with_pybindgen', type="string") |
3408 | 68 |
|
69 |
||
70 |
def configure(conf): |
|
71 |
conf.env['ENABLE_PYTHON_BINDINGS'] = False |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
72 |
if Options.options.python_disable: |
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
73 |
conf.report_optional_feature("python", "Python Bindings", False, |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
74 |
"disabled by user request") |
3408 | 75 |
return |
7468
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
76 |
# Disable python in static builds (bug #1253) |
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
77 |
if ((conf.env['ENABLE_STATIC_NS3']) or \ |
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
78 |
(conf.env['ENABLE_SHARED_AND_STATIC_NS3'])): |
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
79 |
conf.report_optional_feature("python", "Python Bindings", False, |
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
80 |
"bindings incompatible with static build") |
7b8dfd1b02f6
Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents:
7462
diff
changeset
|
81 |
return |
3408 | 82 |
|
6919
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
83 |
enabled_modules = list(conf.env['NS3_ENABLED_MODULES']) |
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
84 |
enabled_modules.sort() |
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
85 |
available_modules = list(conf.env['NS3_MODULES']) |
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
86 |
available_modules.sort() |
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
87 |
all_modules_enabled = (enabled_modules == available_modules) |
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
88 |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
89 |
conf.check_tool('misc', tooldir=['waf-tools']) |
3408 | 90 |
|
5251
306856feb249
Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5249
diff
changeset
|
91 |
if sys.platform == 'cygwin': |
306856feb249
Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5249
diff
changeset
|
92 |
conf.report_optional_feature("python", "Python Bindings", False, |
306856feb249
Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5249
diff
changeset
|
93 |
"unsupported platform 'cygwin'") |
306856feb249
Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5249
diff
changeset
|
94 |
Logs.warn("Python is not supported in CygWin environment. Try MingW instead.") |
306856feb249
Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5249
diff
changeset
|
95 |
return |
3619
a97d3ed04035
Disable Python support on the CygWin platform, at least until/if the problems are fixed.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3612
diff
changeset
|
96 |
|
3408 | 97 |
## Check for Python |
98 |
try: |
|
99 |
conf.check_tool('python') |
|
3473
6bce86ea4778
Require new PyBindGen; make it work for Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3468
diff
changeset
|
100 |
conf.check_python_version((2,3)) |
3408 | 101 |
conf.check_python_headers() |
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
102 |
except Configure.ConfigurationError, ex: |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
103 |
conf.report_optional_feature("python", "Python Bindings", False, str(ex)) |
3408 | 104 |
return |
105 |
||
7363
0f96f5beb8c7
Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7348
diff
changeset
|
106 |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
107 |
if 0: |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
108 |
# alternative code to computing PYTHONDIR, that is more correct than the one in waf 1.5.16 |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
109 |
if 'PYTHONDIR' in conf.environ: |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
110 |
pydir = conf.environ['PYTHONDIR'] |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
111 |
else: |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
112 |
(pydir,) = _get_python_variables(conf.env['PYTHON'], |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
113 |
["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r)" % conf.env['PREFIX']], |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
114 |
['from distutils.sysconfig import get_python_lib']) |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
115 |
if hasattr(conf, 'define'): # conf.define is added by the C tool, so may not exist |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
116 |
conf.define('PYTHONDIR', pydir) |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
117 |
conf.env['PYTHONDIR'] = pydir |
7363
0f96f5beb8c7
Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7348
diff
changeset
|
118 |
|
0f96f5beb8c7
Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7348
diff
changeset
|
119 |
|
4253
732b877beb23
Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4196
diff
changeset
|
120 |
# -fvisibility=hidden optimization |
4430
4a527879c7ab
Fix Python bindings build with gcc < 4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4395
diff
changeset
|
121 |
if (conf.env['CXX_NAME'] == 'gcc' and [int(x) for x in conf.env['CC_VERSION']] >= [4,0,0] |
4a527879c7ab
Fix Python bindings build with gcc < 4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4395
diff
changeset
|
122 |
and conf.check_compilation_flag('-fvisibility=hidden')): |
4253
732b877beb23
Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4196
diff
changeset
|
123 |
conf.env.append_value('CXXFLAGS_PYEXT', '-fvisibility=hidden') |
732b877beb23
Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4196
diff
changeset
|
124 |
conf.env.append_value('CCFLAGS_PYEXT', '-fvisibility=hidden') |
732b877beb23
Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4196
diff
changeset
|
125 |
|
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
126 |
# Check for the location of pybindgen |
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
127 |
if Options.options.with_pybindgen is not None: |
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
128 |
if os.path.isdir(Options.options.with_pybindgen): |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
129 |
conf.msg("Checking for pybindgen location", ("%s (given)" % Options.options.with_pybindgen)) |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
130 |
conf.env['WITH_PYBINDGEN'] = os.path.abspath(Options.options.with_pybindgen) |
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
131 |
else: |
6591
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
132 |
# ns-3-dev uses ../pybindgen, while ns-3 releases use ../REQUIRED_PYBINDGEN_VERSION |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
133 |
pybindgen_dir = os.path.join('..', "pybindgen") |
6591
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
134 |
pybindgen_release_str = "pybindgen-" + '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]) |
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
135 |
pybindgen_release_dir = os.path.join('..', pybindgen_release_str) |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
136 |
if os.path.isdir(pybindgen_dir): |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
137 |
conf.msg("Checking for pybindgen location", ("%s (guessed)" % pybindgen_dir)) |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
138 |
conf.env['WITH_PYBINDGEN'] = os.path.abspath(pybindgen_dir) |
6591
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
139 |
elif os.path.isdir(pybindgen_release_dir): |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
140 |
conf.msg("Checking for pybindgen location", ("%s (guessed)" % pybindgen_release_dir)) |
6591
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
141 |
conf.env['WITH_PYBINDGEN'] = os.path.abspath(pybindgen_release_dir) |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
142 |
del pybindgen_dir |
6591
174d88119ebf
Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents:
6574
diff
changeset
|
143 |
del pybindgen_release_dir |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
144 |
if not conf.env['WITH_PYBINDGEN']: |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
145 |
conf.msg("pybindgen location", False) |
3873
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
146 |
|
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
147 |
# Check for pybindgen |
3873
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
148 |
|
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
149 |
set_pybindgen_pythonpath(conf.env) |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
150 |
|
3408 | 151 |
try: |
152 |
conf.check_python_module('pybindgen') |
|
153 |
except Configure.ConfigurationError: |
|
4077
d2e461e575f4
Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4076
diff
changeset
|
154 |
Logs.warn("pybindgen missing => no python bindings") |
d2e461e575f4
Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4076
diff
changeset
|
155 |
conf.report_optional_feature("python", "Python Bindings", False, |
d2e461e575f4
Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4076
diff
changeset
|
156 |
"PyBindGen missing") |
4082
048db3e90b9b
Bug 467: waf configure enables python after detecting pybindgen is missing
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4077
diff
changeset
|
157 |
return |
3408 | 158 |
else: |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
159 |
out = subprocess.Popen([conf.env['PYTHON'][0], "-c", |
3408 | 160 |
"import pybindgen.version; " |
161 |
"print '.'.join([str(x) for x in pybindgen.version.__version__])"], |
|
162 |
stdout=subprocess.PIPE).communicate()[0] |
|
163 |
pybindgen_version_str = out.strip() |
|
164 |
pybindgen_version = tuple([int(x) for x in pybindgen_version_str.split('.')]) |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
165 |
conf.msg('Checking for pybindgen version', pybindgen_version_str) |
4457
1b45505f9a52
Don't allow pybindgen version greater than our requested version, to avoid python scanning generating backward incompatible API defs.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4440
diff
changeset
|
166 |
if not (pybindgen_version == REQUIRED_PYBINDGEN_VERSION): |
1b45505f9a52
Don't allow pybindgen version greater than our requested version, to avoid python scanning generating backward incompatible API defs.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4440
diff
changeset
|
167 |
Logs.warn("pybindgen (found %s), (need %s)" % |
3408 | 168 |
(pybindgen_version_str, |
169 |
'.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]))) |
|
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
170 |
conf.report_optional_feature("python", "Python Bindings", False, |
4457
1b45505f9a52
Don't allow pybindgen version greater than our requested version, to avoid python scanning generating backward incompatible API defs.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4440
diff
changeset
|
171 |
"PyBindGen version not correct and newer version could not be retrieved") |
4116
6f8542536217
Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4104
diff
changeset
|
172 |
return |
3408 | 173 |
|
5767
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
174 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
175 |
def test(t1, t2): |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
176 |
test_program = ''' |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
177 |
#include <stdint.h> |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
178 |
#include <vector> |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
179 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
180 |
int main () |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
181 |
{ |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
182 |
std::vector< %(type1)s > t = std::vector< %(type2)s > (); |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
183 |
return 0; |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
184 |
} |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
185 |
''' % dict(type1=t1, type2=t2) |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
186 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
187 |
try: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
188 |
ret = conf.run_c_code(code=test_program, |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
189 |
env=conf.env.copy(), compile_filename='test.cc', |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
190 |
features='cxx cprogram', execute=False) |
5767
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
191 |
except Configure.ConfigurationError: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
192 |
ret = 1 |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
193 |
conf.msg('Checking for types %s and %s equivalence' % (t1, t2), (ret and 'no' or 'yes')) |
5767
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
194 |
return not ret |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
195 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
196 |
uint64_is_long = test("uint64_t", "unsigned long") |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
197 |
uint64_is_long_long = test("uint64_t", "unsigned long long") |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
198 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
199 |
if uint64_is_long: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
200 |
conf.env['PYTHON_BINDINGS_APIDEFS'] = 'gcc-LP64' |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
201 |
elif uint64_is_long_long: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
202 |
conf.env['PYTHON_BINDINGS_APIDEFS'] = 'gcc-ILP32' |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
203 |
else: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
204 |
conf.env['PYTHON_BINDINGS_APIDEFS'] = None |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
205 |
if conf.env['PYTHON_BINDINGS_APIDEFS'] is None: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
206 |
msg = 'none available' |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
207 |
else: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
208 |
msg = conf.env['PYTHON_BINDINGS_APIDEFS'] |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
209 |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
210 |
conf.msg('Checking for the apidefs that can be used for Python bindings', msg) |
5767
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
211 |
|
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
212 |
if conf.env['PYTHON_BINDINGS_APIDEFS'] is None: |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
213 |
conf.report_optional_feature("python", "Python Bindings", False, |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
214 |
"No apidefs are available that can be used in this system") |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
215 |
return |
0c70949a5006
Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5753
diff
changeset
|
216 |
|
6919
82217d4007bc
Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6918
diff
changeset
|
217 |
|
3408 | 218 |
## If all has gone well, we finally enable the Python bindings |
219 |
conf.env['ENABLE_PYTHON_BINDINGS'] = True |
|
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
220 |
conf.report_optional_feature("python", "Python Bindings", True, None) |
3408 | 221 |
|
7408
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
222 |
|
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
223 |
# check cxxabi stuff (which Mac OS X Lion breaks) |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
224 |
fragment = r""" |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
225 |
# include <cxxabi.h> |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
226 |
int main () |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
227 |
{ |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
228 |
const abi::__si_class_type_info *_typeinfo __attribute__((unused)) = NULL; |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
229 |
return 0; |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
230 |
} |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
231 |
""" |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
232 |
gcc_rtti_abi = conf.check_nonfatal(fragment=fragment, msg="Checking for internal GCC cxxabi", |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
233 |
okmsg="complete", errmsg='incomplete', |
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
234 |
mandatory=False) |
7408
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
235 |
conf.env["GCC_RTTI_ABI_COMPLETE"] = str(bool(gcc_rtti_abi)) |
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
236 |
|
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
237 |
|
4f1f961b6cdc
Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7373
diff
changeset
|
238 |
|
3408 | 239 |
## Check for pygccxml |
240 |
try: |
|
241 |
conf.check_python_module('pygccxml') |
|
242 |
except Configure.ConfigurationError: |
|
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
243 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
244 |
"Missing 'pygccxml' Python module") |
3408 | 245 |
return |
246 |
||
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
247 |
out = subprocess.Popen([conf.env['PYTHON'][0], "-c", |
3408 | 248 |
"import pygccxml; print pygccxml.__version__"], |
249 |
stdout=subprocess.PIPE).communicate()[0] |
|
250 |
pygccxml_version_str = out.strip() |
|
251 |
pygccxml_version = tuple([int(x) for x in pygccxml_version_str.split('.')]) |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
252 |
conf.msg('Checking for pygccxml version', pygccxml_version_str) |
3408 | 253 |
if not (pygccxml_version >= REQUIRED_PYGCCXML_VERSION): |
4067
165b38956c24
Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4066
diff
changeset
|
254 |
Logs.warn("pygccxml (found %s) is too old (need %s) => " |
3408 | 255 |
"automatic scanning of API definitions will not be possible" % |
256 |
(pygccxml_version_str, |
|
257 |
'.'.join([str(x) for x in REQUIRED_PYGCCXML_VERSION]))) |
|
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
258 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
259 |
"pygccxml too old") |
3408 | 260 |
return |
261 |
||
262 |
||
263 |
## Check gccxml version |
|
264 |
gccxml = conf.find_program('gccxml', var='GCCXML') |
|
265 |
if not gccxml: |
|
4067
165b38956c24
Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4066
diff
changeset
|
266 |
Logs.warn("gccxml missing; automatic scanning of API definitions will not be possible") |
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
267 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
268 |
"gccxml missing") |
3408 | 269 |
return |
270 |
||
271 |
gccxml_version_line = os.popen(gccxml + " --version").readline().strip() |
|
272 |
m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line) |
|
273 |
gccxml_version = m.group(1) |
|
274 |
gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9]) |
|
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
275 |
conf.msg('Checking for gccxml version', gccxml_version) |
3408 | 276 |
if not gccxml_version_ok: |
4067
165b38956c24
Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4066
diff
changeset
|
277 |
Logs.warn("gccxml too old, need version >= 0.9; automatic scanning of API definitions will not be possible") |
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
278 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", False, |
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
279 |
"gccxml too old") |
3408 | 280 |
return |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
281 |
|
3408 | 282 |
## If we reached |
283 |
conf.env['ENABLE_PYTHON_SCANNING'] = True |
|
3625
30afad8324d5
Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3624
diff
changeset
|
284 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", True, None) |
3408 | 285 |
|
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
286 |
# --------------------- |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
287 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
288 |
def get_headers_map(bld): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
289 |
headers_map = {} # header => module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
290 |
for ns3headers in bld.all_task_gen: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
291 |
if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare |
6970
d00c79a3cf1f
Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6961
diff
changeset
|
292 |
if ns3headers.module.endswith('-test'): |
d00c79a3cf1f
Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6961
diff
changeset
|
293 |
continue |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
294 |
for h in ns3headers.to_list(ns3headers.source): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
295 |
headers_map[os.path.basename(h)] = ns3headers.module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
296 |
return headers_map |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
297 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
298 |
def get_module_path(bld, module): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
299 |
for ns3headers in bld.all_task_gen: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
300 |
if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
301 |
if ns3headers.module == module: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
302 |
break |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
303 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
304 |
else: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
305 |
raise ValueError("Module %r not found" % module) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
306 |
return ns3headers.path.abspath() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
307 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
308 |
class apiscan_task(Task.TaskBase): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
309 |
"""Uses gccxml to scan the file 'everything.h' and extract API definitions. |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
310 |
""" |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
311 |
after = 'gen_ns3_module_header ns3header' |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
312 |
before = 'cc cxx gchx' |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
313 |
color = "BLUE" |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
314 |
def __init__(self, curdirnode, env, bld, target, cflags, module): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
315 |
self.bld = bld |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
316 |
super(apiscan_task, self).__init__(generator=self) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
317 |
self.curdirnode = curdirnode |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
318 |
self.env = env |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
319 |
self.target = target |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
320 |
self.cflags = cflags |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
321 |
self.module = module |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
322 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
323 |
def display(self): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
324 |
return 'api-scan-%s\n' % (self.target,) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
325 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
326 |
def run(self): |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
327 |
top_builddir = self.curdirnode.find_dir('../..').abspath(self.env) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
328 |
module_path = get_module_path(self.bld, self.module) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
329 |
headers_map = get_headers_map(self.bld) |
6926
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
330 |
scan_header = os.path.join(top_builddir, "ns3", "%s-module.h" % self.module) |
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
331 |
|
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
332 |
if not os.path.exists(scan_header): |
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
333 |
Logs.error("Cannot apiscan module %r: %s does not exist" % (self.module, scan_header)) |
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
334 |
return 0 |
1b32cc1532a9
Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6923
diff
changeset
|
335 |
|
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
336 |
argv = [ |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
337 |
self.env['PYTHON'], |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
338 |
os.path.join(self.curdirnode.abspath(), 'ns3modulescan-modular.py'), # scanning script |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
339 |
top_builddir, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
340 |
self.module, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
341 |
repr(get_headers_map(self.bld)), |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
342 |
os.path.join(module_path, "bindings", 'modulegen__%s.py' % (self.target)), # output file |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
343 |
self.cflags, |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
344 |
] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
345 |
scan = subprocess.Popen(argv, stdin=subprocess.PIPE) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
346 |
retval = scan.wait() |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
347 |
return retval |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
348 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
349 |
|
4326
179f86838e62
Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4312
diff
changeset
|
350 |
def get_modules_and_headers(bld): |
3408 | 351 |
""" |
352 |
Gets a dict of |
|
353 |
module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...]) |
|
354 |
tuples, one for each module. |
|
355 |
""" |
|
356 |
||
357 |
retval = {} |
|
4326
179f86838e62
Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4312
diff
changeset
|
358 |
for module in bld.all_task_gen: |
3408 | 359 |
if not module.name.startswith('ns3-'): |
360 |
continue |
|
6970
d00c79a3cf1f
Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6961
diff
changeset
|
361 |
if module.name.endswith('-test'): |
d00c79a3cf1f
Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6961
diff
changeset
|
362 |
continue |
3408 | 363 |
module_name = module.name[4:] # strip the ns3- prefix |
364 |
## find the headers object for this module |
|
365 |
headers = [] |
|
4326
179f86838e62
Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4312
diff
changeset
|
366 |
for ns3headers in bld.all_task_gen: |
3408 | 367 |
if type(ns3headers).__name__ != 'ns3header_taskgen': # XXX: find less hackish way to compare |
368 |
continue |
|
369 |
if ns3headers.module != module_name: |
|
370 |
continue |
|
371 |
for source in ns3headers.to_list(ns3headers.source): |
|
6797
613a82415ae3
Fix Python scanning to allow apidefs to be placed on the right module instead of the main ns3module.cc file, for new-style modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
372 |
headers.append(os.path.basename(source)) |
3408 | 373 |
retval[module_name] = (list(module.module_deps), headers) |
374 |
return retval |
|
375 |
||
376 |
||
3541
15fe83e15ff5
Don't scan python bindings until the everything.h file to be scanned is generated. Closes #288.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3540
diff
changeset
|
377 |
|
5249
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
378 |
|
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
379 |
class python_scan_task_collector(Task.TaskBase): |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
380 |
"""Tasks that waits for the python-scan-* tasks to complete and then signals WAF to exit |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
381 |
""" |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
382 |
after = 'apiscan' |
5249
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
383 |
before = 'cc cxx' |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
384 |
color = "BLUE" |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
385 |
def __init__(self, curdirnode, env, bld): |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
386 |
self.bld = bld |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
387 |
super(python_scan_task_collector, self).__init__(generator=self) |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
388 |
self.curdirnode = curdirnode |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
389 |
self.env = env |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
390 |
|
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
391 |
def display(self): |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
392 |
return 'python-scan-collector\n' |
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
393 |
|
85cde7d987ed
Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5203
diff
changeset
|
394 |
def run(self): |
4066
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
395 |
# signal stop (we generated files into the source dir and WAF |
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
396 |
# can't cope with it, so we have to force the user to restart |
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
397 |
# WAF) |
4326
179f86838e62
Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4312
diff
changeset
|
398 |
self.bld.generator.stop = 1 |
4066
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
399 |
return 0 |
d2309cf765d8
Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4064
diff
changeset
|
400 |
|
3541
15fe83e15ff5
Don't scan python bindings until the everything.h file to be scanned is generated. Closes #288.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3540
diff
changeset
|
401 |
|
6897
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
402 |
|
6961
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
403 |
class gen_ns3_compat_pymod_task(Task.Task): |
6897
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
404 |
"""Generates a 'ns3.py' compatibility module.""" |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
405 |
before = 'cc cxx gchx' |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
406 |
color = 'BLUE' |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
407 |
|
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
408 |
def run(self): |
6961
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
409 |
assert len(self.outputs) == 1 |
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
410 |
outfile = file(self.outputs[0].abspath(self.env), "w") |
6897
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
411 |
print >> outfile, "import warnings" |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
412 |
print >> outfile, 'warnings.warn("the ns3 module is a compatibility layer '\ |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
413 |
'and should not be used in newly written code", DeprecationWarning, stacklevel=2)' |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
414 |
print >> outfile |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
415 |
for module in self.bld.env['PYTHON_MODULES_BUILT']: |
6902
3aa6e43dfe41
Modular bindings: handle module names with hyphens
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6901
diff
changeset
|
416 |
print >> outfile, "from ns.%s import *" % (module.replace('-', '_')) |
6897
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
417 |
outfile.close() |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
418 |
return 0 |
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
419 |
|
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
420 |
|
f338f17b0238
Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6893
diff
changeset
|
421 |
|
3408 | 422 |
def build(bld): |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
423 |
if Options.options.python_disable: |
3408 | 424 |
return |
425 |
||
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
426 |
env = bld.env |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
427 |
curdir = bld.path.abspath() |
3591
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
428 |
|
3873
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
429 |
set_pybindgen_pythonpath(env) |
2ad80d9647f0
Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3868
diff
changeset
|
430 |
|
6960
2df22891346b
Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6957
diff
changeset
|
431 |
bld.new_task_gen(features='copy', |
2df22891346b
Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6957
diff
changeset
|
432 |
source="ns__init__.py", |
2df22891346b
Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6957
diff
changeset
|
433 |
target='ns/__init__.py') |
7348
9372b57a6ce4
Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7347
diff
changeset
|
434 |
bld.install_as('${PYTHONDIR}/ns/__init__.py', 'ns__init__.py') |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
435 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
436 |
if Options.options.apiscan: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
437 |
if not env['ENABLE_PYTHON_SCANNING']: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
438 |
raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available") |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
439 |
scan_targets = [] |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
440 |
if sys.platform == 'cygwin': |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
441 |
scan_targets.append(('gcc_cygwin', '')) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
442 |
else: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
443 |
import struct |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
444 |
if struct.calcsize('I') == 4 and struct.calcsize('L') == 8 and struct.calcsize('P') == 8: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
445 |
scan_targets.extend([('gcc_ILP32', '-m32'), ('gcc_LP64', '-m64')]) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
446 |
elif struct.calcsize('I') == 4 and struct.calcsize('L') == 4 and struct.calcsize('P') == 4: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
447 |
scan_targets.append(('gcc_ILP32', '')) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
448 |
else: |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
449 |
raise Utils.WafError("Cannot scan python bindings for unsupported data model") |
6927
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
450 |
|
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
451 |
test_module_path = bld.path.find_dir("../../src/test") |
6923
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
452 |
if Options.options.apiscan == 'all': |
6927
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
453 |
scan_modules = [] |
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
454 |
for mod in bld.all_task_gen: |
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
455 |
if not mod.name.startswith('ns3-'): |
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
456 |
continue |
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
457 |
if mod.path.is_child_of(test_module_path): |
1bde2ae9c25b
Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6926
diff
changeset
|
458 |
continue |
6928
c305a6f33912
./waf --apiscan=all: don't scan modules ending in -test
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6927
diff
changeset
|
459 |
if mod.name.endswith('-test'): |
c305a6f33912
./waf --apiscan=all: don't scan modules ending in -test
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6927
diff
changeset
|
460 |
continue |
6933
4bbaa92c3220
./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6928
diff
changeset
|
461 |
bindings_enabled = (mod.name in env.MODULAR_BINDINGS_MODULES) |
4bbaa92c3220
./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6928
diff
changeset
|
462 |
#print mod.name, bindings_enabled |
4bbaa92c3220
./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6928
diff
changeset
|
463 |
if bindings_enabled: |
4bbaa92c3220
./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6928
diff
changeset
|
464 |
scan_modules.append(mod.name.split('ns3-')[1]) |
6923
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
465 |
else: |
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
466 |
scan_modules = Options.options.apiscan.split(',') |
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
467 |
print "Modules to scan: ", scan_modules |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
468 |
for target, cflags in scan_targets: |
6923
57c9dfe52e67
Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6922
diff
changeset
|
469 |
for module in scan_modules: |
6874
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
470 |
apiscan_task(bld.path, env, bld, target, cflags, module) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
471 |
python_scan_task_collector(bld.path, env, bld) |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
472 |
return |
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
473 |
|
c7537e62f2fa
Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6591
diff
changeset
|
474 |
|
7470
234c01373116
Re-enable the 'ns3' compatility python module, previously accidentally disabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7468
diff
changeset
|
475 |
if env['ENABLE_PYTHON_BINDINGS']: |
7487
82cd20da9650
Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7470
diff
changeset
|
476 |
task = gen_ns3_compat_pymod_task(env=env) |
6961
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
477 |
task.set_outputs(bld.path.find_or_declare("ns3.py")) |
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
478 |
task.dep_vars = ['PYTHON_MODULES_BUILT'] |
ca0f33d08fd0
Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6960
diff
changeset
|
479 |
|
7451
7e112cf83737
Bug 1240 - remove monolithic python bindings from waf
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7408
diff
changeset
|
480 |
# note: the actual build commands for the python bindings are in |
7e112cf83737
Bug 1240 - remove monolithic python bindings from waf
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7408
diff
changeset
|
481 |
# src/wscript, not here. |
7e112cf83737
Bug 1240 - remove monolithic python bindings from waf
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
7408
diff
changeset
|
482 |