wutils.py
author Hajime Tazaki <tazaki@sfc.wide.ad.jp>
Mon, 01 Jun 2015 14:24:27 +0900
changeset 669 cb779a3844be
parent 589 f8acac37468f
child 681 6393a7dbdec0
permissions -rw-r--r--
Bug 2101 - When loading binary not compiled with the correct options, dce crashes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     1
import os
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     2
import os.path
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     3
import sys
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     4
import subprocess
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     5
import shlex
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     6
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     7
# WAF modules
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     8
import Options
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
     9
import Utils
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    10
import Logs
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    11
import TaskGen
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    12
import Build
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    13
import re
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    14
from waflib.Errors import WafError
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    15
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    16
# these are set from the main wscript file
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    17
APPNAME=None
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    18
VERSION=None
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    19
bld=None
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    20
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    21
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    22
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    23
def get_command_template(env, arguments=()):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    24
    cmd = Options.options.command_template or '%s'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    25
    for arg in arguments:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    26
        cmd = cmd + " " + arg
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    27
    return cmd
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    28
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    29
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    30
if hasattr(os.path, "relpath"):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    31
    relpath = os.path.relpath # since Python 2.6
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    32
else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    33
    def relpath(path, start=os.path.curdir):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    34
        """Return a relative version of a path"""
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    35
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    36
        if not path:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    37
            raise ValueError("no path specified")
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    38
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    39
        start_list = os.path.abspath(start).split(os.path.sep)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    40
        path_list = os.path.abspath(path).split(os.path.sep)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    41
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    42
        # Work out how much of the filepath is shared by start and path.
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    43
        i = len(os.path.commonprefix([start_list, path_list]))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    44
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    45
        rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    46
        if not rel_list:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    47
            return os.path.curdir
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    48
        return os.path.join(*rel_list)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    49
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    50
from waflib import Context
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    51
def find_program(program_name, env):
499
eb3c2476efd7 make waf runnable with mpirun when the directory is located under symbolic link
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 450
diff changeset
    52
    launch_dir = os.path.abspath(Options.cwd_launch)
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    53
    #top_dir = os.path.abspath(Options.cwd_launch)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    54
    found_programs = []
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    55
    for obj in bld.all_task_gen:
399
04f3f1b8f76c Bug 1593 - support DCE sub-module under myscripts directory
Hajime Tazaki <tazaki@nict.go.jp>
parents: 382
diff changeset
    56
        if not getattr(obj, 'is_ns3_program', False):
04f3f1b8f76c Bug 1593 - support DCE sub-module under myscripts directory
Hajime Tazaki <tazaki@nict.go.jp>
parents: 382
diff changeset
    57
            continue
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    58
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    59
        ## filter out programs not in the subtree starting at the launch dir
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    60
        if not (obj.path.abspath().startswith(launch_dir)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    61
                or obj.path.get_bld().abspath().startswith(launch_dir)):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    62
            continue
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    63
        
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    64
        name1 = os.path.basename(obj.name)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    65
        name2 = os.path.join(relpath(obj.path.abspath(), launch_dir), obj.name)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    66
        names = [name1, name2]
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    67
        found_programs.extend(names)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    68
        if program_name in names:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    69
            return obj
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    70
    raise ValueError("program '%s' not found; available programs are: %r"
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    71
                     % (program_name, found_programs))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    72
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    73
def get_proc_env(os_env=None):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    74
    env = bld.env
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    75
    if sys.platform == 'linux2':
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    76
        pathvar = 'LD_LIBRARY_PATH'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    77
    elif sys.platform == 'darwin':
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    78
        pathvar = 'DYLD_LIBRARY_PATH'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    79
    elif sys.platform == 'win32':
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    80
        pathvar = 'PATH'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    81
    elif sys.platform == 'cygwin':
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    82
        pathvar = 'PATH'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    83
    elif sys.platform.startswith('freebsd'):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    84
        pathvar = 'LD_LIBRARY_PATH'
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    85
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    86
        Logs.warn(("Don't know how to configure "
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    87
                        "dynamic library path for the platform %r;"
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    88
                        " assuming it's LD_LIBRARY_PATH.") % (sys.platform,))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    89
        pathvar = 'LD_LIBRARY_PATH'        
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    90
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    91
    proc_env = dict(os.environ)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    92
    if os_env is not None:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    93
        proc_env.update(os_env)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    94
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    95
    if pathvar is not None:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    96
        if pathvar in proc_env:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    97
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']) + [proc_env[pathvar]])
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    98
        else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
    99
            proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH']))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   100
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   101
    # DCE specific env
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   102
    proc_env[pathvar] = os.pathsep.join([proc_env[pathvar], \
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   103
                                             os.path.join(bld.out_dir, 'lib'), \
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   104
                                             os.path.join(bld.out_dir, 'bin'), \
382
21175c9f9400 remove dependencies on --prefix configuration
Hajime Tazaki <tazaki@nict.go.jp>
parents: 381
diff changeset
   105
                                             os.path.join(bld.env.NS3_DIR, 'lib'), \
21175c9f9400 remove dependencies on --prefix configuration
Hajime Tazaki <tazaki@nict.go.jp>
parents: 381
diff changeset
   106
                                             os.path.join(bld.env.NS3_DIR, 'bin')])
21175c9f9400 remove dependencies on --prefix configuration
Hajime Tazaki <tazaki@nict.go.jp>
parents: 381
diff changeset
   107
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   108
381
fe9823f0a3bf reorder DCE_PATH
Hajime Tazaki <tazaki@nict.go.jp>
parents: 362
diff changeset
   109
    proc_env['DCE_PATH'] = os.pathsep.join([os.path.join(bld.out_dir, 'bin_dce'), \
382
21175c9f9400 remove dependencies on --prefix configuration
Hajime Tazaki <tazaki@nict.go.jp>
parents: 381
diff changeset
   110
                                                os.path.join(bld.env.NS3_DIR, 'sbin'), \
21175c9f9400 remove dependencies on --prefix configuration
Hajime Tazaki <tazaki@nict.go.jp>
parents: 381
diff changeset
   111
                                                os.path.join(bld.env.NS3_DIR, 'bin_dce'), \
381
fe9823f0a3bf reorder DCE_PATH
Hajime Tazaki <tazaki@nict.go.jp>
parents: 362
diff changeset
   112
                                                proc_env[pathvar]])
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   113
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   114
    proc_env['DCE_ROOT'] = os.pathsep.join([os.path.join(bld.out_dir), \
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   115
                                                os.path.join(bld.env.PREFIX)])
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   116
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   117
    pymoddir = bld.path.find_dir('bindings/python')
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   118
    if pymoddir is not None:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   119
        pymoddir = pymoddir.get_bld().abspath()
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   120
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   121
        pymoddir = ""
449
17602bfc16d4 update python path for visualizer
Hajime Tazaki <tazaki@nict.go.jp>
parents: 416
diff changeset
   122
    import glob
578
71461e470024 (temporal) Bug 1773 - DCE doesn't run on Fedora 19, Ubuntu 13.10 (64bits)
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 499
diff changeset
   123
    pyns3dir = glob.glob(bld.env.NS3_DIR + '/lib*/python*/site-packages')
589
f8acac37468f fix python directory listing
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 578
diff changeset
   124
    # XXX:
450
18d4f4c450fa handle no visualizer case
Hajime Tazaki <tazaki@nict.go.jp>
parents: 449
diff changeset
   125
    if len(pyns3dir) is not 0:
589
f8acac37468f fix python directory listing
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 578
diff changeset
   126
        pyvizdir = pyns3dir[len(pyns3dir) - 1]
450
18d4f4c450fa handle no visualizer case
Hajime Tazaki <tazaki@nict.go.jp>
parents: 449
diff changeset
   127
    else:
18d4f4c450fa handle no visualizer case
Hajime Tazaki <tazaki@nict.go.jp>
parents: 449
diff changeset
   128
        pyvizdir = ''
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   129
    if 'PYTHONPATH' in proc_env:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   130
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir, pyvizdir] + [proc_env['PYTHONPATH']])
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   131
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   132
        proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir, pyvizdir])
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   133
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   134
    if 'PATH' in proc_env:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   135
        proc_env['PATH'] = os.pathsep.join(list(env['NS3_EXECUTABLE_PATH']) + [proc_env['PATH']])
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   136
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   137
        proc_env['PATH'] = os.pathsep.join(list(env['NS3_EXECUTABLE_PATH']))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   138
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   139
    return proc_env
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   140
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   141
def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   142
    proc_env = get_proc_env(os_env)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   143
    if Options.options.valgrind and not force_no_valgrind:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   144
        if Options.options.command_template:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   145
            raise WafError("Options --command-template and --valgrind are conflicting")
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   146
        if not env['VALGRIND']:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   147
            raise WafError("valgrind is not installed")
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   148
        argv = [env['VALGRIND'], "--leak-check=full", "--show-reachable=yes", "--error-exitcode=1"] + argv
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   149
        proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   150
        error = False
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   151
        for line in proc.stderr:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   152
            sys.stderr.write(line)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   153
            if "== LEAK SUMMARY" in line:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   154
                error = True
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   155
        retval = proc.wait()
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   156
        if retval == 0 and error:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   157
            retval = 1
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   158
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   159
        try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   160
            WindowsError
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   161
        except NameError:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   162
            retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   163
        else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   164
            try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   165
                retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   166
            except WindowsError, ex:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   167
                raise WafError("Command %s raised exception %s" % (argv, ex))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   168
    if retval:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   169
        signame = None
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   170
        if retval < 0: # signal?
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   171
            import signal
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   172
            for name, val in vars(signal).iteritems():
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   173
                if len(name) > 3 and name[:3] == 'SIG' and name[3] != '_':
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   174
                    if val == -retval:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   175
                        signame = name
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   176
                        break
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   177
        if signame:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   178
            raise WafError("Command %s terminated with signal %s."
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   179
                                 " Run it under a debugger to get more information "
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   180
                                 "(./waf --run <program> --command-template=\"gdb --args %%s <args>\")." % (argv, signame))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   181
        else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   182
            raise WafError("Command %s exited with code %i" % (argv, retval))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   183
    return retval
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   184
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   185
def get_run_program(program_string, command_template=None):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   186
    """
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   187
    Return the program name and argv of the process that would be executed by
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   188
    run_program(program_string, command_template).
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   189
    """
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   190
    #print "get_run_program_argv(program_string=%r, command_template=%r)" % (program_string, command_template)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   191
    env = bld.env
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   192
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   193
    if command_template in (None, '%s'):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   194
        argv = shlex.split(program_string)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   195
        #print "%r ==shlex.split==> %r" % (program_string, argv)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   196
        program_name = argv[0]
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   197
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   198
        try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   199
            program_obj = find_program(program_name, env)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   200
        except ValueError, ex:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   201
            raise WafError(str(ex))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   202
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   203
        program_node = program_obj.path.find_or_declare(program_obj.target)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   204
        #try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   205
        #    program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   206
        #except AttributeError:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   207
        #    raise Utils.WafError("%s does not appear to be a program" % (program_name,))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   208
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   209
        execvec = [program_node.abspath()] + argv[1:]
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   210
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   211
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   212
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   213
        program_name = program_string
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   214
        try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   215
            program_obj = find_program(program_name, env)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   216
        except ValueError, ex:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   217
            raise WafError(str(ex))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   218
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   219
        program_node = program_obj.path.find_or_declare(program_obj.target)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   220
        #try:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   221
        #    program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   222
        #except AttributeError:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   223
        #    raise Utils.WafError("%s does not appear to be a program" % (program_name,))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   224
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   225
        tmpl = command_template % (program_node.abspath(),)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   226
        execvec = shlex.split(tmpl.replace('\\', '\\\\'))
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   227
        #print "%r ==shlex.split==> %r" % (command_template % (program_node.abspath(env),), execvec)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   228
    return program_name, execvec
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   229
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   230
def run_program(program_string, env, command_template=None, cwd=None, visualize=False):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   231
    """
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   232
    if command_template is not None, then program_string == program
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   233
    name and argv is given by command_template with %s replaced by the
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   234
    full path to the program.  Else, program_string is interpreted as
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   235
    a shell command with first name being the program name.
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   236
    """
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   237
    dummy_program_name, execvec = get_run_program(program_string, command_template)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   238
    if cwd is None:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   239
        if (Options.options.cwd_launch):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   240
            cwd = Options.options.cwd_launch
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   241
        else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   242
            cwd = Options.cwd_launch
410
e4117a78c128 add ./waf --dlm support to use DlmLoader.
Hajime Tazaki <tazaki@nict.go.jp>
parents: 399
diff changeset
   243
    if (Options.options.dlm):
e4117a78c128 add ./waf --dlm support to use DlmLoader.
Hajime Tazaki <tazaki@nict.go.jp>
parents: 399
diff changeset
   244
        dummy_program_name, dce_runner = get_run_program('dce-runner', command_template)
e4117a78c128 add ./waf --dlm support to use DlmLoader.
Hajime Tazaki <tazaki@nict.go.jp>
parents: 399
diff changeset
   245
        execvec = dce_runner + execvec
362
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   246
    if visualize:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   247
        execvec.append("--SimulatorImplementationType=ns3::VisualSimulatorImpl")
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   248
    return run_argv(execvec, env, cwd=cwd)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   249
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   250
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   251
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   252
def run_python_program(program_string, env, visualize=False):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   253
    env = bld.env
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   254
    execvec = shlex.split(program_string)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   255
    if (Options.options.cwd_launch):
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   256
        cwd = Options.options.cwd_launch
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   257
    else:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   258
        cwd = Options.cwd_launch
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   259
    if visualize:
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   260
        execvec.append("--SimulatorImplementationType=ns3::VisualSimulatorImpl")
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   261
    return run_argv([env['PYTHON'][0]] + execvec, env, cwd=cwd)
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   262
1772a9cae1e6 add ./waf --run/--vis/shell/--cwd support, remove setenv.sh
Hajime Tazaki <tazaki@nict.go.jp>
parents:
diff changeset
   263