Add new configuration option¶
This document is a guide for Modules developers that wish to introduce a new configuration option for the module command.
Core code¶
Introducing new configuration option means declaring it then using it (get its
value then branch code in modulecmd.tcl script to adapt
module command behavior.
First declare configuration option in
g_config_defsdefinition arrayFile to edit:
tcl/init.tcl.inExample commit: 2199edf8
New configuration option name should be short yet understandable. If composed of multiple words, they should be joined by
_character. Option value could be superseded by an environment variable, using same name than config, upper-cased and prefixed byMODULES_.Entry in
g_config_defsdefinition array uses option name as key then a list as value composed with:Superseding environment variable
Default value
Is configuration lockable to default value (0 or 1)
Value kind (
ifor integer,sfor string,bfor boolean,lfor colon-separated list,ofor other)Valid value list (empty list if no validation list)
Internal value representation (optional)
Specific procedure to call to initialize option value (optional)
Valid value list kind (empty string,
intbeoreltlist)
Update the Tcl code that compose the
modulecmd.tclscript to adapt behavior depending on the value defined (by default or superseded) for the configuration option. Use thegetConfhelper procedure to fetch configuration option value. This part highly depends on the kind of configuration option introduced.File to edit: file(s) in
tcl/directoryExample commit: 4baf5dc4
Installation scripts¶
If the default value of the configuration option may be selected at
installation time, an installation option should be added on the
configure script.
Define installation option argument in
configurescript, add it to the internal help message of this shell script, define an internal<optionname>variable that is set to the default installation option value, then updated when install option argument is set.File to edit:
configureExample commit: c00ecefa
Define the
<optionname>variable inMakefile.inc.inset to the@<optionname>@mark, that will be replaced by chosen value for option whenconfigurescript will generateMakefile.inc. Define theinstall_<optionname>variable insite.exp.into get value set for option within testsuite. Updatetranslate-in-scriptrule inMakefileto add translation of the@<optionname>@mark into selected value.Files to edit:
Makefile.inc.inMakefilesite.exp.in
Example commit: c00ecefa
Set the
@<optionname>@mark as the default value for configuration option ing_config_defsdefinition array in Tcl core codeFile to edit:
tcl/init.tcl.inExample commit: c00ecefa
When the make installation step is performed the
modulecmd.tclscript file is generated with the@<optionname>@mark replaced by selected default value.
Initialization scripts¶
New configuration option should be referred in the shell completion scripts as
argument for the config sub-command.
Files that should be edited to add reference to the new option:
init/Makefile(contains definitions to build bash and tcsh completion scriptsinit/fish_completioninit/zsh-functions/_module.in
Example commit: abfef4ed
Documentation¶
Man pages and other user documentation have to be updated to describe the introduced option.
Files that should be edited:
doc/source/module.rst(module manpage)add configuration option description with
mconfiganchor underconfigsub-command sectionadd environment variable description with
envvaranchor under ENVIRONMENT section
doc/source/changes.rstadd configuration option under Modules configuration options section of current Modules major version
add environment variable under Environment section of current Modules major version
INSTALL.rstadd configuration and related environment variable and installation option in the table under Configuration options section
Example commits:
In case an installation option has been added, it should be covered by documentation
File to edit:
INSTALL.rstExample commit: 3d19ab52
Testsuite¶
Non-regression testsuite must be adapted first to ensure existing tests still pass then to add specific tests to check the behavior of the added configuration option and ensure overall code coverage does not drop.
First, clear the run test environment from predefined configuration value, set over the associated environment variable.
Files that should be edited:
testsuite/modules.00-init/010-environ.exptestsuite/install.00-init/010-environ.exp
Example commit: 1c9fe1bd
If default value for option could be set at installation time, it may be important to take this chosen default value into account, thanks to the
install_<optionname>Tcl variable set insite.exp.Add new configuration option to the list of options tested over the
configsub-command.File to edit:
testsuite/modules.70-maint/220-config.expExample commit: 1c9fe1bd
Craft specific tests to validate the correct behavior of the configuration when not set, set with valid or invalid values.
File to edit: depends on what is impacted by the new configuration option, if some tests already exist for concerned behavior (existing testsuite file to update) or not (new testfile to create).
Example commit: 122039e5
Optionally if a new installation option has been introduced, it may be interesting to adapt CI configuration to test a value different than the default one
Files to either edit:
.cirrus.yml.github/workflows/linux_tests.yaml
Example commit: 8bf6fb54