Skip to content

Commit fde7a6a

Browse files
committed
put clang-tidy check into ci/cd
1 parent 236bbff commit fde7a6a

File tree

4 files changed

+122
-42
lines changed

4 files changed

+122
-42
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
name: Clang Tidy Check
17+
18+
on:
19+
pull_request:
20+
paths:
21+
- '.github/workflows/cpp_clang_tidy.yml'
22+
- 'cpp/**'
23+
24+
env:
25+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
26+
MVN_CMD: 'mvn -ntp'
27+
WGET_CMD: 'wget -nv'
28+
SETUP: 'source .github/workflows/util/setup-helper.sh'
29+
CCACHE_DIR: "${{ github.workspace }}/.ccache"
30+
# spark.sql.ansi.enabled defaults to false.
31+
SPARK_ANSI_SQL_MODE: false
32+
33+
concurrency:
34+
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
35+
cancel-in-progress: true
36+
37+
jobs:
38+
build-native-lib-centos-7:
39+
runs-on: ubuntu-22.04
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Get Ccache
43+
uses: actions/cache/restore@v4
44+
with:
45+
path: '${{ env.CCACHE_DIR }}'
46+
key: ccache-centos7-release-default-${{github.sha}}
47+
restore-keys: |
48+
ccache-centos7-release-default
49+
- name: Build Gluten native libraries
50+
run: |
51+
docker pull apache/gluten:vcpkg-centos-7
52+
docker run -v $GITHUB_WORKSPACE:/work -w /work apache/gluten:vcpkg-centos-7 bash -c "
53+
set -e
54+
yum install tzdata -y
55+
df -a
56+
cd /work
57+
export CCACHE_DIR=/work/.ccache
58+
mkdir -p /work/.ccache
59+
bash dev/ci-velox-buildstatic-centos-7.sh
60+
mkdir -p /work/.m2/repository/org/apache/arrow/
61+
cp -r /root/.m2/repository/org/apache/arrow/* /work/.m2/repository/org/apache/arrow/
62+
"
63+
64+
- name: "Save ccache"
65+
uses: actions/cache/save@v4
66+
id: ccache
67+
with:
68+
path: '${{ env.CCACHE_DIR }}'
69+
key: ccache-centos7-release-default-${{github.sha}}
70+
- uses: actions/upload-artifact@v4
71+
with:
72+
name: velox-native-lib-centos-7-${{github.sha}}
73+
path: ./cpp/build/
74+
if-no-files-found: error
75+
- uses: actions/upload-artifact@v4
76+
with:
77+
name: arrow-jars-centos-7-${{github.sha}}
78+
path: .m2/repository/org/apache/arrow/
79+
if-no-files-found: error
80+
81+
clang-tidy-check:
82+
needs: build-native-lib-centos-7
83+
runs-on: ubuntu-22.04
84+
container: apache/gluten:centos-8-jdk8
85+
steps:
86+
- uses: actions/checkout@v4
87+
with:
88+
fetch-depth: 0
89+
- uses: actions/download-artifact@v4
90+
with:
91+
name: velox-native-lib-centos-7-${{github.sha}}
92+
path: ./cpp/build/
93+
- name: Check Clang Tidy
94+
run: |
95+
pip3 install regex
96+
cd $GITHUB_WORKSPACE/
97+
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz
98+
tar -xvf clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz
99+
mv clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04/bin/clang-tidy /usr/bin/
100+
chmod +x /usr/bin/clang-tidy
101+
ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
102+
ls /usr/bin/clang-tidy
103+
clang-tidy -version
104+
sed -i "s|/work|$(pwd)|g" cpp/build/compile_commands.json
105+
python3 dev/check.py tidy commit --fix
106+

cpp/core/memory/ArrowMemoryPool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ArrowMemoryPool final : public arrow::MemoryPool {
5454

5555
private:
5656
std::unique_ptr<MemoryAllocator> allocator_;
57+
5758
ArrowMemoryPoolReleaser releaser_;
5859
};
5960

dev/check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def header_command(commit, files, fix):
168168

169169

170170
def tidy_command(commit, files, fix):
171-
files = [file for file in files if regex.match(r".*\.cpp$", file)]
171+
files = [file for file in files if regex.match(r".*\.(cc|cpp|h)$", file)]
172172

173173
if not files:
174174
return 0
@@ -177,7 +177,7 @@ def tidy_command(commit, files, fix):
177177
fix = "--fix" if fix == "fix" else ""
178178

179179
status, stdout, stderr = util.run(
180-
f"{SCRIPTS}/run-clang-tidy.py {commit} {fix} -", input=files
180+
f"{SCRIPTS}/run-clang-tidy.py {commit} {fix} ", input=files
181181
)
182182

183183
if stdout != "":

cpp/run-clang-tidy.py renamed to dev/run-clang-tidy.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -113,53 +113,28 @@ def check_output_has_warnings(output):
113113
return bool(regex.search(r"(?i)\b(warning|error):", output))
114114

115115

116-
def get_modified_cpp_files(commit="HEAD"):
117-
cmd = f"git diff-tree --no-commit-id --name-status -r {commit}"
118-
status, stdout, stderr = run(cmd)
119-
if status != 0:
120-
print("Error running git diff-tree:", stderr, file=sys.stderr)
121-
return []
122-
123-
files = []
124-
for line in stdout.splitlines():
125-
parts = line.strip().split("\t")
126-
if len(parts) < 2:
127-
continue
128-
change_type, path = parts[0], parts[1]
129-
if change_type in ("A", "M") and path.endswith((".cpp", ".cc", ".h")):
130-
files.append(path)
131-
132-
return files
133-
134-
135116
def ensure_compile_db(build_dir):
136117
path = os.path.join(build_dir, "compile_commands.json")
137118
return os.path.exists(path)
138119

139120

140121
def tidy(args):
141-
clang_tidy_bin = args.clang_tidy or "clang-tidy"
142-
build_dir = args.build_dir or "cpp/build"
143-
project_root = args.project_root or "/app/dps-ssc-core-gluten/incubator-gluten"
144-
145-
files = get_modified_cpp_files()
146-
if not files:
147-
print("No modified .cc/.cpp/.h files in the latest commit. Nothing to do.")
148-
return 0
122+
build_dir = "cpp/build/"
123+
print(os.getcwd())
124+
print(os.listdir(build_dir))
125+
print(os.listdir("cpp/build/core"))
149126

150127
if not ensure_compile_db(build_dir):
151128
print("No compile_commands.json found in '{}'.".format(build_dir))
152129
return 1
153130

154131
fix = "--fix" if args.fix == "fix" else ""
155-
header_filter = "^(?!.*build).*".format(regex.escape(project_root))
132+
files = args.files
156133

157134
cmd = (
158-
"xargs {clang} -p={build}/releases --format-style=file --header-filter='{hf}' "
135+
"xargs clang-tidy -p={build} --format-style=file "
159136
"--checks='{checks}' {fix} --quiet".format(
160-
clang=clang_tidy_bin,
161137
build=build_dir,
162-
hf=header_filter,
163138
checks=CODE_CHECKS,
164139
fix=fix,
165140
)
@@ -199,19 +174,17 @@ def parse_args():
199174
parser = argparse.ArgumentParser(
200175
description="Run clang-tidy with project settings (compatible with older Python versions)"
201176
)
202-
parser.add_argument("--fix", help="Apply automatic fixes (use 'fix' to enable)")
203-
parser.add_argument("--clang-tidy", help="Path to clang-tidy binary")
204-
parser.add_argument(
205-
"--build-dir", help="Path to build directory with compile_commands.json"
206-
)
207-
parser.add_argument(
208-
"--project-root", help="Root path of the source project (for header-filter)"
209-
)
177+
parser.add_argument("--fix", action="store_const", default="show", const="fix")
178+
parser.add_argument("--commit", default="", help="Commit for check")
179+
parser.add_argument("files", metavar="FILES", nargs="*", help="files to process")
210180
return parser.parse_args()
211181

212182

213183
def main():
214-
return tidy(parse_args())
184+
args = parse_args()
185+
if not args.files:
186+
args.files = [line.strip() for line in sys.stdin if line.strip()]
187+
return tidy(args)
215188

216189

217190
if __name__ == "__main__":

0 commit comments

Comments
 (0)