Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/8] test: introduce MakeLuaPath.cmake helper
Date: Thu, 18 Aug 2022 12:37:23 +0300	[thread overview]
Message-ID: <Yv4IU3CGEbezyB4W@root> (raw)
In-Reply-To: <1d05bbecc9c9ae57250ec563e202a8e103f86fa4.1660216002.git.imun@tarantool.org>

Hi, Igor!

Thanks for the patch!

Please consider my comments below.

On 11.08.22, Igor Munkin wrote:
> While extending test suites it is often required to append additional
> path where Lua or Lua-C auxiliary modules are located to LUA_PATH or
> LUA_CPATH environment variables. Due to insane semicolon interpolation
> in CMake strings (that converts such string to a list as a result), we
> need to escape semicolon in LUA_PATH/LUA_CPATH strings while building
> the resulting value.
> 
> After the years of struggling MakeLuaPath.cmake module is introduced to

Minor: s/After/Over/

> make LUA_PATH and LUA_CPATH definition convenient with <make_lua_path>
> helper. This function takes all paths given as a variable list argument,
> joins them in a reverse order by a semicolon and yields the resulting
> string to a specified CMake variable.
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
>  cmake/MakeLuaPath.cmake                   | 46 +++++++++++++++++++++++
>  test/CMakeLists.txt                       |  2 +
>  test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt |  8 +++-
>  test/lua-Harness-tests/CMakeLists.txt     | 16 +++++---
>  test/tarantool-tests/CMakeLists.txt       | 28 ++++++++------
>  5 files changed, 81 insertions(+), 19 deletions(-)
>  create mode 100644 cmake/MakeLuaPath.cmake
> 
> diff --git a/cmake/MakeLuaPath.cmake b/cmake/MakeLuaPath.cmake
> new file mode 100644
> index 00000000..9a5a3bb8
> --- /dev/null
> +++ b/cmake/MakeLuaPath.cmake
> @@ -0,0 +1,46 @@
> +# make_lua_path provides a convenient way to define LUA_PATH and
> +# LUA_CPATH variables.
> +#
> +# Example usage:
> +#
> +#   make_lua_path(LUA_PATH
> +#     PATH
> +#       ${CMAKE_CURRENT_SOURCE_DIR}/?.lua
> +#       ${CMAKE_BINARY_DIR}/?.lua
> +#       ./?.lua
> +#   )
> +#
> +# This will give you the string:
> +#    "./?.lua;${CMAKE_BINARY_DIR}/?.lua;${CMAKE_CURRENT_SOURCE_DIR}/?.lua;;"
> +# XXX: Mind the reverse order of the entries in the result string.

Why do we need this behaviour? May be it is better to save strict order
of entries?

> +
> +function(make_lua_path path)
> +  set(prefix ARG)
> +  set(noValues)
> +  set(singleValues)
> +  set(multiValues PATHS)
> +
> +  # FIXME: if we update to CMake >= 3.5, can remove this line.

So, we can just check CMake version as Sergey suggested.

> +  include(CMakeParseArguments)
> +  cmake_parse_arguments(${prefix}
> +                        "${noValues}"
> +                        "${singleValues}"
> +                        "${multiValues}"
> +                        ${ARGN})
> +
> +  # XXX: This is the sentinel semicolon having special meaning

Nit: It's not single semicolon, but two of them. This ";;" special value
is created during concatenation at the next lines.

> +  # for LUA_PATH and LUA_CPATH variables. For more info, see the
> +  # link below:
> +  # https://www.lua.org/manual/5.1/manual.html#pdf-LUA_PATH
> +  set(result "\;")
> +
> +  foreach(inc ${ARG_PATHS})
> +    # XXX: If one joins two strings with semicolon, the value

Typo: s/semicolon/the semicolon/

> +    # automatically becomes a list. I found a single working
> +    # solution to make result variable be a string via "escaping"

Minor: s/be/stay/ or just s/be//
Feel free to ignore.

> +    # the semicolon right in string interpolation.
> +    set(result "${inc}\;${result}")
> +  endforeach()
> +
> +  set(${path} "${result}" PARENT_SCOPE)
> +endfunction()
> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
> index ba25af54..a8262b12 100644
> --- a/test/CMakeLists.txt
> +++ b/test/CMakeLists.txt
> @@ -3,6 +3,8 @@
>  # See the rationale in the root CMakeLists.txt.
>  cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
>  
> +include(MakeLuaPath)
> +

Minor: It would be nice to drop the comment that this will be used in
all test suites by transitivity.
Feel free to ignore.

>  find_program(LUACHECK luacheck)
>  if(LUACHECK)
>    # XXX: The tweak below relates to luacheck problem with paths.
> diff --git a/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt b/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt
> index 8e825f55..b95e7852 100644
> --- a/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt
> +++ b/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt

<snipped>

> diff --git a/test/lua-Harness-tests/CMakeLists.txt b/test/lua-Harness-tests/CMakeLists.txt
> index 12476171..a57104a5 100644
> --- a/test/lua-Harness-tests/CMakeLists.txt
> +++ b/test/lua-Harness-tests/CMakeLists.txt

<snipped>

> diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> index ecda2e63..27866869 100644
> --- a/test/tarantool-tests/CMakeLists.txt
> +++ b/test/tarantool-tests/CMakeLists.txt
> @@ -43,14 +43,11 @@ macro(BuildTestCLib lib sources)
>    # semicolon. If one finds the normal way to make it work, feel
>    # free to reach me.
>    set(TESTLIBS "${lib};${TESTLIBS}" PARENT_SCOPE)
> -  # Add the directory where the lib is built to the LUA_CPATH
> -  # environment variable, so LuaJIT can find and load it.
> -  # XXX: Here we see the other side of the coin. If one joins two
> -  # strings with semicolon, the value automatically becomes a
> -  # list. I found a single working solution to make LUA_CPATH be
> -  # a string via "escaping" the semicolon right in string
> -  # interpolation.
> -  set(LUA_CPATH "${CMAKE_CURRENT_BINARY_DIR}/?${CMAKE_SHARED_LIBRARY_SUFFIX}\;${LUA_CPATH}" PARENT_SCOPE)
> +  # Add the directory where the lib is built to the list with
> +  # entries for LUA_CPATH environment variable, so LuaJIT can find
> +  # and load it. See the comment about extending the list in the
> +  # parent scope few lines above.
> +  set(LUA_CPATHS "${CMAKE_CURRENT_BINARY_DIR}/?${CMAKE_SHARED_LIBRARY_SUFFIX};${LUA_CPATHS}" PARENT_SCOPE)
>    # Also add this directory to LD_LIBRARY_PATH environment
>    # variable, so FFI machinery can find and load it.
>    set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}:${LD_LIBRARY_PATH}" PARENT_SCOPE)
> @@ -76,14 +73,21 @@ add_subdirectory(misclib-sysprof-capi)
>  # in src/ directory and auxiliary tests-related modules are
>  # located in the current directory (but tests are run in the
>  # binary directory), so LUA_PATH need to be updated.
> -set(LUA_PATH
> -  "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua\;${PROJECT_SOURCE_DIR}/src/?.lua"
> +make_lua_path(LUA_PATH
> +  PATHS
> +    ${CMAKE_CURRENT_SOURCE_DIR}/?.lua
> +    ${PROJECT_SOURCE_DIR}/tools/?.lua
> +    ${PROJECT_SOURCE_DIR}/src/?.lua
>  )
> +# Update LUA_CPATH with the library paths collected within
> +# <BuildTestLib> macro.
> +make_lua_path(LUA_CPATH PATHS ${LUA_CPATHS})

Side note: Looks like this part of patching is unnecessary -- we can
just leave it as is (isntead manipulation with ; later in
`make_lua_path()`). But it is good for consistency of working with env
variables, so feel free to ignore.

> +
>  set(LUA_TEST_SUFFIX .test.lua)
>  set(LUA_TEST_FLAGS --failures --shuffle)
>  set(LUA_TEST_ENV
> -  "LUA_PATH=\"${LUA_PATH}\;\;\""
> -  "LUA_CPATH=\"${LUA_CPATH}\;\;\""
> +  "LUA_PATH=\"${LUA_PATH}\""
> +  "LUA_CPATH=\"${LUA_CPATH}\""
>  )
>  
>  if(CMAKE_VERBOSE_MAKEFILE)
> -- 
> 2.34.0
> 

-- 
Best regards,
Sergey Kaplun

  parent reply	other threads:[~2022-08-18  9:39 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 11:17 [Tarantool-patches] [PATCH luajit 0/8] LuaJIT tests and CI enhancements Igor Munkin via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 1/8] test: introduce LUAJIT_TEST_VARDIR variable Igor Munkin via Tarantool-patches
2022-08-15 12:08   ` Sergey Bronnikov via Tarantool-patches
2022-08-18  8:27     ` Sergey Kaplun via Tarantool-patches
2022-08-31 14:53     ` Igor Munkin via Tarantool-patches
2022-09-02 12:06       ` Sergey Bronnikov via Tarantool-patches
2022-10-05 19:51         ` Igor Munkin via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 2/8] test: introduce MakeLuaPath.cmake helper Igor Munkin via Tarantool-patches
2022-08-15 12:08   ` Sergey Bronnikov via Tarantool-patches
2022-08-31 15:07     ` Igor Munkin via Tarantool-patches
2022-09-02 12:09       ` Sergey Bronnikov via Tarantool-patches
2022-08-18  9:37   ` Sergey Kaplun via Tarantool-patches [this message]
2022-08-31 15:19     ` Igor Munkin via Tarantool-patches
2022-09-01 10:16       ` Sergey Kaplun via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 3/8] test: fix tarantool suite for out of source build Igor Munkin via Tarantool-patches
2022-08-15 12:10   ` Sergey Bronnikov via Tarantool-patches
2022-08-18  9:49   ` Sergey Kaplun via Tarantool-patches
2022-08-31 17:20     ` Igor Munkin via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 4/8] ci: use out of source build in GitHub Actions Igor Munkin via Tarantool-patches
2022-08-15 12:13   ` Sergey Bronnikov via Tarantool-patches
2022-08-18  9:58     ` Sergey Kaplun via Tarantool-patches
2022-08-31 15:34       ` Igor Munkin via Tarantool-patches
2022-08-31 15:33     ` Igor Munkin via Tarantool-patches
2022-09-02 12:09       ` Sergey Bronnikov via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 5/8] ci: remove excess parallel level setup Igor Munkin via Tarantool-patches
2022-08-15 12:14   ` Sergey Bronnikov via Tarantool-patches
2022-08-18 10:09   ` Sergey Kaplun via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 6/8] ci: remove arch prefix for macOS M1 workflow Igor Munkin via Tarantool-patches
2022-08-15 12:17   ` Sergey Bronnikov via Tarantool-patches
2022-08-18 10:14   ` Sergey Kaplun via Tarantool-patches
2022-08-31 15:55     ` Igor Munkin via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 7/8] ci: merge x86_64 and ARM64 workflows Igor Munkin via Tarantool-patches
2022-08-15 12:22   ` Sergey Bronnikov via Tarantool-patches
2022-08-18 10:21   ` Sergey Kaplun via Tarantool-patches
2022-08-31 16:02     ` Igor Munkin via Tarantool-patches
2022-08-11 11:17 ` [Tarantool-patches] [PATCH luajit 8/8] ci: merge Linux and macOS workflows Igor Munkin via Tarantool-patches
2022-08-15 12:27   ` Sergey Bronnikov via Tarantool-patches
2022-08-18 10:32   ` Sergey Kaplun via Tarantool-patches
2022-11-11  8:56 ` [Tarantool-patches] [PATCH luajit 0/8] LuaJIT tests and CI enhancements Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yv4IU3CGEbezyB4W@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 2/8] test: introduce MakeLuaPath.cmake helper' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox