Skip to content
Merged
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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "rules_mayhem",
version = "0.8.2",
version = "0.8.3",
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ common --enable_bzlmod
build --spawn_strategy=standalone
```

#### Windows settings

If you're running Windows, you'll also need to add the following:

```
# Enable platform-specific features
common --enable_platform_specific_config=true

# Windows settings
startup --windows_enable_symlinks
startup --output_user_root=C:/tmp # see https://bazel.build/versions/6.3.0/configure/windows#long-path-issues
common:windows --enable_runfiles
```

### Logging into Mayhem

To use Mayhem, you need to generate a token for your account. You can do this by logging into the Mayhem web interface and navigating to Account Settings -> API Tokens.
Expand Down
1 change: 1 addition & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ mayhem_run(
fail_on_defects = True,
junit = "mayhemit_junit.xml",
sarif = "mayhemit_sarif.json",
verbosity = "debug",
)

mayhem_download(
Expand Down
28 changes: 24 additions & 4 deletions mayhem/mayhem.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,19 @@ def mayhem_wait(ctx, mayhem_cli, mayhem_cli_exe, mayhem_out, is_windows, junit,
"""
mayhem_wait_out = ctx.actions.declare_file(ctx.label.name + ".wait.out")

wait = "wait "
junit = "--junit " + junit if junit else ""
sarif = "--sarif " + sarif if sarif else ""
fod = "--fail-on-defects" if fail_on_defects else ""
opts = " ".join([junit, sarif, fod])
opts = " ".join([wait, junit, sarif, fod])

if is_windows:
wait_wrapper = ctx.actions.declare_file(ctx.label.name + "-wait.bat")
wait_wrapper_content = """
@echo off
setlocal
for /f "tokens=*" %%i in ({input_file}) do (
{mayhem_cli} wait {opts} "%%i" >> {output_file}
{mayhem_cli} {opts} "%%i" >> {output_file}
{mayhem_cli} show "%%i" >> {output_file}
{mayhem_cli} show "%%i"
)
Expand All @@ -139,7 +140,7 @@ def mayhem_wait(ctx, mayhem_cli, mayhem_cli_exe, mayhem_out, is_windows, junit,
wait_wrapper = ctx.actions.declare_file(ctx.label.name + "-wait.sh")
wait_wrapper_content = """
#!/bin/bash
{mayhem_cli} wait {opts} $(cat {input_file}) > {output_file}
{mayhem_cli} {opts} $(cat {input_file}) > {output_file}
{mayhem_cli} show $(cat {input_file}) | tee -a {output_file}
""".format(
mayhem_cli=mayhem_cli.path,
Expand Down Expand Up @@ -171,6 +172,12 @@ def _mayhem_run_impl(ctx):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])

args_list = []
if ctx.attr.verbosity:
if ctx.attr.verbosity not in ["debug", "info"]:
fail("Invalid verbosity level: {}. Valid values are 'debug' or 'info'.".format(ctx.attr.verbosity))
else:
args_list.append("--verbosity")
args_list.append(ctx.attr.verbosity)
args_list.append("run")

if ctx.file.mayhemfile:
Expand Down Expand Up @@ -318,7 +325,7 @@ def _mayhem_run_impl(ctx):
wrapper_content = """
#!/bin/bash
echo -n {owner} > {output_file}
{mayhem_cli} --verbosity debug {args} >> {output_file}
{mayhem_cli} {args} >> {output_file}
""".format(
owner=ctx.attr.owner + "/" if ctx.attr.owner else "",
mayhem_cli=ctx.executable._mayhem_cli.path,
Expand Down Expand Up @@ -412,6 +419,7 @@ mayhem_run = rule(
"junit": attr.string(mandatory = False),
"sarif": attr.string(mandatory = False),
"fail_on_defects": attr.bool(mandatory = False),
"verbosity": attr.string(mandatory = False),
"_mayhem_cli": attr.label(
executable = True,
cfg = "exec",
Expand All @@ -427,6 +435,11 @@ def _mayhem_package_impl(ctx):
package_out = ctx.actions.declare_directory(target.basename + "-pkg")

args = ctx.actions.args()
if ctx.attr.verbosity:
if ctx.attr.verbosity not in ["debug", "info"]:
fail("Invalid verbosity level: {}. Valid values are 'debug' or 'info'.".format(ctx.attr.verbosity))
else:
args.add("--verbosity", ctx.attr.verbosity)
args.add("package")
args.add("-o", package_out.path)
args.add(target.path)
Expand All @@ -450,6 +463,7 @@ mayhem_package = rule(
implementation = _mayhem_package_impl,
attrs = {
"binary": attr.label(mandatory = True, allow_single_file = True),
"verbosity": attr.string(mandatory = False),
"_mayhem_cli": attr.label(
executable = True,
cfg = "exec",
Expand All @@ -468,6 +482,11 @@ def _mayhem_download_impl(ctx):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])

args = ctx.actions.args()
if ctx.attr.verbosity:
if ctx.attr.verbosity not in ["debug", "info"]:
fail("Invalid verbosity level: {}. Valid values are 'debug' or 'info'.".format(ctx.attr.verbosity))
else:
args.add("--verbosity", ctx.attr.verbosity)
args.add("download")
args.add("-o", output_dir.path)

Expand Down Expand Up @@ -498,6 +517,7 @@ mayhem_download = rule(
"owner": attr.string(mandatory = False),
"project": attr.string(mandatory = True),
"target": attr.string(mandatory = True),
"verbosity": attr.string(mandatory = False),
"_mayhem_cli": attr.label(
executable = True,
cfg = "exec",
Expand Down
Loading