Skip to content

Commit

Permalink
Merge pull request #2963 from ComputeCanada/mesonninja_overwrites
Browse files Browse the repository at this point in the history
add options to `MesonNinja` easyblock to customize `build_cmd`, `install_cmd`, `builddir`
  • Loading branch information
boegel authored Aug 31, 2023
2 parents 6bcef45 + ae215fb commit 98faac4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions easybuild/easyblocks/generic/mesonninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from easybuild.tools.run import run_cmd

DEFAULT_CONFIGURE_CMD = 'meson'
DEFAULT_BUILD_CMD = 'ninja'
DEFAULT_INSTALL_CMD = 'ninja'


class MesonNinja(EasyBlock):
Expand All @@ -49,7 +51,10 @@ def extra_options(extra_vars=None):
"""Define extra easyconfig parameters specific to MesonNinja."""
extra_vars = EasyBlock.extra_options(extra_vars)
extra_vars.update({
'build_dir': [None, "build_dir to pass to meson", CUSTOM],
'build_cmd': [DEFAULT_BUILD_CMD, "Build command to use", CUSTOM],
'configure_cmd': [DEFAULT_CONFIGURE_CMD, "Configure command to use", CUSTOM],
'install_cmd': [DEFAULT_INSTALL_CMD, "Install command to use", CUSTOM],
'separate_build_dir': [True, "Perform build in a separate directory", CUSTOM],
})
return extra_vars
Expand Down Expand Up @@ -85,12 +90,14 @@ def configure_step(self, cmd_prefix=''):
configure_cmd == DEFAULT_CONFIGURE_CMD):
configure_cmd += ' setup'

cmd = "%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s %(configopts)s %(sourcedir)s" % {
build_dir = self.cfg.get('build_dir') or self.start_dir

cmd = "%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s %(configopts)s %(source_dir)s" % {
'configopts': self.cfg['configopts'],
'configure_cmd': configure_cmd,
'installdir': self.installdir,
'preconfigopts': self.cfg['preconfigopts'],
'sourcedir': self.start_dir,
'source_dir': build_dir,
}
(out, _) = run_cmd(cmd, log_all=True, simple=False)
return out
Expand All @@ -99,12 +106,15 @@ def build_step(self, verbose=False, path=None):
"""
Build with Ninja.
"""
build_cmd = self.cfg.get('build_cmd', DEFAULT_BUILD_CMD)

parallel = ''
if self.cfg['parallel']:
parallel = "-j %s" % self.cfg['parallel']

cmd = "%(prebuildopts)s ninja %(parallel)s %(buildopts)s" % {
cmd = "%(prebuildopts)s %(build_cmd)s %(parallel)s %(buildopts)s" % {
'buildopts': self.cfg['buildopts'],
'build_cmd': build_cmd,
'parallel': parallel,
'prebuildopts': self.cfg['prebuildopts'],
}
Expand All @@ -124,13 +134,16 @@ def install_step(self):
"""
Install with 'ninja install'.
"""
install_cmd = self.cfg.get('install_cmd', DEFAULT_INSTALL_CMD)

parallel = ''
if self.cfg['parallel']:
parallel = "-j %s" % self.cfg['parallel']

cmd = "%(preinstallopts)s ninja %(parallel)s %(installopts)s install" % {
cmd = "%(preinstallopts)s %(install_cmd)s %(parallel)s %(installopts)s install" % {
'installopts': self.cfg['installopts'],
'parallel': parallel,
'install_cmd': install_cmd,
'preinstallopts': self.cfg['preinstallopts'],
}
(out, _) = run_cmd(cmd, log_all=True, simple=False)
Expand Down

0 comments on commit 98faac4

Please sign in to comment.