Make examples and tests be enabled from the .ns3rc file
This commit is contained in:
@@ -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.
|
||||
|
||||
60
utils.py
60
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
|
||||
|
||||
@@ -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
|
||||
|
||||
48
wscript
48
wscript
@@ -30,11 +30,15 @@ import Scripting
|
||||
|
||||
from utils import read_config_file
|
||||
|
||||
# By default, all modules will be enabled.
|
||||
# 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 = "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'):
|
||||
|
||||
Reference in New Issue
Block a user