author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Mon, 29 Dec 2008 13:28:54 +0000 | |
changeset 4064 | 10222f483860 |
parent 3977 | 4daeb41d7fc1 |
child 4066 | d2309cf765d8 |
permissions | -rw-r--r-- |
3408 | 1 |
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
2 |
||
3 |
import re |
|
4 |
import os |
|
5 |
import pproc as subprocess |
|
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 |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
15 |
|
3408 | 16 |
## Adjust python path to look for our local copy of pybindgen |
17 |
LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen") |
|
18 |
#PYBINDGEN_BRANCH = 'lp:pybindgen' |
|
19 |
PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen' |
|
20 |
||
21 |
## https://launchpad.net/pybindgen/ |
|
3868
827884bf1356
Fix build of Python bindings with Python 2.6
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3855
diff
changeset
|
22 |
REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605) |
3408 | 23 |
REQUIRED_PYGCCXML_VERSION = (0, 9, 5) |
24 |
||
25 |
||
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
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
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
|
31 |
|
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
add_to_python_path(LOCAL_PYBINDGEN_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
|
37 |
|
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 |
|
3408 | 39 |
def set_options(opt): |
40 |
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
|
41 |
opt.add_option('--disable-python', |
3408 | 42 |
help=("Don't build Python bindings."), |
43 |
action="store_true", default=False, |
|
44 |
dest='python_disable') |
|
45 |
opt.add_option('--python-scan', |
|
46 |
help=("Rescan Python bindings. Needs working GCCXML / pygccxml environment."), |
|
47 |
action="store_true", default=False, |
|
48 |
dest='python_scan') |
|
49 |
opt.add_option('--pybindgen-checkout', |
|
50 |
help=("During configure, force checkout of pybingen inside ns-3, " |
|
51 |
"instead of using the system installed version."), |
|
52 |
action="store_true", default=False, |
|
53 |
dest='pybindgen_checkout') |
|
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
dest='with_pybindgen', type="string") |
3408 | 58 |
|
59 |
def fetch_pybindgen(conf): |
|
60 |
""" |
|
61 |
Fetches pybindgen from launchpad as bindings/python/pybindgen. |
|
62 |
Returns True if successful, False it not. |
|
63 |
""" |
|
64 |
bzr = conf.find_program("bzr") |
|
65 |
if not bzr: |
|
66 |
warning("the program 'bzr' is needed in order to fetch pybindgen") |
|
67 |
return False |
|
68 |
if len(REQUIRED_PYBINDGEN_VERSION) == 4: |
|
69 |
rev = "-rrevno:%i" % REQUIRED_PYBINDGEN_VERSION[3] |
|
70 |
else: |
|
71 |
rev = "-rtag:%s" % '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]) |
|
3719
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
72 |
|
3408 | 73 |
if os.path.exists(LOCAL_PYBINDGEN_PATH): |
3719
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
74 |
print "Trying to update pybindgen; this will fail if no network connection is available. Hit Ctrl-C to skip." |
3408 | 75 |
|
76 |
cmd = [bzr, "pull", rev, PYBINDGEN_BRANCH] |
|
77 |
print " => ", ' '.join(cmd) |
|
3719
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
78 |
try: |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
79 |
if subprocess.Popen(cmd, cwd=LOCAL_PYBINDGEN_PATH).wait(): |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
80 |
return False |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
81 |
except KeyboardInterrupt: |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
82 |
print "Interrupted; Python bindings will be disabled." |
3408 | 83 |
return False |
84 |
print "Update was successful." |
|
85 |
else: |
|
3719
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
86 |
print "Trying to fetch pybindgen; this will fail if no network connection is available. Hit Ctrl-C to skip." |
3408 | 87 |
cmd = [bzr, "checkout", rev, PYBINDGEN_BRANCH, LOCAL_PYBINDGEN_PATH] |
88 |
print " => ", ' '.join(cmd) |
|
3719
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
89 |
try: |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
90 |
if subprocess.Popen(cmd).wait(): |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
91 |
return False |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
92 |
except KeyboardInterrupt: |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
93 |
print "Interrupted; Python bindings will be disabled." |
3307abd75322
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3663
diff
changeset
|
94 |
shutil.rmtree(LOCAL_PYBINDGEN_PATH, True) |
3408 | 95 |
return False |
96 |
print "Fetch was successful." |
|
97 |
||
98 |
## generate a fake version.py file in pybindgen it's safer this |
|
99 |
## way, since the normal version generation process requires |
|
100 |
## bazaar python bindings, which may not be available. |
|
101 |
vfile = open(os.path.join(LOCAL_PYBINDGEN_PATH, "pybindgen", "version.py"), "wt") |
|
102 |
vfile.write(""" |
|
103 |
# (fake version generated by ns-3) |
|
104 |
__version__ = %r |
|
105 |
""" % list(REQUIRED_PYBINDGEN_VERSION)) |
|
106 |
vfile.close() |
|
107 |
||
108 |
return True |
|
109 |
||
110 |
||
111 |
def configure(conf): |
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
"disabled by user request") |
3408 | 116 |
return |
117 |
||
118 |
conf.check_tool('misc') |
|
119 |
||
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
|
120 |
if sys.platform == 'cygwin': |
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
|
121 |
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
|
122 |
"unsupported platform 'cygwin'") |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
123 |
Logs.warn("Python is not supported in CygWin environment. Try MingW instead.") |
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
|
124 |
return |
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
|
125 |
|
3408 | 126 |
## Check for Python |
127 |
try: |
|
128 |
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
|
129 |
conf.check_python_version((2,3)) |
3408 | 130 |
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
|
131 |
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
|
132 |
conf.report_optional_feature("python", "Python Bindings", False, str(ex)) |
3408 | 133 |
return |
134 |
||
3824
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
135 |
# Fix a bug with WAF and g++ 4.3.2 (it does not include "(GCC") in |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
136 |
# the output of g++ --version, so the WAF python detection fails |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
137 |
# to recognize it is gcc) |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
138 |
gcc_version = os.popen("%s --version" % conf.env['CXX']).readline() |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
139 |
if '(GCC)' in gcc_version or 'g++' in gcc_version: |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
140 |
conf.env.append_value('CXXFLAGS_PYEMBED','-fno-strict-aliasing') |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
141 |
conf.env.append_value('CXXFLAGS_PYEXT','-fno-strict-aliasing') |
c4acb0e1fd28
Work around a WAF bug in failing to recognize GCC while detecting CXXFLAGS for compiling Python extensions.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3755
diff
changeset
|
142 |
|
3408 | 143 |
## 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
|
144 |
|
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
|
145 |
no_net = False |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
146 |
if Options.options.with_pybindgen: |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
147 |
conf.env['WITH_PYBINDGEN'] = os.path.abspath(Options.options.with_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 |
no_net = True |
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 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
150 |
if Options.options.pybindgen_checkout: |
3408 | 151 |
fetch_pybindgen(conf) |
152 |
||
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
|
153 |
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
|
154 |
|
3408 | 155 |
try: |
156 |
conf.check_python_module('pybindgen') |
|
157 |
except Configure.ConfigurationError: |
|
158 |
warning("pybindgen missing") |
|
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
|
159 |
if no_net or not fetch_pybindgen(conf): |
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
|
160 |
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
|
161 |
"PyBindGen missing and could not be retrieved") |
3408 | 162 |
return |
163 |
else: |
|
164 |
out = subprocess.Popen([conf.env['PYTHON'], "-c", |
|
165 |
"import pybindgen.version; " |
|
166 |
"print '.'.join([str(x) for x in pybindgen.version.__version__])"], |
|
167 |
stdout=subprocess.PIPE).communicate()[0] |
|
168 |
pybindgen_version_str = out.strip() |
|
169 |
pybindgen_version = tuple([int(x) for x in pybindgen_version_str.split('.')]) |
|
170 |
conf.check_message('pybindgen', 'version', |
|
171 |
(pybindgen_version >= REQUIRED_PYBINDGEN_VERSION), |
|
172 |
pybindgen_version_str) |
|
173 |
if not (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION): |
|
174 |
warning("pybindgen (found %s) is too old (need %s)" % |
|
175 |
(pybindgen_version_str, |
|
176 |
'.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]))) |
|
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
|
177 |
if no_net or not fetch_pybindgen(conf): |
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
|
178 |
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
|
179 |
"PyBindGen too old and newer version could not be retrieved") |
3408 | 180 |
return |
181 |
||
182 |
## If all has gone well, we finally enable the Python bindings |
|
183 |
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
|
184 |
conf.report_optional_feature("python", "Python Bindings", True, None) |
3408 | 185 |
|
186 |
## Check for pygccxml |
|
187 |
try: |
|
188 |
conf.check_python_module('pygccxml') |
|
189 |
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
|
190 |
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
|
191 |
"Missing 'pygccxml' Python module") |
3408 | 192 |
return |
193 |
||
194 |
out = subprocess.Popen([conf.env['PYTHON'], "-c", |
|
195 |
"import pygccxml; print pygccxml.__version__"], |
|
196 |
stdout=subprocess.PIPE).communicate()[0] |
|
197 |
pygccxml_version_str = out.strip() |
|
198 |
pygccxml_version = tuple([int(x) for x in pygccxml_version_str.split('.')]) |
|
199 |
conf.check_message('pygccxml', 'version', |
|
200 |
(pygccxml_version >= REQUIRED_PYGCCXML_VERSION), |
|
201 |
pygccxml_version_str) |
|
202 |
if not (pygccxml_version >= REQUIRED_PYGCCXML_VERSION): |
|
203 |
warning("pygccxml (found %s) is too old (need %s) => " |
|
204 |
"automatic scanning of API definitions will not be possible" % |
|
205 |
(pygccxml_version_str, |
|
206 |
'.'.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
|
207 |
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
|
208 |
"pygccxml too old") |
3408 | 209 |
return |
210 |
||
211 |
||
212 |
## Check gccxml version |
|
213 |
gccxml = conf.find_program('gccxml', var='GCCXML') |
|
214 |
if not gccxml: |
|
215 |
warning("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
|
216 |
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
|
217 |
"gccxml missing") |
3408 | 218 |
return |
219 |
||
220 |
gccxml_version_line = os.popen(gccxml + " --version").readline().strip() |
|
221 |
m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line) |
|
222 |
gccxml_version = m.group(1) |
|
223 |
gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9]) |
|
224 |
conf.check_message('gccxml', 'version', True, gccxml_version) |
|
225 |
if not gccxml_version_ok: |
|
226 |
warning("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
|
227 |
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
|
228 |
"gccxml too old") |
3408 | 229 |
return |
230 |
||
231 |
## If we reached |
|
232 |
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
|
233 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", True, None) |
3408 | 234 |
|
235 |
||
236 |
prio_headers = { |
|
237 |
-2: ( |
|
238 |
"string.h", # work around http://www.gccxml.org/Bug/view.php?id=6682 |
|
239 |
), |
|
240 |
-1: ( |
|
241 |
"propagation-delay-model.h", |
|
242 |
"propagation-loss-model.h", |
|
243 |
"net-device.h", |
|
244 |
) |
|
245 |
} |
|
246 |
||
247 |
def get_header_prio(header): |
|
248 |
for prio, headers in prio_headers.iteritems(): |
|
249 |
if header in headers: |
|
250 |
return prio |
|
251 |
return 1 |
|
252 |
||
3485
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
253 |
|
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
254 |
def calc_header_include(path): |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
255 |
(head, tail) = os.path.split (path) |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
256 |
if tail == 'ns3': |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
257 |
return '' |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
258 |
else: |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
259 |
return os.path.join (calc_header_include (head), tail) |
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
260 |
|
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
261 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
262 |
class gen_everything_h_task(Task.Task): |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
263 |
before = 'cc cxx' |
3485
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
264 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
265 |
def run(self): |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
266 |
assert len(self.outputs) == 1 |
3408 | 267 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
268 |
header_files = [calc_header_include(node.abspath(self.env)) for node in self.inputs] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
269 |
outfile = file(self.outputs[0].bldpath(self.env), "w") |
3408 | 270 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
271 |
def sort_func(h1, h2): |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
272 |
return cmp((get_header_prio(h1), h1), (get_header_prio(h1), h2)) |
3408 | 273 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
274 |
header_files.sort(sort_func) |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
275 |
|
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
276 |
print >> outfile, """ |
3917
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
277 |
|
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
278 |
/* http://www.nsnam.org/bugzilla/show_bug.cgi?id=413 */ |
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
279 |
#ifdef ECHO |
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
280 |
# undef ECHO |
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
281 |
#endif |
fe95a4f9d423
Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3875
diff
changeset
|
282 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
283 |
""" |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
284 |
for header in header_files: |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
285 |
print >> outfile, "#include \"ns3/%s\"" % (header,) |
3408 | 286 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
287 |
print >> outfile, """ |
3408 | 288 |
namespace ns3 { |
289 |
static inline Ptr<Object> |
|
290 |
__dummy_function_to_force_template_instantiation (Ptr<Object> obj, TypeId typeId) |
|
291 |
{ |
|
292 |
return obj->GetObject<Object> (typeId); |
|
293 |
} |
|
294 |
||
3731
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
295 |
|
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
296 |
static inline void |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
297 |
__dummy_function_to_force_template_instantiation_v2 () |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
298 |
{ |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
299 |
Time t1, t2, t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
300 |
t1 = t2 + t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
301 |
t1 = t2 - t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
302 |
TimeSquare tsq = t2*t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
303 |
Time tsqdiv = tsq/Seconds(1); |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
304 |
Scalar scal = t2/t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
305 |
TimeInvert inv = scal/t3; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
306 |
t1 = scal*t1; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
307 |
t1 = t1/scal; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
308 |
t1 < t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
309 |
t1 <= t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
310 |
t1 == t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
311 |
t1 != t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
312 |
t1 >= t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
313 |
t1 > t2; |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
314 |
} |
317f9dbccc2b
New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3728
diff
changeset
|
315 |
|
3929
909b0a724ed3
Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3917
diff
changeset
|
316 |
|
3408 | 317 |
} |
318 |
""" |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
319 |
outfile.close() |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
320 |
return 0 |
3408 | 321 |
|
322 |
||
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
|
323 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
324 |
class all_ns3_headers_taskgen(TaskGen.task_gen): |
3408 | 325 |
"""Generates a 'everything.h' header file that includes some/all public ns3 headers. |
326 |
This single header file is to be parsed only once by gccxml, for greater efficiency. |
|
327 |
""" |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
328 |
def __init__(self, *args, **kwargs): |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
329 |
super(all_ns3_headers_taskgen, self).__init__(*args, **kwargs) |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
330 |
self.install_path = None |
3409
94ac3e381075
The 'everything.h' header file is only used for Python bindings and should be generated into bindings/python/, not ns3/.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3408
diff
changeset
|
331 |
#self.inst_dir = 'ns3' |
3408 | 332 |
|
333 |
def apply(self): |
|
334 |
## get all of the ns3 headers |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
335 |
ns3_dir_node = Build.bld.path.find_dir("ns3") |
3408 | 336 |
all_headers_inputs = [] |
337 |
||
338 |
for filename in self.to_list(self.source): |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
339 |
src_node = ns3_dir_node.find_or_declare(filename) |
3408 | 340 |
if src_node is None: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
341 |
raise Utils.WafError("source ns3 header file %s not found" % (filename,)) |
3408 | 342 |
all_headers_inputs.append(src_node) |
343 |
||
344 |
## if self.source was empty, include all ns3 headers in enabled modules |
|
345 |
if not all_headers_inputs: |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
346 |
for ns3headers in Build.bld.all_task_gen: |
3408 | 347 |
if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare |
348 |
## skip headers not part of enabled modules |
|
349 |
if self.env['NS3_ENABLED_MODULES']: |
|
350 |
if ("ns3-%s" % ns3headers.module) not in self.env['NS3_ENABLED_MODULES']: |
|
351 |
continue |
|
352 |
||
353 |
for source in ns3headers.to_list(ns3headers.source): |
|
3485
26de1421d000
When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3474
diff
changeset
|
354 |
#source = os.path.basename(source) |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
355 |
node = ns3_dir_node.find_or_declare(source) |
3408 | 356 |
if node is None: |
357 |
fatal("missing header file %s" % (source,)) |
|
358 |
all_headers_inputs.append(node) |
|
359 |
assert all_headers_inputs |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
360 |
all_headers_outputs = [self.path.find_or_declare("everything.h")] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
361 |
task = self.create_task('gen_everything_h', self.env) |
3408 | 362 |
task.set_inputs(all_headers_inputs) |
363 |
task.set_outputs(all_headers_outputs) |
|
364 |
||
365 |
def install(self): |
|
366 |
pass |
|
367 |
||
368 |
||
369 |
def get_modules_and_headers(): |
|
370 |
""" |
|
371 |
Gets a dict of |
|
372 |
module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...]) |
|
373 |
tuples, one for each module. |
|
374 |
""" |
|
375 |
||
376 |
retval = {} |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
377 |
for module in Build.bld.all_task_gen: |
3408 | 378 |
if not module.name.startswith('ns3-'): |
379 |
continue |
|
380 |
module_name = module.name[4:] # strip the ns3- prefix |
|
381 |
## find the headers object for this module |
|
382 |
headers = [] |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
383 |
for ns3headers in Build.bld.all_task_gen: |
3408 | 384 |
if type(ns3headers).__name__ != 'ns3header_taskgen': # XXX: find less hackish way to compare |
385 |
continue |
|
386 |
if ns3headers.module != module_name: |
|
387 |
continue |
|
388 |
for source in ns3headers.to_list(ns3headers.source): |
|
389 |
headers.append(source) |
|
390 |
retval[module_name] = (list(module.module_deps), headers) |
|
391 |
return retval |
|
392 |
||
393 |
||
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
|
394 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
395 |
class python_scan_task(Task.TaskBase): |
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
|
396 |
"""Uses gccxml to scan the file 'everything.h' and extract API definitions. |
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
|
397 |
""" |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
398 |
after = 'gen_everything_h' |
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
|
399 |
def __init__(self, curdirnode, env): |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
400 |
super(python_scan_task, self).__init__() |
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 |
self.curdirnode = curdirnode |
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
|
402 |
self.env = env |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
403 |
self.display = 'python-scan\n' |
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
|
404 |
|
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
|
405 |
def run(self): |
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
|
406 |
#print "Rescanning the python bindings..." |
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
|
407 |
argv = [ |
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
|
408 |
self.env['PYTHON'], |
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
|
409 |
os.path.join(self.curdirnode.abspath(), 'ns3modulescan.py'), # scanning script |
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
|
410 |
self.curdirnode.find_dir('../..').abspath(self.env), # include path (where the ns3 include dir is) |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
411 |
self.curdirnode.find_or_declare('everything.h').abspath(self.env), |
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
|
412 |
os.path.join(self.curdirnode.abspath(), 'ns3modulegen_generated.py'), # output file |
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
|
413 |
] |
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
|
414 |
scan = subprocess.Popen(argv, stdin=subprocess.PIPE) |
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
|
415 |
scan.stdin.write(repr(get_modules_and_headers())) |
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
|
416 |
scan.stdin.close() |
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
|
417 |
if scan.wait(): |
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
|
418 |
raise SystemExit(1) |
3726
d5a2890666e3
Exit WAF after processing --python-scan to avoid incorrect builds, since WAF does not handle well files being generated into the source dir instead of the build dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3721
diff
changeset
|
419 |
raise SystemExit(0) |
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
|
420 |
|
3408 | 421 |
def build(bld): |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
422 |
if Options.options.python_disable: |
3408 | 423 |
return |
424 |
||
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
425 |
env = bld.env |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
426 |
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
|
427 |
|
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
|
428 |
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
|
429 |
|
3408 | 430 |
#Object.register('all-ns3-headers', AllNs3Headers) |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
431 |
#Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE') |
3408 | 432 |
|
3486
818a6bbef490
Only generate everything.h if python bindings are enabled. Based on patch by Mathieu Lacage. Closes #260.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3485
diff
changeset
|
433 |
if env['ENABLE_PYTHON_BINDINGS']: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
434 |
obj = bld.new_task_gen('all_ns3_headers') |
3408 | 435 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
436 |
if Options.options.python_scan: |
3408 | 437 |
if not env['ENABLE_PYTHON_SCANNING']: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
438 |
raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available") |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
439 |
PythonScanTask(bld.path, env) |
3408 | 440 |
|
3424
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
441 |
## Get a list of scanned modules; the set of scanned modules |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
442 |
## may be smaller than the set of all modules, in case a new |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
443 |
## ns3 module is being developed which wasn't scanned yet. |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
444 |
scanned_modules = [] |
3591
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
445 |
for filename in os.listdir(curdir): |
3424
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
446 |
m = re.match(r"^ns3_module_(.+)\.py$", filename) |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
447 |
if m is None: |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
448 |
continue |
3591
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
449 |
name = m.group(1) |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
450 |
if name.endswith("__local"): |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
451 |
continue |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
452 |
scanned_modules.append(name) |
3424
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
453 |
|
3408 | 454 |
if env['ENABLE_PYTHON_BINDINGS']: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
455 |
source = [ |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
456 |
'ns3modulegen.py', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
457 |
'ns3modulegen_generated.py', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
458 |
'ns3modulegen_core_customizations.py', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
459 |
] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
460 |
target = [ |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
461 |
'ns3module.cc', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
462 |
'ns3module.h', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
463 |
'ns3modulegen.log', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
464 |
] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
465 |
argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}', '${SRC[0]}', '${TGT[0]}'] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
466 |
argv.extend(get_modules_and_headers().iterkeys()) |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
467 |
|
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
468 |
#bindgen.name = 'pybindgen' |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
469 |
#bindgen.command = env['PYTHON'] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
470 |
#bindgen.command_is_external = True |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
471 |
#bindgen.stderr = 'ns3modulegen.log' |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
472 |
#bindgen.argv = [ |
3742
3fd36a505c0e
Upgrade to pybindgen rev. 598, to fix bug #291.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3734
diff
changeset
|
473 |
#'-m', 'pdb', |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
474 |
# bindgen.input_file("ns3modulegen.py"), |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
475 |
# bindgen.output_file("ns3module.cc"), |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
476 |
# ] |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
477 |
#bindgen.hidden_inputs = ['ns3modulegen_generated.py', |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
478 |
# 'ns3modulegen_core_customizations.py'] |
3423
f84261098ab0
Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
479 |
|
f84261098ab0
Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
480 |
for module in scanned_modules: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
481 |
source.append("ns3_module_%s.py" % module) |
3591
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
482 |
local = "ns3_module_%s__local.py" % module |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
483 |
if os.path.exists(os.path.join(curdir, local)): |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
484 |
source.append(local) |
3423
f84261098ab0
Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
485 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
486 |
argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
487 |
|
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
488 |
#bindgen.hidden_outputs = ['ns3module.h'] |
3423
f84261098ab0
Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
489 |
for module in scanned_modules: |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
490 |
target.append("ns3_module_%s.cc" % module) |
3423
f84261098ab0
Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
491 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
492 |
#bindgen.prio = 50 |
3408 | 493 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
494 |
#bindgen.os_env = dict(os.environ) |
3639
8e69ebf086f1
Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3637
diff
changeset
|
495 |
features = [] |
8e69ebf086f1
Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3637
diff
changeset
|
496 |
for (name, caption, was_enabled, reason_not_enabled) in env['NS3_OPTIONAL_FEATURES']: |
8e69ebf086f1
Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3637
diff
changeset
|
497 |
if was_enabled: |
8e69ebf086f1
Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3637
diff
changeset
|
498 |
features.append(name) |
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
499 |
#bindgen.os_env['NS3_ENABLED_FEATURES'] = ','.join(features) |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
500 |
|
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
501 |
bindgen = bld.new_task_gen('command', source=source, target=target, |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
502 |
command=argv, variables=dict(FEATURES=(','.join(features)))) |
3420
390db659644b
If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3417
diff
changeset
|
503 |
|
3408 | 504 |
|
505 |
## we build python bindings if either we have the tools to |
|
506 |
## generate them or if the pregenerated source file is already |
|
507 |
## present in the source dir. |
|
508 |
if env['ENABLE_PYTHON_BINDINGS'] \ |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
509 |
or os.path.exists(os.path.join(bld.path.abspath(), 'ns3module.cc')): |
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
510 |
pymod = bld.new_task_gen('cxx', 'shlib', 'pyext') |
3408 | 511 |
pymod.source = ['ns3module.cc', 'ns3module_helpers.cc'] |
512 |
pymod.includes = '.' |
|
3424
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
513 |
for module in scanned_modules: |
fd8ae9ea848b
Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3423
diff
changeset
|
514 |
pymod.source.append("ns3_module_%s.cc" % module) |
3408 | 515 |
pymod.target = 'ns3/_ns3' |
516 |
pymod.name = 'ns3module' |
|
517 |
pymod.uselib_local = "ns3" |
|
3417
06df0787254b
Make sure we don't trigger deprecation warnings while compiling the python bindings.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3412
diff
changeset
|
518 |
pymod.env.append_value('CXXDEFINES', ['NS_DEPRECATED=""', 'NS3_DEPRECATED_H']) |
3408 | 519 |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
520 |
# copy the __init__.py file to the build dir. waf can't handle |
3408 | 521 |
# this, it's against waf's principles to have build dir files |
522 |
# with the same name as source dir files, apparently. |
|
4064
10222f483860
Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3977
diff
changeset
|
523 |
dirnode = bld.path.find_dir('ns3') |
3408 | 524 |
src = os.path.join(dirnode.abspath(), '__init__.py') |
525 |
dst = os.path.join(dirnode.abspath(env), '__init__.py') |
|
526 |
try: |
|
527 |
need_copy = os.stat(src).st_mtime > os.stat(dst).st_mtime |
|
528 |
except OSError: |
|
529 |
need_copy = True |
|
530 |
if need_copy: |
|
531 |
try: |
|
532 |
os.mkdir(os.path.dirname(dst)) |
|
533 |
except OSError: |
|
534 |
pass |
|
535 |
print "%r -> %r" % (src, dst) |
|
536 |
shutil.copy2(src, dst) |