Skip to content
Open
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
43 changes: 39 additions & 4 deletions easybuild/easyblocks/generic/mesonninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@

from easybuild.tools import LooseVersion
from easybuild.framework.easyblock import EasyBlock
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig import BUILD, CUSTOM
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import change_dir, create_unused_dir, which
from easybuild.tools.modules import get_software_version
from easybuild.tools.run import run_shell_cmd

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


Expand All @@ -59,7 +60,9 @@ def extra_options(extra_vars=None):
"This disabled costly asserts in code, typical for production.", CUSTOM],
'configure_cmd': [DEFAULT_CONFIGURE_CMD, "Configure command to use", CUSTOM],
'install_cmd': [DEFAULT_INSTALL_CMD, "Install command to use", CUSTOM],
'runtest': [None, "Meson target to test build, or True to use 'meson test'", BUILD],
'separate_build_dir': [True, "Perform build in a separate directory", CUSTOM],
'test_cmd': [DEFAULT_TEST_CMD, "Test command to use ('runtest' value is appended)", CUSTOM],
})
return extra_vars

Expand Down Expand Up @@ -149,13 +152,45 @@ def build_step(self, *args, **kwargs):

def test_step(self):
"""
Run tests using Ninja.
Run tests using Meson.
"""
if self.cfg['runtest']:
cmd = "%s %s %s" % (self.cfg['pretestopts'], self.cfg['runtest'], self.cfg['testopts'])
runtest = self.cfg['runtest']

if runtest:
# Essentially runtest = True. Use the default behavior.
if isinstance(runtest, bool):
test_cmd = self.cfg.get('test_cmd') or DEFAULT_TEST_CMD

# Run tests as recommended in https://mesonbuild.com/Unit-tests.html#testing-tool
if test_cmd == DEFAULT_TEST_CMD:
runtest = 'test'
# User has defined the test_cmd. Adding test by default here might cause trouble, hence omit.
else:
runtest = ''
# EasyConfig defined the test command to be executed via runtest
else:
test_cmd = ''
Comment on lines +171 to +172

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to give a warning if we are overriding a test_cmd set in the EC file.

Maybe for another PR but in the configuremake EB we use both test_cmd and runtest, would have to check other EBs but we might want to make this behavior more consistent (maybe even move the general test logic at the framework level)


full_test_cmd = ' '.join([x for x in (test_cmd, runtest, self.cfg['testopts']) if x])
# Make sure Meson does not use more resources than we want.
# From the documentation:
# By default Meson uses as many concurrent processes as there are cores on the test machine.
if self.cfg.parallel >= 1 and 'meson' in full_test_cmd:
if 'MESON_TESTTHREADS' not in self.cfg['pretestopts']:
self.cfg.update('pretestopts', f" export MESON_TESTTHREADS={self.cfg.parallel} && ")
# Preferred way to set parallelism since Meson v1.7.0, but does not hurt to set both.
if 'MESON_NUM_PROCESSES' not in self.cfg['pretestopts']:
self.cfg.update('pretestopts', f" export MESON_NUM_PROCESSES={self.cfg.parallel} && ")

# Compose command filtering out empty values
cmd = ' '.join([x for x in (self.cfg['pretestopts'], full_test_cmd) if x])
res = run_shell_cmd(cmd)

return res.output

# No test executed, hence no output to return
return ''

def install_step(self):
"""
Install with 'ninja install'.
Expand Down