env modifications : added a validation rule
This commit is contained in:
parent
1e468c5541
commit
491babd5cd
@ -34,8 +34,9 @@
|
||||
import sys
|
||||
|
||||
import spack
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.filesystem import *
|
||||
from spack.environment import EnvironmentModifications, concatenate_paths
|
||||
from spack.environment import EnvironmentModifications, concatenate_paths, validate
|
||||
from spack.util.environment import *
|
||||
from spack.util.executable import Executable, which
|
||||
|
||||
@ -288,8 +289,7 @@ def setup_package(pkg):
|
||||
# Allow dependencies to set up environment as well
|
||||
for dependency_spec in pkg.spec.traverse(root=False):
|
||||
dependency_spec.package.setup_dependent_environment(env, pkg.spec)
|
||||
# TODO : implement validation
|
||||
#validate(env)
|
||||
validate(env, tty.warn)
|
||||
env.apply_modifications()
|
||||
|
||||
|
||||
|
@ -202,3 +202,33 @@ def concatenate_paths(paths):
|
||||
string
|
||||
"""
|
||||
return ':'.join(str(item) for item in paths)
|
||||
|
||||
|
||||
def set_or_unset_not_first(variable, changes, errstream):
|
||||
"""
|
||||
Check if we are going to set or unset something after other modifications have already been requested
|
||||
"""
|
||||
indexes = [ii for ii, item in enumerate(changes) if ii != 0 and type(item) in [SetEnv, UnsetEnv]]
|
||||
if indexes:
|
||||
good = '\t \t{context} at {filename}:{lineno}'
|
||||
nogood = '\t--->\t{context} at {filename}:{lineno}'
|
||||
errstream('Suspicious requests to set or unset the variable \'{var}\' found'.format(var=variable))
|
||||
for ii, item in enumerate(changes):
|
||||
print_format = nogood if ii in indexes else good
|
||||
errstream(print_format.format(**item.args))
|
||||
|
||||
|
||||
def validate(env, errstream):
|
||||
"""
|
||||
Validates the environment modifications to check for the presence of suspicious patterns. Prompts a warning for
|
||||
everything that was found
|
||||
|
||||
Current checks:
|
||||
- set or unset variables after other changes on the same variable
|
||||
|
||||
Args:
|
||||
env: list of environment modifications
|
||||
"""
|
||||
modifications = env.group_by_name()
|
||||
for variable, list_of_changes in sorted(modifications.items()):
|
||||
set_or_unset_not_first(variable, list_of_changes, errstream)
|
||||
|
Loading…
Reference in New Issue
Block a user