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