wscript
changeset 3826 40c5841b616d
parent 3703 71d93292bc49
child 3834 debf281cc42b
equal deleted inserted replaced
3817:4ed410f69d36 3826:40c5841b616d
    10 import pproc as subprocess
    10 import pproc as subprocess
    11 
    11 
    12 import Params
    12 import Params
    13 import Object
    13 import Object
    14 import ccroot
    14 import ccroot
       
    15 import Task
    15 
    16 
    16 Params.g_autoconfig = 1
    17 Params.g_autoconfig = 1
    17 
    18 
    18 # the following two variables are used by the target "waf dist"
    19 # the following two variables are used by the target "waf dist"
    19 VERSION = file("VERSION").read().strip()
    20 VERSION = file("VERSION").read().strip()
   164                    default=False, dest='regression_generate', action="store_true")
   165                    default=False, dest='regression_generate', action="store_true")
   165     opt.add_option('--regression-tests',
   166     opt.add_option('--regression-tests',
   166                    help=('For regression testing, only run/generate the indicated regression tests, '
   167                    help=('For regression testing, only run/generate the indicated regression tests, '
   167                          'specified as a comma separated list of test names'),
   168                          'specified as a comma separated list of test names'),
   168                    dest='regression_tests', type="string")
   169                    dest='regression_tests', type="string")
       
   170     opt.add_option('--disable-sudo',
       
   171                    help=('Do not attempt to use sudo to setup suid bits on ns3 executables.'),
       
   172                    dest='disable_sudo', action='store_true',
       
   173                    default=False)
   169 
   174 
   170     # options provided in a script in a subdirectory named "src"
   175     # options provided in a script in a subdirectory named "src"
   171     opt.sub_options('src')
   176     opt.sub_options('src')
   172     opt.sub_options('bindings/python')
   177     opt.sub_options('bindings/python')
   173     opt.sub_options('src/internet-stack')
   178     opt.sub_options('src/internet-stack')
   273                                            Params.g_options.enable_modules.split(',')]
   278                                            Params.g_options.enable_modules.split(',')]
   274 
   279 
   275     # we cannot run regression tests without diff
   280     # we cannot run regression tests without diff
   276     conf.find_program('diff', var='DIFF')
   281     conf.find_program('diff', var='DIFF')
   277 
   282 
       
   283     # for suid bits
       
   284     conf.find_program('sudo', var='SUDO')
       
   285 
   278     # we cannot pull regression traces without mercurial
   286     # we cannot pull regression traces without mercurial
   279     conf.find_program('hg', var='MERCURIAL')
   287     conf.find_program('hg', var='MERCURIAL')
   280 
   288 
   281     # Write a summary of optional features status
   289     # Write a summary of optional features status
   282     print "---- Summary of optional NS-3 features:"
   290     print "---- Summary of optional NS-3 features:"
   285             status = 'enabled'
   293             status = 'enabled'
   286         else:
   294         else:
   287             status = 'not enabled (%s)' % reason_not_enabled
   295             status = 'not enabled (%s)' % reason_not_enabled
   288         print "%-30s: %s" % (caption, status)
   296         print "%-30s: %s" % (caption, status)
   289 
   297 
       
   298 
       
   299 class SuidBuildTask(Task.TaskBase):
       
   300     """task that makes a binary Suid
       
   301     """
       
   302     def __init__(self, bld, program):
       
   303         self.m_display = 'build-suid'
       
   304         self.prio = 1000 # build after the rest of ns-3
       
   305         self.__program = program
       
   306         self.__env = bld.env ()
       
   307         super(SuidBuildTask, self).__init__()
       
   308 
       
   309     def run(self):
       
   310         try:
       
   311             program_obj = _find_program(self.__program.target, self.__env)
       
   312         except ValueError, ex:
       
   313             Params.fatal(str(ex))
       
   314 
       
   315         try:
       
   316             program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
       
   317         except AttributeError:
       
   318             Params.fatal("%s does not appear to be a program" % (program_name,))
       
   319 
       
   320         filename = program_node.abspath(self.__env)
       
   321         os.system ('sudo chown root ' + filename)
       
   322         os.system ('sudo chmod u+s ' + filename)
       
   323 
       
   324 def create_suid_program(bld, name):
       
   325     program = bld.create_obj('cpp', 'program')
       
   326     program.is_ns3_program = True
       
   327     program.module_deps = list()
       
   328     program.name = name
       
   329     program.target = name
       
   330     if bld.env ()['SUDO'] and not Params.g_options.disable_sudo:
       
   331         SuidBuildTask (bld, program)
       
   332     return program
   290 
   333 
   291 def create_ns3_program(bld, name, dependencies=('simulator',)):
   334 def create_ns3_program(bld, name, dependencies=('simulator',)):
   292     program = bld.create_obj('cpp', 'program')
   335     program = bld.create_obj('cpp', 'program')
   293     program.is_ns3_program = True
   336     program.is_ns3_program = True
   294     program.name = name
   337     program.name = name
   338         import Runner
   381         import Runner
   339         Runner.exec_command = _exec_command_interact_win32
   382         Runner.exec_command = _exec_command_interact_win32
   340 
   383 
   341     Params.g_cwd_launch = Params.g_build.m_curdirnode.abspath()
   384     Params.g_cwd_launch = Params.g_build.m_curdirnode.abspath()
   342     bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
   385     bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
       
   386     bld.create_suid_program = types.MethodType(create_suid_program, bld)
   343     variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
   387     variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
   344     variant_env = bld.env_of_name(variant_name)
   388     variant_env = bld.env_of_name(variant_name)
   345     bld.m_allenvs['default'] = variant_env # switch to the active variant
   389     bld.m_allenvs['default'] = variant_env # switch to the active variant
   346 
   390 
   347     if Params.g_options.shell:
   391     if Params.g_options.shell: