Skip to content

Commit bf1ef53

Browse files
committed
Migrate to new consistent to-all-my-C-projects precommit hooks (with MSVC on wine testing and more)
1 parent 26cff11 commit bf1ef53

10 files changed

Lines changed: 127 additions & 55 deletions

.pre-commit-config.yaml

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,82 @@
11
repos:
2-
- repo: local
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
34
hooks:
4-
- id: clang-format
5-
name: clang-format
6-
entry: clang-format -i --style=LLVM
7-
language: system
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: mixed-line-ending
8+
- repo: https://github.com/pre-commit/mirrors-clang-format
9+
rev: v18.1.8
10+
hooks:
11+
- id: clang-format
12+
args: ['-style=LLVM']
813
types_or: [c, c++]
9-
require_serial: true
10-
- id: cppcheck
11-
name: cppcheck
12-
entry: cppcheck --error-exitcode=1 --force
13-
language: system
14+
- repo: local
15+
hooks:
16+
- id: cppcheck
17+
name: Cppcheck
18+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" cppcheck
19+
language: python
20+
pass_filenames: false
1421
types_or: [c, c++]
15-
- id: custom-checks
16-
name: Build, Test, Valgrind, Coverage, Shields
17-
entry: ./scripts/run_custom_checks.sh
18-
language: system
22+
- id: build-gcc
23+
name: Build (GCC)
24+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" build gcc
25+
language: python
26+
pass_filenames: false
27+
- id: test-gcc
28+
name: Test (GCC)
29+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" test gcc
30+
language: python
31+
pass_filenames: false
32+
- id: build-clang
33+
name: Build (Clang)
34+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" build clang
35+
language: python
36+
pass_filenames: false
37+
- id: test-clang
38+
name: Test (Clang)
39+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" test clang
40+
language: python
41+
pass_filenames: false
42+
- id: build-msvc-wine
43+
name: Build (MSVC Wine)
44+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" build msvc_wine
45+
language: python
46+
pass_filenames: false
47+
- id: test-msvc-wine
48+
name: Test (MSVC Wine)
49+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" test msvc_wine
50+
language: python
51+
pass_filenames: false
52+
- id: build-msvc
53+
name: Build (MSVC)
54+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" build msvc
55+
language: python
56+
pass_filenames: false
57+
- id: test-msvc
58+
name: Test (MSVC)
59+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" test msvc
60+
language: python
61+
pass_filenames: false
62+
- id: build-mingw
63+
name: Build (MinGW)
64+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" build mingw
65+
language: python
66+
pass_filenames: false
67+
- id: test-mingw
68+
name: Test (MinGW)
69+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" test mingw
70+
language: python
71+
pass_filenames: false
72+
- id: valgrind
73+
name: Valgrind (GCC)
74+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" valgrind gcc
75+
language: python
76+
pass_filenames: false
77+
- id: update-shields
78+
name: Update README Shields
79+
entry: python3 -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/SamuelMarks/c-ci/master/precommit_matrix.py').read())" shields
80+
language: python
81+
additional_dependencies: [gcovr]
1982
pass_filenames: false

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,3 @@ write_basic_package_version_file(
143143
)
144144
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
145145
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
146-

c89stringutils/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ if (C89STRINGUTILS_BUILD_AMALGAMATION)
9494
install(FILES "${amalg_file}"
9595
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
9696
endif()
97-

c89stringutils/c89stringutils_string_extras.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,27 @@ C89STRINGUTILS_EXPORT int c89stringutils_jasprintf(char **unto, const char *fmt,
520520
#endif
521521

522522
#if !defined(HAVE_ASPRINTF)
523+
/**
524+
* @brief Write formatted output to a dynamically allocated string using a
525+
* va_list.
526+
* @param str A pointer to a string pointer where the allocated string will be
527+
* stored.
528+
* @param fmt The format string.
529+
* @param ap The va_list of arguments.
530+
* @return The number of characters printed, or -1 on error.
531+
*/
523532
C89STRINGUTILS_EXPORT int vasprintf(char **str, const char *fmt, va_list ap) {
524533
return c89stringutils_vasprintf(str, fmt, ap);
525534
}
526535

536+
/**
537+
* @brief Write formatted output to a dynamically allocated string.
538+
* @param str A pointer to a string pointer where the allocated string will be
539+
* stored.
540+
* @param fmt The format string.
541+
* @param ... The arguments.
542+
* @return The number of characters printed, or -1 on error.
543+
*/
527544
C89STRINGUTILS_EXPORT int asprintf(char **str, const char *fmt, ...) {
528545
int rc;
529546
va_list args;
@@ -534,6 +551,14 @@ C89STRINGUTILS_EXPORT int asprintf(char **str, const char *fmt, ...) {
534551
}
535552
#endif
536553

554+
/**
555+
* @brief `jasprintf`, a version of `asprintf` that concatenates on successive
556+
* calls.
557+
* @param unto The string to append to.
558+
* @param fmt The format string.
559+
* @param ... The arguments.
560+
* @return The number of characters printed, or -1 on error.
561+
*/
537562
C89STRINGUTILS_EXPORT int jasprintf(char **unto, const char *fmt, ...) {
538563
int rc;
539564
va_list args;

c89stringutils/c89stringutils_string_extras.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ extern "C" {
1818
#include <string.h>
1919
#include <errno.h>
2020

21+
#if !(defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WATCOMC__))
22+
#include <sys/param.h>
23+
#endif
24+
#ifndef _MSC_VER
25+
#include <strings.h>
26+
#endif
27+
/* clang-format on */
28+
2129
#if defined(_MSC_VER)
2230
#define NUM_FORMAT "%I64d"
2331
#else
@@ -59,8 +67,6 @@ extern "C" {
5967

6068
#else
6169

62-
#include <sys/param.h>
63-
6470
#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || \
6571
_POSIX_C_SOURCE >= 200112L
6672
#define HAVE_SNPRINTF_H
@@ -90,9 +96,12 @@ extern "C" {
9096

9197
#else
9298

93-
#if !defined(__APPLE__) && !defined(__APPLE_CC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
99+
#if !defined(__APPLE__) && !defined(__APPLE_CC__) && !defined(_MSC_VER) && \
100+
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
94101
typedef int errno_t;
95-
#endif /* !defined(__APPLE__) && !defined(__APPLE_CC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) */
102+
#endif /* !defined(__APPLE__) && !defined(__APPLE_CC__) && !defined(_MSC_VER) \
103+
&& !defined(__MINGW32__) && !defined(__CYGWIN__) && \
104+
!defined(__WATCOMC__) */
96105

97106
#if defined(__linux__) || defined(linux) || defined(__linux) || defined(ANY_BSD)
98107
#define strerror_s strerror_r
@@ -115,11 +124,6 @@ typedef int errno_t;
115124
defined(__APPLE__) && defined(__MACH__) || \
116125
defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) */
117126

118-
#ifdef HAVE_STRINGS_H
119-
#include <strings.h>
120-
#endif /* HAVE_STRINGS_H */
121-
/* clang-format on */
122-
123127
/**
124128
* @brief Compare at most n characters of two strings, ignoring case.
125129
* @param s1 The first string to compare.

c89stringutils/tests/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
/* clang-format off */
66
#if defined(_MSC_VER)
7+
#ifndef _CRT_SECURE_NO_WARNINGS
78
#define _CRT_SECURE_NO_WARNINGS
89
#endif
10+
#endif
911
#include <greatest.h>
1012
#include <c89stringutils_log.h>
1113
#include <stdlib.h>

reports/test_coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

scripts/run_custom_checks.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/update_shields.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ def get_doc_coverage():
3535
def update_readme():
3636
test_cov = get_test_coverage()
3737
doc_cov = get_doc_coverage()
38-
38+
3939
test_cov_enc = urllib.parse.quote(test_cov)
4040
doc_cov_enc = urllib.parse.quote(doc_cov)
41-
41+
4242
test_shield = f"![Test Coverage](https://img.shields.io/badge/test__coverage-{test_cov_enc}-brightgreen)"
4343
doc_shield = f"![Doc Coverage](https://img.shields.io/badge/doc__coverage-{doc_cov_enc}-brightgreen)"
44-
44+
4545
with open('README.md', 'r') as f:
4646
readme = f.read()
47-
47+
4848
# Replace old shields if they exist
4949
readme = re.sub(r'!\[Test Coverage\]\(https://img\.shields\.io/badge/test__coverage-[^)]+\)\n?', '', readme)
5050
readme = re.sub(r'!\[Doc Coverage\]\(https://img\.shields\.io/badge/doc__coverage-[^)]+\)\n?', '', readme)
51-
51+
5252
# Insert new shields next to the license shield
5353
license_shield = r'(\[!\[License\]\(https://img\.shields\.io/badge/license-[^)]+\)\]\([^)]+\))'
54-
54+
5555
new_shields = f"\\1\n{doc_shield}\n{test_shield}"
56-
56+
5757
new_readme = re.sub(license_shield, new_shields, readme, count=1)
58-
58+
5959
with open('README.md', 'w') as f:
6060
f.write(new_readme)
61-
61+
6262
if __name__ == '__main__':
6363
update_readme()

0 commit comments

Comments
 (0)