-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Demo/WIP Add codechecker_store #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
furtib
wants to merge
3
commits into
Ericsson:main
Choose a base branch
from
furtib:codechecker-store
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| Store | ||
| ===== | ||
|
|
||
| ## store() | ||
|
|
||
| The Bazel rule `store()` uploads CodeChecker analysis results to a remote | ||
| [CodeChecker server](https://codechecker.readthedocs.io/en/latest/web/user_guide/). | ||
| It collects the analysis output from one or more `codechecker_test()` targets | ||
| and runs | ||
| [`CodeChecker store`](https://github.com/Ericsson/codechecker/blob/master/docs/web/user_guide.md#store) | ||
| under the hood. | ||
|
|
||
| To use it, add the following to your BUILD file: | ||
|
|
||
| ```python | ||
| load( | ||
| "@rules_codechecker//:defs.bzl", | ||
| "codechecker_test", | ||
| "codechecker_store", | ||
| ) | ||
| ``` | ||
|
|
||
| Create a `codechecker_test()` target and a `codechecker_store()` target that references it: | ||
|
|
||
| ```python | ||
| codechecker_test( | ||
| name = "codechecker", | ||
| targets = [ | ||
| "your_target", | ||
| ], | ||
| ) | ||
|
|
||
| codechecker_store( | ||
| name = "store", | ||
| targets = [ | ||
| ":codechecker", | ||
| ], | ||
| ) | ||
| ``` | ||
|
|
||
| Then run it, passing the server URL and a run name: | ||
|
|
||
| ```bash | ||
| bazel run //:store -- --url=http://localhost:8001/Default --name=my_run | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| | Parameter | Description | | ||
| |-------------|-----------------------------------------------------------------------------| | ||
| | `name` | Name of the store target. | | ||
| | `targets` | List of `codechecker_test()` targets whose results should be stored. | | ||
| | `toolchain` | Optional `codechecker_toolchain()` target. When set, tools from this target are used instead of Bazel's toolchain resolution. | | ||
| | `tags` | Bazel tags. The `"store"` tag is added automatically. | | ||
|
|
||
| ### Runtime arguments | ||
|
|
||
| The `--url` and `--name` arguments are required and passed after `--` on the | ||
| command line: | ||
|
|
||
| | Argument | Description | | ||
| |----------|--------------------------------------------------------------------| | ||
| | `--url` | URL of the CodeChecker server product, e.g. `http://localhost:8001/Default`. | | ||
| | `--name` | Name of the analysis run on the server. | | ||
|
|
||
|
|
||
| ### How it works | ||
|
|
||
| 1. `codechecker_test()` exposes its analysis output via an output group. | ||
| 2. `codechecker_store()` collects those files from all its target dependencies. | ||
| 3. The report data is symlinked to a writable temporary directory (Bazel outputs | ||
| are read-only and `CodeChecker store` needs write access). | ||
| 4. `CodeChecker store` is executed against the specified server. | ||
|
|
||
| > [!NOTE] | ||
| > The `codechecker_store()` rule is an executable rule (`bazel run`), not a test rule. | ||
| > It is meant to be run manually when you want to publish results. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # Copyright 2026 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Rule for storing CodeChecker analysis results on a remote server. | ||
|
|
||
| Usage: | ||
| bazel run :my_store -- --url=http://localhost:8001/Default --name=my_run | ||
| """ | ||
|
|
||
| def _store_impl(ctx): | ||
| # Resolve CodeChecker from the toolchain | ||
| if ctx.attr.toolchain: | ||
| info = ctx.attr.toolchain[platform_common.ToolchainInfo].codecheckerinfo | ||
| else: | ||
| info = ctx.toolchains["//:toolchain_type"].codecheckerinfo | ||
|
|
||
| # Collect codechecker_files entries from targets. | ||
| # | ||
| # Each entry is passed to the store script via --files. Entries may | ||
| # be either: | ||
| # * a directory (monolithic codechecker_test): report data lives | ||
| # in a "data" subdirectory inside it, and | ||
| # * individual report files (per_file_test): plists/logs that | ||
| # already live directly under the target's "data" directory. | ||
| # The store script inspects each --files entry at runtime and | ||
| # handles directories and individual files accordingly. | ||
| codechecker_files_entries = [] | ||
| for target in ctx.attr.targets: | ||
| if OutputGroupInfo in target: | ||
| files = target[OutputGroupInfo].codechecker_files.to_list() | ||
| codechecker_files_entries.extend(files) | ||
|
|
||
| if not codechecker_files_entries: | ||
| fail("No codechecker_files found in targets. " + | ||
| "Make sure targets are codechecker_test or " + | ||
| "per_file_test rules.") | ||
|
|
||
| store_script = ctx.attr._store_script[DefaultInfo].files_to_run | ||
|
|
||
| # Build --files arguments for each codechecker_files entry | ||
| files_args = " ".join([ | ||
| "--files='{}'".format(d.short_path) | ||
| for d in codechecker_files_entries | ||
| ]) | ||
|
|
||
| # Generate the launcher shell script | ||
| launcher = ctx.actions.declare_file( | ||
| ctx.label.name + "_launcher.sh", | ||
| ) | ||
| ctx.actions.write( | ||
| output = launcher, | ||
| content = """#!/bin/bash | ||
| exec {script} \ | ||
| --codechecker_path '{codechecker}' \ | ||
| {files_args} \ | ||
| "$@" | ||
| """.format( | ||
| script = store_script.executable.short_path, | ||
| codechecker = info.codechecker.short_path, | ||
| files_args = files_args, | ||
| ), | ||
| is_executable = True, | ||
| ) | ||
|
|
||
| run_files = ( | ||
| codechecker_files_entries + | ||
| [launcher] + | ||
| info.runfiles.to_list() | ||
| ) | ||
| all_runfiles = ctx.runfiles(files = run_files) | ||
| all_runfiles = all_runfiles.merge( | ||
| ctx.attr._store_script[DefaultInfo].default_runfiles, | ||
| ) | ||
|
|
||
| return [ | ||
| DefaultInfo( | ||
| executable = launcher, | ||
| runfiles = all_runfiles, | ||
| ), | ||
| ] | ||
|
|
||
| _store = rule( | ||
| implementation = _store_impl, | ||
| attrs = { | ||
| "targets": attr.label_list( | ||
| doc = "List of codechecker_test targets " + | ||
| "whose results should be stored.", | ||
| ), | ||
| "toolchain": attr.label( | ||
| default = None, | ||
| doc = "Optional toolchain() target. " + | ||
| "When set, tools from this target are used " + | ||
| "instead of Bazel's toolchain resolution.", | ||
| ), | ||
| "_store_script": attr.label( | ||
| allow_files = True, | ||
| executable = True, | ||
| cfg = "target", | ||
| default = ":store_script", | ||
| ), | ||
| }, | ||
| executable = True, | ||
| toolchains = ["//:toolchain_type"], | ||
| ) | ||
|
|
||
| def store( | ||
| name, | ||
| targets, | ||
| toolchain = None, | ||
| tags = [], | ||
| **kwargs): | ||
| """ | ||
| Macro to create a CodeChecker store target. | ||
|
|
||
| Run with: | ||
| bazel run :<name> -- --url=<server_url> --name=<run_name> | ||
|
|
||
| Args: | ||
| name: Name of the store target. | ||
| targets: List of codechecker_test targets whose | ||
| results should be stored. | ||
| toolchain: Optional toolchain() target. | ||
| tags: Bazel tags. | ||
| **kwargs: Other miscellaneous arguments. | ||
| """ | ||
| store_tags = [] + tags | ||
| if "store" not in tags: | ||
| store_tags.append("store") | ||
| _store( | ||
| name = name, | ||
| targets = targets, | ||
| toolchain = toolchain, | ||
| tags = store_tags, | ||
| # Needed to be able to depend on test targets. | ||
| testonly = True, | ||
| **kwargs | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @furtib,
This is very interesting approach! Thanks for this prototype!
But I have many practical questions, for instance:
:codecheckertest fails?Let's discuss!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
Thanks for taking a look so fast!
:codecheckertest actually fails in this case!CodeChecker cmd loginbefore it, and it worked.I have changed it so we capture everything after
--and pass it to CodeChecker. This should work for most arguments. One notable exception is the config file one; I think I should integrate this into the rule, otherwise users must use absolute paths for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do note that since
bazel runis interactive, we could also prompt the user.