wutils.py
author Tom Henderson <tomh@tomh.org>
Thu, 30 Aug 2018 13:39:08 -0700
changeset 13764 ee1b8a17f63a
parent 11765 308891f0a6da
permissions -rw-r--r--
tcp: Update status of NSC TCP in manual
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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:
diff changeset
     1
import os
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:
diff changeset
     2
import os.path
9277
0f87d1cb030c Upgrade waf to 1.7.10 and fix included wscripts
Vedran Miletić <rivanvx@gmail.com>
parents: 7855
diff changeset
     3
import re
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:
diff changeset
     4
import sys
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
     5
import subprocess
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:
diff changeset
     6
import shlex
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
     7
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
     8
# WAF modules
9277
0f87d1cb030c Upgrade waf to 1.7.10 and fix included wscripts
Vedran Miletić <rivanvx@gmail.com>
parents: 7855
diff changeset
     9
from waflib import Options, Utils, Logs, TaskGen, Build, Context
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
    10
from waflib.Errors import WafError
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:
diff changeset
    11
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:
diff changeset
    12
# these are set from the main wscript file
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:
diff changeset
    13
APPNAME=None
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:
diff changeset
    14
VERSION=None
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
    15
bld=None
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    16
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:
diff changeset
    17
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:
diff changeset
    18
4119
9ffcf2400aa5 Bug #323: waf --valgrind doesn't check for valgrind first
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
    19
def get_command_template(env, arguments=()):
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
    20
    cmd = Options.options.command_template or '%s'
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:
diff changeset
    21
    for arg in arguments:
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:
diff changeset
    22
        cmd = cmd + " " + arg
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:
diff changeset
    23
    return cmd
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:
diff changeset
    24
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:
diff changeset
    25
4108
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    26
if hasattr(os.path, "relpath"):
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    27
    relpath = os.path.relpath # since Python 2.6
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    28
else:
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    29
    def relpath(path, start=os.path.curdir):
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    30
        """Return a relative version of a path"""
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    31
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    32
        if not path:
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    33
            raise ValueError("no path specified")
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    34
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    35
        start_list = os.path.abspath(start).split(os.path.sep)
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    36
        path_list = os.path.abspath(path).split(os.path.sep)
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    37
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    38
        # Work out how much of the filepath is shared by start and path.
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    39
        i = len(os.path.commonprefix([start_list, path_list]))
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    40
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    41
        rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    42
        if not rel_list:
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    43
            return os.path.curdir
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    44
        return os.path.join(*rel_list)
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    45
9277
0f87d1cb030c Upgrade waf to 1.7.10 and fix included wscripts
Vedran Miletić <rivanvx@gmail.com>
parents: 7855
diff changeset
    46
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:
diff changeset
    47
def find_program(program_name, env):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
    48
    launch_dir = os.path.abspath(Context.launch_dir)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
    49
    #top_dir = os.path.abspath(Options.cwd_launch)
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:
diff changeset
    50
    found_programs = []
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
    51
    for obj in bld.all_task_gen:
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:
diff changeset
    52
        if not getattr(obj, 'is_ns3_program', False):
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:
diff changeset
    53
            continue
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:
diff changeset
    54
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:
diff changeset
    55
        ## filter out programs not in the subtree starting at the launch dir
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:
diff changeset
    56
        if not (obj.path.abspath().startswith(launch_dir)
7855
015c4b6a0e07 Fix waf --run inside an example subdir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7705
diff changeset
    57
                or obj.path.get_bld().abspath().startswith(launch_dir)):
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:
diff changeset
    58
            continue
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:
diff changeset
    59
        
7684
35d52a4a96e9 Make sure waf --run name works with program names, regardless of any prefix/sufix applied for installation purposes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7538
diff changeset
    60
        name1 = obj.name
35d52a4a96e9 Make sure waf --run name works with program names, regardless of any prefix/sufix applied for installation purposes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7538
diff changeset
    61
        name2 = os.path.join(relpath(obj.path.abspath(), launch_dir), obj.name)
4108
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    62
        names = [name1, name2]
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    63
        found_programs.extend(names)
92bae583f934 waf --run now takes either full path to a program or just the (flat) program name, for all C++ programs
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
    64
        if program_name in names:
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:
diff changeset
    65
            return obj
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:
diff changeset
    66
    raise ValueError("program '%s' not found; available programs are: %r"
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:
diff changeset
    67
                     % (program_name, found_programs))
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:
diff changeset
    68
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:
diff changeset
    69
def get_proc_env(os_env=None):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
    70
    env = bld.env
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 10658
diff changeset
    71
    if sys.platform == 'linux2' or sys.platform == 'linux':
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:
diff changeset
    72
        pathvar = 'LD_LIBRARY_PATH'
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:
diff changeset
    73
    elif sys.platform == 'darwin':
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:
diff changeset
    74
        pathvar = 'DYLD_LIBRARY_PATH'
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:
diff changeset
    75
    elif sys.platform == 'win32':
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:
diff changeset
    76
        pathvar = 'PATH'
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:
diff changeset
    77
    elif sys.platform == 'cygwin':
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:
diff changeset
    78
        pathvar = 'PATH'
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:
diff changeset
    79
    elif sys.platform.startswith('freebsd'):
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:
diff changeset
    80
        pathvar = 'LD_LIBRARY_PATH'
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:
diff changeset
    81
    else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    82
        Logs.warn(("Don't know how to configure "
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:
diff changeset
    83
                        "dynamic library path for the platform %r;"
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:
diff changeset
    84
                        " assuming it's LD_LIBRARY_PATH.") % (sys.platform,))
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:
diff changeset
    85
        pathvar = 'LD_LIBRARY_PATH'        
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:
diff changeset
    86
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:
diff changeset
    87
    proc_env = dict(os.environ)
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:
diff changeset
    88
    if os_env is not None:
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:
diff changeset
    89
        proc_env.update(os_env)
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:
diff changeset
    90
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:
diff changeset
    91
    if pathvar is not None:
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:
diff changeset
    92
        if pathvar in proc_env:
11658
ea99cd3b169c temporarily rollback a Python 3 related change
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    93
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']) + [proc_env[pathvar]])
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:
diff changeset
    94
        else:
11658
ea99cd3b169c temporarily rollback a Python 3 related change
Tom Henderson <tomh@tomh.org>
parents: 11634
diff changeset
    95
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']))
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:
diff changeset
    96
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
    97
    pymoddir = bld.path.find_dir('bindings/python').get_bld().abspath()
6953
aa8081396a16 Bug 1081 - wutils.py refers to the old directory for visualizer module
ishan <ishan.chhabra@gmail.com>
parents: 6886
diff changeset
    98
    pyvizdir = bld.path.find_dir('src/visualizer').abspath()
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:
diff changeset
    99
    if 'PYTHONPATH' in proc_env:
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   100
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir, pyvizdir] + [proc_env['PYTHONPATH']])
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:
diff changeset
   101
    else:
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   102
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir, pyvizdir])
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:
diff changeset
   103
5975
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   104
    if 'PATH' in proc_env:
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   105
        proc_env['PATH'] = os.pathsep.join(list(env['NS3_EXECUTABLE_PATH']) + [proc_env['PATH']])
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   106
    else:
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   107
        proc_env['PATH'] = os.pathsep.join(list(env['NS3_EXECUTABLE_PATH']))
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   108
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:
diff changeset
   109
    return proc_env
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:
diff changeset
   110
4388
fd90dd412e67 Force valgrind to not be used for Python tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4332
diff changeset
   111
def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
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:
diff changeset
   112
    proc_env = get_proc_env(os_env)
4388
fd90dd412e67 Force valgrind to not be used for Python tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4332
diff changeset
   113
    if Options.options.valgrind and not force_no_valgrind:
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   114
        if Options.options.command_template:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   115
            raise WafError("Options --command-template and --valgrind are conflicting")
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   116
        if not env['VALGRIND']:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   117
            raise WafError("valgrind is not installed")
11765
308891f0a6da fix broken waf --valgrind argument; also make compatible with Python 3
Tom Henderson <tomh@tomh.org>
parents: 11658
diff changeset
   118
        # Use the first program found in the env['VALGRIND'] list
308891f0a6da fix broken waf --valgrind argument; also make compatible with Python 3
Tom Henderson <tomh@tomh.org>
parents: 11658
diff changeset
   119
        argv = [env['VALGRIND'][0], "--leak-check=full", "--show-reachable=yes", "--error-exitcode=1"] + argv
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   120
        proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE)
11765
308891f0a6da fix broken waf --valgrind argument; also make compatible with Python 3
Tom Henderson <tomh@tomh.org>
parents: 11658
diff changeset
   121
        stderrdata = proc.communicate()[1]
308891f0a6da fix broken waf --valgrind argument; also make compatible with Python 3
Tom Henderson <tomh@tomh.org>
parents: 11658
diff changeset
   122
        stderrdata = stderrdata.decode('utf-8')
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   123
        error = False
11765
308891f0a6da fix broken waf --valgrind argument; also make compatible with Python 3
Tom Henderson <tomh@tomh.org>
parents: 11658
diff changeset
   124
        for line in stderrdata:
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   125
            sys.stderr.write(line)
5917
aa8364846523 Bug 792: Neither test.py nor waf --valgrind catch all kinds of memory leaks
Craig Dowell <craigdo@ee.washington.edu>
parents: 4584
diff changeset
   126
            if "== LEAK SUMMARY" in line:
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   127
                error = True
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   128
        retval = proc.wait()
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   129
        if retval == 0 and error:
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   130
            retval = 1
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   131
    else:
4583
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   132
        try:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   133
            WindowsError
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   134
        except NameError:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   135
            retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   136
        else:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   137
            try:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   138
                retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 10658
diff changeset
   139
            except WindowsError as ex:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   140
                raise WafError("Command %s raised exception %s" % (argv, ex))
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:
diff changeset
   141
    if retval:
6275
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   142
        signame = None
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   143
        if retval < 0: # signal?
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   144
            import signal
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 10658
diff changeset
   145
            for name, val in vars(signal).items():
6275
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   146
                if len(name) > 3 and name[:3] == 'SIG' and name[3] != '_':
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   147
                    if val == -retval:
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   148
                        signame = name
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   149
                        break
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   150
        if signame:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   151
            raise WafError("Command %s terminated with signal %s."
6275
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   152
                                 " Run it under a debugger to get more information "
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   153
                                 "(./waf --run <program> --command-template=\"gdb --args %%s <args>\")." % (argv, signame))
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   154
        else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   155
            raise WafError("Command %s exited with code %i" % (argv, retval))
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:
diff changeset
   156
    return retval
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:
diff changeset
   157
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   158
def get_run_program(program_string, command_template=None):
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:
diff changeset
   159
    """
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   160
    Return the program name and argv of the process that would be executed by
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   161
    run_program(program_string, command_template).
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:
diff changeset
   162
    """
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   163
    #print "get_run_program_argv(program_string=%r, command_template=%r)" % (program_string, command_template)
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
   164
    env = 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:
diff changeset
   165
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:
diff changeset
   166
    if command_template in (None, '%s'):
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:
diff changeset
   167
        argv = shlex.split(program_string)
4584
7f4ee7f84b19 Fix win32/mingw bug running commands with command-template: needed to escape backslashes before calling shlex.split().
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4583
diff changeset
   168
        #print "%r ==shlex.split==> %r" % (program_string, argv)
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:
diff changeset
   169
        program_name = argv[0]
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:
diff changeset
   170
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:
diff changeset
   171
        try:
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:
diff changeset
   172
            program_obj = find_program(program_name, env)
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 10658
diff changeset
   173
        except ValueError as ex:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   174
            raise WafError(str(ex))
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:
diff changeset
   175
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   176
        program_node = program_obj.path.find_or_declare(program_obj.target)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   177
        #try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   178
        #    program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   179
        #except AttributeError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   180
        #    raise Utils.WafError("%s does not appear to be a program" % (program_name,))
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:
diff changeset
   181
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   182
        execvec = [program_node.abspath()] + argv[1:]
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:
diff changeset
   183
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:
diff changeset
   184
    else:
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:
diff changeset
   185
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:
diff changeset
   186
        program_name = program_string
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:
diff changeset
   187
        try:
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:
diff changeset
   188
            program_obj = find_program(program_name, env)
11634
99173c0ad09b port wscripts, test.py, and waf-tools to Python3
Siddharth Santurkar <siddharth.santurkar@ieee.org>
parents: 10658
diff changeset
   189
        except ValueError as ex:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   190
            raise WafError(str(ex))
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   191
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6953
diff changeset
   192
        program_node = program_obj.path.find_or_declare(program_obj.target)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   193
        #try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   194
        #    program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   195
        #except AttributeError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   196
        #    raise Utils.WafError("%s does not appear to be a program" % (program_name,))
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:
diff changeset
   197
7535
2024597e0ad8 Bug 1266 - gdb cannot be loaded
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7510
diff changeset
   198
        tmpl = command_template % (program_node.abspath(),)
4584
7f4ee7f84b19 Fix win32/mingw bug running commands with command-template: needed to escape backslashes before calling shlex.split().
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4583
diff changeset
   199
        execvec = shlex.split(tmpl.replace('\\', '\\\\'))
7f4ee7f84b19 Fix win32/mingw bug running commands with command-template: needed to escape backslashes before calling shlex.split().
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4583
diff changeset
   200
        #print "%r ==shlex.split==> %r" % (command_template % (program_node.abspath(env),), execvec)
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   201
    return program_name, execvec
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:
diff changeset
   202
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   203
def run_program(program_string, env, command_template=None, cwd=None, visualize=False):
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   204
    """
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   205
    if command_template is not None, then program_string == program
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   206
    name and argv is given by command_template with %s replaced by the
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   207
    full path to the program.  Else, program_string is interpreted as
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   208
    a shell command with first name being the program name.
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   209
    """
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   210
    dummy_program_name, execvec = get_run_program(program_string, command_template)
4110
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   211
    if cwd is None:
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   212
        if (Options.options.cwd_launch):
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   213
            cwd = Options.options.cwd_launch
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   214
        else:
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   215
            cwd = Options.cwd_launch
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   216
    if visualize:
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   217
        execvec.append("--SimulatorImplementationType=ns3::VisualSimulatorImpl")
4332
a1c7bc503a0c Detect valgrind memory leak reports; based on patch by Mathieu Lacage; closes bug #532
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4326
diff changeset
   218
    return run_argv(execvec, env, cwd=cwd)
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:
diff changeset
   219
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:
diff changeset
   220
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:
diff changeset
   221
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   222
def run_python_program(program_string, env, visualize=False):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
   223
    env = 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:
diff changeset
   224
    execvec = shlex.split(program_string)
4137
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   225
    if (Options.options.cwd_launch):
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   226
        cwd = Options.options.cwd_launch
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   227
    else:
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   228
        cwd = Options.cwd_launch
6676
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   229
    if visualize:
8a57344a8d09 Codereview Issue 2692041: Add pyviz module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6624
diff changeset
   230
        execvec.append("--SimulatorImplementationType=ns3::VisualSimulatorImpl")
7510
aabd5141cd16 Fix waf check
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   231
    return run_argv([env['PYTHON'][0]] + execvec, env, cwd=cwd)
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:
diff changeset
   232
7538
e4f691d808b1 Patch the WAF task runner to fix performance, until the issue is fixed upstream.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7535
diff changeset
   233
10658
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   234
def uniquify_list(seq):
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   235
    """Remove duplicates while preserving order
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   236
       From Dave Kirby http://www.peterbe.com/plog/uniqifiers-benchmark
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   237
    """
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   238
    seen = set()
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   239
    return [ x for x in seq if x not in seen and not seen.add(x)]
2a407999964e bug 1869: append local build directory before recursing into modules
Tom Henderson <tomh@tomh.org>
parents: 9277
diff changeset
   240