From 0e9307eb5070e170eb1638eeb14014574b5cc4da Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 10 Aug 2026 15:44:17 +0200 Subject: [PATCH] Add dependencies of tools from toolchain to runfiles --- src/codechecker.bzl | 9 ++------- src/codechecker_toolchain.bzl | 19 +++++++++++++++++++ src/per_file.bzl | 12 +++++------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/codechecker.bzl b/src/codechecker.bzl index 6580d5c3..2f54a785 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -118,15 +118,13 @@ def _codechecker_impl(ctx): ctx.actions.run( inputs = depset( [ - info.codechecker, - info.clangsa, - info.clang_tidy, ctx.outputs.codechecker_script, ctx.outputs.codechecker_commands, ctx.outputs.codechecker_skipfile, config_file, ] + source_files, ), + tools = [info.runfiles], outputs = [ codechecker_files, ctx.outputs.codechecker_log, @@ -250,10 +248,7 @@ def _codechecker_test_impl(ctx): # Return test script and all required files run_files = default_runfiles + [ ctx.outputs.codechecker_test_script, - info.codechecker, - info.clang_tidy, - info.clangsa, - ] + ] + info.runfiles.to_list() return [ DefaultInfo( files = depset(all_files), diff --git a/src/codechecker_toolchain.bzl b/src/codechecker_toolchain.bzl index 45f83044..f8da745b 100644 --- a/src/codechecker_toolchain.bzl +++ b/src/codechecker_toolchain.bzl @@ -8,15 +8,34 @@ CodeCheckerInfo = provider( "clang_tidy": "clang-tidy executable", "clangsa": "Clang executable", "codechecker": "CodeChecker executable", + "runfiles": "Depset of files needed to run the tools: the three executables " + + "plus their transitive data_runfiles. Pass to `tools` in " + + "ctx.actions.run and include in test runfiles.", }, ) def _codechecker_toolchain_impl(ctx): + runfiles = depset( + direct = [ + ctx.executable.codechecker, + ctx.executable.clangsa, + ctx.executable.clang_tidy, + ], + transitive = [ + # We also collect files necessary for these programs to run. + # Those files should be declared with `data = [...]` + # in the executable's target. + ctx.attr.codechecker[DefaultInfo].data_runfiles.files, + ctx.attr.clangsa[DefaultInfo].data_runfiles.files, + ctx.attr.clang_tidy[DefaultInfo].data_runfiles.files, + ], + ) toolchain_info = platform_common.ToolchainInfo( codecheckerinfo = CodeCheckerInfo( codechecker = ctx.executable.codechecker, clang_tidy = ctx.executable.clang_tidy, clangsa = ctx.executable.clangsa, + runfiles = runfiles, ), ) return [toolchain_info] diff --git a/src/per_file.bzl b/src/per_file.bzl index 339a1623..d4ddad04 100644 --- a/src/per_file.bzl +++ b/src/per_file.bzl @@ -69,9 +69,6 @@ def _run_code_checker( compile_commands_json, config_file, config, - info.codechecker, - info.clangsa, - info.clang_tidy, ] + sources_and_headers else: # NOTE: we collect only headers, so CTU may not work! @@ -81,9 +78,6 @@ def _run_code_checker( config_file, src, config, - info.codechecker, - info.clangsa, - info.clang_tidy, ], transitive = [headers]) outputs = [ @@ -104,6 +98,7 @@ def _run_code_checker( inputs = inputs, outputs = outputs, executable = ctx.outputs.per_file_script, + tools = [info.runfiles], arguments = [ info.codechecker.path, data_dir, @@ -177,6 +172,7 @@ def _create_wrapper_script(ctx, options, compile_commands_json, config_file): ) def _per_file_impl(ctx): + info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo compile_commands = None for output in compile_commands_impl(ctx): if type(output) == "DefaultInfo": @@ -235,7 +231,9 @@ def _per_file_impl(ctx): files = depset( direct = all_files, ) - run_files = [ctx.outputs.test_script, info.codechecker] + all_files + run_files = [ + ctx.outputs.test_script, + ] + info.runfiles.to_list() + all_files return [ DefaultInfo( files = files,