Repository: spack/spack

Issue:
run_env.append_flags() doesn't appear to work
In `setup_environment(self, spack_env, run_env)`, calling `run_env.append_flags()` doesn't seem to do anything to the produced module file:
`run_env.append_flags('LDFLAGS', '-lflang')`
```
----------------------------------------------------------------------------------
-----------------------------------
whatis("Flang is a Fortran compiler targeting LLVM. ")
prepend_path("PATH","spack_root/opt/spack/linux-rhel7-x86_64/cla
ng-7.0.0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/bin")
prepend_path("LD_LIBRARY_PATH","spack_root/opt/spack/linux-rhel7
-x86_64/clang-7.0.0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/lib")
prepend_path("LIBRARY_PATH","spack_root/opt/spack/linux-rhel7-x8
6_64/clang-7.0.0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/lib")
prepend_path("CPATH","spack_root/opt/spack/linux-rhel7-x86_64/cl
ang-7.0.0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/include")
prepend_path("CMAKE_PREFIX_PATH","spack_root/opt/spack/linux-rhe
l7-x86_64/clang-7.0.0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/")
prepend_path("CPATH","spack_root/opt/spack/linux-rhel7-x86_64/cl
ang-7.0.0/libxml2-2.9.8-c2mmc7mjc5ueuggrih5vaaxtnbwf46fd/include/libxml2")
setenv("FC","spack_root/opt/spack/linux-rhel7-x86_64/clang-7.0.0
/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/bin/flang")
setenv("F77","spack_root/opt/spack/linux-rhel7-x86_64/clang-7.0.
0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/bin/flang")
setenv("F90","spack_root/opt/spack/linux-rhel7-x86_64/clang-7.0.
0/flang-20181226-vvb75vzgebl6pvtyhy3okiovrutlo35r/bin/flang")
help([[Flang is a Fortran compiler targeting LLVM.
]])
```

run_env.set() does work:
`run_env.set('LDFLAGS', '-lflang')`
```
[...]
setenv("LDFLAGS","-lflang")
help([[Flang is a Fortran compiler targeting LLVM.
]])
```
Fix append_flag for module files
Resolves [#10299](https://github.com/spack/spack/issues/10299)

`run_env.append_flags('LDFLAGS', '-lflang')` was not making any changes in the module file when being called in `setup_environment(self, spack_env, run_env)`. Other commands work, such as `run_env.set('LDFLAGS', '-lflang')` but not append_flag


Discussion:

Restarting tests so required can hopefully run
Should we merge this @tgamblin?
It would be good if we can add a test and merge this.
I still think it would be good to add a test and get this merged. Added to v0.19.2 milestone

Resolving patch:
diff --git a/var/spack/repos/builtin.mock/packages/module-path-separator/package.py b/var/spack/repos/builtin.mock/packages/module-path-separator/package.py
--- a/var/spack/repos/builtin.mock/packages/module-path-separator/package.py
+++ b/var/spack/repos/builtin.mock/packages/module-path-separator/package.py
@@ -20,3 +20,6 @@ def setup_run_environment(self, env):
         env.append_path("SEMICOLON", "bar", separator=";")
         env.prepend_path("SEMICOLON", "bar", separator=";")
         env.remove_path("SEMICOLON", "bar", separator=";")
+
+        env.append_flags("SPACE", "qux")
+        env.remove_flags("SPACE", "qux")


Test patch:
diff --git a/lib/spack/spack/test/modules/lmod.py b/lib/spack/spack/test/modules/lmod.py
--- a/lib/spack/spack/test/modules/lmod.py
+++ b/lib/spack/spack/test/modules/lmod.py
@@ -144,6 +144,8 @@ def test_prepend_path_separator(self, modulefile_content, module_configuration):
         assert len([x for x in content if 'append_path("SEMICOLON", "bar", ";")' in x]) == 1
         assert len([x for x in content if 'prepend_path("SEMICOLON", "bar", ";")' in x]) == 1
         assert len([x for x in content if 'remove_path("SEMICOLON", "bar", ";")' in x]) == 1
+        assert len([x for x in content if 'append_path("SPACE", "qux", " ")' in x]) == 1
+        assert len([x for x in content if 'remove_path("SPACE", "qux", " ")' in x]) == 1
 
     @pytest.mark.parametrize("config_name", ["exclude", "blacklist"])
     def test_exclude(self, modulefile_content, module_configuration, config_name):
diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py
--- a/lib/spack/spack/test/modules/tcl.py
+++ b/lib/spack/spack/test/modules/tcl.py
@@ -120,6 +120,8 @@ def test_prepend_path_separator(self, modulefile_content, module_configuration):
         assert len([x for x in content if 'append-path --delim ";" SEMICOLON "bar"' in x]) == 1
         assert len([x for x in content if 'prepend-path --delim ";" SEMICOLON "bar"' in x]) == 1
         assert len([x for x in content if 'remove-path --delim ";" SEMICOLON "bar"' in x]) == 1
+        assert len([x for x in content if 'append-path --delim " " SPACE "qux"' in x]) == 1
+        assert len([x for x in content if 'remove-path --delim " " SPACE "qux"' in x]) == 1
 
     @pytest.mark.parametrize("config_name", ["exclude", "blacklist"])
     def test_exclude(self, modulefile_content, module_configuration, config_name):