From c94505dc0db73c65390c75985cfb7a75fa1c1e57 Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Sun, 19 Oct 2025 12:33:17 +0200 Subject: [PATCH] Do not build tests for release --- .gitea/workflows/build.yaml | 6 +++--- README.md | 6 ++++-- meson.build | 23 +++++++++++++++-------- meson_options.txt | 5 +++++ scripts/build.sh | 7 ++++++- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 6594d22..52ceccf 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -35,13 +35,13 @@ jobs: apt-cache policy libusb-1.0-0-dev echo "=== End dependency package version ===" - name: Build ptprnt debug - run: scripts/build.sh debug --coverage --test + run: scripts/build.sh -j2 debug --coverage --test - name: Generate coverage run: scripts/generate_coverage.sh --text - name: Coverage report run: cat ./coverageReport/coverage.txt - - name: build and release - run: scripts/build.sh release + - name: build release + run: scripts/build.sh -j2 release - name: upload release binary uses: actions/upload-artifact@v3 with: diff --git a/README.md b/README.md index a95502a..bbc93dc 100644 --- a/README.md +++ b/README.md @@ -204,10 +204,10 @@ This is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher **Build script:** ```bash -# Release build +# Release build (tests disabled for faster builds) ./scripts/build.sh release -# Debug build +# Debug build (tests enabled) ./scripts/build.sh debug # Debug with tests @@ -223,6 +223,8 @@ This is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher ./scripts/build.sh --help ``` +**Note:** Tests are only built in debug mode to keep release builds fast and small. Release builds do not include test binaries or link against gtest/gmock. + **Running tests:** ```bash # Using build script diff --git a/meson.build b/meson.build index 80c0be0..25a6427 100644 --- a/meson.build +++ b/meson.build @@ -63,13 +63,20 @@ ptprnt_exe = executable( ) ### Unit tests +# Only build tests for debug builds or when explicitly enabled +build_tests = get_option('buildtype') == 'debug' or get_option('build_tests') -# GTest and GMock -gtest_proj = subproject('gtest') -gtest_dep = gtest_proj.get_variable('gtest_main_dep') -gmock_dep = gtest_proj.get_variable('gmock_main_dep') -if not gtest_dep.found() - error('MESON_SKIP_TEST: gtest not installed.') -endif +if build_tests + # GTest and GMock + gtest_proj = subproject('gtest') + gtest_dep = gtest_proj.get_variable('gtest_main_dep') + gmock_dep = gtest_proj.get_variable('gmock_main_dep') + if not gtest_dep.found() + error('MESON_SKIP_TEST: gtest not installed.') + endif -subdir('tests') \ No newline at end of file + subdir('tests') + message('Tests enabled (buildtype=' + get_option('buildtype') + ')') +else + message('Tests disabled (use debug build or -Dbuild_tests=true to enable)') +endif \ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt index 9cc746f..586619d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,3 +2,8 @@ option('usb_trace_only', type: 'boolean', value: false, description: 'Enable USB trace mode: log USB data without sending to device (saves label tape during debugging)') + +option('build_tests', + type: 'boolean', + value: false, + description: 'Build unit tests (automatically enabled for debug builds)') diff --git a/scripts/build.sh b/scripts/build.sh index 157f169..ad269c7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -108,7 +108,12 @@ else echo -e "${YELLOW}Warning: Coverage is only supported for debug builds, ignoring --coverage${NC}" fi - echo -e "${BLUE}Building release version${NC}" + if [[ "${RUN_TESTS}" == true ]]; then + echo -e "${YELLOW}Warning: Tests are not built for release builds (use debug build for testing)${NC}" + RUN_TESTS=false + fi + + echo -e "${BLUE}Building release version (tests disabled)${NC}" fi # Setup or reconfigure build directory