Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions easybuild/easyblocks/generic/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@
@author: Kenneth Hoste (Ghent University)
@author: Pieter De Baets (Ghent University)
@author: Jens Timmerman (Ghent University)
@author: Alex Domingo (Vrije Universiteit Brussel)
@author: Pavel Grochal (INUITS)
"""

import os

from easybuild.framework.easyblock import EasyBlock
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.filetools import copy_dir, remove_dir
from easybuild.tools.run import run_cmd


class Tarball(EasyBlock):
Expand All @@ -43,6 +49,21 @@ class Tarball(EasyBlock):
- will unpack binary and copy it to the install dir
"""

@staticmethod
def extra_options(extra_vars=None):
"""Extra easyconfig parameters specific to Tarball."""
extra_vars = EasyBlock.extra_options(extra=extra_vars)
extra_vars.update({
'install_type': [None, "Defaults to extract tarball into clean directory. Options: 'merge' merges tarball "
"to existing directory, 'subdir' extracts tarball into its own sub-directory", CUSTOM],
'preinstall_cmd': [None, "Command to execute before installation", CUSTOM],
})
return extra_vars

def __init__(self, *args, **kwargs):
"""Initialize easyblock."""
super(Tarball, self).__init__(*args, **kwargs)

def configure_step(self):
"""
Dummy configure method
Expand All @@ -57,8 +78,45 @@ def build_step(self):

def install_step(self, src=None):
"""Install by copying from specified source directory (or 'start_dir' if not specified)."""
remove_dir(self.installdir)
copy_dir(src or self.cfg['start_dir'], self.installdir, symlinks=self.cfg['keepsymlinks'])

# Run preinstallopts and/or preinstall_cmd before copy of source directory
preinstall_cmd = None
if self.cfg['preinstallopts']:
preinstall_opts = self.cfg['preinstallopts'].split('&&')
preinstall_cmd = '&&'.join([opt for opt in preinstall_opts if opt and not opt.isspace()])
if self.cfg['preinstall_cmd']:
preinstall_cmd = '&& '.join([cmd for cmd in [preinstall_cmd, self.cfg['preinstall_cmd']] if cmd])
if preinstall_cmd:
self.log.info("Preparing installation of %s using command '%s'..." % (self.name, preinstall_cmd))
run_cmd(preinstall_cmd, log_all=True, simple=True)

# Copy source directory
source_path = src or self.cfg['start_dir']

if self.cfg['install_type'] == 'subdir':
# Wipe and install in a sub-directory with the name of the package
install_path = os.path.join(self.installdir, self.name.lower())
dirs_exist_ok = False
install_logmsg = "Copying tarball contents of %s to sub-directory %s..."
elif self.cfg['install_type'] == 'merge':
# Enable merging with root of existing installdir
install_path = self.installdir
dirs_exist_ok = True
install_logmsg = "Merging tarball contents of %s to %s..."
else:
if self.cfg['install_type']:
self.log.warning("Ignoring unknown option '%s' for index_type." % self.cfg['install_type'])
# Wipe and copy root of installation directory (default)
install_path = self.installdir
dirs_exist_ok = False
install_logmsg = "Wiping %s and copying tarball contents of %s into it..."

self.log.info(install_logmsg % (self.name, install_path))

if not dirs_exist_ok:
remove_dir(install_path)

copy_dir(source_path, install_path, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=dirs_exist_ok)

def sanity_check_rpath(self):
"""Skip the rpath sanity check, this is binary software"""
Expand Down