bindings/python/wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue, 29 Mar 2011 18:50:56 +0100
changeset 6973 0512aabc17ad
parent 6970 d00c79a3cf1f
child 6995 7ae22c26c5da
permissions -rw-r--r--
Tentatively switch to build modular bindings by default, to test them
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; -*-
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
     2
import types
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
import re
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
import os
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
import pproc as subprocess
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
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
     7
import sys
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
     9
import Task
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    10
import Options
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    11
import Configure
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    12
import TaskGen
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    13
import Logs
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    14
import Build
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    15
import Utils
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    16
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
## https://launchpad.net/pybindgen/
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6933
diff changeset
    18
REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 779)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
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
    22
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    23
from TaskGen import feature, after
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    24
import Task, ccroot
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    25
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    26
@feature('pch')
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    27
@after('apply_link')
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    28
def process_pch(self):
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    29
    node = self.path.find_resource(self.pch)
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    30
    assert node
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    31
    tsk = self.create_task('gchx')
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    32
    tsk.set_inputs(node)
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    33
    tsk.set_outputs(node.parent.find_or_declare(node.name + '.gch'))
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    34
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    35
comp_line = '${CXX} ${CXXFLAGS} ${CPPFLAGS} ${_CXXINCFLAGS} ${_CXXDEFFLAGS} ${SRC} -o ${TGT}'
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    36
cls = Task.simple_task_type('gchx', comp_line, before='cc cxx')
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    37
cls.scan = ccroot.scan
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    38
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    39
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    40
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    41
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
    42
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
    43
    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
    44
        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
    45
    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
    46
        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
    47
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
    48
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
    49
    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
    50
        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
    51
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
    52
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
def set_options(opt):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    opt.tool_options('python')
6879
fdb88975069a Document in the --bindings-type waf option that modular bindings are experimental
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
    55
    c = ("monolithic", "modular", "both")
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
    56
    opt.add_option('--bindings-type', type="choice",
6879
fdb88975069a Document in the --bindings-type waf option that modular bindings are experimental
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
    57
                   choices=c,
fdb88975069a Document in the --bindings-type waf option that modular bindings are experimental
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
    58
                   help=("Type of Python bindings to build %r.  "
fdb88975069a Document in the --bindings-type waf option that modular bindings are experimental
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
    59
                         "Warning: the modular bindings are still experimental." % (c,)),
6973
0512aabc17ad Tentatively switch to build modular bindings by default, to test them
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6970
diff changeset
    60
                   default="modular",
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
    61
                   dest='bindings_type')
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
    62
    opt.add_option('--disable-python',
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
                   help=("Don't build Python bindings."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
                   dest='python_disable')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
    opt.add_option('--python-scan',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
                   help=("Rescan Python bindings.  Needs working GCCXML / pygccxml environment."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
                   dest='python_scan')
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
    70
    opt.add_option('--apiscan',
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
    71
                   help=("EXPERIMENTAL: Rescan the API for the indicated module(s), for Python bindings.  "
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
    72
                         "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
    73
                         "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
    74
                   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
    75
    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
    76
                   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
    77
                   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
    78
                   dest='with_pybindgen', type="string")
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
    79
    opt.add_option('--enable-python-pch',
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    80
                   help=("Enable precompiled headers when compiling python bindings, to speed up compilation."),
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    81
                   action="store_true", default=False,
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
    82
                   dest='enable_python_pch')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
def configure(conf):
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
    86
    conf.env['ENABLE_PYTHON_PCH'] = Options.options.enable_python_pch
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
    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
    88
    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
    89
        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
    90
                                     "disabled by user request")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
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
    93
    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
    94
    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
    95
    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
    96
    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
    97
    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
    98
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
    conf.check_tool('misc')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
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
   101
    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
   102
        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
   103
                                     "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
   104
        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
   105
        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
   106
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
    ## Check for Python
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
        conf.check_tool('python')
3473
6bce86ea4778 Require new PyBindGen; make it work for Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3468
diff changeset
   110
        conf.check_python_version((2,3))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
        conf.check_python_headers()
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
   112
    except Configure.ConfigurationError, ex:
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
   113
        conf.report_optional_feature("python", "Python Bindings", False, str(ex))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
4253
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
   116
    # -fvisibility=hidden optimization
4430
4a527879c7ab Fix Python bindings build with gcc < 4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4395
diff changeset
   117
    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
   118
        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
   119
        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
   120
        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
   121
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   122
    # 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
   123
    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
   124
        if os.path.isdir(Options.options.with_pybindgen):
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   125
            conf.check_message("pybindgen location", '', True, ("%s (given)" % Options.options.with_pybindgen))
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   126
            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
   127
    else:
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   128
        # 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
   129
        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
   130
        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
   131
        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
   132
        if os.path.isdir(pybindgen_dir):
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   133
            conf.check_message("pybindgen location", '', True, ("%s (guessed)" % pybindgen_dir))
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   134
            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
   135
        elif os.path.isdir(pybindgen_release_dir):
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   136
            conf.check_message("pybindgen location", '', True, ("%s (guessed)" % pybindgen_release_dir))
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   137
            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
   138
        del pybindgen_dir
6591
174d88119ebf Help waf to guess release versions of nsc and pybindgen
Tom Henderson <tomh@tomh.org>
parents: 6574
diff changeset
   139
        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
   140
    if not conf.env['WITH_PYBINDGEN']:
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   141
        conf.check_message("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
   142
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   143
    # 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
   144
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
   145
    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
   146
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
        conf.check_python_module('pybindgen')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
    except Configure.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
   150
        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
   151
        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
   152
                                     "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
   153
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
    else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
        out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
                                "import pybindgen.version; "
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
                                "print '.'.join([str(x) for x in pybindgen.version.__version__])"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
                                stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
        pybindgen_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
        pybindgen_version = tuple([int(x) for x in pybindgen_version_str.split('.')])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
        conf.check_message('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
   162
                           (pybindgen_version == REQUIRED_PYBINDGEN_VERSION),
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
                           pybindgen_version_str)
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
   164
        if not (pybindgen_version == REQUIRED_PYBINDGEN_VERSION):
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
   165
            Logs.warn("pybindgen (found %s), (need %s)" %
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
                    (pybindgen_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
                     '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])))
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   168
            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
   169
                                         "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
   170
            return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
5767
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   172
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   173
    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
   174
        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
   175
#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
   176
#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
   177
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   178
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
   179
{
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   180
   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
   181
   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
   182
}
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   183
''' % 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
   184
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   185
        try:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   186
            ret = conf.run_c_code(code=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
   187
                                  env=conf.env.copy(), compile_filename='test.cc',
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   188
                                  compile_mode='cxx',type='cprogram', execute=False)
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   189
        except Configure.ConfigurationError:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   190
            ret = 1
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   191
        conf.check_message_custom('types %s and %s' % (t1, t2), 'equivalency', (ret and 'no' or 'yes'))
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   192
        return not ret
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
    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
   195
    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
   196
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   197
    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
   198
        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
   199
    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
   200
        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
   201
    else:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   202
        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
   203
    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
   204
        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
   205
    else:
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   206
        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
   207
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   208
    conf.check_message_custom('the apidefs that can be used for Python bindings', '', msg)
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   209
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   210
    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
   211
        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
   212
                                     "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
   213
        return
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   214
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
   215
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
   216
    conf.env['BINDINGS_TYPE'] = Options.options.bindings_type
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
   217
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
   218
    if not all_modules_enabled:
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
   219
        if conf.env['BINDINGS_TYPE'] == 'both':
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
   220
            conf.env['BINDINGS_TYPE'] = 'modular'
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
   221
        elif conf.env['BINDINGS_TYPE'] == 'monolithic':
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
   222
            conf.report_optional_feature("python", "Python Bindings", False, "Monolithic python bindings need all ns-3 modules to be enabled")
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
   223
            return
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
   224
            
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   225
    ## 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
   226
    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
   227
    conf.report_optional_feature("python", "Python Bindings", True, None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   228
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   229
    if conf.env['BINDINGS_TYPE'] == 'both':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   230
        msg = "monolithic and modular"
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   231
    else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   232
        msg = conf.env['BINDINGS_TYPE']
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   233
    conf.check_message_custom('type of bindings to build', '', 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
   234
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
    ## Check for pygccxml
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
        conf.check_python_module('pygccxml')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
    except Configure.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
   239
        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
   240
                                     "Missing 'pygccxml' Python module")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   241
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   242
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   243
    out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   244
                            "import pygccxml; print pygccxml.__version__"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
                            stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   246
    pygccxml_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
    pygccxml_version = tuple([int(x) for x in pygccxml_version_str.split('.')])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   248
    conf.check_message('pygccxml', 'version',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   249
                       (pygccxml_version >= REQUIRED_PYGCCXML_VERSION),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   250
                       pygccxml_version_str)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   251
    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
   252
        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
   253
                "automatic scanning of API definitions will not be possible" %
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   254
                (pygccxml_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   255
                 '.'.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
   256
        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
   257
                                     "pygccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
    
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   260
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   261
    ## Check gccxml version
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
    gccxml = conf.find_program('gccxml', var='GCCXML')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   263
    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
   264
        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
   265
        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
   266
                                     "gccxml missing")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   268
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
    gccxml_version_line = os.popen(gccxml + " --version").readline().strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
    gccxml_version = m.group(1)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
    gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
    conf.check_message('gccxml', 'version', True, gccxml_version)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
    if not gccxml_version_ok:
4067
165b38956c24 Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   275
        Logs.warn("gccxml 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
   276
        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
   277
                                     "gccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
        return
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   279
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
    ## If we reached
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
    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
   282
    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
   283
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   284
    
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   285
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   286
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   287
# ---------------------
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   288
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   289
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
   290
    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
   291
    for ns3headers in bld.all_task_gen:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   292
        if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare
6970
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   293
            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
   294
                continue
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   295
            for h in ns3headers.to_list(ns3headers.source):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   296
                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
   297
    return headers_map
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   298
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   299
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
   300
    for ns3headers in bld.all_task_gen:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   301
        if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   302
            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
   303
                break
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   304
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   305
    else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   306
        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
   307
    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
   308
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   309
class apiscan_task(Task.TaskBase):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   310
    """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
   311
    """
6899
b203843366e5 Modular bindings: waf dep. fix.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6897
diff changeset
   312
    after = 'gen_ns3_module_header_task ns3header_task'
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   313
    before = 'cc cxx gchx'
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   314
    color = "BLUE"
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   315
    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
   316
        self.bld = bld
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   317
        super(apiscan_task, self).__init__(generator=self)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   318
        self.curdirnode = curdirnode
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   319
        self.env = env
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   320
        self.target = target
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   321
        self.cflags = cflags
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   322
        self.module = module
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 display(self):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   325
        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
   326
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   327
    def run(self):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   328
        top_builddir = self.curdirnode.find_dir('../..').abspath(self.env)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   329
        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
   330
        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
   331
        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
   332
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
   333
        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
   334
            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
   335
            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
   336
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   337
        argv = [
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   338
            self.env['PYTHON'],
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   339
            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
   340
            top_builddir,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   341
            self.module,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   342
            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
   343
            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
   344
            self.cflags,
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   345
            ]
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   346
        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
   347
        retval = scan.wait()
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   348
        return retval
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   349
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   350
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   351
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   352
# --------------
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   353
prio_headers = {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   354
    -2: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   355
        "string.h", # work around http://www.gccxml.org/Bug/view.php?id=6682
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   356
        ),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   357
    -1: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   358
        "propagation-delay-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   359
        "propagation-loss-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   360
        "net-device.h",
4742
f22beb219798 Re-scan Python bindings and use newer PyBindGen.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4535
diff changeset
   361
        "ipv4-interface.h",
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   362
        )
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   363
     }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   364
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   365
def get_header_prio(header):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   366
    for prio, headers in prio_headers.iteritems():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   367
        if header in headers:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   368
            return prio
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   369
    return 1
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   370
3485
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   371
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   372
def calc_header_include(path):
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   373
    (head, tail) = os.path.split (path)
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   374
    if tail == 'ns3':
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   375
        return ''
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   376
    else:
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   377
        return os.path.join (calc_header_include (head), tail)
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   378
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   379
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   380
class gen_everything_h_task(Task.Task):
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
   381
    before = 'cc cxx gchx'
4068
e0eb69d55e40 correct dependency problem
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4067
diff changeset
   382
    after = 'ns3header_task'
e0eb69d55e40 correct dependency problem
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4067
diff changeset
   383
    color = 'BLUE'
3485
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   384
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   385
    def run(self):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   386
        assert len(self.outputs) == 1
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   387
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   388
        header_files = [calc_header_include(node.abspath(self.env)) for node in self.inputs]
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   389
        outfile = file(self.outputs[0].bldpath(self.env), "w")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   390
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   391
        def sort_func(h1, h2):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   392
            return cmp((get_header_prio(h1), h1), (get_header_prio(h1), h2))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   393
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   394
        header_files.sort(sort_func)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   395
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   396
        print >> outfile, """
3917
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   397
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   398
/* http://www.nsnam.org/bugzilla/show_bug.cgi?id=413 */
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   399
#ifdef ECHO
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   400
# undef ECHO
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   401
#endif
fe95a4f9d423 Work around #define ECHO in a system header file included by Python.h on Mac OS X (bug #413)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3875
diff changeset
   402
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   403
    """
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   404
        for header in header_files:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   405
            print >> outfile, "#include \"ns3/%s\"" % (header,)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   406
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   407
        print >> outfile, """
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   408
namespace ns3 {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   409
static inline Ptr<Object>
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   410
__dummy_function_to_force_template_instantiation (Ptr<Object> obj, TypeId typeId)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   411
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   412
   return obj->GetObject<Object> (typeId);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   413
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   414
3731
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   415
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   416
static inline void
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   417
__dummy_function_to_force_template_instantiation_v2 ()
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   418
{
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   419
   Time t1, t2, t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   420
   t1 = t2 + t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   421
   t1 = t2 - t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   422
   TimeSquare tsq = t2*t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   423
   Time tsqdiv = tsq/Seconds(1);
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   424
   Scalar scal = t2/t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   425
   TimeInvert inv = scal/t3;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   426
   t1 = scal*t1;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   427
   t1 = t1/scal;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   428
   t1 < t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   429
   t1 <= t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   430
   t1 == t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   431
   t1 != t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   432
   t1 >= t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   433
   t1 > t2;
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   434
}
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3728
diff changeset
   435
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3917
diff changeset
   436
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   437
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   438
"""
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   439
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   440
        return 0
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   441
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   442
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
   443
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   444
class all_ns3_headers_taskgen(TaskGen.task_gen):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   445
    """Generates a 'everything.h' header file that includes some/all public ns3 headers.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   446
    This single header file is to be parsed only once by gccxml, for greater efficiency.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   447
    """
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   448
    def __init__(self, *args, **kwargs):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   449
        super(all_ns3_headers_taskgen, self).__init__(*args, **kwargs)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   450
        self.install_path = None
3409
94ac3e381075 The 'everything.h' header file is only used for Python bindings and should be generated into bindings/python/, not ns3/.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
   451
        #self.inst_dir = 'ns3'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   452
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   453
    def apply(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   454
        ## get all of the ns3 headers
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   455
        ns3_dir_node = self.bld.path.find_dir("ns3")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   456
        all_headers_inputs = []
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   457
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   458
        for filename in self.to_list(self.source):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   459
            src_node = ns3_dir_node.find_or_declare(filename)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   460
            if src_node is None:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   461
                raise Utils.WafError("source ns3 header file %s not found" % (filename,))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   462
            all_headers_inputs.append(src_node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   463
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   464
        ## if self.source was empty, include all ns3 headers in enabled modules
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   465
        if not all_headers_inputs:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   466
            for ns3headers in self.bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   467
                if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   468
                    ## skip headers not part of enabled modules
6970
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   469
                    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
   470
                        continue
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   471
                    if self.env['NS3_ENABLED_MODULES']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   472
                        if ("ns3-%s" % ns3headers.module) not in self.env['NS3_ENABLED_MODULES']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   473
                            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   474
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   475
                    for source in ns3headers.to_list(ns3headers.source):
3485
26de1421d000 When generating the everything.h header file for Python, handle ns3 headers inside subdirectories properly.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3474
diff changeset
   476
                        #source = os.path.basename(source)
6399
49cf05006165 Allow headers to be in subdirectories with respect to wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6352
diff changeset
   477
                        node = ns3_dir_node.find_or_declare(os.path.basename(source))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   478
                        if node is None:
4067
165b38956c24 Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   479
                            raise Utils.WafError("missing header file %s" % (source,))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   480
                        all_headers_inputs.append(node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   481
        assert all_headers_inputs
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   482
        all_headers_outputs = [self.path.find_or_declare("everything.h")]
5942
7c66549b828d Upgrade waf from 1.5.9 to 1.5.11
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5940
diff changeset
   483
        task = self.create_task('gen_everything_h', env=self.env)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   484
        task.set_inputs(all_headers_inputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   485
        task.set_outputs(all_headers_outputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   486
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   487
    def install(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   488
        pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   489
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   490
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   491
def get_modules_and_headers(bld):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   492
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   493
    Gets a dict of
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   494
       module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   495
    tuples, one for each module.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   496
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   497
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   498
    retval = {}
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   499
    for module in bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   500
        if not module.name.startswith('ns3-'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   501
            continue
6970
d00c79a3cf1f Make sure --python-scan ignores -test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6961
diff changeset
   502
        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
   503
            continue
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   504
        module_name = module.name[4:] # strip the ns3- prefix
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   505
        ## find the headers object for this module
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   506
        headers = []
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   507
        for ns3headers in bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   508
            if type(ns3headers).__name__ != 'ns3header_taskgen': # XXX: find less hackish way to compare
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   509
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   510
            if ns3headers.module != module_name:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   511
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   512
            for source in ns3headers.to_list(ns3headers.source):
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
   513
                headers.append(os.path.basename(source))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   514
        retval[module_name] = (list(module.module_deps), headers)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   515
    return retval
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   516
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   517
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
   518
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   519
class python_scan_task(Task.TaskBase):
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
   520
    """Uses gccxml to scan the file 'everything.h' and extract API definitions.
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
   521
    """
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   522
    after = 'gen_everything_h_task'
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
   523
    before = 'cc cxx gchx'
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   524
    color = "BLUE"
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   525
    def __init__(self, curdirnode, env, bld, target, cflags):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   526
        self.bld = bld
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   527
        super(python_scan_task, self).__init__(generator=self)
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
   528
        self.curdirnode = curdirnode
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
   529
        self.env = env
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   530
        self.target = target
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   531
        self.cflags = cflags
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   532
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   533
    def display(self):
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   534
        return 'python-scan-%s\n' % (self.target,)
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
   535
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
   536
    def run(self):
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   537
        defsdir = os.path.join(self.curdirnode.abspath(), 'apidefs', self.target)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   538
        try:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   539
            os.mkdir(defsdir)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   540
        except OSError:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   541
            pass
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
   542
        argv = [
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
   543
            self.env['PYTHON'],
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
   544
            os.path.join(self.curdirnode.abspath(), 'ns3modulescan.py'), # scanning script
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
   545
            self.curdirnode.find_dir('../..').abspath(self.env), # include path (where the ns3 include dir is)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   546
            self.curdirnode.find_or_declare('everything.h').abspath(self.env),
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   547
            os.path.join(defsdir, 'ns3modulegen_generated.py'), # output file
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   548
            self.cflags,
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
   549
            ]
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
   550
        scan = subprocess.Popen(argv, stdin=subprocess.PIPE)
6352
378abdf67899 python-scan: avoid possible deadlock passing list of modules to the api scanner process
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6290
diff changeset
   551
        print >> scan.stdin, repr(get_modules_and_headers(self.bld))
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
   552
        scan.stdin.close()
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   553
        retval = scan.wait()
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   554
        return retval
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   555
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   556
class python_scan_task_collector(Task.TaskBase):
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   557
    """Tasks that waits for the python-scan-* tasks to complete and then signals WAF to exit
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   558
    """
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   559
    after = 'python_scan_task apiscan_task'
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   560
    before = 'cc cxx'
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   561
    color = "BLUE"
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   562
    def __init__(self, curdirnode, env, bld):
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   563
        self.bld = bld
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   564
        super(python_scan_task_collector, self).__init__(generator=self)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   565
        self.curdirnode = curdirnode
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   566
        self.env = env
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   567
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   568
    def display(self):
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   569
        return 'python-scan-collector\n'
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   570
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   571
    def run(self):
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   572
        # signal stop (we generated files into the source dir and WAF
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   573
        # can't cope with it, so we have to force the user to restart
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   574
        # WAF)
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   575
        self.bld.generator.stop = 1
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   576
        return 0
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   577
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
   578
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
   579
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
   580
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
   581
    """Generates a 'ns3.py' compatibility module."""
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
   582
    before = 'cc cxx gchx'
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
   583
    color = 'BLUE'
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
   584
    
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
   585
    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
   586
        assert len(self.outputs) == 1
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
   587
        outfile = file(self.outputs[0].abspath(self.env), "w")
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
   588
        print >> outfile, "import warnings"
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
   589
        print >> outfile, 'warnings.warn("the ns3 module is a compatibility layer '\
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
   590
            'and should not be used in newly written code", DeprecationWarning, stacklevel=2)'
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
   591
        print >> outfile
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
   592
        for module in self.bld.env['PYTHON_MODULES_BUILT']:
6902
3aa6e43dfe41 Modular bindings: handle module names with hyphens
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6901
diff changeset
   593
            print >> outfile, "from ns.%s import *" % (module.replace('-', '_'))
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
   594
        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
   595
        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
   596
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
   597
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
   598
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   599
def build(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   600
    if Options.options.python_disable:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   601
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   602
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   603
    env = bld.env
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   604
    curdir = bld.path.abspath()
3591
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   605
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
   606
    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
   607
6960
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   608
    bld.new_task_gen(features='copy',
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   609
                     source="ns__init__.py",
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   610
                     target='ns/__init__.py')
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   611
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   612
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   613
    if env['ENABLE_PYTHON_BINDINGS'] and env['BINDINGS_TYPE'] in ('monolithic', 'both'):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   614
        obj = bld.new_task_gen('all_ns3_headers')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   615
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   616
    if Options.options.python_scan:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   617
        if not env['ENABLE_PYTHON_SCANNING']:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   618
            raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available")
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   619
        scan_targets = []
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   620
        if sys.platform == 'cygwin':
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   621
            scan_targets.append(('gcc-cygwin', ''))
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   622
        else:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   623
            import struct
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   624
            if struct.calcsize('I') == 4 and struct.calcsize('L') == 8 and struct.calcsize('P') == 8:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   625
                scan_targets.extend([('gcc-ILP32', '-m32'), ('gcc-LP64', '-m64')])
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   626
            elif struct.calcsize('I') == 4 and struct.calcsize('L') == 4 and struct.calcsize('P') == 4:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   627
                scan_targets.append(('gcc-ILP32', ''))
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   628
            else:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   629
                raise Utils.WafError("Cannot scan python bindings for unsupported data model")
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   630
        for target, cflags in scan_targets:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   631
            python_scan_task(bld.path, env, bld, target, cflags)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   632
        python_scan_task_collector(bld.path, env, bld)
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   633
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   634
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   635
    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
   636
        if not env['ENABLE_PYTHON_SCANNING']:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   637
            raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available")
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   638
        scan_targets = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   639
        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
   640
            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
   641
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   642
            import struct
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   643
            if struct.calcsize('I') == 4 and struct.calcsize('L') == 8 and struct.calcsize('P') == 8:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   644
                scan_targets.extend([('gcc_ILP32', '-m32'), ('gcc_LP64', '-m64')])
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   645
            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
   646
                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
   647
            else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   648
                raise Utils.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
   649
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   650
        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
   651
        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
   652
            scan_modules = []
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   653
            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
   654
                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
   655
                    continue
1bde2ae9c25b Make ./waf --apiscan=all skip the test modules
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6926
diff changeset
   656
                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
   657
                    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
   658
                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
   659
                    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
   660
                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
   661
                #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
   662
                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
   663
                    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
   664
        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
   665
            scan_modules = Options.options.apiscan.split(',')
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
   666
        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
   667
        for target, cflags in scan_targets:
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
   668
            for module in scan_modules:
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   669
                apiscan_task(bld.path, 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
   670
        python_scan_task_collector(bld.path, env, bld)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   671
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   672
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   673
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   674
    if env['ENABLE_PYTHON_BINDINGS'] and env['BINDINGS_TYPE'] in ('monolithic', 'both'):
5767
0c70949a5006 Improved detection of apidefs to use for python (Bug 734)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5753
diff changeset
   675
        apidefs = env['PYTHON_BINDINGS_APIDEFS']
3424
fd8ae9ea848b Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3423
diff changeset
   676
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   677
        ## Get a list of scanned modules; the set of scanned modules
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   678
        ## may be smaller than the set of all modules, in case a new
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   679
        ## ns3 module is being developed which wasn't scanned yet.
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   680
        scanned_modules = []
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   681
        for filename in os.listdir(os.path.join(curdir, 'apidefs', apidefs)):
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   682
            m = re.match(r"^ns3_module_(.+)\.py$", filename)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   683
            if m is None:
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   684
                continue
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   685
            name = m.group(1)
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   686
            if name.endswith("__local"):
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   687
                continue
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   688
            scanned_modules.append(name)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6591
diff changeset
   689
        print "scanned_modules:", scanned_modules
5203
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   690
        debug = ('PYBINDGEN_DEBUG' in os.environ)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   691
        source = [
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   692
            'ns3modulegen.py',
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   693
            'apidefs/%s/ns3modulegen_generated.py' % (apidefs,),
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   694
            'ns3modulegen_core_customizations.py',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   695
            ]
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   696
        target = [
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   697
            'ns3module.cc',
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
   698
            'pch/ns3module.h',
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   699
            ]
5203
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   700
        if not debug:
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   701
            target.append('ns3modulegen.log')
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   702
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   703
        argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}']
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   704
        if debug:
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   705
            argv.extend(["-m", "pdb"])
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   706
        argv.extend(['${SRC[0]}', '${TGT[0]}', os.path.join(curdir, 'apidefs', apidefs)])
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   707
        
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   708
        argv.extend(get_modules_and_headers(bld).iterkeys())
3423
f84261098ab0 Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3421
diff changeset
   709
        for module in scanned_modules:
5249
85cde7d987ed Python: allow multiple api definitions directories, one per data model.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5203
diff changeset
   710
            source.append("apidefs/%s/ns3_module_%s.py" % (apidefs, module))
3591
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   711
            local = "ns3_module_%s__local.py" % module
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   712
            if os.path.exists(os.path.join(curdir, local)):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   713
                source.append(local)
3423
f84261098ab0 Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3421
diff changeset
   714
5203
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   715
        if not debug:
1ccc02a7676b Python bindings rescan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4771
diff changeset
   716
            argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   717
3423
f84261098ab0 Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3421
diff changeset
   718
        for module in scanned_modules:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   719
            target.append("ns3_module_%s.cc" % module)
3423
f84261098ab0 Make Python bindings depend only on NS-3 modules that have been API-scanned, not all modules.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3421
diff changeset
   720
3639
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3637
diff changeset
   721
        features = []
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3637
diff changeset
   722
        for (name, caption, was_enabled, reason_not_enabled) in env['NS3_OPTIONAL_FEATURES']:
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3637
diff changeset
   723
            if was_enabled:
8e69ebf086f1 Use the information provided by conf.report_optional_feature() to enable/disable python bindings for optional APIs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3637
diff changeset
   724
                features.append(name)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   725
4312
a20c4300f959 Add code that, when waf is updated in a future version, makes sure python bindings are re-generated whenever the optional features set changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4255
diff changeset
   726
        bindgen = bld.new_task_gen('command', source=source, target=target, command=argv)
a20c4300f959 Add code that, when waf is updated in a future version, makes sure python bindings are re-generated whenever the optional features set changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4255
diff changeset
   727
        bindgen.env['FEATURES'] = ','.join(features)
a20c4300f959 Add code that, when waf is updated in a future version, makes sure python bindings are re-generated whenever the optional features set changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4255
diff changeset
   728
        bindgen.dep_vars = ['FEATURES']
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
   729
        bindgen.before = 'cxx gchx'
4088
e52c06d86145 Add dependency annotations for the task that generates Python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4082
diff changeset
   730
        bindgen.after = 'gen_everything_h_task'
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4312
diff changeset
   731
        bindgen.name = "pybindgen-command"
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
   732
 
6918
614b5388a1ae Bug 1075 - Python examples fail when static built is enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6913
diff changeset
   733
        features = 'cxx cshlib pyext'
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
   734
        if env['ENABLE_PYTHON_PCH']:
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
   735
            features += ' pch'
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
   736
        pymod = bld.new_task_gen(features=features)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   737
        pymod.source = ['ns3module.cc', 'ns3module_helpers.cc']
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
   738
        pymod.includes = '. pch'
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
   739
        if env['ENABLE_PYTHON_PCH']:
86045031f03a Add option to enable gcc precompiled header for compiling python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6134
diff changeset
   740
            pymod.pch = 'pch/ns3module.h'
3424
fd8ae9ea848b Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3423
diff changeset
   741
        for module in scanned_modules:
fd8ae9ea848b Again, make Python depend only on scanned modules (last fix was incomplete).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3423
diff changeset
   742
            pymod.source.append("ns3_module_%s.cc" % module)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   743
        pymod.target = 'ns3/_ns3'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   744
        pymod.name = 'ns3module'
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   745
        pymod.uselib_local = bld.env['NS3_ENABLED_MODULES']
4395
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4394
diff changeset
   746
        if pymod.env['ENABLE_STATIC_NS3']:
4440
c47d51e4b286 enable python+static build on osx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4430
diff changeset
   747
            if sys.platform == 'darwin':
c47d51e4b286 enable python+static build on osx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4430
diff changeset
   748
                pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   749
                for mod in pymod.uselib_local:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   750
                    pymod.env.append_value('LINKFLAGS', '-l' + mod)
4440
c47d51e4b286 enable python+static build on osx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4430
diff changeset
   751
            else:
c47d51e4b286 enable python+static build on osx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4430
diff changeset
   752
                pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   753
                for mod in pymod.uselib_local:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   754
                    pymod.env.append_value('LINKFLAGS', '-l' + mod)
4440
c47d51e4b286 enable python+static build on osx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4430
diff changeset
   755
                pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
4104
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   756
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   757
        defines = list(pymod.env['CXXDEFINES'])
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   758
        defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   759
        if Options.platform == 'win32':
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   760
            try:
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   761
                defines.remove('_DEBUG') # causes undefined symbols on win32
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   762
            except ValueError:
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   763
                pass
19147674758a On native win32, we cannot use -D_DEBUG when compiling Python extensions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4101
diff changeset
   764
        pymod.env['CXXDEFINES'] = defines
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   765
6960
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   766
        bld.new_task_gen(features='copy',
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   767
                         source="ns3__init__.py",
2df22891346b Use the waf 'copy' tool to copy __init__.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6957
diff changeset
   768
                         target='ns3/__init__.py')
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
   769
6901
1f837f7b2f11 Fix: The compat. ns3.py module is not needed when --bindings-type=both
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6899
diff changeset
   770
    if env['ENABLE_PYTHON_BINDINGS'] and env['BINDINGS_TYPE'] in ('modular',):
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
   771
        task = gen_ns3_compat_pymod_task(env)
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
   772
        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
   773
        task.dep_vars = ['PYTHON_MODULES_BUILT']
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
   774