16 # https://github.com/gjcarneiro/pybindgen |
16 # https://github.com/gjcarneiro/pybindgen |
17 REQUIRED_PYBINDGEN_VERSION = '0.17.0.post41+ngd10fa60' |
17 REQUIRED_PYBINDGEN_VERSION = '0.17.0.post41+ngd10fa60' |
18 REQUIRED_PYGCCXML_VERSION = (0, 9, 5) |
18 REQUIRED_PYGCCXML_VERSION = (0, 9, 5) |
19 |
19 |
20 RUN_ME=-3 |
20 RUN_ME=-3 |
|
21 |
|
22 # return types of some APIs differ in Python 2/3 (type string vs class bytes) |
|
23 # This method will decode('utf-8') a byte object in Python 3, |
|
24 # and do nothing in Python 2 |
|
25 def maybe_decode(input): |
|
26 if sys.version_info < (3,): |
|
27 return input |
|
28 else: |
|
29 try: |
|
30 return input.decode('utf-8') |
|
31 except: |
|
32 sys.exc_clear() |
|
33 return input |
21 |
34 |
22 def add_to_python_path(path): |
35 def add_to_python_path(path): |
23 if os.environ.get('PYTHONPATH', ''): |
36 if os.environ.get('PYTHONPATH', ''): |
24 os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH') |
37 os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH') |
25 else: |
38 else: |
166 else: |
179 else: |
167 out = subprocess.Popen([conf.env['PYTHON'][0], "-c", |
180 out = subprocess.Popen([conf.env['PYTHON'][0], "-c", |
168 "import pybindgen.version; " |
181 "import pybindgen.version; " |
169 "print(pybindgen.__version__)"], |
182 "print(pybindgen.__version__)"], |
170 stdout=subprocess.PIPE).communicate()[0] |
183 stdout=subprocess.PIPE).communicate()[0] |
171 pybindgen_version = out.strip() |
184 pybindgen_version = maybe_decode(out.strip()) |
172 conf.msg('Checking for pybindgen version', pybindgen_version) |
185 conf.msg('Checking for pybindgen version', pybindgen_version) |
173 if not (pybindgen_version == REQUIRED_PYBINDGEN_VERSION): |
186 if not (pybindgen_version == REQUIRED_PYBINDGEN_VERSION): |
174 Logs.warn("pybindgen (found %r), (need %r)" % |
187 Logs.warn("pybindgen (found %r), (need %r)" % |
175 (pybindgen_version, REQUIRED_PYBINDGEN_VERSION)) |
188 (pybindgen_version, REQUIRED_PYBINDGEN_VERSION)) |
176 conf.report_optional_feature("python", "Python Bindings", False, |
189 conf.report_optional_feature("python", "Python Bindings", False, |
413 before = 'cxx' |
426 before = 'cxx' |
414 color = 'BLUE' |
427 color = 'BLUE' |
415 |
428 |
416 def run(self): |
429 def run(self): |
417 assert len(self.outputs) == 1 |
430 assert len(self.outputs) == 1 |
418 outfile = file(self.outputs[0].abspath(), "w") |
431 outfile = open(self.outputs[0].abspath(), "w") |
419 print("import warnings", file=outfile) |
432 print("import warnings", file=outfile) |
420 print('warnings.warn("the ns3 module is a compatibility layer '\ |
433 print('warnings.warn("the ns3 module is a compatibility layer '\ |
421 'and should not be used in newly written code", DeprecationWarning, stacklevel=2)', file=outfile) |
434 'and should not be used in newly written code", DeprecationWarning, stacklevel=2)', file=outfile) |
422 print(file=outfile) |
435 print(file=outfile) |
423 for module in self.bld.env['PYTHON_MODULES_BUILT']: |
436 for module in self.bld.env['PYTHON_MODULES_BUILT']: |