author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Mon, 08 Sep 2008 12:19:46 +0100 | |
changeset 3648 | f912b24ddf2d |
parent 3639 | 8e69ebf086f1 |
child 3753 | a84a48233eb3 |
permissions | -rwxr-xr-x |
3408 | 1 |
|
2 |
LOCAL_MODULES = [ |
|
3 |
#'my_extra_api_definitions', |
|
4 |
] |
|
5 |
||
6 |
||
7 |
||
8 |
import sys |
|
9 |
import os |
|
10 |
||
11 |
from pybindgen import FileCodeSink, write_preamble |
|
12 |
from pybindgen.module import MultiSectionFactory |
|
13 |
import pybindgen.settings |
|
14 |
||
3473
6bce86ea4778
Require new PyBindGen; make it work for Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3421
diff
changeset
|
15 |
from ns3modulegen_generated import module_init, register_types, register_methods, register_functions |
3408 | 16 |
import ns3modulegen_core_customizations |
17 |
import callbacks_list |
|
18 |
||
19 |
this_script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
|
20 |
||
21 |
class ErrorHandler(pybindgen.settings.ErrorHandler): |
|
22 |
def handle_error(self, wrapper, exception, traceback_): |
|
23 |
try: |
|
24 |
stack = wrapper.stack_where_defined |
|
25 |
except AttributeError: |
|
26 |
print >> sys.stderr, "??:??: %s / %r" % (wrapper, exception) |
|
27 |
else: |
|
28 |
stack = list(stack) |
|
29 |
stack.reverse() |
|
30 |
for (filename, line_number, function_name, text) in stack: |
|
31 |
file_dir = os.path.dirname(os.path.abspath(filename)) |
|
32 |
if file_dir == this_script_dir: |
|
33 |
print >> sys.stderr, "%s:%i: %r" % (os.path.join("..", "bindings", "python", os.path.basename(filename)), |
|
34 |
line_number, exception) |
|
35 |
break |
|
36 |
return True |
|
37 |
pybindgen.settings.error_handler = ErrorHandler() |
|
38 |
||
3546
cecda7126440
New PyBindGen, fixes python wrapper identity issue.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3538
diff
changeset
|
39 |
pybindgen.settings.wrapper_registry = pybindgen.settings.StdMapWrapperRegistry |
cecda7126440
New PyBindGen, fixes python wrapper identity issue.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3538
diff
changeset
|
40 |
|
3408 | 41 |
|
42 |
class MyMultiSectionFactory(MultiSectionFactory): |
|
43 |
||
44 |
def __init__(self, main_file_name, modules): |
|
45 |
super(MyMultiSectionFactory, self).__init__() |
|
46 |
self.main_file_name = main_file_name |
|
47 |
self.main_sink = FileCodeSink(open(main_file_name, "wt")) |
|
48 |
self.header_name = "ns3module.h" |
|
49 |
header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name) |
|
50 |
self.header_sink = FileCodeSink(open(header_file_name, "wt")) |
|
3538
99f49426595a
Python: fix bad parameter passed into pybindgen.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3473
diff
changeset
|
51 |
self.section_sinks = {'__main__': self.main_sink} |
3408 | 52 |
|
53 |
for module in modules: |
|
54 |
section_name = 'ns3_module_%s' % module.replace('-', '_') |
|
55 |
file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name) |
|
56 |
sink = FileCodeSink(open(file_name, "wt")) |
|
57 |
self.section_sinks[section_name] = sink |
|
58 |
||
59 |
def get_section_code_sink(self, section_name): |
|
60 |
return self.section_sinks[section_name] |
|
61 |
||
62 |
def get_main_code_sink(self): |
|
63 |
return self.main_sink |
|
64 |
||
65 |
def get_common_header_code_sink(self): |
|
66 |
return self.header_sink |
|
67 |
||
68 |
def get_common_header_include(self): |
|
69 |
return '"%s"' % self.header_name |
|
70 |
||
71 |
def close(self): |
|
72 |
self.header_sink.file.close() |
|
73 |
self.main_sink.file.close() |
|
74 |
for sink in self.section_sinks.itervalues(): |
|
75 |
sink.file.close() |
|
76 |
||
77 |
||
78 |
||
79 |
def main(): |
|
80 |
out = MyMultiSectionFactory(sys.argv[1], sys.argv[2:]) |
|
81 |
root_module = module_init() |
|
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
|
82 |
root_module.add_include('"everything.h"') |
3408 | 83 |
|
84 |
register_types(root_module) |
|
85 |
||
86 |
ns3modulegen_core_customizations.Simulator_customizations(root_module) |
|
87 |
ns3modulegen_core_customizations.CommandLine_customizations(root_module) |
|
88 |
||
89 |
||
90 |
for local_module in LOCAL_MODULES: |
|
91 |
mod = __import__(local_module) |
|
92 |
mod.register_types(root_module) |
|
93 |
||
94 |
ns3modulegen_core_customizations.generate_callback_classes(root_module.after_forward_declarations, |
|
95 |
callbacks_list.callback_classes) |
|
96 |
||
97 |
||
98 |
register_methods(root_module) |
|
99 |
||
100 |
for local_module in LOCAL_MODULES: |
|
101 |
mod = __import__(local_module) |
|
102 |
mod.register_methods(root_module) |
|
103 |
||
104 |
ns3modulegen_core_customizations.Object_customizations(root_module) |
|
3421
b9424c43753d
Python: make helper class methods using attribute optional parameters work.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3420
diff
changeset
|
105 |
ns3modulegen_core_customizations.Attribute_customizations(root_module) |
3408 | 106 |
|
107 |
register_functions(root_module) |
|
108 |
||
109 |
for local_module in LOCAL_MODULES: |
|
110 |
mod = __import__(local_module) |
|
111 |
mod.register_functions(root_module) |
|
112 |
||
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:
3582
diff
changeset
|
113 |
enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',') |
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:
3409
diff
changeset
|
114 |
|
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:
3409
diff
changeset
|
115 |
# if GtkConfigStore support is disabled, disable the class wrapper |
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:
3582
diff
changeset
|
116 |
if 'GtkConfigStore' not in enabled_features: |
3582
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
117 |
try: |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
118 |
root_module.classes.remove(root_module['ns3::GtkConfigStore']) |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
119 |
except KeyError: |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
120 |
pass |
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:
3409
diff
changeset
|
121 |
|
3575
1f5d9b97a1a2
Fix compilation of Python bindings when libsqlite3 is not available (and so the class SqliteDataOutput is omitted).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3546
diff
changeset
|
122 |
# if no sqlite, the class SqliteDataOutput is disabled |
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:
3582
diff
changeset
|
123 |
if 'SqliteDataOutput' not in enabled_features: |
3582
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
124 |
try: |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
125 |
root_module.classes.remove(root_module['ns3::SqliteDataOutput']) |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
126 |
except KeyError: |
96fa2a7b5f88
catch KeyError exception to avoid failing when sqlite or gtk are not installed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3575
diff
changeset
|
127 |
pass |
3575
1f5d9b97a1a2
Fix compilation of Python bindings when libsqlite3 is not available (and so the class SqliteDataOutput is omitted).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3546
diff
changeset
|
128 |
|
3648
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
129 |
if 'Threading' not in enabled_features: |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
130 |
for clsname in ['SystemThread', 'SystemMutex', 'SystemCondition', 'CriticalSection']: |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
131 |
root_module.classes.remove(root_module['ns3::%s' % clsname]) |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
132 |
|
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
133 |
if 'RealTime' not in enabled_features: |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
134 |
for clsname in ['WallClockSynchronizer', 'RealtimeSimulatorImpl', 'RealtimeEventLock']: |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
135 |
root_module.classes.remove(root_module['ns3::%s' % clsname]) |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
136 |
root_module.enums.remove(root_module['ns3::RealtimeSimulatorImpl::SynchronizationMode']) |
f912b24ddf2d
Detect the pthread.h header file and automatically disable components that cannot build without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3639
diff
changeset
|
137 |
|
3408 | 138 |
root_module.generate(out, '_ns3') |
139 |
||
140 |
out.close() |
|
141 |
||
142 |
if __name__ == '__main__': |
|
143 |
main() |
|
144 |