wscript
changeset 4064 10222f483860
parent 4029 4267fd454004
child 4069 430a6edb0fa0
--- a/wscript	Thu Dec 18 22:33:33 2008 -0800
+++ b/wscript	Mon Dec 29 13:28:54 2008 +0000
@@ -1,24 +1,31 @@
 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+# python lib modules
 import sys
 import shutil
 import types
 import optparse
 import os.path
 
+# WAF modules
 import pproc as subprocess
-
-import Params
-import Object
+import Options
+import Logs
+import TaskGen
 import ccroot
 import Task
+import Utils
+import Build
+import Configure
 
+# local modules
 import wutils
 import regression
 
-Params.g_autoconfig = 1
+Options.autoconfig = 1
 
 # the following two variables are used by the target "waf dist"
-VERSION = file("VERSION").read().strip()
+VERSION = file("VERSION", "rt").read().strip()
 APPNAME = 'ns'
 
 wutils.VERSION = VERSION
@@ -36,7 +43,7 @@
     shutil.rmtree("nsc", True)
 
     if not os.path.exists("bindings/python/pybindgen"):
-        Params.fatal("Missing pybindgen checkout; run './waf configure --pybindgen-checkout' first.")
+        raise Utils.WafError("Missing pybindgen checkout; run './waf configure --pybindgen-checkout' first.")
 
     ## build the name of the traces subdirectory.  Will be something like
     ## ns-3-dev-ref-traces
@@ -44,7 +51,7 @@
     ## Create a tar.bz2 file with the traces
     traces_dir = os.path.join(regression.REGRESSION_DIR, traces_name)
     if not os.path.isdir(traces_dir):
-        Params.warning("Not creating traces archive: the %s directory does not exist" % traces_dir)
+        Logs.warn("Not creating traces archive: the %s directory does not exist" % traces_dir)
     else:
         traceball = traces_name + wutils.TRACEBALL_SUFFIX
         tar = tarfile.open(os.path.join("..", traceball), 'w:bz2')
@@ -160,19 +167,18 @@
     flag: can be a string or a list of strings
     """
 
-    # Check for -Wno-error=deprecated-declarations
-    save_CXXFLAGS = list(conf.env['CXXFLAGS'])
-    conf.env.append_value('CXXFLAGS', flag)
-    e = conf.create_test_configurator()
-    e.mandatory = 0
-    e.code = '#include <stdio.h>\nint main() { return 0; }\n'
-    e.want_message = 0
-    ok = e.run()
-    conf.check_message_custom(flag, 'compilation flag support',
-                              (ok and 'yes' or 'no'))
+    env = conf.env.copy()
+    env.append_value('CXXFLAGS', flag)
+    try:
+        retval = conf.run_c_code(code='#include <stdio.h>\nint main() { return 0; }\n',
+                                 env=env, compile_filename='test.cc',
+                                 compile_mode='cxx',type='program', execute=False)
+    except Configure.ConfigurationError:
+        ok = False
+    else:
+        ok = (retval == 0)
+    conf.check_message_custom(flag, 'support', (ok and 'yes' or 'no'))
 
-    if not ok: # if it doesn't accept, remove it again
-        conf.env['CXXFLAGS'] = save_CXXFLAGS
     
 def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled):
     conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled))
@@ -184,12 +190,14 @@
     conf.report_optional_feature = types.MethodType(report_optional_feature, conf)
     conf.env['NS3_OPTIONAL_FEATURES'] = []
 
-    conf.env['NS3_BUILDDIR'] = conf.m_blddir
+    conf.env['NS3_BUILDDIR'] = conf.blddir
     conf.check_tool('compiler_cxx')
+    conf.check_tool('pkgconfig')
+    conf.check_tool('command')
 
     # create the second environment, set the variant and set its name
     variant_env = conf.env.copy()
-    debug_level = Params.g_options.debug_level.lower()
+    debug_level = Options.options.debug_level.lower()
     if debug_level == 'ultradebug':
         variant_name = 'debug'
     else:
@@ -197,12 +205,12 @@
 
     variant_env['INCLUDEDIR'] = os.path.join(variant_env['PREFIX'], 'include')
 
-    if Params.g_options.regression_traces is not None:
-        variant_env['REGRESSION_TRACES'] = os.path.join("..", Params.g_options.regression_traces)
+    if Options.options.regression_traces is not None:
+        variant_env['REGRESSION_TRACES'] = os.path.join("..", Options.options.regression_traces)
     else:
         variant_env['REGRESSION_TRACES'] = None
 
-    if Params.g_options.enable_gcov:
+    if Options.options.enable_gcov:
         variant_name += '-gcov'
         variant_env.append_value('CCFLAGS', '-fprofile-arcs')
         variant_env.append_value('CCFLAGS', '-ftest-coverage')
@@ -226,13 +234,13 @@
         check_compilation_flag(conf, '-Wno-error=deprecated-declarations')
 
         
-    if 'debug' in Params.g_options.debug_level.lower():
+    if 'debug' in Options.options.debug_level.lower():
         variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
         variant_env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
 
     ## In optimized builds we still want debugging symbols, e.g. for
     ## profiling, and at least partially usable stack traces.
-    if ('optimized' in Params.g_options.debug_level.lower() 
+    if ('optimized' in Options.options.debug_level.lower() 
         and 'CXXFLAGS' not in os.environ):
         for flag in variant_env['CXXFLAGS_DEBUG']:
             ## this probably doesn't work for MSVC
@@ -240,7 +248,7 @@
                 variant_env.append_value('CXXFLAGS', flag)
 
     ## in optimized builds, replace -O2 with -O3
-    if 'optimized' in Params.g_options.debug_level.lower():
+    if 'optimized' in Options.options.debug_level.lower():
         lst = variant_env['CXXFLAGS']
         for i, flag in enumerate(lst):
             if flag == '-O2':
@@ -254,9 +262,9 @@
     conf.sub_config('utils')
     conf.sub_config('bindings/python')
 
-    if Params.g_options.enable_modules:
+    if Options.options.enable_modules:
         conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
-                                           Params.g_options.enable_modules.split(',')]
+                                           Options.options.enable_modules.split(',')]
 
     # we cannot run regression tests without diff
     conf.find_program('diff', var='DIFF')
@@ -280,9 +288,9 @@
 class SuidBuildTask(Task.TaskBase):
     """task that makes a binary Suid
     """
+    after = 'link'
     def __init__(self, bld, program):
         self.m_display = 'build-suid'
-        self.prio = 1000 # build after the rest of ns-3
         self.__program = program
         self.__env = bld.env ()
         super(SuidBuildTask, self).__init__()
@@ -291,29 +299,30 @@
         try:
             program_obj = wutils.find_program(self.__program.target, self.__env)
         except ValueError, ex:
-            Params.fatal(str(ex))
+            raise Utils.WafError(str(ex))
 
-        try:
-            program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
-        except AttributeError:
-            Params.fatal("%s does not appear to be a program" % (self.__program.name,))
+        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
+        #try:
+        #    program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
+        #except AttributeError:
+        #    raise Utils.WafError("%s does not appear to be a program" % (self.__program.name,))
 
         filename = program_node.abspath(self.__env)
         os.system ('sudo chown root ' + filename)
         os.system ('sudo chmod u+s ' + filename)
 
 def create_suid_program(bld, name):
-    program = bld.create_obj('cpp', 'program')
+    program = bld.new_task_gen('cxx', 'program')
     program.is_ns3_program = True
     program.module_deps = list()
     program.name = name
     program.target = name
-    if bld.env ()['SUDO'] and Params.g_options.enable_sudo:
-        SuidBuildTask (bld, program)
+    if bld.env['SUDO'] and Options.options.enable_sudo:
+        SuidBuildTask(bld, program)
     return program
 
 def create_ns3_program(bld, name, dependencies=('simulator',)):
-    program = bld.create_obj('cpp', 'program')
+    program = bld.new_task_gen('cxx', 'program')
     program.is_ns3_program = True
     program.name = name
     program.target = program.name
@@ -322,7 +331,7 @@
     return program
 
 def add_scratch_programs(bld):
-    all_modules = [mod[len("ns3-"):] for mod in bld.env()['NS3_MODULES']]
+    all_modules = [mod[len("ns3-"):] for mod in bld.env['NS3_MODULES']]
     for filename in os.listdir("scratch"):
         if filename.startswith('.') or filename == 'CVS':
 	    continue
@@ -356,7 +365,7 @@
 
 
 def build(bld):
-    if Params.g_options.no_task_lines:
+    if Options.options.no_task_lines:
         import Runner
         def null_printout(s):
             pass
@@ -366,28 +375,30 @@
         import Runner
         Runner.exec_command = _exec_command_interact_win32
 
-    Params.g_cwd_launch = Params.g_build.m_curdirnode.abspath()
+    Options.cwd_launch = bld.path.abspath()
     bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
     bld.create_suid_program = types.MethodType(create_suid_program, bld)
+
+    # switch default variant to the one matching our debug level
     variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
     variant_env = bld.env_of_name(variant_name)
-    bld.m_allenvs['default'] = variant_env # switch to the active variant
+    bld.all_envs['default'] = variant_env
 
-    if Params.g_options.shell:
+    if Options.options.shell:
         run_shell()
         raise SystemExit(0)
 
-    if Params.g_options.doxygen:
+    if Options.options.doxygen:
         doxygen()
         raise SystemExit(0)
 
     check_shell()
 
-    if Params.g_options.doxygen:
+    if Options.options.doxygen:
         doxygen()
         raise SystemExit(0)
 
-    print "Entering directory `%s'" % os.path.join(Params.g_build.m_curdirnode.abspath(), 'build')
+    print "Entering directory `%s'" % os.path.join(bld.path.abspath(), 'build')
     # process subfolders from here
     bld.add_subdirs('src')
     bld.add_subdirs('samples utils examples')
@@ -397,13 +408,13 @@
     ## if --enabled-modules option was given, we disable building the
     ## modules that were not enabled, and programs that depend on
     ## disabled modules.
-    env = bld.env()
+    env = bld.env
 
-    if Params.g_options.enable_modules:
-        Params.warning("the option --enable-modules is being applied to this build only;"
+    if Options.options.enable_modules:
+        Logs.warn("the option --enable-modules is being applied to this build only;"
                        " to make it permanent it needs to be given to waf configure.")
         env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
-                                      Params.g_options.enable_modules.split(',')]
+                                      Options.options.enable_modules.split(',')]
 
     if env['NS3_ENABLED_MODULES']:
         modules = env['NS3_ENABLED_MODULES']
@@ -422,17 +433,17 @@
                         changed = True
 
         ## remove objects that depend on modules not listed
-        for obj in list(Object.g_allobjs):
+        for obj in list(Build.bld.all_task_gen):
             if hasattr(obj, 'ns3_module_dependencies'):
                 for dep in obj.ns3_module_dependencies:
                     if dep not in modules:
-                        Object.g_allobjs.remove(obj)
+                        Build.bld.all_task_gen.remove(obj)
                         break
             if obj.name in env['NS3_MODULES'] and obj.name not in modules:
-                Object.g_allobjs.remove(obj)
+                Build.bld.all_task_gen.remove(obj)
 
     ## Create a single ns3 library containing all enabled modules
-    lib = bld.create_obj('cpp', 'shlib')
+    lib = bld.new_task_gen('cxx', 'shlib')
     lib.name = 'ns3'
     lib.target = 'ns3'
     if env['NS3_ENABLED_MODULES']:
@@ -445,25 +456,25 @@
 
     bld.add_subdirs('bindings/python')
 
-    if Params.g_options.run:
+    if Options.options.run:
         # Check that the requested program name is valid
-        program_name, dummy_program_argv = wutils.get_run_program(Params.g_options.run, get_command_template())
+        program_name, dummy_program_argv = wutils.get_run_program(Options.options.run, get_command_template())
 
         # When --run'ing a program, tell WAF to only build that program,
         # nothing more; this greatly speeds up compilation when all you
         # want to do is run a test program.
-        if not Params.g_options.compile_targets:
-            Params.g_options.compile_targets = program_name
+        if not Options.options.compile_targets:
+            Options.options.compile_targets = program_name
 
 
 
 def get_command_template(*arguments):
-    if Params.g_options.valgrind:
-        if Params.g_options.command_template:
-            Params.fatal("Options --command-template and --valgrind are conflicting")
+    if Options.options.valgrind:
+        if Options.options.command_template:
+            raise Utils.WafError("Options --command-template and --valgrind are conflicting")
         cmd = "valgrind --leak-check=full %s"
     else:
-        cmd = Params.g_options.command_template or '%s'
+        cmd = Options.options.command_template or '%s'
     for arg in arguments:
         cmd = cmd + " " + arg
     return cmd
@@ -477,14 +488,14 @@
     #ut.want_to_see_test_error = True
     #ut.run()
     #ut.print_results()
-    env = Params.g_build.env_of_name('default')
+    env = Build.bld.env
 
-    if Params.g_commands['check']:
+    if Options.commands['check']:
         _run_waf_check()
 
-    if Params.g_options.regression or Params.g_options.regression_generate:
+    if Options.options.regression or Options.options.regression_generate:
         if not env['DIFF']:
-            Params.fatal("Cannot run regression tests: the 'diff' program is not installed.")
+            raise Utils.WafError("Cannot run regression tests: the 'diff' program is not installed.")
 
         _dir = os.getcwd()
         os.chdir("regression")
@@ -498,20 +509,20 @@
         if retval:
             sys.exit(retval)
 
-    if Params.g_options.lcov_report:
+    if Options.options.lcov_report:
         lcov_report()
 
-    if Params.g_options.run:
-        wutils.run_program(Params.g_options.run, get_command_template())
+    if Options.options.run:
+        wutils.run_program(Options.options.run, get_command_template())
         raise SystemExit(0)
 
-    if Params.g_options.pyrun:
-        wutils.run_python_program(Params.g_options.pyrun)
+    if Options.options.pyrun:
+        wutils.run_python_program(Options.options.pyrun)
         raise SystemExit(0)
 
 def _run_waf_check():
     ## generate the trace sources list docs
-    env = Params.g_build.env_of_name('default')
+    env = Build.bld.env
     proc_env = wutils.get_proc_env()
     try:
         program_obj = wutils.find_program('print-introspected-doxygen', env)
@@ -520,7 +531,7 @@
                        # --enable-modules=xxx
         pass
     else:
-        prog = program_obj.path.find_build(ccroot.get_target_name(program_obj)).abspath(env)
+        prog = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj)).abspath(env)
         out = open(os.path.join('doc', 'introspected-doxygen.h'), 'w')
         if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
             raise SystemExit(1)
@@ -541,7 +552,7 @@
 def check_shell():
     if 'NS3_MODULE_PATH' not in os.environ:
         return
-    env = Params.g_build.env_of_name('default')
+    env = Build.bld.env
     correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH'])
     found_modpath = os.environ['NS3_MODULE_PATH']
     if found_modpath != correct_modpath:
@@ -554,7 +565,7 @@
                "You should correct this situation before running any program.  Possible solutions:\n"
                "  1. Exit this shell, and start a new one\n"
                "  2. Run a new nested shell")
-        Params.fatal(msg)
+        raise Utils.WafError(msg)
 
 
 def run_shell():
@@ -563,12 +574,12 @@
     else:
         shell = os.environ.get("SHELL", "/bin/sh")
 
-    env = Params.g_build.env_of_name('default')
+    env = Build.bld.env
     wutils.run_argv([shell], {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])})
 
 def doxygen():
     if not os.path.exists('doc/introspected-doxygen.h'):
-        Params.warning("doc/introspected-doxygen.h does not exist; run waf check to generate it.")
+        Logs.warn("doc/introspected-doxygen.h does not exist; run waf check to generate it.")
 
     ## run doxygen
     doxygen_config = os.path.join('doc', 'doxygen.conf')
@@ -576,11 +587,11 @@
         raise SystemExit(1)
 
 def lcov_report():
-    env = Params.g_build.env_of_name('default')
+    env = Build.bld.env
     variant_name = env['NS3_ACTIVE_VARIANT']
 
     if 'gcov' not in variant_name:
-        Params.fatal("project not configured for code coverage;"
+        raise Utils.WafError("project not configured for code coverage;"
                      " reconfigure with --enable-gcov")
 
     os.chdir(blddir)
@@ -618,7 +629,7 @@
 ## implementation that is more efficient.
 ##
 import Scripting
-from Scripting import g_dist_exts, g_excludes, BLDDIR
+from Scripting import dist_exts, excludes, BLDDIR
 import Utils
 import os
 
@@ -667,7 +678,7 @@
                 if name.startswith('.') or name.startswith('++'):
                     to_remove = True
                 else:
-                    for x in g_dist_exts:
+                    for x in dist_exts:
                         if ends(x):
                             to_remove = True
                             break
@@ -707,7 +718,7 @@
     build_dir = getattr(Utils.g_module, BLDDIR, None)
 
     # Copy everything into the new folder
-    copytree('.', TMPFOLDER, excludes=g_excludes, build_dir=build_dir)
+    copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir)
 
     # TODO undocumented hook
     dist_hook = getattr(Utils.g_module, 'dist_hook', None)