Skip to content

Commit

Permalink
rework sourcing of MODULES_SITECONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
nanobowers committed Mar 19, 2019
1 parent 03d68c2 commit 08c77a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
7 changes: 4 additions & 3 deletions doc/source/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ Modulecmd startup
^^^^^^^^^^^^^^^^^

Upon invocation **modulecmd.tcl** sources a site-specific configuration
script if it exists. The default location for this script is in
|emph etcdir|\ */siteconfig.tcl*, though this default file location may be
overridden by specifying the *$MODULES_SITECONFIG* environment variable.
script if it exists. The location for this script is in
|emph etcdir|\ */siteconfig.tcl*. An additional siteconfig path may be
specified with the *$MODULES_SITECONFIG* environment variable and will be
loaded after |emph etcdir|\ */siteconfig.tcl*, if it exists.
This Tcl script enables to supersede any global variable or procedure
definition of **modulecmd.tcl**.

Expand Down
36 changes: 16 additions & 20 deletions modulecmd.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ set reportfd stderr ;# File descriptor to use to report messages
set g_pager {@pager@} ;# Default command to page into, empty=disable
set g_pager_opts {@pageropts@} ;# Options to pass to the pager command

# Get site config which can be used to define global procedures or settings
proc getSiteConfig {} {
if {![info exist ::g_siteconfig]} {
# default value set at configure time
set site_config @etcdir@/siteconfig.tcl
set g_siteconfig @etcdir@/siteconfig.tcl

# overriden value coming from environment
if {[info exist ::env(MODULES_SITECONFIG)]} {
set site_config $::env(MODULES_SITECONFIG)
reportDebug "Overriding g_siteconfig with $::env(MODULES_SITECONFIG)"
# Source site config which can be used to define global procedures or
# settings. We first look for the global siteconfig, then if
# $MODULES_SITECONFIG exists will source that.
proc sourceSiteConfig {} {
set siteConfigs [list $::g_siteconfig]
if {[info exist ::env(MODULES_SITECONFIG)]} {
lappend siteConfigs $::env(MODULES_SITECONFIG)
}
foreach config $siteConfigs {
if {[file readable $config]} {
reportDebug "Source site configuration ($config)"
if {[catch {source $config} errMsg]} {
reportErrorAndExit "Site configuration source failed\n$errMsg"
}
}

set ::g_siteconfig $site_config
reportDebug "site_config set to '$site_config'"
}

return $::g_siteconfig
}

# Used to tell if a machine is running Windows or not
Expand Down Expand Up @@ -8260,12 +8261,7 @@ if {[catch {
reportDebug "CALLING $argv0 $argv"

# source site configuration script if any
if {[file readable [getSiteConfig]]} {
reportDebug "Source site configuration ([getSiteConfig])"
if {[catch {source [getSiteConfig]} errMsg]} {
reportErrorAndExit "Site configuration source failed\n$errMsg"
}
}
sourceSiteConfig

# Parse shell
set g_shell [lindex $argv 0]
Expand Down

0 comments on commit 08c77a9

Please sign in to comment.