@@ -78,21 +78,38 @@ jobs:
7878 with :
7979 python-version : ' 3.14'
8080
81- - name : Resolve clang-format requirement
81+ - name : Resolve C/C++ lint requirements
8282 shell : bash
8383 run : |
84- requirement="clang-format"
84+ clang_format_requirement="clang-format"
85+ cmakelang_requirement="cmakelang"
86+ requirements_project=""
8587 submodule="third-party/lizardbyte-common"
86-
87- if git config -f .gitmodules --get-regexp path 2>/dev/null | grep -Fq " ${submodule}"; then
88+ submodule_configured=false
89+
90+ if python -c \
91+ 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["name"])' \
92+ 2>/dev/null | grep -Fxq "lizardbyte-common"; then
93+ requirements_project="."
94+ elif git config -f .gitmodules --get-regexp path 2>/dev/null | grep -Fq " ${submodule}"; then
95+ submodule_configured=true
8896 if git submodule update --init --depth 1 -- "${submodule}"; then
89- pinned_requirement=$(SUBMODULE="${submodule}" python - <<'PY'
97+ requirements_project="${submodule}"
98+ else
99+ echo "::warning::Unable to check out ${submodule}; using the latest C/C++ lint tool versions."
100+ fi
101+ else
102+ echo "${submodule} is not configured; using the latest C/C++ lint tool versions."
103+ fi
104+
105+ if [ -n "${requirements_project}" ]; then
106+ pinned_requirements=$(PROJECT="${requirements_project}" python - <<'PY'
90107 import os
91108 import re
92109 import tomllib
93110 from pathlib import Path
94111
95- pyproject = Path(os.environ["SUBMODULE "]) / "pyproject.toml"
112+ pyproject = Path(os.environ["PROJECT "]) / "pyproject.toml"
96113 try:
97114 config = tomllib.loads(pyproject.read_text(encoding="utf-8"))
98115 except (OSError, tomllib.TOMLDecodeError):
@@ -101,32 +118,46 @@ jobs:
101118 dependencies = config.get("dependency-groups", {}).get("lint-c", [])
102119 if not dependencies:
103120 dependencies = config.get("project", {}).get("optional-dependencies", {}).get("lint-c", [])
104- for dependency in dependencies:
105- if not isinstance(dependency, str):
106- continue
107- if re.fullmatch(r"clang-format==[0-9]+(?:\.[0-9]+)*(?:\.\*)?", dependency):
108- print(dependency)
109- break
110- PY
121+
122+ pins = []
123+ for package in ("clang-format", "cmakelang"):
124+ pattern = rf"{re.escape(package)}==[0-9]+(?:\.[0-9]+)*(?:\.\*)?"
125+ pin = next(
126+ (
127+ dependency
128+ for dependency in dependencies
129+ if isinstance(dependency, str) and re.fullmatch(pattern, dependency)
130+ ),
131+ "",
111132 )
133+ pins.append(pin)
112134
113- if [ -n "${pinned_requirement}" ]; then
114- requirement="${pinned_requirement}"
115- else
116- echo "::warning::Unable to find the clang-format pin in ${submodule}; using the latest version."
117- fi
135+ print("|".join(pins))
136+ PY
137+ )
138+ IFS="|" read -r pinned_clang_format pinned_cmakelang <<< "${pinned_requirements}"
139+
140+ if [ -n "${pinned_clang_format}" ]; then
141+ clang_format_requirement="${pinned_clang_format}"
142+ else
143+ echo "::warning::No clang-format pin found in ${requirements_project}; using the latest version."
144+ fi
145+
146+ if [ -n "${pinned_cmakelang}" ]; then
147+ cmakelang_requirement="${pinned_cmakelang}"
118148 else
119- echo "::warning::Unable to check out ${submodule }; using the latest clang-format version."
149+ echo "::warning::No cmakelang pin found in ${requirements_project }; using the latest version."
120150 fi
151+ fi
121152
153+ if [ "${submodule_configured}" = true ]; then
122154 # Keep the targeted submodule checkout out of every lint file search below.
123155 git submodule deinit --force -- "${submodule}" || true
124- else
125- echo "${submodule} is not configured; using the latest clang-format version."
126156 fi
127157
128- echo "Installing ${requirement}"
129- echo "CLANG_FORMAT_REQUIREMENT=${requirement}" >> "${GITHUB_ENV}"
158+ echo "Installing ${clang_format_requirement} and ${cmakelang_requirement}"
159+ echo "CLANG_FORMAT_REQUIREMENT=${clang_format_requirement}" >> "${GITHUB_ENV}"
160+ echo "CMAKELANG_REQUIREMENT=${cmakelang_requirement}" >> "${GITHUB_ENV}"
130161
131162 - name : Install Python dependencies
132163 shell : bash
@@ -137,7 +168,7 @@ jobs:
137168 pip \
138169 setuptools \
139170 wheel \
140- cmakelang \
171+ "${CMAKELANG_REQUIREMENT}" \
141172 flake8 \
142173 flake8-github-annotations \
143174 nb-clean \
@@ -198,7 +229,7 @@ jobs:
198229 with :
199230 ignore_patterns : ${{ inputs.check_trailing_space_ignore_pattern }}
200231
201- - name : C++ - find files
232+ - name : C/C ++ - find files
202233 id : cpp_files
203234 if : always()
204235 shell : bash
@@ -214,7 +245,7 @@ jobs:
214245 )
215246 ignore_files=$(find . -type f -iname ".clang-format-ignore")
216247
217- # Loop through each C++ file
248+ # Loop through each C/C ++ file
218249 for file in $found_files; do
219250 for ignore_file in $ignore_files; do
220251 ignore_directory=$(dirname "$ignore_file")
@@ -235,13 +266,13 @@ jobs:
235266 # shellcheck disable=SC2086 # do not quote to keep this as a single line
236267 echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
237268
238- - name : C++ - Update Clang format config
269+ - name : C/C ++ - Update Clang format config
239270 if : always() && steps.cpp_files.outputs.found_files
240271 shell : bash
241272 run : |
242273 echo "LineEnding: LF" >> .clang-format
243274
244- - name : C++ - Clang format (diff)
275+ - name : C/C ++ - Clang format (diff)
245276 id : clang_format_diff
246277 if : always() && steps.cpp_files.outputs.found_files
247278 shell : bash
@@ -269,7 +300,7 @@ jobs:
269300 set -e
270301 exit "${error}"
271302
272- - name : C++ - Clang format (annotations)
303+ - name : C/C ++ - Clang format (annotations)
273304 if : always() && steps.clang_format_diff.outcome == 'failure'
274305 shell : bash
275306 run : |
@@ -295,7 +326,7 @@ jobs:
295326 found_files=$(find . -type f -iname "CMakeLists.txt" -o -iname "*.cmake")
296327 ignore_files=$(find . -type f -iname ".cmake-lint-ignore")
297328
298- # Loop through each C++ file
329+ # Loop through each CMake file
299330 for file in $found_files; do
300331 for ignore_file in $ignore_files; do
301332 ignore_directory=$(dirname "$ignore_file")
0 commit comments