bindings/python/wscript
author Tom Henderson <tomh@tomh.org>
Tue, 15 Sep 2015 11:21:53 -0700
changeset 11667 3dac5b408933
parent 11661 68c0e7f87bdf
child 11672 51263c7e64bb
permissions -rw-r--r--
Added tag ns-3.24 for changeset e8634b0101f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
     2
from __future__ import print_function
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
     3
import types
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
import re
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
import os
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
     6
import subprocess
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
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
     8
import sys
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
    10
from waflib import Task, Options, Configure, TaskGen, Logs, Build, Utils, Errors
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
    11
from waflib.Errors import WafError
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    12
9721
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
    13
# feature  = TaskGen.feature
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
    14
# after = TaskGen.after
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    15
11541
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
    16
# https://github.com/gjcarneiro/pybindgen
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
    17
REQUIRED_PYBINDGEN_VERSION = '0.17.0.post41+ngd10fa60'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
10398
458687e0055d bug 1622: make apiscan Task always run
Tom Henderson <tomh@tomh.org>
parents: 10214
diff changeset
    20
RUN_ME=-3
6137
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    21
11661
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    22
# return types of some APIs differ in Python 2/3 (type string vs class bytes)
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    23
# This method will decode('utf-8') a byte object in Python 3,
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    24
# and do nothing in Python 2
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    25
def maybe_decode(input):
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    26
    if sys.version_info < (3,):
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    27
        return input
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    28
    else:
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    29
        try: 
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    30
            return input.decode('utf-8')
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    31
        except:
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    32
            sys.exc_clear()
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    33
            return input
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    34
3873
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    35
def add_to_python_path(path):
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    36
    if os.environ.get('PYTHONPATH', ''):
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    37
        os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH')
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    38
    else:
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    39
        os.environ['PYTHONPATH'] = path
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    40
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    41
def set_pybindgen_pythonpath(env):
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    42
    if env['WITH_PYBINDGEN']:
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    43
        add_to_python_path(env['WITH_PYBINDGEN'])
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    44
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    45
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    46
def options(opt):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
    47
    opt.load('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
    48
    opt.add_option('--disable-python',
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
                   help=("Don't build Python bindings."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
                   dest='python_disable')
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
    52
    opt.add_option('--apiscan',
7503
0d495639ee3e Remove the EXPERIMENTAL from --apiscan option help
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    53
                   help=("Rescan the API for the indicated module(s), for Python bindings.  "
6923
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
    54
                         "Needs working GCCXML / pygccxml environment.  "
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
    55
                         "The metamodule 'all' expands to all available ns-3 modules."),
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
    56
                   default=None, dest='apiscan', metavar="MODULE[,MODULE...]")
3873
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    57
    opt.add_option('--with-pybindgen',
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    58
                   help=('Path to an existing pybindgen source tree to use.'),
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    59
                   default=None,
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
    60
                   dest='with_pybindgen', type="string")
7517
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
    61
    opt.add_option('--with-python',
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
    62
                   help=('Path to the Python interpreter to use.'),
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
    63
                   default=None, dest='with_python', type="string")
10639
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
    64
    opt.add_option('--no32bit-scan',
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
    65
                   help=("Don't scan for the 32-bit variant of the bindings on 64-bit platforms."),
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
    66
                   action="store_true", default=False,
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
    67
                   dest='no32bit_scan')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
def configure(conf):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
    conf.env['ENABLE_PYTHON_BINDINGS'] = False
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    72
    if Options.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
    73
        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
    74
                                     "disabled by user request")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
        return
7468
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    76
    # Disable python in static builds (bug #1253)
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    77
    if ((conf.env['ENABLE_STATIC_NS3']) or \
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    78
      (conf.env['ENABLE_SHARED_AND_STATIC_NS3'])):
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    79
        conf.report_optional_feature("python", "Python Bindings", False,
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    80
                                     "bindings incompatible with static build")
7b8dfd1b02f6 Bug 1253 - disable python bindings if static build selected
Tom Henderson <tomh@tomh.org>
parents: 7462
diff changeset
    81
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
6919
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    83
    enabled_modules = list(conf.env['NS3_ENABLED_MODULES'])
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    84
    enabled_modules.sort()
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    85
    available_modules = list(conf.env['NS3_MODULES'])
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    86
    available_modules.sort()
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    87
    all_modules_enabled = (enabled_modules == available_modules)
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
    88
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
    89
    conf.load('misc', tooldir=['waf-tools'])
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
5251
306856feb249 Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
    91
    if sys.platform == 'cygwin':
306856feb249 Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
    92
        conf.report_optional_feature("python", "Python Bindings", False,
306856feb249 Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
    93
                                     "unsupported platform 'cygwin'")
306856feb249 Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
    94
        Logs.warn("Python is not supported in CygWin environment.  Try MingW instead.")
306856feb249 Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5249
diff changeset
    95
        return
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
    96
7517
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
    97
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
    ## Check for Python
7517
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
    99
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
   100
    if Options.options.with_python is not None:
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
   101
        conf.env.PYTHON = Options.options.with_python
319c875844d7 Add a --with-python configuration option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7509
diff changeset
   102
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    try:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   104
        conf.load('python')
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   105
    except Errors.ConfigurationError as ex:
7716
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   106
        conf.report_optional_feature("python", "Python Bindings", False,
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   107
                                     "The python interpreter was not found")
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   108
        return
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   109
    try:
3473
6bce86ea4778 Require new PyBindGen; make it work for Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3468
diff changeset
   110
        conf.check_python_version((2,3))
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   111
    except Errors.ConfigurationError as ex:
7716
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   112
        conf.report_optional_feature("python", "Python Bindings", False,
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   113
                                     "The python found version is too low (2.3 required)")
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   114
        return
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   115
    try:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
        conf.check_python_headers()
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   117
    except Errors.ConfigurationError as ex:
7716
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   118
        conf.report_optional_feature("python", "Python Bindings", False,
8758b76b756c Bug 1273 - Better error message on missing Python development files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7715
diff changeset
   119
                                     "Python library or headers missing")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   122
    # stupid Mac OSX Python wants to build extensions as "universal
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   123
    # binaries", i386, x86_64, and ppc, but this way the type
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   124
    # __uint128_t is not available.  We need to disable the multiarch
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   125
    # crap by removing the -arch parameters.
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   126
    for flags_var in ["CFLAGS_PYEXT", "CFLAGS_PYEMBED", "CXXFLAGS_PYEMBED",
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   127
                      "CXXFLAGS_PYEXT", "LINKFLAGS_PYEMBED", "LINKFLAGS_PYEXT"]:
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   128
        flags = conf.env[flags_var]
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   129
        i = 0
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   130
        while i < len(flags):
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   131
            if flags[i] == '-arch':
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   132
                del flags[i]
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   133
                del flags[i]
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   134
                continue
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   135
            i += 1
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   136
        conf.env[flags_var] = flags
7363
0f96f5beb8c7 Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7348
diff changeset
   137
4253
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   138
    # -fvisibility=hidden optimization
4430
4a527879c7ab Fix Python bindings build with gcc < 4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4395
diff changeset
   139
    if (conf.env['CXX_NAME'] == 'gcc' and [int(x) for x in conf.env['CC_VERSION']] >= [4,0,0]
4a527879c7ab Fix Python bindings build with gcc < 4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4395
diff changeset
   140
        and conf.check_compilation_flag('-fvisibility=hidden')):
4253
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   141
        conf.env.append_value('CXXFLAGS_PYEXT', '-fvisibility=hidden')
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   142
        conf.env.append_value('CCFLAGS_PYEXT', '-fvisibility=hidden')
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   143
7746
c1a97d303064 Add -Wno-array-bounds to compile the python bindings, for clang
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7716
diff changeset
   144
    if conf.check_compilation_flag('-Wno-array-bounds'):
c1a97d303064 Add -Wno-array-bounds to compile the python bindings, for clang
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7716
diff changeset
   145
        conf.env.append_value('CXXFLAGS_PYEXT', '-Wno-array-bounds')
c1a97d303064 Add -Wno-array-bounds to compile the python bindings, for clang
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7716
diff changeset
   146
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   147
    # Check for the location of pybindgen
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   148
    if Options.options.with_pybindgen is not None:
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   149
        if os.path.isdir(Options.options.with_pybindgen):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   150
            conf.msg("Checking for pybindgen location", ("%s (given)" % Options.options.with_pybindgen))
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   151
            conf.env['WITH_PYBINDGEN'] = os.path.abspath(Options.options.with_pybindgen)
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   152
    else:
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   153
        # ns-3-dev uses ../pybindgen, while ns-3 releases use ../REQUIRED_PYBINDGEN_VERSION
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   154
        pybindgen_dir = os.path.join('..', "pybindgen")
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   155
        pybindgen_release_str = "pybindgen-" + '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   156
        pybindgen_release_dir = os.path.join('..', pybindgen_release_str)
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   157
        if os.path.isdir(pybindgen_dir):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   158
            conf.msg("Checking for pybindgen location", ("%s (guessed)" % pybindgen_dir))
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   159
            conf.env['WITH_PYBINDGEN'] = os.path.abspath(pybindgen_dir)
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   160
        elif os.path.isdir(pybindgen_release_dir):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   161
            conf.msg("Checking for pybindgen location", ("%s (guessed)" % pybindgen_release_dir))
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   162
            conf.env['WITH_PYBINDGEN'] = os.path.abspath(pybindgen_release_dir)
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   163
        del pybindgen_dir
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   164
        del pybindgen_release_dir
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   165
    if not conf.env['WITH_PYBINDGEN']:
7509
2531d57f638e Minor cleanup
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7503
diff changeset
   166
        conf.msg("Checking for pybindgen location", False)
3873
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   167
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   168
    # Check for pybindgen
3873
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   169
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   170
    set_pybindgen_pythonpath(conf.env)
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   171
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
        conf.check_python_module('pybindgen')
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   174
    except Errors.ConfigurationError:
4077
d2e461e575f4 Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4076
diff changeset
   175
        Logs.warn("pybindgen missing => no python bindings")
d2e461e575f4 Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4076
diff changeset
   176
        conf.report_optional_feature("python", "Python Bindings", False,
d2e461e575f4 Don't build or fetch NSC/pybindgen, those tasks are now moved to ns-3-allinone
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4076
diff changeset
   177
                                     "PyBindGen missing")
4082
048db3e90b9b Bug 467: waf configure enables python after detecting pybindgen is missing
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4077
diff changeset
   178
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
    else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   180
        out = subprocess.Popen([conf.env['PYTHON'][0], "-c",
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
                                "import pybindgen.version; "
11541
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
   182
                                "print(pybindgen.__version__)"],
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
                                stdout=subprocess.PIPE).communicate()[0]
11661
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
   184
        pybindgen_version = maybe_decode(out.strip())
11541
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
   185
        conf.msg('Checking for pybindgen version', pybindgen_version)
4457
1b45505f9a52 Don't allow pybindgen version greater than our requested version, to avoid python scanning generating backward incompatible API defs.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4440
diff changeset
   186
        if not (pybindgen_version == REQUIRED_PYBINDGEN_VERSION):
11541
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
   187
            Logs.warn("pybindgen (found %r), (need %r)" %
f53094838f22 Update to get pybindgen from github, with new version scheme
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 11471
diff changeset
   188
                      (pybindgen_version, REQUIRED_PYBINDGEN_VERSION))
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   189
            conf.report_optional_feature("python", "Python Bindings", False,
4457
1b45505f9a52 Don't allow pybindgen version greater than our requested version, to avoid python scanning generating backward incompatible API defs.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4440
diff changeset
   190
                                         "PyBindGen version not correct and newer version could not be retrieved")
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   191
            return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   192
5767
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   193
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   194
    def test(t1, t2):
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   195
        test_program = '''
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   196
#include <stdint.h>
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   197
#include <vector>
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   198
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   199
int main ()
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   200
{
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   201
   std::vector< %(type1)s > t = std::vector< %(type2)s > ();
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   202
   return 0;
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   203
}
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   204
''' % dict(type1=t1, type2=t2)
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   205
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   206
        try:
11458
126b15bc1efc Fix Python bindings wscript and waf-tools for Waf 1.8
Vedran Miletić <rivanvx@gmail.com>
parents: 11074
diff changeset
   207
            ret = conf.check(compiler='cxx', fragment=test_program, features='cxx')
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   208
        except Errors.ConfigurationError:
11458
126b15bc1efc Fix Python bindings wscript and waf-tools for Waf 1.8
Vedran Miletić <rivanvx@gmail.com>
parents: 11074
diff changeset
   209
            ret = False
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   210
        conf.msg('Checking for types %s and %s equivalence' % (t1, t2), (ret and 'no' or 'yes'))
11458
126b15bc1efc Fix Python bindings wscript and waf-tools for Waf 1.8
Vedran Miletić <rivanvx@gmail.com>
parents: 11074
diff changeset
   211
        return ret
5767
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   212
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   213
    uint64_is_long = test("uint64_t", "unsigned long")
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   214
    uint64_is_long_long = test("uint64_t", "unsigned long long")
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   215
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   216
    if uint64_is_long:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   217
        conf.env['PYTHON_BINDINGS_APIDEFS'] = 'gcc-LP64'
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   218
    elif uint64_is_long_long:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   219
        conf.env['PYTHON_BINDINGS_APIDEFS'] = 'gcc-ILP32'
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   220
    else:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   221
        conf.env['PYTHON_BINDINGS_APIDEFS'] = None
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   222
    if conf.env['PYTHON_BINDINGS_APIDEFS'] is None:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   223
        msg = 'none available'
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   224
    else:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   225
        msg = conf.env['PYTHON_BINDINGS_APIDEFS']
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   226
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   227
    conf.msg('Checking for the apidefs that can be used for Python bindings', msg)
5767
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   228
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   229
    if conf.env['PYTHON_BINDINGS_APIDEFS'] is None:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   230
        conf.report_optional_feature("python", "Python Bindings", False,
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   231
                                     "No apidefs are available that can be used in this system")
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   232
        return
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   233
6919
82217d4007bc Bug 1076 - Waf gives an error if you enable only a single module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6918
diff changeset
   234
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
    ## If all has gone well, we finally enable the Python bindings
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
    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
   237
    conf.report_optional_feature("python", "Python Bindings", True, None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   239
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   240
    # check cxxabi stuff (which Mac OS X Lion breaks)
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   241
    fragment = r"""
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   242
# include <cxxabi.h>
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   243
int main ()
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   244
{
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   245
   const abi::__si_class_type_info *_typeinfo  __attribute__((unused)) = NULL;
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   246
   return 0;
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   247
}
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   248
"""
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   249
    gcc_rtti_abi = conf.check_nonfatal(fragment=fragment, msg="Checking for internal GCC cxxabi",
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   250
                                       okmsg="complete", errmsg='incomplete',
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   251
                                       mandatory=False)
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   252
    conf.env["GCC_RTTI_ABI_COMPLETE"] = str(bool(gcc_rtti_abi))
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   253
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   254
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7373
diff changeset
   255
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   256
    ## Check for pygccxml
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   257
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
        conf.check_python_module('pygccxml')
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   259
    except Errors.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
   260
        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
   261
                                     "Missing 'pygccxml' Python module")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   263
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   264
    out = subprocess.Popen([conf.env['PYTHON'][0], "-c",
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   265
                            "import pygccxml; print pygccxml.__version__"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
                            stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
    pygccxml_version_str = out.strip()
11074
ff5ee93352fe Bug 2013: pygccxml versions > 1.0.0 prepend a 'v' to version number
Ben Newton <bn@cs.unc.edu>
parents: 10973
diff changeset
   268
    # Bug 2013:  pygccxml versions > 1.0.0 prepend a 'v' to version number
ff5ee93352fe Bug 2013: pygccxml versions > 1.0.0 prepend a 'v' to version number
Ben Newton <bn@cs.unc.edu>
parents: 10973
diff changeset
   269
    pygccxml_version_str = pygccxml_version_str.lstrip('v')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    pygccxml_version = tuple([int(x) for x in pygccxml_version_str.split('.')])
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   271
    conf.msg('Checking for pygccxml version', pygccxml_version_str)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
    if not (pygccxml_version >= REQUIRED_PYGCCXML_VERSION):
4067
165b38956c24 Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   273
        Logs.warn("pygccxml (found %s) is too old (need %s) => "
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
                "automatic scanning of API definitions will not be possible" %
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
                (pygccxml_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   276
                 '.'.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
   277
        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
   278
                                     "pygccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
        return
10969
99f95535826f Python bindings: fix generation of callback wrappers with the newest pybindgen
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10820
diff changeset
   280
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   282
    ## Check gccxml version
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   283
    try:
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   284
        gccxml = conf.find_program('gccxml', var='GCCXML')
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   285
    except WafError:
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   286
        gccxml = None
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
    if not gccxml:
4067
165b38956c24 Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   288
        Logs.warn("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
   289
        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
   290
                                     "gccxml missing")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   292
11459
b08e8279b57d Fix printing of gccxml version (Waf 1.8 API change)
Vedran Miletić <rivanvx@gmail.com>
parents: 11458
diff changeset
   293
    gccxml_version_line = os.popen(gccxml[0] + " --version").readline().strip()
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
    m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line)
11582
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   295
    try:
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   296
        gccxml_version = m.group(1)
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   297
        gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9])
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   298
    except AttributeError:
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   299
        gccxml_version = gccxml_version_line
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   300
        gccxml_version_ok = False
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   301
    conf.msg('Checking for gccxml version', gccxml_version)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   302
    if not gccxml_version_ok:
11582
60fd364fb2a5 Detect gccxml using CastXML wrapper in waf configure
Vedran Miletić <rivanvx@gmail.com>
parents: 11541
diff changeset
   303
        Logs.warn("gccxml version unknown or 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
   304
        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
   305
                                     "gccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   306
        return
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   307
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
    ## If we reached
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
    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
   310
    conf.report_optional_feature("pygccxml", "Python API Scanning Support", True, None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   312
# ---------------------
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   313
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   314
def get_headers_map(bld):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   315
    headers_map = {} # header => module
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   316
    for ns3headers in bld.all_task_gen:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   317
        if 'ns3header' in getattr(ns3headers, "features", []):
6970
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   318
            if ns3headers.module.endswith('-test'):
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   319
                continue
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   320
            for h in ns3headers.to_list(ns3headers.headers):
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   321
                headers_map[os.path.basename(h)] = ns3headers.module
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   322
    return headers_map
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   323
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   324
def get_module_path(bld, module):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   325
    for ns3headers in bld.all_task_gen:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   326
        if 'ns3header' in getattr(ns3headers, "features", []):
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   327
            if ns3headers.module == module:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   328
                break
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   329
    else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   330
        raise ValueError("Module %r not found" % module)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   331
    return ns3headers.path.abspath()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   332
10214
045d74ea9550 waf --apiscan will no longer try to abort waf build at the end of scanning, to avoid the waf hang. Fixes #1622.
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10212
diff changeset
   333
class apiscan_task(Task.Task):
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   334
    """Uses gccxml to scan the file 'everything.h' and extract API definitions.
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   335
    """
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7470
diff changeset
   336
    after = 'gen_ns3_module_header ns3header'
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   337
    before = 'cxx command'
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   338
    color = "BLUE"
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   339
    def __init__(self, curdirnode, env, bld, target, cflags, module):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   340
        self.bld = bld
10214
045d74ea9550 waf --apiscan will no longer try to abort waf build at the end of scanning, to avoid the waf hang. Fixes #1622.
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10212
diff changeset
   341
        super(apiscan_task, self).__init__(generator=self, env=env)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   342
        self.curdirnode = curdirnode
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   343
        self.env = env
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   344
        self.target = target
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   345
        self.cflags = cflags
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   346
        self.module = module
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   347
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   348
    def display(self):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   349
        return 'api-scan-%s\n' % (self.target,)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   350
9721
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   351
    def uid(self):
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   352
        try:
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   353
            return self.uid_
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   354
        except AttributeError:
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   355
            m = Utils.md5()
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   356
            up = m.update
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   357
            up(self.__class__.__name__.encode())
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   358
            up(self.curdirnode.abspath().encode())
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   359
            up(self.target)
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   360
            self.uid_ = m.digest()
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   361
            return self.uid_
337ed5271d36 bug 1562: waf upgrade, patch to launch apiscan task
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9295
diff changeset
   362
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   363
    def run(self):
10214
045d74ea9550 waf --apiscan will no longer try to abort waf build at the end of scanning, to avoid the waf hang. Fixes #1622.
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10212
diff changeset
   364
        self.inputs = [self.bld.bldnode.find_resource("ns3/{0}-module.h".format(self.module))]
045d74ea9550 waf --apiscan will no longer try to abort waf build at the end of scanning, to avoid the waf hang. Fixes #1622.
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10212
diff changeset
   365
        self.outputs = [self.bld.srcnode.find_resource("src/{}/bindings/modulegen__{}.py".format(self.module, self.target))]
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   366
        top_builddir = self.bld.bldnode.abspath()
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   367
        module_path = get_module_path(self.bld, self.module)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   368
        headers_map = get_headers_map(self.bld)
6926
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   369
        scan_header = os.path.join(top_builddir, "ns3", "%s-module.h" % self.module)
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   370
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   371
        if not os.path.exists(scan_header):
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   372
            Logs.error("Cannot apiscan module %r: %s does not exist" % (self.module, scan_header))
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   373
            return 0
1b32cc1532a9 Modular bindings: before scanning a module, check that xxx-module.h exists, skip the scanning if it doesn't
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6923
diff changeset
   374
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   375
        argv = [
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   376
            self.env['PYTHON'][0],
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   377
            os.path.join(self.curdirnode.abspath(), 'ns3modulescan-modular.py'), # scanning script
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   378
            top_builddir,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   379
            self.module,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   380
            repr(get_headers_map(self.bld)),
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   381
            os.path.join(module_path, "bindings", 'modulegen__%s.py' % (self.target)), # output file
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   382
            self.cflags,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   383
            ]
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   384
        scan = subprocess.Popen(argv, stdin=subprocess.PIPE)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   385
        retval = scan.wait()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   386
        return retval
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   387
10398
458687e0055d bug 1622: make apiscan Task always run
Tom Henderson <tomh@tomh.org>
parents: 10214
diff changeset
   388
    def runnable_status(self):
10423
dface7efc30d update comment to align with ns-3.18.1
Tom Henderson <tomh@tomh.org>
parents: 10398
diff changeset
   389
        # By default, Waf Task will skip running a task if the signature of
dface7efc30d update comment to align with ns-3.18.1
Tom Henderson <tomh@tomh.org>
parents: 10398
diff changeset
   390
        # the build has not changed.  We want this task to always run if
dface7efc30d update comment to align with ns-3.18.1
Tom Henderson <tomh@tomh.org>
parents: 10398
diff changeset
   391
        # invoked by the user, particularly since --apiscan=all will require
dface7efc30d update comment to align with ns-3.18.1
Tom Henderson <tomh@tomh.org>
parents: 10398
diff changeset
   392
        # invoking this task many times, once per module.
10398
458687e0055d bug 1622: make apiscan Task always run
Tom Henderson <tomh@tomh.org>
parents: 10214
diff changeset
   393
        return RUN_ME
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   394
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   395
def get_modules_and_headers(bld):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   396
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   397
    Gets a dict of
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   398
       module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   399
    tuples, one for each module.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   400
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   401
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   402
    retval = {}
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   403
    for module in bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   404
        if not module.name.startswith('ns3-'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   405
            continue
6970
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   406
        if module.name.endswith('-test'):
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   407
            continue
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   408
        module_name = module.name[4:] # strip the ns3- prefix
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   409
        ## find the headers object for this module
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   410
        headers = []
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   411
        for ns3headers in bld.all_task_gen:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   412
            if 'ns3header' not in getattr(ns3headers, "features", []):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   413
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   414
            if ns3headers.module != module_name:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   415
                continue
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   416
            for source in ns3headers.to_list(ns3headers.headers):
6797
613a82415ae3 Fix Python scanning to allow apidefs to be placed on the right module instead of the main ns3module.cc file, for new-style modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   417
                headers.append(os.path.basename(source))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   418
        retval[module_name] = (list(module.module_deps), headers)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   419
    return retval
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   420
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   421
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
   422
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   423
6961
ca0f33d08fd0 Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6960
diff changeset
   424
class gen_ns3_compat_pymod_task(Task.Task):
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   425
    """Generates a 'ns3.py' compatibility module."""
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   426
    before = 'cxx'
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   427
    color = 'BLUE'
10969
99f95535826f Python bindings: fix generation of callback wrappers with the newest pybindgen
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10820
diff changeset
   428
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   429
    def run(self):
6961
ca0f33d08fd0 Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6960
diff changeset
   430
        assert len(self.outputs) == 1
11661
68c0e7f87bdf additional Python 2/3 compatibility
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
   431
        outfile = open(self.outputs[0].abspath(), "w")
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   432
        print("import warnings", file=outfile)
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   433
        print('warnings.warn("the ns3 module is a compatibility layer '\
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   434
            'and should not be used in newly written code", DeprecationWarning, stacklevel=2)', file=outfile)
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   435
        print(file=outfile)
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   436
        for module in self.bld.env['PYTHON_MODULES_BUILT']:
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   437
            print("from ns.%s import *" % (module.replace('-', '_')), file=outfile)
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   438
        outfile.close()
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   439
        return 0
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   440
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   441
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6893
diff changeset
   442
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   443
def build(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   444
    if Options.options.python_disable:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   445
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   446
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   447
    env = bld.env
3873
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   448
    set_pybindgen_pythonpath(env)
2ad80d9647f0 Add a --with-pybindgen option, to allow external pybindgen to be used instead of fetching it from the network
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3868
diff changeset
   449
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   450
    if Options.options.apiscan:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   451
        if not env['ENABLE_PYTHON_SCANNING']:
7555
9dfb9d9c295f Fix typos: Utils.WafError -> WafError
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   452
            raise WafError("Cannot re-scan python bindings: (py)gccxml not available")
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   453
        scan_targets = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   454
        if sys.platform == 'cygwin':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   455
            scan_targets.append(('gcc_cygwin', ''))
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   456
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   457
            import struct
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   458
            if struct.calcsize('I') == 4 and struct.calcsize('L') == 8 and struct.calcsize('P') == 8:
10639
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
   459
                if not Options.options.no32bit_scan:
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
   460
                    scan_targets.append(('gcc_ILP32', '-m32'))
6600e199f788 Add option to disable scanning for 32-bit bindings on 64-bit platforms
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 10629
diff changeset
   461
                scan_targets.append(('gcc_LP64', '-m64'))
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   462
            elif struct.calcsize('I') == 4 and struct.calcsize('L') == 4 and struct.calcsize('P') == 4:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   463
                scan_targets.append(('gcc_ILP32', ''))
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   464
            else:
7555
9dfb9d9c295f Fix typos: Utils.WafError -> WafError
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   465
                raise WafError("Cannot scan python bindings for unsupported data model")
6927
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   466
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   467
        test_module_path = bld.path.find_dir("../../src/test")
6923
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
   468
        if Options.options.apiscan == 'all':
6927
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   469
            scan_modules = []
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   470
            for mod in bld.all_task_gen:
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   471
                if not mod.name.startswith('ns3-'):
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   472
                    continue
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   473
                if mod.path.is_child_of(test_module_path):
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   474
                    continue
6928
c305a6f33912 ./waf --apiscan=all: don't scan modules ending in -test
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6927
diff changeset
   475
                if mod.name.endswith('-test'):
c305a6f33912 ./waf --apiscan=all: don't scan modules ending in -test
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6927
diff changeset
   476
                    continue
6933
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6928
diff changeset
   477
                bindings_enabled = (mod.name in env.MODULAR_BINDINGS_MODULES)
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6928
diff changeset
   478
                #print mod.name, bindings_enabled
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6928
diff changeset
   479
                if bindings_enabled:
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6928
diff changeset
   480
                    scan_modules.append(mod.name.split('ns3-')[1])
6923
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
   481
        else:
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
   482
            scan_modules = Options.options.apiscan.split(',')
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 11582
diff changeset
   483
        print("Modules to scan: ", scan_modules)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   484
        for target, cflags in scan_targets:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   485
            group = bld.get_group(bld.current_group)
6923
57c9dfe52e67 Modular bindings: add support for the apiscan target 'all', that means scan all ns-3 modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6922
diff changeset
   486
            for module in scan_modules:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   487
                group.append(apiscan_task(bld.path, env, bld, target, cflags, module))
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   488
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   489
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   490
7470
234c01373116 Re-enable the 'ns3' compatility python module, previously accidentally disabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7468
diff changeset
   491
    if env['ENABLE_PYTHON_BINDINGS']:
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   492
        task = gen_ns3_compat_pymod_task(env=env.derive())
6961
ca0f33d08fd0 Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6960
diff changeset
   493
        task.set_outputs(bld.path.find_or_declare("ns3.py"))
ca0f33d08fd0 Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6960
diff changeset
   494
        task.dep_vars = ['PYTHON_MODULES_BUILT']
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   495
        task.bld = bld
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   496
        grp = bld.get_group(bld.current_group)
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   497
        grp.append(task)
6961
ca0f33d08fd0 Modular bindings: don't always generate compat ns3.py, only when needed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6960
diff changeset
   498
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 8896
diff changeset
   499
        bld(features='copy', source="ns__init__.py", target='ns/__init__.py')
7676
e1e64c0fa1da Install the ns/__init__.py file also in PYTHONARCHDIR; fixes #1329.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7672
diff changeset
   500
        bld.install_as('${PYTHONARCHDIR}/ns/__init__.py', 'ns__init__.py')
7536
1f697c6f0b12 Bug 1257 - waf install __init__ Python files even with --disable-python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7517
diff changeset
   501
1f697c6f0b12 Bug 1257 - waf install __init__ Python files even with --disable-python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7517
diff changeset
   502
7451
7e112cf83737 Bug 1240 - remove monolithic python bindings from waf
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7408
diff changeset
   503
    # note: the actual build commands for the python bindings are in
7e112cf83737 Bug 1240 - remove monolithic python bindings from waf
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7408
diff changeset
   504
    # src/wscript, not here.