Skip to content

Commit 514e605

Browse files
authored
CI-unixish.yml: fixed and enabled all build steps for macos (#4832)
1 parent b53bb36 commit 514e605

7 files changed

Lines changed: 53 additions & 34 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ jobs:
314314
if: contains(matrix.os, 'macos')
315315
run: |
316316
# pcre was removed from runner images in November 2022
317-
brew install coreutils python3 pcre
317+
brew install coreutils python3 pcre gnu-sed
318318
319319
- name: Install missing Python packages
320320
run: |
@@ -335,9 +335,8 @@ jobs:
335335
run: |
336336
make -j$(nproc) check HAVE_RULES=yes
337337
338-
# the script uses sed parameters not supported by MacOS
338+
# requires "gnu-sed" installed on macos
339339
- name: Run extra tests
340-
if: contains(matrix.os, 'ubuntu')
341340
run: |
342341
tools/generate_and_run_more_tests.sh
343342
@@ -351,9 +350,8 @@ jobs:
351350
cd 'cpp check/test/cli'
352351
python3 -m pytest test-*.py
353352
354-
# fails on macos since some includes (e.g. sys/epoll.h) are not available
355353
- name: Run cfg tests
356-
if: contains(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-22.04'
354+
if: matrix.os != 'ubuntu-22.04'
357355
run: |
358356
make -j$(nproc) checkcfg
359357
@@ -364,9 +362,7 @@ jobs:
364362
env:
365363
STRICT: 1
366364

367-
# it seems macos has no "wc" command
368365
- name: Run showtimetop5 tests
369-
if: contains(matrix.os, 'ubuntu')
370366
run: |
371367
./tools/test_showtimetop5.sh
372368

test/cfg/gnu.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@
1919
#include <sys/mman.h>
2020
#include <sys/sem.h>
2121
#include <wchar.h>
22-
#ifndef __CYGWIN__
22+
#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__))
2323
#include <sys/epoll.h>
2424
#endif
2525
#include <strings.h>
26+
#ifdef __gnu_linux__
2627
#include <error.h>
28+
#endif
2729
#include <getopt.h>
2830
#include <netdb.h>
2931

32+
#ifdef __gnu_linux__
3033
void unreachableCode_error(void) // #11197
3134
{
3235
error(1, 0, ""); // will call exit() if the first parameter is non-zero
3336
// cppcheck-suppress unusedVariable
3437
// TODO cppcheck-suppress unreachableCode
3538
int i;
3639
}
40+
#endif
3741

3842
int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret, char* buf, size_t buflen, struct hostent** result, int* h_errnop)
3943
{
@@ -431,7 +435,7 @@ void leakReturnValNotUsed()
431435
return;
432436
}
433437

434-
#ifndef __CYGWIN__
438+
#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__))
435439
int nullPointer_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
436440
{
437441
// no warning is expected

test/cfg/posix.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
88
//
99

10+
#define _BSD_SOURCE
11+
1012
#include <aio.h>
1113
#include <stdio.h> // <- FILE
1214
#include <dirent.h>
@@ -19,7 +21,7 @@
1921
#include <pwd.h>
2022
#include <dlfcn.h>
2123
#include <fcntl.h>
22-
// unavailable on some linux systems #include <ndbm.h>
24+
// #include <ndbm.h> // unavailable on some linux systems
2325
#include <netdb.h>
2426
#include <regex.h>
2527
#include <time.h>
@@ -28,20 +30,23 @@
2830
#include <stdarg.h>
2931
#include <ctype.h>
3032
#include <stdbool.h>
33+
#if !(defined(__APPLE__) && defined(__MACH__))
3134
#include <mqueue.h>
32-
#define _XOPEN_SOURCE
35+
#endif
3336
#include <stdlib.h>
3437
#include <unistd.h>
3538
#include <wchar.h>
3639
#include <string.h>
3740
#include <strings.h>
3841

42+
#if !(defined(__APPLE__) && defined(__MACH__))
3943
void nullPointer_mq_timedsend(mqd_t mqdes, const char* msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec* abs_timeout) {
4044
// cppcheck-suppress nullPointer
4145
(void) mq_timedsend(mqdes, NULL, msg_len, msg_prio, abs_timeout);
4246
// cppcheck-suppress nullPointer
4347
(void) mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL);
4448
}
49+
#endif
4550

4651
#if __TRACE_H__ // <trace.h>
4752

@@ -143,13 +148,15 @@ int nullPointer_getopt(int argc, char* const argv[], const char* optstring)
143148
return getopt(argc, argv, optstring);
144149
}
145150

151+
#if !(defined(__APPLE__) && defined(__MACH__))
146152
int invalidFunctionArgStr_mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
147153
{
148154
// No warning is expected for:
149155
const char msg = '0';
150156
(void) mq_send(mqdes, &msg, 1, 0);
151157
return mq_send(mqdes, msg_ptr, msg_len, 0);
152158
}
159+
#endif
153160

154161
void invalidFunctionArgStr_mbsnrtowcs(void)
155162
{
@@ -492,6 +499,7 @@ int nullPointer_aio_suspend(const struct aiocb *const aiocb_list[], int nitems,
492499
return aio_suspend(aiocb_list, nitems, timeout);
493500
}
494501

502+
#ifdef __linux__
495503
// Note: Since glibc 2.28, this function symbol is no longer available to newly linked applications.
496504
void invalidFunctionArg_llseek(int fd, loff_t offset, int origin)
497505
{
@@ -522,6 +530,7 @@ void invalidFunctionArg_llseek(int fd, loff_t offset, int origin)
522530
// cppcheck-suppress llseekCalled
523531
(void)llseek(fd, offset, SEEK_END);
524532
}
533+
#endif
525534

526535
void invalidFunctionArg_lseek64(int fd, off_t offset, int origin)
527536
{

test/cfg/runtests.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ CPPCHECK_OPT='--check-library --platform=unix64 --enable=style,information --inc
2727

2828
# Compiler settings
2929
CXX=g++
30-
CXX_OPT='-fsyntax-only -std=c++2a -Wno-format -Wno-format-security -Wno-deprecated-declarations'
30+
CXX_OPT='-fsyntax-only -w -std=c++2a'
3131
CC=gcc
32-
CC_OPT='-Wno-format -Wno-stringop-overread -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only'
32+
CC_OPT='-fsyntax-only -w -std=c11'
3333

3434
function get_pkg_config_cflags {
3535
set +e
@@ -194,7 +194,10 @@ function sqlite3_fn {
194194

195195
# openmp.c
196196
function openmp_fn {
197-
${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c
197+
# MacOS compiler has no OpenMP by default
198+
if ! command -v sw_vers; then
199+
${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c
200+
fi
198201
}
199202

200203
# python.c

test/cfg/std.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#endif
2929
#include <inttypes.h>
3030
#include <float.h>
31+
#include <stdarg.h>
32+
#include <sys/types.h>
3133

3234
size_t invalidFunctionArgStr_wcslen(void)
3335
{

tools/run_more_tests.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
# Script Used by generate_and_run_more_tests.sh
33

4+
# "gsed" is a GNU compatible version of "sed" on MacOS
5+
SED_CMD=$(command -v gsed || command -v sed)
6+
47
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
58

69
set -e
@@ -19,85 +22,85 @@ $CPPCHECK -q --template=cppcheck1 . 2> 1.txt
1922

2023

2124
# (!x) => (x==0)
22-
sed -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp
25+
$SED_CMD -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp
2326
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
2427

2528
# (x==0) => (0==x)
26-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp
29+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp
2730
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
2831

2932
# (0==x) => (!x)
30-
sed -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp
33+
$SED_CMD -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp
3134
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
3235

3336

3437

3538

3639
# if (x) => (x!=0)
37-
sed -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
40+
$SED_CMD -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
3841
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
3942

4043
# while (x) => (x!=0)
41-
sed -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
44+
$SED_CMD -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
4245
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
4346

4447
# (x!=0) => (0!=x)
45-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp
48+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp
4649
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
4750

4851
# (0!=x) => (x)
49-
sed -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp
52+
$SED_CMD -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp
5053
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
5154

5255

5356
# (x < 0) => (0 > x)
54-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
57+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
5558
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
5659

5760
# (x <= 0) => (0 >= x)
58-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
61+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
5962
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6063

6164
# (x > 0) => (0 < x)
62-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
65+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
6366
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6467

6568
# (x >= 0) => (0 <= x)
66-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
69+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
6770
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6871

6972
# (x == 123) => (123 == x)
70-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
73+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
7174
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
7275

7376
# (x != 123) => (123 != x)
74-
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
77+
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
7578
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
7679

7780

7881

7982
# (0 < x) => (x > 0)
80-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
83+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
8184
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
8285

8386
# (0 <= x) => (x >= 0)
84-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
87+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
8588
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
8689

8790
# (0 > x) => (x < 0)
88-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
91+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
8992
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
9093

9194
# (0 >= x) => (x <= 0)
92-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
95+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
9396
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
9497

9598
# (123 == x) => (x == 123)
96-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
99+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
97100
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
98101

99102
# (123 != x) => (x <= 123)
100-
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
103+
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
101104
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
102105

103106

tools/test_showtimetop5.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
2+
# "gwc" is a GNU compatible of "wc" on MacOS
3+
WC_CMD=$(command -v gwc || command -v wc)
24
output=$(./cppcheck --showtime=top5 cli/cmdlineparser.h --language=c++ --quiet)
35
echo "$output"
4-
if [[ "$(echo "$output" | wc -l)" != 7 ]] ; then
6+
if [[ "$(echo "$output" | $WC_CMD -l)" != 7 ]] ; then
57
false
68
fi

0 commit comments

Comments
 (0)