Repository: spack/spack

Issue:
==> Error: TypeError: expected str, bytes or os.PathLike object, not NoneType
<!-- Explain, in a clear and concise way, the command you ran and the result you were trying to achieve.
Example: "I ran `spack find` to list all the installed packages and ..." -->

### Steps to reproduce the issue

```console
(base) warndt@cori08:~> git clone https://github.com/spack/spack.git
Cloning into 'spack'...
remote: Enumerating objects: 79, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (69/69), done.
remote: Total 269924 (delta 28), reused 1 (delta 0), pack-reused 269845
Receiving objects: 100% (269924/269924), 108.53 MiB | 20.29 MiB/s, done.
Resolving deltas: 100% (113818/113818), done.
Checking out files: 100% (7834/7834), done.
(base) warndt@cori08:~> cd spack/bin
(base) warndt@cori08:~/spack/bin> ./spack install zlib
==> Installing zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa
==> No binary for zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa found: installing from source
==> Error: TypeError: expected str, bytes or os.PathLike object, not NoneType

/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py:872, in _setup_pkg_and_run:
        869        tb_string = traceback.format_exc()
        870
        871        # build up some context from the offending package so we can
  >>    872        # show that, too.
        873        package_context = get_package_context(tb)
        874
        875        logfile = None


(base) warndt@cori08:~/spack/bin>  

```

Also tried "libelf" instead of "zlib" and got same outcome.


### Information on your system

<!-- Please include the output of `spack debug report` -->

This is on Cori at NERSC. I also tried the spack install with our module. Same outcome.

(base) warndt@cori08:~/spack/bin> ./spack debug report
* **Spack:** 0.16.1-1694-f213cf8349
* **Python:** 3.7.4
* **Platform:** cray-sles15-haswell
* **Concretizer:** original

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### debug mode version
```
(base) warndt@cori08:~/spack/bin> ./spack -d install zlib
==> [2021-03-12-12:48:43.204085] '/bin/bash' '--norc' '--noprofile' '-lc' 'echo $CRAY_CPU_TARGET'
==> [2021-03-12-12:48:43.211558] default to front-end architecture
==> [2021-03-12-12:48:43.245154] Imported install from built-in commands
==> [2021-03-12-12:48:43.246504] Reading config file /global/u1/w/warndt/spack/etc/spack/defaults/config.yaml
==> [2021-03-12-12:48:43.268471] Imported install from built-in commands
==> [2021-03-12-12:48:43.269690] Reading config file /global/u1/w/warndt/spack/etc/spack/defaults/repos.yaml
==> [2021-03-12-12:48:43.530262] Reading config file /global/u1/w/warndt/spack/etc/spack/defaults/packages.yaml
==> [2021-03-12-12:48:43.560194] Reading config file /global/homes/w/warndt/.spack/cray/compilers.yaml
==> [2021-03-12-12:48:44.283559] '/bin/bash' '--norc' '--noprofile' '-lc' 'echo $CRAY_CPU_TARGET'
==> [2021-03-12-12:48:44.290836] default to front-end architecture
==> [2021-03-12-12:48:44.309215] DATABASE LOCK TIMEOUT: 3s
==> [2021-03-12-12:48:44.309310] PACKAGE LOCK TIMEOUT: No timeout
==> [2021-03-12-12:48:44.314067] Initializing the build queue from the build requests
==> [2021-03-12-12:48:44.314143] Initializing the build queue for zlib
==> [2021-03-12-12:48:44.314731] Processing dependencies for zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa: ('build', 'link', 'run')
==> [2021-03-12-12:48:44.329885] Removing failure marking for zlib
==> [2021-03-12-12:48:44.330363] Pkg id zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa has the following dependents:
==> [2021-03-12-12:48:44.333581] Ensure all dependencies know all dependents across specs
==> [2021-03-12-12:48:44.334177] Acquiring a write lock on zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa with timeout 1e-09
==> [2021-03-12-12:48:44.336984] Creating stage lock spack-stage-zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa
==> [2021-03-12-12:48:44.338185] Installing zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa
==> [2021-03-12-12:48:44.338263] Searching for binary cache of zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa
==> [2021-03-12-12:48:44.338437] Reading config file /global/u1/w/warndt/spack/etc/spack/defaults/mirrors.yaml
==> [2021-03-12-12:48:44.473550] Did not find cray-cnl7-haswell-gcc-9.2.0-zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa.spec.yaml on https://spack-llnl-mirror.s3-us-west-2.amazonaws.com/build_cache/cray-cnl7-haswell-gcc-9.2.0-zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa.spec.yaml
  Download failed: HTTP Error 404: Not Found
==> [2021-03-12-12:48:44.475269] No binary for zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa found: installing from source
==> [2021-03-12-12:48:51.525611] [TOOLCHAIN] MATCH Cce
==> [2021-03-12-12:48:53.735443] A dependency has updated CPATH, this may lead pkg-config to assume that the package is part of the system includes and omit it when invoked with '--cflags'.
==> [2021-03-12-12:48:54.217550] Module name: gcc/9.2.0
==> [2021-03-12-12:48:54.217788] Package directory variable prefix: GCC
==> [2021-03-12-12:48:54.228218] Error: TypeError: expected str, bytes or os.PathLike object, not NoneType

/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py:872, in _setup_pkg_and_run:
        869        tb_string = traceback.format_exc()
        870
        871        # build up some context from the offending package so we can
  >>    872        # show that, too.
        873        package_context = get_package_context(tb)
        874
        875        logfile = None


Traceback (most recent call last):
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py", line 855, in _setup_pkg_and_run
    context=context)
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py", line 753, in setup_package
    set_module_variables_for_package(pkg)
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py", line 544, in set_module_variables_for_package
    _set_variables_for_single_module(pkg, mod)
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py", line 487, in _set_variables_for_single_module
    m.std_cmake_args = spack.build_systems.cmake.CMakePackage._std_args(pkg)
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_systems/cmake.py", line 187, in _std_args
    spack.build_environment.get_rpaths(pkg)),
  File "/global/u1/w/warndt/spack/lib/spack/spack/build_environment.py", line 656, in get_rpaths
    return list(dedupe(filter_system_paths(rpaths)))
  File "/global/u1/w/warndt/spack/lib/spack/spack/util/environment.py", line 61, in filter_system_paths
    return [p for p in paths if not is_system_path(p)]
  File "/global/u1/w/warndt/spack/lib/spack/spack/util/environment.py", line 61, in <listcomp>
    return [p for p in paths if not is_system_path(p)]
  File "/global/u1/w/warndt/spack/lib/spack/spack/util/environment.py", line 56, in is_system_path
    return os.path.normpath(path) in system_dirs
  File "/global/common/cori_cle7/software/python/3.7-anaconda-2019.10/lib/python3.7/posixpath.py", line 340, in normpath
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
==> [2021-03-12-12:48:54.228580] Flagging zlib-1.2.11-qc2sg7pqaekt7vmovo4jzn33gjm4wtaa as failed: TypeError: expected str, bytes or os.PathLike object, not NoneType
==> [2021-03-12-12:48:54.232688] ChildError: TypeError: expected str, bytes or os.PathLike object, not NoneType
```

### Additional information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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

<!-- We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively!

If you want to ask a question about the tool (how to use it, what it can currently do, etc.), try the `#general` channel on our Slack first. We have a welcoming community and chances are you'll get your reply faster and without opening an issue.

Other than that, thanks for taking the time to contribute to Spack! -->



Discussion:
I had old junk somewhere in .spack/ referring to gcc 9.2 which is not present on the system. blowing everything away and starting fresh worked.

the error messages here could be better

Resolving patch:
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -59,7 +59,7 @@ def is_system_path(path):
     Returns:
         True or False
     """
-    return os.path.normpath(path) in system_dirs
+    return path and os.path.normpath(path) in system_dirs
 
 
 def filter_system_paths(paths):


Test patch:
diff --git a/lib/spack/spack/test/util/environment.py b/lib/spack/spack/test/util/environment.py
--- a/lib/spack/spack/test/util/environment.py
+++ b/lib/spack/spack/test/util/environment.py
@@ -22,6 +22,8 @@ def prepare_environment_for_tests():
 def test_is_system_path():
     assert(envutil.is_system_path('/usr/bin'))
     assert(not envutil.is_system_path('/nonsense_path/bin'))
+    assert(not envutil.is_system_path(''))
+    assert(not envutil.is_system_path(None))
 
 
 test_paths = ['/usr/bin',