Skip to content

Commit 3dcc373

Browse files
committed
Add linter infrastructure for clang-format
Signed-off-by: Irwin D'Souza <dsouzai.gh@gmail.com>
1 parent bfdd4a8 commit 3dcc373

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright IBM Corp. and others 2025
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] https://openjdk.org/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
*******************************************************************************/
22+
23+
timestamps {
24+
timeout(time: 8, unit: 'HOURS') {
25+
stage('Queue') {
26+
node('sw.os.linux && hw.arch.x86 && sw.tool.docker') {
27+
def tmpDesc = currentBuild.description ? currentBuild.description + "<br>" : ""
28+
currentBuild.description = tmpDesc + "<a href=${JENKINS_URL}computer/${NODE_NAME}>${NODE_NAME}</a>"
29+
try {
30+
def gitConfig = scm.getUserRemoteConfigs().get(0)
31+
def refspec = gitConfig.getRefspec() ? gitConfig.getRefspec() : ""
32+
checkout changelog: false, poll: false,
33+
scm: [$class: 'GitSCM',
34+
branches: [[name: scm.branches[0].name]],
35+
userRemoteConfigs: [[
36+
refspec: "${refspec}",
37+
url: "${gitConfig.getUrl()}"]]
38+
]
39+
stage('Pull Infra') {
40+
sh "buildenv/jenkins/clang_format/pullInfra.sh"
41+
}
42+
stage('Docker Build') {
43+
dir('buildenv/jenkins/clang_format') {
44+
sh "docker build -t clang-format -f Dockerfile ."
45+
}
46+
}
47+
stage('Format Check') {
48+
sh "buildenv/jenkins/clang_format/clangFormatCheck.sh"
49+
}
50+
stage('Cleanup Infra') {
51+
sh "buildenv/jenkins/clang_format/cleanupInfra.sh"
52+
}
53+
} finally {
54+
cleanWs()
55+
}
56+
}
57+
}
58+
}
59+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash -f
2+
###############################################################################
3+
# Copyright IBM Corp. and others 2025
4+
#
5+
# This program and the accompanying materials are made available under
6+
# the terms of the Eclipse Public License 2.0 which accompanies this
7+
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8+
# or the Apache License, Version 2.0 which accompanies this distribution and
9+
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# This Source Code may also be made available under the following
12+
# Secondary Licenses when the conditions for such availability set
13+
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14+
# General Public License, version 2 with the GNU Classpath
15+
# Exception [1] and GNU General Public License, version 2 with the
16+
# OpenJDK Assembly Exception [2].
17+
#
18+
# [1] https://www.gnu.org/software/classpath/license.html
19+
# [2] https://openjdk.org/legal/assembly-exception.html
20+
#
21+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
22+
###############################################################################
23+
24+
allFiles=$(git diff -C --diff-filter=ACM --name-only origin/master HEAD --)
25+
if [ x"$allFiles" = x ] ; then
26+
echo "There are no files to check for code formatting."
27+
else
28+
lines='-----------------------------------'
29+
badFiles=
30+
for file in $allFiles ; do
31+
case "$file" in
32+
runtime/compiler/*.c | \
33+
runtime/compiler/*.cpp | \
34+
runtime/compiler/*.h | \
35+
runtime/compiler/*.hpp)
36+
echo "file:$file"
37+
good="$file.good"
38+
docker run --rm -v "$WORKSPACE:/src" clang-format:latest clang-format -style=file:runtime/compiler/.clang-format "/src/$file" > "$good"
39+
diffOutput=$(diff -u "$file" "$good")
40+
if [ "$diffOutput" != "" ] ; then
41+
echo "ERROR - not formatted as expected: '$file'"
42+
echo "$diffOutput"
43+
echo "$lines"
44+
badFiles="$badFiles $file"
45+
rm -f "$good"
46+
fi
47+
;;
48+
*)
49+
;;
50+
esac
51+
done
52+
53+
if [ x"$badFiles" = x ] ; then
54+
echo "All modified files appear to have correct code formatting."
55+
else
56+
hashes='###################################'
57+
echo "$hashes"
58+
echo "The following files were modified and have incorrect code formatting:"
59+
for file in $badFiles ; do
60+
echo "$file"
61+
done
62+
echo "$hashes"
63+
exit 1
64+
fi
65+
fi
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash -f
2+
###############################################################################
3+
# Copyright IBM Corp. and others 2025
4+
#
5+
# This program and the accompanying materials are made available under
6+
# the terms of the Eclipse Public License 2.0 which accompanies this
7+
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8+
# or the Apache License, Version 2.0 which accompanies this distribution and
9+
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# This Source Code may also be made available under the following
12+
# Secondary Licenses when the conditions for such availability set
13+
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14+
# General Public License, version 2 with the GNU Classpath
15+
# Exception [1] and GNU General Public License, version 2 with the
16+
# OpenJDK Assembly Exception [2].
17+
#
18+
# [1] https://www.gnu.org/software/classpath/license.html
19+
# [2] https://openjdk.org/legal/assembly-exception.html
20+
#
21+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
22+
###############################################################################
23+
24+
rm -f runtime/compiler/.clang-format
25+
rm -f buildenv/jenkins/clang_format/Dockerfile
26+
rm -f buildenv/jenkins/clang_format/clang-format-wrapper.sh
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash -f
2+
###############################################################################
3+
# Copyright IBM Corp. and others 2025
4+
#
5+
# This program and the accompanying materials are made available under
6+
# the terms of the Eclipse Public License 2.0 which accompanies this
7+
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8+
# or the Apache License, Version 2.0 which accompanies this distribution and
9+
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10+
#
11+
# This Source Code may also be made available under the following
12+
# Secondary Licenses when the conditions for such availability set
13+
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14+
# General Public License, version 2 with the GNU Classpath
15+
# Exception [1] and GNU General Public License, version 2 with the
16+
# OpenJDK Assembly Exception [2].
17+
#
18+
# [1] https://www.gnu.org/software/classpath/license.html
19+
# [2] https://openjdk.org/legal/assembly-exception.html
20+
#
21+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
22+
###############################################################################
23+
24+
wget https://raw.githubusercontent.com/eclipse-omr/omr/refs/heads/master/compiler/.clang-format -P runtime/compiler/
25+
wget https://raw.githubusercontent.com/eclipse-omr/omr/refs/heads/master/buildenv/jenkins/clang_format/Dockerfile -P buildenv/jenkins/clang_format/
26+
wget https://raw.githubusercontent.com/eclipse-omr/omr/refs/heads/master/buildenv/jenkins/clang_format/clang-format-wrapper.sh -P buildenv/jenkins/clang_format/

0 commit comments

Comments
 (0)