Skip to content

Commit 1ee7dbd

Browse files
committed
Merge branch 'ps/upgrade-clar'
Buildfix and upgrade of Clar to a newer version. * ps/upgrade-clar: cmake: set up proper dependencies for generated clar headers cmake: fix compilation of clar-based unit tests Makefile: extract script to generate clar declarations Makefile: adjust sed command for generating "clar-decls.h" t/unit-tests: update clar to 206accb
2 parents 31fe139 + 30bf9f0 commit 1ee7dbd

File tree

14 files changed

+219
-166
lines changed

14 files changed

+219
-166
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,9 +3905,7 @@ GIT-TEST-SUITES: FORCE
39053905
fi
39063906

39073907
$(UNIT_TEST_DIR)/clar-decls.h: $(patsubst %,$(UNIT_TEST_DIR)/%.c,$(CLAR_TEST_SUITES)) GIT-TEST-SUITES
3908-
$(QUIET_GEN)for suite in $(CLAR_TEST_SUITES); do \
3909-
sed -ne "s/^\(void test_$${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)$$\)/extern \1;/p" $(UNIT_TEST_DIR)/$$suite.c; \
3910-
done >$@
3908+
$(QUIET_GEN)$(SHELL_PATH) $(UNIT_TEST_DIR)/generate-clar-decls.sh "$@" $(filter %.c,$^)
39113909
$(UNIT_TEST_DIR)/clar.suite: $(UNIT_TEST_DIR)/clar-decls.h
39123910
$(QUIET_GEN)awk -f $(UNIT_TEST_DIR)/clar-generate.awk $< >$(UNIT_TEST_DIR)/clar.suite
39133911
$(UNIT_TEST_DIR)/clar/clar.o: $(UNIT_TEST_DIR)/clar.suite

contrib/buildsystems/CMakeLists.txt

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,47 +1002,21 @@ foreach(unit_test ${unit_test_PROGRAMS})
10021002
endforeach()
10031003

10041004
parse_makefile_for_scripts(clar_test_SUITES "CLAR_TEST_SUITES" "")
1005-
1006-
set(clar_decls "")
1007-
set(clar_cbs "")
1008-
set(clar_cbs_count 0)
1009-
set(clar_suites "static struct clar_suite _clar_suites[] = {\n")
1010-
list(LENGTH clar_test_SUITES clar_suites_count)
1011-
foreach(suite ${clar_test_SUITES})
1012-
file(STRINGS "${CMAKE_SOURCE_DIR}/t/unit-tests/${suite}.c" decls
1013-
REGEX "^void test_${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*\\(void\\)$")
1014-
1015-
list(LENGTH decls decls_count)
1016-
string(REGEX REPLACE "void (test_${suite}__([a-zA-Z_0-9]*))\\(void\\)" " { \"\\2\", &\\1 },\n" cbs ${decls})
1017-
string(JOIN "" cbs ${cbs})
1018-
list(TRANSFORM decls PREPEND "extern ")
1019-
string(JOIN ";\n" decls ${decls})
1020-
1021-
string(APPEND clar_decls "${decls};\n")
1022-
string(APPEND clar_cbs
1023-
"static const struct clar_func _clar_cb_${suite}[] = {\n"
1024-
${cbs}
1025-
"};\n")
1026-
string(APPEND clar_suites
1027-
" {\n"
1028-
" \"${suite}\",\n"
1029-
" { NULL, NULL },\n"
1030-
" { NULL, NULL },\n"
1031-
" _clar_cb_${suite}, ${decls_count}, 1\n"
1032-
" },\n")
1033-
math(EXPR clar_cbs_count "${clar_cbs_count}+${decls_count}")
1034-
endforeach()
1035-
string(APPEND clar_suites
1036-
"};\n"
1037-
"static const size_t _clar_suite_count = ${clar_suites_count};\n"
1038-
"static const size_t _clar_callback_count = ${clar_cbs_count};\n")
1039-
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${clar_decls}")
1040-
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar_cbs}" "${clar_suites}")
1041-
10421005
list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/")
10431006
list(TRANSFORM clar_test_SUITES APPEND ".c")
1044-
add_library(unit-tests-lib ${clar_test_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c")
1045-
target_include_directories(unit-tests-lib PRIVATE "${CMAKE_SOURCE_DIR}/t/unit-tests")
1007+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1008+
COMMAND ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" ${clar_test_SUITES}
1009+
DEPENDS ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh ${clar_test_SUITES})
1010+
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1011+
COMMAND awk -f "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" > "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1012+
DEPENDS "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h")
1013+
1014+
add_library(unit-tests-lib ${clar_test_SUITES}
1015+
"${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c"
1016+
"${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1017+
"${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1018+
)
1019+
target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests")
10461020
add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c")
10471021
target_link_libraries(unit-tests unit-tests-lib common-main)
10481022
set_target_properties(unit-tests

t/unit-tests/clar/.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
insert_final_newline = true
6+
7+
[*.{c,h}]
8+
indent_style = tab
9+
tab_width = 8
10+
11+
[CMakeLists.txt]
12+
indent_style = tab
13+
tab_width = 8

t/unit-tests/clar/.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
os: [ ubuntu-latest, macos-latest ]
13+
platform:
14+
- os: ubuntu-latest
15+
generator: Unix Makefiles
16+
- os: macos-latest
17+
generator: Unix Makefiles
18+
- os: windows-latest
19+
generator: Visual Studio 17 2022
20+
- os: windows-latest
21+
generator: MSYS Makefiles
22+
- os: windows-latest
23+
generator: MinGW Makefiles
1424

15-
runs-on: ${{ matrix.os }}
25+
runs-on: ${{ matrix.platform.os }}
1626

1727
steps:
1828
- name: Check out
1929
uses: actions/checkout@v2
2030
- name: Build
2131
run: |
22-
cd test
23-
make
32+
mkdir build
33+
cd build
34+
cmake .. -G "${{matrix.platform.generator}}"
35+
cmake --build .

t/unit-tests/clar/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

t/unit-tests/clar/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.16..3.29)
2+
3+
project(clar LANGUAGES C)
4+
5+
option(BUILD_TESTS "Build test executable" ON)
6+
7+
add_library(clar INTERFACE)
8+
target_sources(clar INTERFACE
9+
clar.c
10+
clar.h
11+
clar/fixtures.h
12+
clar/fs.h
13+
clar/print.h
14+
clar/sandbox.h
15+
clar/summary.h
16+
)
17+
set_target_properties(clar PROPERTIES
18+
C_STANDARD 90
19+
C_STANDARD_REQUIRED ON
20+
C_EXTENSIONS OFF
21+
)
22+
23+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
24+
include(CTest)
25+
if(BUILD_TESTING)
26+
add_subdirectory(test)
27+
endif()
28+
endif()

0 commit comments

Comments
 (0)