File tree Expand file tree Collapse file tree
test/com/github/bazel_contrib/contrib_rules_jvm/checkstyle Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ bzl_library(
1313 name = "checkstyle" ,
1414 srcs = ["checkstyle.bzl" ],
1515 visibility = ["//java:__subpackages__" ],
16- deps = [":checkstyle_config" ],
16+ deps = [
17+ ":checkstyle_config" ,
18+ "@bazel_skylib//lib:paths" ,
19+ ],
1720)
1821
1922bzl_library (
Original file line number Diff line number Diff line change 11load (":checkstyle_config.bzl" , "CheckStyleInfo" )
22load ("@apple_rules_lint//lint:defs.bzl" , "LinterInfo" )
3+ load ("@bazel_skylib//lib:paths.bzl" , "paths" )
34
45"""
56Checkstyle rule implementation
@@ -10,12 +11,15 @@ def _checkstyle_impl(ctx):
1011 config = info .config_file
1112 output_format = info .output_format
1213
14+ config_dir = paths .dirname (config .short_path )
15+ maybe_cd_config_dir = ["cd {}" .format (config_dir )] if config_dir else []
16+
1317 script = "\n " .join ([
1418 "#!/usr/bin/env bash" ,
1519 "set -o pipefail" ,
1620 "set -e" ,
1721 "OLDPWD=$PWD" ,
18- "cd {config_dir}" . format ( config_dir = config . dirname ),
22+ ] + maybe_cd_config_dir + [
1923 "$OLDPWD/{lib} -f {output_format} -c {config} {srcs} |sed s:$OLDPWD/::g" .format (
2024 lib = info .checkstyle .short_path ,
2125 output_format = output_format ,
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ checkstyle_config(
1212 data = ["suppressions.xml" ],
1313)
1414
15+ checkstyle_config (
16+ name = "copied_checkstyle_with_suppressions" ,
17+ config_file = "copied_checkstyle_with_suppressions.xml" ,
18+ data = ["suppressions.xml" ],
19+ )
20+
1521checkstyle_test (
1622 name = "this_should_fail_missing_file" ,
1723 srcs = ["Sample.java" ],
@@ -32,8 +38,21 @@ checkstyle_test(
3238 config = ":checkstyle_with_suppressions" ,
3339)
3440
41+ checkstyle_test (
42+ name = "this_should_also_pass" ,
43+ srcs = ["Sample.java" ],
44+ config = ":copied_checkstyle_with_suppressions" ,
45+ )
46+
3547java_library (
3648 name = "checkstyle" ,
3749 testonly = True ,
3850 srcs = ["Sample.java" ],
3951)
52+
53+ genrule (
54+ name = "copy_config_file" ,
55+ srcs = ["checkstyle_with_suppressions.xml" ],
56+ outs = ["copied_checkstyle_with_suppressions.xml" ],
57+ cmd = "cp $< $@" ,
58+ )
You can’t perform that action at this time.
0 commit comments