Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve Bazel easyblock: add support for running tests, enable static linking, use build dir rather than tmpdir, verbose output #2285

Merged
Merged
Changes from 3 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
48 changes: 47 additions & 1 deletion easybuild/easyblocks/b/bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from distutils.version import LooseVersion
import glob
import os
import tempfile

import easybuild.tools.environment as env
from easybuild.framework.easyblock import EasyBlock
Expand Down Expand Up @@ -96,13 +97,24 @@ def fixup_hardcoded_paths(self):

apply_regex_substitutions(os.path.join('tools', 'cpp', 'CROSSTOOL'), regex_subs)

def prepare_step(self, *args, **kwargs):
"""Setup bazel output root"""
super(EB_Bazel, self).prepare_step(*args, **kwargs)
self.bazel_tmp_dir = tempfile.mkdtemp(suffix='-bazel-tmp', dir=self.builddir)
self.output_user_root = tempfile.mkdtemp(suffix='-bazel-root', dir=self.builddir)

def configure_step(self):
"""Custom configuration procedure for Bazel."""

# Last instance of hardcoded paths was removed in 0.24.0
if LooseVersion(self.version) < LooseVersion('0.24.0'):
self.fixup_hardcoded_paths()

# Keep temporary directory in case of error. EB will clean it up on success
apply_regex_substitutions(os.path.join('scripts', 'bootstrap', 'buildenv.sh'), [
(r'atexit cleanup_tempdir_.*', '')
])

# enable building in parallel
bazel_args = '--jobs=%d' % self.cfg['parallel']

Expand All @@ -112,13 +124,47 @@ def configure_step(self):
# See https://github.com/bazelbuild/bazel/issues/10377
bazel_args += ' --host_javabase=@local_jdk//:jdk'

# Link C++ libs statically, see https://github.com/bazelbuild/bazel/issues/4137
env.setvar('BAZEL_LINKOPTS', '-static-libstdc++:-static-libgcc')
env.setvar('BAZEL_LINKLIBS', '-l%:libstdc++.a')
boegel marked this conversation as resolved.
Show resolved Hide resolved

env.setvar('EXTRA_BAZEL_ARGS', bazel_args)
env.setvar('EMBED_LABEL', self.version)
env.setvar('VERBOSE', 'yes')

def build_step(self):
"""Custom build procedure for Bazel."""
cmd = '%s ./compile.sh' % self.cfg['prebuildopts']
cmd = ' '.join([
"TMPDIR='%s'" % self.bazel_tmp_dir, # The initial bootstrap of bazel is done in TMPDIR
self.cfg['prebuildopts'],
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
"bash -c 'set -x && ./compile.sh'", # Show the commands the script is running to faster debug failures
])
run_cmd(cmd, log_all=True, simple=True, log_ok=True)

def test_step(self):
"""Test the compilation"""

runtest = self.cfg['runtest']
if runtest:
# This could be used to pass options to Bazel: runtest = '--bazel-opt=foo test'
if runtest is True:
runtest = 'test'
lexming marked this conversation as resolved.
Show resolved Hide resolved
cmd = " ".join([
self.cfg['pretestopts'],
os.path.join('output', 'bazel'),
# Avoid bazel using $HOME
'--output_user_root=%s' % self.output_user_root,
runtest,
'--jobs=%d' % self.cfg['parallel'],
'--host_javabase=@local_jdk//:jdk',
# Be more verbose
'--subcommands', '--verbose_failures',
# Just build tests
'--build_tests_only',
self.cfg['testopts']
])
run_cmd(cmd, log_all=True, simple=True)

def install_step(self):
"""Custom install procedure for Bazel."""
copy_file(os.path.join('output', 'bazel'), os.path.join(self.installdir, 'bin', 'bazel'))
Expand Down