new branch and also pushing some architecture changes where os is detected by linux and darwin and manually set by cray and bgq
This commit is contained in:
		@@ -39,20 +39,25 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class InvalidSysTypeError(serr.SpackError):
 | 
					class InvalidSysTypeError(serr.SpackError):
 | 
				
			||||||
    def __init__(self, sys_type):
 | 
					    def __init__(self, sys_type):
 | 
				
			||||||
        super(InvalidSysTypeError, self).__init__("Invalid sys_type value for Spack: " + sys_type)
 | 
					        super(InvalidSysTypeError, self).__init__(
 | 
				
			||||||
 | 
					                "Invalid sys_type value for Spack: " + sys_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NoSysTypeError(serr.SpackError):
 | 
					class NoSysTypeError(serr.SpackError):
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
        super(NoSysTypeError, self).__init__("Could not determine sys_type for this machine.")
 | 
					        super(NoSysTypeError, self).__init__(
 | 
				
			||||||
 | 
					                "Could not determine sys_type for this machine.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@key_ordering
 | 
					@key_ordering
 | 
				
			||||||
class Target(object):
 | 
					class Target(object):
 | 
				
			||||||
    """ Target is the processor of the host machine. The host machine may have different front-end
 | 
					    """ Target is the processor of the host machine. 
 | 
				
			||||||
        and back-end targets, especially if it is a Cray machine. The target will have a name and
 | 
					        The host machine may have different front-end
 | 
				
			||||||
        also the module_name (e.g craype-compiler). Targets will also recognize which platform
 | 
					        and back-end targets, especially if it is a Cray machine. 
 | 
				
			||||||
        they came from using the set_platform method. Targets will have compiler finding strategies
 | 
					        The target will have a name and module_name (e.g craype-compiler). 
 | 
				
			||||||
 | 
					        Targets will also recognize which platform
 | 
				
			||||||
 | 
					        they came from using the set_platform method. 
 | 
				
			||||||
 | 
					        Targets will have compiler finding strategies
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, name, compiler_strategy, module_name=None):
 | 
					    def __init__(self, name, compiler_strategy, module_name=None):
 | 
				
			||||||
@@ -64,6 +69,9 @@ def __init__(self, name, compiler_strategy, module_name=None):
 | 
				
			|||||||
    def set_platform(self, platform):
 | 
					    def set_platform(self, platform):
 | 
				
			||||||
        self.platform_name = platform.name
 | 
					        self.platform_name = platform.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def set_operating_system(self, operating_sys):
 | 
				
			||||||
 | 
					        self.platform_os = operating_sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def to_dict(self):
 | 
					    def to_dict(self):
 | 
				
			||||||
        d = {}
 | 
					        d = {}
 | 
				
			||||||
        d['name'] = self.name
 | 
					        d['name'] = self.name
 | 
				
			||||||
@@ -71,6 +79,7 @@ def to_dict(self):
 | 
				
			|||||||
        d['module_name'] = self.module_name
 | 
					        d['module_name'] = self.module_name
 | 
				
			||||||
        if self.platform_name:
 | 
					        if self.platform_name:
 | 
				
			||||||
            d['platform'] = self.platform_name
 | 
					            d['platform'] = self.platform_name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return d
 | 
					        return d
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
@@ -87,14 +96,16 @@ def from_dict(d):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _cmp_key(self):
 | 
					    def _cmp_key(self):
 | 
				
			||||||
        return (self.name, self.compiler_strategy, self.module_name)
 | 
					        return (self.name, self.compiler_strategy, 
 | 
				
			||||||
 | 
					                self.module_name, self.platform_os)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        return self.__str__()
 | 
					        return self.__str__()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        if self.platform_name:
 | 
					        if self.platform_name and self.platform_os:
 | 
				
			||||||
            return self.platform_name + '-' + self.name
 | 
					            return (self.platform_name + '-' + 
 | 
				
			||||||
 | 
					                    self.platform_os + '-'  + self.name)
 | 
				
			||||||
        return self.name
 | 
					        return self.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@key_ordering
 | 
					@key_ordering
 | 
				
			||||||
@@ -105,26 +116,38 @@ class Platform(object):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    priority        = None # Subclass needs to set this number. This controls order in which platform is detected.
 | 
					    priority        = None # Subclass needs to set this number. This controls order in which platform is detected.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    front_end       = None
 | 
					    front_end       = None
 | 
				
			||||||
    back_end        = None
 | 
					    back_end        = None
 | 
				
			||||||
    default         = None # The default back end target. On cray ivybridge
 | 
					    default         = None # The default back end target. On cray ivybridge
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    front_os        = None
 | 
				
			||||||
 | 
					    back_os         = None
 | 
				
			||||||
 | 
					    default_os      = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, name):
 | 
					    def __init__(self, name):
 | 
				
			||||||
        self.targets = {}
 | 
					        self.targets = {}
 | 
				
			||||||
        self.name = name
 | 
					        self.name = name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def add_target(self, name, target):
 | 
					    def add_target(self, name, target):
 | 
				
			||||||
        """Used by the platform specific subclass to list available targets. Raises an error
 | 
					        """Used by the platform specific subclass to list available targets. 
 | 
				
			||||||
        if the platform specifies a name that is reserved by spack as an alias.
 | 
					            Raises an error if the platform specifies a name 
 | 
				
			||||||
 | 
					            that is reserved by spack as an alias.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        if name in ['front_end', 'fe', 'back_end', 'be', 'default']:
 | 
					        if name in ['front_end', 'fe', 'back_end', 'be', 'default']:
 | 
				
			||||||
            raise ValueError("%s is a spack reserved alias and cannot be the name of a target" % name)
 | 
					            raise ValueError(
 | 
				
			||||||
 | 
					                            "%s is a spack reserved" \
 | 
				
			||||||
 | 
					                             "alias and cannot be the name of a target" 
 | 
				
			||||||
 | 
					                             % name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        target.set_operating_system(self.platform_os())
 | 
				
			||||||
        target.set_platform(self)
 | 
					        target.set_platform(self)
 | 
				
			||||||
        self.targets[name] = target
 | 
					        self.targets[name] = target
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def target(self, name):
 | 
					    def target(self, name):
 | 
				
			||||||
        """This is a getter method for the target dictionary that handles defaulting based
 | 
					        """This is a getter method for the target dictionary that 
 | 
				
			||||||
        on the values provided by default, front-end, and back-end. This can be overwritten
 | 
					        handles defaulting based on the values provided by default, 
 | 
				
			||||||
 | 
					        front-end, and back-end. This can be overwritten
 | 
				
			||||||
        by a subclass for which we want to provide further aliasing options.
 | 
					        by a subclass for which we want to provide further aliasing options.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        if name == 'default':
 | 
					        if name == 'default':
 | 
				
			||||||
@@ -136,6 +159,51 @@ def target(self, name):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return self.targets[name]
 | 
					        return self.targets[name]
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def _detect_linux_os(self):
 | 
				
			||||||
 | 
					        """ If it is one a linux machine use the python method platform.dist()
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        os_name = py_platform.dist()[0]
 | 
				
			||||||
 | 
					        version = py_platform.dist()[1]
 | 
				
			||||||
 | 
					 a      return os_name + version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _detect_mac_os(self):
 | 
				
			||||||
 | 
					        """If it is on a mac machine then use the python method platform.mac_ver
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        mac_releases = {'10.6' : 'snowleopard', '10.7' : 'lion',
 | 
				
			||||||
 | 
					                        '10.8' : 'mountainlion', '10.9' : 'mavericks',
 | 
				
			||||||
 | 
					                        '10.10' : 'yosemite', '10.11' : 'elcapitan'}
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        mac_ver = py_platform.mac_ver()
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            os_name = mac_releases[mac_ver]
 | 
				
			||||||
 | 
					            mac_ver = Version(mac_ver) 
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        except KeyError:
 | 
				
			||||||
 | 
					            os_name = 'mac_os'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return os_name 
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def set_os(self):
 | 
				
			||||||
 | 
					        """ Set the OS according to the platform it is on. Darwin and Linux
 | 
				
			||||||
 | 
					            will simply be an auto-detected linux distro or mac release. The
 | 
				
			||||||
 | 
					            special cases will be for Cray and BGQ machines which have two
 | 
				
			||||||
 | 
					            different OS for login and compute nodes. The client should provide
 | 
				
			||||||
 | 
					            the name and major version of the operating system
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        if self.name == 'darwin':
 | 
				
			||||||
 | 
					            self.default_os = self._detect_mac_os()
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.default_os = self._detect_linux_os()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def platform_os(self, name=None):
 | 
				
			||||||
 | 
					        """ Get the platform operating system from the platform """
 | 
				
			||||||
 | 
					        if name == 'front_os':
 | 
				
			||||||
 | 
					            return self.front_os
 | 
				
			||||||
 | 
					        elif name == 'back_os':
 | 
				
			||||||
 | 
					            return self.back_os
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return self.default_os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def detect(self):
 | 
					    def detect(self):
 | 
				
			||||||
        """ Subclass is responsible for implementing this method.
 | 
					        """ Subclass is responsible for implementing this method.
 | 
				
			||||||
@@ -144,6 +212,7 @@ def detect(self):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        return self.__str__()
 | 
					        return self.__str__()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -153,43 +222,6 @@ def __str__(self):
 | 
				
			|||||||
    def _cmp_key(self):
 | 
					    def _cmp_key(self):
 | 
				
			||||||
        return (self.name, (_cmp_key(t) for t in self.targets.values()))
 | 
					        return (self.name, (_cmp_key(t) for t in self.targets.values()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_sys_type_from_spack_globals():
 | 
					 | 
				
			||||||
    """Return the SYS_TYPE from spack globals, or None if it isn't set."""
 | 
					 | 
				
			||||||
    if not hasattr(spack, "sys_type"):
 | 
					 | 
				
			||||||
        return None
 | 
					 | 
				
			||||||
    elif hasattr(spack.sys_type, "__call__"):
 | 
					 | 
				
			||||||
        return spack.sys_type() #If in __init__.py there is a sys_type() then call that
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        return spack.sys_type # Else use the attributed which defaults to None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# This is livermore dependent. Hard coded for livermore
 | 
					 | 
				
			||||||
#def get_sys_type_from_environment():
 | 
					 | 
				
			||||||
#    """Return $SYS_TYPE or None if it's not defined."""
 | 
					 | 
				
			||||||
#    return os.environ.get('SYS_TYPE')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def get_mac_sys_type():
 | 
					 | 
				
			||||||
    """Return a Mac OS SYS_TYPE or None if this isn't a mac.
 | 
					 | 
				
			||||||
       Front-end config
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    mac_ver = py_platform.mac_ver()[0]
 | 
					 | 
				
			||||||
    if not mac_ver:
 | 
					 | 
				
			||||||
        return None
 | 
					 | 
				
			||||||
    return "macosx_%s_%s" % (Version(mac_ver).up_to(2), py_platform.machine())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def get_sys_type_from_uname():
 | 
					 | 
				
			||||||
    """ Returns a sys_type from the uname argument
 | 
					 | 
				
			||||||
        Front-end config
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
        platform_proc = subprocess.Popen(['uname', '-i'], stdout = subprocess.PIPE)
 | 
					 | 
				
			||||||
        platform, _ = platform_proc.communicate()
 | 
					 | 
				
			||||||
        return platform.strip()
 | 
					 | 
				
			||||||
    except:
 | 
					 | 
				
			||||||
        return None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@memoized
 | 
					@memoized
 | 
				
			||||||
def all_platforms():
 | 
					def all_platforms():
 | 
				
			||||||
    modules = []
 | 
					    modules = []
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user