131 opt.add_option('--valgrind', |
133 opt.add_option('--valgrind', |
132 help=('Change the default command template to run programs and unit tests with valgrind'), |
134 help=('Change the default command template to run programs and unit tests with valgrind'), |
133 action="store_true", default=False, |
135 action="store_true", default=False, |
134 dest='valgrind') |
136 dest='valgrind') |
135 opt.add_option('--shell', |
137 opt.add_option('--shell', |
136 help=('Run a shell with an environment suitably modified to run locally built programs'), |
138 help=('DEPRECATED (run ./waf shell)'), |
137 action="store_true", default=False, |
139 action="store_true", default=False, |
138 dest='shell') |
140 dest='shell') |
139 opt.add_option('--enable-sudo', |
141 opt.add_option('--enable-sudo', |
140 help=('Use sudo to setup suid bits on ns3 executables.'), |
142 help=('Use sudo to setup suid bits on ns3 executables.'), |
141 dest='enable_sudo', action='store_true', |
143 dest='enable_sudo', action='store_true', |
159 opt.sub_options('src') |
161 opt.sub_options('src') |
160 opt.sub_options('bindings/python') |
162 opt.sub_options('bindings/python') |
161 opt.sub_options('src/internet-stack') |
163 opt.sub_options('src/internet-stack') |
162 |
164 |
163 |
165 |
164 def check_compilation_flag(conf, flag): |
166 def _check_compilation_flag(conf, flag): |
165 """ |
167 """ |
166 Checks if the C++ compiler accepts a certain compilation flag or flags |
168 Checks if the C++ compiler accepts a certain compilation flag or flags |
167 flag: can be a string or a list of strings |
169 flag: can be a string or a list of strings |
168 """ |
170 """ |
169 |
171 |
184 def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled): |
186 def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled): |
185 conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled)) |
187 conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled)) |
186 |
188 |
187 def configure(conf): |
189 def configure(conf): |
188 # attach some extra methods |
190 # attach some extra methods |
189 conf.check_compilation_flag = types.MethodType(check_compilation_flag, conf) |
191 conf.check_compilation_flag = types.MethodType(_check_compilation_flag, conf) |
190 conf.report_optional_feature = types.MethodType(report_optional_feature, conf) |
192 conf.report_optional_feature = types.MethodType(report_optional_feature, conf) |
191 conf.env['NS3_OPTIONAL_FEATURES'] = [] |
193 conf.env['NS3_OPTIONAL_FEATURES'] = [] |
192 |
194 |
193 conf.env['NS3_BUILDDIR'] = conf.blddir |
195 conf.env['NS3_BUILDDIR'] = conf.blddir |
194 conf.check_tool('compiler_cxx') |
196 conf.check_tool('compiler_cxx') |
233 env = variant_env |
235 env = variant_env |
234 |
236 |
235 env.append_value('CXXDEFINES', 'RUN_SELF_TESTS') |
237 env.append_value('CXXDEFINES', 'RUN_SELF_TESTS') |
236 |
238 |
237 if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ: |
239 if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ: |
238 if check_compilation_flag(conf, '-Wno-error=deprecated-declarations'): |
240 if conf.check_compilation_flag('-Wno-error=deprecated-declarations'): |
239 env.append_value('CXXFLAGS', '-Wno-error=deprecated-declarations') |
241 env.append_value('CXXFLAGS', '-Wno-error=deprecated-declarations') |
240 |
242 |
241 if Options.options.build_profile == 'debug': |
243 if Options.options.build_profile == 'debug': |
242 env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE') |
244 env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE') |
243 env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE') |
245 env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE') |
376 # switch default variant to the one matching our debug level |
379 # switch default variant to the one matching our debug level |
377 variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT'] |
380 variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT'] |
378 variant_env = bld.env_of_name(variant_name) |
381 variant_env = bld.env_of_name(variant_name) |
379 bld.all_envs['default'] = variant_env |
382 bld.all_envs['default'] = variant_env |
380 |
383 |
381 if Options.options.shell: |
|
382 run_shell() |
|
383 raise SystemExit(0) |
|
384 |
|
385 if Options.options.doxygen: |
|
386 doxygen() |
|
387 raise SystemExit(0) |
|
388 |
|
389 check_shell() |
|
390 |
|
391 if Options.options.doxygen: |
|
392 doxygen() |
|
393 raise SystemExit(0) |
|
394 |
|
395 print "Entering directory `%s'" % os.path.join(bld.path.abspath(), 'build') |
|
396 # process subfolders from here |
384 # process subfolders from here |
397 bld.add_subdirs('src') |
385 bld.add_subdirs('src') |
398 bld.add_subdirs('samples utils examples') |
386 bld.add_subdirs('samples utils examples') |
399 |
387 |
400 add_scratch_programs(bld) |
388 add_scratch_programs(bld) |
425 if dep not in modules: |
413 if dep not in modules: |
426 modules.append(dep) |
414 modules.append(dep) |
427 changed = True |
415 changed = True |
428 |
416 |
429 ## remove objects that depend on modules not listed |
417 ## remove objects that depend on modules not listed |
430 for obj in list(Build.bld.all_task_gen): |
418 for obj in list(bld.all_task_gen): |
431 if hasattr(obj, 'ns3_module_dependencies'): |
419 if hasattr(obj, 'ns3_module_dependencies'): |
432 for dep in obj.ns3_module_dependencies: |
420 for dep in obj.ns3_module_dependencies: |
433 if dep not in modules: |
421 if dep not in modules: |
434 Build.bld.all_task_gen.remove(obj) |
422 bld.all_task_gen.remove(obj) |
435 break |
423 break |
436 if obj.name in env['NS3_MODULES'] and obj.name not in modules: |
424 if obj.name in env['NS3_MODULES'] and obj.name not in modules: |
437 Build.bld.all_task_gen.remove(obj) |
425 bld.all_task_gen.remove(obj) |
438 |
426 |
439 ## Create a single ns3 library containing all enabled modules |
427 ## Create a single ns3 library containing all enabled modules |
440 lib = bld.new_task_gen('cxx', 'shlib') |
428 lib = bld.new_task_gen('cxx', 'shlib') |
441 lib.name = 'ns3' |
429 lib.name = 'ns3' |
442 lib.target = 'ns3' |
430 lib.target = 'ns3' |
466 raise Utils.WafError("Cannot run regression tests: reference traces directory not given" |
454 raise Utils.WafError("Cannot run regression tests: reference traces directory not given" |
467 " (--with-regression-traces configure option)") |
455 " (--with-regression-traces configure option)") |
468 regression.run_regression(bld, regression_traces) |
456 regression.run_regression(bld, regression_traces) |
469 |
457 |
470 |
458 |
471 def shutdown(): |
459 |
472 env = Build.bld.env |
460 def shutdown(ctx): |
473 |
461 bld = wutils.bld |
474 if Options.commands['check']: |
462 env = bld.env |
475 _run_waf_check() |
463 |
|
464 #if Options.commands['check']: |
|
465 # _run_waf_check() |
476 |
466 |
477 if Options.options.lcov_report: |
467 if Options.options.lcov_report: |
478 lcov_report() |
468 lcov_report() |
479 |
469 |
480 if Options.options.run: |
470 if Options.options.run: |
483 |
473 |
484 if Options.options.pyrun: |
474 if Options.options.pyrun: |
485 wutils.run_python_program(Options.options.pyrun) |
475 wutils.run_python_program(Options.options.pyrun) |
486 raise SystemExit(0) |
476 raise SystemExit(0) |
487 |
477 |
488 def _run_waf_check(): |
478 if Options.options.shell: |
|
479 raise Utils.WafError("Run `./waf shell' now, instead of `./waf shell'") |
|
480 |
|
481 if Options.options.doxygen: |
|
482 doxygen() |
|
483 raise SystemExit(0) |
|
484 |
|
485 check_shell(bld) |
|
486 |
|
487 if Options.options.doxygen: |
|
488 doxygen() |
|
489 raise SystemExit(0) |
|
490 |
|
491 |
|
492 check_context = Build.BuildContext |
|
493 def check(bld): |
|
494 "run the NS-3 unit tests" |
|
495 Scripting.build(bld) |
489 ## generate the trace sources list docs |
496 ## generate the trace sources list docs |
490 env = Build.bld.env |
497 env = bld.env |
491 proc_env = wutils.get_proc_env() |
498 proc_env = wutils.get_proc_env() |
492 try: |
499 try: |
493 program_obj = wutils.find_program('print-introspected-doxygen', env) |
500 program_obj = wutils.find_program('print-introspected-doxygen', env) |
494 except ValueError: # could happen if print-introspected-doxygen is |
501 except ValueError: # could happen if print-introspected-doxygen is |
495 # not built because of waf configure |
502 # not built because of waf configure |
512 print "-- Skipping NS-3 Python bindings unit tests: Python bindings not enabled." |
519 print "-- Skipping NS-3 Python bindings unit tests: Python bindings not enabled." |
513 |
520 |
514 |
521 |
515 |
522 |
516 |
523 |
517 def check_shell(): |
524 def check_shell(bld): |
518 if 'NS3_MODULE_PATH' not in os.environ: |
525 if 'NS3_MODULE_PATH' not in os.environ: |
519 return |
526 return |
520 env = Build.bld.env |
527 env = bld.env |
521 correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH']) |
528 correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH']) |
522 found_modpath = os.environ['NS3_MODULE_PATH'] |
529 found_modpath = os.environ['NS3_MODULE_PATH'] |
523 if found_modpath != correct_modpath: |
530 if found_modpath != correct_modpath: |
524 msg = ("Detected shell (waf --shell) with incorrect configuration\n" |
531 msg = ("Detected shell (./waf shell) with incorrect configuration\n" |
525 "=========================================================\n" |
532 "=========================================================\n" |
526 "Possible reasons for this problem:\n" |
533 "Possible reasons for this problem:\n" |
527 " 1. You switched to another ns-3 tree from inside this shell\n" |
534 " 1. You switched to another ns-3 tree from inside this shell\n" |
528 " 2. You switched ns-3 debug level (waf configure --debug)\n" |
535 " 2. You switched ns-3 debug level (waf configure --debug)\n" |
529 " 3. You modified the list of built ns-3 modules\n" |
536 " 3. You modified the list of built ns-3 modules\n" |
531 " 1. Exit this shell, and start a new one\n" |
538 " 1. Exit this shell, and start a new one\n" |
532 " 2. Run a new nested shell") |
539 " 2. Run a new nested shell") |
533 raise Utils.WafError(msg) |
540 raise Utils.WafError(msg) |
534 |
541 |
535 |
542 |
536 def run_shell(): |
543 shell_context = Build.BuildContext |
|
544 def shell(ctx): |
|
545 """run a shell with an environment suitably modified to run locally built programs""" |
|
546 |
|
547 #make sure we build first" |
|
548 Scripting.build(ctx) |
|
549 |
537 if sys.platform == 'win32': |
550 if sys.platform == 'win32': |
538 shell = os.environ.get("COMSPEC", "cmd.exe") |
551 shell = os.environ.get("COMSPEC", "cmd.exe") |
539 else: |
552 else: |
540 shell = os.environ.get("SHELL", "/bin/sh") |
553 shell = os.environ.get("SHELL", "/bin/sh") |
541 |
554 |
542 env = Build.bld.env |
555 env = wutils.bld.env |
543 wutils.run_argv([shell], {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])}) |
556 wutils.run_argv([shell], {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])}) |
544 |
557 |
545 def doxygen(): |
558 def doxygen(): |
546 if not os.path.exists('doc/introspected-doxygen.h'): |
559 if not os.path.exists('doc/introspected-doxygen.h'): |
547 Logs.warn("doc/introspected-doxygen.h does not exist; run waf check to generate it.") |
560 Logs.warn("doc/introspected-doxygen.h does not exist; run waf check to generate it.") |
596 import Scripting |
609 import Scripting |
597 from Scripting import dist_exts, excludes, BLDDIR |
610 from Scripting import dist_exts, excludes, BLDDIR |
598 import Utils |
611 import Utils |
599 import os |
612 import os |
600 |
613 |
601 def copytree(src, dst, symlinks=False, excludes=(), build_dir=None): |
614 def _copytree(src, dst, symlinks=False, excludes=(), build_dir=None): |
602 """Recursively copy a directory tree using copy2(). |
615 """Recursively copy a directory tree using copy2(). |
603 |
616 |
604 The destination directory must not already exist. |
617 The destination directory must not already exist. |
605 If exception(s) occur, an Error is raised with a list of reasons. |
618 If exception(s) occur, an Error is raised with a list of reasons. |
606 |
619 |
666 if errors: |
679 if errors: |
667 raise shutil.Error, errors |
680 raise shutil.Error, errors |
668 |
681 |
669 |
682 |
670 def DistDir(appname, version): |
683 def DistDir(appname, version): |
671 "make a distribution directory with all the sources in it" |
684 #"make a distribution directory with all the sources in it" |
672 import shutil |
685 import shutil |
673 |
686 |
674 # Our temporary folder where to put our files |
687 # Our temporary folder where to put our files |
675 TMPFOLDER=appname+'-'+version |
688 TMPFOLDER=appname+'-'+version |
676 |
689 |
681 |
694 |
682 # Remove the Build dir |
695 # Remove the Build dir |
683 build_dir = getattr(Utils.g_module, BLDDIR, None) |
696 build_dir = getattr(Utils.g_module, BLDDIR, None) |
684 |
697 |
685 # Copy everything into the new folder |
698 # Copy everything into the new folder |
686 copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir) |
699 _copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir) |
687 |
700 |
688 # TODO undocumented hook |
701 # TODO undocumented hook |
689 dist_hook = getattr(Utils.g_module, 'dist_hook', None) |
702 dist_hook = getattr(Utils.g_module, 'dist_hook', None) |
690 if dist_hook: |
703 if dist_hook: |
691 os.chdir(TMPFOLDER) |
704 os.chdir(TMPFOLDER) |