forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58d6fe5
commit 49a220b
Showing
4 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
dirty=$(git ls-files --modified) | ||
|
||
set +x | ||
if [[ $dirty ]]; then | ||
echo "=================================" | ||
echo "Files were not formatted properly" | ||
echo "$dirty" | ||
echo "=================================" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
|
||
if [ ${#} -eq 1 -a "${1}" = "VERBOSE" ]; then | ||
VERBOSITY="-l debug" | ||
else | ||
VERBOSITY="" | ||
fi | ||
|
||
if [ "${CI}" ]; then | ||
MODE="--check" | ||
else | ||
MODE="-i" | ||
fi | ||
|
||
# Runs the formatter in parallel on the code base. | ||
# Return codes: | ||
# - 1 there are files to be formatted | ||
# - 0 everything looks fine | ||
|
||
# Get CPU count | ||
OS=$(uname) | ||
NPROC=1 | ||
if [[ ${OS} = "Linux" ]] ; then | ||
NPROC=$(nproc) | ||
elif [[ ${OS} = "Darwin" ]] ; then | ||
NPROC=$(sysctl -n hw.physicalcpu) | ||
fi | ||
|
||
# Discover clang-format | ||
if ! type cmake-format 2> /dev/null ; then | ||
echo "Required cmake-format not found" | ||
exit 1 | ||
fi | ||
|
||
find . -type d \( \ | ||
-path ./.deps -o \ | ||
-path ./\*build\* -o \ | ||
-path ./deps/jansson -o \ | ||
-path ./plugins/decklink/\*/decklink-sdk -o \ | ||
-path ./plugins/enc-amf -o \ | ||
-path ./plugins/mac-syphon/syphon-framework -o \ | ||
-path ./plugins/obs-outputs/ftl-sdk -o \ | ||
-path ./plugins/sl-vst -o \ | ||
-path ./plugins/obs-browser -o \ | ||
-path ./plugins/win-dshow/libdshowcapture -o \ | ||
-path ./plugins/obs-websocket/deps \ | ||
\) -prune -false -type f -o \ | ||
-name 'CMakeLists.txt' -or \ | ||
-name '*.cmake' \ | ||
| xargs -L10 -P ${NPROC} cmake-format ${MODE} ${VERBOSITY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
# Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
set -o xtrace | ||
|
||
if [ ${#} -eq 1 ]; then | ||
VERBOSITY="--verbose" | ||
else | ||
VERBOSITY="" | ||
fi | ||
|
||
# Runs the Clang Formatter in parallel on the code base. | ||
# Return codes: | ||
# - 1 there are files to be formatted | ||
# - 0 everything looks fine | ||
|
||
# Get CPU count | ||
OS=$(uname) | ||
NPROC=1 | ||
if [[ ${OS} = "Linux" ]] ; then | ||
NPROC=$(nproc) | ||
elif [[ ${OS} = "Darwin" ]] ; then | ||
NPROC=$(sysctl -n hw.physicalcpu) | ||
fi | ||
|
||
# Discover clang-format | ||
if type clang-format-17 2> /dev/null ; then | ||
CLANG_FORMAT=clang-format-17 | ||
elif type clang-format 2> /dev/null ; then | ||
# Clang format found, but need to check version | ||
CLANG_FORMAT=clang-format | ||
V=$(clang-format --version) | ||
if [[ $V != *"version 13.0"* ]]; then | ||
echo "clang-format is not 13.0 (returned ${V})" | ||
exit 1 | ||
fi | ||
else | ||
echo "No appropriate clang-format found (expected clang-format-17.0.0, or clang-format)" | ||
exit 1 | ||
fi | ||
|
||
find . -type d \( \ | ||
-path ./.deps -o \ | ||
-path ./\*build\* -o \ | ||
-path ./cmake -o \ | ||
-path ./plugins/decklink/\*/decklink-sdk -o \ | ||
-path ./plugins/enc-amf -o \ | ||
-path ./plugins/mediasoup-connector -o \ | ||
-path ./plugins/sl-vst -o \ | ||
-path ./plugins/mac-syphon/syphon-framework -o \ | ||
-path ./plugins/obs-outputs/ftl-sdk -o \ | ||
-path ./plugins/obs-websocket/deps -o \ | ||
-path ./plugins/win-spout/deps \ | ||
\) -prune -false -type f -o \ | ||
-name '*.h' -or \ | ||
-name '*.hpp' -or \ | ||
-name '*.m' -or \ | ||
-name '*.mm' -or \ | ||
-name '*.c' -or \ | ||
-name '*.cpp' \ | ||
| xargs -L100 -P ${NPROC} "${CLANG_FORMAT}" ${VERBOSITY} -i -style=file -fallback-style=none | ||
|
||
git diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Clang Format Check | ||
|
||
on: | ||
push: | ||
paths-ignore: ['**.md'] | ||
branches-ignore: [streamlabs] | ||
pull_request: | ||
paths-ignore: ['**.md'] | ||
branches-ignore: [streamlabs] | ||
|
||
jobs: | ||
clang-format-check: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'recursive' | ||
|
||
- name: Install clang format 17 | ||
shell: bash | ||
run: | | ||
echo ::group::Install Dependencies | ||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | ||
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH | ||
echo "/home/linuxbrew/.linuxbrew/opt/clang-format@17/bin" >> $GITHUB_PATH | ||
brew install --quiet zsh | ||
echo ::endgroup:: | ||
- name: 'Run clang-format' | ||
run: | | ||
./.github/scripts/check-format.sh | ||
./.github/scripts/check-changes.sh |