@@ -45,6 +45,24 @@ load("//lint/private:lint_aspect.bzl", "LintOptionsInfo", "OPTIONAL_SARIF_PARSER
4545
4646_MNEMONIC = "AspectRulesLintClippy"
4747
48+ def _marker_to_exit_code (ctx , marker , exit_code ):
49+ """Write 0 to exit_code if marker exists, fail otherwise.
50+
51+ rules_rust won't write the exit code to the success_marker, so we assert that it exists and write the exit code ourselves.
52+ If there is no success marker, the action has failed anyway.
53+
54+ Args:
55+ ctx (ctx): The rule or aspect context. Must have access to `ctx.actions.run_shell`
56+ marker (File): A file that will only exist if the action has succeeded
57+ exit_code (File): A file that will be written with the exit code 0 if marker exists
58+ """
59+ ctx .actions .run_shell (
60+ outputs = [exit_code ],
61+ inputs = [marker ],
62+ arguments = [exit_code .path ],
63+ command = "echo '0' > $1" ,
64+ )
65+
4866# buildifier: disable=function-docstring
4967def _clippy_aspect_impl (target , ctx ):
5068 if not should_visit (ctx .rule , ctx .attr ._rule_kinds ):
@@ -73,31 +91,35 @@ def _clippy_aspect_impl(target, ctx):
7391 # (1) modify the patcher so that it can run an action through a macro, or
7492 # (2) modify rules_rust so that it gives us a struct with a command line we can run it with the patcher.
7593
94+ human_success_indicator = ctx .actions .declare_file (OUTFILE_FORMAT .format (label = target .label .name , mnemonic = _MNEMONIC , suffix = "human_success_indicator" ))
7695 rust_clippy_action .action (
7796 ctx ,
7897 clippy_executable = clippy_bin ,
7998 process_wrapper = ctx .executable ._process_wrapper ,
80- src = crate_info ,
99+ crate_info = crate_info ,
81100 config = ctx .file ._config_file ,
82101 output = outputs .human .out ,
83- success_marker = outputs . human . exit_code , # This won't write the exit code, but it wil only write the file if the process has succeeded.
102+ success_marker = human_success_indicator ,
84103 cap_at_warnings = True , # We don't want to crash the process if there are clippy errors, we just want to report them.
85104 extra_clippy_flags = extra_options ,
86105 )
106+ _marker_to_exit_code (ctx , human_success_indicator , outputs .human .exit_code )
87107
108+ machine_success_indicator = ctx .actions .declare_file (OUTFILE_FORMAT .format (label = target .label .name , mnemonic = _MNEMONIC , suffix = "machine_success_indicator" ))
88109 raw_machine_report = ctx .actions .declare_file (OUTFILE_FORMAT .format (label = target .label .name , mnemonic = _MNEMONIC , suffix = "raw_machine_report" ))
89110 rust_clippy_action .action (
90111 ctx ,
91112 clippy_executable = clippy_bin ,
92113 process_wrapper = ctx .executable ._process_wrapper ,
93- src = crate_info ,
114+ crate_info = crate_info ,
94115 config = ctx .file ._config_file ,
95116 output = raw_machine_report ,
96- success_marker = outputs . machine . exit_code , # This won't write the exit code, but it wil only write the file if the process has succeeded.
117+ success_marker = machine_success_indicator ,
97118 cap_at_warnings = True ,
98119 extra_clippy_flags = extra_options ,
99120 error_format = "json" ,
100121 )
122+ _marker_to_exit_code (ctx , machine_success_indicator , outputs .machine .exit_code )
101123
102124 # clippy uses rustc's IO format, which doesn't have a SARIF output mode built in,
103125 # and they're not planning to add one.
0 commit comments