Repository: spack/spack

Issue:
Specifying more than one operating_system in the same compilers.yaml entry
For convenience, I'm using the same configuration files for two Macs that run a different MacOS version (one with Sierra, the other with High Sierra, but apart from that they are identical from spack's point of view: same compilers installed, same everything installed). Generated executables are exactly the same on both machines (exactly same compilers -custom build-, exactly same MacOS SDK, and exactly same ${MACOSX_DEPLOYMENT_TARGET} (ie: 10.12).

In fact, spack generates exactly the same `compilers.yaml` file on both machines, with the only difference that in one you see "sierra" for the `operating_system` entry, and in the other you see "highsierra".

Now, can I use the same `compilers.yaml` file for both machines? Apparently, `operating_system` will allow only one string, according to the schema. But is there any "dumb tag" that will allow both sierra and highsierra, or maybe even all MacOS versions? Or can I disable the `operating_system` entry in some way? If possible to disable, would it have any consequence on built packages?


Discussion:
Did you try merging the two `compilers.yaml` into a single file? Is that not working?
Yes, thanks, it seems to work!!

BTW, have you ever seen an error like this when executing `spack compiler info` on some compiler?

```
cesss$ spack compiler info clang@8.1.0-apple
clang@8.1.0-apple:
	paths:
		cc = /usr/bin/clang
		cxx = /usr/bin/clang++
		f77 = None
		fc = None
==> Error: 'set'
```

What does `==> Error: 'set'` mean? The interesting thing is that it happens for one compiler only, and that it's in a `compilers.yaml` file generated by `spack`, before my modifications.
@cesss Can you show the output of:
```console
$ spack -d compiler info
```
?
Sure!

```
cesss$ spack -d compiler info clang@8.1.0-apple
==> [2020-02-13-15:26:35.826934] Imported compiler from built-in commands
==> [2020-02-13-15:26:35.829337] Imported compiler from built-in commands
==> [2020-02-13-15:26:35.830055] Reading config file /Users/cesss/.spack/darwin/compilers.yaml
clang@8.1.0-apple:
	paths:
		cc = /usr/bin/clang
		cxx = /usr/bin/clang++
		f77 = None
		fc = None
==> [2020-02-13-15:26:35.845718] Reading config file /Users/cesss/spack/etc/spack/defaults/config.yaml
==> [2020-02-13-15:26:35.856527] Reading config file /Users/cesss/.spack/darwin/config.yaml
Traceback (most recent call last):
  File "/Users/cesss/spack/bin/spack", line 64, in <module>
    sys.exit(spack.main.main())
  File "/Users/cesss/spack/lib/spack/spack/main.py", line 754, in main
    return _invoke_command(command, parser, args, unknown)
  File "/Users/cesss/spack/lib/spack/spack/main.py", line 488, in _invoke_command
    return_val = command(parser, args)
  File "/Users/cesss/lib/spack/spack/cmd/compiler.py", line 182, in compiler
    action[args.compiler_command](args)
  File "/Users/cesss/spack/lib/spack/spack/cmd/compiler.py", line 145, in compiler_info
    if len(c.environment['set']) != 0:
  File "/Users/cesss/spack/lib/spack/external/ruamel/yaml/comments.py", line 426, in __getitem__
    return ordereddict.__getitem__(self, key)
KeyError: 'set'
```

BTW, this is not the compiler I'm going to use, but the one from Xcode... however this error puzzles me...
Next commands:
```console
$ cat /Users/cesss/.spack/darwin/config.yaml
$ cat /Users/cesss/.spack/darwin/compilers.yaml
```
It seems there's something wrong with the `environment` attribute missing a `set` key, either in the code or in the config.
I deleted my `config.yaml` so I'm now using the default, and the error and output is the same, so we can rule `config.yaml` out of being the cause. 

This is the `compilers.yaml` that triggers such error (generated by spack):

```
compilers:
- compiler:
    paths:
      cc: /usr/bin/clang
      cxx: /usr/bin/clang++
      f77:
      fc:
    operating_system: sierra
    target: x86_64
    modules: []
    environment:
      unset: []
    extra_rpaths: []
    flags: {}
    spec: clang@8.1.0-apple
- compiler:
    paths:
      cc:
      cxx:
      f77: /usr/local/bin/gfortran
      fc: /usr/local/bin/gfortran
    operating_system: sierra
    target: x86_64
    modules: []
    environment: {}
    extra_rpaths: []
    flags: {}
    spec: gcc@6.3.0
- compiler:
    paths:
      cc: /Users/cesss/MacOSX10.12-llvm7.0.0-x86_64/LLVM/7.0.0/bin/clang
      cxx: /Users/cesss/MacOSX10.12-llvm7.0.0-x86_64/LLVM/7.0.0/bin/clang++
      f77: /usr/local/bin/gfortran
      fc: /usr/local/bin/gfortran
    operating_system: sierra
    target: x86_64
    modules: []
    environment: {}
    extra_rpaths: []
    spec: clang@7.0.0

```

This happens on High Sierra. I can try if it also happens on Sierra, later.
BTW, I checked I'm back on default config by issuing `spack config get config` and seeing that actually I'm back to defaults
@cess Confirmed the behavior you see, that's definitely a bug.

Resolving patch:
diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py
--- a/lib/spack/spack/cmd/compiler.py
+++ b/lib/spack/spack/cmd/compiler.py
@@ -142,7 +142,7 @@ def compiler_info(args):
                 for flag, flag_value in iteritems(c.flags):
                     print("\t\t%s = %s" % (flag, flag_value))
             if len(c.environment) != 0:
-                if len(c.environment['set']) != 0:
+                if len(c.environment.get('set', {})) != 0:
                     print("\tenvironment:")
                     print("\t    set:")
                     for key, value in iteritems(c.environment['set']):


Test patch: