Repository: spack/spack

Issue:
cannot specify multiple cflags on the command line
In the current origin/develop version of spack (presently e6cae97), I cannot figure out how to specify multiple cflags on the command line.

### Steps to reproduce the issue

```console
$ spack spec coreutils cflags="-g -fno-omit-frame-pointer"
```

### Error Message

```console
Input spec
--------------------------------
coreutils cflags="-g" ~fno-omit-frame-pointer

Concretized
--------------------------------
==> Error: Package coreutils has no variant fno-omit-frame-pointer!
```

If I check out revision a940ff34d and run the same command, then it works as expected:

```console
Input spec
--------------------------------
coreutils cflags="-g -fno-omit-frame-pointer" 

Concretized
--------------------------------
coreutils@8.29%gcc@8.3.0 cflags="-g -fno-omit-frame-pointer"  arch=linux-ubuntu19.04-x86_64
```

It appears as though the argument encapsulated with quotation marks are being split when they were not before.  Is there a different way to escape or group things like this now?

### Information on your system

Ubuntu 19.04

I don't believe the packages.yaml or package I am installing matters.  I just use coreutils as an example because it is simple in terms of dependencies.





Discussion:
Anyone have an idea for a workaround?  This gets more problematic for debugging as origin/develop (and all of its package updates) diverges further from the working revision of spack.
@carns Saw this issue right now. I need to investigate in which commit this broke, but apparently you can work around it by escaping spaces in your `cflags`:
```console
$ spack spec coreutils cflags="-g\ -fno-omit-frame-pointer"
Input spec
--------------------------------
coreutils cflags="-g -fno-omit-frame-pointer" 

Concretized
--------------------------------
coreutils@8.29%gcc@9.0.1 cflags="-g -fno-omit-frame-pointer"  arch=linux-ubuntu18.04-broadwell
```
Ah, thank you for the workaround.  That will be helpful until a fix is in place.
It seems this broke after merging #3206. Will investigate further on the issue.

Resolving patch:
diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py
--- a/lib/spack/spack/cmd/__init__.py
+++ b/lib/spack/spack/cmd/__init__.py
@@ -24,6 +24,7 @@
 import spack.spec
 import spack.store
 import spack.util.spack_json as sjson
+import spack.util.string
 from spack.error import SpackError
 
 
@@ -134,7 +135,9 @@ def parse_specs(args, **kwargs):
     tests = kwargs.get('tests', False)
 
     try:
-        sargs = args if isinstance(args, six.string_types) else ' '.join(args)
+        sargs = args
+        if not isinstance(args, six.string_types):
+            sargs = ' '.join(spack.util.string.quote(args))
         specs = spack.spec.parse(sargs)
         for spec in specs:
             if concretize:


Test patch:
diff --git a/lib/spack/spack/test/cmd/common/arguments.py b/lib/spack/spack/test/cmd/common/arguments.py
--- a/lib/spack/spack/test/cmd/common/arguments.py
+++ b/lib/spack/spack/test/cmd/common/arguments.py
@@ -9,6 +9,7 @@
 import pytest
 
 
+import spack.cmd
 import spack.cmd.common.arguments as arguments
 import spack.config
 
@@ -62,3 +63,20 @@ def test_negative_integers_not_allowed_for_parallel_jobs(parser):
         parser.parse_args(['-j', '-2'])
 
     assert 'expected a positive integer' in str(exc_info.value)
+
+
+@pytest.mark.parametrize('specs,expected_variants,unexpected_variants', [
+    (['coreutils', 'cflags=-O3 -g'], [], ['g']),
+    (['coreutils', 'cflags=-O3', '-g'], ['g'], []),
+])
+@pytest.mark.regression('12951')
+def test_parse_spec_flags_with_spaces(
+        specs, expected_variants, unexpected_variants
+):
+    spec_list = spack.cmd.parse_specs(specs)
+    assert len(spec_list) == 1
+
+    s = spec_list.pop()
+
+    assert all(x not in s.variants for x in unexpected_variants)
+    assert all(x in s.variants for x in expected_variants)