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