author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Tue, 07 Oct 2008 12:23:57 +0100 | |
changeset 3734 | 7e092d900d80 |
parent 3731 | 317f9dbccc2b |
child 3742 | 3fd36a505c0e |
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 Params |
|
5 |
import Configure |
|
6 |
import Object |
|
7 |
import Action |
|
8 |
import os |
|
9 |
import Task |
|
10 |
import pproc as subprocess |
|
11 |
from Params import fatal, warning |
|
12 |
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
|
13 |
import sys |
3408 | 14 |
|
15 |
## Adjust python path to look for our local copy of pybindgen |
|
16 |
LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen") |
|
17 |
#PYBINDGEN_BRANCH = 'lp:pybindgen' |
|
18 |
PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen' |
|
19 |
if os.environ.get('PYTHONPATH', ''): |
|
20 |
os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH + os.pathsep + os.environ.get('PYTHONPATH') |
|
21 |
else: |
|
22 |
os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH |
|
23 |
||
24 |
## https://launchpad.net/pybindgen/ |
|
3734
7e092d900d80
Fix compat. with Python < 2.5 (fixes ns-old regression failure)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3731
diff
changeset
|
25 |
REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 595) |
3408 | 26 |
REQUIRED_PYGCCXML_VERSION = (0, 9, 5) |
27 |
||
28 |
||
29 |
def set_options(opt): |
|
30 |
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
|
31 |
opt.add_option('--disable-python', |
3408 | 32 |
help=("Don't build Python bindings."), |
33 |
action="store_true", default=False, |
|
34 |
dest='python_disable') |
|
35 |
opt.add_option('--python-scan', |
|
36 |
help=("Rescan Python bindings. Needs working GCCXML / pygccxml environment."), |
|
37 |
action="store_true", default=False, |
|
38 |
dest='python_scan') |
|
39 |
opt.add_option('--pybindgen-checkout', |
|
40 |
help=("During configure, force checkout of pybingen inside ns-3, " |
|
41 |
"instead of using the system installed version."), |
|
42 |
action="store_true", default=False, |
|
43 |
dest='pybindgen_checkout') |
|
44 |
||
45 |
def fetch_pybindgen(conf): |
|
46 |
""" |
|
47 |
Fetches pybindgen from launchpad as bindings/python/pybindgen. |
|
48 |
Returns True if successful, False it not. |
|
49 |
""" |
|
50 |
bzr = conf.find_program("bzr") |
|
51 |
if not bzr: |
|
52 |
warning("the program 'bzr' is needed in order to fetch pybindgen") |
|
53 |
return False |
|
54 |
if len(REQUIRED_PYBINDGEN_VERSION) == 4: |
|
55 |
rev = "-rrevno:%i" % REQUIRED_PYBINDGEN_VERSION[3] |
|
56 |
else: |
|
57 |
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
|
58 |
|
3408 | 59 |
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
|
60 |
print "Trying to update pybindgen; this will fail if no network connection is available. Hit Ctrl-C to skip." |
3408 | 61 |
|
62 |
cmd = [bzr, "pull", rev, PYBINDGEN_BRANCH] |
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
print "Interrupted; Python bindings will be disabled." |
3408 | 69 |
return False |
70 |
print "Update was successful." |
|
71 |
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
|
72 |
print "Trying to fetch pybindgen; this will fail if no network connection is available. Hit Ctrl-C to skip." |
3408 | 73 |
cmd = [bzr, "checkout", rev, PYBINDGEN_BRANCH, LOCAL_PYBINDGEN_PATH] |
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
shutil.rmtree(LOCAL_PYBINDGEN_PATH, True) |
3408 | 81 |
return False |
82 |
print "Fetch was successful." |
|
83 |
||
84 |
## generate a fake version.py file in pybindgen it's safer this |
|
85 |
## way, since the normal version generation process requires |
|
86 |
## bazaar python bindings, which may not be available. |
|
87 |
vfile = open(os.path.join(LOCAL_PYBINDGEN_PATH, "pybindgen", "version.py"), "wt") |
|
88 |
vfile.write(""" |
|
89 |
# (fake version generated by ns-3) |
|
90 |
__version__ = %r |
|
91 |
""" % list(REQUIRED_PYBINDGEN_VERSION)) |
|
92 |
vfile.close() |
|
93 |
||
94 |
return True |
|
95 |
||
96 |
||
97 |
def configure(conf): |
|
98 |
conf.env['ENABLE_PYTHON_BINDINGS'] = False |
|
99 |
if Params.g_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
|
100 |
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
|
101 |
"disabled by user request") |
3408 | 102 |
return |
103 |
||
104 |
conf.check_tool('misc') |
|
105 |
||
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
|
106 |
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
|
107 |
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
|
108 |
"unsupported platform 'cygwin'") |
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
|
109 |
warning("Python is not supported in CygWin environment. Try MingW instead.") |
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
|
110 |
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
|
111 |
|
3408 | 112 |
## Check for Python |
113 |
try: |
|
114 |
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
|
115 |
conf.check_python_version((2,3)) |
3408 | 116 |
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
|
117 |
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
|
118 |
conf.report_optional_feature("python", "Python Bindings", False, str(ex)) |
3408 | 119 |
return |
120 |
||
121 |
## Check for pybindgen |
|
122 |
if Params.g_options.pybindgen_checkout: |
|
123 |
fetch_pybindgen(conf) |
|
124 |
||
125 |
try: |
|
126 |
conf.check_python_module('pybindgen') |
|
127 |
except Configure.ConfigurationError: |
|
128 |
warning("pybindgen missing") |
|
129 |
if 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
|
130 |
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
|
131 |
"PyBindGen missing and could not be retrieved") |
3408 | 132 |
return |
133 |
else: |
|
134 |
out = subprocess.Popen([conf.env['PYTHON'], "-c", |
|
135 |
"import pybindgen.version; " |
|
136 |
"print '.'.join([str(x) for x in pybindgen.version.__version__])"], |
|
137 |
stdout=subprocess.PIPE).communicate()[0] |
|
138 |
pybindgen_version_str = out.strip() |
|
139 |
pybindgen_version = tuple([int(x) for x in pybindgen_version_str.split('.')]) |
|
140 |
conf.check_message('pybindgen', 'version', |
|
141 |
(pybindgen_version >= REQUIRED_PYBINDGEN_VERSION), |
|
142 |
pybindgen_version_str) |
|
143 |
if not (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION): |
|
144 |
warning("pybindgen (found %s) is too old (need %s)" % |
|
145 |
(pybindgen_version_str, |
|
146 |
'.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]))) |
|
147 |
if 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
|
148 |
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
|
149 |
"PyBindGen too old and newer version could not be retrieved") |
3408 | 150 |
return |
151 |
||
152 |
## If all has gone well, we finally enable the Python bindings |
|
153 |
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
|
154 |
conf.report_optional_feature("python", "Python Bindings", True, None) |
3408 | 155 |
|
156 |
## Check for pygccxml |
|
157 |
try: |
|
158 |
conf.check_python_module('pygccxml') |
|
159 |
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
|
160 |
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
|
161 |
"Missing 'pygccxml' Python module") |
3408 | 162 |
return |
163 |
||
164 |
out = subprocess.Popen([conf.env['PYTHON'], "-c", |
|
165 |
"import pygccxml; print pygccxml.__version__"], |
|
166 |
stdout=subprocess.PIPE).communicate()[0] |
|
167 |
pygccxml_version_str = out.strip() |
|
168 |
pygccxml_version = tuple([int(x) for x in pygccxml_version_str.split('.')]) |
|
169 |
conf.check_message('pygccxml', 'version', |
|
170 |
(pygccxml_version >= REQUIRED_PYGCCXML_VERSION), |
|
171 |
pygccxml_version_str) |
|
172 |
if not (pygccxml_version >= REQUIRED_PYGCCXML_VERSION): |
|
173 |
warning("pygccxml (found %s) is too old (need %s) => " |
|
174 |
"automatic scanning of API definitions will not be possible" % |
|
175 |
(pygccxml_version_str, |
|
176 |
'.'.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
|
177 |
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
|
178 |
"pygccxml too old") |
3408 | 179 |
return |
180 |
||
181 |
||
182 |
## Check gccxml version |
|
183 |
gccxml = conf.find_program('gccxml', var='GCCXML') |
|
184 |
if not gccxml: |
|
185 |
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
|
186 |
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
|
187 |
"gccxml missing") |
3408 | 188 |
return |
189 |
||
190 |
gccxml_version_line = os.popen(gccxml + " --version").readline().strip() |
|
191 |
m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line) |
|
192 |
gccxml_version = m.group(1) |
|
193 |
gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9]) |
|
194 |
conf.check_message('gccxml', 'version', True, gccxml_version) |
|
195 |
if not gccxml_version_ok: |
|
196 |
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
|
197 |
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
|
198 |
"gccxml too old") |
3408 | 199 |
return |
200 |
||
201 |
## If we reached |
|
202 |
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
|
203 |
conf.report_optional_feature("pygccxml", "Python API Scanning Support", True, None) |
3408 | 204 |
|
205 |
||
206 |
prio_headers = { |
|
207 |
-2: ( |
|
208 |
"string.h", # work around http://www.gccxml.org/Bug/view.php?id=6682 |
|
209 |
), |
|
210 |
-1: ( |
|
211 |
"propagation-delay-model.h", |
|
212 |
"propagation-loss-model.h", |
|
213 |
"net-device.h", |
|
214 |
) |
|
215 |
} |
|
216 |
||
217 |
def get_header_prio(header): |
|
218 |
for prio, headers in prio_headers.iteritems(): |
|
219 |
if header in headers: |
|
220 |
return prio |
|
221 |
return 1 |
|
222 |
||
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
|
223 |
|
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
|
224 |
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
|
225 |
(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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
|
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
|
231 |
|
3408 | 232 |
def gen_ns3_metaheader(task): |
233 |
assert len(task.m_outputs) == 1 |
|
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
|
234 |
|
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
|
235 |
header_files = [calc_header_include(node.abspath(task.m_env)) for node in task.m_inputs] |
3408 | 236 |
outfile = file(task.m_outputs[0].bldpath(task.m_env), "w") |
237 |
||
238 |
def sort_func(h1, h2): |
|
239 |
return cmp((get_header_prio(h1), h1), (get_header_prio(h1), h2)) |
|
240 |
||
241 |
header_files.sort(sort_func) |
|
242 |
||
243 |
for header in header_files: |
|
244 |
print >> outfile, "#include \"ns3/%s\"" % (header,) |
|
245 |
||
246 |
print >> outfile, """ |
|
247 |
namespace ns3 { |
|
248 |
static inline Ptr<Object> |
|
249 |
__dummy_function_to_force_template_instantiation (Ptr<Object> obj, TypeId typeId) |
|
250 |
{ |
|
251 |
return obj->GetObject<Object> (typeId); |
|
252 |
} |
|
253 |
||
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
|
254 |
|
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
|
255 |
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
|
256 |
__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
|
257 |
{ |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
} |
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
|
274 |
|
3408 | 275 |
} |
276 |
""" |
|
277 |
outfile.close() |
|
278 |
return 0 |
|
279 |
||
280 |
||
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
|
281 |
|
3408 | 282 |
class all_ns3_headers_taskgen(Object.task_gen): |
283 |
"""Generates a 'everything.h' header file that includes some/all public ns3 headers. |
|
284 |
This single header file is to be parsed only once by gccxml, for greater efficiency. |
|
285 |
""" |
|
286 |
def __init__(self, *features): |
|
287 |
Object.task_gen.__init__(self, *features) |
|
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
|
288 |
self.inst_var = 0#'INCLUDEDIR' |
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
|
289 |
#self.inst_dir = 'ns3' |
3408 | 290 |
|
291 |
def apply(self): |
|
292 |
## get all of the ns3 headers |
|
293 |
ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3") |
|
294 |
all_headers_inputs = [] |
|
295 |
||
296 |
for filename in self.to_list(self.source): |
|
297 |
src_node = ns3_dir_node.find_build(filename) |
|
298 |
if src_node is None: |
|
299 |
Params.fatal("source ns3 header file %s not found" % (filename,)) |
|
300 |
all_headers_inputs.append(src_node) |
|
301 |
||
302 |
## if self.source was empty, include all ns3 headers in enabled modules |
|
303 |
if not all_headers_inputs: |
|
304 |
for ns3headers in Object.g_allobjs: |
|
305 |
if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare |
|
306 |
## skip headers not part of enabled modules |
|
307 |
if self.env['NS3_ENABLED_MODULES']: |
|
308 |
if ("ns3-%s" % ns3headers.module) not in self.env['NS3_ENABLED_MODULES']: |
|
309 |
continue |
|
310 |
||
311 |
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
|
312 |
#source = os.path.basename(source) |
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
|
313 |
node = ns3_dir_node.find_build(source) |
3408 | 314 |
if node is None: |
315 |
fatal("missing header file %s" % (source,)) |
|
316 |
all_headers_inputs.append(node) |
|
317 |
assert all_headers_inputs |
|
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
|
318 |
all_headers_outputs = [self.path.find_build("everything.h")] |
3408 | 319 |
task = self.create_task('gen-ns3-metaheader', self.env, 4) |
320 |
task.set_inputs(all_headers_inputs) |
|
321 |
task.set_outputs(all_headers_outputs) |
|
322 |
||
323 |
def install(self): |
|
324 |
pass |
|
325 |
||
326 |
||
327 |
def get_modules_and_headers(): |
|
328 |
""" |
|
329 |
Gets a dict of |
|
330 |
module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...]) |
|
331 |
tuples, one for each module. |
|
332 |
""" |
|
333 |
||
334 |
retval = {} |
|
335 |
for module in Object.g_allobjs: |
|
336 |
if not module.name.startswith('ns3-'): |
|
337 |
continue |
|
338 |
module_name = module.name[4:] # strip the ns3- prefix |
|
339 |
## find the headers object for this module |
|
340 |
headers = [] |
|
341 |
for ns3headers in Object.g_allobjs: |
|
342 |
if type(ns3headers).__name__ != 'ns3header_taskgen': # XXX: find less hackish way to compare |
|
343 |
continue |
|
344 |
if ns3headers.module != module_name: |
|
345 |
continue |
|
346 |
for source in ns3headers.to_list(ns3headers.source): |
|
347 |
headers.append(source) |
|
348 |
retval[module_name] = (list(module.module_deps), headers) |
|
349 |
return retval |
|
350 |
||
351 |
||
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
|
352 |
|
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
|
353 |
class PythonScanTask(Task.TaskBase): |
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
|
354 |
"""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
|
355 |
""" |
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
|
356 |
def __init__(self, curdirnode, env): |
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
|
357 |
self.m_display = 'python-scan' |
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
|
358 |
self.prio = 5 # everything.h has prio 4 |
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
|
359 |
super(PythonScanTask, self).__init__() |
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
|
360 |
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
|
361 |
self.env = env |
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
|
362 |
|
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
|
363 |
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
|
364 |
#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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
self.curdirnode.find_dir('../..').abspath(self.env), # include path (where the ns3 include dir is) |
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
|
369 |
self.curdirnode.find_build('everything.h').abspath(self.env), |
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
|
370 |
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
|
371 |
] |
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
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
|
3408 | 379 |
def build(bld): |
380 |
if Params.g_options.python_disable: |
|
381 |
return |
|
382 |
||
383 |
env = bld.env_of_name('default') |
|
3591
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
384 |
curdir = bld.m_curdirnode.abspath() |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
385 |
|
3408 | 386 |
#Object.register('all-ns3-headers', AllNs3Headers) |
387 |
Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE') |
|
388 |
||
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
|
389 |
if env['ENABLE_PYTHON_BINDINGS']: |
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
|
390 |
obj = bld.create_obj('all_ns3_headers') |
3408 | 391 |
|
392 |
if Params.g_options.python_scan: |
|
393 |
if not env['ENABLE_PYTHON_SCANNING']: |
|
394 |
Params.fatal("Cannot re-scan python bindings: (py)gccxml not available") |
|
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
|
395 |
PythonScanTask(bld.m_curdirnode, env) |
3408 | 396 |
|
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
|
397 |
## 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
|
398 |
## 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
|
399 |
## 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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
continue |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
408 |
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
|
409 |
|
3408 | 410 |
if env['ENABLE_PYTHON_BINDINGS']: |
411 |
bindgen = bld.create_obj('command-output') |
|
412 |
bindgen.name = 'pybindgen' |
|
413 |
bindgen.command = env['PYTHON'] |
|
414 |
bindgen.command_is_external = True |
|
3411
eca46ea15a04
Redirect the stderr of pybindgen to a log file (ns3modulegen.log).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3409
diff
changeset
|
415 |
bindgen.stderr = 'ns3modulegen.log' |
3408 | 416 |
bindgen.argv = [ |
417 |
bindgen.input_file("ns3modulegen.py"), |
|
418 |
bindgen.output_file("ns3module.cc"), |
|
419 |
] |
|
420 |
bindgen.argv.extend(get_modules_and_headers().iterkeys()) |
|
3647
cd704871a4ed
Python bindings generation does not need to depend on the 'everything.h' file, only API scanning and compilation of the generated sources.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
421 |
bindgen.hidden_inputs = ['ns3modulegen_generated.py', |
3408 | 422 |
'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
|
423 |
|
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
|
424 |
for module in scanned_modules: |
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
|
425 |
bindgen.hidden_inputs.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
|
426 |
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
|
427 |
if os.path.exists(os.path.join(curdir, local)): |
f548d13ffd4e
Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3575
diff
changeset
|
428 |
bindgen.hidden_inputs.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
|
429 |
|
3408 | 430 |
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
|
431 |
for module in scanned_modules: |
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
|
432 |
bindgen.hidden_outputs.append("ns3_module_%s.cc" % module) |
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
|
433 |
|
3408 | 434 |
bindgen.prio = 50 |
435 |
||
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
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
features.append(name) |
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
|
441 |
bindgen.os_env['NS3_ENABLED_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
|
442 |
|
3408 | 443 |
|
444 |
## we build python bindings if either we have the tools to |
|
445 |
## generate them or if the pregenerated source file is already |
|
446 |
## present in the source dir. |
|
447 |
if env['ENABLE_PYTHON_BINDINGS'] \ |
|
448 |
or os.path.exists(os.path.join(bld.m_curdirnode.abspath(), 'ns3module.cc')): |
|
449 |
pymod = bld.create_obj('cpp', 'shlib', 'pyext') |
|
450 |
pymod.source = ['ns3module.cc', 'ns3module_helpers.cc'] |
|
451 |
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
|
452 |
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
|
453 |
pymod.source.append("ns3_module_%s.cc" % module) |
3408 | 454 |
pymod.target = 'ns3/_ns3' |
455 |
pymod.name = 'ns3module' |
|
456 |
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
|
457 |
pymod.env.append_value('CXXDEFINES', ['NS_DEPRECATED=""', 'NS3_DEPRECATED_H']) |
3408 | 458 |
|
459 |
# copy the __init__.py file to the build dir waf can't handle |
|
460 |
# this, it's against waf's principles to have build dir files |
|
461 |
# with the same name as source dir files, apparently. |
|
462 |
dirnode = bld.m_curdirnode.find_dir('ns3') |
|
463 |
src = os.path.join(dirnode.abspath(), '__init__.py') |
|
464 |
dst = os.path.join(dirnode.abspath(env), '__init__.py') |
|
465 |
try: |
|
466 |
need_copy = os.stat(src).st_mtime > os.stat(dst).st_mtime |
|
467 |
except OSError: |
|
468 |
need_copy = True |
|
469 |
if need_copy: |
|
470 |
try: |
|
471 |
os.mkdir(os.path.dirname(dst)) |
|
472 |
except OSError: |
|
473 |
pass |
|
474 |
print "%r -> %r" % (src, dst) |
|
475 |
shutil.copy2(src, dst) |