Repository: spack/spack

Issue:
Adding depends_on('tcl') with Tcl in packages.yaml causes /usr/bin to be at front (!) of PATH in install()
Adding `depends_on('tcl')` to a spec when Tcl is specified in `packages.yaml` as being in the system results in `/usr/bin` being put at the front of `PATH`, ahead of the compiler wrapper locations. 

### Steps to reproduce the issue

1. Apply the following patch to the `zlib` spec:
   ```patch
   diff --git a/var/spack/repos/builtin/packages/zlib/package.py b/var/spack/repos/builtin/packages/zlib/package.py
   index 7ff6a9a..a602018 100644
   --- a/var/spack/repos/builtin/packages/zlib/package.py
   +++ b/var/spack/repos/builtin/packages/zlib/package.py
   @@ -23,7 +23,7 @@
    # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    ##############################################################################
    from spack import *
   -
   +import os
    
    # Although zlib comes with a configure script, it does not use Autotools
    # The AutotoolsPackage causes zlib to fail to build with PGI
   @@ -48,6 +48,9 @@ class Zlib(Package):
        variant('optimize', default=True,
                description='Enable -O2 for a more optimized lib')
 
   +    depends_on('tcl')
   +    print("PATH after depends_on() calls: {0}".format(os.environ['PATH']))
   +
        patch('w_patch.patch', when="@1.2.11%cce")
    
        @property
   @@ -64,6 +67,7 @@ class Zlib(Package):
                spack_env.append_flags('CFLAGS', '-O2')
    
        def install(self, spec, prefix):
   +        print("PATH on entry to install(): {0}".format(os.environ['PATH']))
            config_args = []
            if '~shared' in spec:
                config_args.append('--static')
   ```
1. Add the following clause to `etc/spack/packages.yaml`:     
   ```yaml
     tcl:
       paths:
         tcl@8.5.13 arch=linux-rhel7-x86_64: /usr
   ```
1. Attempt to build `zlib`
   ```
   spack install zlib
   ```
1. Look at the output and in `<install-dir>/.spack.build.out` for `PATH` diagnostic printouts.

### Root cause.

https://github.com/spack/spack/blob/a63450bc4537f8db04530d0dacdc98babbdd38f2/var/spack/repos/builtin/packages/tcl/package.py#L105

### Information on your system

SLF7, Spack from `develop@6a0f9ccf8`.



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -34,6 +34,7 @@
 
 import spack
 from spack import *
+from spack.util.environment import is_system_path
 from spack.util.prefix import Prefix
 import spack.util.spack_json as sjson
 
@@ -543,7 +544,10 @@ def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
         # where a system provided python is run against the standard libraries
         # of a Spack built python. See issue #7128
         spack_env.set('PYTHONHOME', self.home)
-        spack_env.prepend_path('PATH', os.path.dirname(self.command.path))
+
+        path = os.path.dirname(self.command.path)
+        if not is_system_path(path):
+            spack_env.prepend_path('PATH', path)
 
         python_paths = []
         for d in dependent_spec.traverse(
diff --git a/var/spack/repos/builtin/packages/tcl/package.py b/var/spack/repos/builtin/packages/tcl/package.py
--- a/var/spack/repos/builtin/packages/tcl/package.py
+++ b/var/spack/repos/builtin/packages/tcl/package.py
@@ -24,6 +24,7 @@
 ##############################################################################
 import os
 
+from spack.util.environment import is_system_path
 from spack import *
 
 
@@ -102,7 +103,9 @@ def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
         # where a system provided tcl is run against the standard libraries
         # of a Spack built tcl. See issue #7128 that relates to python but
         # it boils down to the same situation we have here.
-        spack_env.prepend_path('PATH', os.path.dirname(self.command.path))
+        path = os.path.dirname(self.command.path)
+        if not is_system_path(path):
+            spack_env.prepend_path('PATH', path)
 
         tcl_paths = [join_path(self.prefix, self.tcl_builtin_lib_dir)]
 


Test patch: