From 9743445e44781ad2c07b6d3c3cfeb9769f937dcd Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 25 Jan 2023 14:46:44 -0500 Subject: [PATCH] Meta: Allow running Lagom tests with "serenity.sh run lagom " After 5ac57f9, we could no longer run "serenity.sh run lagom TestString" because the TestString binary now lives in a subdirectory under Build/lagom. Thus the existing method of running "$BUILD_DIR/TestString" could not work. This adds a "run-lagom-target" custom target to Lagom, to run a command and pass arguments to that invocation. It turns out there really isn't a "pretty" way of doing this with CMake or Ninja. But we can pass these as environment variables for CMake to interpret. We just must be careful to massage arguments into a CMake list. --- Meta/Lagom/CMakeLists.txt | 9 +++++++++ Meta/serenity.sh | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index b349f4ae36f..aba20e6b4e3 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -688,3 +688,12 @@ if (ENABLE_FUZZERS) else() export_components("${CMAKE_BINARY_DIR}/components.ini") endif() + +if (NOT "$ENV{LAGOM_TARGET}" STREQUAL "") + add_custom_target(run-lagom-target + COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SERENITY_PROJECT_ROOT}" "$" $ENV{LAGOM_ARGS} + DEPENDS "$" + USES_TERMINAL + VERBATIM + ) +endif() diff --git a/Meta/serenity.sh b/Meta/serenity.sh index 9dcec769929..31986f1e58b 100755 --- a/Meta/serenity.sh +++ b/Meta/serenity.sh @@ -401,6 +401,23 @@ run_gdb() { fi } +build_and_run_lagom_target() { + local lagom_target="${CMD_ARGS[0]}" + local lagom_args + + # All command arguments must have any existing semicolon escaped, to prevent CMake from + # interpreting them as list separators. + local cmd_args=() + for arg in "${CMD_ARGS[@]:1}"; do + cmd_args+=( "${arg//;/\\;}" ) + done + + # Then existing list separators must be replaced with a semicolon for CMake. + lagom_args=$(IFS=';' ; echo -e "${cmd_args[*]}") + + LAGOM_TARGET="${lagom_target}" LAGOM_ARGS="${lagom_args[*]}" build_target "run-lagom-target" +} + if [[ "$CMD" =~ ^(build|install|image|copy-src|run|gdb|test|rebuild|recreate|kaddr2line|addr2line|setup-and-run)$ ]]; then cmd_with_target [[ "$CMD" != "recreate" && "$CMD" != "rebuild" ]] || delete_target @@ -429,11 +446,11 @@ if [[ "$CMD" =~ ^(build|install|image|copy-src|run|gdb|test|rebuild|recreate|kad ;; run) if [ "$TARGET" = "lagom" ]; then - build_target "${CMD_ARGS[0]}" if [ "${CMD_ARGS[0]}" = "ladybird" ]; then + build_target "${CMD_ARGS[0]}" ninja -C "$BUILD_DIR" run-ladybird else - "$BUILD_DIR/${CMD_ARGS[0]}" "${CMD_ARGS[@]:1}" + build_and_run_lagom_target fi else build_target