[Tarantool-patches] [PATCH luajit 2/8] test: introduce MakeLuaPath.cmake helper

Sergey Kaplun skaplun at tarantool.org
Thu Sep 1 13:16:19 MSK 2022


Hi, Igor!

Thanks for the fixes!

On 31.08.22, Igor Munkin wrote:
> Sergey,
> 
> Thanks for your review!
> 
> On 18.08.22, Sergey Kaplun wrote:

<snipped>

> > > +# 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?
> 
> The code will become more complex as a result and in the 99.999% of the
> cases the order of LUA_PATH entries doesn't bother you.

But it bothers me for the lua-Harness tests already. We get the
following snippet from <303-package.t>:

|   f = io.open('syntax.lua', 'w')
|   f:write [[?syntax error?]]
|   f:close()
|   local r, e = pcall(require, 'syntax')
|   error_matches(function () require('syntax') end,
|           "^error loading module 'syntax' from file '%.[/\\]syntax%.lua':",
|           "function require (syntax error)")

As we can see `error_matches()` expects "file './syntax.lua'" string
from the output, but if "./.?lua" path isn't the first one, this test
will fail due to the whole path in the output.

>                                                         So I don't see
> we should make the code more complex to save the order of the entries.

As far as I don't usually read from bottom to top (except mcode encoding)
it is more convenient to me to use strict order.

Also, as for me the following patch (feel free to modify it as you want)
doesn't make the code too complex:

===================================================================
diff --git a/cmake/MakeLuaPath.cmake b/cmake/MakeLuaPath.cmake
index 9a5a3bb8..f92bdb19 100644
--- a/cmake/MakeLuaPath.cmake
+++ b/cmake/MakeLuaPath.cmake
@@ -28,19 +28,23 @@ function(make_lua_path path)
                         "${multiValues}"
                         ${ARGN})
 
-  # XXX: This is the sentinel semicolon having special meaning
-  # 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
     # automatically becomes a list. I found a single working
     # solution to make result variable be a string via "escaping"
     # the semicolon right in string interpolation.
-    set(result "${inc}\;${result}")
+    if(result)
+      set(result "${result}\;${inc}")
+    else()
+      set(result "${inc}")
+    endif()
   endforeach()
 
+  # XXX: This is the sentinel semicolon having special meaning
+  # 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 "${result}\;\;")
+
   set(${path} "${result}" PARENT_SCOPE)
 endfunction()
===================================================================

> 
> > 
> > > +
> > > +function(make_lua_path path)

<snipped>

> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> -- 
> Best regards,
> IM

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list