bindings/python/wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed, 04 Mar 2009 11:34:51 +0000
changeset 4255 07f1fdd8a33e
parent 4253 732b877beb23
child 4312 a20c4300f959
permissions -rw-r--r--
Check if the compiler *really* supports -fvisibility=hidden.
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; -*-
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
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/
4253
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
    18
REQUIRED_PYBINDGEN_VERSION = (0, 10, 0, 630)
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
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
    22
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
    23
    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
    24
        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
    25
    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
    26
        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
    27
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
    28
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
    29
    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
    30
        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
    31
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
    32
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
def set_options(opt):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
    opt.tool_options('python')
3637
a6d8bf62a61d For better consistency, option --nsc becomes --enable-nsc, --python-disable becomes --disable-python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3625
diff changeset
    35
    opt.add_option('--disable-python',
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
                   help=("Don't build Python bindings."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
                   dest='python_disable')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
    opt.add_option('--python-scan',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
                   help=("Rescan Python bindings.  Needs working GCCXML / pygccxml environment."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
                   dest='python_scan')
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
    43
    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
    44
                   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
    45
                   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
    46
                   dest='with_pybindgen', type="string")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
def configure(conf):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
    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
    51
    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
    52
        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
    53
                                     "disabled by user request")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
    conf.check_tool('misc')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
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
    58
    if sys.platform == 'cygwin':
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
    59
        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
    60
                                     "unsupported platform 'cygwin'")
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
    61
        Logs.warn("Python is not supported in CygWin environment.  Try MingW instead.")
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
    62
        return
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
    63
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
    ## Check for Python
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
        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
    67
        conf.check_python_version((2,3))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
        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
    69
    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
    70
        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
    71
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
4253
732b877beb23 Compile python bindings with -fvisibility=hidden, when possible. Closes #515.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4196
diff changeset
    73
    # -fvisibility=hidden optimization
4255
07f1fdd8a33e Check if the compiler *really* supports -fvisibility=hidden.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4253
diff changeset
    74
    if conf.env['CXX_NAME'] == 'gcc' 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
    75
        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
    76
        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
    77
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    78
    # 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
    79
    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
    80
        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
    81
            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
    82
            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
    83
    else:
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    84
        pybindgen_dir = os.path.join('..', "pybindgen")
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    85
        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
    86
            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
    87
            conf.env['WITH_PYBINDGEN'] = os.path.abspath(pybindgen_dir)
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    88
        del pybindgen_dir
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    89
    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
    90
        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
    91
4116
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
    92
    # 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
    93
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
    94
    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
    95
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
        conf.check_python_module('pybindgen')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
    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
    99
        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
   100
        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
   101
                                     "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
   102
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
        out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
                                "import pybindgen.version; "
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
                                "print '.'.join([str(x) for x in pybindgen.version.__version__])"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
                                stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
        pybindgen_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
        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
   110
        conf.check_message('pybindgen', 'version',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
                           (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
                           pybindgen_version_str)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
        if not (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION):
4067
165b38956c24 Convert warning to Logs.warn (waf api change)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   114
            Logs.warn("pybindgen (found %s) is too old (need %s)" %
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
                    (pybindgen_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
                     '.'.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
   117
            conf.report_optional_feature("python", "Python Bindings", False,
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   118
                                         "PyBindGen too old and newer version could not be retrieved")
6f8542536217 Try to guess pybindgen location (more #478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4104
diff changeset
   119
            return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
    ## 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
   122
    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
   123
    conf.report_optional_feature("python", "Python Bindings", True, None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
    ## Check for pygccxml
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
        conf.check_python_module('pygccxml')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
    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
   129
        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
   130
                                     "Missing 'pygccxml' Python module")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
                            "import pygccxml; print pygccxml.__version__"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
                            stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
    pygccxml_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
    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
   138
    conf.check_message('pygccxml', 'version',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
                       (pygccxml_version >= REQUIRED_PYGCCXML_VERSION),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
                       pygccxml_version_str)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
    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
   142
        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
   143
                "automatic scanning of API definitions will not be possible" %
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
                (pygccxml_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
                 '.'.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
   146
        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
   147
                                     "pygccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
    
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
    ## Check gccxml version
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
    gccxml = conf.find_program('gccxml', var='GCCXML')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
    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
   154
        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
   155
        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
   156
                                     "gccxml missing")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
    gccxml_version_line = os.popen(gccxml + " --version").readline().strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
    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
   161
    gccxml_version = m.group(1)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
    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
   163
    conf.check_message('gccxml', 'version', True, gccxml_version)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
    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
   165
        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
   166
        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
   167
                                     "gccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
    
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
    ## If we reached
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
    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
   172
    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
   173
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
prio_headers = {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
    -2: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177
        "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
   178
        ),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
    -1: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
        "propagation-delay-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
        "propagation-loss-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   182
        "net-device.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
        )
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
     }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   186
def get_header_prio(header):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   187
    for prio, headers in prio_headers.iteritems():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
        if header in headers:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
            return prio
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
    return 1
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
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
   192
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
   193
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
   194
    (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
   195
    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
   196
        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
   197
    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
   198
        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
   199
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
   200
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   201
class gen_everything_h_task(Task.Task):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   202
    before = 'cc cxx'
4068
e0eb69d55e40 correct dependency problem
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4067
diff changeset
   203
    after = 'ns3header_task'
e0eb69d55e40 correct dependency problem
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4067
diff changeset
   204
    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
   205
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   206
    def run(self):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   207
        assert len(self.outputs) == 1
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   209
        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
   210
        outfile = file(self.outputs[0].bldpath(self.env), "w")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   212
        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
   213
            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
   214
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   215
        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
   216
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   217
        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
   218
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
   219
/* 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
   220
#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
   221
# 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
   222
#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
   223
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   224
    """
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   225
        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
   226
            print >> outfile, "#include \"ns3/%s\"" % (header,)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   227
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   228
        print >> outfile, """
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   229
namespace ns3 {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
static inline Ptr<Object>
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   231
__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
   232
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
   return obj->GetObject<Object> (typeId);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   234
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
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
   236
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
   237
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
   238
__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
   239
{
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
   240
   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
   241
   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
   242
   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
   243
   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
   244
   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
   245
   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
   246
   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
   247
   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
   248
   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
   249
   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
   250
   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
   251
   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
   252
   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
   253
   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
   254
   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
   255
}
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
   256
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3917
diff changeset
   257
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
"""
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   260
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   261
        return 0
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   263
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
   264
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   265
class all_ns3_headers_taskgen(TaskGen.task_gen):
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
    """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
   267
    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
   268
    """
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   269
    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
   270
        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
   271
        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
   272
        #self.inst_dir = 'ns3'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
    def apply(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
        ## get all of the ns3 headers
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   276
        ns3_dir_node = Build.bld.path.find_dir("ns3")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
        all_headers_inputs = []
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
        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
   280
            src_node = ns3_dir_node.find_or_declare(filename)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
            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
   282
                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
   283
            all_headers_inputs.append(src_node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   285
        ## 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
   286
        if not all_headers_inputs:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   287
            for ns3headers in Build.bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   288
                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
   289
                    ## skip headers not part of enabled modules
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   290
                    if self.env['NS3_ENABLED_MODULES']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
                        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
   292
                            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   293
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
                    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
   295
                        #source = os.path.basename(source)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   296
                        node = ns3_dir_node.find_or_declare(source)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   297
                        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
   298
                            raise Utils.WafError("missing header file %s" % (source,))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   299
                        all_headers_inputs.append(node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   300
        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
   301
        all_headers_outputs = [self.path.find_or_declare("everything.h")]
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   302
        task = self.create_task('gen_everything_h', self.env)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   303
        task.set_inputs(all_headers_inputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   304
        task.set_outputs(all_headers_outputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   305
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   306
    def install(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   307
        pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   310
def get_modules_and_headers():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   312
    Gets a dict of
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   313
       module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   314
    tuples, one for each module.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
    retval = {}
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   318
    for module in Build.bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
        if not module.name.startswith('ns3-'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
        module_name = module.name[4:] # strip the ns3- prefix
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   322
        ## find the headers object for this module
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
        headers = []
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   324
        for ns3headers in Build.bld.all_task_gen:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
            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
   326
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
            if ns3headers.module != module_name:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
            for source in ns3headers.to_list(ns3headers.source):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
                headers.append(source)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   331
        retval[module_name] = (list(module.module_deps), headers)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   332
    return retval
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   333
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   334
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
   335
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   336
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
   337
    """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
   338
    """
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   339
    after = 'gen_everything_h_task'
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   340
    before = 'cc cxx'
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
   341
    def __init__(self, curdirnode, env):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   342
        super(python_scan_task, self).__init__()
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
   343
        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
   344
        self.env = env
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   345
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   346
    def display(self):
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   347
        return 'python-scan\n'
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
   348
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
   349
    def run(self):
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
   350
        #print "Rescanning the python bindings..."
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
   351
        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
   352
            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
   353
            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
   354
            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
   355
            self.curdirnode.find_or_declare('everything.h').abspath(self.env),
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
   356
            os.path.join(self.curdirnode.abspath(), 'ns3modulegen_generated.py'), # output file
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
   357
            ]
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
   358
        scan = subprocess.Popen(argv, stdin=subprocess.PIPE)
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
   359
        scan.stdin.write(repr(get_modules_and_headers()))
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
   360
        scan.stdin.close()
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   361
        retval = scan.wait()
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   362
        print "Scan finished with exit code", retval
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   363
        if retval:
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   364
            return retval
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   365
        # 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
   366
        # 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
   367
        # WAF)
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   368
        Build.bld.generator.stop = 1
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   369
        return 0
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   370
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
   371
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   372
def build(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   373
    if Options.options.python_disable:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   374
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   375
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   376
    env = bld.env
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   377
    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
   378
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
   379
    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
   380
3486
818a6bbef490 Only generate everything.h if python bindings are enabled. Based on patch by Mathieu Lacage. Closes #260.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3485
diff changeset
   381
    if env['ENABLE_PYTHON_BINDINGS']:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   382
        obj = bld.new_task_gen('all_ns3_headers')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   383
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   384
    if Options.options.python_scan:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   385
        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
   386
            raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available")
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   387
        python_scan_task(bld.path, env)
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   388
        return
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   389
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
   390
    ## Get a list of scanned modules; the set of 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
   391
    ## may be smaller than the set of all modules, in case a new
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
   392
    ## ns3 module is being developed which wasn't scanned yet.
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
   393
    scanned_modules = []
3591
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   394
    for filename in os.listdir(curdir):
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
   395
        m = re.match(r"^ns3_module_(.+)\.py$", filename)
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
   396
        if m is None:
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
   397
            continue
3591
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   398
        name = m.group(1)
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   399
        if name.endswith("__local"):
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   400
            continue
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   401
        scanned_modules.append(name)
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
   402
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   403
    if env['ENABLE_PYTHON_BINDINGS']:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   404
        source = [
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   405
            'ns3modulegen.py',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   406
            'ns3modulegen_generated.py',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   407
            'ns3modulegen_core_customizations.py',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   408
            ]
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   409
        target = [
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   410
            'ns3module.cc',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   411
            'ns3module.h',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   412
            'ns3modulegen.log',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   413
            ]
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   414
        argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}', '${SRC[0]}', '${TGT[0]}']
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   415
        argv.extend(get_modules_and_headers().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
   416
        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
   417
            source.append("ns3_module_%s.py" % 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
   418
            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
   419
            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
   420
                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
   421
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   422
        argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   423
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
   424
        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
   425
            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
   426
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
   427
        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
   428
        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
   429
            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
   430
                features.append(name)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   431
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   432
        bindgen = bld.new_task_gen('command', source=source, target=target,
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   433
                                   command=argv, variables=dict(FEATURES=(','.join(features))))
4088
e52c06d86145 Add dependency annotations for the task that generates Python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4082
diff changeset
   434
        bindgen.before = 'cxx'
e52c06d86145 Add dependency annotations for the task that generates Python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4082
diff changeset
   435
        bindgen.after = 'gen_everything_h_task'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   436
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   437
    ## we build python bindings if either we have the tools to
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   438
    ## generate them or if the pregenerated source file is already
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   439
    ## present in the source dir.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   440
    if env['ENABLE_PYTHON_BINDINGS'] \
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   441
            or os.path.exists(os.path.join(bld.path.abspath(), 'ns3module.cc')):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   442
        pymod = bld.new_task_gen('cxx', 'shlib', 'pyext')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   443
        pymod.source = ['ns3module.cc', 'ns3module_helpers.cc']
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   444
        pymod.includes = '.'
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
   445
        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
   446
            pymod.source.append("ns3_module_%s.cc" % module)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   447
        pymod.target = 'ns3/_ns3'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   448
        pymod.name = 'ns3module'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   449
        pymod.uselib_local = "ns3"
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
   450
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
   451
        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
   452
        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
   453
        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
   454
            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
   455
                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
   456
            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
   457
                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
   458
        pymod.env['CXXDEFINES'] = defines
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   459
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   460
        # copy the __init__.py file to the build dir. waf can't handle
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   461
        # this, it's against waf's principles to have build dir files
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   462
        # with the same name as source dir files, apparently.
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3977
diff changeset
   463
        dirnode = bld.path.find_dir('ns3')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   464
        src = os.path.join(dirnode.abspath(), '__init__.py')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   465
        dst = os.path.join(dirnode.abspath(env), '__init__.py')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   466
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   467
            need_copy = os.stat(src).st_mtime > os.stat(dst).st_mtime
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   468
        except OSError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   469
            need_copy = True
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   470
        if need_copy:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   471
            try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   472
                os.mkdir(os.path.dirname(dst))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   473
            except OSError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   474
                pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   475
            print "%r -> %r" % (src, dst)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   476
            shutil.copy2(src, dst)