Skip to content

Commit 3244b9e

Browse files
authored
chore: add clang-format to venv (#1066)
* chore: make format * roll-back linter changes in CI * chore: add clang-format to venv * more references to clang-format
1 parent b598af0 commit 3244b9e

File tree

16 files changed

+29
-47
lines changed

16 files changed

+29
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4
20-
- run: |
21-
sudo apt update
22-
sudo apt install clang-format-15
23-
make style-15
20+
- run: make style
2421

2522
build-ios:
2623
name: Xcode Build for iOS

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Building and testing `sentry-native` currently requires the following tools:
1414
- **clang-format** and **black**, to format the C/C++ and python code respectively.
1515
- **curl** and **zlib** libraries (e.g. on Ubuntu: libcurl4-openssl-dev, libz-dev)
1616

17-
`pytest` and `black` are installed as virtualenv dependencies automatically.
17+
`pytest`, `clang-format` and `black` are installed as virtualenv dependencies automatically.
1818

1919
## Setting up Environment
2020

@@ -142,12 +142,12 @@ The example currently supports the following commands:
142142
- `disable-backend`: Disables the build-configured crash-handler backend.
143143
- `before-send`: Installs a `before_send()` callback that retains the event.
144144
- `discarding-before-send`: Installs a `before_send()` callback that discards the event.
145-
- `on-crash`: Installs an `on_crash()` callback that retains the crash event.
145+
- `on-crash`: Installs an `on_crash()` callback that retains the crash event.
146146
- `discarding-on-crash`: Installs an `on_crash()` callback that discards the crash event.
147147
- `override-sdk-name`: Changes the SDK name via the options at runtime.
148148
- `stack-overflow`: Provokes a stack-overflow.
149149

150-
Only on Windows using crashpad with its WER handler module:
150+
Only on Windows using crashpad with its WER handler module:
151151

152152
- `fastfail`: Crashes the application using the `__fastfail` intrinsic directly, thus by-passing SEH.
153153
- `stack-buffer-overrun`: Triggers the Windows Control Flow Guard, which also fast fails and in turn by-passes SEH.

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ setup-venv: .venv/bin/python
6666
.venv/bin/pip install --upgrade --requirement tests/requirements.txt
6767

6868
format: setup-venv
69-
@clang-format -i \
69+
@.venv/bin/clang-format -i \
7070
examples/*.c \
7171
include/*.h \
7272
src/*.c \
@@ -80,12 +80,8 @@ format: setup-venv
8080
.PHONY: format
8181

8282
style: setup-venv
83-
@.venv/bin/python ./scripts/check-clang-format.py -r examples include src tests/unit
83+
@.venv/bin/python ./scripts/check-clang-format.py \
84+
--clang-format-executable .venv/bin/clang-format \
85+
-r examples include src tests/unit
8486
@.venv/bin/black --diff --check tests
8587
.PHONY: style
86-
87-
# TODO: workaround for clang-format 15+ where local formatting breaks with clang-format-14 based style checks on CI
88-
style-15: setup-venv
89-
@.venv/bin/python ./scripts/check-clang-format.py --clang-format-executable /usr/bin/clang-format-15 -r examples include src tests/unit
90-
@.venv/bin/black --diff --check tests
91-
.PHONY: style-15

examples/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifdef SENTRY_PLATFORM_WINDOWS
2020
# include <malloc.h>
2121
# include <synchapi.h>
22-
# define sleep_s(SECONDS) Sleep((SECONDS)*1000)
22+
# define sleep_s(SECONDS) Sleep((SECONDS) * 1000)
2323
#else
2424

2525
# include <signal.h>

scripts/git-precommit-hook.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
CFILES=`git diff-index --cached --name-only HEAD | grep -E "^(examples|include|src|tests/unit).*\.(c|h|cpp)$"`
4-
PYFILES=`git diff-index --cached --name-only HEAD | grep -E "^tests.*\.py$"`
3+
CFILES=$(git diff-index --cached --name-only HEAD | grep -E "^(examples|include|src|tests/unit).*\.(c|h|cpp)$")
4+
PYFILES=$(git diff-index --cached --name-only HEAD | grep -E "^tests.*\.py$")
55

66
if [ -n "$CFILES" ]; then
7-
clang-format -i $CFILES
7+
.venv/bin/clang-format -i $CFILES
88
fi
99
if [ -n "$PYFILES" ]; then
1010
.venv/bin/black $PYFILES

src/backends/sentry_backend_crashpad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ crashpad_backend_startup(
406406

407407
// register attachments
408408
for (sentry_attachment_t *attachment = options->attachments; attachment;
409-
attachment = attachment->next) {
409+
attachment = attachment->next) {
410410
attachments.emplace_back(attachment->path->path);
411411
}
412412

src/backends/sentry_backend_inproc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
* Both breakpad and crashpad are way more defensive in the setup of their
3838
* signal stacks and take existing stacks into account (or reuse them).
3939
*/
40-
#define SIGNAL_DEF(Sig, Desc) \
41-
{ \
42-
Sig, #Sig, Desc \
43-
}
40+
#define SIGNAL_DEF(Sig, Desc) { Sig, #Sig, Desc }
4441

4542
#define MAX_FRAMES 128
4643

src/modulefinder/sentry_modulefinder_apple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ add_image(const struct mach_header *mh, intptr_t UNUSED(vmaddr_slide))
5555
bool has_uuid = false;
5656

5757
for (size_t i = 0; cmd && (i < header->ncmds) && (!has_uuid || !has_size);
58-
++i,
58+
++i,
5959
cmd
60-
= (const struct load_command *)((const char *)cmd + cmd->cmdsize)) {
60+
= (const struct load_command *)((const char *)cmd + cmd->cmdsize)) {
6161
if (cmd->cmd == CMD_SEGMENT) {
6262
const mach_segment_command_type *seg
6363
= (const mach_segment_command_type *)cmd;

src/path/sentry_path_windows.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
static const size_t MAX_READ_TO_BUFFER = 134217728;
1919

2020
#ifndef __MINGW32__
21-
# define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
22-
# define S_ISDIR(m) (((m)&_S_IFMT) == _S_IFDIR)
21+
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
22+
# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
2323
#endif
2424

2525
struct sentry_pathiter_s {

src/sentry_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
501501

502502
SENTRY_TRACE("adding attachments to envelope");
503503
for (sentry_attachment_t *attachment = options->attachments; attachment;
504-
attachment = attachment->next) {
504+
attachment = attachment->next) {
505505
sentry_envelope_item_t *item = sentry__envelope_add_from_path(
506506
envelope, attachment->path, "attachment");
507507
if (!item) {

0 commit comments

Comments
 (0)