-
Notifications
You must be signed in to change notification settings - Fork 3
Distribute sanitizer/clang-tidy policies via bazelrc-preset.bzl #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ exports_files( | |
| [ | ||
| "LICENSE.md", | ||
| "NOTICE", | ||
| "presets.bzl", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # ******************************************************************************* | ||
| # 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 | ||
| # ******************************************************************************* | ||
|
|
||
| """bazelrc-preset.bzl extra_presets for the clang-tidy policy. | ||
|
|
||
| Mirrors the `test:clang-tidy` flags in clang_tidy.bazelrc, for consumers using | ||
| bazelrc-preset.bzl (https://github.com/bazel-contrib/bazelrc-preset.bzl) instead of | ||
| `import`. | ||
|
|
||
| The `aspects` value is a label relative to the consuming repo, not score_cpp_policies | ||
| — each consumer defines its own `tools/lint/linters.bzl` (see clang_tidy/README.md). | ||
| """ | ||
|
|
||
| # buildifier: keep-sorted | ||
| CLANG_TIDY_PRESETS = { | ||
| "aspects": struct( | ||
| command = "test:clang-tidy", | ||
| default = "//tools/lint:linters.bzl%clang_tidy_aspect", | ||
| description = "Run the consumer's clang-tidy aspect (see clang_tidy/README.md step 3-4) under --config=clang-tidy.", | ||
| ), | ||
| "extra_toolchains": struct( | ||
| command = "test:clang-tidy", | ||
| default = "@llvm_toolchain//:cc-toolchain-x86_64-linux", | ||
| description = "Use the LLVM toolchain registered by the consumer's llvm_toolchain extension for clang-tidy.", | ||
| ), | ||
| "output_groups": struct( | ||
|
Member
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. Is this something that is then collected by filegroup output_group selection? |
||
| command = "test:clang-tidy", | ||
| default = "+rules_lint_report", | ||
| description = "Surface the rules_lint_report output group produced by the clang-tidy aspect.", | ||
| ), | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # ******************************************************************************* | ||
| # 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 | ||
| # ******************************************************************************* | ||
|
|
||
| """Single entry point for all score_cpp_policies bazelrc-preset.bzl presets. | ||
|
|
||
| Consumers wanting every policy this repo ships should load PRESETS: | ||
|
|
||
| load("@score_cpp_policies//:presets.bzl", "PRESETS") | ||
|
|
||
| bazelrc_preset( | ||
| name = "preset", | ||
| extra_presets = PRESETS, | ||
| ) | ||
|
|
||
| Consumers wanting only one policy (e.g. sanitizers without clang-tidy) can load the | ||
| individual dicts instead: SANITIZER_PRESETS, CLANG_TIDY_PRESETS. | ||
|
|
||
| Coverage and CodeQL are not included here yet. | ||
| """ | ||
|
|
||
| load("//clang_tidy:presets.bzl", "CLANG_TIDY_PRESETS") | ||
| load("//sanitizers:presets.bzl", "SANITIZER_PRESETS") | ||
|
|
||
| PRESETS = SANITIZER_PRESETS | CLANG_TIDY_PRESETS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| # ******************************************************************************* | ||
| # 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 | ||
| # ******************************************************************************* | ||
|
|
||
| """bazelrc-preset.bzl extra_presets for the sanitizers policy. | ||
|
|
||
| Mirrors the --config=asan/ubsan/lsan/tsan/asan_ubsan_lsan/tsan_ubsan flags in | ||
| sanitizers.bazelrc, for consumers using bazelrc-preset.bzl | ||
| (https://github.com/bazel-contrib/bazelrc-preset.bzl) instead of `import`. | ||
| """ | ||
|
|
||
| _WRAPPER = "@score_cpp_policies//sanitizers:wrapper" | ||
|
|
||
| # buildifier: keep-sorted | ||
| SANITIZER_PRESETS = { | ||
| "@score_cpp_policies//sanitizers/flags:asan": struct( | ||
| command = "build:asan", | ||
| default = True, | ||
| description = "Activate the ASan cc_feature (score_asan) for the //sanitizers/flags:asan_on config_setting.", | ||
| ), | ||
| "@score_cpp_policies//sanitizers/flags:lsan": struct( | ||
| command = "build:lsan", | ||
| default = True, | ||
| description = "Activate the LSan cc_feature (score_lsan) for the //sanitizers/flags:lsan_on config_setting.", | ||
| ), | ||
| "@score_cpp_policies//sanitizers/flags:tsan": struct( | ||
| command = "build:tsan", | ||
| default = True, | ||
| description = "Activate the TSan cc_feature (score_tsan) for the //sanitizers/flags:tsan_on config_setting.", | ||
| ), | ||
| "@score_cpp_policies//sanitizers/flags:ubsan": struct( | ||
| command = "build:ubsan", | ||
| default = True, | ||
| description = "Activate the UBSan cc_feature (score_ubsan) for the //sanitizers/flags:ubsan_on config_setting.", | ||
| ), | ||
| "config": [ | ||
| struct( | ||
| command = "build:asan", | ||
| default = "with_debug_symbols", | ||
| description = "Keep debug symbols (-g1, --strip=never) so sanitizer stack traces are readable.", | ||
| ), | ||
| struct( | ||
| command = "build:ubsan", | ||
| default = "with_debug_symbols", | ||
| description = "Keep debug symbols (-g1, --strip=never) so sanitizer stack traces are readable.", | ||
| ), | ||
| struct( | ||
| command = "build:lsan", | ||
| default = "with_debug_symbols", | ||
| description = "Keep debug symbols (-g1, --strip=never) so sanitizer stack traces are readable.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan", | ||
| default = "with_debug_symbols", | ||
| description = "Keep debug symbols (-g1, --strip=never) so sanitizer stack traces are readable.", | ||
| ), | ||
| struct( | ||
| command = "build:asan_ubsan_lsan", | ||
| default = "asan", | ||
| allow_repeated = True, | ||
| description = "Composite config: address + leak + UB checking together.", | ||
| ), | ||
| struct( | ||
| command = "build:asan_ubsan_lsan", | ||
| default = "ubsan", | ||
| allow_repeated = True, | ||
| description = "Composite config: address + leak + UB checking together.", | ||
| ), | ||
| struct( | ||
| command = "build:asan_ubsan_lsan", | ||
| default = "lsan", | ||
| allow_repeated = True, | ||
| description = "Composite config: address + leak + UB checking together.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan_ubsan", | ||
| default = "tsan", | ||
| allow_repeated = True, | ||
| description = "Composite config: thread + UB checking together.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan_ubsan", | ||
| default = "ubsan", | ||
| allow_repeated = True, | ||
| description = "Composite config: thread + UB checking together.", | ||
| ), | ||
| ], | ||
| "features": [ | ||
| struct( | ||
| command = "test:with_debug_symbols", | ||
| default = "debug_symbols", | ||
| description = "Emit -g1 debug info under any sanitizer config so stack traces resolve symbols.", | ||
| ), | ||
| struct( | ||
| command = "build:asan", | ||
| default = "score_asan", | ||
| description = "Compile/link with -fsanitize=address via the score_asan cc_feature.", | ||
| ), | ||
| struct( | ||
| command = "build:ubsan", | ||
| default = "score_ubsan", | ||
| description = "Compile/link with -fsanitize=undefined via the score_ubsan cc_feature.", | ||
| ), | ||
| struct( | ||
| command = "build:lsan", | ||
| default = "score_lsan", | ||
| description = "Compile/link with -fsanitize=leak via the score_lsan cc_feature.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan", | ||
| default = "score_tsan", | ||
| description = "Compile/link with -fsanitize=thread via the score_tsan cc_feature.", | ||
| ), | ||
| ], | ||
| "platform_suffix": [ | ||
|
Member
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. Why do we need this? This will duplicate build tree for each configuration. Is there a reason why we do this? |
||
| struct( | ||
| command = "build:asan", | ||
| default = "asan", | ||
| description = "Disambiguate the asan output tree from plain builds.", | ||
| ), | ||
| struct( | ||
| command = "build:ubsan", | ||
| default = "ubsan", | ||
| description = "Disambiguate the ubsan output tree from plain builds.", | ||
| ), | ||
| struct( | ||
| command = "build:lsan", | ||
| default = "lsan", | ||
| description = "Disambiguate the lsan output tree from plain builds.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan", | ||
| default = "tsan", | ||
| description = "Disambiguate the tsan output tree from plain builds.", | ||
| ), | ||
| struct( | ||
| command = "build:asan_ubsan_lsan", | ||
| default = "asan_ubsan_lsan", | ||
| description = "Canonical suffix for the composite asan+ubsan+lsan config, overriding the per-sanitizer suffixes.", | ||
| ), | ||
| struct( | ||
| command = "build:tsan_ubsan", | ||
| default = "tsan_ubsan", | ||
| description = "Canonical suffix for the composite tsan+ubsan config, overriding the per-sanitizer suffixes.", | ||
| ), | ||
| ], | ||
| "run_under": [ | ||
| struct( | ||
| command = "test:asan", | ||
| default = _WRAPPER, | ||
| description = "Run tests under the sanitizers wrapper so suppressions/options env files are applied.", | ||
| ), | ||
| struct( | ||
| command = "test:ubsan", | ||
| default = _WRAPPER, | ||
| description = "Run tests under the sanitizers wrapper so suppressions/options env files are applied.", | ||
| ), | ||
| struct( | ||
| command = "test:lsan", | ||
| default = _WRAPPER, | ||
| description = "Run tests under the sanitizers wrapper so suppressions/options env files are applied.", | ||
| ), | ||
| struct( | ||
| command = "test:tsan", | ||
| default = _WRAPPER, | ||
| description = "Run tests under the sanitizers wrapper so suppressions/options env files are applied.", | ||
| ), | ||
| ], | ||
| "strip": struct( | ||
| command = "build:with_debug_symbols", | ||
| default = "never", | ||
| description = "Never strip symbols under any sanitizer config so stack traces remain readable.", | ||
| ), | ||
| } | ||
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.
This means they have to register all toolchains that they want to use on the project level? How then toolchain resolution is working? How this thing know which toolchain is selected?