From 7ccf56a0b72fc6ce550d10e125a0dfa99d8b5f51 Mon Sep 17 00:00:00 2001
From: Matt Belhorn <belhornmp@ornl.gov>
Date: Mon, 31 Oct 2016 00:02:27 -0400
Subject: [PATCH] Removes cyclic dependency on spack.config. (#2121)

Merge #2030 added a cyclic dependency between the Cray platform needing
to read a `targets.yaml` config file and `config.py` needing to get the
platform names.

This commit removes the cyclic dependency in favor of the more general
config scheme. It also removes the now functionless `targets.yaml`
config file. This breaks 'frontend' targets on the Cray platform but
all architecture targets, including the frontend, that are provided by
CrayPE are added to the Platform anyway so users can be explicit about
the architecture targeted by the Cray compiler wrappers:

```
spack spec libelf arch=cray-CNL-frontend
```

becomes

```
spack spec libelf arch=cray-CNL-mc8         # on an XK7 or
spack spec libelf arch=cray-CNL-sandybridge # on an older XC30, etc..
```

The only way the 'frontend' target can be defined after this commit is
through target environment variables.
---
 lib/spack/spack/config.py         |  1 -
 lib/spack/spack/platforms/cray.py |  7 ++---
 lib/spack/spack/schema/targets.py | 45 -------------------------------
 3 files changed, 2 insertions(+), 51 deletions(-)
 delete mode 100644 lib/spack/spack/schema/targets.py

diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index 6a67f01d66..de5f55775c 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -179,7 +179,6 @@
     'mirrors': spack.schema.mirrors.schema,
     'repos': spack.schema.repos.schema,
     'packages': spack.schema.packages.schema,
-    'targets': spack.schema.targets.schema,
     'modules': spack.schema.modules.schema,
 }
 
diff --git a/lib/spack/spack/platforms/cray.py b/lib/spack/spack/platforms/cray.py
index 9138ad7afe..94e2949e4a 100644
--- a/lib/spack/spack/platforms/cray.py
+++ b/lib/spack/spack/platforms/cray.py
@@ -1,7 +1,7 @@
 import os
 import re
-import spack.config
 import llnl.util.tty as tty
+from spack import build_env_path
 from spack.util.executable import which
 from spack.architecture import Platform, Target, NoPlatformError
 from spack.operating_systems.linux_distro import LinuxDistro
@@ -46,13 +46,10 @@ def __init__(self):
             self.add_target(name, Target(name, 'craype-%s' % target))
 
         # Get aliased targets from config or best guess from environment:
-        conf = spack.config.get_config('targets')
         for name in ('front_end', 'back_end'):
             _target = getattr(self, name, None)
             if _target is None:
                 _target = os.environ.get('SPACK_' + name.upper())
-            if _target is None:
-                _target = conf.get(name)
             if _target is None and name == 'back_end':
                 _target = self._default_target_from_env()
             if _target is not None:
@@ -82,7 +79,7 @@ def setup_platform_environment(cls, pkg, env):
             similar to linux/standard linker behavior
         """
         env.set('CRAYPE_LINK_TYPE', 'dynamic')
-        cray_wrapper_names = join_path(spack.build_env_path, 'cray')
+        cray_wrapper_names = join_path(build_env_path, 'cray')
         if os.path.isdir(cray_wrapper_names):
             env.prepend_path('PATH', cray_wrapper_names)
             env.prepend_path('SPACK_ENV_PATH', cray_wrapper_names)
diff --git a/lib/spack/spack/schema/targets.py b/lib/spack/spack/schema/targets.py
deleted file mode 100644
index 312474cab4..0000000000
--- a/lib/spack/spack/schema/targets.py
+++ /dev/null
@@ -1,45 +0,0 @@
-##############################################################################
-# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
-# Produced at the Lawrence Livermore National Laboratory.
-#
-# This file is part of Spack.
-# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
-# LLNL-CODE-647188
-#
-# For details, see https://github.com/llnl/spack
-# Please also see the LICENSE file for our notice and the LGPL.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License (as
-# published by the Free Software Foundation) version 2.1, February 1999.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
-# conditions of the GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##############################################################################
-"""Schema for target configuration files."""
-
-
-schema = {
-    '$schema': 'http://json-schema.org/schema#',
-    'title': 'Spack target configuration file schema',
-    'type': 'object',
-    'additionalProperties': False,
-    'patternProperties': {
-        r'targets:?': {
-            'type': 'object',
-            'default': {},
-            'additionalProperties': False,
-            'patternProperties': {
-                r'\w[\w-]*': {  # target name
-                    'type': 'string',
-                },
-            },
-        },
-    },
-}
-- 
GitLab