@@ -10,6 +10,10 @@ _ATTRS = {
1010 executable = True ,
1111 cfg = "exec" ,
1212 ),
13+ "_final_result_template" : attr .label (
14+ default = Label ("//detekt:final_result.sh.tpl" ),
15+ allow_single_file = True ,
16+ ),
1317 "srcs" : attr .label_list (
1418 mandatory = True ,
1519 allow_files = [".kt" , ".kts" ],
@@ -217,8 +221,9 @@ def _impl(
217221 action_inputs .extend (platform_jar_files + classpath )
218222 detekt_arguments .add ("--classpath" , ":" .join ([f .path for f in platform_jar_files ] + [f .path for f in classpath ]))
219223
220- action_inputs .extend (ctx .files .plugins )
221- detekt_arguments .add_joined ("--plugins" , ctx .files .plugins , join_with = "," )
224+ plugin_jars = [plugin for plugin in ctx .files .plugins if plugin .extension == "jar" ]
225+ action_inputs .extend (plugin_jars )
226+ detekt_arguments .add_joined ("--plugins" , plugin_jars , join_with = "," )
222227
223228 txt_report = ctx .actions .declare_file ("{}_detekt_report.txt" .format (ctx .label .name ))
224229 action_outputs .append (txt_report )
@@ -246,14 +251,13 @@ def _impl(
246251
247252 execution_result = ctx .actions .declare_file ("{}_exit_code.txt" .format (ctx .label .name ))
248253 run_files .append (execution_result )
249- action_outputs .append (execution_result )
250254 detekt_arguments .add ("--execution-result" , "{}" .format (execution_result .path ))
251255
252256 ctx .actions .run (
253257 mnemonic = "Detekt" ,
254258 progress_message = "Running Detekt for {}" .format (str (ctx .label )),
255259 inputs = action_inputs ,
256- outputs = action_outputs ,
260+ outputs = action_outputs + [ execution_result ] ,
257261 executable = ctx .executable ._detekt_wrapper ,
258262 execution_requirements = {
259263 "requires-worker-protocol" : "proto" ,
@@ -267,19 +271,14 @@ def _impl(
267271 # Note: this is not compatible with Windows, feel free to submit PR!
268272 # text report-contents are always printed to shell
269273 final_result = ctx .actions .declare_file (ctx .attr .name + ".sh" )
270- ctx .actions .write (
274+ ctx .actions .expand_template (
271275 output = final_result ,
272- content = """
273- #!/bin/bash
274- set -euo pipefail
275- exit_code=$(cat {execution_result})
276- report=$(cat {text_report})
277- if [ ! -z "$report" ]; then
278- echo "$report"
279- fi
280- {baseline_script}
281- exit "$exit_code"
282- """ .format (execution_result = execution_result .short_path , text_report = txt_report .short_path , baseline_script = baseline_script ),
276+ template = ctx .file ._final_result_template ,
277+ substitutions = {
278+ "{baseline_script}" : baseline_script ,
279+ "{execution_result}" : execution_result .short_path ,
280+ "{text_report}" : txt_report .short_path ,
281+ },
283282 is_executable = True ,
284283 )
285284
0 commit comments