diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 41b17f8..64fabad 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -17,7 +17,7 @@ jobs: run: | bazel run //tools:buildifier.check - check-tidy: + check-tidy-matrix: runs-on: ubuntu-latest strategy: fail-fast: false @@ -25,28 +25,20 @@ jobs: include: - bazel: latest compiler: clang-18 - example: misc-unused-alias-decls - bazel: latest compiler: clang-17 - example: misc-unused-alias-decls - bazel: latest compiler: clang-16 - example: misc-unused-alias-decls - bazel: latest compiler: clang-15 - example: misc-unused-alias-decls - bazel: latest compiler: clang-14 - example: misc-unused-alias-decls - bazel: 7.x compiler: clang-18 - example: misc-unused-alias-decls - bazel: 6.x compiler: clang-18 - example: misc-unused-alias-decls - bazel: 5.x compiler: clang-18 - example: misc-unused-alias-decls steps: - name: install ${{ matrix.compiler }} @@ -74,7 +66,7 @@ jobs: run: | set -x - cd example/${{ matrix.example }} + cd example if [[ "${{ matrix.bazel }}" < 6 ]]; then sed -i '/enable_bzlmod/d' .bazelrc @@ -85,14 +77,56 @@ jobs: --config=clang-tidy \ --color=yes \ //... | tee log || true - cat log - grep "error: .*${{ matrix.example }}" log + + grep "error: .*misc-unused-alias-decls" log + + check-tidy-extra-options: + runs-on: ubuntu-latest + steps: + - name: install clang-tidy + shell: bash + run: | + set -x + + version=18 + + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh $version + sudo apt-get install -y clang-tidy-$version libc++-$version-dev + + sudo ln -sf $(which clang-tidy-$version) /usr/bin/clang-tidy + clang-tidy-$version --version + + - uses: actions/checkout@v4 + + - name: run clang-tidy + shell: bash + env: + CC: clang-18 + run: | + set -x + + cd example + + bazel build \ + --announce_rc \ + --config=clang-tidy \ + --color=yes \ + --@rules_clang_tidy//:extra-options=--enable-check-profile \ + --@rules_clang_tidy//:extra-options=--checks='fuchsia-*' \ + //... | tee log || true + + grep "clang-tidy checks profiling" log + grep "error: .*misc-unused-alias-decls" log + grep "error: .*fuchsia-trailing-return" log all: runs-on: ubuntu-latest if: ${{ github.base_ref == 'main' }} needs: - buildifier - - check-tidy + - check-tidy-matrix + - check-tidy-extra-options steps: - run: true diff --git a/BUILD.bazel b/BUILD.bazel index ab0cec2..230a797 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,4 @@ -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +load("//private:extra_options_flag.bzl", "extra_options_flag") load("//private:path_binary_wrapper.bzl", "path_binary_wrapper") package(default_visibility = ["//visibility:public"]) @@ -36,9 +36,9 @@ label_flag( # Extra options appended after `tidy_options`. This allows extra options to be # specified on the command line (e.g. changing the checks to use with # `clang-tidy`). -string_flag( +extra_options_flag( name = "extra-options", - build_setting_default = "", + build_setting_default = [""], ) # Manually applies fixes from .yaml files contained in a specified directory. diff --git a/README.md b/README.md index 4ea5ecf..8b1110c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,8 @@ build:clang-tidy-export-fixes --remote_download_outputs=toplevel bazel build //... --config=clang-tidy-export-fixes ``` -If only a subset of checks needs to be run, those can be specified with `extra-options`. +If only a subset of checks needs to be run, those can be specified with +`extra-options`. This flag can be specified multiples times. ```sh bazel build //... --config=clang-tidy-export-fixes \ @@ -160,4 +161,4 @@ set, `clang-apply-replacements` must be in `PATH`. Similarly to ## Requirements - Bazel 5.x -- ClangTidy ?? +- ClangTidy ?? (at least 14?) diff --git a/example/misc-unused-alias-decls/.bazelrc b/example/.bazelrc similarity index 100% rename from example/misc-unused-alias-decls/.bazelrc rename to example/.bazelrc diff --git a/example/BUILD.bazel b/example/BUILD.bazel new file mode 100644 index 0000000..0eae3fe --- /dev/null +++ b/example/BUILD.bazel @@ -0,0 +1,4 @@ +cc_binary( + name = "misc-unused-alias-decls", + srcs = ["misc-unused-alias-decls.cpp"], +) diff --git a/example/misc-unused-alias-decls/WORKSPACE.bazel b/example/WORKSPACE.bazel similarity index 71% rename from example/misc-unused-alias-decls/WORKSPACE.bazel rename to example/WORKSPACE.bazel index 0592cd1..c379d96 100644 --- a/example/misc-unused-alias-decls/WORKSPACE.bazel +++ b/example/WORKSPACE.bazel @@ -1,4 +1,4 @@ local_repository( name = "rules_clang_tidy", - path = "../..", + path = "..", ) diff --git a/example/misc-unused-alias-decls/main.cpp b/example/misc-unused-alias-decls.cpp similarity index 100% rename from example/misc-unused-alias-decls/main.cpp rename to example/misc-unused-alias-decls.cpp diff --git a/example/misc-unused-alias-decls/BUILD.bazel b/example/misc-unused-alias-decls/BUILD.bazel deleted file mode 100644 index 2938ae1..0000000 --- a/example/misc-unused-alias-decls/BUILD.bazel +++ /dev/null @@ -1,4 +0,0 @@ -cc_binary( - name = "main", - srcs = ["main.cpp"], -) diff --git a/make_clang_tidy_aspect.bzl b/make_clang_tidy_aspect.bzl index 0ecfaf2..03b546a 100644 --- a/make_clang_tidy_aspect.bzl +++ b/make_clang_tidy_aspect.bzl @@ -127,7 +127,7 @@ sed --in-place --expression "s+$(pwd)+%workspace%+g" {outfile} " ".join(kwargs["tidy_options"]), ), extra_options = sub_outfile( - ctx.attr._extra_options[BuildSettingInfo].value, + " ".join(ctx.attr._extra_options[BuildSettingInfo].value), ), infile = source_file.path, outfile = out.path, diff --git a/private/extra_options_flag.bzl b/private/extra_options_flag.bzl new file mode 100644 index 0000000..00bb564 --- /dev/null +++ b/private/extra_options_flag.bzl @@ -0,0 +1,18 @@ +""" +Defines a repeatable options flag. +""" + +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") + +def _impl(ctx): + return [ + BuildSettingInfo(value = ctx.build_setting_value), + ] + +extra_options_flag = rule( + implementation = _impl, + build_setting = config.string_list( + flag = True, + repeatable = True, + ), +)