Repository: spack/spack

Issue:
`require` does not work with `cflags=`
### Steps to reproduce

Adding `cflags=` to the spec in `packages:<apps>:require:` throws an error. Interestingly, using variants with the equals sign works fine.

### Error message

```
[ec2-user@ip-10-12-10-115 ]$ spack config rm packages:openfoam
[ec2-user@ip-10-12-10-115 ]$ spack config add packages:openfoam:require:"openfoam@2006_220610 ^scotch@6.0.9"
[ec2-user@ip-10-12-10-115 ]$ spack spec -U openfoam 1>/dev/null; echo $?
0
[ec2-user@ip-10-12-10-115 ]$ spack config rm packages:openfoam
[ec2-user@ip-10-12-10-115 ]$ spack config add packages:openfoam:require:"openfoam@2006_220610 scotch=False"
[ec2-user@ip-10-12-10-115 ]$ spack spec -U openfoam 1>/dev/null; echo $?
0
[ec2-user@ip-10-12-10-115 ]$ spack config rm packages:openfoam
[ec2-user@ip-10-12-10-115 ]$ spack config add packages:openfoam:require:"openfoam@2006_220610 cflags=foo"
[ec2-user@ip-10-12-10-115 ]$ spack spec -U openfoam 1>/dev/null; echo $?
==> Error: Cannot satisfy the requirements in packages.yaml for the 'openfoam' package. You may want to delete them to proceed with concretization. To check where the requirements are defined run 'spack config blame packages'
1
```

### Information on your system

* **Spack:** 0.20.0.dev0 (c6ee30497c59d19d78a9ccf48ce54fb7430818d3)
* **Python:** 3.7.10
* **Platform:** linux-amzn2-icelake
* **Concretizer:** clingo


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
Another reproducer:

This `packages.yaml` works:
```
packages:
  tar:
    require: 'tar zip=gzip'
```

however, this `packages.yaml` does not:
```
packages:
  tar:                        
    require: 'tar zip=gzip cflags=foo'
```


Resolving patch:
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -2463,11 +2463,16 @@ def reorder_flags(self):
 
                     # add flags from each source, lowest to highest precedence
                     for name in sorted_sources:
-                        source = self._specs[name] if name in self._hash_specs else cmd_specs[name]
-                        extend_flag_list(from_sources, source.compiler_flags.get(flag_type, []))
+                        all_src_flags = list()
+                        per_pkg_sources = [self._specs[name]]
+                        if name in cmd_specs:
+                            per_pkg_sources.append(cmd_specs[name])
+                        for source in per_pkg_sources:
+                            all_src_flags.extend(source.compiler_flags.get(flag_type, []))
+                        extend_flag_list(from_sources, all_src_flags)
 
                 # compiler flags from compilers config are lowest precedence
-                ordered_compiler_flags = from_compiler + from_sources
+                ordered_compiler_flags = list(llnl.util.lang.dedupe(from_compiler + from_sources))
                 compiler_flags = spec.compiler_flags.get(flag_type, [])
 
                 msg = "%s does not equal %s" % (set(compiler_flags), set(ordered_compiler_flags))


Test patch:
diff --git a/lib/spack/spack/test/concretize_requirements.py b/lib/spack/spack/test/concretize_requirements.py
--- a/lib/spack/spack/test/concretize_requirements.py
+++ b/lib/spack/spack/test/concretize_requirements.py
@@ -381,6 +381,22 @@ def test_one_package_multiple_oneof_groups(concretize_scope, test_repo):
     assert s2.satisfies("%gcc+shared")
 
 
+@pytest.mark.regression("34241")
+def test_require_cflags(concretize_scope, test_repo):
+    """Ensures that flags can be required from configuration."""
+    if spack.config.get("config:concretizer") == "original":
+        pytest.skip("Original concretizer does not support configuration" " requirements")
+
+    conf_str = """\
+packages:
+  y:
+    require: cflags="-g"
+"""
+    update_packages_config(conf_str)
+    spec = Spec("y").concretized()
+    assert spec.satisfies("cflags=-g")
+
+
 def test_requirements_for_package_that_is_not_needed(concretize_scope, test_repo):
     """Specify requirements for specs that are not concretized or
     a dependency of a concretized spec (in other words, none of