wutils.py
author Tom Henderson <tomh@tomh.org>
Fri, 20 Aug 2010 12:17:19 -0700
changeset 6589 9c325569fb01
parent 6275 77f833c7ddae
permissions -rw-r--r--
Help waf to guess release versions of nsc and pybindgen
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
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
     3
import sys
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 pproc as subprocess
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
     5
import shlex
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
     6
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
     7
# WAF modules
3866
9e946fee902c Refactor wscript code to move regression testing code to a separate python module (bug 325)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
import ccroot
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
     9
import Options
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    10
import Utils
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    11
import Logs
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    12
import TaskGen
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    13
import Build
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
    14
import re
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    15
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
    16
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
# 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
    18
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
    19
VERSION=None
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
    20
bld=None
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    21
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
    22
#
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
# The last part of the path name to use to find the regression traces tarball.
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
# path will be APPNAME + '-' + VERSION + REGRESSION_SUFFIX + TRACEBALL_SUFFIX,
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
# e.g., ns-3-dev-ref-traces.tar.bz2
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
    26
#
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
    27
TRACEBALL_SUFFIX = ".tar.bz2"
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
    28
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
    29
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
    30
4119
9ffcf2400aa5 Bug #323: waf --valgrind doesn't check for valgrind first
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4110
diff changeset
    31
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
    32
    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
    33
    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
    34
        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
    35
    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
    36
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
    37
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
    38
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
    39
    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
    40
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
    41
    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
    42
        """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
    43
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
        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
    45
            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
    46
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
    47
        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
    48
        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
    49
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
    50
        # 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
    51
        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
    52
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
    53
        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
    54
        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
    55
            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
    56
        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
    57
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
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
def find_program(program_name, env):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    60
    launch_dir = os.path.abspath(Options.cwd_launch)
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
    61
    top_dir = os.path.abspath(Options.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
    62
    found_programs = []
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
    63
    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
    64
        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
    65
            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
    66
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
        ## 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
    68
        if not (obj.path.abspath().startswith(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
    69
                or obj.path.abspath(env).startswith(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
    70
            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
    71
        
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
    72
        name1 = obj.target
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
    73
        name2 = os.path.join(relpath(obj.path.abspath(), top_dir), obj.target)
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
    74
        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
    75
        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
    76
        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
    77
            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
    78
    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
    79
                     % (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
    80
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
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
    82
    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
    83
    if sys.platform == 'linux2':
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
        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
    85
    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
    86
        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
    87
    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
    88
        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
    89
    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
    90
        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
    91
    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
    92
        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
    93
    else:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
    94
        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
    95
                        "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
    96
                        " 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
    97
        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
    98
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
    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
   100
    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
   101
        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
   102
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
    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
   104
        if pathvar in 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
   105
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']) + [proc_env[pathvar]])
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
   106
        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
   107
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_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
   108
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
   109
    pymoddir = bld.path.find_dir('bindings/python').abspath(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
   110
    if 'PYTHONPATH' in 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
   111
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir] + [proc_env['PYTHONPATH']])
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
    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
   113
        proc_env['PYTHONPATH'] = pymoddir
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
   114
5975
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   115
    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
   116
        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
   117
    else:
c85cb9b073a0 comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents: 5917
diff changeset
   118
        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
   119
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
   120
    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
   121
4388
fd90dd412e67 Force valgrind to not be used for Python tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4332
diff changeset
   122
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
   123
    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
   124
    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
   125
        if Options.options.command_template:
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
   126
            raise Utils.WafError("Options --command-template and --valgrind are conflicting")
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
        if not env['VALGRIND']:
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
            raise Utils.WafError("valgrind is not installed")
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
   129
        argv = [env['VALGRIND'], "--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
   130
        proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE)
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
        error = False
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
   132
        for line in proc.stderr:
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
   133
            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
   134
            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
   135
                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
   136
        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
   137
        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
   138
            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
   139
    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
   140
        try:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   141
            WindowsError
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   142
        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
   143
            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
   144
        else:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   145
            try:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   146
                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
   147
            except WindowsError, ex:
384117906219 Handle WindowsError exception in subprocess.Popen called from _run_argv
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4388
diff changeset
   148
                raise Utils.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
   149
    if retval:
6275
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   150
        signame = None
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   151
        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
   152
            import signal
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   153
            for name, val in vars(signal).iteritems():
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   154
                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
   155
                    if val == -retval:
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   156
                        signame = name
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   157
                        break
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   158
        if signame:
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   159
            raise Utils.WafError("Command %s terminated with signal %s."
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   160
                                 " 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
   161
                                 "(./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
   162
        else:
77f833c7ddae Bug 894 - ./waf --run error message upon segfault
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5975
diff changeset
   163
            raise Utils.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
   164
    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
   165
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   166
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
   167
    """
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   168
    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
   169
    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
   170
    """
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   171
    #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
   172
    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
   173
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
   174
    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
   175
        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
   176
        #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
   177
        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
   178
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
   179
        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
   180
            program_obj = find_program(program_name, 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
   181
        except ValueError, ex:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   182
            raise Utils.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
   183
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   184
        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   185
        #try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   186
        #    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
   187
        #except AttributeError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   188
        #    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
   189
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
   190
        execvec = [program_node.abspath(env)] + argv[1:]
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
   191
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
   192
    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
   193
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
   194
        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
   195
        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
   196
            program_obj = find_program(program_name, 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
   197
        except ValueError, ex:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   198
            raise Utils.WafError(str(ex))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   199
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   200
        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   201
        #try:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   202
        #    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
   203
        #except AttributeError:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3933
diff changeset
   204
        #    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
   205
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
   206
        tmpl = command_template % (program_node.abspath(env),)
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
   207
        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
   208
        #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
   209
    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
   210
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
   211
def run_program(program_string, env, command_template=None, cwd=None):
3933
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   212
    """
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   213
    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
   214
    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
   215
    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
   216
    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
   217
    """
3c149230e98a Fix waf problem running programs with arguments.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3866
diff changeset
   218
    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
   219
    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
   220
        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
   221
            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
   222
        else:
04170734fa8b Don't abuse os.chdir so much (not thread safe)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4108
diff changeset
   223
            cwd = Options.cwd_launch
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
   224
    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
   225
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
   226
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
   227
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
   228
def run_python_program(program_string, env):
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4137
diff changeset
   229
    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
   230
    execvec = shlex.split(program_string)
4137
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   231
    if (Options.options.cwd_launch):
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   232
        cwd = Options.options.cwd_launch
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   233
    else:
c1303bd63eb5 Fix waf --pyrun bug
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4119
diff changeset
   234
        cwd = Options.cwd_launch
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
   235
    return run_argv([env['PYTHON']] + 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
   236
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
   237