bindings/python/wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sat, 27 Sep 2008 15:06:38 +0100
changeset 3719 3307abd75322
parent 3663 457fea62fbdd
child 3721 3748390f3608
permissions -rw-r--r--
Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
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 Params
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
import Configure
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
import Object
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
import Action
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
import os
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
import Task
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
import pproc as subprocess
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
from Params import fatal, warning
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
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
    13
import sys
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
## Adjust python path to look for our local copy of pybindgen
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
#PYBINDGEN_BRANCH = 'lp:pybindgen'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
if os.environ.get('PYTHONPATH', ''):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
    os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH + os.pathsep + os.environ.get('PYTHONPATH')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
    os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
## https://launchpad.net/pybindgen/
3663
457fea62fbdd Problem of Python bindings in MinGW has been fixed
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3647
diff changeset
    25
REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 578)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
def set_options(opt):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
    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
    31
    opt.add_option('--disable-python',
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
                   help=("Don't build Python bindings."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
                   dest='python_disable')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
    opt.add_option('--python-scan',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
                   help=("Rescan Python bindings.  Needs working GCCXML / pygccxml environment."),
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_scan')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
    opt.add_option('--pybindgen-checkout',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
                   help=("During configure, force checkout of pybingen inside ns-3, "
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
                         "instead of using the system installed version."),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
                   action="store_true", default=False,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
                   dest='pybindgen_checkout')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
def fetch_pybindgen(conf):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
    Fetches pybindgen from launchpad as bindings/python/pybindgen.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
    Returns True if successful, False it not.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
    bzr = conf.find_program("bzr")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
    if not bzr:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
        warning("the program 'bzr' is needed in order to fetch pybindgen")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
        return False
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    if len(REQUIRED_PYBINDGEN_VERSION) == 4:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
        rev = "-rrevno:%i" % REQUIRED_PYBINDGEN_VERSION[3]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
    else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
        rev = "-rtag:%s" % '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])
3719
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    58
        
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
    if os.path.exists(LOCAL_PYBINDGEN_PATH):
3719
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    60
        print "Trying to update pybindgen; this will fail if no network connection is available.  Hit Ctrl-C to skip."
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
        cmd = [bzr, "pull", rev, PYBINDGEN_BRANCH]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
        print " => ", ' '.join(cmd)
3719
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    64
        try:
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    65
            if subprocess.Popen(cmd, cwd=LOCAL_PYBINDGEN_PATH).wait():
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    66
                return False
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    67
        except KeyboardInterrupt:
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    68
            print "Interrupted; Python bindings will be disabled."
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
            return False
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
        print "Update was successful."
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
    else:
3719
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    72
        print "Trying to fetch pybindgen; this will fail if no network connection is available.  Hit Ctrl-C to skip."
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
        cmd = [bzr, "checkout", rev, PYBINDGEN_BRANCH, LOCAL_PYBINDGEN_PATH]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
        print " => ", ' '.join(cmd)
3719
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    75
        try:
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    76
            if subprocess.Popen(cmd).wait():
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    77
                return False
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    78
        except KeyboardInterrupt:
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    79
            print "Interrupted; Python bindings will be disabled."
3307abd75322 Allow interrupting PyBindGen fetching, via Ctrl-C, for the impatient developers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3663
diff changeset
    80
            shutil.rmtree(LOCAL_PYBINDGEN_PATH, True)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
            return False
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
        print "Fetch was successful."
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
    ## generate a fake version.py file in pybindgen it's safer this
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
    ## way, since the normal version generation process requires
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
    ## bazaar python bindings, which may not be available.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
    vfile = open(os.path.join(LOCAL_PYBINDGEN_PATH, "pybindgen", "version.py"), "wt")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    vfile.write("""
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
# (fake version generated by ns-3)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
__version__ = %r
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
""" % list(REQUIRED_PYBINDGEN_VERSION))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    vfile.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    return True
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
def configure(conf):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
    conf.env['ENABLE_PYTHON_BINDINGS'] = False
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
    if Params.g_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
   100
        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
   101
                                     "disabled by user request")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    conf.check_tool('misc')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
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
    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
   107
        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
   108
                                     "unsupported platform 'cygwin'")
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
   109
        warning("Python is not supported in CygWin environment.  Try MingW instead.")
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
   110
        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
   111
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
    ## Check for Python
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
        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
   115
        conf.check_python_version((2,3))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
        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
   117
    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
   118
        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
   119
        return
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
    ## Check for pybindgen
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
    if Params.g_options.pybindgen_checkout:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
        fetch_pybindgen(conf)
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
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
        conf.check_python_module('pybindgen')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
    except Configure.ConfigurationError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
        warning("pybindgen missing")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
        if not fetch_pybindgen(conf):
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
   130
            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
   131
                                         "PyBindGen missing and could not be retrieved")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
            return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
        out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
                                "import pybindgen.version; "
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
                                "print '.'.join([str(x) for x in pybindgen.version.__version__])"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
                                stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
        pybindgen_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
        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
   140
        conf.check_message('pybindgen', 'version',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
                           (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
                           pybindgen_version_str)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
        if not (pybindgen_version >= REQUIRED_PYBINDGEN_VERSION):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
            warning("pybindgen (found %s) is too old (need %s)" %
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
                    (pybindgen_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
                     '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
            if not fetch_pybindgen(conf):
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
   148
                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
   149
                                             "PyBindGen too old and newer version could not be retrieved")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
                return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
    ## 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
   153
    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
   154
    conf.report_optional_feature("python", "Python Bindings", True, None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
    ## Check for pygccxml
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
    try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
        conf.check_python_module('pygccxml')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
    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
   160
        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
   161
                                     "Missing 'pygccxml' Python module")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
    out = subprocess.Popen([conf.env['PYTHON'], "-c",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
                            "import pygccxml; print pygccxml.__version__"],
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
                            stdout=subprocess.PIPE).communicate()[0]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
    pygccxml_version_str = out.strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
    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
   169
    conf.check_message('pygccxml', 'version',
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
                       (pygccxml_version >= REQUIRED_PYGCCXML_VERSION),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
                       pygccxml_version_str)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
    if not (pygccxml_version >= REQUIRED_PYGCCXML_VERSION):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
        warning("pygccxml (found %s) is too old (need %s) => "
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
                "automatic scanning of API definitions will not be possible" %
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
                (pygccxml_version_str,
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
                 '.'.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
   177
        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
   178
                                     "pygccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
    
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   182
    ## Check gccxml version
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
    gccxml = conf.find_program('gccxml', var='GCCXML')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
    if not gccxml:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
        warning("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
   186
        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
   187
                                     "gccxml missing")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
    gccxml_version_line = os.popen(gccxml + " --version").readline().strip()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
    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
   192
    gccxml_version = m.group(1)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   193
    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
   194
    conf.check_message('gccxml', 'version', True, gccxml_version)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   195
    if not gccxml_version_ok:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
        warning("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
   197
        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
   198
                                     "gccxml too old")
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   199
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
    
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
    ## If we reached
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
    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
   203
    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
   204
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   206
prio_headers = {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
    -2: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
        "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
   209
        ),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
    -1: (
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
        "propagation-delay-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
        "propagation-loss-model.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
        "net-device.h",
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
        )
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
     }
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   216
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
def get_header_prio(header):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   218
    for prio, headers in prio_headers.iteritems():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   219
        if header in headers:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   220
            return prio
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   221
    return 1
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   222
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
   223
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
   224
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
   225
    (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
   226
    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
   227
        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
   228
    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
   229
        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
   230
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
   231
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   232
def gen_ns3_metaheader(task):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
    assert len(task.m_outputs) == 1
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
   234
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
   235
    header_files = [calc_header_include(node.abspath(task.m_env)) for node in task.m_inputs]
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
    outfile = file(task.m_outputs[0].bldpath(task.m_env), "w")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
    def sort_func(h1, h2):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   239
        return cmp((get_header_prio(h1), h1), (get_header_prio(h1), h2))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   240
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   241
    header_files.sort(sort_func)
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
    for header in header_files:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   244
        print >> outfile, "#include \"ns3/%s\"" % (header,)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   246
    print >> outfile, """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
namespace ns3 {
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   248
static inline Ptr<Object>
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   249
__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
   250
{
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   251
   return obj->GetObject<Object> (typeId);
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   252
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   253
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   254
}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   255
"""
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   256
    outfile.close()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   257
    return 0
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
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
   260
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   261
class all_ns3_headers_taskgen(Object.task_gen):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
    """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
   263
    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
   264
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   265
    def __init__(self, *features):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
        Object.task_gen.__init__(self, *features)
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
   267
        self.inst_var = 0#'INCLUDEDIR'
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
   268
        #self.inst_dir = 'ns3'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    def apply(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
        ## get all of the ns3 headers
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
        ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
        all_headers_inputs = []
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
        for filename in self.to_list(self.source):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   276
            src_node = ns3_dir_node.find_build(filename)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
            if src_node is None:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
                Params.fatal("source ns3 header file %s not found" % (filename,))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
            all_headers_inputs.append(src_node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
        ## 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
   282
        if not all_headers_inputs:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   283
            for ns3headers in Object.g_allobjs:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
                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
   285
                    ## skip headers not part of enabled modules
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   286
                    if self.env['NS3_ENABLED_MODULES']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
                        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
   288
                            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   289
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   290
                    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
   291
                        #source = os.path.basename(source)
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
   292
                        node = ns3_dir_node.find_build(source)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   293
                        if node is None:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
                            fatal("missing header file %s" % (source,))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   295
                        all_headers_inputs.append(node)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   296
        assert all_headers_inputs
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
   297
        all_headers_outputs = [self.path.find_build("everything.h")]
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   298
        task = self.create_task('gen-ns3-metaheader', self.env, 4)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   299
        task.set_inputs(all_headers_inputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   300
        task.set_outputs(all_headers_outputs)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   301
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   302
    def install(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   303
        pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   304
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 get_modules_and_headers():
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   307
    """
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
    Gets a dict of
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
       module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   310
    tuples, one for each module.
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
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   313
    retval = {}
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   314
    for module in Object.g_allobjs:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
        if not module.name.startswith('ns3-'):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
            continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
        module_name = module.name[4:] # strip the ns3- prefix
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   318
        ## find the headers object for this module
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
        headers = []
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
        for ns3headers in Object.g_allobjs:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
            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
   322
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
            if ns3headers.module != module_name:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   324
                continue
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
            for source in ns3headers.to_list(ns3headers.source):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   326
                headers.append(source)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
        retval[module_name] = (list(module.module_deps), headers)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
    return retval
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
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
   331
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
   332
class PythonScanTask(Task.TaskBase):
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
   333
    """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
   334
    """
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
    def __init__(self, curdirnode, env):
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
   336
        self.m_display = 'python-scan'
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
        self.prio = 5 # everything.h has prio 4
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
        super(PythonScanTask, self).__init__()
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
   339
        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
   340
        self.env = env
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
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
   342
    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
   343
        #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
   344
        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
   345
            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
   346
            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
   347
            self.curdirnode.find_dir('../..').abspath(self.env), # include path (where the ns3 include dir is)
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
            self.curdirnode.find_build('everything.h').abspath(self.env),
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
            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
   350
            ]
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
        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
   352
        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
   353
        scan.stdin.close()
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
        if scan.wait():
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
   355
            raise SystemExit(1)
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
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
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   358
def build(bld):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   359
    if Params.g_options.python_disable:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   360
        return
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   361
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   362
    env = bld.env_of_name('default')
3591
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   363
    curdir = bld.m_curdirnode.abspath()
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   364
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   365
    #Object.register('all-ns3-headers', AllNs3Headers)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   366
    Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   367
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
   368
    if env['ENABLE_PYTHON_BINDINGS']:
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
   369
        obj = bld.create_obj('all_ns3_headers')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   370
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   371
    if Params.g_options.python_scan:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   372
        if not env['ENABLE_PYTHON_SCANNING']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   373
            Params.fatal("Cannot re-scan python bindings: (py)gccxml not available")
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
   374
        PythonScanTask(bld.m_curdirnode, env)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   375
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
   376
    ## 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
   377
    ## 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
   378
    ## 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
   379
    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
   380
    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
   381
        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
   382
        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
   383
            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
   384
        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
   385
        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
   386
            continue
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   387
        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
   388
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   389
    if env['ENABLE_PYTHON_BINDINGS']:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   390
        bindgen = bld.create_obj('command-output')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   391
        bindgen.name = 'pybindgen'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   392
        bindgen.command = env['PYTHON']
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   393
        bindgen.command_is_external = True
3411
eca46ea15a04 Redirect the stderr of pybindgen to a log file (ns3modulegen.log).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3409
diff changeset
   394
        bindgen.stderr = 'ns3modulegen.log'
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   395
        bindgen.argv = [
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   396
            bindgen.input_file("ns3modulegen.py"),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   397
            bindgen.output_file("ns3module.cc"),
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   398
            ]
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   399
        bindgen.argv.extend(get_modules_and_headers().iterkeys())
3647
cd704871a4ed Python bindings generation does not need to depend on the 'everything.h' file, only API scanning and compilation of the generated sources.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3639
diff changeset
   400
        bindgen.hidden_inputs = ['ns3modulegen_generated.py',
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   401
                                 'ns3modulegen_core_customizations.py']
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
   402
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
   403
        for module in scanned_modules:
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
   404
            bindgen.hidden_inputs.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
   405
            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
   406
            if os.path.exists(os.path.join(curdir, local)):
f548d13ffd4e Fix build when ns3_module_*__local.py files are used.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3575
diff changeset
   407
                bindgen.hidden_inputs.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
   408
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   409
        bindgen.hidden_outputs = ['ns3module.h']
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
   410
        for module in scanned_modules:
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
   411
            bindgen.hidden_outputs.append("ns3_module_%s.cc" % module)
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
   412
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   413
        bindgen.prio = 50
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   414
3420
390db659644b If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3417
diff changeset
   415
        bindgen.os_env = dict(os.environ)
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
   416
        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
   417
        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
   418
            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
   419
                features.append(name)
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
   420
        bindgen.os_env['NS3_ENABLED_FEATURES'] = ','.join(features)
3420
390db659644b If GtkConfigStore support is disabled, disable the python bindings for it, or else compilation fails.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3417
diff changeset
   421
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   422
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   423
    ## 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
   424
    ## generate them or if the pregenerated source file is already
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   425
    ## present in the source dir.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   426
    if env['ENABLE_PYTHON_BINDINGS'] \
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   427
            or os.path.exists(os.path.join(bld.m_curdirnode.abspath(), 'ns3module.cc')):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   428
        pymod = bld.create_obj('cpp', 'shlib', 'pyext')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   429
        pymod.source = ['ns3module.cc', 'ns3module_helpers.cc']
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   430
        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
   431
        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
   432
            pymod.source.append("ns3_module_%s.cc" % module)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   433
        pymod.target = 'ns3/_ns3'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   434
        pymod.name = 'ns3module'
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   435
        pymod.uselib_local = "ns3"
3417
06df0787254b Make sure we don't trigger deprecation warnings while compiling the python bindings.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3412
diff changeset
   436
        pymod.env.append_value('CXXDEFINES', ['NS_DEPRECATED=""', 'NS3_DEPRECATED_H'])
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
        # copy the __init__.py file to the build dir waf can't handle
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   439
        # 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
   440
        # with the same name as source dir files, apparently.
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   441
        dirnode = bld.m_curdirnode.find_dir('ns3')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   442
        src = os.path.join(dirnode.abspath(), '__init__.py')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   443
        dst = os.path.join(dirnode.abspath(env), '__init__.py')
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   444
        try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   445
            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
   446
        except OSError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   447
            need_copy = True
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   448
        if need_copy:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   449
            try:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   450
                os.mkdir(os.path.dirname(dst))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   451
            except OSError:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   452
                pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   453
            print "%r -> %r" % (src, dst)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   454
            shutil.copy2(src, dst)