|
| 1 | +## |
| 2 | +# Copyright 2015-2015 Ghent University |
| 3 | +# |
| 4 | +# This file is part of EasyBuild, |
| 5 | +# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), |
| 6 | +# with support of Ghent University (http://ugent.be/hpc), |
| 7 | +# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en), |
| 8 | +# the Hercules foundation (http://www.herculesstichting.be/in_English) |
| 9 | +# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). |
| 10 | +# |
| 11 | +# http://github.com/hpcugent/easybuild |
| 12 | +# |
| 13 | +# EasyBuild is free software: you can redistribute it and/or modify |
| 14 | +# it under the terms of the GNU General Public License as published by |
| 15 | +# the Free Software Foundation v2. |
| 16 | +# |
| 17 | +# EasyBuild is distributed in the hope that it will be useful, |
| 18 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | +# GNU General Public License for more details. |
| 21 | +# |
| 22 | +# You should have received a copy of the GNU General Public License |
| 23 | +# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>. |
| 24 | +## |
| 25 | +""" |
| 26 | +EasyBuild support for installing Cray toolchains, implemented as an easyblock |
| 27 | +
|
| 28 | +@author: Kenneth Hoste (Ghent University) |
| 29 | +""" |
| 30 | + |
| 31 | +from easybuild.easyblocks.generic.bundle import Bundle |
| 32 | + |
| 33 | + |
| 34 | +KNOWN_PRGENVS = ['PrgEnv-cray', 'PrgEnv-gnu', 'PrgEnv-intel', 'PrgEnv-pgi'] |
| 35 | + |
| 36 | + |
| 37 | +class CrayToolchain(Bundle): |
| 38 | + """ |
| 39 | + Compiler toolchain: generate module file only, nothing to build/install |
| 40 | + """ |
| 41 | + def make_module_dep(self): |
| 42 | + """ |
| 43 | + Generate load/swap statements for dependencies in the module file |
| 44 | + """ |
| 45 | + # build dict with info for 'module swap' statements for dependencies, |
| 46 | + # i.e. a mapping of full module name to the module name to unload before loading |
| 47 | + # for example: {'fftw/3.3.4.1': 'fftw', 'cray-libsci/13.0.4': 'cray-libsci'} |
| 48 | + unload_info = {} |
| 49 | + for dep in self.toolchain.dependencies: |
| 50 | + mod_name = dep['full_mod_name'] |
| 51 | + # determine versionless module name, e.g. 'fftw/3.3.4.1' => 'fftw' |
| 52 | + depname = '/'.join(mod_name.split('/')[:-1]) |
| 53 | + if not mod_name.startswith('PrgEnv-'): |
| 54 | + unload_info.update({mod_name: depname}) |
| 55 | + else: |
| 56 | + my_prgenv_short = depname |
| 57 | + my_prgenv_full = dep['full_mod_name'] |
| 58 | + |
| 59 | + self.log.debug("Swap info for dependencies of %s: %s", self.full_mod_name, unload_info) |
| 60 | + txt = super(CrayToolchain, self).make_module_dep(unload_info=unload_info) |
| 61 | + swap_prgenv = "if { [ is-loaded " + my_prgenv_short + " ] } { \n" |
| 62 | + swap_prgenv += " module swap " + my_prgenv_short + " " + my_prgenv_full + "\n}\n" |
| 63 | + |
| 64 | + # unload statements for PrgEnv-* modules must be included *first* |
| 65 | + comment = self.module_generator.comment("first, unload any PrgEnv module that may be loaded").strip() |
| 66 | + prgenv_unloads = ['', comment] |
| 67 | + for prgenv in KNOWN_PRGENVS: |
| 68 | + if prgenv not in my_prgenv_short: |
| 69 | + prgenv_unloads.append(self.module_generator.unload_module(prgenv).strip()) |
| 70 | + |
| 71 | + comment = self.module_generator.comment("next, load toolchain components") |
| 72 | + txt = '\n'.join(prgenv_unloads) + '\n\n' + comment + swap_prgenv + txt |
| 73 | + return txt |
0 commit comments