bindings/python/wscript
changeset 11634 99173c0ad09b
parent 11582 60fd364fb2a5
child 11661 68c0e7f87bdf
equal deleted inserted replaced
11633:6b74df04cf44 11634:99173c0ad09b
     1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
     1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
       
     2 from __future__ import print_function
     2 import types
     3 import types
     3 import re
     4 import re
     4 import os
     5 import os
     5 import subprocess
     6 import subprocess
     6 import shutil
     7 import shutil
    86     if Options.options.with_python is not None:
    87     if Options.options.with_python is not None:
    87         conf.env.PYTHON = Options.options.with_python
    88         conf.env.PYTHON = Options.options.with_python
    88 
    89 
    89     try:
    90     try:
    90         conf.load('python')
    91         conf.load('python')
    91     except Errors.ConfigurationError, ex:
    92     except Errors.ConfigurationError as ex:
    92         conf.report_optional_feature("python", "Python Bindings", False,
    93         conf.report_optional_feature("python", "Python Bindings", False,
    93                                      "The python interpreter was not found")
    94                                      "The python interpreter was not found")
    94         return
    95         return
    95     try:
    96     try:
    96         conf.check_python_version((2,3))
    97         conf.check_python_version((2,3))
    97     except Errors.ConfigurationError, ex:
    98     except Errors.ConfigurationError as ex:
    98         conf.report_optional_feature("python", "Python Bindings", False,
    99         conf.report_optional_feature("python", "Python Bindings", False,
    99                                      "The python found version is too low (2.3 required)")
   100                                      "The python found version is too low (2.3 required)")
   100         return
   101         return
   101     try:
   102     try:
   102         conf.check_python_headers()
   103         conf.check_python_headers()
   103     except Errors.ConfigurationError, ex:
   104     except Errors.ConfigurationError as ex:
   104         conf.report_optional_feature("python", "Python Bindings", False,
   105         conf.report_optional_feature("python", "Python Bindings", False,
   105                                      "Python library or headers missing")
   106                                      "Python library or headers missing")
   106         return
   107         return
   107 
   108 
   108     # stupid Mac OSX Python wants to build extensions as "universal
   109     # stupid Mac OSX Python wants to build extensions as "universal
   413     color = 'BLUE'
   414     color = 'BLUE'
   414 
   415 
   415     def run(self):
   416     def run(self):
   416         assert len(self.outputs) == 1
   417         assert len(self.outputs) == 1
   417         outfile = file(self.outputs[0].abspath(), "w")
   418         outfile = file(self.outputs[0].abspath(), "w")
   418         print >> outfile, "import warnings"
   419         print("import warnings", file=outfile)
   419         print >> outfile, 'warnings.warn("the ns3 module is a compatibility layer '\
   420         print('warnings.warn("the ns3 module is a compatibility layer '\
   420             'and should not be used in newly written code", DeprecationWarning, stacklevel=2)'
   421             'and should not be used in newly written code", DeprecationWarning, stacklevel=2)', file=outfile)
   421         print >> outfile
   422         print(file=outfile)
   422         for module in self.bld.env['PYTHON_MODULES_BUILT']:
   423         for module in self.bld.env['PYTHON_MODULES_BUILT']:
   423             print >> outfile, "from ns.%s import *" % (module.replace('-', '_'))
   424             print("from ns.%s import *" % (module.replace('-', '_')), file=outfile)
   424         outfile.close()
   425         outfile.close()
   425         return 0
   426         return 0
   426 
   427 
   427 
   428 
   428 
   429 
   464                 #print mod.name, bindings_enabled
   465                 #print mod.name, bindings_enabled
   465                 if bindings_enabled:
   466                 if bindings_enabled:
   466                     scan_modules.append(mod.name.split('ns3-')[1])
   467                     scan_modules.append(mod.name.split('ns3-')[1])
   467         else:
   468         else:
   468             scan_modules = Options.options.apiscan.split(',')
   469             scan_modules = Options.options.apiscan.split(',')
   469         print "Modules to scan: ", scan_modules
   470         print("Modules to scan: ", scan_modules)
   470         for target, cflags in scan_targets:
   471         for target, cflags in scan_targets:
   471             group = bld.get_group(bld.current_group)
   472             group = bld.get_group(bld.current_group)
   472             for module in scan_modules:
   473             for module in scan_modules:
   473                 group.append(apiscan_task(bld.path, env, bld, target, cflags, module))
   474                 group.append(apiscan_task(bld.path, env, bld, target, cflags, module))
   474         return
   475         return
   486         bld.install_as('${PYTHONARCHDIR}/ns/__init__.py', 'ns__init__.py')
   487         bld.install_as('${PYTHONARCHDIR}/ns/__init__.py', 'ns__init__.py')
   487 
   488 
   488 
   489 
   489     # note: the actual build commands for the python bindings are in
   490     # note: the actual build commands for the python bindings are in
   490     # src/wscript, not here.
   491     # src/wscript, not here.
   491