From 08a259c6e2df10b78c6a36266b07c9a89aa0b3ba Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 17 Oct 2023 19:57:48 +0200 Subject: [PATCH 1/3] chore(linux): Fix build scripts Creating the coverage option to ninja previously didn't work reliably. This change re-orders the parameters passed to `meson setup` and seems to work better. Additionally this change refactors the scripts and makes use of `builder_run_action`. --- linux/ibus-keyman/build.sh | 47 ++++++++++------------------ linux/keyman-system-service/build.sh | 37 +++++++++------------- 2 files changed, 31 insertions(+), 53 deletions(-) diff --git a/linux/ibus-keyman/build.sh b/linux/ibus-keyman/build.sh index c2c45deec15..5e13ef12e01 100755 --- a/linux/ibus-keyman/build.sh +++ b/linux/ibus-keyman/build.sh @@ -49,46 +49,31 @@ else MESON_COVERAGE= fi -if builder_start_action clean; then - rm -rf "$THIS_SCRIPT_PATH/../build/" - builder_finish_action success clean -fi - -if builder_start_action configure; then - cd "$THIS_SCRIPT_PATH" - # shellcheck disable=SC2086 - meson setup "$MESON_PATH" --werror --buildtype $MESON_TARGET ${MESON_COVERAGE} "${builder_extra_params[@]}" - builder_finish_action success configure -fi - -if builder_start_action build; then - cd "$THIS_SCRIPT_PATH/$MESON_PATH" - ninja - builder_finish_action success build -fi +configure_action() { + # shellcheck disable=SC2086,SC2154 + meson setup ${MESON_COVERAGE} --werror --buildtype $MESON_TARGET "${builder_extra_params[@]}" "$MESON_PATH" +} -if builder_start_action test; then - cd "$THIS_SCRIPT_PATH/$MESON_PATH" +test_action() { if builder_has_option --no-integration; then + # shellcheck disable=SC2086,SC2154 meson test --print-errorlogs $builder_verbose setup-src-test keymanutil-tests print-kmpdetails-test print-kmp-test bcp47-util-tests teardown-src-test else + # shellcheck disable=SC2086 meson test --print-errorlogs $builder_verbose fi if builder_has_option --coverage; then # Note: requires lcov > 1.16 to properly work (see https://github.com/mesonbuild/meson/issues/6747) ninja coverage-html fi - builder_finish_action success test -fi +} -if builder_start_action install; then - cd "$THIS_SCRIPT_PATH/$MESON_PATH" - ninja install - builder_finish_action success install -fi +builder_run_action clean rm -rf "$THIS_SCRIPT_PATH/../build/" +builder_run_action configure configure_action -if builder_start_action uninstall; then - cd "$THIS_SCRIPT_PATH/$MESON_PATH" - ninja uninstall - builder_finish_action success uninstall -fi +[ -d "$MESON_PATH" ] && cd "$MESON_PATH" + +builder_run_action build ninja +builder_run_action test test_action +builder_run_action install ninja install +builder_run_action uninstall ninja uninstall diff --git a/linux/keyman-system-service/build.sh b/linux/keyman-system-service/build.sh index bfa4b62c3bf..8ba82712955 100755 --- a/linux/keyman-system-service/build.sh +++ b/linux/keyman-system-service/build.sh @@ -45,33 +45,26 @@ else MESON_COVERAGE= fi -builder_run_action clean rm -rf "$THIS_SCRIPT_PATH/build/" +configure_action() { + # shellcheck disable=SC2086,SC2154 + meson setup ${MESON_COVERAGE} --werror --buildtype $MESON_TARGET "${builder_extra_params[@]}" "$MESON_PATH" +} -# shellcheck disable=SC2086 -builder_run_action configure meson setup "$MESON_PATH" --werror --buildtype $MESON_TARGET ${MESON_COVERAGE} "${builder_extra_params[@]}" - -cd "$MESON_PATH" || true - -if builder_start_action build; then - ninja - builder_finish_action success build -fi - -if builder_start_action test; then +test_action() { + # shellcheck disable=SC2086,SC2154 meson test --print-errorlogs $builder_verbose if builder_has_option --coverage; then # Note: requires lcov > 1.16 to properly work (see https://github.com/mesonbuild/meson/issues/6747) ninja coverage-html fi - builder_finish_action success test -fi +} -if builder_start_action install; then - ninja install - builder_finish_action success install -fi +builder_run_action clean rm -rf "$THIS_SCRIPT_PATH/build/" +builder_run_action configure configure_action -if builder_start_action uninstall; then - ninja uninstall - builder_finish_action success uninstall -fi +[ -d "$MESON_PATH" ] && cd "$MESON_PATH" + +builder_run_action build ninja +builder_run_action test test_action +builder_run_action install ninja install +builder_run_action uninstall ninja uninstall From 2a19a2fb12b45a837656c458d431a4022f73ab00 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 18 Oct 2023 10:32:41 +0200 Subject: [PATCH 2/3] chore(linux): Fix coverage report creation for keyman-system-service Since keyman-system-service is a dependency of ibus-keyman it gets build when ibus-keyman gets build. However, in that case the `--coverage` flag doesn't get passed through in which case the `coverage-html` target is missing from ninja. This change fixes this problem by checking if ninja has the `coverage-html` target. If not we remove the output directory which causes the configure action to run again with the `--coverage` option. --- linux/keyman-system-service/build.sh | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/linux/keyman-system-service/build.sh b/linux/keyman-system-service/build.sh index 8ba82712955..d9cb9785ee8 100755 --- a/linux/keyman-system-service/build.sh +++ b/linux/keyman-system-service/build.sh @@ -35,15 +35,22 @@ else fi MESON_PATH="build/$(uname -m)/$MESON_TARGET" -builder_describe_outputs \ - configure "${MESON_PATH}/build.ninja" \ - build "${MESON_PATH}/src/keyman-system-service" +clean_action() { + rm -rf "$THIS_SCRIPT_PATH/build/" +} -if builder_has_option --coverage; then - MESON_COVERAGE=-Db_coverage=true -else - MESON_COVERAGE= -fi +check_missing_coverage_configuration() { + if builder_has_option --coverage && [ -d "$MESON_PATH" ]; then + # It's possible that we got configured because we're a dependency of ibus-keyman + # in which case the `--coverage` option wasn't passed along. + cd "$MESON_PATH" + if ! ninja -t targets | grep -q coverage-html ; then + cd "$THIS_SCRIPT_PATH" + clean_action + fi + cd "$THIS_SCRIPT_PATH" + fi +} configure_action() { # shellcheck disable=SC2086,SC2154 @@ -59,7 +66,19 @@ test_action() { fi } -builder_run_action clean rm -rf "$THIS_SCRIPT_PATH/build/" +check_missing_coverage_configuration + +builder_describe_outputs \ + configure "${MESON_PATH}/build.ninja" \ + build "${MESON_PATH}/src/keyman-system-service" + +if builder_has_option --coverage; then + MESON_COVERAGE=-Db_coverage=true +else + MESON_COVERAGE= +fi + +builder_run_action clean clean_action builder_run_action configure configure_action [ -d "$MESON_PATH" ] && cd "$MESON_PATH" From 798026632d2466b92f0deb89a6342bc05df7711e Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 18 Oct 2023 11:37:58 +0200 Subject: [PATCH 3/3] chore(linux): Update readme --- docs/linux/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/linux/README.md b/docs/linux/README.md index 354ee895318..8ee91fbe81e 100644 --- a/docs/linux/README.md +++ b/docs/linux/README.md @@ -89,6 +89,21 @@ The `run-tests` script accepts different arguments which can be seen with ### Code Coverage Report +#### Prerequisites + +Code coverage reports require some additional tools: lcov, gcovr, +libdatetime-perl, and coverage. + +You can install these with: + +```bash +sudo apt update +sudo apt install -y lcov libdatetime-perl gcovr +pip3 install coverage +``` + +#### Creating and displaying code coverage reports + All three projects (ibus-keyman, keyman-config, and keyman-system-service) can produce code coverage reports.