Skip to content
Snippets Groups Projects
Commit 7508d51c authored by Jens Henrik Göbbert's avatar Jens Henrik Göbbert
Browse files

initial commit

parent 6007e854
Branches
Tags
No related merge requests found
##
# Copyright 2009-2021 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for installing MATLAB, implemented as an easyblock
@author: Stijn De Weirdt (Ghent University)
@author: Dries Verdegem (Ghent University)
@author: Kenneth Hoste (Ghent University)
@author: Pieter De Baets (Ghent University)
@author: Jens Timmerman (Ghent University)
@author: Fotis Georgatos (Uni.Lu, NTUA)
"""
import re
import os
import stat
import tempfile
from distutils.version import LooseVersion
from easybuild.easyblocks.generic.packedbinary import PackedBinary
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_file, read_file, write_file
from easybuild.tools.py2vs3 import string_type
from easybuild.tools.run import run_cmd
class EB_MATLAB(PackedBinary):
"""Support for installing MATLAB."""
def __init__(self, *args, **kwargs):
"""Add extra config options specific to MATLAB."""
super(EB_MATLAB, self).__init__(*args, **kwargs)
self.comp_fam = None
self.configfile = os.path.join(self.builddir, 'my_installer_input.txt')
@staticmethod
def extra_options():
extra_vars = {
'java_options': ['-Xmx256m', "$_JAVA_OPTIONS value set for install and in module file.", CUSTOM],
'key': [None, "Installation key(s), make one install for each key. Single key or a list of keys", CUSTOM],
'extend_libpath': [True, "Extend LD_LIBRARY_PATH", CUSTOM],
}
return PackedBinary.extra_options(extra_vars)
def configure_step(self):
"""Configure MATLAB installation: create license file."""
licfile = self.cfg['license_file']
if licfile is None and os.getenv('EB_MATLAB_LICFILE') is not None:
licfile = os.getenv('EB_MATLAB_LICFILE', 'matlab.lic')
else:
licserv = self.cfg['license_server']
if licserv is None:
licserv = os.getenv('EB_MATLAB_LICENSE_SERVER', 'license.example.com')
licport = self.cfg['license_server_port']
if licport is None:
licport = os.getenv('EB_MATLAB_LICENSE_SERVER_PORT', '00000')
# create license file
lictxt = '\n'.join([
"SERVER %s 000000000000 %s" % (licserv, licport),
"USE_SERVER",
])
licfile = os.path.join(self.builddir, 'matlab.lic')
write_file(licfile, lictxt)
try:
copy_file(os.path.join(self.cfg['start_dir'], 'installer_input.txt'), self.configfile)
# read file in binary mode to avoid UTF-8 encoding issues when using Python 3,
# due to non-UTF-8 characters...
config = read_file(self.configfile, mode='rb')
# use raw byte strings (must be 'br', not 'rb'),
# required when using Python 3 because file was read in binary mode
regdest = re.compile(br"^# destinationFolder=.*", re.M)
regagree = re.compile(br"^# agreeToLicense=.*", re.M)
regmode = re.compile(br"^# mode=.*", re.M)
reglicpath = re.compile(br"^# licensePath=.*", re.M)
# must use byte-strings here when using Python 3, see above
config = regdest.sub(b"destinationFolder=%s" % self.installdir.encode('utf-8'), config)
config = regagree.sub(b"agreeToLicense=Yes", config)
config = regmode.sub(b"mode=silent", config)
config = reglicpath.sub(b"licensePath=%s" % licfile.encode('utf-8'), config)
write_file(self.configfile, config)
except IOError as err:
raise EasyBuildError("Failed to create installation config file %s: %s", self.configfile, err)
self.log.debug('configuration file written to %s:\n %s', self.configfile, config)
def install_step(self):
"""MATLAB install procedure using 'install' command."""
src = os.path.join(self.cfg['start_dir'], 'install')
# make sure install script is executable
adjust_permissions(src, stat.S_IXUSR)
if LooseVersion(self.version) >= LooseVersion('2016b'):
jdir = os.path.join(self.cfg['start_dir'], 'sys', 'java', 'jre', 'glnxa64', 'jre', 'bin')
for perm_dir in [os.path.join(self.cfg['start_dir'], 'bin', 'glnxa64'), jdir]:
adjust_permissions(perm_dir, stat.S_IXUSR)
# make sure $DISPLAY is not defined, which may lead to (hard to trace) problems
# this is a workaround for not being able to specify --nodisplay to the install scripts
if 'DISPLAY' in os.environ:
os.environ.pop('DISPLAY')
if '_JAVA_OPTIONS' not in self.cfg['preinstallopts']:
java_opts = 'export _JAVA_OPTIONS="%s" && ' % self.cfg['java_options']
self.cfg['preinstallopts'] = java_opts + self.cfg['preinstallopts']
if LooseVersion(self.version) >= LooseVersion('2016b'):
change_dir(self.builddir)
# Build the cmd string
cmdlist = [
self.cfg['preinstallopts'],
src,
'-inputFile',
self.configfile,
]
if LooseVersion(self.version) < LooseVersion('2020a'):
# MATLAB installers < 2020a ignore $TMPDIR (always use /tmp) and might need a large tmpdir
tmpdir = tempfile.mkdtemp()
cmdlist.extend([
'-v',
'-tmpdir',
tmpdir,
])
cmdlist.append(self.cfg['installopts'])
cmd = ' '.join(cmdlist)
keys = self.cfg['key']
if keys is None:
keys = os.getenv('EB_MATLAB_KEY', '00000-00000-00000-00000-00000-00000-00000-00000-00000-00000')
if isinstance(keys, string_type):
keys = keys.split(',')
# Compile the installation key regex outside of the loop
regkey = re.compile(br"^(# )?fileInstallationKey=.*", re.M)
# Run an install for each key
for i, key in enumerate(keys):
self.log.info('Installing MATLAB with key %s of %s', i + 1, len(keys))
try:
config = read_file(self.configfile, mode='rb')
config = regkey.sub(b"fileInstallationKey=%s" % key.encode('utf-8'), config)
write_file(self.configfile, config)
except IOError as err:
raise EasyBuildError("Failed to update config file %s: %s", self.configfile, err)
(out, _) = run_cmd(cmd, log_all=True, simple=False)
# check installer output for known signs of trouble
patterns = [
"Error: You have entered an invalid File Installation Key",
]
for pattern in patterns:
regex = re.compile(pattern, re.I)
if regex.search(out):
raise EasyBuildError("Found error pattern '%s' in output of installation command '%s': %s",
regex.pattern, cmd, out)
def sanity_check_step(self):
"""Custom sanity check for MATLAB."""
custom_paths = {
'files': ["bin/matlab", "bin/glnxa64/MATLAB", "toolbox/local/classpath.txt"],
'dirs': ["java/jar"],
}
super(EB_MATLAB, self).sanity_check_step(custom_paths=custom_paths)
def make_module_extra(self):
"""Extend PATH and set proper _JAVA_OPTIONS (e.g., -Xmx)."""
txt = super(EB_MATLAB, self).make_module_extra()
# make MATLAB runtime available
if self.cfg['extend_libpath'] and LooseVersion(self.version) >= LooseVersion('2017a'):
for ldlibdir in ['runtime', 'bin', os.path.join('sys', 'os')]:
libdir = os.path.join(ldlibdir, 'glnxa64')
txt += self.module_generator.prepend_paths('LD_LIBRARY_PATH', libdir)
if self.cfg['java_options']:
txt += self.module_generator.set_environment('_JAVA_OPTIONS', self.cfg['java_options'])
return txt
name = 'MATLAB'
version = '2020b'
homepage = 'https://www.mathworks.com/products/matlab.html'
description = """MATLAB is a high-level language and interactive environment
that enables you to perform computationally intensive tasks faster than with
traditional programming languages such as C, C++, and Fortran.
"""
toolchain = SYSTEM
sources = [SOURCELOWER_TAR_GZ]
# checksums = ['']
dependencies = [('Java', '15', '', SYSTEM)]
java_options = '-Xmx2048m'
extend_libpath = False
# Attention: before calling 'eb':
# export EB_MATLAB_KEY as fileInstallationKey
# export EB_MATLAB_LICFILE as license file
postinstallcmds = [
# create a wrapper script to ensure we do not mess up the environment
# because MATLAB comes with its own libstdc++ and other system libs
# in $EBROOTMATLAB/sys/os/glnxa64/
'mv %(installdir)s/bin/matlab %(installdir)s/bin/matlab.bin ',
(
'{ cat > %(installdir)s/bin/matlab; } << EOF\n'
'#!/bin/bash\n'
'\n'
'MYPATH=\$(readlink -f \$0)\n'
'export MATLAB_PATH=\$(realpath \$(dirname "\$MYPATH")/..)\n'
'\n'
'export LD_LIBRARY_PATH=\$MATLAB_PATH/runtime/glnxa64:\$LD_LIBRARY_PATH\n'
'export LD_LIBRARY_PATH=\$MATLAB_PATH/bin/glnxa64:\$LD_LIBRARY_PATH\n'
'export LD_LIBRARY_PATH=\$MATLAB_PATH/sys/os/glnxa64:\$LD_LIBRARY_PATH\n'
'\n'
'"\$MATLAB_PATH/bin/matlab.bin" "\$@"\n'
'EOF'
),
'chmod +x %(installdir)s/bin/matlab',
]
sanity_check_paths = {
'files': ['bin/matlab', 'bin/glnxa64/MATLAB'],
'dirs': [],
}
moduleclass = 'math'
Before running `eb` to install MATLAB you need to
a) export the file installation key as EB_MATLAB_KEY, like the following example
export EB_MATLAB_KEY='00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000-00000'
b) export the absolute path to the license file as EB_MATLAB_LICFILE, like the following example
export EB_MATLAB_LICFILE=/home/matlab/matlab.lic
c) copy the packed matlab sources as 'matlab-2020b.tar.gz' to the working directory
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment