diff options
author | Massimiliano Culpo <massimiliano.culpo@googlemail.com> | 2016-10-12 07:55:14 +0200 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2016-10-11 22:55:14 -0700 |
commit | eb178956301fabf1cffe2cd3e947b311761e5ad8 (patch) | |
tree | 97fe41adc101a671a6ec4e442be10fa1fea0822b /lib/spack | |
parent | 949766d92eade0919a2fe2bdb95de21e7f990d91 (diff) | |
download | spack-eb178956301fabf1cffe2cd3e947b311761e5ad8.tar.gz spack-eb178956301fabf1cffe2cd3e947b311761e5ad8.tar.bz2 spack-eb178956301fabf1cffe2cd3e947b311761e5ad8.tar.xz spack-eb178956301fabf1cffe2cd3e947b311761e5ad8.zip |
environment modifications : permit to pass parameters along with file to be sourced (#1626)
Diffstat (limited to 'lib/spack')
-rw-r--r-- | lib/spack/spack/environment.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/data/sourceme_parameters.sh | 7 | ||||
-rw-r--r-- | lib/spack/spack/test/environment.py | 8 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index b0eadef7a6..de30a9c7be 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -271,8 +271,12 @@ class EnvironmentModifications(object): env = EnvironmentModifications() # Check if the files are actually there - if not all(os.path.isfile(file) for file in args): - raise RuntimeError('trying to source non-existing files') + files = [line.split(' ')[0] for line in args] + non_existing = [file for file in files if not os.path.isfile(file)] + if non_existing: + message = 'trying to source non-existing files\n' + message += '\n'.join(non_existing) + raise RuntimeError(message) # Relevant kwd parameters and formats info = dict(kwargs) info.setdefault('shell', '/bin/bash') diff --git a/lib/spack/spack/test/data/sourceme_parameters.sh b/lib/spack/spack/test/data/sourceme_parameters.sh new file mode 100644 index 0000000000..3826eb092b --- /dev/null +++ b/lib/spack/spack/test/data/sourceme_parameters.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +if [[ "$1" == "intel64" ]] ; then + export FOO='intel64' +else + export FOO='default' +fi
\ No newline at end of file diff --git a/lib/spack/spack/test/environment.py b/lib/spack/spack/test/environment.py index 9b5d75f273..c404433a56 100644 --- a/lib/spack/spack/test/environment.py +++ b/lib/spack/spack/test/environment.py @@ -119,7 +119,8 @@ class EnvironmentTest(unittest.TestCase): 'spack', 'test', 'data') files = [ join_path(datadir, 'sourceme_first.sh'), - join_path(datadir, 'sourceme_second.sh') + join_path(datadir, 'sourceme_second.sh'), + join_path(datadir, 'sourceme_parameters.sh intel64') ] env = EnvironmentModifications.from_sourcing_files(*files) modifications = env.group_by_name() @@ -134,6 +135,11 @@ class EnvironmentTest(unittest.TestCase): self.assertEqual(len(modifications['NEW_VAR']), 1) self.assertTrue(isinstance(modifications['NEW_VAR'][0], SetEnv)) self.assertEqual(modifications['NEW_VAR'][0].value, 'new') + + self.assertEqual(len(modifications['FOO']), 1) + self.assertTrue(isinstance(modifications['FOO'][0], SetEnv)) + self.assertEqual(modifications['FOO'][0].value, 'intel64') + # Unset variables self.assertEqual(len(modifications['EMPTY_PATH_LIST']), 1) self.assertTrue(isinstance( |