From 46d63e113babcb3c9ccbdb1e93020e14df9b3f9c Mon Sep 17 00:00:00 2001
From: Mitch Watrous
Date: Tue, 12 Apr 2011 10:39:17 -0700
Subject: [PATCH 1/5] Make examples and tests be enabled from the .ns3rc file
---
src/wscript | 4 ++++
utils.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++-----
utils/.ns3rc | 6 ++++++
wscript | 52 +++++++++++++++++++++++++++++++++++----------
4 files changed, 106 insertions(+), 16 deletions(-)
diff --git a/src/wscript b/src/wscript
index afc1e12f6..19e71f02a 100644
--- a/src/wscript
+++ b/src/wscript
@@ -105,6 +105,10 @@ def create_ns3_module(bld, name, dependencies=(), test=False):
pcfile = bld.new_task_gen('ns3pcfile')
pcfile.module = module
+ # Initially create an empty value for this because the pcfile
+ # writing task assumes every module has a uselib attribute.
+ module.uselib = ''
+
module.is_ns3_module = True
module.name = 'ns3-' + name
# Add the proper path to the module's name.
diff --git a/utils.py b/utils.py
index e36e20acb..4ffe9632d 100644
--- a/utils.py
+++ b/utils.py
@@ -44,6 +44,38 @@ def get_list_from_file(file_path, list_name):
return list
+def get_bool_from_file(file_path, bool_name, value_if_missing):
+ '''Looks for a Python boolean variable called bool_name in the
+ file specified by file_path and returns its value.
+
+ If the file or boolean variable aren't found, this function will
+ return value_if_missing.
+
+ '''
+
+ # Read in the file if it exists.
+ if os.path.exists(file_path):
+ file_in = open(file_path, "r")
+
+ # Look for the boolean variable.
+ bool_found = False
+ for line in file_in:
+ if bool_name in line:
+ # Evaluate the variable's line once it is found. Make
+ # the split function only split it once.
+ bool = eval(line.split('=', 1)[1].strip())
+ bool_found = True
+ break
+
+ # Close the file
+ file_in.close()
+
+ if bool_found:
+ return bool
+ else:
+ return value_if_missing
+
+
def read_config_file():
'''Reads the NS-3 configuration file and returns a list of enabled modules.
@@ -53,20 +85,38 @@ def read_config_file():
'''
+ # By default, all modules will be enabled, examples will be enabled,
+ # and tests will be disabled.
+ modules_enabled = ['all_modules']
+ examples_enabled = True
+ tests_enabled = False
+
# See if the ns3 configuration file exists in the current working
# directory and then look for it in the ~ directory.
+ config_file_exists = False
dot_ns3rc_name = '.ns3rc'
dot_ns3rc_path = dot_ns3rc_name
if not os.path.exists(dot_ns3rc_path):
dot_ns3rc_path = os.path.expanduser('~/') + dot_ns3rc_name
if not os.path.exists(dot_ns3rc_path):
- # Enable all modules if the .ns3rc file can't be found.
- return ['all_modules']
+ # Return all of the default values if the .ns3rc file can't be found.
+ return (config_file_exists, modules_enabled, examples_enabled, tests_enabled)
- # Read in the ns3 configuration file.
+ config_file_exists = True
+
+ # Read in the enabled modules.
modules_enabled = get_list_from_file(dot_ns3rc_path, 'modules_enabled')
if not modules_enabled:
# Enable all modules if the modules_enabled line can't be found.
- return ['all_modules']
+ modules_enabled = ['all_modules']
+
+ # Read in whether examples should be enabled or not.
+ value_if_missing = True
+ examples_enabled = get_bool_from_file(dot_ns3rc_path, 'examples_enabled', value_if_missing)
+
+ # Read in whether tests should be enabled or not.
+ value_if_missing = False
+ tests_enabled = get_bool_from_file(dot_ns3rc_path, 'tests_enabled', value_if_missing)
+
+ return (config_file_exists, modules_enabled, examples_enabled, tests_enabled)
- return modules_enabled
diff --git a/utils/.ns3rc b/utils/.ns3rc
index 68647fca5..8d88d94fb 100644
--- a/utils/.ns3rc
+++ b/utils/.ns3rc
@@ -5,3 +5,9 @@
#
# All modules can be enabled by choosing 'all_modules'.
modules_enabled = ['all_modules']
+
+# Set this equal to true if you want examples to be run.
+examples_enabled = True
+
+# Set this equal to true if you want tests to be run.
+tests_enabled = False
diff --git a/wscript b/wscript
index ce3f33e15..fe33c46c3 100644
--- a/wscript
+++ b/wscript
@@ -30,11 +30,15 @@ import Scripting
from utils import read_config_file
-# By default, all modules will be enabled.
-modules_enabled = ['all_modules']
+# By default, all modules will be enabled, examples will be enabled,
+# and tests will be disabled.
+modules_enabled = ['all_modules']
+examples_enabled = True
+tests_enabled = False
-# Get the list of enabled modules out of the NS-3 configuration file.
-modules_enabled = read_config_file()
+# Get the information out of the NS-3 configuration file.
+config_file_exists = False
+(config_file_exists, modules_enabled, examples_enabled, tests_enabled) = read_config_file()
sys.path.insert(0, os.path.abspath('waf-tools'))
try:
@@ -163,14 +167,16 @@ def set_options(opt):
default=False)
opt.add_option('--disable-tests',
help=('Do not build the ns-3 tests.'),
- dest='enable_tests', action='store_false')
+ dest='disable_tests', action='store_true',
+ default=False)
opt.add_option('--enable-examples',
help=('Build the ns-3 examples and samples.'),
dest='enable_examples', action='store_true',
- default=True)
+ default=False)
opt.add_option('--disable-examples',
help=('Do not build the ns-3 examples and samples.'),
- dest='enable_examples', action='store_false')
+ dest='disable_examples', action='store_true',
+ default=False)
opt.add_option('--check',
help=('DEPRECATED (run ./test.py)'),
default=False, dest='check', action="store_true")
@@ -321,21 +327,45 @@ def configure(conf):
conf.report_optional_feature("ENABLE_SUDO", "Use sudo to set suid bit", env['ENABLE_SUDO'], why_not_sudo)
+ # Decide if tests will be built or not.
if Options.options.enable_tests:
+ # Tests were explicitly enabled.
env['ENABLE_TESTS'] = True
why_not_tests = "option --enable-tests selected"
- else:
+ elif Options.options.disable_tests:
+ # Tests were explicitly disabled.
env['ENABLE_TESTS'] = False
- why_not_tests = "defaults to disabled"
+ why_not_tests = "option --disable-tests selected"
+ else:
+ # Enable tests based on the ns3 configuration file.
+ env['ENABLE_TESTS'] = tests_enabled
+ if config_file_exists:
+ why_not_tests = "based on configuration file"
+ elif tests_enabled:
+ why_not_tests = "defaults to enabled"
+ else:
+ why_not_tests = "defaults to disabled"
conf.report_optional_feature("ENABLE_TESTS", "Build tests", env['ENABLE_TESTS'], why_not_tests)
+ # Decide if examples will be built or not.
if Options.options.enable_examples:
+ # Examples were explicitly enabled.
env['ENABLE_EXAMPLES'] = True
- why_not_examples = "defaults to enabled"
- else:
+ why_not_examples = "option --enable-examples selected"
+ elif Options.options.disable_examples:
+ # Examples were explicitly disabled.
env['ENABLE_EXAMPLES'] = False
why_not_examples = "option --disable-examples selected"
+ else:
+ # Enable examples based on the ns3 configuration file.
+ env['ENABLE_EXAMPLES'] = examples_enabled
+ if config_file_exists:
+ why_not_examples = "based on configuration file"
+ elif examples_enabled:
+ why_not_examples = "defaults to enabled"
+ else:
+ why_not_examples = "defaults to disabled"
env['EXAMPLE_DIRECTORIES'] = []
for dir in os.listdir('examples'):
From 1f9ea7d2ef55f8ba3a9075ece4ffc4ff3f81a9f2 Mon Sep 17 00:00:00 2001
From: Mitch Watrous
Date: Tue, 12 Apr 2011 14:35:16 -0700
Subject: [PATCH 2/5] Make examples not be built by default
---
CHANGES.html | 8 +++----
doc/build.txt | 4 ++--
doc/manual/source/attributes.rst | 4 ++--
doc/manual/source/click.rst | 2 +-
doc/manual/source/distributed.rst | 2 +-
doc/manual/source/openflow-switch.rst | 2 +-
doc/manual/source/tcp.rst | 2 +-
doc/release_steps.txt | 2 +-
doc/testing/source/testing-framework.rst | 5 ++--
doc/tutorial/source/conceptual-overview.rst | 4 ++--
doc/tutorial/source/getting-started.rst | 26 ++++++++++-----------
utils.py | 6 ++---
utils/.ns3rc | 2 +-
wscript | 4 ++--
14 files changed, 37 insertions(+), 36 deletions(-)
diff --git a/CHANGES.html b/CHANGES.html
index 34a35e960..ab80d15b8 100644
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -48,17 +48,17 @@ us a note on ns-developers mailing list.
Changes to build system: