summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/bootstrap.py60
-rw-r--r--lib/spack/spack/solver/asp.py9
2 files changed, 57 insertions, 12 deletions
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py
index 52bd810e89..3d51ca931e 100644
--- a/lib/spack/spack/bootstrap.py
+++ b/lib/spack/spack/bootstrap.py
@@ -5,6 +5,13 @@
import contextlib
import os
import sys
+try:
+ import sysconfig # novm
+except ImportError:
+ # Not supported on Python 2.6
+ pass
+
+import archspec.cpu
import llnl.util.filesystem as fs
import llnl.util.tty as tty
@@ -20,17 +27,33 @@ import spack.util.executable
from spack.util.environment import EnvironmentModifications
+def spec_for_current_python():
+ """For bootstrapping purposes we are just interested in the Python
+ minor version (all patches are ABI compatible with the same minor)
+ and on whether ucs4 support has been enabled for Python 2.7
+
+ See:
+ https://www.python.org/dev/peps/pep-0513/
+ https://stackoverflow.com/a/35801395/771663
+ """
+ version_str = '.'.join(str(x) for x in sys.version_info[:2])
+ variant_str = ''
+ if sys.version_info[0] == 2 and sys.version_info[1] == 7:
+ unicode_size = sysconfig.get_config_var('Py_UNICODE_SIZE')
+ variant_str = '+ucs4' if unicode_size == 4 else '~ucs4'
+
+ spec_fmt = 'python@{0} {1}'
+ return spec_fmt.format(version_str, variant_str)
+
+
@contextlib.contextmanager
def spack_python_interpreter():
"""Override the current configuration to set the interpreter under
which Spack is currently running as the only Python external spec
available.
"""
- python_cls = type(spack.spec.Spec('python').package)
python_prefix = os.path.dirname(os.path.dirname(sys.executable))
- externals = python_cls.determine_spec_details(
- python_prefix, [os.path.basename(sys.executable)])
- external_python = externals[0]
+ external_python = spec_for_current_python()
entry = {
'buildable': False,
@@ -60,9 +83,10 @@ def make_module_available(module, spec=None, install=False):
# We can constrain by a shortened version in place of a version range
# because this spec is only used for querying or as a placeholder to be
# replaced by an external that already has a concrete version. This syntax
- # is not suffucient when concretizing without an external, as it will
+ # is not sufficient when concretizing without an external, as it will
# concretize to python@X.Y instead of python@X.Y.Z
- spec.constrain('^python@%d.%d' % sys.version_info[:2])
+ python_requirement = '^' + spec_for_current_python()
+ spec.constrain(python_requirement)
installed_specs = spack.store.db.query(spec, installed=True)
for ispec in installed_specs:
@@ -197,3 +221,27 @@ def ensure_bootstrap_configuration():
with spack.store.use_store(spack.paths.user_bootstrap_store):
with spack_python_interpreter():
yield
+
+
+def clingo_root_spec():
+ # Construct the root spec that will be used to bootstrap clingo
+ spec_str = 'clingo-bootstrap@spack+python'
+
+ # Add a proper compiler hint to the root spec. We use GCC for
+ # everything but MacOS.
+ if str(spack.architecture.platform()) == 'darwin':
+ spec_str += ' %apple-clang'
+ else:
+ spec_str += ' %gcc'
+
+ # Add hint to use frontend operating system on Cray
+ if str(spack.architecture.platform()) == 'cray':
+ spec_str += ' os=fe'
+
+ # Add the generic target
+ generic_target = archspec.cpu.host().family
+ spec_str += ' target={0}'.format(str(generic_target))
+
+ tty.debug('[BOOTSTRAP ROOT SPEC] clingo: {0}'.format(spec_str))
+
+ return spack.spec.Spec(spec_str)
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index d9ae6a170c..020e1620a6 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -253,14 +253,11 @@ class PyclingoDriver(object):
# TODO: Find a way to vendor the concrete spec
# in a cross-platform way
with spack.bootstrap.ensure_bootstrap_configuration():
- generic_target = archspec.cpu.host().family
- spec_str = 'clingo-bootstrap@spack+python target={0}'.format(
- str(generic_target)
- )
- clingo_spec = spack.spec.Spec(spec_str)
+ clingo_spec = spack.bootstrap.clingo_root_spec()
clingo_spec._old_concretize()
spack.bootstrap.make_module_available(
- 'clingo', spec=clingo_spec, install=True)
+ 'clingo', spec=clingo_spec, install=True
+ )
import clingo
self.out = asp or llnl.util.lang.Devnull()
self.cores = cores