Skip to content

Commit

Permalink
bazel: apply buildifier
Browse files Browse the repository at this point in the history
* documenting arguments and modules as well
  • Loading branch information
manuelnaranjo committed Mar 12, 2024
1 parent 66508ea commit 9cb6aba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)

bazel_dep(name = "contrib_rules_jvm", version = "0.24.0")

bazel_dep(name = "rules_java", version = "7.4.0")
bazel_dep(name = "rules_jvm_external", version = "6.0")

Expand Down
4 changes: 3 additions & 1 deletion e2e/smoke/sample-from-upstream/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ java_pitest_test(
"--verbosity=TRACE",
"--testPlugin=junit5",
],
library_target = ":sample-from-upstream",
library_targets = [
":sample-from-upstream",
],
target_classes = ["com.example.*"],
test_targets = [
":com_example_test_HasExcludedMethodsTesteeTest",
Expand Down
33 changes: 20 additions & 13 deletions pitest/private/rules.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@rules_java//java:defs.bzl", "java_test", "java_common")
"rule implementation for pitest"

load("@rules_java//java:defs.bzl", "java_common", "java_test")

# Common package prefixes, in the order we want to check for them
_PREFIXES = (".com.", ".org.", ".net.", ".io.", ".ai.", ".co.", ".me.")
Expand Down Expand Up @@ -39,7 +41,7 @@ def _extract_jar_impl(ctx):
)

for x in ctx.files.target:
cmd = "{cmd}$CWD/{jar_path} -xf $CWD/{file};\n".format(cmd = cmd, jar_path = jar_path, file=x.path)
cmd = "{cmd}$CWD/{jar_path} -xf $CWD/{file};\n".format(cmd = cmd, jar_path = jar_path, file = x.path)

cmd = "%srm -rf META-INF;\n" % cmd

Expand All @@ -51,12 +53,12 @@ def _extract_jar_impl(ctx):
use_default_shell_env = True,
)

return DefaultInfo(files=depset([out]))
return DefaultInfo(files = depset([out]))

_extract_jar = rule(
implementation = _extract_jar_impl,
attrs = {
"target": attr.label_list(allow_files=True),
"target": attr.label_list(allow_files = True),
"_jdk": attr.label(
default = "@rules_java//toolchains:current_host_java_runtime",
providers = [java_common.JavaRuntimeInfo],
Expand All @@ -75,7 +77,7 @@ def java_pitest_test(
src_dirs = [],
data = [],
test_targets = [],
library_target = None,
library_targets = [],
target_classes = [],
**kwargs):
"""Runs pitest test using Bazel.
Expand All @@ -90,21 +92,27 @@ def java_pitest_test(
specified, the class name will be inferred from a combination of
the current bazel package and the `name` attribute.
runtime_deps: Additional runtime dependencies for the test.
**kwargs: Aditional flags to the test
args: extra args for the pitest cli
srcs: java source files to make available to the mutate tree
src_dirs: directories to enable for pitest
data: extra data to pass into the pitest runfiles
test_targets: bazel test targets that are used by pitest
library_targets: bazel libraries that are going to be mutated by pitest
target_classes: pitest targetClasses cli argument
package_prefixes: List of prefixes for your maven targets
**kwargs: Aditional flags to the test
"""
if test_class:
clazz = test_class
else:
clazz = _get_package_name(package_prefixes) + name



src_dirs = [native.package_name()] + src_dirs

_extract_jar(
name = "%s-classes" % name,
target = [ library_target ]
target = library_targets,
)

_extract_jar(
Expand All @@ -113,7 +121,6 @@ def java_pitest_test(
testonly = True,
)


args = list(args)
args += [
"--reportDir",
Expand All @@ -133,15 +140,15 @@ def java_pitest_test(
main_class = "org.pitest.mutationtest.commandline.MutationCoverageReport",
test_class = clazz,
runtime_deps = runtime_deps,
data = srcs + data + test_targets + [
library_target,
data = srcs + data + test_targets + library_targets + [
":%s-classes" % name,
":%s-test-classes" % name,
"@rules_java//toolchains:current_java_runtime",
],
args = args,
jvm_flags = [
"-cp", "$$CLASSPATH:$(location :%s-classes):$(location :%s-test-classes)" % (name, name)
"-cp",
"$$CLASSPATH:$(location :%s-classes):$(location :%s-test-classes)" % (name, name),
],
**kwargs
)

0 comments on commit 9cb6aba

Please sign in to comment.