wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 05 Oct 2009 15:32:12 +0100
changeset 5368 09b539910969
parent 5361 e8989b44bffb
child 5369 86beb5869f67
permissions -rw-r--r--
typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
     2
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
     3
# python lib modules
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
     4
import sys
695
90a68c1c4328 WAF: add a dist_hook function to exclude the generated documentation from waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 694
diff changeset
     5
import shutil
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     6
import types
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     7
import optparse
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     8
import os.path
4450
0ca9b9b410a0 bug 567: --enable-static does not work on i686
Andrey Hippo <ahippo@yandex.ru>
parents: 4447
diff changeset
     9
import re
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    10
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    11
# WAF modules
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2990
diff changeset
    12
import pproc as subprocess
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    13
import Options
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
    14
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    15
import Logs
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    16
import TaskGen
4195
e0a27ec2991a WAF: fix Task.maxjobs=1 (for sudo); icc flags.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4190
diff changeset
    17
import Constants
4076
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    18
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2990
diff changeset
    19
import ccroot
4076
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    20
ccroot.USE_TOP_LEVEL = True
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    21
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
    22
import Task
4195
e0a27ec2991a WAF: fix Task.maxjobs=1 (for sudo); icc flags.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4190
diff changeset
    23
Task.algotype = Constants.JOBCONTROL # so that Task.maxjobs=1 takes effect
e0a27ec2991a WAF: fix Task.maxjobs=1 (for sudo); icc flags.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4190
diff changeset
    24
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    25
import Utils
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    26
import Build
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    27
import Configure
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
    28
import Scripting
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    29
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    30
import cflags # override the build profiles from waf
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    31
cflags.profiles = {
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    32
	# profile name: [optimization_level, warnings_level, debug_level]
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    33
	'debug':     [0, 2, 3],
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    34
	'optimized': [3, 2, 1],
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    35
	}
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    36
cflags.default_profile = 'debug'
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    37
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    38
# local modules
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    39
import wutils
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    40
import regression
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    41
4070
c2ad9c39fa06 Correct way to enable WAF autoconfigure
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4069
diff changeset
    42
Configure.autoconfig = 1
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    43
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    44
# the following two variables are used by the target "waf dist"
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    45
VERSION = file("VERSION", "rt").read().strip()
694
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    46
APPNAME = 'ns'
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    47
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    48
wutils.VERSION = VERSION
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    49
wutils.APPNAME = APPNAME
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    50
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    51
#
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    52
# The last part of the path name to use to find the regression traces.  The
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    53
# path will be APPNAME + '-' + VERSION + REGRESSION_SUFFIX, e.g.,
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    54
# ns-3-dev-ref-traces
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    55
#
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    56
REGRESSION_SUFFIX = "-ref-traces"
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    57
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
    58
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    59
# these variables are mandatory ('/' are converted automatically)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    60
srcdir = '.'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    61
blddir = 'build'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    62
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    63
def load_env():
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    64
    bld_cls = getattr(Utils.g_module, 'build_context', Utils.Context)
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    65
    bld_ctx = bld_cls()
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    66
    bld_ctx.load_dirs(os.path.abspath(os.path.join (srcdir,'..')),
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    67
                      os.path.abspath(os.path.join (srcdir,'..', blddir)))
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    68
    bld_ctx.load_envs()
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    69
    env = bld_ctx.get_env()
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    70
    return env
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    71
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    72
def get_files(base_dir):
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    73
    retval = []
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    74
    reference=os.path.dirname(base_dir)
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    75
    for root, dirs, files in os.walk(base_dir):
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    76
        if root.find('.hg') != -1:
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    77
            continue
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    78
        for file in files:
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    79
            if file.find('.hg') != -1:
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    80
                continue
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    81
            fullname = os.path.join(root,file)
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    82
            # we can't use os.path.relpath because it's new in python 2.6
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    83
            relname = fullname.replace(reference + '/','')
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    84
            retval.append([fullname,relname])
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    85
    return retval
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    86
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    87
1531
ebd805503b55 WAF: update to WAF trunk to get bug fixes and smaller script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1506
diff changeset
    88
def dist_hook():
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    89
    import tarfile
921
37b54ed96b09 WAF: ignore errors on shutil.rmtree in dist_hook, so that waf dist works even when no docs were previously generated.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 919
diff changeset
    90
    shutil.rmtree("doc/html", True)
37b54ed96b09 WAF: ignore errors on shutil.rmtree in dist_hook, so that waf dist works even when no docs were previously generated.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 919
diff changeset
    91
    shutil.rmtree("doc/latex", True)
3627
672f2a6de8b4 Exclude any possible 'nsc' folder from the dist tarball (nsc is ~= 100MB).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3625
diff changeset
    92
    shutil.rmtree("nsc", True)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    93
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    94
    ## build the name of the traces subdirectory.  Will be something like
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    95
    ## ns-3-dev-ref-traces
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    96
    traces_name = APPNAME + '-' + VERSION + REGRESSION_SUFFIX
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    97
    ## Create a tar.bz2 file with the traces
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    98
    env = load_env()
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
    99
    regression_dir = env['REGRESSION_TRACES']
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   100
    if not os.path.isdir(regression_dir):
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   101
        Logs.warn("Not creating traces archive: the %s directory does not exist" % regression_dir)
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
   102
    else:
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   103
        traceball = traces_name + wutils.TRACEBALL_SUFFIX
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   104
        tar = tarfile.open(os.path.join("..", traceball), 'w:bz2')
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   105
        files = get_files(regression_dir)
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   106
        for fullfilename,relfilename in files:
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   107
            tar.add(fullfilename,arcname=relfilename)
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
   108
        tar.close()
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
   109
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   110
def set_options(opt):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   111
    # options provided by the modules
642
033f1f4891ab Make WAF check for the abstract tool 'compiler_cxx', instead of manually checking for multiple compilers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 600
diff changeset
   112
    opt.tool_options('compiler_cxx')
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   113
    opt.tool_options('cflags')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   114
2846
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   115
    opt.add_option('--cwd',
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   116
                   help=('Set the working directory for a program.'),
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   117
                   action="store", type="string", default=None,
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   118
                   dest='cwd_launch')
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   119
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   120
    opt.add_option('--enable-gcov',
787
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
   121
                   help=('Enable code coverage analysis.'
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
   122
                         ' WARNING: this option only has effect '
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
   123
                         'with the configure command.'),
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   124
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   125
                   dest='enable_gcov')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   126
2866
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   127
    opt.add_option('--no-task-lines',
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   128
                   help=("Don't print task lines, i.e. messages saying which tasks are being executed by WAF."
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   129
                         "  Coupled with a single -v will cause WAF to output only the executed commands,"
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   130
                         " just like 'make' does by default."),
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   131
                   action="store_true", default=False,
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   132
                   dest='no_task_lines')
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   133
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   134
    opt.add_option('--lcov-report',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   135
                   help=('Generate a code coverage report '
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   136
                         '(use this option at build time, not in configure)'),
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   137
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   138
                   dest='lcov_report')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   139
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   140
    opt.add_option('--doxygen',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   141
                   help=('Run doxygen to generate html documentation from source comments'),
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   142
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   143
                   dest='doxygen')
4770
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   144
    opt.add_option('--doxygen-no-build',
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   145
                   help=('Run doxygen to generate html documentation from source comments, '
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   146
                         'but do not wait for ns-3 to finish the full build.'),
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   147
                   action="store_true", default=False,
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   148
                   dest='doxygen_no_build')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   149
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   150
    opt.add_option('--run',
935
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   151
                   help=('Run a locally built program; argument can be a program name,'
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   152
                         ' or a command starting with the program name.'),
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   153
                   type="string", default='', dest='run')
935
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   154
    opt.add_option('--command-template',
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   155
                   help=('Template of the command used to run the program given by --run;'
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   156
                         ' It should be a shell command string containing %s inside,'
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   157
                         ' which will be replaced by the actual program.'),
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   158
                   type="string", default=None, dest='command_template')
3419
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   159
    opt.add_option('--pyrun',
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   160
                   help=('Run a python program using locally built ns3 python module;'
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   161
                         ' argument is the path to the python program, optionally followed'
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   162
                         ' by command-line options that are passed to the program.'),
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   163
                   type="string", default='', dest='pyrun')
2207
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   164
    opt.add_option('--valgrind',
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   165
                   help=('Change the default command template to run programs and unit tests with valgrind'),
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   166
                   action="store_true", default=False,
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   167
                   dest='valgrind')
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   168
    opt.add_option('--shell',
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   169
                   help=('DEPRECATED (run ./waf shell)'),
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   170
                   action="store_true", default=False,
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   171
                   dest='shell')
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   172
    opt.add_option('--enable-sudo',
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   173
                   help=('Use sudo to setup suid bits on ns3 executables.'),
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   174
                   dest='enable_sudo', action='store_true',
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   175
                   default=False)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   176
    opt.add_option('--regression',
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   177
                   help=("Enable regression testing; only used for the 'check' target"),
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   178
                   default=False, dest='regression', action="store_true")
4531
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   179
    opt.add_option('--check',
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   180
                   help=('DEPRECATED (run ./test.py)'),
4531
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   181
                   default=False, dest='check', action="store_true")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   182
    opt.add_option('--regression-generate',
2884
635509281306 Fix a diff|head race condition; Fix regression error messages to indicate the new waf commands to run regression tests.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2882
diff changeset
   183
                   help=("Generate new regression test traces."),
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   184
                   default=False, dest='regression_generate', action="store_true")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   185
    opt.add_option('--regression-tests',
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   186
                   help=('For regression testing, only run/generate the indicated regression tests, '
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   187
                         'specified as a comma separated list of test names'),
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   188
                   dest='regression_tests', type="string")
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   189
    opt.add_option('--with-regression-traces',
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   190
                   help=('Path to the regression reference traces directory'),
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   191
                   default=None,
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   192
                   dest='regression_traces', type="string")
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   193
    opt.add_option('--enable-static',
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   194
                   help=('Compile NS-3 statically: works only on linux, without python'),
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   195
                   dest='enable_static', action='store_true',
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   196
                   default=False)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   197
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   198
    # options provided in a script in a subdirectory named "src"
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   199
    opt.sub_options('src')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   200
    opt.sub_options('bindings/python')
3628
a9c05c7e54f2 Move all NSC related build code into src/internet-stack, to unclutter a bit the main wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3627
diff changeset
   201
    opt.sub_options('src/internet-stack')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   202
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   203
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   204
def _check_compilation_flag(conf, flag):
3407
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   205
    """
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   206
    Checks if the C++ compiler accepts a certain compilation flag or flags
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   207
    flag: can be a string or a list of strings
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   208
    """
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   209
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   210
    env = conf.env.copy()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   211
    env.append_value('CXXFLAGS', flag)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   212
    try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   213
        retval = conf.run_c_code(code='#include <stdio.h>\nint main() { return 0; }\n',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   214
                                 env=env, compile_filename='test.cc',
4367
63c04791fae2 Make the --enable-sudo option work correctly again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4354
diff changeset
   215
                                 compile_mode='cxx',type='cprogram', execute=False)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   216
    except Configure.ConfigurationError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   217
        ok = False
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   218
    else:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   219
        ok = (retval == 0)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   220
    conf.check_message_custom(flag, 'support', (ok and 'yes' or 'no'))
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   221
    return ok
3407
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   222
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   223
    
3625
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   224
def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled):
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   225
    conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled))
3407
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   226
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   227
def configure(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: 3623
diff changeset
   228
    # attach some extra methods
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   229
    conf.check_compilation_flag = types.MethodType(_check_compilation_flag, 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: 3623
diff changeset
   230
    conf.report_optional_feature = types.MethodType(report_optional_feature, conf)
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   231
    conf.env['NS3_OPTIONAL_FEATURES'] = []
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   232
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   233
    conf.env['NS3_BUILDDIR'] = conf.blddir
1531
ebd805503b55 WAF: update to WAF trunk to get bug fixes and smaller script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1506
diff changeset
   234
    conf.check_tool('compiler_cxx')
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   235
    conf.check_tool('cflags')
4075
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   236
    try:
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   237
        conf.check_tool('pkgconfig')
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   238
    except Configure.ConfigurationError:
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   239
        pass
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   240
    conf.check_tool('command')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   241
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   242
    # Check for the location of regression reference traces
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   243
    if Options.options.regression_traces is not None:
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   244
        if os.path.isdir(Options.options.regression_traces):
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   245
            conf.check_message("regression traces location", '', True, ("%s (given)" % Options.options.regression_traces))
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   246
            conf.env['REGRESSION_TRACES'] = os.path.abspath(Options.options.regression_traces)
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   247
    else:
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   248
        traces = os.path.join('..', "%s-%s%s" % (APPNAME, VERSION, REGRESSION_SUFFIX))
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   249
        if os.path.isdir(traces):
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   250
            conf.check_message("regression reference traces", '', True, ("%s (guessed)" % traces))
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   251
            conf.env['REGRESSION_TRACES'] = os.path.abspath(traces)
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   252
        del traces
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   253
    if not conf.env['REGRESSION_TRACES']:
4115
ec4e46b9547b Try to guess the location of the reference traces, when --with-regression-traces is not given (#478)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4114
diff changeset
   254
        conf.check_message("regression reference traces", '', False)
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   255
4594
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   256
    # create the second environment, set the variant and set its name
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   257
    variant_env = conf.env.copy()
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   258
    variant_name = Options.options.build_profile
14ce84fd7ae3 make dist generation work again
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4550
diff changeset
   259
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   260
    if Options.options.enable_gcov:
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   261
        variant_name += '-gcov'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   262
        variant_env.append_value('CCFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   263
        variant_env.append_value('CCFLAGS', '-ftest-coverage')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   264
        variant_env.append_value('CXXFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   265
        variant_env.append_value('CXXFLAGS', '-ftest-coverage')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   266
        variant_env.append_value('LINKFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   267
    
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   268
    conf.env['NS3_ACTIVE_VARIANT'] = variant_name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   269
    variant_env['NS3_ACTIVE_VARIANT'] = variant_name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   270
    variant_env.set_variant(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   271
    conf.set_env_name(variant_name, variant_env)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   272
    conf.setenv(variant_name)
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   273
    env = variant_env
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   274
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   275
    env.append_value('CXXDEFINES', 'RUN_SELF_TESTS')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   276
    
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   277
    if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   278
        if conf.check_compilation_flag('-Wno-error=deprecated-declarations'):
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   279
            env.append_value('CXXFLAGS', '-Wno-error=deprecated-declarations')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   280
        
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   281
    if Options.options.build_profile == 'debug':
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   282
        env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   283
        env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
1426
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   284
4190
b6734a5d920c work around to allow FreeBSD to run tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4179
diff changeset
   285
    env['PLATFORM'] = sys.platform
b6734a5d920c work around to allow FreeBSD to run tap-bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4179
diff changeset
   286
5252
481053e0cd10 Bug 681: wrong compilation options for icpc (Intel C/C++ Compiler)
Andrey Mazo <mazo@iitp.ru>
parents: 5201
diff changeset
   287
    if conf.env['CXX_NAME'] in ['gcc', 'icc']:
4348
0572c4011b3d Enable the link option --enable-auto-import on cygwin; closes #525.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4333
diff changeset
   288
        if sys.platform == 'win32':
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   289
            env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")
4348
0572c4011b3d Enable the link option --enable-auto-import on cygwin; closes #525.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4333
diff changeset
   290
        elif sys.platform == 'cygwin':
0572c4011b3d Enable the link option --enable-auto-import on cygwin; closes #525.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4333
diff changeset
   291
            env.append_value("LINKFLAGS", "-Wl,--enable-auto-import")
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   292
4386
2e79cbd62d28 bug 553: Running code built with a special gcc
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 4369
diff changeset
   293
        cxx, = env['CXX']
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   294
4386
2e79cbd62d28 bug 553: Running code built with a special gcc
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 4369
diff changeset
   295
        p = subprocess.Popen([cxx, '-print-file-name=libstdc++.so'], stdout=subprocess.PIPE)
4387
dff0992d7cce Make sure the 'g++ -print-file-name' code does not break if gcc doesn't know anything about the libstdc++.so file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4386
diff changeset
   296
        libstdcxx_location = os.path.dirname(p.stdout.read().strip())
4386
2e79cbd62d28 bug 553: Running code built with a special gcc
Gustavo Carneiro <gjcarneiro@gmail.com>
parents: 4369
diff changeset
   297
        p.wait()
4387
dff0992d7cce Make sure the 'g++ -print-file-name' code does not break if gcc doesn't know anything about the libstdc++.so file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4386
diff changeset
   298
        if libstdcxx_location:
dff0992d7cce Make sure the 'g++ -print-file-name' code does not break if gcc doesn't know anything about the libstdc++.so file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4386
diff changeset
   299
            conf.env.append_value('NS3_MODULE_PATH', libstdcxx_location)
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
   300
4447
0b42685f6b78 Don't event try to enable -Wl,--soname option if we're not on linux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4446
diff changeset
   301
        if Options.platform in ['linux']:
0b42685f6b78 Don't event try to enable -Wl,--soname option if we're not on linux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4446
diff changeset
   302
            if conf.check_compilation_flag('-Wl,--soname=foo'):
0b42685f6b78 Don't event try to enable -Wl,--soname option if we're not on linux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4446
diff changeset
   303
                env['WL_SONAME_SUPPORTED'] = True
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   304
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   305
    conf.sub_config('src')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   306
    conf.sub_config('bindings/python')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   307
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   308
    if Options.options.enable_modules:
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   309
        conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   310
                                           Options.options.enable_modules.split(',')]
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   311
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   312
    # for suid bits
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   313
    conf.find_program('sudo', var='SUDO')
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   314
4171
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   315
    why_not_sudo = "because we like it"
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   316
    if Options.options.enable_sudo and conf.env['SUDO']:
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   317
        env['ENABLE_SUDO'] = True
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   318
    else:
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   319
        env['ENABLE_SUDO'] = False
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   320
        if Options.options.enable_sudo:
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   321
            why_not_sudo = "program sudo not found"
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   322
        else:
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   323
            why_not_sudo = "option --enable-sudo not selected"
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   324
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   325
    conf.report_optional_feature("ENABLE_SUDO", "Use sudo to set suid bit", env['ENABLE_SUDO'], why_not_sudo)
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   326
3677
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   327
    # we cannot pull regression traces without mercurial
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   328
    conf.find_program('hg', var='MERCURIAL')
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   329
4119
9ffcf2400aa5 Bug #323: waf --valgrind doesn't check for valgrind first
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4118
diff changeset
   330
    conf.find_program('valgrind', var='VALGRIND')
9ffcf2400aa5 Bug #323: waf --valgrind doesn't check for valgrind first
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4118
diff changeset
   331
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   332
    env['ENABLE_STATIC_NS3'] = False
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   333
    if Options.options.enable_static:
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   334
        if env['PLATFORM'].startswith('linux') and \
5252
481053e0cd10 Bug 681: wrong compilation options for icpc (Intel C/C++ Compiler)
Andrey Mazo <mazo@iitp.ru>
parents: 5201
diff changeset
   335
                env['CXX_NAME'] in ['gcc', 'icc']:
4450
0ca9b9b410a0 bug 567: --enable-static does not work on i686
Andrey Hippo <ahippo@yandex.ru>
parents: 4447
diff changeset
   336
            if re.match('i[3-6]86', os.uname()[4]):
4438
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   337
                conf.report_optional_feature("static", "Static build", True, '')
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   338
                env['ENABLE_STATIC_NS3'] = True
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   339
            elif os.uname()[4] == 'x86_64':
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   340
                if env['ENABLE_PYTHON_BINDINGS'] and \
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   341
                        not conf.check_compilation_flag('-mcmodel=large'):
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   342
                    conf.report_optional_feature("static", "Static build", False,
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   343
                                                 "Can't enable static builds because " + \
4441
aa527a27537d improve wording
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4439
diff changeset
   344
                                                     "no -mcmodel=large compiler " \
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   345
                                                     "option. Try --disable-python or upgrade your " \
4441
aa527a27537d improve wording
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4439
diff changeset
   346
                                                     "compiler to at least gcc 4.3.x.")
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   347
                else:
4438
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   348
                    conf.report_optional_feature("static", "Static build", True, '')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   349
                    env['ENABLE_STATIC_NS3'] = True                    
4439
e2fc73a10bad enable static builds on cygwin
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4438
diff changeset
   350
        elif env['CXX_NAME'] == 'gcc' and \
e2fc73a10bad enable static builds on cygwin
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4438
diff changeset
   351
                (env['PLATFORM'].startswith('darwin') or \
e2fc73a10bad enable static builds on cygwin
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4438
diff changeset
   352
                     env['PLATFORM'].startswith('cygwin')):
4438
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   353
                conf.report_optional_feature("static", "Static build", True, '')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   354
                env['ENABLE_STATIC_NS3'] = True
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   355
        else:
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   356
            conf.report_optional_feature("static", "Static build", False,
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   357
                                         "Unsupported platform")
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   358
    else:
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   359
        conf.report_optional_feature("static", "Static build", False,
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   360
                                     "option --enable-static not selected")
4773
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   361
    have_gsl = conf.pkg_check_modules('GSL', 'gsl', mandatory=False)
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   362
    conf.env['ENABLE_GSL'] = have_gsl
4436
56fc927210c6 attempt to detect broken --enable-static invocations.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4395
diff changeset
   363
4773
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   364
    conf.report_optional_feature("GSL", "GNU Scientific Library (GSL)",
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   365
                                 conf.env['ENABLE_GSL'],
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   366
                                 "GSL not found")
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   367
    if have_gsl:
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   368
        conf.env.append_value('CXXDEFINES', "ENABLE_GSL")
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4770
diff changeset
   369
        conf.env.append_value('CCDEFINES', "ENABLE_GSL")
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   370
3625
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   371
    # Write a summary of optional features status
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   372
    print "---- Summary of optional NS-3 features:"
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   373
    for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   374
        if was_enabled:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   375
            status = 'enabled'
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   376
        else:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   377
            status = 'not enabled (%s)' % reason_not_enabled
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   378
        print "%-30s: %s" % (caption, status)
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   379
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   380
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   381
class SuidBuildTask(Task.TaskBase):
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   382
    """task that makes a binary Suid
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   383
    """
4179
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   384
    after = 'cxx_link cc_link'
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   385
    maxjobs = 1
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   386
    def __init__(self, bld, program):
4367
63c04791fae2 Make the --enable-sudo option work correctly again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4354
diff changeset
   387
        self.bld = bld
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   388
        self.m_display = 'build-suid'
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   389
        self.__program = program
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   390
        self.__env = bld.env.copy ()
4367
63c04791fae2 Make the --enable-sudo option work correctly again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4354
diff changeset
   391
        super(SuidBuildTask, self).__init__(generator=self)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   392
        try:
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   393
            program_obj = wutils.find_program(self.__program.target, self.__env)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   394
        except ValueError, ex:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   395
            raise Utils.WafError(str(ex))
4179
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   396
        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   397
        self.filename = program_node.abspath(self.__env)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   398
4179
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   399
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   400
    def run(self):
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   401
        print >> sys.stderr, 'setting suid bit on executable ' + self.filename
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   402
        if subprocess.Popen(['sudo', 'chown', 'root', self.filename]).wait():
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   403
            return 1
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   404
        if subprocess.Popen(['sudo', 'chmod', 'u+s', self.filename]).wait():
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   405
            return 1
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   406
        return 0
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   407
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   408
    def runnable_status(self):
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   409
        "RUN_ME SKIP_ME or ASK_LATER"
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   410
        st = os.stat(self.filename)
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   411
        if st.st_uid == 0:
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   412
            return Constants.SKIP_ME
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   413
        else:
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   414
            return Constants.RUN_ME
2758871405b7 tweak wifi example, fix waf problems (thanks to Gustavo)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4172
diff changeset
   415
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   416
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   417
def create_suid_program(bld, name):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   418
    program = bld.new_task_gen('cxx', 'program')
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   419
    program.is_ns3_program = True
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   420
    program.module_deps = list()
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   421
    program.name = name
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   422
    program.target = name
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4119
diff changeset
   423
4171
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   424
    if bld.env['ENABLE_SUDO']:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   425
        SuidBuildTask(bld, program)
4171
902589866374 teach enable-sudo to be a config time thing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4164
diff changeset
   426
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   427
    return program
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   428
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   429
def create_ns3_program(bld, name, dependencies=('simulator',)):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   430
    program = bld.new_task_gen('cxx', 'program')
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2990
diff changeset
   431
    program.is_ns3_program = True
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   432
    program.name = name
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   433
    program.target = program.name
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   434
    program.uselib_local = 'ns3'
1858
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1855
diff changeset
   435
    program.ns3_module_dependencies = ['ns3-'+dep for dep in dependencies]
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   436
    if program.env['ENABLE_STATIC_NS3']:
4438
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   437
        if sys.platform == 'darwin':
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   438
            program.env.append_value('LINKFLAGS', '-Wl,-all_load')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   439
            program.env.append_value('LINKFLAGS', '-lns3')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   440
        else:
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   441
            program.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   442
            program.env.append_value('LINKFLAGS', '-lns3')
8d9f6e489f94 enable darwin static builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4436
diff changeset
   443
            program.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   444
    return program
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   445
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   446
def add_scratch_programs(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   447
    all_modules = [mod[len("ns3-"):] for mod in bld.env['NS3_MODULES']]
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   448
    for filename in os.listdir("scratch"):
3867
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   449
        if filename.startswith('.') or filename == 'CVS':
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   450
	    continue
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   451
        if os.path.isdir(os.path.join("scratch", filename)):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   452
            obj = bld.create_ns3_program(filename, all_modules)
4108
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   453
            obj.path = obj.path.find_dir('scratch').find_dir(filename)
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   454
            obj.find_sources_in_dirs('.')
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   455
            obj.target = filename
3927
a2a992900b0b Make sure obj.name == obj.target for 'scratch' programs; fixes issue reported in ns-3-users with ./waf --run scratch/simple not working.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3919
diff changeset
   456
            obj.name = obj.target
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   457
        elif filename.endswith(".cc"):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   458
            name = filename[:-len(".cc")]
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   459
            obj = bld.create_ns3_program(name, all_modules)
4108
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   460
            obj.path = obj.path.find_dir('scratch')
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   461
            obj.source = filename
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4103
diff changeset
   462
            obj.target = name
3927
a2a992900b0b Make sure obj.name == obj.target for 'scratch' programs; fixes issue reported in ns-3-users with ./waf --run scratch/simple not working.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3919
diff changeset
   463
            obj.name = obj.target
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   464
3282
5e57c2f1cfb7 Add a WAF workaround for the 'Input line is too long.' error in win32/mingw.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3281
diff changeset
   465
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   466
def build(bld):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   467
    wutils.bld = bld
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   468
    if Options.options.no_task_lines:
2866
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   469
        import Runner
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   470
        def null_printout(s):
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   471
            pass
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   472
        Runner.printout = null_printout
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   473
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   474
    Options.cwd_launch = bld.path.abspath()
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   475
    bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   476
    bld.create_suid_program = types.MethodType(create_suid_program, bld)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   477
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   478
    # switch default variant to the one matching our debug level
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   479
    variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   480
    variant_env = bld.env_of_name(variant_name)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   481
    bld.all_envs['default'] = variant_env
762
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   482
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   483
    # process subfolders from here
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   484
    bld.add_subdirs('src')
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents: 3293
diff changeset
   485
    bld.add_subdirs('samples utils examples')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   486
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   487
    add_scratch_programs(bld)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   488
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   489
    ## if --enabled-modules option was given, we disable building the
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   490
    ## modules that were not enabled, and programs that depend on
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   491
    ## disabled modules.
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   492
    env = bld.env
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   493
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   494
    if Options.options.enable_modules:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   495
        Logs.warn("the option --enable-modules is being applied to this build only;"
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   496
                       " to make it permanent it needs to be given to waf configure.")
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   497
        env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   498
                                      Options.options.enable_modules.split(',')]
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   499
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   500
    if env['NS3_ENABLED_MODULES']:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   501
        modules = env['NS3_ENABLED_MODULES']
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   502
        changed = True
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   503
        while changed:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   504
            changed = False
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   505
            for module in modules:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   506
                module_obj = Object.name_to_obj(module)
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   507
                if module_obj is None:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   508
                    raise ValueError("module %s not found" % module)
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   509
                for dep in module_obj.add_objects:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   510
                    if not dep.startswith('ns3-'):
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   511
                        continue
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   512
                    if dep not in modules:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   513
                        modules.append(dep)
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   514
                        changed = True
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   515
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   516
        ## remove objects that depend on modules not listed
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   517
        for obj in list(bld.all_task_gen):
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   518
            if hasattr(obj, 'ns3_module_dependencies'):
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   519
                for dep in obj.ns3_module_dependencies:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   520
                    if dep not in modules:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   521
                        bld.all_task_gen.remove(obj)
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   522
                        break
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   523
            if obj.name in env['NS3_MODULES'] and obj.name not in modules:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   524
                bld.all_task_gen.remove(obj)
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   525
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   526
    ## Create a single ns3 library containing all enabled modules
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   527
    if env['ENABLE_STATIC_NS3']:
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   528
        lib = bld.new_task_gen('cxx', 'staticlib')
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   529
        lib.name = 'ns3'
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   530
        lib.target = 'ns3'
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   531
    else:
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   532
        lib = bld.new_task_gen('cxx', 'shlib')
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   533
        lib.name = 'ns3'
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   534
        lib.target = 'ns3'
5252
481053e0cd10 Bug 681: wrong compilation options for icpc (Intel C/C++ Compiler)
Andrey Mazo <mazo@iitp.ru>
parents: 5201
diff changeset
   535
        if lib.env['CXX_NAME'] in ['gcc', 'icc'] and env['WL_SONAME_SUPPORTED']:
4446
56b16bcd3afc Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4441
diff changeset
   536
            lib.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % ccroot.get_target_name(lib))
4535
0878cd580565 Bug #594: cygwin won't build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4531
diff changeset
   537
        if sys.platform == 'cygwin':
0878cd580565 Bug #594: cygwin won't build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4531
diff changeset
   538
            lib.features.append('implib') # workaround for WAF bug #472
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4388
diff changeset
   539
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   540
    if env['NS3_ENABLED_MODULES']:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   541
        lib.add_objects = list(modules)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   542
        env['NS3_ENABLED_MODULES'] = list(modules)
3014
b9c517e4bfd5 WAF: add uselib_local to the ns3 library to pull in library dependencies from the ns-3 modules into the main library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3002
diff changeset
   543
        lib.uselib_local = list(modules)
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   544
    else:
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   545
        lib.add_objects = list(env['NS3_MODULES'])
3014
b9c517e4bfd5 WAF: add uselib_local to the ns3 library to pull in library dependencies from the ns-3 modules into the main library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3002
diff changeset
   546
        lib.uselib_local = list(env['NS3_MODULES'])
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   547
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   548
    bld.add_subdirs('bindings/python')
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   549
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   550
    if Options.options.run:
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   551
        # Check that the requested program name is valid
4119
9ffcf2400aa5 Bug #323: waf --valgrind doesn't check for valgrind first
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4118
diff changeset
   552
        program_name, dummy_program_argv = wutils.get_run_program(Options.options.run, wutils.get_command_template(env))
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3927
diff changeset
   553
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   554
        # When --run'ing a program, tell WAF to only build that program,
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   555
        # nothing more; this greatly speeds up compilation when all you
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   556
        # want to do is run a test program.
4760
f774ff724ee4 Bug #609: --check and --regression should build only the required binaries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4751
diff changeset
   557
        Options.options.compile_targets += ',' + os.path.basename(program_name)
f774ff724ee4 Bug #609: --check and --regression should build only the required binaries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4751
diff changeset
   558
        for gen in bld.all_task_gen:
f774ff724ee4 Bug #609: --check and --regression should build only the required binaries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4751
diff changeset
   559
            if type(gen).__name__ in ['ns3header_taskgen', 'ns3moduleheader_taskgen']:
f774ff724ee4 Bug #609: --check and --regression should build only the required binaries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4751
diff changeset
   560
                gen.post()
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   561
4114
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   562
    if Options.options.regression or Options.options.regression_generate:
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   563
        regression_traces = env['REGRESSION_TRACES']
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   564
        if not regression_traces:
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   565
            raise Utils.WafError("Cannot run regression tests: reference traces directory not given"
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   566
                                 " (--with-regression-traces configure option)")
a6c5ccfa3451 Run regression tests as WAF tasks, plus simplify how unit tests are declared. Closes #480.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
   567
        regression.run_regression(bld, regression_traces)
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   568
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   569
#    if Options.options.check:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   570
#        Options.options.compile_targets += ',run-tests'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   571
#        if env['ENABLE_PYTHON_BINDINGS']:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   572
#            Options.options.compile_targets += ',ns3module,pybindgen-command'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   573
#        _run_check(bld)
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3429
diff changeset
   574
4770
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   575
    if Options.options.doxygen_no_build:
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   576
        doxygen()
d21013536be3 Add a waf --doxygen-no-build option, for a quicker testing loop of doxygen documentation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4769
diff changeset
   577
        raise SystemExit(0)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   578
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   579
def shutdown(ctx):
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   580
    bld = wutils.bld
4328
20a0a6244177 waf fix
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   581
    if wutils.bld is None:
20a0a6244177 waf fix
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   582
        return
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   583
    env = bld.env
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   584
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   585
    #if Options.commands['check']:
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   586
    #    _run_waf_check()
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   587
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   588
    if Options.options.lcov_report:
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   589
        lcov_report()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   590
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   591
    if Options.options.run:
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4328
diff changeset
   592
        wutils.run_program(Options.options.run, env, wutils.get_command_template(env))
935
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   593
        raise SystemExit(0)
53e1e53c373f WAF: add a --command-template option to e.g. allow running programs with valgrind, gdb, etc.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 934
diff changeset
   594
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   595
    if Options.options.pyrun:
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4328
diff changeset
   596
        wutils.run_python_program(Options.options.pyrun, env)
3419
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   597
        raise SystemExit(0)
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   598
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   599
    if Options.options.shell:
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   600
        raise Utils.WafError("Please run `./waf shell' now, instead of `./waf --shell'")
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   601
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   602
    if Options.options.check:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   603
        raise Utils.WafError("Please run `./test.py' now, instead of `./waf --check'")
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   604
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   605
    if Options.options.doxygen:
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   606
        doxygen()
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   607
        raise SystemExit(0)
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   608
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   609
    check_shell(bld)
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   610
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   611
    if Options.options.doxygen:
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   612
        doxygen()
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   613
        raise SystemExit(0)
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   614
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   615
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   616
check_context = Build.BuildContext
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   617
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   618
def check(bld):
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   619
    """run the NS-3 unit tests (deprecated in favour of test.py)"""
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   620
    raise Utils.WafError("Please run `./test.py' now, instead of './waf check'")
4531
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   621
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   622
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   623
class print_introspected_doxygen_task(Task.TaskBase):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   624
    after = 'cc cxx cc_link cxx_link'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   625
    color = 'BLUE'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   626
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   627
    def __init__(self, bld):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   628
        self.bld = bld
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   629
        super(print_introspected_doxygen_task, self).__init__(generator=self)
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   630
        
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   631
    def __str__(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   632
        return 'print-introspected-doxygen\n'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   633
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   634
    def runnable_status(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   635
        return Task.RUN_ME
1540
fd4e69513199 Now run doxygen again before the build, but the doc/trace-source-list.h is generated during waf check; make doxygen less verbose, and give a warning when doc/trace-source-list.h is missing.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1536
diff changeset
   636
4531
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   637
    def run(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   638
        ## generate the trace sources list docs
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   639
        env = wutils.bld.env
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   640
        proc_env = wutils.get_proc_env()
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   641
        try:
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   642
            program_obj = wutils.find_program('print-introspected-doxygen', env)
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   643
        except ValueError: # could happen if print-introspected-doxygen is
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   644
                           # not built because of waf configure
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   645
                           # --enable-modules=xxx
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   646
            pass
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   647
        else:
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   648
            prog = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj)).abspath(env)
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   649
            out = open(os.path.join('..', 'doc', 'introspected-doxygen.h'), 'w')
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   650
            if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   651
                raise SystemExit(1)
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   652
            out.close()
1536
23593050aa96 Run the program print-trace-sources to generate doc/trace-source-list.h when generating docs. As a side effect, --doxygen is now has to be processed at the end of the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1532
diff changeset
   653
4531
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   654
class run_python_unit_tests_task(Task.TaskBase):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   655
    after = 'cc cxx cc_link cxx_link'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   656
    color = 'BLUE'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   657
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   658
    def __init__(self, bld):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   659
        self.bld = bld
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   660
        super(run_python_unit_tests_task, self).__init__(generator=self)
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   661
        
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   662
    def __str__(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   663
        return 'run-python-unit-tests\n'
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   664
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   665
    def runnable_status(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   666
        return Task.RUN_ME
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   667
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   668
    def run(self):
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   669
        proc_env = wutils.get_proc_env()
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   670
        wutils.run_argv([self.bld.env['PYTHON'], os.path.join("..", "utils", "python-unit-tests.py")],
14a102415139 Run unit tests as indenpendent WAF tasks
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4450
diff changeset
   671
                        self.bld.env, proc_env, force_no_valgrind=True)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   672
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   673
#class run_a_unit_test_task(Task.TaskBase):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   674
#    after = 'cc cxx cc_link cxx_link'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   675
#    color = 'BLUE'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   676
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   677
#    def __init__(self, bld, name_of_test):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   678
#        self.bld = bld
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   679
#        super(run_a_unit_test_task, self).__init__(generator=self)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   680
#        self.name_of_test = name_of_test
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   681
#        try:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   682
#            program_obj = wutils.find_program("run-tests", self.bld.env)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   683
#        except ValueError, ex:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   684
#            raise Utils.WafError(str(ex))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   685
#        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   686
#        self.program_path = program_node.abspath(self.bld.env)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   687
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   688
#    def __str__(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   689
#        return 'run-unit-test(%s)\n' % self.name_of_test
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   690
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   691
#    def runnable_status(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   692
#        return Task.RUN_ME
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   693
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   694
#    def run(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   695
#        #print repr([self.program_path, self.name_of_test])
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   696
#        try:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   697
#            self.retval = wutils.run_argv([self.program_path, self.name_of_test], self.bld.env)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   698
#        except Utils.WafError:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   699
#            self.retval = 1
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   700
#        #print "running test %s: exit with %i" % (self.name_of_test, retval)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   701
#        return 0
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   702
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   703
#class get_list_of_unit_tests_task(Task.TaskBase):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   704
#    after = 'cc cxx cc_link cxx_link'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   705
#    color = 'BLUE'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   706
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   707
#    def __init__(self, bld):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   708
#        self.bld = bld
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   709
#        super(get_list_of_unit_tests_task, self).__init__(generator=self)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   710
#        self.tests = []
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   711
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   712
#    def __str__(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   713
#        return 'get-unit-tests-list\n'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   714
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   715
#    def runnable_status(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   716
#        return Task.RUN_ME
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   717
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   718
#    def run(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   719
#        try:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   720
#            program_obj = wutils.find_program("run-tests", self.bld.env)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   721
#        except ValueError, ex:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   722
#            raise Utils.WafError(str(ex))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   723
#        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   724
#        program_path = program_node.abspath(self.bld.env)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   725
#        proc = subprocess.Popen([program_path, "--ListTests"], stdout=subprocess.PIPE,
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   726
#                                env=wutils.get_proc_env())
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   727
#        self.tests = [l.rstrip() for l in proc.stdout.readlines()]
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   728
#        retval = proc.wait()
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   729
#        if retval:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   730
#            return retval
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   731
#        test_tasks = []
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   732
#        for name_of_test in self.tests:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   733
#            test_tasks.append(run_a_unit_test_task(self.bld, name_of_test))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   734
#        collector = collect_unit_test_results_task(self.bld, list(test_tasks))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   735
#        collector.run_after = list(test_tasks)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   736
#        self.more_tasks = [collector] + test_tasks
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   737
#        
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   738
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   739
#class collect_unit_test_results_task(Task.TaskBase):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   740
#    after = 'run_a_unit_test_task'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   741
#    color = 'BLUE'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   742
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   743
#    def __init__(self, bld, test_tasks):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   744
#        self.bld = bld
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   745
#        super(collect_unit_test_results_task, self).__init__(generator=self)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   746
#        self.test_tasks = test_tasks
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   747
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   748
#    def __str__(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   749
#        return 'collect-unit-tests-results\n'
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   750
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   751
#    def runnable_status(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   752
#        for t in self.run_after:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   753
#            if not t.hasrun:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   754
#                return Task.ASK_LATER
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   755
#        return Task.RUN_ME
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   756
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   757
#    def run(self):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   758
#        failed_tasks = []
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   759
#        for task in self.test_tasks:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   760
#            if task.retval:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   761
#                failed_tasks.append(task)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   762
#        if failed_tasks:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   763
#            print "C++ UNIT TESTS: %i tests passed, %i failed (%s)." % \
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   764
#                (len(self.test_tasks) - len(failed_tasks), len(failed_tasks),
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   765
#                 ', '.join(t.name_of_test for t in failed_tasks))
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   766
#            return 1
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   767
#        else:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   768
#            print "C++ UNIT TESTS: all %i tests passed." % (len(self.test_tasks),)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   769
#            return 0
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   770
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   771
#
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   772
#def _run_check(bld):
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   773
#    task = get_list_of_unit_tests_task(bld)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   774
#    print_introspected_doxygen_task(bld)
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   775
#    if bld.env['ENABLE_PYTHON_BINDINGS']:
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5252
diff changeset
   776
#        run_python_unit_tests_task(bld)
3419
8d3f5c0f55fa Add WAF option --pyrun, to make it easier to run Python programs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3418
diff changeset
   777
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   778
def check_shell(bld):
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   779
    if 'NS3_MODULE_PATH' not in os.environ:
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   780
        return
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   781
    env = bld.env
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   782
    correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH'])
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   783
    found_modpath = os.environ['NS3_MODULE_PATH']
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   784
    if found_modpath != correct_modpath:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   785
        msg = ("Detected shell (./waf shell) with incorrect configuration\n"
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   786
               "=========================================================\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   787
               "Possible reasons for this problem:\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   788
               "  1. You switched to another ns-3 tree from inside this shell\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   789
               "  2. You switched ns-3 debug level (waf configure --debug)\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   790
               "  3. You modified the list of built ns-3 modules\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   791
               "You should correct this situation before running any program.  Possible solutions:\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   792
               "  1. Exit this shell, and start a new one\n"
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   793
               "  2. Run a new nested shell")
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   794
        raise Utils.WafError(msg)
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   795
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   796
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   797
shell_context = Build.BuildContext
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   798
def shell(ctx):
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   799
    """run a shell with an environment suitably modified to run locally built programs"""
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   800
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   801
    #make sure we build first"
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   802
    Scripting.build(ctx)
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   803
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   804
    if sys.platform == 'win32':
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   805
        shell = os.environ.get("COMSPEC", "cmd.exe")
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   806
    else:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   807
        shell = os.environ.get("SHELL", "/bin/sh")
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   808
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   809
    env = wutils.bld.env
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4328
diff changeset
   810
    wutils.run_argv([shell], env, {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])})
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   811
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   812
def doxygen():
1855
ee15fef0cb62 print-trace-sources.cc -> print-introspected-doxygen.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1804
diff changeset
   813
    if not os.path.exists('doc/introspected-doxygen.h'):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   814
        Logs.warn("doc/introspected-doxygen.h does not exist; run waf check to generate it.")
1536
23593050aa96 Run the program print-trace-sources to generate doc/trace-source-list.h when generating docs. As a side effect, --doxygen is now has to be processed at the end of the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1532
diff changeset
   815
23593050aa96 Run the program print-trace-sources to generate doc/trace-source-list.h when generating docs. As a side effect, --doxygen is now has to be processed at the end of the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1532
diff changeset
   816
    ## run doxygen
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   817
    doxygen_config = os.path.join('doc', 'doxygen.conf')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   818
    if subprocess.Popen(['doxygen', doxygen_config]).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   819
        raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   820
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   821
def lcov_report():
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   822
    env = Build.bld.env
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   823
    variant_name = env['NS3_ACTIVE_VARIANT']
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   824
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   825
    if 'gcov' not in variant_name:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   826
        raise Utils.WafError("project not configured for code coverage;"
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   827
                     " reconfigure with --enable-gcov")
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   828
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   829
    os.chdir(blddir)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   830
    try:
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   831
        lcov_report_dir = os.path.join(variant_name, 'lcov-report')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   832
        create_dir_command = "rm -rf " + lcov_report_dir
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   833
        create_dir_command += " && mkdir " + lcov_report_dir + ";"
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   834
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   835
        if subprocess.Popen(create_dir_command, shell=True).wait():
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   836
            raise SystemExit(1)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   837
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   838
        info_file = os.path.join(lcov_report_dir, variant_name + '.info')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   839
        lcov_command = "../utils/lcov/lcov -c -d . -o " + info_file
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   840
        lcov_command += " --source-dirs=" + os.getcwd()
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   841
        lcov_command += ":" + os.path.join(
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   842
            os.getcwd(), variant_name, 'include')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   843
        if subprocess.Popen(lcov_command, shell=True).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   844
            raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   845
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   846
        genhtml_command = "../utils/lcov/genhtml -o " + lcov_report_dir
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   847
        genhtml_command += " " + info_file
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   848
        if subprocess.Popen(genhtml_command, shell=True).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   849
            raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   850
    finally:
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   851
        os.chdir("..")
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   852
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   853
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   854
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   855
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   856
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   857
## The default WAF DistDir implementation is rather slow, because it
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   858
## first copies everything and only later removes unwanted files and
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   859
## directories; this means that it needless copies the full build dir
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   860
## and the .hg repository tree.  Here we provide a replacement DistDir
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   861
## implementation that is more efficient.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   862
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   863
import Scripting
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   864
from Scripting import dist_exts, excludes, BLDDIR
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   865
import Utils
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   866
import os
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   867
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   868
def _copytree(src, dst, symlinks=False, excludes=(), build_dir=None):
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   869
    """Recursively copy a directory tree using copy2().
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   870
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   871
    The destination directory must not already exist.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   872
    If exception(s) occur, an Error is raised with a list of reasons.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   873
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   874
    If the optional symlinks flag is true, symbolic links in the
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   875
    source tree result in symbolic links in the destination tree; if
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   876
    it is false, the contents of the files pointed to by symbolic
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   877
    links are copied.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   878
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   879
    XXX Consider this example code rather than the ultimate tool.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   880
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   881
    Note: this is a modified version of shutil.copytree from python
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   882
    2.5.2 library; modified for WAF purposes to exclude dot dirs and
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   883
    another list of files.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   884
    """
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   885
    names = os.listdir(src)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   886
    os.makedirs(dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   887
    errors = []
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   888
    for name in names:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   889
        srcname = os.path.join(src, name)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   890
        dstname = os.path.join(dst, name)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   891
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   892
            if symlinks and os.path.islink(srcname):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   893
                linkto = os.readlink(srcname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   894
                os.symlink(linkto, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   895
            elif os.path.isdir(srcname):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   896
                if name in excludes:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   897
                    continue
3867
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   898
                elif name.startswith('.') or name.startswith(',,') or name.startswith('++') or name.startswith('CVS'):
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   899
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   900
                elif name == build_dir:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   901
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   902
                else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   903
                    ## build_dir is not passed into the recursive
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   904
                    ## copytree, but that is intentional; it is a
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   905
                    ## directory name valid only at the top level.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   906
                    copytree(srcname, dstname, symlinks, excludes)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   907
            else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   908
                ends = name.endswith
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   909
                to_remove = False
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   910
                if name.startswith('.') or name.startswith('++'):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   911
                    to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   912
                else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   913
                    for x in dist_exts:
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   914
                        if ends(x):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   915
                            to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   916
                            break
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   917
                if not to_remove:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   918
                    shutil.copy2(srcname, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   919
            # XXX What about devices, sockets etc.?
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   920
        except (IOError, os.error), why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   921
            errors.append((srcname, dstname, str(why)))
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   922
        # catch the Error from the recursive copytree so that we can
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   923
        # continue with other files
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   924
        except shutil.Error, err:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   925
            errors.extend(err.args[0])
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   926
    try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   927
        shutil.copystat(src, dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   928
    except WindowsError:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   929
        # can't copy file access times on Windows
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   930
        pass
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   931
    except OSError, why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   932
        errors.extend((src, dst, str(why)))
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   933
    if errors:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   934
        raise shutil.Error, errors
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   935
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   936
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   937
def DistDir(appname, version):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   938
    #"make a distribution directory with all the sources in it"
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   939
    import shutil
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   940
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   941
    # Our temporary folder where to put our files
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   942
    TMPFOLDER=appname+'-'+version
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   943
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   944
    # Remove an old package directory
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   945
    if os.path.exists(TMPFOLDER): shutil.rmtree(TMPFOLDER)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   946
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   947
    global g_dist_exts, g_excludes
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   948
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   949
    # Remove the Build dir
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   950
    build_dir = getattr(Utils.g_module, BLDDIR, None)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   951
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   952
    # Copy everything into the new folder
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4202
diff changeset
   953
    _copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir)
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   954
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   955
    # TODO undocumented hook
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   956
    dist_hook = getattr(Utils.g_module, 'dist_hook', None)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   957
    if dist_hook:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   958
        os.chdir(TMPFOLDER)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   959
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   960
            dist_hook()
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   961
        finally:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   962
            # go back to the root directory
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   963
            os.chdir('..')
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   964
    return TMPFOLDER
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   965
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   966
Scripting.DistDir = DistDir
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   967
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   968