Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 15 additions & 8 deletions bazel/private/gtest_report.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The tests are run as part of the build, and the generated XML report is made ava
ATTENTION:
This rule will not rerun tests unless this rule was modified or the test executable was modified.
E.g. Bazel arguments like "--runs_per_test" do not have an effect on this rule.
"""

_RULE_ATTRS = {
# In order for args expansion to work in bazel for an executable rule
Expand All @@ -27,7 +26,7 @@ _RULE_ATTRS = {
),
}

def _gtest_report_subrule_impl(ctx, name, executable, inputs):
def _gtest_report_subrule_impl(ctx, name, executable, inputs, suppress_stdout = False):
link = ctx.actions.declare_file(name + "_runner")
xml = ctx.actions.declare_file("{}_test.xml".format(name))

Expand All @@ -40,12 +39,20 @@ def _gtest_report_subrule_impl(ctx, name, executable, inputs):
args = ctx.actions.args()
args.add("--gtest_output=xml:{}".format(xml.path))

ctx.actions.run(
outputs = [xml],
inputs = depset([executable], transitive = [inputs]),
arguments = [args],
executable = link,
)
if suppress_stdout:
ctx.actions.run_shell(
outputs = [xml],
inputs = depset([link, executable], transitive = [inputs]),
arguments = [args],
command = '"{}" "$@" >/dev/null'.format(link.path),
)
else:
ctx.actions.run(
outputs = [xml],
inputs = depset([executable], transitive = [inputs]),
arguments = [args],
executable = link,
)

return xml

Expand Down
50 changes: 34 additions & 16 deletions bazel/private/lobster_test.bzl
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
load("//bazel:providers.bzl", "LobsterProvider")

def _lobster_report_subrule_impl(ctx, inputs, lobster_config, _lobster_report):
def _lobster_report_subrule_impl(ctx, inputs, lobster_config, suppress_stdout = False, _lobster_report = None):
lobster_report = ctx.actions.declare_file(ctx.label.name + "_report.json")

args = ctx.actions.args()
args.add_all(["--lobster-config", lobster_config.path])
args.add_all(["--out", lobster_report.path])

ctx.actions.run(
executable = _lobster_report,
inputs = depset(inputs + [lobster_config]),
outputs = [lobster_report],
arguments = [args],
progress_message = "lobster-report {}".format(lobster_report.path),
)
if suppress_stdout:
ctx.actions.run_shell(
inputs = depset(inputs + [lobster_config]),
outputs = [lobster_report],
arguments = [args],
command = '"{executable}" "$@" >/dev/null'.format(executable = _lobster_report.path),
progress_message = "lobster-report {}".format(lobster_report.path),
)
else:
ctx.actions.run(
executable = _lobster_report,
inputs = depset(inputs + [lobster_config]),
outputs = [lobster_report],
arguments = [args],
progress_message = "lobster-report {}".format(lobster_report.path),
)

return lobster_report

Expand All @@ -28,7 +37,7 @@ subrule_lobster_report = subrule(
},
)

def _lobster_html_report_subrule_impl(ctx, lobster_report, _lobster_html_report):
def _lobster_html_report_subrule_impl(ctx, lobster_report, suppress_stdout = False, _lobster_html_report = None):
lobster_html_report = ctx.actions.declare_file("{}_report.html".format(ctx.label.name))

# Compute relative path from the HTML output back to the workspace root so
Expand All @@ -43,13 +52,22 @@ def _lobster_html_report_subrule_impl(ctx, lobster_report, _lobster_html_report)
args.add_all(["--out", lobster_html_report.path])
args.add_all(["--source-root", source_root])

ctx.actions.run(
executable = _lobster_html_report,
inputs = [lobster_report],
outputs = [lobster_html_report],
arguments = [args],
progress_message = "lobster-html-report {}".format(lobster_html_report.path),
)
if suppress_stdout:
ctx.actions.run_shell(
inputs = [lobster_report],
outputs = [lobster_html_report],
arguments = [args],
command = '"{executable}" "$@" >/dev/null'.format(executable = _lobster_html_report.path),
progress_message = "lobster-html-report {}".format(lobster_html_report.path),
)
else:
ctx.actions.run(
executable = _lobster_html_report,
inputs = [lobster_report],
outputs = [lobster_html_report],
arguments = [args],
progress_message = "lobster-html-report {}".format(lobster_html_report.path),
)

return lobster_html_report

Expand Down
Loading