Skip to content

Commit 433d4a9

Browse files
committed
ci: improve clang-format check (#1950)
ci: improve clang-format 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. These changes reduce the approximate total elapsed time of a CI clang-format job from 8:00+ to under 0:30. Signed-off-by: Larry Gritz <[email protected]>
1 parent 98113a0 commit 433d4a9

File tree

7 files changed

+78
-65
lines changed

7 files changed

+78
-65
lines changed

.github/workflows/build-steps.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ on:
5858
type: string
5959
build_docs:
6060
type: string
61+
clang_format:
62+
type: string
6163
generator:
6264
type: string
6365
ctest_args:
@@ -162,6 +164,10 @@ jobs:
162164
if: inputs.skip_tests != '1'
163165
shell: bash
164166
run: src/build-scripts/ci-test.bash
167+
- name: clang-format
168+
if: inputs.clang_format == '1'
169+
shell: bash
170+
run: src/build-scripts/run-clang-format.bash
165171
- name: Code coverage
166172
if: inputs.coverage == '1'
167173
run: src/build-scripts/ci-coverage.bash

.github/workflows/ci.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ jobs:
235235
coverage: ${{ matrix.coverage || 0 }}
236236
sonar: ${{ matrix.sonar || 0 }}
237237
llvm_action_ver: ${{ matrix.llvm_action_ver }}
238+
clang_format: ${{ matrix.clang_format }}
238239
strategy:
239240
fail-fast: false
240241
matrix:
@@ -467,22 +468,20 @@ jobs:
467468
# the console output).
468469
- desc: "clang-format"
469470
nametag: clang-format
470-
runner: ubuntu-latest
471+
runner: ubuntu-24.04
471472
cxx_std: 17
472473
extra_artifacts: "src/*.*"
473-
opencolorio_ver: v2.4.0
474-
openexr_ver: v3.1.11
475-
openimageio_ver: release
476474
python_ver: "3.10"
477-
simd: avx2,f16c
478-
batched: b8_AVX2
475+
pybind11_ver: "0"
476+
skip_build: 1
479477
skip_tests: 1
480-
setenvs: export BUILDTARGET=clang-format
481-
LLVM_VERSION=17.0.6
482-
LLVM_DISTRO_NAME=ubuntu-22.04
483-
OPENIMAGEIO_CMAKE_FLAGS=-DUSE_PYTHON=0
484-
USE_PYTHON=0
485-
QT_VERSION=0
478+
clang_format: 1
479+
setenvs: export OPENIMAGEIO_CMAKE_FLAGS=-DUSE_PYTHON=0
480+
USE_PYTHON=0 QT_VERSION=0 PUGIXML_VERSION=0
481+
SKIP_APT_GET_UPDATE=0
482+
SKIP_SYSTEM_DEPS_INSTALL=1
483+
EXTRA_DEP_PACKAGES="clang-format-17"
484+
CLANG_FORMAT_EXE=clang-format-17
486485

487486

488487
macos:

src/build-scripts/gh-installdeps.bash

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ else
8484
time sudo apt-get update
8585
fi
8686

87-
time sudo apt-get -q install -y \
88-
git cmake ninja-build ccache g++ \
89-
libboost-dev libboost-thread-dev libboost-filesystem-dev \
90-
libtiff-dev libgif-dev libpng-dev \
91-
flex bison libbison-dev \
92-
libpugixml-dev \
93-
libopencolorio-dev
87+
if [[ "${SKIP_SYSTEM_DEPS_INSTALL}" != "1" ]] ; then
88+
time sudo apt-get -q install -y \
89+
git cmake ccache ninja-build g++ \
90+
libboost-dev libboost-thread-dev libboost-filesystem-dev \
91+
libtiff-dev libgif-dev libpng-dev \
92+
flex bison libbison-dev \
93+
libpugixml-dev \
94+
libopencolorio-dev
95+
fi
9496

9597
if [[ "${QT_VERSION:-5}" == "5" ]] ; then
9698
time sudo apt-get -q install -y qt5-default || /bin/true
@@ -101,7 +103,9 @@ else
101103
time sudo apt-get -q install -y ${EXTRA_DEP_PACKAGES}
102104
fi
103105

104-
time sudo apt-get -q install -y python3-numpy
106+
if [[ "${USE_PYTHON}" != "0" ]] ; then
107+
time sudo apt-get -q install -y python3-numpy
108+
fi
105109
if [[ "${PIP_INSTALLS}" != "" ]] ; then
106110
time pip3 install ${PIP_INSTALLS}
107111
fi
@@ -167,16 +171,18 @@ fi
167171
# Packages we need to build from scratch.
168172
#
169173

170-
source src/build-scripts/build_pybind11.bash
174+
if [[ "$PYBIND11_VERSION" != "0" ]] ; then
175+
source src/build-scripts/build_pybind11.bash
176+
fi
171177

172178
if [[ "$OPENEXR_VERSION" != "" ]] ; then
173179
source src/build-scripts/build_openexr.bash
174180
fi
175181

176-
# if [[ "$PUGIXML_VERSION" != "" ]] ; then
182+
if [[ "$PUGIXML_VERSION" != "0" ]] ; then
177183
source src/build-scripts/build_pugixml.bash
178184
export MY_CMAKE_FLAGS+=" -DUSE_EXTERNAL_PUGIXML=1 "
179-
# fi
185+
fi
180186

181187
if [[ "$OPENCOLORIO_VERSION" != "" ]] ; then
182188
source src/build-scripts/build_opencolorio.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 Open Shading Language project.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
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' -o -name '*.cu' \) -print \
15+
| grep -Ev 'testsuite/.*\.h|src/shaders'`
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

testsuite/example-batched-deformer/oslbatcheddeformer.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ class MyBatchedRendererServices final
128128
{
129129
return false;
130130
}
131-
bool is_overridden_get_matrix_WmWsWf() const override
132-
{
133-
return false;
134-
}
131+
bool is_overridden_get_matrix_WmWsWf() const override { return false; }
135132
bool is_overridden_get_inverse_matrix_WmsWf() const override
136133
{
137134
return false;
@@ -140,30 +137,12 @@ class MyBatchedRendererServices final
140137
{
141138
return false;
142139
}
143-
bool is_overridden_texture() const override
144-
{
145-
return false;
146-
}
147-
bool is_overridden_texture3d() const override
148-
{
149-
return false;
150-
}
151-
bool is_overridden_environment() const override
152-
{
153-
return false;
154-
}
155-
bool is_overridden_pointcloud_search() const override
156-
{
157-
return false;
158-
}
159-
bool is_overridden_pointcloud_get() const override
160-
{
161-
return false;
162-
}
163-
bool is_overridden_pointcloud_write() const override
164-
{
165-
return false;
166-
}
140+
bool is_overridden_texture() const override { return false; }
141+
bool is_overridden_texture3d() const override { return false; }
142+
bool is_overridden_environment() const override { return false; }
143+
bool is_overridden_pointcloud_search() const override { return false; }
144+
bool is_overridden_pointcloud_get() const override { return false; }
145+
bool is_overridden_pointcloud_write() const override { return false; }
167146
};
168147

169148
// RendererServices is the interface through which OSL requests things back
@@ -243,8 +222,9 @@ main(int argc, char* argv[])
243222
std::cout
244223
<< "Error: Hardware doesn't support 4, 8 or 16 wide SIMD or the OSL has not been configured and built with a proper USE_BATCHED."
245224
<< std::endl;
246-
std::cout << "Error: e.g.: USE_BATCHED=b4_SSE2,b8_AVX2,b8_AVX512,b16_AVX512"
247-
<< std::endl;
225+
std::cout
226+
<< "Error: e.g.: USE_BATCHED=b4_SSE2,b8_AVX2,b8_AVX512,b16_AVX512"
227+
<< std::endl;
248228
return -1;
249229
}
250230

@@ -439,8 +419,7 @@ main(int argc, char* argv[])
439419

440420
if (batch_width == 16) {
441421
batched_shadepoints(std::integral_constant<int, 16> {});
442-
}
443-
else if (batch_width == 8) {
422+
} else if (batch_width == 8) {
444423
batched_shadepoints(std::integral_constant<int, 8> {});
445424
} else {
446425
batched_shadepoints(std::integral_constant<int, 4> {});

testsuite/example-cuda/rend_lib.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ osl_bind_interpolated_param(void* sg_, OSL::ustring_pod name, long long type,
230230
char status = *userdata_initialized;
231231
if (status == 0) {
232232
bool ok = rend_get_userdata(HDSTR(name), userdata_data,
233-
symbol_data_size, (*(OSL::TypeDesc*)&type),
234-
userdata_index);
233+
symbol_data_size, (*(OSL::TypeDesc*)&type),
234+
userdata_index);
235235
*userdata_initialized = status = 1 + ok;
236236
}
237237
if (status == 2) {

testsuite/example-deformer/osldeformer.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MyRendererServices final : public OSL::RendererServices {
118118
//Not recommended for production renderer but fine for osldeformer
119119
std::atomic<uint32_t> next_thread_index { 0 };
120120
constexpr uint32_t uninitialized_thread_index = -1;
121-
thread_local uint32_t this_threads_index = uninitialized_thread_index;
121+
thread_local uint32_t this_threads_index = uninitialized_thread_index;
122122

123123

124124
int
@@ -290,14 +290,13 @@ main(int argc, char* argv[])
290290
// Run the shader (will automagically optimize and JIT the first
291291
// time it executes).
292292

293-
if(this_threads_index == uninitialized_thread_index) {
294-
295-
this_threads_index = next_thread_index.fetch_add(1u);
296-
}
297-
int thread_index = this_threads_index;
293+
if (this_threads_index == uninitialized_thread_index) {
294+
this_threads_index = next_thread_index.fetch_add(1u);
295+
}
296+
int thread_index = this_threads_index;
298297

299-
shadsys->execute(*ctx, *mygroup.get(), thread_index, /*shade point index= */ i,
300-
shaderglobals,
298+
shadsys->execute(*ctx, *mygroup.get(), thread_index,
299+
/*shade point index= */ i, shaderglobals,
301300
/*userdata arena start=*/&userdata,
302301
/*output arena start=*/&Pout);
303302

0 commit comments

Comments
 (0)