WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
--- a/doc/build-waf.txt Wed May 23 17:32:32 2007 +0100
+++ b/doc/build-waf.txt Wed May 23 19:20:54 2007 +0100
@@ -35,6 +35,17 @@
Run code coverage analysis (assuming the project was configured
with --enable-gcov)
+ 4. ./waf --run "program [args]"
+ Run a ns3 program, given its target name, with the given
+ arguments. This takes care of automatically modifying the the
+ path for finding the ns3 dynamic libraries in the environment
+ before running the program. Note: the "program [args]" string is
+ parsed using POSIX shell rules.
+
+ 5. ./waf --shell
+ Starts a nested system shell with modified environment to run ns3 programs.
+
+
=== Extending ns-3 ===
To add new modules:
--- a/src/wscript Wed May 23 17:32:32 2007 +0100
+++ b/src/wscript Wed May 23 19:20:54 2007 +0100
@@ -17,35 +17,17 @@
def set_options(opt):
opt.sub_options('simulator')
-
- rpath_default = (sys.platform == 'linux2')
- opt.add_option('--enable-rpath',
- help=("Link programs with rpath"),
- action="store_true", dest='enable_rpath', default=rpath_default)
- opt.add_option('--disable-rpath',
- help=("Don't link programs with rpath"),
- action="store_false", dest='enable_rpath', default=rpath_default)
def configure(conf):
conf.sub_config('core')
conf.sub_config('simulator')
- conf.env['ENABLE_RPATH'] = Params.g_options.enable_rpath
-
def build(bld):
-
- ## Add a global RPATH pointing to each module, so that programs can find the libs
- ## Note: this is slightly evil; we get away because our programs
- ## and libs are not supposed to be installed system wide.
env = bld.env_of_name('default')
for module in all_modules:
node = bld.m_curdirnode.find_dir(module)
- if sys.platform == 'win32':
- os.environ["PATH"] = ';'.join([os.environ["PATH"], node.abspath(env)])
- else:
- if env['ENABLE_RPATH']:
- env.append_value('RPATH', '-Wl,-rpath=%s' % (node.abspath(env),))
+ node_path = node.abspath(env)
+ env.append_value('NS3_MODULE_PATH', node_path)
bld.add_subdirs(all_modules)
-
--- a/wscript Wed May 23 17:32:32 2007 +0100
+++ b/wscript Wed May 23 19:20:54 2007 +0100
@@ -1,6 +1,7 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import os
import sys
+import shlex
import Params
import Object
@@ -90,6 +91,15 @@
action="store_true", default=False,
dest='doxygen')
+ opt.add_option('--run',
+ help=('Run a locally built program'),
+ type="string", default='', dest='run')
+
+ opt.add_option('--shell',
+ help=('Run a shell with an environment suitably modified to run locally built programs'),
+ action="store_true", default=False,
+ dest='shell')
+
# options provided in a script in a subdirectory named "src"
opt.sub_options('src')
@@ -138,20 +148,90 @@
def shutdown():
- import UnitTest
- ut = UnitTest.unit_test()
- ut.change_to_testfile_dir = True
- ut.want_to_see_test_output = True
- ut.want_to_see_test_error = True
- ut.run()
+ #import UnitTest
+ #ut = UnitTest.unit_test()
+ #ut.change_to_testfile_dir = True
+ #ut.want_to_see_test_output = True
+ #ut.want_to_see_test_error = True
+ #ut.run()
#ut.print_results()
+ if Params.g_commands['check']:
+ run_program('run-tests')
+
if Params.g_options.lcov_report:
lcov_report()
if Params.g_options.doxygen:
doxygen()
+ if Params.g_options.run:
+ run_program(Params.g_options.run)
+
+ elif Params.g_options.shell:
+ run_shell()
+
+def _find_program(program_name):
+ for obj in Object.g_allobjs:
+ if obj.target == program_name:
+ return obj
+ raise ValueError("progam '%s' not found" % (program_name,))
+
+def _run_argv(argv):
+ env = Params.g_build.env_of_name('default')
+ if sys.platform == 'linux2':
+ pathvar = 'LD_LIBRARY_PATH'
+ pathsep = ':'
+ elif sys.platform == 'darwin':
+ pathvar = 'DYLD_LIBRARY_PATH'
+ pathsep = ':'
+ elif sys.platform == 'win32':
+ pathvar = 'PATH'
+ pathsep = ';'
+ else:
+ Params.warning(("Don't know how to configure "
+ "dynamic library path for the platform '%s'") % (sys.platform,))
+ pathvar = None
+ pathsep = None
+
+ os_env = dict(os.environ)
+ if pathvar is not None:
+ if pathvar in os_env:
+ os_env[pathvar] = pathsep.join([os_env[pathvar]] + list(env['NS3_MODULE_PATH']))
+ else:
+ os_env[pathvar] = pathsep.join(list(env['NS3_MODULE_PATH']))
+
+ retval = subprocess.Popen(argv, env=os_env).wait()
+ if retval:
+ raise SystemExit(retval)
+
+
+def run_program(program_string):
+ env = Params.g_build.env_of_name('default')
+ argv = shlex.split(program_string)
+ program_name = argv[0]
+
+ try:
+ program_obj = _find_program(program_name)
+ except ValueError:
+ Params.fatal("progam '%s' not found" % (program_name,))
+
+ try:
+ program_node, = program_obj.m_linktask.m_outputs
+ except AttributeError:
+ Params.fatal("%s does not appear to be a program" % (program_name,))
+
+ execvec = [program_node.abspath(env)] + argv[1:]
+ return _run_argv(execvec)
+
+
+def run_shell():
+ if sys.platform == 'win32':
+ shell = os.environ.get("COMSPEC", "cmd.exe")
+ else:
+ shell = os.environ.get("SHELL", "/bin/sh")
+ _run_argv([shell])
+
def doxygen():
doxygen_config = os.path.join('doc', 'doxygen.conf')