-
Notifications
You must be signed in to change notification settings - Fork 93
CodeQL: Have better pack selection (use really the vendored one) #757
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
Changes from all commits
2f05514
f9ad8bd
f5075f9
d9dc397
50059e7
819d6c1
3c9846a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,20 +433,45 @@ bazel_dep(name = "rules_pkg", version = "1.2.0", dev_dependency = True) | |
|
|
||
| http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| # CodeQL Coding Standards release used for BOTH the query sources / report | ||
| # scripts (@codeql_coding_standards) and the pre-compiled query pack | ||
| # (@codeql_coding_standards_compiled). These two must always come from the same | ||
| # release, so their version is defined once here and both derive their download | ||
| # URL from it. | ||
| CODING_STANDARDS_VERSION = "2.61.0" | ||
|
|
||
| # The version of this tool needs to be deduced by the mentioned compatible version of the codeql_coding_standards release! | ||
| http_archive( | ||
| name = "codeql_bundle", | ||
| build_file = "//third_party/codeql:codeql.BUILD", | ||
| sha256 = "0144d4bc415aee0d5638119dfb626a2d8689e2ff21758ba211a3984862b8522c", | ||
| url = "https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.26.0/codeql-bundle-linux64.tar.gz", | ||
| sha256 = "a94f674bb3c23ea5e9a2ad06b64847dd0277b15014d2517ecd9c41c88e6caa65", | ||
| url = "https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.21.4/codeql-bundle-linux64.tar.gz", | ||
| ) | ||
|
|
||
| git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
|
||
| git_repository( | ||
| http_archive( | ||
| name = "codeql_coding_standards", | ||
| build_file = "//third_party/codeql:codeql_coding_standards.BUILD", | ||
| commit = "06dc6bc32b05152fbe94dbf341a3e854574c9df5", # v2.61.0 | ||
| remote = "https://github.com/github/codeql-coding-standards.git", | ||
| patch_args = ["-p1"], | ||
| patches = ["//third_party/codeql:codeql_coding_standards_misra.patch"], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also create a PR upstream for that? It seems to be that it should be trivial for them to accept
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already did: github/codeql-coding-standards#1163 |
||
| sha256 = "a0ab708bfcd06e29b5f1ddaf49470bd5f234aa23de527aa893572a25a6ff7f47", | ||
| strip_prefix = "codeql-coding-standards-{version}".format(version = CODING_STANDARDS_VERSION), | ||
| urls = ["https://github.com/github/codeql-coding-standards/archive/refs/tags/v{version}.tar.gz".format(version = CODING_STANDARDS_VERSION)], | ||
| ) | ||
|
|
||
| # The MISRA C++ analysis runs a pre-compiled query pack published with the | ||
| # codeql-coding-standards release (see codeql_release_pack.bzl). This avoids | ||
| # compiling the queries locally while keeping the analysis hermetic (pinned by | ||
| # sha256) and aligned with the pinned coding_standards version above. | ||
| codeql_release_pack = use_repo_rule( | ||
| "//third_party/codeql:codeql_release_pack.bzl", | ||
| "codeql_release_pack", | ||
| ) | ||
|
|
||
| codeql_release_pack( | ||
| name = "codeql_coding_standards_compiled", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this, we have now |
||
| pack_tarball = "misra-cpp-coding-standards.tgz", | ||
| sha256 = "fdddef5a7ca1c66ebdbe6c79c60c7b5b6b274dbc3c9ecbc4bb9a0a13cead20a1", | ||
| urls = ["https://github.com/github/codeql-coding-standards/releases/download/v{version}/coding-standards-codeql-packs.zip".format(version = CODING_STANDARDS_VERSION)], | ||
| ) | ||
|
|
||
| register_toolchains( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| packs: | ||
| - codeql/misra-cpp-coding-standards@2.61.0 | ||
| # CodeQL code-scanning configuration passed to `codeql database init` | ||
| # (--codescanning-config). The MISRA C++ pack to run is intentionally NOT listed | ||
| # here: it is pinned once by the vendored pre-compiled pack (see MODULE.bazel / | ||
| # @codeql_coding_standards_compiled) and passed explicitly to `database analyze` | ||
| # by codeql_lint.py, so the pack name and version have a single source of truth. | ||
| # This file only carries analysis-wide query filters. | ||
| query-filters: | ||
| - exclude: | ||
| tags: exclude-from-incremental |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| diff --git a/scripts/reports/utils.py b/scripts/reports/utils.py | ||
| index 5751139..6fbf353 100644 | ||
| --- a/scripts/reports/utils.py | ||
| +++ b/scripts/reports/utils.py | ||
| @@ -183,7 +183,10 @@ def generate_guideline_compliance_summary(output_directory, results_summary): | ||
| print( | ||
| "**Result**: " + ("Not compliant" if total_guidelines_violated > 0 else "Compliant")) | ||
| standard_pretty_name = { | ||
| - "cert": "CERT C++ 2016", "autosar": "AUTOSAR C++ R22-11, R21-11, R20-11, R19-11 and R19-03"} | ||
| + "cert": "CERT C++ 2016", | ||
| + "autosar": "AUTOSAR C++ R22-11, R21-11, R20-11, R19-11 and R19-03", | ||
| + "misra": "MISRA C++:2023", | ||
| + } | ||
| print("**Coding Standards applied**: " + ", ".join([standard_pretty_name[standard_short_name] | ||
| for standard_short_name in results_summary.guideline_violation_count.keys()])) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| """Repository rule that vendors a pre-compiled CodeQL coding-standards pack. | ||
|
|
||
| The github/codeql-coding-standards project publishes, for every release, a | ||
| `coding-standards-codeql-packs.zip` asset that bundles each standard's query | ||
| pack **already compiled** (`.qlx` files plus all library dependencies vendored | ||
| under `.codeql/libraries/`). Using these avoids compiling the queries ourselves | ||
| (which is slow and, via `codeql pack create`, does not work inside Bazel's | ||
| sandbox), while still keeping the analysis hermetic and pinned: the download is | ||
| content-addressed by sha256 and the pack is fetched from the same release we pin | ||
| elsewhere. | ||
|
|
||
| The zip contains one `<standard>-coding-standards.tgz` per standard; this rule | ||
| extracts the requested one and exposes its contents as a `pack` filegroup whose | ||
| root is the pack directory (containing `qlpack.yml`, `codeql-suites/`, `rules/` | ||
| and `.codeql/libraries/`). | ||
| """ | ||
|
|
||
| def _codeql_release_pack_impl(repository_ctx): | ||
| repository_ctx.download( | ||
| url = repository_ctx.attr.urls, | ||
| output = "packs.zip", | ||
| sha256 = repository_ctx.attr.sha256, | ||
| ) | ||
|
|
||
| # The outer zip contains per-standard tarballs; extract only the one we need | ||
| # into the `pack/` subdirectory, which becomes the pack root. | ||
| repository_ctx.extract(archive = "packs.zip", output = "_packs") | ||
| repository_ctx.extract( | ||
| archive = "_packs/" + repository_ctx.attr.pack_tarball, | ||
| output = "pack", | ||
| ) | ||
| repository_ctx.delete("packs.zip") | ||
| repository_ctx.delete("_packs") | ||
|
|
||
| repository_ctx.file( | ||
| "BUILD.bazel", | ||
| "filegroup(\n" + | ||
| " name = \"pack\",\n" + | ||
| " srcs = glob([\"pack/**\"], allow_empty = False),\n" + | ||
| " visibility = [\"//visibility:public\"],\n" + | ||
| ")\n", | ||
| ) | ||
|
|
||
| codeql_release_pack = repository_rule( | ||
| implementation = _codeql_release_pack_impl, | ||
| doc = "Downloads and unpacks a pre-compiled coding-standards CodeQL pack.", | ||
| attrs = { | ||
| "urls": attr.string_list( | ||
| mandatory = True, | ||
| doc = "URL(s) of the coding-standards-codeql-packs.zip release asset.", | ||
| ), | ||
| "sha256": attr.string( | ||
| mandatory = True, | ||
| doc = "Expected sha256 of the downloaded zip.", | ||
| ), | ||
| "pack_tarball": attr.string( | ||
| mandatory = True, | ||
| doc = "Name of the per-standard .tgz inside the zip to extract.", | ||
| ), | ||
| }, | ||
| ) |
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.
How do we know in the future which bundle can we use together with the coding standard version? Should be put at least a comment with a link that explains how they relate to each other and what is supported with what?