wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sat, 17 Jan 2009 16:57:42 +0000
changeset 4103 a7dfdc073085
parent 4101 ca51ffa0d02b
child 4108 92bae583f934
permissions -rw-r--r--
Remove no longer needed WAF command execution win32 workaround
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
     2
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
     3
# python lib modules
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
     4
import sys
695
90a68c1c4328 WAF: add a dist_hook function to exclude the generated documentation from waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 694
diff changeset
     5
import shutil
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     6
import types
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     7
import optparse
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
     8
import os.path
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     9
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    10
# WAF modules
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2990
diff changeset
    11
import pproc as subprocess
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    12
import Options
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    13
import Logs
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    14
import TaskGen
4076
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    15
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
    16
import ccroot
4076
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    17
ccroot.USE_TOP_LEVEL = True
1c67ab5f959a Upgrade WAF; fix Darwin (OSX) build problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4075
diff changeset
    18
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
    19
import Task
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    20
import Utils
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    21
import Build
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    22
import Configure
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    23
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    24
import cflags # override the build profiles from waf
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    25
cflags.profiles = {
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    26
	# profile name: [optimization_level, warnings_level, debug_level]
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    27
	'debug':     [0, 2, 3],
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    28
	'optimized': [3, 2, 1],
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    29
	}
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    30
cflags.default_profile = 'debug'
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    31
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    32
# local modules
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    33
import wutils
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    34
import regression
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    35
4070
c2ad9c39fa06 Correct way to enable WAF autoconfigure
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4069
diff changeset
    36
Configure.autoconfig = 1
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    37
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    38
# the following two variables are used by the target "waf dist"
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    39
VERSION = file("VERSION", "rt").read().strip()
694
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    40
APPNAME = 'ns'
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    41
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    42
wutils.VERSION = VERSION
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    43
wutils.APPNAME = APPNAME
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    44
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    45
# 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
    46
srcdir = '.'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    47
blddir = 'build'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    48
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
    49
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
    50
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
    51
    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
    52
    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
    53
    shutil.rmtree("doc/latex", True)
3627
672f2a6de8b4 Exclude any possible 'nsc' folder from the dist tarball (nsc is ~= 100MB).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3625
diff changeset
    54
    shutil.rmtree("nsc", True)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    55
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    56
    ## 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
    57
    ## ns-3-dev-ref-traces
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    58
    traces_name = APPNAME + '-' + VERSION + regression.REGRESSION_SUFFIX
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    59
    ## Create a tar.bz2 file with the traces
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    60
    traces_dir = os.path.join(regression.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
    61
    if not os.path.isdir(traces_dir):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
    62
        Logs.warn("Not creating traces archive: the %s directory does not exist" % traces_dir)
2886
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    63
    else:
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
    64
        traceball = traces_name + wutils.TRACEBALL_SUFFIX
3284
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    65
        tar = tarfile.open(os.path.join("..", traceball), 'w:bz2')
510fed881852 fixes for regression numbering
Craig Dowell <craigdo@ee.washington.edu>
parents: 3282
diff changeset
    66
        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
    67
        tar.close()
8226157800a8 Create regression traces tarball automatically on waf dist.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2884
diff changeset
    68
        ## 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
    69
        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
    70
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    71
def set_options(opt):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    72
    # 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
    73
    opt.tool_options('compiler_cxx')
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    74
    opt.tool_options('cflags')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    75
2846
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
    76
    opt.add_option('--cwd',
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
    77
                   help=('Set the working directory for a program.'),
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
    78
                   action="store", type="string", default=None,
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
    79
                   dest='cwd_launch')
7689461231ac start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2622
diff changeset
    80
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    81
    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
    82
                   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
    83
                         ' 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
    84
                         'with the configure command.'),
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    85
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    86
                   dest='enable_gcov')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    87
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
    88
    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
    89
                   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
    90
                         "  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
    91
                         " 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
    92
                   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
    93
                   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
    94
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    95
    opt.add_option('--lcov-report',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    96
                   help=('Generate a code coverage report '
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    97
                         '(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
    98
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    99
                   dest='lcov_report')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   100
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   101
    opt.add_option('--doxygen',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   102
                   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
   103
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   104
                   dest='doxygen')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   105
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
   106
    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
   107
                   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
   108
                         ' 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
   109
                   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
   110
    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
   111
                   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
   112
                         ' 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
   113
                         ' 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
   114
                   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
   115
    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
   116
                   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
   117
                         ' 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
   118
                         ' 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
   119
                   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
   120
    opt.add_option('--valgrind',
d841cca00990 Add a --valgrind WAF option (bug #124)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2178
diff changeset
   121
                   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
   122
                   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
   123
                   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
   124
    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
   125
                   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
   126
                   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
   127
                   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
   128
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   129
    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
   130
                   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
   131
                   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
   132
    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
   133
                   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
   134
                   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
   135
    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
   136
                   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
   137
                         '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
   138
                   dest='regression_tests', type="string")
3834
debf281cc42b reverse sense of waf sudo flag to --enable-sudo
Craig Dowell <craigdo@ee.washington.edu>
parents: 3826
diff changeset
   139
    opt.add_option('--enable-sudo',
debf281cc42b reverse sense of waf sudo flag to --enable-sudo
Craig Dowell <craigdo@ee.washington.edu>
parents: 3826
diff changeset
   140
                   help=('Use sudo to setup suid bits on ns3 executables.'),
debf281cc42b reverse sense of waf sudo flag to --enable-sudo
Craig Dowell <craigdo@ee.washington.edu>
parents: 3826
diff changeset
   141
                   dest='enable_sudo', action='store_true',
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   142
                   default=False)
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   143
    opt.add_option('--with-regression-traces',
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   144
                   help=('Path to the regression reference traces directory'),
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   145
                   default=None,
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   146
                   dest='regression_traces', type="string")
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   147
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   148
    # 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
   149
    opt.sub_options('src')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   150
    opt.sub_options('bindings/python')
3628
a9c05c7e54f2 Move all NSC related build code into src/internet-stack, to unclutter a bit the main wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3627
diff changeset
   151
    opt.sub_options('src/internet-stack')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   152
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   153
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
   154
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
   155
    """
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
   156
    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
   157
    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
   158
    """
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
   159
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   160
    env = conf.env.copy()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   161
    env.append_value('CXXFLAGS', flag)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   162
    try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   163
        retval = conf.run_c_code(code='#include <stdio.h>\nint main() { return 0; }\n',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   164
                                 env=env, compile_filename='test.cc',
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   165
                                 compile_mode='cxx',type='program', execute=False)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   166
    except Configure.ConfigurationError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   167
        ok = False
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   168
    else:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   169
        ok = (retval == 0)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   170
    conf.check_message_custom(flag, 'support', (ok and 'yes' or 'no'))
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   171
    return ok
3407
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   172
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
   173
    
3625
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   174
def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled):
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   175
    conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled))
3407
038f13c8741c Check that the compiler accepts -Wno-error=deprecated-declarations before using it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3406
diff changeset
   176
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   177
def configure(conf):
3625
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   178
    # attach some extra methods
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   179
    conf.check_compilation_flag = types.MethodType(check_compilation_flag, conf)
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   180
    conf.report_optional_feature = types.MethodType(report_optional_feature, conf)
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   181
    conf.env['NS3_OPTIONAL_FEATURES'] = []
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   182
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   183
    conf.env['NS3_BUILDDIR'] = conf.blddir
1531
ebd805503b55 WAF: update to WAF trunk to get bug fixes and smaller script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1506
diff changeset
   184
    conf.check_tool('compiler_cxx')
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   185
    conf.check_tool('cflags')
4075
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   186
    try:
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   187
        conf.check_tool('pkgconfig')
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   188
    except Configure.ConfigurationError:
bc8a646b1338 Gracefully ignore missing pkg-config
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4070
diff changeset
   189
        pass
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   190
    conf.check_tool('command')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   191
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   192
    # 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
   193
    variant_env = conf.env.copy()
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   194
    variant_name = Options.options.build_profile
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
   195
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   196
    if Options.options.regression_traces is not None:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   197
        variant_env['REGRESSION_TRACES'] = os.path.join("..", Options.options.regression_traces)
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   198
    else:
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   199
        variant_env['REGRESSION_TRACES'] = None
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   200
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   201
    if Options.options.enable_gcov:
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   202
        variant_name += '-gcov'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   203
        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
   204
        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
   205
        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
   206
        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
   207
        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
   208
    
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   209
    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
   210
    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
   211
    variant_env.set_variant(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   212
    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
   213
    conf.setenv(variant_name)
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   214
    env = variant_env
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   215
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   216
    env.append_value('CXXDEFINES', 'RUN_SELF_TESTS')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   217
    
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   218
    if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ:
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   219
        if check_compilation_flag(conf, '-Wno-error=deprecated-declarations'):
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   220
            env.append_value('CXXFLAGS', '-Wno-error=deprecated-declarations')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   221
        
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   222
    if Options.options.build_profile == 'debug':
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   223
        env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   224
        env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
1426
30b9f2b59a1c WAF: in optimized builds, replace -O2 with -O3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1425
diff changeset
   225
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
   226
    if sys.platform == 'win32':
4069
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   227
        if env['COMPILER_CXX'] == 'g++':
430a6edb0fa0 New WAF cflags tool, to add back the compilation flags (debug/optimized)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   228
            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
   229
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   230
    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
   231
    conf.sub_config('utils')
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   232
    conf.sub_config('bindings/python')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   233
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   234
    if Options.options.enable_modules:
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   235
        conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   236
                                           Options.options.enable_modules.split(',')]
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   237
3677
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   238
    # we cannot run regression tests without diff
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
   239
    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
   240
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   241
    # for suid bits
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   242
    conf.find_program('sudo', var='SUDO')
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   243
3677
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   244
    # we cannot pull regression traces without mercurial
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   245
    conf.find_program('hg', var='MERCURIAL')
33334b53632f Check for mercurial in configuration stage; also fixes OSError exception when mercurial was not available.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3676
diff changeset
   246
3625
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   247
    # Write a summary of optional features status
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   248
    print "---- Summary of optional NS-3 features:"
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   249
    for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   250
        if was_enabled:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   251
            status = 'enabled'
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   252
        else:
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   253
            status = 'not enabled (%s)' % reason_not_enabled
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   254
        print "%-30s: %s" % (caption, status)
30afad8324d5 Add a summary of optional features at the end of the configuration stage.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3623
diff changeset
   255
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   256
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   257
class SuidBuildTask(Task.TaskBase):
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   258
    """task that makes a binary Suid
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   259
    """
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   260
    after = 'link'
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   261
    def __init__(self, bld, program):
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   262
        self.m_display = 'build-suid'
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   263
        self.__program = program
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   264
        self.__env = bld.env ()
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   265
        super(SuidBuildTask, self).__init__()
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   266
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   267
    def run(self):
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   268
        try:
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   269
            program_obj = wutils.find_program(self.__program.target, self.__env)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   270
        except ValueError, ex:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   271
            raise Utils.WafError(str(ex))
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   272
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   273
        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   274
        #try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   275
        #    program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   276
        #except AttributeError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   277
        #    raise Utils.WafError("%s does not appear to be a program" % (self.__program.name,))
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   278
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   279
        filename = program_node.abspath(self.__env)
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   280
        os.system ('sudo chown root ' + filename)
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   281
        os.system ('sudo chmod u+s ' + filename)
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   282
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   283
def create_suid_program(bld, name):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   284
    program = bld.new_task_gen('cxx', 'program')
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   285
    program.is_ns3_program = True
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   286
    program.module_deps = list()
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   287
    program.name = name
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   288
    program.target = name
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   289
    if bld.env['SUDO'] and Options.options.enable_sudo:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   290
        SuidBuildTask(bld, program)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   291
    return program
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   292
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
   293
def create_ns3_program(bld, name, dependencies=('simulator',)):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   294
    program = bld.new_task_gen('cxx', 'program')
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2990
diff changeset
   295
    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
   296
    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
   297
    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
   298
    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
   299
    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
   300
    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
   301
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   302
def add_scratch_programs(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   303
    all_modules = [mod[len("ns3-"):] for mod in bld.env['NS3_MODULES']]
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   304
    for filename in os.listdir("scratch"):
3867
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   305
        if filename.startswith('.') or filename == 'CVS':
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   306
	    continue
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   307
        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
   308
            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
   309
            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
   310
            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
   311
            obj.target = os.path.join(filename, filename)
3927
a2a992900b0b Make sure obj.name == obj.target for 'scratch' programs; fixes issue reported in ns-3-users with ./waf --run scratch/simple not working.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3919
diff changeset
   312
            obj.name = obj.target
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   313
        elif filename.endswith(".cc"):
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   314
            name = filename[:-len(".cc")]
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   315
            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
   316
            obj.source = "scratch/%s" % filename
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   317
            obj.target = "scratch/%s" % name
3927
a2a992900b0b Make sure obj.name == obj.target for 'scratch' programs; fixes issue reported in ns-3-users with ./waf --run scratch/simple not working.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3919
diff changeset
   318
            obj.name = obj.target
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   319
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
   320
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   321
def build(bld):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   322
    if Options.options.no_task_lines:
2866
1d829915f092 Add a --no-task-lines WAF option; together with -v it makes WAF just print executed commands, like 'make' does.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2846
diff changeset
   323
        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
   324
        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
   325
            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
   326
        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
   327
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   328
    Options.cwd_launch = bld.path.abspath()
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1213
diff changeset
   329
    bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
3826
40c5841b616d merge in tap device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3703
diff changeset
   330
    bld.create_suid_program = types.MethodType(create_suid_program, bld)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   331
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   332
    # switch default variant to the one matching our debug level
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   333
    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
   334
    variant_env = bld.env_of_name(variant_name)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   335
    bld.all_envs['default'] = variant_env
762
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   336
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   337
    if Options.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
   338
        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
   339
        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
   340
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   341
    if Options.options.doxygen:
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
   342
        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
   343
        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
   344
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
   345
    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
   346
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   347
    if Options.options.doxygen:
1717
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   348
        doxygen()
61831be6aede WAF: handle the option --doxygen before building the entire project.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 935
diff changeset
   349
        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
   350
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   351
    print "Entering directory `%s'" % os.path.join(bld.path.abspath(), 'build')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   352
    # process subfolders from here
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   353
    bld.add_subdirs('src')
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents: 3293
diff changeset
   354
    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
   355
3275
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   356
    add_scratch_programs(bld)
b0d91237f2ec [Bug 221] need a scratch directory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3189
diff changeset
   357
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
   358
    ## 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
   359
    ## 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
   360
    ## disabled modules.
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   361
    env = bld.env
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   362
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   363
    if Options.options.enable_modules:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   364
        Logs.warn("the option --enable-modules is being applied to this build only;"
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   365
                       " 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
   366
        env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   367
                                      Options.options.enable_modules.split(',')]
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   368
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
    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
   370
        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
   371
        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
   372
        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
   373
            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
   374
            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
   375
                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
   376
                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
   377
                    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
   378
                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
   379
                    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
   380
                        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
   381
                    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
   382
                        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
   383
                        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
   384
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
        ## remove objects that depend on modules not listed
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   386
        for obj in list(Build.bld.all_task_gen):
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   387
            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
   388
                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
   389
                    if dep not in modules:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   390
                        Build.bld.all_task_gen.remove(obj)
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   391
                        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
   392
            if obj.name in env['NS3_MODULES'] and obj.name not in modules:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   393
                Build.bld.all_task_gen.remove(obj)
1880
0148d5911946 New waf snapshot; move the ns3 library back to the top build dir (the 'lib' was only a workaround for a waf problem); allow --enable-modules on a per build run basis.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   394
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
    ## Create a single ns3 library containing all enabled modules
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   396
    lib = bld.new_task_gen('cxx', 'shlib')
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
   397
    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
   398
    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
   399
    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
   400
        lib.add_objects = list(modules)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   401
        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
   402
        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
   403
    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
   404
        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
   405
        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
   406
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   407
    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
   408
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   409
    if Options.options.run:
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   410
        # Check that the requested program name is valid
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   411
        program_name, dummy_program_argv = wutils.get_run_program(Options.options.run, get_command_template())
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3927
diff changeset
   412
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   413
        # When --run'ing a program, tell WAF to only build that program,
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   414
        # nothing more; this greatly speeds up compilation when all you
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   415
        # want to do is run a test program.
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   416
        if not Options.options.compile_targets:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   417
            Options.options.compile_targets = program_name
3919
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   418
fd796ed5b166 Post-fix the last patch, to make sure invalid program names passed into --run trigger an informative error message as before.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3918
diff changeset
   419
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3429
diff changeset
   420
3623
5209cecd2ade bug 312: ./waf check fails.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3618
diff changeset
   421
def get_command_template(*arguments):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   422
    if Options.options.valgrind:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   423
        if Options.options.command_template:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   424
            raise Utils.WafError("Options --command-template and --valgrind are conflicting")
3617
1fec65ceb523 add wifi+wired bridge example
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3579
diff changeset
   425
        cmd = "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
   426
    else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   427
        cmd = Options.options.command_template or '%s'
3617
1fec65ceb523 add wifi+wired bridge example
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3579
diff changeset
   428
    for arg in arguments:
1fec65ceb523 add wifi+wired bridge example
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3579
diff changeset
   429
        cmd = cmd + " " + arg
1fec65ceb523 add wifi+wired bridge example
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3579
diff changeset
   430
    return cmd
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   431
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
   432
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   433
def shutdown():
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   434
    env = Build.bld.env
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   435
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   436
    if Options.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
   437
        _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
   438
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   439
    if Options.options.regression or Options.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
   440
        if not env['DIFF']:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   441
            raise Utils.WafError("Cannot run regression tests: the 'diff' program is not installed.")
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   442
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   443
        _dir = os.getcwd()
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   444
        os.chdir("regression")
3872
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   445
        regression_traces = env['REGRESSION_TRACES']
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   446
        if not regression_traces:
8e757a83fb36 Add a --with-regression-traces configure option, to allow using externally supplied regression traces instead of fetching them from the network.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3867
diff changeset
   447
            regression_traces = None
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   448
        try:
4029
4267fd454004 gustavo's retcode patch for regression
gjc@inescporto.pt
parents: 3933
diff changeset
   449
            retval = regression.run_regression(regression_traces)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   450
        finally:
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   451
            os.chdir(_dir)
4029
4267fd454004 gustavo's retcode patch for regression
gjc@inescporto.pt
parents: 3933
diff changeset
   452
        if retval:
4267fd454004 gustavo's retcode patch for regression
gjc@inescporto.pt
parents: 3933
diff changeset
   453
            sys.exit(retval)
2881
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   454
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   455
    if Options.options.lcov_report:
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   456
        lcov_report()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   457
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   458
    if Options.options.run:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   459
        wutils.run_program(Options.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
   460
        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
   461
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   462
    if Options.options.pyrun:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   463
        wutils.run_python_program(Options.options.pyrun)
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
   464
        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
   465
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
   466
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
   467
    ## generate the trace sources list docs
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   468
    env = Build.bld.env
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   469
    proc_env = wutils.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
   470
    try:
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   471
        program_obj = wutils.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
   472
    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
   473
                       # 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
   474
                       # --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
   475
        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
   476
    else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   477
        prog = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj)).abspath(env)
3665
31e3bf84da41 Use subprocess.Popen instead of os.system to improve portability of the regression testing framework
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3628
diff changeset
   478
        out = open(os.path.join('doc', 'introspected-doxygen.h'), 'w')
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
   479
        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
   480
            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
   481
        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
   482
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   483
    print "-- Running NS-3 C++ core unit tests..."
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   484
    wutils.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
   485
3429
2658cf81a5cd Don't run python unit tests if python bindings not enabled. Closes #254.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3419
diff changeset
   486
    if env['ENABLE_PYTHON_BINDINGS']:
2658cf81a5cd Don't run python unit tests if python bindings not enabled. Closes #254.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3419
diff changeset
   487
        print "-- Running NS-3 Python bindings unit tests..."
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   488
        wutils.run_argv([env['PYTHON'], os.path.join("utils", "python-unit-tests.py")], proc_env)
3429
2658cf81a5cd Don't run python unit tests if python bindings not enabled. Closes #254.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3419
diff changeset
   489
    else:
2658cf81a5cd Don't run python unit tests if python bindings not enabled. Closes #254.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3419
diff changeset
   490
        print "-- Skipping NS-3 Python bindings unit tests: Python bindings not enabled."
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   491
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3331
diff changeset
   492
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
   493
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
   494
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
   495
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
   496
    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
   497
        return
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   498
    env = Build.bld.env
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   499
    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
   500
    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
   501
    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
   502
        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
   503
               "=========================================================\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
   504
               "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
   505
               "  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
   506
               "  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
   507
               "  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
   508
               "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
   509
               "  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
   510
               "  2. Run a new nested shell")
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   511
        raise Utils.WafError(msg)
1016
58a56b52a08b Detect when running waf --shell with stale environment variables and give an error when it happens.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1015
diff changeset
   512
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
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
   514
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
   515
    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
   516
        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
   517
    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
   518
        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
   519
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   520
    env = Build.bld.env
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3845
diff changeset
   521
    wutils.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
   522
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
   523
def doxygen():
1855
ee15fef0cb62 print-trace-sources.cc -> print-introspected-doxygen.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1804
diff changeset
   524
    if not os.path.exists('doc/introspected-doxygen.h'):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   525
        Logs.warn("doc/introspected-doxygen.h does not exist; run waf check to generate it.")
1536
23593050aa96 Run the program print-trace-sources to generate doc/trace-source-list.h when generating docs. As a side effect, --doxygen is now has to be processed at the end of the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1532
diff changeset
   526
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
   527
    ## 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
   528
    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
   529
    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
   530
        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
   531
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
   532
def lcov_report():
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   533
    env = Build.bld.env
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   534
    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
   535
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
   536
    if 'gcov' not in variant_name:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   537
        raise Utils.WafError("project not configured for code coverage;"
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   538
                     " 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
   539
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
   540
    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
   541
    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
   542
        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
   543
        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
   544
        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
   545
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
   546
        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
   547
            raise SystemExit(1)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   548
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
   549
        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
   550
        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
   551
        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
   552
        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
   553
            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
   554
        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
   555
            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
   556
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
   557
        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
   558
        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
   559
        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
   560
            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
   561
    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
   562
        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
   563
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   564
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   565
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   566
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   567
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   568
## 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
   569
## 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
   570
## 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
   571
## 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
   572
## implementation that is more efficient.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   573
##
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   574
import Scripting
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   575
from Scripting import dist_exts, excludes, BLDDIR
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   576
import Utils
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   577
import os
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   578
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   579
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
   580
    """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
   581
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   582
    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
   583
    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
   584
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   585
    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
   586
    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
   587
    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
   588
    links are copied.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   589
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   590
    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
   591
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   592
    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
   593
    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
   594
    another list of files.
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   595
    """
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   596
    names = os.listdir(src)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   597
    os.makedirs(dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   598
    errors = []
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   599
    for name in names:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   600
        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
   601
        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
   602
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   603
            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
   604
                linkto = os.readlink(srcname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   605
                os.symlink(linkto, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   606
            elif os.path.isdir(srcname):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   607
                if name in excludes:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   608
                    continue
3867
e29698e2e158 Bug 387: Build fails with junk subdirectories in "scratch" directory
Andrey Hippo <ahippo@yandex.ru>
parents: 3866
diff changeset
   609
                elif name.startswith('.') or name.startswith(',,') or name.startswith('++') or name.startswith('CVS'):
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   610
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   611
                elif name == build_dir:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   612
                    continue
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   613
                else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   614
                    ## 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
   615
                    ## 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
   616
                    ## 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
   617
                    copytree(srcname, dstname, symlinks, excludes)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   618
            else:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   619
                ends = name.endswith
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   620
                to_remove = False
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   621
                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
   622
                    to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   623
                else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   624
                    for x in dist_exts:
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   625
                        if ends(x):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   626
                            to_remove = True
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   627
                            break
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   628
                if not to_remove:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   629
                    shutil.copy2(srcname, dstname)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   630
            # 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
   631
        except (IOError, os.error), why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   632
            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
   633
        # 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
   634
        # continue with other files
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   635
        except shutil.Error, err:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   636
            errors.extend(err.args[0])
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   637
    try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   638
        shutil.copystat(src, dst)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   639
    except WindowsError:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   640
        # 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
   641
        pass
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   642
    except OSError, why:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   643
        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
   644
    if errors:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   645
        raise shutil.Error, errors
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   646
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   647
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   648
def DistDir(appname, version):
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   649
    "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
   650
    import shutil
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   651
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   652
    # 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
   653
    TMPFOLDER=appname+'-'+version
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   654
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   655
    # Remove an old package directory
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   656
    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
   657
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   658
    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
   659
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   660
    # Remove the Build dir
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   661
    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
   662
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   663
    # Copy everything into the new folder
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4029
diff changeset
   664
    copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir)
2622
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   665
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   666
    # TODO undocumented hook
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   667
    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
   668
    if dist_hook:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   669
        os.chdir(TMPFOLDER)
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   670
        try:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   671
            dist_hook()
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   672
        finally:
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   673
            # 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
   674
            os.chdir('..')
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   675
    return TMPFOLDER
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   676
6440851b111a Make waf dist much more efficient.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2345
diff changeset
   677
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
   678
81d1080cd0ae Integrate regression testing into the main waf script.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2866
diff changeset
   679