diff --git a/.github/workflows/lint_pull_request.yml b/.github/workflows/lint_pull_request.yml index 732f8c4b4e..ffd5e31c52 100644 --- a/.github/workflows/lint_pull_request.yml +++ b/.github/workflows/lint_pull_request.yml @@ -23,6 +23,13 @@ jobs: - name: diff scan, clang-tidy for all files which are in `.clang-tidy-diff-scans.txt` run: ./tools/scripts/clang_tidy_check.sh scan_list .clang-tidy-diff-scans.txt "${{ steps.changed_files.outputs.added_modified }}" + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 + check-for-todo: runs-on: ubuntu-24.04 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..868d587e1d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +exclude: ^bazel- +repos: + - repo: https://github.com/warchant/pre-commit-buildifier + rev: 0.1.3 + hooks: + - id: buildifier + args: ["--version=v8.0.3", "--lint=warn", "--warnings=all", "-v"] diff --git a/BUILD.bazel b/BUILD.bazel index 3955fa5006..4132c3bfe0 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -15,7 +15,6 @@ # SPDX-License-Identifier: Apache-2.0 load("@bazel_skylib//rules:common_settings.bzl", "string_flag") -load("@buildifier_prebuilt//:rules.bzl", "buildifier") exports_files(["LICENSE"]) @@ -57,33 +56,3 @@ alias( actual = "//iceoryx_posh:iox-roudi", visibility = ["//visibility:public"], ) - -# Execute `bazel run //:buildifier` to fix formating of all starlark files in the workspace -buildifier( - name = "buildifier", - verbose = True, -) - -# Execute `bazel run //:buildifier_test` to check all starlark files for correctness -buildifier( - name = "buildifier_test", - mode = "check", - verbose = True, -) - -# Execute `bazel run //:buildifier_lint` to reformat and run the linter on all starlark files -buildifier( - name = "buildifier_lint", - lint_mode = "fix", - lint_warnings = ["all"], - verbose = True, -) - -# Execute `bazel run //:buildifier_lint_check` to reformat and run the linter on all starlark files -buildifier( - name = "buildifier_lint_check", - lint_mode = "warn", - lint_warnings = ["all"], - mode = "check", - verbose = True, -) diff --git a/MODULE.bazel b/MODULE.bazel index 21dd12f671..9e2bedbe69 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,11 +8,6 @@ bazel_dep(name = "cpptoml", version = "0.1.1") bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "rules_cc", version = "0.1.1") -bazel_dep( - name = "buildifier_prebuilt", - version = "7.1.2", - dev_dependency = True, -) bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True) bazel_dep(name = "ncurses", version = "6.4.20221231.bcr.4") diff --git a/bazel/buildifier_prebuilt/BUILD.bazel b/bazel/buildifier_prebuilt/BUILD.bazel deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bazel/buildifier_prebuilt/repositories.bzl b/bazel/buildifier_prebuilt/repositories.bzl deleted file mode 100644 index a873c9f8a5..0000000000 --- a/bazel/buildifier_prebuilt/repositories.bzl +++ /dev/null @@ -1,35 +0,0 @@ -""" -Copyright 2024, Eclipse Foundation and the iceoryx contributors. All rights reserved. - -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. - -SPDX-License-Identifier: Apache-2.0 - -This module downloads the buildifier prebuilt project and its deps: https://github.com/keith/buildifier-prebuilt -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - -BUILDIFIER_PREBUILT_VERSION = "7.3.1" - -def load_buildifier_prebuilt_repositories(): - maybe( - name = "buildifier_prebuilt", - repo_rule = http_archive, - sha256 = "7f85b688a4b558e2d9099340cfb510ba7179f829454fba842370bccffb67d6cc", - strip_prefix = "buildifier-prebuilt-{version}".format(version = BUILDIFIER_PREBUILT_VERSION), - urls = [ - "http://github.com/keith/buildifier-prebuilt/archive/{version}.tar.gz".format(version = BUILDIFIER_PREBUILT_VERSION), - ], - ) diff --git a/bazel/buildifier_prebuilt/setup.bzl b/bazel/buildifier_prebuilt/setup.bzl deleted file mode 100644 index c0444b59b4..0000000000 --- a/bazel/buildifier_prebuilt/setup.bzl +++ /dev/null @@ -1,27 +0,0 @@ -""" -Copyright 2024, Eclipse Foundation and the iceoryx contributors. All rights reserved. - -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. - -SPDX-License-Identifier: Apache-2.0 - -This module prepares the buildifier prebuilt project and its deps: https://github.com/keith/buildifier-prebuilt -""" - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -def setup_buildifier_prebuilt(): - buildifier_prebuilt_deps() - - buildifier_prebuilt_register_toolchains() diff --git a/bazel/load_repositories.bzl b/bazel/load_repositories.bzl index 94547fe2a1..9de6baa26f 100644 --- a/bazel/load_repositories.bzl +++ b/bazel/load_repositories.bzl @@ -17,7 +17,6 @@ SPDX-License-Identifier: Apache-2.0 """ load("//bazel/bazelbuild:repositories.bzl", "load_com_github_bazelbuild_rules_cc_repositories") -load("//bazel/buildifier_prebuilt:repositories.bzl", "load_buildifier_prebuilt_repositories") load("//bazel/cpptoml:repositories.bzl", "load_cpptoml_repositories") load("//bazel/googletest:repositories.bzl", "load_googletest_repositories") load("//bazel/ncurses:repositories.bzl", "load_ncurses_repositories") @@ -29,7 +28,6 @@ def load_repositories(): """ load_com_github_bazelbuild_rules_cc_repositories() load_bazel_skylib_repositories() - load_buildifier_prebuilt_repositories() load_googletest_repositories() load_cpptoml_repositories() load_ncurses_repositories() diff --git a/bazel/setup_repositories.bzl b/bazel/setup_repositories.bzl index 6c303434ea..15756b0a59 100644 --- a/bazel/setup_repositories.bzl +++ b/bazel/setup_repositories.bzl @@ -16,7 +16,6 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 """ -load("//bazel/buildifier_prebuilt:setup.bzl", "setup_buildifier_prebuilt") load("//bazel/skylib:setup.bzl", "setup_skylib") def setup_repositories(): @@ -24,4 +23,3 @@ def setup_repositories(): Loads repositories for iceoryx dependencies """ setup_skylib() - setup_buildifier_prebuilt() diff --git a/doc/website/advanced/installation-guide-for-contributors.md b/doc/website/advanced/installation-guide-for-contributors.md index 2cbb1f128a..862b94d598 100644 --- a/doc/website/advanced/installation-guide-for-contributors.md +++ b/doc/website/advanced/installation-guide-for-contributors.md @@ -156,27 +156,25 @@ When working with Bazel, additional tools can help the developer to maintain a consistent codebase similar to the Clang Tools (clang-format and clang-tidy) for C++. The [Buildifier Tool](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md) offers formatting and linting for Bazel files. +It is integrated via [pre-commit](https://pre-commit.com/). +You may install pre-commit with the following command: -The formatting is based on rules given by Buildifier and the linting is based on -a list of [warnings](https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md). +```bash +pip install -U pre-commit identify +``` -To check formatting of the Bazel files the following command needs to run in the iceoryx -workspace. +You can invoke pre-commit manually (inside the repository) on all changed files: ```bash -cd iceoryx -bazel run //:buildifier +pre-commit ``` -Buildifier automatically reformat the code. - -For formatting and linting this command will do the job: +or you can install it as a git hook which will automatically run before every commit: ```bash -cd iceoryx -bazel run //:buildifier_lint +pre-commit install ``` -The CI will check for the correct formatting and linting. -See the `BUILD.bazel` file -in iceoryx workspace for available commands. +pre-commit runs a list of checks that check for the correct formatting and linting. + +There is a CI job that runs pre-commit on all changes files in a pull request. diff --git a/tools/ci/build-test-ubuntu-bazel.sh b/tools/ci/build-test-ubuntu-bazel.sh index f6e8515d85..0b2b91c00e 100755 --- a/tools/ci/build-test-ubuntu-bazel.sh +++ b/tools/ci/build-test-ubuntu-bazel.sh @@ -34,9 +34,6 @@ $(gcc --version) $(clang --version) $(bazel --version)" -msg "Linting Bazel files" -bazel run //:buildifier_lint_check - # Build everything including stresstests msg "Bazel build" bazel build //...