From d1e41c25ac999f7356ff8021792681a377e42f24 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Sun, 10 Dec 2023 11:53:20 +0800 Subject: [PATCH] feat(Makefile): install `clang-format` and `clang-tidy` from PyPI --- .github/workflows/lint.yml | 14 ++++---------- Dockerfile | 2 +- Makefile | 11 ++++------- tests/requirements.txt | 2 ++ 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 472d5967..88e7ec3b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -91,21 +91,15 @@ jobs: run: | make cpplint + - name: clang-format + run: | + make clang-format + - name: clang-tidy run: | sudo apt-get update && sudo apt-get install libomp-dev --yes make clang-tidy - - name: clang-format - run: | - ( - source /etc/os-release - wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME} llvm-toolchain-${UBUNTU_CODENAME} main" --yes - ) - sudo apt-get update && sudo apt-get install clang-format --yes - make clang-format - - name: addlicense run: | make addlicense diff --git a/Dockerfile b/Dockerfile index 246a81e9..41febb5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,7 +48,7 @@ FROM builder AS devel-builder # Install extra dependencies RUN sudo apt-get update && \ - sudo apt-get install -y golang clang-format clang-tidy && \ + sudo apt-get install -y golang && \ sudo chown -R "$(whoami):$(whoami)" "$(realpath /usr/lib/go)" && \ sudo rm -rf /var/lib/apt/lists/* diff --git a/Makefile b/Makefile index e9099f0c..5cff5f05 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,6 @@ CUDA_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.cuh" -o -name " COMMIT_HASH = $(shell git log -1 --format=%h) PATH := $(HOME)/go/bin:$(PATH) PYTHON ?= $(shell command -v python3 || command -v python) -CLANG_FORMAT ?= $(shell command -v clang-format-17 || command -v clang-format) PYTESTOPTS ?= .PHONY: default @@ -96,12 +95,10 @@ cpplint-install: $(call check_pip_install,cpplint) clang-format-install: - command -v clang-format-17 || command -v clang-format || \ - sudo apt-get install -y clang-format-17 || \ - sudo apt-get install -y clang-format + $(call check_pip_install,clang-format) clang-tidy-install: - command -v clang-tidy || sudo apt-get install -y clang-tidy + $(call check_pip_install,clang-tidy) go-install: # requires go >= 1.16 @@ -172,8 +169,8 @@ cpplint: cpplint-install $(PYTHON) -m cpplint $(CXX_FILES) $(CUDA_FILES) clang-format: clang-format-install - $(CLANG_FORMAT) --version - $(CLANG_FORMAT) --style=file -i $(CXX_FILES) $(CUDA_FILES) -n --Werror + clang-format --version + clang-format --style=file -i $(CXX_FILES) $(CUDA_FILES) -n --Werror clang-tidy: clang-tidy-install cmake-configure clang-tidy --version diff --git a/tests/requirements.txt b/tests/requirements.txt index ee54732b..2fa484aa 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -26,4 +26,6 @@ doc8 pydocstyle[toml] pyenchant cpplint +clang-format +clang-tidy pre-commit