wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sat, 12 Jul 2008 19:33:29 +0100
changeset 3419 8d3f5c0f55fa
parent 3418 3ba0b240cff5
child 3429 2658cf81a5cd
permissions -rw-r--r--
Add WAF option --pyrun, to make it easier to run Python programs.
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; -*-
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
     2
import sys
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
     3
import shlex
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
     4
import shutil
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
     5
import urllib
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
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     9
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
    10
import pproc as subprocess
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
    11
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    12
import Params
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    13
import Object
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
    14
import ccroot
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    15
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    16
Params.g_autoconfig = 1
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    17
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    18
# the following two variables are used by the target "waf dist"
694
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    19
VERSION = file("VERSION").read().strip()
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    20
APPNAME = 'ns'
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    21
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    22
# 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
    23
srcdir = '.'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    24
blddir = 'build'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    25
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    26
#
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    27
# The directory in which the tarball of the reference traces lives.  This is
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    28
# used if Mercurial is not on the system.
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    29
#
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    30
REGRESSION_TRACES_URL = "http://www.nsnam.org/releases/"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    31
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    32
#
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    33
# The path to the Mercurial repository used to find the reference traces if
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    34
# we find "hg" on the system.  We expect that the repository will be named
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    35
# identically to refDirName below
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    36
#
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    37
REGRESSION_TRACES_REPO = "http://code.nsnam.org/"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    38
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    39
#
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    40
# Name of the local directory where the regression code lives.
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    41
#
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    42
REGRESSION_DIR = "regression"
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    43
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    44
#
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    45
# The last part of the path name to use to find the regression traces.  The
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    46
# path will be APPNAME + '-' + VERSION + REGRESSION_SUFFIX, e.g.,
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    47
# ns-3-dev-ref-traces
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    48
#
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    49
REGRESSION_SUFFIX = "-ref-traces"
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    50
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    51
#
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    52
# The last part of the path name to use to find the regression traces tarball.
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    53
# path will be APPNAME + '-' + VERSION + REGRESSION_SUFFIX + TRACEBALL_SUFFIX,
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    54
# e.g., ns-3-dev-ref-traces.tar.bz2
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    55
#
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    56
TRACEBALL_SUFFIX = ".tar.bz2"
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    57
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    58
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
    59
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
    60
    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
    61
    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
    62
    shutil.rmtree("doc/latex", True)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    63
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
    64
    if not os.path.exists("bindings/python/pybindgen"):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
    65
        Params.fatal("Missing pybindgen checkout; run './waf configure --pybindgen-checkout' first.")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
    66
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    67
    ## 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
    68
    ## ns-3-dev-ref-traces
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    69
    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
    70
    ## Create a tar.bz2 file with the traces
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    71
    traces_dir = os.path.join(REGRESSION_DIR, traces_name)
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    72
    if not os.path.isdir(traces_dir):
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    73
        Params.warning("Not creating traces archive: the %s directory does not exist" % traces_dir)
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    74
    else:
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    75
        traceball = traces_name + TRACEBALL_SUFFIX
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    76
        tar = tarfile.open(os.path.join("..", traceball), 'w:bz2')
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    77
        tar.add(traces_dir)
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    78
        tar.close()
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    79
        ## Now remove it; we do not ship the traces with the main tarball...
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    80
        shutil.rmtree(traces_dir, True)
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    81
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    82
def set_options(opt):
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
    83
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
    84
    def debug_option_callback(option, opt, value, parser):
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
    85
        if value == 'debug':
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
    86
            setattr(parser.values, option.dest, 'ultradebug')
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
    87
        elif value == 'optimized':
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
    88
            setattr(parser.values, option.dest, 'optimized')
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
    89
        else:
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
    90
            raise optparse.OptionValueError("allowed --debug-level values"
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
    91
                                            " are debug, optimized.")
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
    92
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
    93
    opt.add_option('-d', '--debug-level',
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
    94
                   action='callback',
1425
e4cdb57f162c WAF: fix debug level to be 'ultradebug' by default, instead of 'debug'.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1424
diff changeset
    95
                   type="string", dest='debug_level', default='ultradebug',
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
    96
                   help=('Specify the debug level, does nothing if CFLAGS is set'
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
    97
                         ' in the environment. [Allowed Values: debug, optimized].'
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
    98
                         ' 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
    99
                         'with the configure command.'),
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
   100
                   callback=debug_option_callback)
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
   101
    
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   102
    # 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
   103
    opt.tool_options('compiler_cxx')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   104
2846
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   105
    opt.add_option('--cwd',
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   106
                   help=('Set the working directory for a program.'),
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   107
                   action="store", type="string", default=None,
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   108
                   dest='cwd_launch')
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   109
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   110
    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
   111
                   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
   112
                         ' 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
   113
                         'with the configure command.'),
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   114
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   115
                   dest='enable_gcov')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   116
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
   117
    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
   118
                   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
   119
                         "  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
   120
                         " 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
   121
                   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
   122
                   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
   123
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   124
    opt.add_option('--lcov-report',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   125
                   help=('Generate a code coverage report '
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   126
                         '(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
   127
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   128
                   dest='lcov_report')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   129
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   130
    opt.add_option('--doxygen',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   131
                   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
   132
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   133
                   dest='doxygen')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   134
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
   135
    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
   136
                   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
   137
                         ' 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
   138
                   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
   139
    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
   140
                   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
   141
                         ' 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
   142
                         ' 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
   143
                   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
   144
    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
   145
                   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
   146
                         ' 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
   147
                         ' 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
   148
                   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
   149
    opt.add_option('--valgrind',
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   150
                   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
   151
                   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
   152
                   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
   153
    opt.add_option('--shell',
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
   154
                   help=('Run a shell with an environment suitably modified to run locally built programs'),
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
   155
                   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
   156
                   dest='shell')
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
   157
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   158
    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
   159
                   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
   160
                   default=False, dest='regression', action="store_true")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   161
    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
   162
                   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
   163
                   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
   164
    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
   165
                   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
   166
                         '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
   167
                   dest='regression_tests', type="string")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   168
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   169
    # 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
   170
    opt.sub_options('src')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   171
    opt.sub_options('bindings/python')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   172
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   173
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
   174
def check_compilation_flag(conf, flag):
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
   175
    """
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
   176
    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
   177
    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
   178
    """
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
   179
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
   180
    # Check for -Wno-error=deprecated-declarations
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
   181
    save_CXXFLAGS = list(conf.env['CXXFLAGS'])
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
   182
    conf.env.append_value('CXXFLAGS', flag)
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
   183
    e = conf.create_test_configurator()
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
   184
    e.mandatory = 0
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
   185
    e.code = '#include <stdio.h>\nint main() { return 0; }\n'
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
   186
    e.want_message = 0
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
   187
    ok = e.run()
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
   188
    conf.check_message_custom(flag, 'compilation flag support',
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
   189
                              (ok and 'yes' or 'no'))
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
   190
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
   191
    if not ok: # if it doesn't accept, remove it again
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
   192
        conf.env['CXXFLAGS'] = save_CXXFLAGS
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
   193
    
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
   194
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   195
def configure(conf):
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
   196
    conf.check_tool('compiler_cxx')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   197
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   198
    # create the second environment, set the variant and set its name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   199
    variant_env = conf.env.copy()
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
   200
    debug_level = Params.g_options.debug_level.lower()
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
   201
    if debug_level == 'ultradebug':
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
   202
        variant_name = 'debug'
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
   203
    else:
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
   204
        variant_name = debug_level
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   205
1532
1f54822519c0 WAF: set env['INCLUDEDIR'] to PREFIX/include so that ns3 headers get installed on 'waf install' (also shuts up the warnings in waf distcheck)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1531
diff changeset
   206
    variant_env['INCLUDEDIR'] = os.path.join(variant_env['PREFIX'], 'include')
1f54822519c0 WAF: set env['INCLUDEDIR'] to PREFIX/include so that ns3 headers get installed on 'waf install' (also shuts up the warnings in waf distcheck)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1531
diff changeset
   207
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   208
    if Params.g_options.enable_gcov:
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   209
        variant_name += '-gcov'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   210
        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
   211
        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
   212
        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
   213
        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
   214
        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
   215
    
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   216
    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
   217
    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
   218
    variant_env.set_variant(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   219
    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
   220
    conf.setenv(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   221
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   222
    variant_env.append_value('CXXDEFINES', 'RUN_SELF_TESTS')
786
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   223
    
924
fa23f33acca0 WAF: don't change CXXFLAGS if CXXFLAGS is set in the OS environment (so that user CXXFLAGS take precedence).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 923
diff changeset
   224
    if (os.path.basename(conf.env['CXX']).startswith("g++")
fa23f33acca0 WAF: don't change CXXFLAGS if CXXFLAGS is set in the OS environment (so that user CXXFLAGS take precedence).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 923
diff changeset
   225
        and 'CXXFLAGS' not in os.environ):
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
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
   227
        variant_env.append_value('CXXFLAGS', '-Werror')
786
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   228
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
   229
        check_compilation_flag(conf, '-Wno-error=deprecated-declarations')
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
   230
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
   231
        
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   232
    if 'debug' in Params.g_options.debug_level.lower():
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   233
        variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1502
diff changeset
   234
        variant_env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   235
923
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   236
    ## In optimized builds we still want debugging symbols, e.g. for
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   237
    ## profiling, and at least partially usable stack traces.
924
fa23f33acca0 WAF: don't change CXXFLAGS if CXXFLAGS is set in the OS environment (so that user CXXFLAGS take precedence).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 923
diff changeset
   238
    if ('optimized' in Params.g_options.debug_level.lower() 
fa23f33acca0 WAF: don't change CXXFLAGS if CXXFLAGS is set in the OS environment (so that user CXXFLAGS take precedence).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 923
diff changeset
   239
        and 'CXXFLAGS' not in os.environ):
923
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   240
        for flag in variant_env['CXXFLAGS_DEBUG']:
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   241
            ## this probably doesn't work for MSVC
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   242
            if flag.startswith('-g'):
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   243
                variant_env.append_value('CXXFLAGS', flag)
f5d38217e7a2 WAF: add debugging symbols to optimized builds
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 921
diff changeset
   244
1426
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   245
    ## in optimized builds, replace -O2 with -O3
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   246
    if 'optimized' in Params.g_options.debug_level.lower():
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   247
        lst = variant_env['CXXFLAGS']
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   248
        for i, flag in enumerate(lst):
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   249
            if flag == '-O2':
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   250
                lst[i] = '-O3'
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   251
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
   252
    if sys.platform == 'win32':
786
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   253
        if os.path.basename(conf.env['CXX']).startswith("g++"):
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   254
            variant_env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")
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
   255
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   256
    conf.sub_config('src')
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1532
diff changeset
   257
    conf.sub_config('utils')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   258
    conf.sub_config('bindings/python')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   259
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
   260
    if Params.g_options.enable_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
   261
        conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
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
   262
                                           Params.g_options.enable_modules.split(',')]
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
   263
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   264
    ## we cannot run regression tests without diff
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   265
    conf.find_program('diff', var='DIFF')
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   266
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   267
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
   268
def create_ns3_program(bld, name, dependencies=('simulator',)):
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
   269
    program = bld.create_obj('cpp', '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
   270
    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
   271
    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
   272
    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
   273
    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
   274
    program.ns3_module_dependencies = ['ns3-'+dep for dep in dependencies]
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
   275
    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
   276
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   277
def add_scratch_programs(bld):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   278
    all_modules = [mod[len("ns3-"):] for mod in bld.env()['NS3_MODULES']]
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   279
    for filename in os.listdir("scratch"):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   280
        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
   281
            obj = bld.create_ns3_program(filename, all_modules)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   282
            obj.path = obj.path.find_dir('scratch')
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   283
            obj.find_sources_in_dirs(filename)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   284
            obj.target = os.path.join(filename, filename)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   285
        elif filename.endswith(".cc"):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   286
            name = filename[:-len(".cc")]
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   287
            obj = bld.create_ns3_program(name, all_modules)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   288
            obj.source = "scratch/%s" % filename
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   289
            obj.target = "scratch/%s" % name
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
   290
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
   291
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
   292
##
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
   293
## This replacement spawn function increases the maximum command line length to 32k
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
   294
##
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
   295
def _exec_command_interact_win32(s):
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
   296
    if Params.g_verbose:
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
   297
        print s
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
   298
    startupinfo = subprocess.STARTUPINFO()
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
   299
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
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
   300
    proc = subprocess.Popen(s, shell=False, startupinfo=startupinfo)
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
   301
    stat = proc.wait()
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
   302
    if stat & 0xff:
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
   303
        return stat | 0x80
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
   304
    return stat >> 8
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
   305
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
   306
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   307
def build(bld):
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
   308
    if Params.g_options.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
   309
        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
   310
        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
   311
            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
   312
        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
   313
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
   314
    if sys.platform == 'win32':
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
   315
        import Runner
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
   316
        Runner.exec_command = _exec_command_interact_win32
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
   317
1307
fa2e8988fda7 Add some tweaks to enable building under emacs.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1306
diff changeset
   318
    Params.g_cwd_launch = Params.g_build.m_curdirnode.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
   319
    bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   320
    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
   321
    variant_env = bld.env_of_name(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   322
    bld.m_allenvs['default'] = variant_env # switch to the active variant
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
   323
915
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   324
    if Params.g_options.shell:
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
   325
        run_shell()
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
   326
        raise SystemExit(0)
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
   327
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
   328
    if Params.g_options.doxygen:
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
   329
        doxygen()
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
   330
        raise SystemExit(0)
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
   331
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
   332
    check_shell()
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
   333
1717
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   334
    if Params.g_options.doxygen:
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   335
        doxygen()
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   336
        raise SystemExit(0)
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   337
3002
3f851016493d WAF: use os.path.join in the message 'Entering directory ...'
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3001
diff changeset
   338
    print "Entering directory `%s'" % os.path.join(Params.g_build.m_curdirnode.abspath(), 'build')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   339
    # process subfolders from here
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   340
    bld.add_subdirs('src')
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents: 3293
diff changeset
   341
    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
   342
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   343
    add_scratch_programs(bld)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   344
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
   345
    ## 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
   346
    ## 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
   347
    ## disabled 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
   348
    env = bld.env()
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
   349
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
   350
    if Params.g_options.enable_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
   351
        Params.warning("the option --enable-modules is being applied to this build only;"
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
   352
                       " 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
   353
        env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
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
   354
                                      Params.g_options.enable_modules.split(',')]
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
   355
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
   356
    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
   357
        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
   358
        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
   359
        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
   360
            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
   361
            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
   362
                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
   363
                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
   364
                    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
   365
                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
   366
                    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
   367
                        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
   368
                    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
   369
                        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
   370
                        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
   371
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
   372
        ## remove objects that depend on modules not listed
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
   373
        for obj in list(Object.g_allobjs):
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
   374
            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
   375
                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
   376
                    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
   377
                        Object.g_allobjs.remove(obj)
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
   378
                        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
   379
            if obj.name in env['NS3_MODULES'] and obj.name 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
   380
                Object.g_allobjs.remove(obj)
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
   381
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
   382
    ## Create a single ns3 library containing all 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
   383
    lib = bld.create_obj('cpp', 'shlib')
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
   384
    lib.name = '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
   385
    lib.target = '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
   386
    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
   387
        lib.add_objects = list(modules)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   388
        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
   389
        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
   390
    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
   391
        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
   392
        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
   393
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   394
    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
   395
2207
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   396
def get_command_template():
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   397
    if Params.g_options.valgrind:
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   398
        if Params.g_options.command_template:
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   399
            Params.fatal("Options --command-template and --valgrind are conflicting")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   400
        return "valgrind --leak-check=full %s"
2207
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   401
    else:
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   402
        return (Params.g_options.command_template or '%s')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   403
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
   404
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   405
def shutdown():
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
   406
    #import UnitTest
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
   407
    #ut = UnitTest.unit_test()
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
   408
    #ut.change_to_testfile_dir = True
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
   409
    #ut.want_to_see_test_output = True
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
   410
    #ut.want_to_see_test_error = True
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
   411
    #ut.run()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   412
    #ut.print_results()
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   413
    env = Params.g_build.env_of_name('default')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   414
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
   415
    if Params.g_commands['check']:
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
   416
        _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
   417
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   418
    if Params.g_options.regression or Params.g_options.regression_generate:
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   419
        if not env['DIFF']:
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   420
            Params.fatal("Cannot run regression tests: the 'diff' program is not installed.")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   421
        _dir = os.getcwd()
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   422
        os.chdir("regression")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   423
        try:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   424
            run_regression()
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   425
        finally:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   426
            os.chdir(_dir)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   427
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   428
    if Params.g_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
   429
        lcov_report()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   430
915
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   431
    if Params.g_options.run:
2207
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   432
        run_program(Params.g_options.run, get_command_template())
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
   433
        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
   434
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
   435
    if Params.g_options.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
   436
        run_python_program(Params.g_options.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
   437
        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
   438
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
   439
def _run_waf_check():
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
   440
    ## generate the trace sources list docs
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
   441
    env = Params.g_build.env_of_name('default')
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
   442
    proc_env = _get_proc_env()
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
   443
    try:
2344
7617aa80498d Fix a typo in the WAF scripts; don't access m_linktask directly, use the get_target_name() method instead (to make it work with waf trunk).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2212
diff changeset
   444
        program_obj = _find_program('print-introspected-doxygen', env)
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
   445
    except ValueError: # could happen if print-introspected-doxygen is
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
   446
                       # not built because of waf configure
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
   447
                       # --enable-modules=xxx
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
   448
        pass
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
   449
    else:
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
   450
        prog = program_obj.path.find_build(ccroot.get_target_name(program_obj)).abspath(env)
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
   451
        out = open('doc/introspected-doxygen.h', 'w')
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
   452
        if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
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
   453
            raise SystemExit(1)
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
   454
        out.close()
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
   455
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   456
    print "-- Running NS-3 C++ core unit tests..."
2207
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   457
    run_program('run-tests', get_command_template())
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
   458
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   459
    print "-- Running NS-3 Python bindings unit tests..."
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   460
    _run_argv([env['PYTHON'], os.path.join("utils", "python-unit-tests.py")], proc_env)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   461
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   462
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   463
def _find_program(program_name, env):
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   464
    launch_dir = os.path.abspath(Params.g_cwd_launch)
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   465
    found_programs = []
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
   466
    for obj in Object.g_allobjs:
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
   467
        if not getattr(obj, 'is_ns3_program', False):
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   468
            continue
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   469
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   470
        ## filter out programs not in the subtree starting at the launch dir
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   471
        if not (obj.path.abspath().startswith(launch_dir)
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   472
                or obj.path.abspath(env).startswith(launch_dir)):
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   473
            continue
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   474
        
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   475
        found_programs.append(obj.target)
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
   476
        if obj.target == program_name:
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
   477
            return obj
917
aed7f1b9e783 WAF: fix simple typo in error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 916
diff changeset
   478
    raise ValueError("program '%s' not found; available programs are: %r"
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   479
                     % (program_name, found_programs))
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
   480
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
   481
def _get_proc_env(os_env=None):
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
   482
    env = Params.g_build.env_of_name('default')
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
   483
    if sys.platform == 'linux2':
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
   484
        pathvar = 'LD_LIBRARY_PATH'
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
   485
    elif sys.platform == 'darwin':
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
   486
        pathvar = 'DYLD_LIBRARY_PATH'
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
   487
    elif 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
   488
        pathvar = 'PATH'
785
bf8e7773836a WAF: configure dynamic path for the cygwin platform.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 764
diff changeset
   489
    elif sys.platform == 'cygwin':
bf8e7773836a WAF: configure dynamic path for the cygwin platform.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 764
diff changeset
   490
        pathvar = '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
   491
    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
   492
        Params.warning(("Don't know how to configure "
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
   493
                        "dynamic library path for the platform '%s'") % (sys.platform,))
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
   494
        pathvar = None
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
   495
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
   496
    proc_env = dict(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
   497
    if os_env is not None:
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
   498
        proc_env.update(os_env)
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
   499
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
   500
    if pathvar is not None:
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
   501
        if pathvar in proc_env:
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
   502
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']) + [proc_env[pathvar]])
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
   503
        else:
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
   504
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   505
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   506
    pymoddir = Params.g_build.m_curdirnode.find_dir('bindings/python').abspath(env)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   507
    if 'PYTHONPATH' in proc_env:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   508
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir] + [proc_env['PYTHONPATH']])
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   509
    else:
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   510
        proc_env['PYTHONPATH'] = pymoddir
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   511
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
   512
    return proc_env
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
   513
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
   514
def _run_argv(argv, os_env=None):
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
   515
    proc_env = _get_proc_env(os_env)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   516
    env = Params.g_build.env_of_name('default')
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
   517
    retval = subprocess.Popen(argv, env=proc_env).wait()
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
   518
    if retval:
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
   519
        Params.fatal("Command %s exited with code %i" % (argv, retval))
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
   520
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
   521
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
   522
def run_program(program_string, command_template=None):
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
   523
    """
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
   524
    if command_template is not None, then program_string == 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
   525
    name and argv is given by command_template with %s replaced by the
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
   526
    full path to the program.  Else, program_string is interpreted as
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
   527
    a shell command with first name being the 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
   528
    """
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
   529
    env = Params.g_build.env_of_name('default')
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
   530
2345
79f77914c31c Fix the WAF --run option for running a program with command line options
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2344
diff changeset
   531
    if command_template in (None, '%s'):
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
   532
        argv = shlex.split(program_string)
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
   533
        program_name = argv[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
   534
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
   535
        try:
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
   536
            program_obj = _find_program(program_name, env)
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
   537
        except ValueError, ex:
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
   538
            Params.fatal(str(ex))
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
   539
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
   540
        try:
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
   541
            program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
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
   542
        except AttributeError:
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
   543
            Params.fatal("%s does not appear to be a program" % (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
   544
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
   545
        execvec = [program_node.abspath(env)] + argv[1:]
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
   546
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
   547
    else:
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
   548
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
   549
        program_name = program_string
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
   550
        try:
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
   551
            program_obj = _find_program(program_name, env)
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
   552
        except ValueError, ex:
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
   553
            Params.fatal(str(ex))
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
   554
        try:
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
   555
            program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
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
   556
        except AttributeError:
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
   557
            Params.fatal("%s does not appear to be a program" % (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
   558
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
   559
        execvec = shlex.split(command_template % (program_node.abspath(env),))
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
   560
919
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   561
    former_cwd = os.getcwd()
2846
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   562
    if (Params.g_options.cwd_launch):
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   563
        os.chdir(Params.g_options.cwd_launch)
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   564
    else:
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
   565
        os.chdir(Params.g_cwd_launch)
919
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   566
    try:
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
   567
        retval = _run_argv(execvec)
919
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   568
    finally:
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   569
        os.chdir(former_cwd)
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
   570
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
   571
    return retval
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
   572
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
   573
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
   574
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
   575
def run_python_program(program_string):
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
   576
    env = Params.g_build.env_of_name('default')
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
   577
    execvec = shlex.split(program_string)
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
   578
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
   579
    former_cwd = os.getcwd()
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
   580
    if (Params.g_options.cwd_launch):
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
   581
        os.chdir(Params.g_options.cwd_launch)
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
   582
    else:
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
   583
        os.chdir(Params.g_cwd_launch)
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
   584
    try:
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
   585
        retval = _run_argv([env['PYTHON']] + execvec)
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
   586
    finally:
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
   587
        os.chdir(former_cwd)
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
   588
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
   589
    return retval
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
   590
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
   591
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
   592
def check_shell():
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
   593
    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
   594
        return
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
   595
    env = Params.g_build.env_of_name('default')
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
   596
    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
   597
    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
   598
    if found_modpath != correct_modpath:
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
   599
        msg = ("Detected shell (waf --shell) with incorrect configuration\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
   600
               "=========================================================\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
   601
               "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
   602
               "  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
   603
               "  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
   604
               "  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
   605
               "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
   606
               "  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
   607
               "  2. Run a new nested shell")
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
   608
        Params.fatal(msg)
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
   609
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
   610
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
   611
def run_shell():
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
   612
    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
   613
        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
   614
    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
   615
        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
   616
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
   617
    env = Params.g_build.env_of_name('default')
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
   618
    _run_argv([shell], {'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
   619
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
   620
def doxygen():
1855
ee15fef0cb62 print-trace-sources.cc -> print-introspected-doxygen.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1804
diff changeset
   621
    if not os.path.exists('doc/introspected-doxygen.h'):
ee15fef0cb62 print-trace-sources.cc -> print-introspected-doxygen.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1804
diff changeset
   622
        Params.warning("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
   623
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
   624
    ## 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
   625
    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
   626
    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
   627
        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
   628
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
   629
def 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
   630
    env = Params.g_build.env_of_name('default')
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
   631
    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
   632
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
   633
    if 'gcov' not in variant_name:
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
   634
        Params.fatal("project not configured for code coverage;"
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
   635
                     " 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
   636
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
   637
    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
   638
    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
   639
        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
   640
        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
   641
        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
   642
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
   643
        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
   644
            raise SystemExit(1)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   645
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
   646
        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
   647
        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
   648
        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
   649
        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
   650
            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
   651
        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
   652
            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
   653
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
   654
        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
   655
        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
   656
        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
   657
            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
   658
    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
   659
        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
   660
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   661
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   662
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   663
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   664
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   665
## 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
   666
## 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
   667
## 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
   668
## 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
   669
## implementation that is more efficient.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   670
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   671
import Scripting
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   672
from Scripting import g_dist_exts, g_excludes, BLDDIR
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   673
import Utils
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   674
import os
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   675
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   676
def copytree(src, dst, symlinks=False, excludes=(), build_dir=None):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   677
    """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
   678
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   679
    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
   680
    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
   681
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   682
    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
   683
    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
   684
    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
   685
    links are copied.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   686
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   687
    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
   688
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   689
    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
   690
    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
   691
    another list of files.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   692
    """
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   693
    names = os.listdir(src)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   694
    os.makedirs(dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   695
    errors = []
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   696
    for name in names:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   697
        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
   698
        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
   699
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   700
            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
   701
                linkto = os.readlink(srcname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   702
                os.symlink(linkto, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   703
            elif os.path.isdir(srcname):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   704
                if name in excludes:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   705
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   706
                elif name.startswith('.') or name.startswith(',,') or name.startswith('++'):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   707
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   708
                elif name == build_dir:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   709
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   710
                else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   711
                    ## 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
   712
                    ## 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
   713
                    ## 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
   714
                    copytree(srcname, dstname, symlinks, excludes)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   715
            else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   716
                ends = name.endswith
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   717
                to_remove = False
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   718
                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
   719
                    to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   720
                else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   721
                    for x in g_dist_exts:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   722
                        if ends(x):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   723
                            to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   724
                            break
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   725
                if not to_remove:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   726
                    shutil.copy2(srcname, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   727
            # 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
   728
        except (IOError, os.error), why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   729
            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
   730
        # 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
   731
        # continue with other files
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   732
        except shutil.Error, err:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   733
            errors.extend(err.args[0])
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   734
    try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   735
        shutil.copystat(src, dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   736
    except WindowsError:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   737
        # 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
   738
        pass
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   739
    except OSError, why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   740
        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
   741
    if errors:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   742
        raise shutil.Error, errors
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   743
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   744
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   745
def DistDir(appname, version):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   746
    "make a distribution directory with all the sources in it"
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   747
    import shutil
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   748
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   749
    # 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
   750
    TMPFOLDER=appname+'-'+version
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   751
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   752
    # Remove an old package directory
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   753
    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
   754
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   755
    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
   756
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   757
    # Remove the Build dir
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   758
    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
   759
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   760
    # Copy everything into the new folder
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   761
    copytree('.', TMPFOLDER, excludes=g_excludes, build_dir=build_dir)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   762
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   763
    # TODO undocumented hook
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   764
    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
   765
    if dist_hook:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   766
        os.chdir(TMPFOLDER)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   767
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   768
            dist_hook()
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   769
        finally:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   770
            # 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
   771
            os.chdir('..')
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   772
    return TMPFOLDER
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   773
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   774
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
   775
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   776
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   777
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   778
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   779
### Regression testing
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   780
class Regression(object):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   781
    def __init__(self, testdir):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   782
        self.testdir = testdir
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   783
        env = Params.g_build.env_of_name('default')
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   784
        self.diff = env['DIFF']
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   785
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   786
    def run_test(self, verbose, generate, refDirName, testName):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   787
        refTestDirName = os.path.join(refDirName, (testName + ".ref"))
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   788
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   789
        if not os.path.exists(refDirName):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   790
            print"No reference trace repository"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   791
            return 1
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   792
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   793
        if generate:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   794
            if not os.path.exists(refTestDirName):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   795
                print "creating new " + refTestDirName
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   796
                os.mkdir(refTestDirName)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   797
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   798
            Params.g_options.cwd_launch = refTestDirName
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   799
            run_program(testName)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   800
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   801
            print "Remember to commit " + refTestDirName
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   802
            return 0
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   803
        else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   804
            if not os.path.exists(refTestDirName):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   805
                print "Cannot locate reference traces"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   806
                return 1
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   807
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   808
            shutil.rmtree("traces");
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   809
            os.mkdir("traces")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   810
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   811
            #os.system("./waf --cwd regression/traces --run " +
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   812
            #  testName + " > /dev/null 2>&1")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   813
            Params.g_options.cwd_launch = "traces"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   814
            run_program(testName, command_template=get_command_template())
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   815
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   816
            if verbose:
2882
542f4d57464b Fix case of 'diff xxx | head' appearing to succeed even if the diff command returned non-zero exit statux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2881
diff changeset
   817
                #diffCmd = "diff traces " + refTestDirName + " | head"
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   818
                diffCmd = subprocess.Popen([self.diff, "traces", refTestDirName],
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
   819
                                           stderr=subprocess.PIPE, stdout=subprocess.PIPE)
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
   820
                headCmd = subprocess.Popen("head", stdin=diffCmd.stdout)
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
   821
                rc2 = headCmd.wait()
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
   822
                diffCmd.stdout.close()
2882
542f4d57464b Fix case of 'diff xxx | head' appearing to succeed even if the diff command returned non-zero exit statux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2881
diff changeset
   823
                rc1 = diffCmd.wait()
542f4d57464b Fix case of 'diff xxx | head' appearing to succeed even if the diff command returned non-zero exit statux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2881
diff changeset
   824
                rc = rc1 or rc2
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   825
            else:
3189
7ddf4ad61707 Check for the 'diff' command, don't allow running regression tests without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3178
diff changeset
   826
                diffCmd = self.diff +" traces " + refTestDirName + \
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   827
                    " > /dev/null 2>&1"
2882
542f4d57464b Fix case of 'diff xxx | head' appearing to succeed even if the diff command returned non-zero exit statux.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2881
diff changeset
   828
                rc = os.system(diffCmd)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   829
            if rc:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   830
                print "----------"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   831
                print "Traces differ in test: test-" + testName
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
   832
                print "Reference traces in directory: regression/" + refTestDirName
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   833
                print "Traces in directory: traces"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   834
                print "Rerun regression test as: " + \
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
   835
                    "\"./waf --regression --regression-tests=test-" + testName + "\""
3178
62e90655a935 make sure we output the right diff command
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3064
diff changeset
   836
                print "Then do \"diff -u regression/" + refTestDirName + " regression/traces" \
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   837
                    "\" for details"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   838
                print "----------"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   839
            return rc
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   840
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   841
def _find_tests(testdir):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   842
    """Return a list of test modules in the test directory
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   843
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   844
    Arguments:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   845
    testdir -- the directory to look in for tests
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   846
    """
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   847
    names = os.listdir(testdir)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   848
    tests = []
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   849
    for name in names:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   850
        if name[:5] == "test-" and name[-3:] == ".py":
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   851
            testname = name[:-3]
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   852
            tests.append(testname)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   853
    tests.sort()
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   854
    return tests
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   855
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   856
def run_regression():
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   857
    """Execute regression tests."""
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   858
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   859
    testdir = "tests"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   860
    if not os.path.exists(testdir):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   861
        print "Tests directory does not exist"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   862
        sys.exit(3)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   863
    
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   864
    sys.path.append(testdir)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   865
    sys.modules['tracediff'] = Regression(testdir)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   866
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   867
    if Params.g_options.regression_tests:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   868
        tests = Params.g_options.regression_tests.split(',')
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   869
    else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   870
        tests = _find_tests(testdir)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   871
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   872
    print "========== Running Regression Tests =========="
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   873
    dir_name = APPNAME + '-' + VERSION + REGRESSION_SUFFIX
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   874
3287
da71d4c1859f print out which repo is used for regression
Craig Dowell <craigdo@ee.washington.edu>
parents: 3286
diff changeset
   875
    if os.system("hg version > /dev/null 2>&1") == 0:
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   876
        print "Synchronizing reference traces using Mercurial."
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   877
        if not os.path.exists(dir_name):
3293
97c8fa9fa536 same messages for all versions of getting traces
craigdo@craig-dowells-imac.local
parents: 3289
diff changeset
   878
            print "Cloning " + REGRESSION_TRACES_REPO + dir_name + " from repo."
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   879
            os.system("hg clone " + REGRESSION_TRACES_REPO + dir_name + " > /dev/null 2>&1")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   880
        else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   881
            _dir = os.getcwd()
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   882
            os.chdir(dir_name)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   883
            try:
3293
97c8fa9fa536 same messages for all versions of getting traces
craigdo@craig-dowells-imac.local
parents: 3289
diff changeset
   884
                print "Pulling " + REGRESSION_TRACES_REPO + dir_name + " from repo."
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   885
                result = os.system("hg -q pull %s && hg -q update" % (REGRESSION_TRACES_REPO + dir_name))
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   886
            finally:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   887
                os.chdir("..")
2990
69ddc1c42130 Missing hg update when 'Synchronizing reference traces using Mercurial'
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2910
diff changeset
   888
            if result:
69ddc1c42130 Missing hg update when 'Synchronizing reference traces using Mercurial'
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2910
diff changeset
   889
                Params.fatal("Synchronizing reference traces using Mercurial failed.")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   890
    else:
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   891
        traceball = dir_name + TRACEBALL_SUFFIX
3293
97c8fa9fa536 same messages for all versions of getting traces
craigdo@craig-dowells-imac.local
parents: 3289
diff changeset
   892
        print "Retrieving " + traceball + " from web."
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   893
        urllib.urlretrieve(REGRESSION_TRACES_URL + traceball, traceball)
3289
bd7baccf47a3 tweaks after actually doing it
Craig Dowell <craigdo@ee.washington.edu>
parents: 3287
diff changeset
   894
        os.system("tar -xjf %s -C .." % (traceball))
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   895
    print "Done."
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   896
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   897
    if not os.path.exists(dir_name):
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   898
        print "Reference traces directory does not exist"
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   899
        return 3
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   900
    
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   901
    bad = []
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   902
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   903
    for test in tests:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   904
        result = _run_regression_test(test)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   905
        if result == 0:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   906
            if Params.g_options.regression_generate:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   907
                print "GENERATE " + test
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   908
            else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   909
                print "PASS " + test
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   910
        else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   911
            bad.append(test)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   912
            print "FAIL " + test
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   913
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   914
    return len(bad) > 0
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   915
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   916
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   917
def _run_regression_test(test):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   918
    """Run a single test.
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   919
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   920
    Arguments:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   921
    test -- the name of the test
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   922
    """
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   923
    if os.path.exists("traces"):
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   924
        files = os.listdir("traces")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   925
        for file in files:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   926
            if file == '.' or file == '..':
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   927
                continue
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   928
            path = "traces" + os.sep + file
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   929
            os.remove(path)
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   930
    else:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   931
        os.mkdir("traces")
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   932
    
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   933
    dir_name = APPNAME + '-' + VERSION + REGRESSION_SUFFIX
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   934
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   935
    mod = __import__(test, globals(), locals(), [])
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   936
    return mod.run(verbose=(Params.g_options.verbose > 0),
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   937
                   generate=Params.g_options.regression_generate,
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
   938
                   refDirName=dir_name)