Skip to content

Commit 6c8f370

Browse files
committed
ci: Improved clang-format CI task
Old: Do a build with target 'clang-format', relying on our build system. But that means that we need to do the cmake config step, and need a bunch of dependencies set up so that the config doesn't fail. New: Make a new run-clang-format.bash utility to issue the commands for the right files. No "build" is requred, and the only dependencies we need are the minimum it takes to run clang-format itself. Also, I noticed that we never had been clang-format testing the .cpp and .h files in the testsuite itself. So enable that now, and commit the small amount of reformatting that it identified. These changes reduce the approximate total elapsed time of a CI clang-format job from nearly 7:00 to 0:35. Signed-off-by: Larry Gritz <[email protected]>
1 parent aaa599b commit 6c8f370

13 files changed

+301
-201
lines changed

.github/workflows/build-steps.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ on:
5252
type: string
5353
build_docs:
5454
type: string
55+
clang_format:
56+
type: string
5557
generator:
5658
type: string
5759
ctest_args:
@@ -144,6 +146,10 @@ jobs:
144146
if: inputs.skip_tests != '1'
145147
shell: bash
146148
run: src/build-scripts/ci-test.bash
149+
- name: clang-format
150+
if: inputs.clang_format == '1'
151+
shell: bash
152+
run: src/build-scripts/run-clang-format.bash
147153
- name: Code coverage
148154
if: inputs.coverage == '1'
149155
run: src/build-scripts/ci-coverage.bash

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ jobs:
267267
skip_tests: ${{ matrix.skip_tests }}
268268
abi_check: ${{ matrix.abi_check }}
269269
build_docs: ${{ matrix.build_docs }}
270+
clang_format: ${{ matrix.clang_format }}
270271
generator: ${{ matrix.generator }}
271272
ctest_args: ${{ matrix.ctest_args }}
272273
ctest_test_timeout: ${{ matrix.ctest_test_timeout }}
@@ -367,24 +368,25 @@ jobs:
367368
setenvs: export OIIO_CMAKE_FLAGS="-DOIIO_BUILD_TOOLS=0 -DOIIO_BUILD_TESTS=0 -DUSE_PYTHON=0"
368369
USE_OPENCV=0 USE_FFMPEG=0 USE_PYTHON=0 USE_FREETYPE=0
369370

370-
# Test formatting. This test entry doesn't do a full build, it
371+
# Test formatting. This test entry doesn't build at all, it
371372
# just runs clang-format on everything, and passes if nothing is
372373
# misformatted. Upon failure, the build artifact will be the full
373374
# source code with the formatting fixed (diffs will also appear in
374375
# the console output).
375376
- desc: "clang-format"
376377
nametag: clang-format
377-
runner: ubuntu-latest
378+
runner: ubuntu-24.04
378379
cxx_std: 17
379380
extra_artifacts: "src/*.*"
380-
openexr_ver: v3.1.13
381381
python_ver: "3.10"
382+
pybind11_ver: "0"
383+
clang_format: 1
384+
skip_build: 1
382385
skip_tests: 1
383-
setenvs: export BUILDTARGET=clang-format
384-
OIIO_CMAKE_FLAGS=-DUSE_PYTHON=0
385-
LLVM_VERSION=17.0.6 LLVM_DISTRO_NAME=ubuntu-22.04
386-
SKIP_SYSTEM_DEPS_INSTALL=1 QT_VERSION=0
387-
OpenImageIO_OPTIONAL_DEPS=ALL
386+
setenvs: export SKIP_SYSTEM_DEPS_INSTALL=1 SKIP_APT_GET_UPDATE=1
387+
INSTALL_OPENCV=0 QT_VERSION=0 USE_LIBHEIF=0
388+
EXTRA_DEP_PACKAGES="clang-format-17"
389+
CLANG_FORMAT_EXE=clang-format-17
388390

389391
- desc: latest releases gcc13 C++20 py3.12 avx2 exr3.3 ocio2.4
390392
nametag: linux-latest-releases

src/build-scripts/gh-installdeps.bash

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ else
8686
time sudo apt-get update
8787
fi
8888

89-
time sudo apt-get -q install -y \
90-
git cmake ninja-build ccache g++ \
91-
libilmbase-dev libopenexr-dev \
92-
libtiff-dev libgif-dev libpng-dev
9389
if [[ "${SKIP_SYSTEM_DEPS_INSTALL}" != "1" ]] ; then
9490
time sudo apt-get -q install -y --fix-missing \
91+
git cmake ccache \
92+
ninja-build g++ libilmbase-dev libopenexr-dev \
93+
libtiff-dev libgif-dev libpng-dev \
9594
libraw-dev libwebp-dev \
9695
libavcodec-dev libavformat-dev libswscale-dev libavutil-dev \
9796
dcmtk libopenvdb-dev \
@@ -112,7 +111,9 @@ else
112111
time sudo apt-get -q install -y ${EXTRA_DEP_PACKAGES}
113112
fi
114113

115-
time sudo apt-get -q install -y python3-numpy
114+
if [[ "${USE_PYTHON}" != "0" ]] ; then
115+
time sudo apt-get -q install -y python3-numpy
116+
fi
116117
if [[ "${PIP_INSTALLS}" != "" ]] ; then
117118
time pip3 install ${PIP_INSTALLS}
118119
fi
@@ -158,7 +159,9 @@ fi
158159
# Packages we need to build from scratch.
159160
#
160161

161-
source src/build-scripts/build_pybind11.bash
162+
if [[ "$PYBIND11_VERSION" != "0" ]] ; then
163+
source src/build-scripts/build_pybind11.bash
164+
fi
162165

163166
if [[ "$OPENEXR_VERSION" != "" ]] ; then
164167
source src/build-scripts/build_openexr.bash
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
# Important: set -ex causes this whole script to terminate with error if
8+
# any command in it fails. This is crucial for CI tests.
9+
set -ex
10+
11+
CLANG_FORMAT_EXE=${CLANG_FORMAT_EXE:="clang-format"}
12+
echo "Running " `which clang-format` " version " `${CLANG_FORMAT_EXE} --version`
13+
14+
files=`find ./{src,testsuite} \( -name '*.h' -o -name '*.cpp' \) -print \
15+
| grep -Ev 'pugixml|SHA1|farmhash.cpp|libdpx|libcineon|bcdec.h|gif.h|stb_sprintf.h'`
16+
17+
18+
${CLANG_FORMAT_EXE} -i -style=file $files
19+
git diff --color
20+
THEDIFF=`git diff`
21+
if [[ "$THEDIFF" != "" ]] ; then
22+
echo "git diff was not empty. Failing clang-format check."
23+
exit 1
24+
fi

src/cmake/compiler.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ endif ()
568568
# is being built as a subproject.
569569
if (PROJECT_IS_TOP_LEVEL)
570570
set (CLANG_FORMAT_EXE_HINT "" CACHE PATH "clang-format executable's directory (will search if not specified")
571-
set (CLANG_FORMAT_INCLUDES "src/*.h" "src/*.cpp"
571+
set (CLANG_FORMAT_INCLUDES "src/*.h" "src/*.cpp testsuite/*.cpp testsuite/*.h"
572572
CACHE STRING "Glob patterns to include for clang-format")
573573
set (CLANG_FORMAT_EXCLUDES "*pugixml*" "*SHA1*" "*/farmhash.cpp"
574574
"src/dpx.imageio/libdpx/*"

testsuite/docs-examples-cpp/src/docs-examples-imagebuf.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#include <OpenImageIO/imageio.h>
1515
using namespace OIIO;
1616

17-
void example1()
17+
void
18+
example1()
1819
{
1920
//
2021
// Example code fragment from the docs goes here.
@@ -32,7 +33,8 @@ void example1()
3233

3334

3435

35-
int main(int /*argc*/, char** /*argv*/)
36+
int
37+
main(int /*argc*/, char** /*argv*/)
3638
{
3739
// Each example function needs to get called here, or it won't execute
3840
// as part of the test.

0 commit comments

Comments
 (0)