-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: making progress with the rules
- Loading branch information
1 parent
ad7a8ec
commit 841621b
Showing
9 changed files
with
134 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"Public API re-exports" | ||
|
||
def example(): | ||
"""This is an example""" | ||
pass | ||
load("//pitest/private:rules.bzl", _java_pitest_test = "java_pitest_test") | ||
|
||
java_pitest_test = _java_pitest_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,7 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@rules_java//java:defs.bzl", "java_binary") | ||
|
||
bzl_library( | ||
name = "versions", | ||
srcs = ["versions.bzl"], | ||
visibility = ["//pitest:__subpackages__"], | ||
) | ||
|
||
java_binary( | ||
name = "pitest-cli", | ||
runtime_deps = [ | ||
"@maven_pitest//:org_pitest_pitest_command_line" | ||
], | ||
main_class = "org.pitest.mutationtest.commandline.MutationCoverageReport", | ||
visibility = ["//pitest:__subpackages__"] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,77 @@ | ||
def _pitest_impl(ctx): | ||
print("inside rule", ctx) | ||
pass | ||
|
||
pitest = rule( | ||
implemenation = _pitest_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files = True), | ||
"targetClasses": attr.string_list(), | ||
"outputFormat": attr.string_list(default=["HTML"]), | ||
"outputEncoding": attr.string(default = "UTF-8"), | ||
"target": attr.label(mandatory = True, cfg = "exec"), | ||
"extraArguments": attr.string_dict(default = {}), | ||
"_pitest_cli": attr.label( | ||
default = "//pitest/private:pitest-cli", | ||
cfg = "exec" | ||
), | ||
} | ||
) | ||
load("@rules_java//java:defs.bzl", "java_test") | ||
|
||
# Common package prefixes, in the order we want to check for them | ||
_PREFIXES = (".com.", ".org.", ".net.", ".io.", ".ai.", ".co.", ".me.") | ||
|
||
# By default bazel computes the name of test classes based on the | ||
# standard Maven directory structure, which we may not always use, | ||
# so try to compute the correct package name. | ||
# | ||
# this method is based on: https://github.com/bazel-contrib/rules_jvm/blob/f0a9a36e881f4813f50656eaee81f9988b2b7d29/java/private/package.bzl#L7 | ||
def _get_package_name(prefixes = []): | ||
pkg = native.package_name().replace("/", ".") | ||
if len(prefixes) == 0: | ||
prefixes = _PREFIXES | ||
|
||
for prefix in prefixes: | ||
idx = pkg.find(prefix) | ||
if idx != -1: | ||
return pkg[idx + 1:] + "." | ||
|
||
return "" | ||
|
||
def java_pitest_test( | ||
name, | ||
test_class = None, | ||
package_prefixes = [], | ||
runtime_deps = [], | ||
args = [], | ||
srcs = [], | ||
src_dirs = [], | ||
data = [], | ||
target = None, | ||
target_classes = [], | ||
**kwargs): | ||
"""Runs pitest test using Bazel. | ||
This is designed to be a drop-in replacement for `java_test`, but | ||
rather than using a JUnit4 runner it provides support for using | ||
pitest directly. The arguments are the same as used by `java_test`. | ||
Args: | ||
name: The name of the test. | ||
test_class: The Java class to be loaded by the test runner. If not | ||
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 | ||
package_prefixes: List of prefixes for your maven targets | ||
""" | ||
if test_class: | ||
clazz = test_class | ||
else: | ||
clazz = _get_package_name(package_prefixes) + name | ||
|
||
src_dirs = [native.package_name()] + src_dirs | ||
|
||
args = list(args) | ||
args += [ | ||
"--reportDir", | ||
"report-dir", | ||
"--sourceDirs", | ||
",".join(src_dirs), | ||
"--targetClasses", | ||
",".join(target_classes), | ||
] | ||
|
||
java_test( | ||
name = name, | ||
main_class = "org.pitest.mutationtest.commandline.MutationCoverageReport", | ||
test_class = clazz, | ||
runtime_deps = runtime_deps + [ | ||
"@com_bookingcom_rules_pitest//pitest:org_pitest_pitest_command_line", | ||
], | ||
data = srcs + data + [target], | ||
args = args, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters