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
5 changes: 4 additions & 1 deletion java/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ bzl_library(
name = "checkstyle",
srcs = ["checkstyle.bzl"],
visibility = ["//java:__subpackages__"],
deps = [":checkstyle_config"],
deps = [
":checkstyle_config",
"@bazel_skylib//lib:paths",
],
)

bzl_library(
Expand Down
6 changes: 5 additions & 1 deletion java/private/checkstyle.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load(":checkstyle_config.bzl", "CheckStyleInfo")
load("@apple_rules_lint//lint:defs.bzl", "LinterInfo")
load("@bazel_skylib//lib:paths.bzl", "paths")

"""
Checkstyle rule implementation
Expand All @@ -10,12 +11,15 @@ def _checkstyle_impl(ctx):
config = info.config_file
output_format = info.output_format

config_dir = paths.dirname(config.short_path)
maybe_cd_config_dir = ["cd {}".format(config_dir)] if config_dir else []

script = "\n".join([
"#!/usr/bin/env bash",
"set -o pipefail",
"set -e",
"OLDPWD=$PWD",
"cd {config_dir}".format(config_dir = config.dirname),
] + maybe_cd_config_dir + [
"$OLDPWD/{lib} -f {output_format} -c {config} {srcs} |sed s:$OLDPWD/::g".format(
lib = info.checkstyle.short_path,
output_format = output_format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ checkstyle_config(
data = ["suppressions.xml"],
)

checkstyle_config(
name = "copied_checkstyle_with_suppressions",
config_file = "copied_checkstyle_with_suppressions.xml",
data = ["suppressions.xml"],
)

checkstyle_test(
name = "this_should_fail_missing_file",
srcs = ["Sample.java"],
Expand All @@ -32,8 +38,21 @@ checkstyle_test(
config = ":checkstyle_with_suppressions",
)

checkstyle_test(
name = "this_should_also_pass",
srcs = ["Sample.java"],
config = ":copied_checkstyle_with_suppressions",
)

java_library(
name = "checkstyle",
testonly = True,
srcs = ["Sample.java"],
)

genrule(
name = "copy_config_file",
srcs = ["checkstyle_with_suppressions.xml"],
outs = ["copied_checkstyle_with_suppressions.xml"],
cmd = "cp $< $@",
)