Skip to content

Feat: Add option to override toolchain on a per target basis - #294

Open
furtib wants to merge 3 commits into
Ericsson:mainfrom
furtib:per-target-toolchain-selection
Open

Feat: Add option to override toolchain on a per target basis#294
furtib wants to merge 3 commits into
Ericsson:mainfrom
furtib:per-target-toolchain-selection

Conversation

@furtib

@furtib furtib commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Why:
Users want the ability to use different versions of CodeChecker (or analyzers) on a per-target basis.

What:

  • Added a codechecker_toolchain parameter to codechecker_test, through which users can override Bazel's toolchain resolution. (Preserves previous behaviour if not specified.)

Addresses:
Fixes: #278

@furtib
furtib requested a review from Szelethus August 17, 2026 11:10
@furtib furtib self-assigned this Aug 17, 2026
@furtib furtib added the enhancement New feature or request label Aug 17, 2026
@furtib furtib changed the title Feat: Add option to override toolchain on a per platform basis Feat: Add option to override toolchain on a per target basis Aug 17, 2026
@furtib
furtib force-pushed the per-target-toolchain-selection branch from 49eeec8 to 8c383e1 Compare August 17, 2026 11:28
Comment thread src/codechecker.bzl Outdated
config_file, codechecker_env = get_config_file(ctx)

info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo
info = resolve_toolchain_info(ctx)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of doubt that we need a function here...

if ctx.attr.toolchain:
    info = ctx.attr.toolchain[platform_common.ToolchainInfo].codecheckerinfo
else:
    info = ctx.toolchains["//:toolchain_type"].codecheckerinfo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid code duplication as much as possible (we have to do this for all 3 rules: codechecker, codechecker_test and pre_file_test), but I guess we do not necessarily need it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the drawback behind small, tidy functions that are reused? I'd strongly prefer the earlier solution.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main drawback of small functions is that excessive breaking up of code increases cognitive overhead and makes it harder to follow the overall logic. The same for splitting functionality into multiple files - that increases navigation complexity, which forces you to jump between files just to trace how a feature works. Besides it makes solution less self-contained and tend to add unnecessary dependencies (tight coupling) which also leads to loosing track of them - we already have it (tools.bzl, common.bzl, codechecker_toolchain.bzl). Ultimately, a balanced and very reasonable approach should be taken when breaking down code into functions and files, and not just DRY.

Comment thread src/codechecker.bzl Outdated
Comment thread src/codechecker.bzl

@furtib furtib left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review!

Comment thread src/codechecker.bzl
Comment thread src/codechecker.bzl Outdated
Comment thread src/codechecker.bzl Outdated
config_file, codechecker_env = get_config_file(ctx)

info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo
info = resolve_toolchain_info(ctx)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid code duplication as much as possible (we have to do this for all 3 rules: codechecker, codechecker_test and pre_file_test), but I guess we do not necessarily need it.

@furtib
furtib force-pushed the per-target-toolchain-selection branch from f4a947e to 0c119c9 Compare August 19, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-target toolchain selection argument

3 participants