Skip to content

Commit 4983bd1

Browse files
committed
Use validation actions to ensure builds fail when their validation checks fail
Add comment Fix filenames
1 parent d774f92 commit 4983bd1

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

examples/demoapp/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ springboot(
204204
bazelrun_script = "custom_bazelrun_script.sh",
205205
boot_app_class = "com.sample.SampleMain",
206206
boot_launcher_class = "org.springframework.boot.loader.launch.JarLauncher",
207+
# Verify that dupe class checking works in this second springboot rule too
208+
dupeclassescheck_enable = True,
209+
dupeclassescheck_ignorelist = "demoapp_dupeclass_allowlist.txt",
207210
java_library = ":demoapp_lib",
208211
deps = [":rootclassloader_lib"],
209212
)

springboot/springboot.bzl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ _appjar_locator_rule = rule(
9393

9494
def _dupeclasses_rule_impl(ctx):
9595
# setup the output file (contains SUCCESS, NOT_RUN, or the list of errors)
96-
output = ctx.actions.declare_file(ctx.attr.out)
96+
output = ctx.actions.declare_file(ctx.attr.name + "_results.txt")
9797
outputs = [output]
9898

9999
if not ctx.attr.dupeclassescheck_enable:
@@ -138,7 +138,6 @@ _dupeclasses_rule = rule(
138138
"springbootjar": attr.label(),
139139
"dupeclassescheck_ignorelist": attr.label(allow_files = True),
140140
"dupeclassescheck_enable": attr.bool(),
141-
"out": attr.string(),
142141
},
143142
)
144143

@@ -147,7 +146,7 @@ _dupeclasses_rule = rule(
147146

148147
def _javaxdetect_rule_impl(ctx):
149148
# setup the output file (contains SUCCESS, NOT_RUN, or the list of errors)
150-
output = ctx.actions.declare_file(ctx.attr.out)
149+
output = ctx.actions.declare_file(ctx.attr.name + "_results.txt")
151150
outputs = [output]
152151

153152
if not ctx.attr.javaxdetect_enable:
@@ -192,15 +191,14 @@ _javaxdetect_rule = rule(
192191
"springbootjar": attr.label(),
193192
"javaxdetect_ignorelist": attr.label(allow_files = True),
194193
"javaxdetect_enable": attr.bool(),
195-
"out": attr.string(),
196194
},
197195
)
198196

199197
# ***************************************************************
200198
# BANNED DEPS RULE
201199

202200
def _banneddeps_rule_impl(ctx):
203-
output = ctx.actions.declare_file(ctx.attr.out)
201+
output = ctx.actions.declare_file(ctx.attr.name + "_results.txt")
204202
outputs = [output]
205203

206204
if ctx.attr.deps_banned == None:
@@ -236,7 +234,6 @@ _banneddeps_rule = rule(
236234
"springboot_rule_name": attr.string(),
237235
"deps_banned": attr.string_list(),
238236
"deps": attr.label_list(),
239-
"out": attr.string(),
240237
},
241238
)
242239

@@ -325,11 +322,18 @@ def _springboot_rule_impl(ctx):
325322
for data_target in data_target.files.to_list():
326323
runfiles_list.append(data_target)
327324

328-
return [DefaultInfo(
329-
files = outs,
330-
executable = outer_bazelrun_script_file,
331-
runfiles = ctx.runfiles(files = runfiles_list),
332-
)]
325+
validations = ctx.files.dupecheck_rule + ctx.files.javaxdetect_rule + ctx.files.banneddeps_rule
326+
327+
return [
328+
DefaultInfo(
329+
files = outs,
330+
executable = outer_bazelrun_script_file,
331+
runfiles = ctx.runfiles(files = runfiles_list),
332+
),
333+
# Special output group for validation results that ensures they are put into the critical
334+
# path of the build. https://bazel.build/versions/8.4.0/extending/rules#validation_actions
335+
OutputGroupInfo(_validation = validations),
336+
]
333337

334338
_springboot_rule = rule(
335339
implementation = _springboot_rule_impl,
@@ -644,7 +648,6 @@ def springboot(
644648
springbootjar = genjar_rule,
645649
dupeclassescheck_enable = dupeclassescheck_enable,
646650
dupeclassescheck_ignorelist = dupeclassescheck_ignorelist,
647-
out = "dupecheck_results.txt",
648651
tags = tags,
649652
testonly = testonly,
650653
restricted_to = restricted_to,
@@ -664,7 +667,6 @@ def springboot(
664667
springbootjar = genjar_rule,
665668
javaxdetect_enable = javaxdetect_enable,
666669
javaxdetect_ignorelist = javaxdetect_ignorelist,
667-
out = "javaxdetect_results.txt",
668670
tags = tags,
669671
testonly = testonly,
670672
restricted_to = restricted_to,
@@ -683,7 +685,6 @@ def springboot(
683685
name = bannedcheck_rule,
684686
deps = [":" + dep_aggregator_rule],
685687
deps_banned = deps_banned,
686-
out = "bannedcheck_results.txt",
687688
tags = tags,
688689
testonly = testonly,
689690
restricted_to = restricted_to,

0 commit comments

Comments
 (0)