Merge pull request #1122 from LLNL/bugfix/newarch-sys_type

Bugfix/newarch sys type
This commit is contained in:
Todd Gamblin 2016-06-27 10:07:03 -07:00 committed by GitHub
commit 3ea9d1e665
12 changed files with 88 additions and 74 deletions

View file

@ -91,16 +91,10 @@
import spack.error as serr import spack.error as serr
class InvalidSysTypeError(serr.SpackError): class NoPlatformError(serr.SpackError):
def __init__(self, sys_type):
super(InvalidSysTypeError, self).__init__(
"Invalid sys_type value for Spack: " + sys_type)
class NoSysTypeError(serr.SpackError):
def __init__(self): def __init__(self):
super(NoSysTypeError, self).__init__( super(NoPlatformError, self).__init__(
"Could not determine sys_type for this machine.") "Could not determine a platform for this machine.")
@key_ordering @key_ordering
@ -345,14 +339,17 @@ def to_dict(self):
@key_ordering @key_ordering
class Arch(object): class Arch(object):
"Architecture is now a class to help with setting attributes" """Architecture is now a class to help with setting attributes.
def __init__(self, platform=None, platform_os=None, target=None): TODO: refactor so that we don't need this class.
self.platform = platform """
if platform and platform_os:
platform_os = self.platform.operating_system(platform_os) def __init__(self, plat=None, os=None, target=None):
self.platform_os = platform_os self.platform = plat
if platform and target: if plat and os:
os = self.platform.operating_system(os)
self.platform_os = os
if plat and target:
target = self.platform.target(target) target = self.platform.target(target)
self.target = target self.target = target
@ -409,27 +406,27 @@ def to_dict(self):
return d return d
def _target_from_dict(target_name, platform=None): def _target_from_dict(target_name, plat=None):
""" Creates new instance of target and assigns all the attributes of """ Creates new instance of target and assigns all the attributes of
that target from the dictionary that target from the dictionary
""" """
if not platform: if not plat:
platform = sys_type() plat = platform()
return platform.target(target_name) return plat.target(target_name)
def _operating_system_from_dict(os_name, platform=None): def _operating_system_from_dict(os_name, plat=None):
""" uses platform's operating system method to grab the constructed """ uses platform's operating system method to grab the constructed
operating systems that are valid on the platform. operating systems that are valid on the platform.
""" """
if not platform: if not plat:
platform = sys_type() plat = platform()
if isinstance(os_name, dict): if isinstance(os_name, dict):
name = os_name['name'] name = os_name['name']
version = os_name['version'] version = os_name['version']
return platform.operating_system(name+version) return plat.operating_system(name+version)
else: else:
return platform.operating_system(os_name) return plat.operating_system(os_name)
def _platform_from_dict(platform_name): def _platform_from_dict(platform_name):
@ -504,16 +501,35 @@ def all_platforms():
@memoized @memoized
def sys_type(): def platform():
""" Gather a list of all available subclasses of platforms. """Detects the platform for this machine.
Sorts the list according to their priority looking. Priority is
an arbitrarily set number. Detects platform either using uname or Gather a list of all available subclasses of platforms.
a file path (/opt/cray...) Sorts the list according to their priority looking. Priority is
an arbitrarily set number. Detects platform either using uname or
a file path (/opt/cray...)
""" """
# Try to create a Platform object using the config file FIRST # Try to create a Platform object using the config file FIRST
platform_list = all_platforms() platform_list = all_platforms()
platform_list.sort(key=lambda a: a.priority) platform_list.sort(key=lambda a: a.priority)
for platform in platform_list: for platform_cls in platform_list:
if platform.detect(): if platform_cls.detect():
return platform() return platform_cls()
@memoized
def sys_type():
"""Print out the "default" platform-os-target tuple for this machine.
On machines with only one target OS/target, prints out the
platform-os-target for the frontend. For machines with a frontend
and a backend, prints the default backend.
TODO: replace with use of more explicit methods to get *all* the
backends, as client code should really be aware of cross-compiled
architectures.
"""
arch = Arch(platform(), 'default_os', 'default_target')
return str(arch)

View file

@ -315,7 +315,7 @@ def all_os_classes():
""" """
classes = [] classes = []
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
for os_class in platform.operating_sys.values(): for os_class in platform.operating_sys.values():
classes.append(os_class) classes.append(os_class)

View file

@ -221,7 +221,7 @@ def _concretize_platform(self, spec):
if isinstance(spec.root.architecture.platform,spack.architecture.Platform): if isinstance(spec.root.architecture.platform,spack.architecture.Platform):
spec.architecture.platform = spec.root.architecture.platform spec.architecture.platform = spec.root.architecture.platform
else: else:
spec.architecture.platform = spack.architecture.sys_type() spec.architecture.platform = spack.architecture.platform()
return True #changed? return True #changed?
def concretize_architecture(self, spec): def concretize_architecture(self, spec):

View file

@ -149,7 +149,7 @@ def install(self, prefix):
@when('arch=chaos_5_x86_64_ib') @when('arch=chaos_5_x86_64_ib')
def install(self, prefix): def install(self, prefix):
# This will be executed instead of the default install if # This will be executed instead of the default install if
# the package's sys_type() is chaos_5_x86_64_ib. # the package's platform() is chaos_5_x86_64_ib.
@when('arch=bgqos_0") @when('arch=bgqos_0")
def install(self, prefix): def install(self, prefix):

View file

@ -2216,7 +2216,7 @@ def do_parse(self):
for spec in specs: for spec in specs:
for s in spec.traverse(): for s in spec.traverse():
if s.architecture.os_string or s.architecture.target_string: if s.architecture.os_string or s.architecture.target_string:
s._set_platform(spack.architecture.sys_type()) s._set_platform(spack.architecture.platform())
return specs return specs
def parse_compiler(self, text): def parse_compiler(self, text):

View file

@ -5,7 +5,7 @@
import os import os
import platform as py_platform import platform as py_platform
import spack import spack
from spack.architecture import * import spack.architecture
from spack.spec import * from spack.spec import *
from spack.platforms.cray_xc import CrayXc from spack.platforms.cray_xc import CrayXc
from spack.platforms.linux import Linux from spack.platforms.linux import Linux
@ -19,14 +19,14 @@ class ArchitectureTest(MockPackagesTest):
def setUp(self): def setUp(self):
super(ArchitectureTest, self).setUp() super(ArchitectureTest, self).setUp()
self.platform = sys_type() self.platform = spack.architecture.platform()
def tearDown(self): def tearDown(self):
super(ArchitectureTest, self).tearDown() super(ArchitectureTest, self).tearDown()
def test_dict_functions_for_architecture(self): def test_dict_functions_for_architecture(self):
arch = Arch() arch = spack.architecture.Arch()
arch.platform = spack.architecture.sys_type() arch.platform = spack.architecture.platform()
arch.platform_os = arch.platform.operating_system('default_os') arch.platform_os = arch.platform.operating_system('default_os')
arch.target = arch.platform.target('default_target') arch.target = arch.platform.target('default_target')
@ -36,18 +36,23 @@ def test_dict_functions_for_architecture(self):
self.assertEqual(arch, new_arch) self.assertEqual(arch, new_arch)
self.assertTrue( isinstance(arch, Arch) ) self.assertTrue( isinstance(arch, spack.architecture.Arch) )
self.assertTrue( isinstance(arch.platform, Platform) ) self.assertTrue( isinstance(arch.platform, spack.architecture.Platform) )
self.assertTrue( isinstance(arch.platform_os, OperatingSystem) ) self.assertTrue( isinstance(arch.platform_os,
self.assertTrue( isinstance(arch.target, Target) ) spack.architecture.OperatingSystem) )
self.assertTrue( isinstance(new_arch, Arch) ) self.assertTrue( isinstance(arch.target,
self.assertTrue( isinstance(new_arch.platform, Platform) ) spack.architecture.Target) )
self.assertTrue( isinstance(new_arch.platform_os, OperatingSystem) ) self.assertTrue( isinstance(new_arch, spack.architecture.Arch) )
self.assertTrue( isinstance(new_arch.target, Target) ) self.assertTrue( isinstance(new_arch.platform,
spack.architecture.Platform) )
self.assertTrue( isinstance(new_arch.platform_os,
spack.architecture.OperatingSystem) )
self.assertTrue( isinstance(new_arch.target,
spack.architecture.Target) )
def test_sys_type(self): def test_platform(self):
output_platform_class = sys_type() output_platform_class = spack.architecture.platform()
my_arch_class = None my_arch_class = None
if os.path.exists('/opt/cray/craype'): if os.path.exists('/opt/cray/craype'):
my_platform_class = CrayXc() my_platform_class = CrayXc()

View file

@ -257,8 +257,8 @@ def test_external_package(self):
def test_external_package_module(self): def test_external_package_module(self):
# No tcl modules on darwin/linux machines # No tcl modules on darwin/linux machines
# TODO: improved way to check for this. # TODO: improved way to check for this.
if (spack.architecture.sys_type().name == 'darwin' or if (spack.architecture.platform().name == 'darwin' or
spack.architecture.sys_type().name == 'linux'): spack.architecture.platform().name == 'linux'):
return return
spec = Spec('externalmodule') spec = Spec('externalmodule')

View file

@ -34,7 +34,7 @@
from spack.repository import RepoPath from spack.repository import RepoPath
from spack.spec import Spec from spack.spec import Spec
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
linux_os_name = 'debian' linux_os_name = 'debian'
linux_os_version = '6' linux_os_version = '6'

View file

@ -93,7 +93,7 @@ def test_default_works(self):
def test_target_match(self): def test_target_match(self):
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
targets = platform.targets.values() targets = platform.targets.values()
for target in targets[:-1]: for target in targets[:-1]:
pkg = spack.repo.get('multimethod target='+target.name) pkg = spack.repo.get('multimethod target='+target.name)

View file

@ -242,7 +242,7 @@ def test_unsatisfiable_compiler_version(self):
def test_unsatisfiable_architecture(self): def test_unsatisfiable_architecture(self):
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
self.set_pkg_dep('mpileaks', 'mpich platform=test target=be') self.set_pkg_dep('mpileaks', 'mpich platform=test target=be')
spec = Spec('mpileaks ^mpich platform=test target=fe ^callpath ^dyninst ^libelf ^libdwarf') spec = Spec('mpileaks ^mpich platform=test target=fe ^callpath ^dyninst ^libelf ^libdwarf')

View file

@ -141,7 +141,6 @@ def test_satisfies_compiler_version(self):
def test_satisfies_architecture(self): def test_satisfies_architecture(self):
platform = spack.architecture.sys_type()
self.check_satisfies( self.check_satisfies(
'foo platform=test target=frontend os=frontend', 'foo platform=test target=frontend os=frontend',
'platform=test target=frontend os=frontend') 'platform=test target=frontend os=frontend')
@ -396,7 +395,7 @@ def test_constrain_changed(self):
self.check_constrain_changed('libelf', 'debug=2') self.check_constrain_changed('libelf', 'debug=2')
self.check_constrain_changed('libelf', 'cppflags="-O3"') self.check_constrain_changed('libelf', 'cppflags="-O3"')
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
self.check_constrain_changed('libelf', 'target='+platform.target('default_target').name) self.check_constrain_changed('libelf', 'target='+platform.target('default_target').name)
self.check_constrain_changed('libelf', 'os='+platform.operating_system('default_os').name) self.check_constrain_changed('libelf', 'os='+platform.operating_system('default_os').name)
@ -412,7 +411,7 @@ def test_constrain_not_changed(self):
self.check_constrain_not_changed('libelf debug=2', 'debug=2') self.check_constrain_not_changed('libelf debug=2', 'debug=2')
self.check_constrain_not_changed('libelf cppflags="-O3"', 'cppflags="-O3"') self.check_constrain_not_changed('libelf cppflags="-O3"', 'cppflags="-O3"')
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
default_target = platform.target('default_target').name default_target = platform.target('default_target').name
self.check_constrain_not_changed('libelf target='+default_target, 'target='+default_target) self.check_constrain_not_changed('libelf target='+default_target, 'target='+default_target)
@ -425,7 +424,7 @@ def test_constrain_dependency_changed(self):
self.check_constrain_changed('libelf^foo', 'libelf^foo+debug') self.check_constrain_changed('libelf^foo', 'libelf^foo+debug')
self.check_constrain_changed('libelf^foo', 'libelf^foo~debug') self.check_constrain_changed('libelf^foo', 'libelf^foo~debug')
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
default_target = platform.target('default_target').name default_target = platform.target('default_target').name
self.check_constrain_changed('libelf^foo', 'libelf^foo target='+default_target) self.check_constrain_changed('libelf^foo', 'libelf^foo target='+default_target)
@ -439,6 +438,6 @@ def test_constrain_dependency_not_changed(self):
self.check_constrain_not_changed('libelf^foo~debug', 'libelf^foo~debug') self.check_constrain_not_changed('libelf^foo~debug', 'libelf^foo~debug')
self.check_constrain_not_changed('libelf^foo cppflags="-O3"', 'libelf^foo cppflags="-O3"') self.check_constrain_not_changed('libelf^foo cppflags="-O3"', 'libelf^foo cppflags="-O3"')
platform = spack.architecture.sys_type() platform = spack.architecture.platform()
default_target = platform.target('default_target').name default_target = platform.target('default_target').name
self.check_constrain_not_changed('libelf^foo target='+default_target, 'libelf^foo target='+default_target) self.check_constrain_not_changed('libelf^foo target='+default_target, 'libelf^foo target='+default_target)

View file

@ -106,13 +106,7 @@ def has_a_default(self):
# #
# Make sure we can switch methods on different target # Make sure we can switch methods on different target
# #
# for platform_name in ['cray_xc', 'darwin', 'linux']: platform = spack.architecture.platform()
# file_path = join_path(spack.platform_path, platform_name)
# platform_mod = imp.load_source('spack.platforms', file_path + '.py')
# cls = getattr(platform_mod, mod_to_class(platform_name))
# platform = cls()
platform = spack.architecture.sys_type()
targets = platform.targets.values() targets = platform.targets.values()
if len(targets) > 1: if len(targets) > 1:
targets = targets[:-1] targets = targets[:-1]