Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment
@ 2021-02-02 20:57 Igor Munkin via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
                   ` (5 more replies)
  0 siblings, 6 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

This series moves LuaJIT-related parts of Tarantool testing machinery to
LuaJIT repository. For this purpose the build system is partially ported
to CMake. To avoid Makefiles name clashing the original build system is
renamed to keep it working. As a result of these changes one need to
explicitly specify the Makefile in the build command:
| make -f Makefile.original <options>

These changes provides CMake build system only for the following OS:
GNU/Linux, OSX, FreeBSD. For other platrforms use the old build system.

To run all available tests a separate target is introduced. The whole
testing machinery is reworked much but the existing tests are left
mostly unchanged. However, considering the way LuaJIT is integrated
into Tarantool, this machinery provides two new configuration options:
* LUAJIT_USE_TEST: to omit <test> target configuration for LuaJIT to
  respect CMP0002 policy.
* LUAJIT_TEST_BINARY: to choose which binary (i.e. Lua runtime) to be
  used for running them.

The latter option value is used as a dependency for tests, and its
default value is $<TARGET_FILE:${LUAJIT_DEPS}>. Unfortunately older
CMake can't expand the generator expression used in DEPENDS section of
<add_custom_(command|target)>. As a result the CMake minimum required
version is bumped to 3.1 project-wide[1]. For more info see CMake Release
notes[2] for 3.1 version.

Finally, existing tests are grouped and moved to a separate directory
under the root test directory to make the further addition of other
available test suites in scope of #4064[3] and #4473[4] easier.

Tarantool tests are implemented using Tarantool on-board TAP module[5],
that is moved to LuaJIT repository with a little changes to save Lua
chunks untouched. Other auxiliary files for Tarantool-specific testing
(such as *.skipcond, suite.ini), in turn, are removed.

To run static analysis for Lua chunks a separate target is introduced.
In scope of this target luacheck is run against all Lua chunks within
LuaJIT repository except those inherited from LuaJIT vanilla repository,
to leave them coherent with the upstream.

Since the regular static analysis has not been enabled for the test
chunks in LuaJIT repository yet, the tests for recently implemented
features still produce luacheck warnings. The most of the issues are
fixed in scope of the commit 8fc103fb1a21c28185a1942e75d8d9485e3aade7
('test: fix warnings spotted by luacheck') and the last patch fixes the
remaining ones.

[1]: https://lists.tarantool.org/tarantool-patches/20210127130947.yw5sdswpokujblyr@tarantool.org/T/#t
[2]: https://cmake.org/cmake/help/latest/release/3.1.html#commands
[3]: https://github.com/tarantool/tarantool/issues/4064
[4]: https://github.com/tarantool/tarantool/issues/4473
[5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/

Branch: https://github.com/tarantool/luajit/tree/imun/gh-4862-cmake
Issues:
* https://github.com/tarantool/tarantool/issues/4862
* https://github.com/tarantool/tarantool/issues/5470
* https://github.com/tarantool/tarantool/issues/5631

Igor Munkin (5):
  build: preserve the original build system
  build: replace GNU Make with CMake
  test: run LuaJIT tests via CMake
  test: fix warnings found with luacheck in misclib*
  test: run luacheck static analysis via CMake

 .gitignore                                    |  14 +-
 .luacheckrc                                   |  11 +
 CMakeLists.txt                                | 290 +++++++++++++
 Makefile => Makefile.original                 |  44 +-
 cmake/LuaJITUtils.cmake                       |  31 ++
 cmake/MakeSourceList.cmake                    |  47 +++
 cmake/SetDynASMFlags.cmake                    | 130 ++++++
 cmake/SetTargetFlags.cmake                    |  42 ++
 cmake/SetVersion.cmake                        |  45 ++
 etc/CMakeLists.txt                            |  33 ++
 etc/{luajit.pc => luajit.pc.in}               |   4 +-
 src/CMakeLists.txt                            | 396 ++++++++++++++++++
 src/{Makefile.dep => Makefile.dep.original}   |   0
 src/{Makefile => Makefile.original}           |   4 +-
 src/host/CMakeLists.txt                       |  62 +++
 test/CMakeLists.txt                           |  62 ++-
 test/gh-4427-ffi-sandwich.skipcond            |   7 -
 test/gh-4427-ffi-sandwich/CMakeLists.txt      |   1 -
 test/lj-flush-on-trace.skipcond               |   7 -
 test/lj-flush-on-trace/CMakeLists.txt         |   1 -
 test/misclib-getmetrics-capi.skipcond         |   7 -
 test/misclib-getmetrics-capi/CMakeLists.txt   |   1 -
 test/misclib-getmetrics-lapi.skipcond         |   7 -
 test/suite.ini                                |   6 -
 test/tarantool-tests/CMakeLists.txt           |  92 ++++
 .../gh-3196-incorrect-string-length.test.lua  |   2 +-
 .../gh-4427-ffi-sandwich.test.lua             |  24 +-
 .../gh-4427-ffi-sandwich/CMakeLists.txt       |   1 +
 .../gh-4427-ffi-sandwich/libsandwich.c        |   0
 ...gh-4476-fix-string-find-recording.test.lua |   2 +-
 ...gh-4773-tonumber-fail-on-NUL-char.test.lua |   2 +-
 .../lj-494-table-chain-infinite-loop.test.lua |   2 +-
 ...lj-505-fold-no-strref-for-ptrdiff.test.lua |   2 +-
 .../lj-524-fold-conv-respect-src-irt.test.lua |   2 +-
 .../lj-flush-on-trace.test.lua                |  24 +-
 .../lj-flush-on-trace/CMakeLists.txt          |   1 +
 .../lj-flush-on-trace/libflush.c              |   0
 .../misclib-getmetrics-capi.test.lua          |  27 +-
 .../misclib-getmetrics-capi/CMakeLists.txt    |   1 +
 .../misclib-getmetrics-capi/testgetmetrics.c  |   0
 .../misclib-getmetrics-lapi.test.lua          |  38 +-
 .../misclib-memprof-lapi.test.lua             |  15 +-
 .../or-232-unsink-64-kptr.test.lua            |   0
 test/tarantool-tests/tap.lua                  | 306 ++++++++++++++
 test/tarantool-tests/utils.lua                |  43 ++
 test/utils.lua                                |  33 --
 tools/CMakeLists.txt                          |  77 ++++
 tools/luajit-parse-memprof                    |   9 -
 tools/luajit-parse-memprof.in                 |   6 +
 49 files changed, 1796 insertions(+), 165 deletions(-)
 create mode 100644 .luacheckrc
 create mode 100644 CMakeLists.txt
 rename Makefile => Makefile.original (85%)
 create mode 100644 cmake/LuaJITUtils.cmake
 create mode 100644 cmake/MakeSourceList.cmake
 create mode 100644 cmake/SetDynASMFlags.cmake
 create mode 100644 cmake/SetTargetFlags.cmake
 create mode 100644 cmake/SetVersion.cmake
 create mode 100644 etc/CMakeLists.txt
 rename etc/{luajit.pc => luajit.pc.in} (91%)
 create mode 100644 src/CMakeLists.txt
 rename src/{Makefile.dep => Makefile.dep.original} (100%)
 rename src/{Makefile => Makefile.original} (99%)
 create mode 100644 src/host/CMakeLists.txt
 delete mode 100644 test/gh-4427-ffi-sandwich.skipcond
 delete mode 100644 test/gh-4427-ffi-sandwich/CMakeLists.txt
 delete mode 100644 test/lj-flush-on-trace.skipcond
 delete mode 100644 test/lj-flush-on-trace/CMakeLists.txt
 delete mode 100644 test/misclib-getmetrics-capi.skipcond
 delete mode 100644 test/misclib-getmetrics-capi/CMakeLists.txt
 delete mode 100644 test/misclib-getmetrics-lapi.skipcond
 delete mode 100644 test/suite.ini
 create mode 100644 test/tarantool-tests/CMakeLists.txt
 rename test/{ => tarantool-tests}/gh-3196-incorrect-string-length.test.lua (94%)
 rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich.test.lua (70%)
 create mode 100644 test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
 rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich/libsandwich.c (100%)
 rename test/{ => tarantool-tests}/gh-4476-fix-string-find-recording.test.lua (99%)
 rename test/{ => tarantool-tests}/gh-4773-tonumber-fail-on-NUL-char.test.lua (95%)
 rename test/{ => tarantool-tests}/lj-494-table-chain-infinite-loop.test.lua (99%)
 rename test/{ => tarantool-tests}/lj-505-fold-no-strref-for-ptrdiff.test.lua (96%)
 rename test/{ => tarantool-tests}/lj-524-fold-conv-respect-src-irt.test.lua (95%)
 rename test/{ => tarantool-tests}/lj-flush-on-trace.test.lua (70%)
 create mode 100644 test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
 rename test/{ => tarantool-tests}/lj-flush-on-trace/libflush.c (100%)
 rename test/{ => tarantool-tests}/misclib-getmetrics-capi.test.lua (88%)
 create mode 100644 test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
 rename test/{ => tarantool-tests}/misclib-getmetrics-capi/testgetmetrics.c (100%)
 rename test/{ => tarantool-tests}/misclib-getmetrics-lapi.test.lua (94%)
 rename test/{ => tarantool-tests}/misclib-memprof-lapi.test.lua (86%)
 rename test/{ => tarantool-tests}/or-232-unsink-64-kptr.test.lua (100%)
 create mode 100644 test/tarantool-tests/tap.lua
 create mode 100644 test/tarantool-tests/utils.lua
 delete mode 100644 test/utils.lua
 create mode 100644 tools/CMakeLists.txt
 delete mode 100755 tools/luajit-parse-memprof
 create mode 100644 tools/luajit-parse-memprof.in

-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
@ 2021-02-02 20:57 ` Igor Munkin via Tarantool-patches
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
  2021-02-09 11:38   ` Sergey Kaplun via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

Since the build machinery is going to be ported to CMake there would be
Makefile names clashing. This change renames the original build system
(and a couple of auxiliary files requiring configuring) to keep all this
machinery working.

As a result of these changes one need to explicitly specify the Makefile
in the build command:
| make -f Makefile.original <options>

Needed for tarantool/tarantool#4862

Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 Makefile => Makefile.original               | 44 +++++++++++++--------
 etc/{luajit.pc => luajit.pc.in}             |  4 +-
 src/{Makefile.dep => Makefile.dep.original} |  0
 src/{Makefile => Makefile.original}         |  4 +-
 tools/luajit-parse-memprof                  |  9 -----
 tools/luajit-parse-memprof.in               |  6 +++
 6 files changed, 38 insertions(+), 29 deletions(-)
 rename Makefile => Makefile.original (85%)
 rename etc/{luajit.pc => luajit.pc.in} (91%)
 rename src/{Makefile.dep => Makefile.dep.original} (100%)
 rename src/{Makefile => Makefile.original} (99%)
 delete mode 100755 tools/luajit-parse-memprof
 create mode 100644 tools/luajit-parse-memprof.in

diff --git a/Makefile b/Makefile.original
similarity index 85%
rename from Makefile
rename to Makefile.original
index 61967df..b85d4bf 100644
--- a/Makefile
+++ b/Makefile.original
@@ -85,10 +85,10 @@ INSTALL_X= install -m 0755
 INSTALL_F= install -m 0644
 UNINSTALL= $(RM)
 LDCONFIG= ldconfig -n
-SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
-            -e "s|^multilib=.*|multilib=$(MULTILIB)|"
-SED_TMEMPROF= sed -e "s|^TOOL_DIR=.*|TOOL_DIR=$(INSTALL_TOOLSLIB)|" \
-                  -e "s|^LUAJIT_BIN=.*|LUAJIT_BIN=$(INSTALL_T)|"
+SED_PC= sed -e "s|@LUAJIT_PC_PREFIX@|$(PREFIX)|" \
+            -e "s|@LUAJIT_PC_MULTILIB@|$(MULTILIB)|"
+SED_TMEMPROF= sed -e "s|@LUAJIT_TOOLS_DIR@|$(INSTALL_TOOLSLIB)|" \
+                  -e "s|@LUAJIT_TOOLS_BIN@|$(INSTALL_T)|"
 
 FILE_T= luajit
 FILE_A= libluajit.a
@@ -123,9 +123,9 @@ endif
 
 INSTALL_DEP= src/luajit
 
-default all $(INSTALL_DEP):
+default all $(INSTALL_DEP): tools
 	@echo "==== Building LuaJIT $(VERSION) ===="
-	$(MAKE) -C src
+	$(MAKE) -C src -f Makefile.original
 	@echo "==== Successfully built LuaJIT $(VERSION) ===="
 
 install: $(INSTALL_DEP)
@@ -140,17 +140,17 @@ install: $(INSTALL_DEP)
 	  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \
 	  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :
 	cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)
-	cd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \
-	  $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \
-	  $(RM) $(FILE_PC).tmp
+	cd etc && $(SED_PC) $(FILE_PC).in > $(FILE_PC) && \
+	  $(INSTALL_F) $(FILE_PC) $(INSTALL_PC) && \
+	  $(RM) $(FILE_PC)
 	cd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)
 	cd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)
 	cd tools/utils && $(INSTALL_F) $(FILES_UTILSLIB) $(INSTALL_UTILSLIB)
 	cd tools/memprof && $(INSTALL_F) $(FILES_MEMPROFLIB) $(INSTALL_MEMPROFLIB)
 	cd tools && $(INSTALL_F) $(FILES_TOOLSLIB) $(INSTALL_TOOLSLIB)
-	cd tools && $(SED_TMEMPROF) $(FILE_TMEMPROF) > $(FILE_TMEMPROF).tmp && \
-	  $(INSTALL_X) $(FILE_TMEMPROF).tmp $(INSTALL_TMEMPROF) && \
-	  $(RM) $(FILE_TMEMPROF).tmp
+	cd tools && $(SED_TMEMPROF) $(FILE_TMEMPROF).in > $(FILE_TMEMPROF) && \
+	  $(INSTALL_X) $(FILE_TMEMPROF) $(INSTALL_TMEMPROF) && \
+	  $(RM) $(FILE_TMEMPROF)
 	@echo "==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ===="
 	@echo ""
 	@echo "Note: the development releases deliberately do NOT install a symlink for luajit"
@@ -185,13 +185,25 @@ uninstall:
 
 ##############################################################################
 
-amalg:
+amalg: tools
 	@echo "Building LuaJIT $(VERSION)"
-	$(MAKE) -C src amalg
+	$(MAKE) -C src -f Makefile.original amalg
 
 clean:
-	$(MAKE) -C src clean
+	$(RM) tools/$(FILE_TMEMPROF)
+	$(MAKE) -C src -f Makefile.original clean
 
-.PHONY: all install amalg clean
+tools: tools/$(FILE_TMEMPROF)
+
+# FIXME: This is an ugly hack to manually configure an auxiliary
+# tools/luajit-parse-memprof. I hope this file will have gone away
+# in scope of https://github.com/tarantool/tarantool/issues/5688.
+tools/$(FILE_TMEMPROF):
+	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
+	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
+	     $@.in > $@
+	@chmod +x $@
+
+.PHONY: all install amalg clean tools
 
 ##############################################################################
diff --git a/etc/luajit.pc b/etc/luajit.pc.in
similarity index 91%
rename from etc/luajit.pc
rename to etc/luajit.pc.in
index a78f174..f32385d 100644
--- a/etc/luajit.pc
+++ b/etc/luajit.pc.in
@@ -5,8 +5,8 @@ relver=0
 version=${majver}.${minver}.${relver}-beta3
 abiver=5.1
 
-prefix=/usr/local
-multilib=lib
+prefix=@LUAJIT_PC_PREFIX@
+multilib=@LUAJIT_PC_MULTILIB@
 exec_prefix=${prefix}
 libdir=${exec_prefix}/${multilib}
 libname=luajit-${abiver}
diff --git a/src/Makefile.dep b/src/Makefile.dep.original
similarity index 100%
rename from src/Makefile.dep
rename to src/Makefile.dep.original
diff --git a/src/Makefile b/src/Makefile.original
similarity index 99%
rename from src/Makefile
rename to src/Makefile.original
index 825b01c..502504c 100644
--- a/src/Makefile
+++ b/src/Makefile.original
@@ -624,7 +624,7 @@ depend:
 	      -e "s|^\([^l ]\)|host/\1|" \
 	      -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
 	      -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
-	      -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
+	      -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep.original
 	@for file in $(ALL_HDRGEN); do \
 	  test -s $$file || $(HOST_RM) $$file; \
 	  done
@@ -699,7 +699,7 @@ $(HOST_O): %.o: %.c
 	$(E) "HOSTCC    $@"
 	$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
 
-include Makefile.dep
+include Makefile.dep.original
 
 ##############################################################################
 # Target file rules.
diff --git a/tools/luajit-parse-memprof b/tools/luajit-parse-memprof
deleted file mode 100755
index c814301..0000000
--- a/tools/luajit-parse-memprof
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-#
-# Launcher for memprof parser.
-
-# This two variables are replaced on installing.
-TOOL_DIR=$(dirname `readlink -f $0`)
-LUAJIT_BIN=$TOOL_DIR/../src/luajit
-
-LUA_PATH="$TOOL_DIR/?.lua;;" $LUAJIT_BIN $TOOL_DIR/memprof.lua $@
diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
new file mode 100644
index 0000000..8867202
--- /dev/null
+++ b/tools/luajit-parse-memprof.in
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+# Launcher for memprof parser.
+
+LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
+	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
@ 2021-02-02 20:57 ` Igor Munkin via Tarantool-patches
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
                     ` (2 more replies)
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake Igor Munkin via Tarantool-patches
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

In scope of this patch the LuaJIT build system is partially ported from
GNU Make to CMake. These changes provides CMake build system only for
the following OS: GNU/Linux, OSX, FreeBSD. For other platrforms use the
old build system (see the recipe in the previous commit).

Several components of the new build system such as automatic version
detection, source files list generation and some recipes for
CMakeLists.txt are taken verbatim or adapted from LuaVela repository.

Part of tarantool/tarantool#4862

Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 .gitignore                 |  12 +-
 CMakeLists.txt             | 261 +++++++++++++++++++++++++
 cmake/LuaJITUtils.cmake    |  31 +++
 cmake/MakeSourceList.cmake |  47 +++++
 cmake/SetDynASMFlags.cmake | 130 ++++++++++++
 cmake/SetTargetFlags.cmake |  42 ++++
 cmake/SetVersion.cmake     |  45 +++++
 etc/CMakeLists.txt         |  32 +++
 src/CMakeLists.txt         | 391 +++++++++++++++++++++++++++++++++++++
 src/host/CMakeLists.txt    |  61 ++++++
 tools/CMakeLists.txt       |  77 ++++++++
 11 files changed, 1128 insertions(+), 1 deletion(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 cmake/LuaJITUtils.cmake
 create mode 100644 cmake/MakeSourceList.cmake
 create mode 100644 cmake/SetDynASMFlags.cmake
 create mode 100644 cmake/SetTargetFlags.cmake
 create mode 100644 cmake/SetVersion.cmake
 create mode 100644 etc/CMakeLists.txt
 create mode 100644 src/CMakeLists.txt
 create mode 100644 src/host/CMakeLists.txt
 create mode 100644 tools/CMakeLists.txt

diff --git a/.gitignore b/.gitignore
index 1a07bf7..a21ee1c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 *.[oa]
-*.so
+*.so*
 *.obj
 *.lib
 *.exp
@@ -9,3 +9,13 @@
 *.dmp
 *.swp
 .tags
+
+# CMake generated artefacts
+CMakeCache.txt
+CMakeFiles
+Makefile
+cmake_install.cmake
+compile_commands.json
+install_manifest.txt
+luajit-parse-memprof
+luajit.pc
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..0dba5d8
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,261 @@
+# LuaJIT -- interpreter and JIT compiler for Lua language.
+# This is the main entry point for building, testing and
+# packaging the project.
+# Major portions taken verbatim or adapted from the uJIT.
+# Copyright (C) 2015-2019 IPONWEB Ltd.
+
+# --- Initial setup ------------------------------------------------------------
+
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+project(LuaJIT C)
+
+#
+# XXX: Originally CMake machinery is introduced to make LuaJIT
+# testing self-sufficient. Since there are only few systems
+# covered with the tests in our CI, there is no need to support
+# others for now and the original build system can be used.
+#
+
+if(NOT(
+   CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
+   CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
+   CMAKE_SYSTEM_NAME STREQUAL "FreeBSD"
+))
+  message(FATAL_ERROR
+    "Please use the old build system:\n\tmake -f Makefile.original <options>"
+  )
+endif()
+
+# --- Fine-tuning cmake environment --------------------------------------------
+
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+include(LuaJITUtils)
+include(SetVersion)
+
+# --- Variables to be exported to child scopes ---------------------------------
+
+SetVersion(
+  LUAJIT_VERSION
+  LUAJIT_VERSION_MAJOR
+  LUAJIT_VERSION_MINOR
+  LUAJIT_VERSION_PATCH
+  LUAJIT_VERSION_TWEAK
+  LUAJIT_PRERELEASE
+)
+
+set(LUAJIT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
+set(LUAJIT_BINARY_DIR "${PROJECT_BINARY_DIR}/src")
+
+# Names of the CLI binaries.
+set(LUAJIT_CLI_NAME "luajit")
+set(LUAJIT_LIB_NAME "luajit")
+
+# Specialized install paths.
+set(LUAJIT_DATAROOTDIR
+  share/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}.${LUAJIT_VERSION_PATCH}${LUAJIT_PRERELEASE}
+)
+set(LUAJIT_INCLUDEDIR
+  include/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}
+)
+
+set(BUILDMODE_VALUES mixed static dynamic)
+list(GET BUILDMODE_VALUES 0 BUILDMODE_DEFAULT)
+set(BUILDMODE ${BUILDMODE_DEFAULT} CACHE STRING
+  "Build mode. Choose one of the following: ${BUILDMODE_VALUES}."
+)
+set_property(CACHE BUILDMODE PROPERTY STRINGS ${BUILDMODE_VALUES})
+
+# Check that BUILDMODE value is correct.
+# FIXME: In CMake 3.5 we'll be able to use IN_LIST here.
+list(FIND BUILDMODE_VALUES ${BUILDMODE} BUILDMODE_INDEX)
+if(BUILDMODE_INDEX EQUAL -1)
+  message(FATAL_ERROR "BUILDMODE must be one of the following: ${BUILDMODE_VALUES}.")
+endif()
+
+# --- Compilation flags setup --------------------------------------------------
+
+if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
+  AppendFlags(TARGET_C_FLAGS -DLUA_ROOT='"${CMAKE_INSTALL_PREFIX}"')
+endif()
+
+if(CMAKE_LIBRARY_ARCHITECTURE)
+  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
+endif()
+
+# Since the assembler part does NOT maintain a frame pointer, it's
+# pointless to slow down the C part by not omitting it. Debugging,
+# tracebacks and unwinding are not affected -- the assembler part
+# has frame unwind information and GCC emits it where needed (x64)
+# or with -g.
+AppendFlags(CMAKE_C_FLAGS -fomit-frame-pointer -fno-stack-protector)
+
+# Re-defined to benefit from expanding macros in gdb.
+set(CMAKE_C_FLAGS_DEBUG "-g -ggdb3")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g -ggdb3")
+# Re-defined since default cmake release optimization level is O3.
+set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+
+AppendFlags(CMAKE_C_FLAGS -Wall)
+option(LUAJIT_ENABLE_WARNINGS "Build LuaJIT with warnings enabled" OFF)
+if(LUAJIT_ENABLE_WARNINGS)
+  AppendFlags(CMAKE_C_FLAGS
+    -Wextra
+    -Wdeclaration-after-statement
+    -Wpointer-arith
+    -Wredundant-decls
+    -Wshadow
+  )
+endif()
+
+# Auxilary flags for main targets (libraries, binaries).
+AppendFlags(TARGET_C_FLAGS
+  -D_FILE_OFFSET_BITS=64
+  -D_LARGEFILE_SOURCE
+  -U_FORTIFY_SOURCE
+)
+
+# Permanently disable the FFI extension to reduce the size of the
+# LuaJIT executable. But please consider that the FFI library is
+# compiled-in, but NOT loaded by default. It only allocates any
+# memory, if you actually make use of it.
+option(LUAJIT_DISABLE_FFI "FFI support" OFF)
+if(LUAJIT_DISABLE_FFI)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_FFI)
+endif()
+set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI)
+
+# Features from Lua 5.2 that are unlikely to break existing code
+# are enabled by default. Some other features that *might* break
+# some existing code (e.g. __pairs or os.execute() return values)
+# can be enabled here.
+# XXX: this does not provide full compatibility with Lua 5.2 at
+# this time.
+option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
+if(LUAJIT_LUA52COMPAT)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT)
+endif()
+
+# Disable the JIT compiler, i.e. turn LuaJIT into a pure
+# interpreter.
+option(LUAJIT_DISABLE_JIT "JIT support" OFF)
+if(LUAJIT_DISABLE_JIT)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_JIT)
+endif()
+set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT)
+
+# Some architectures (e.g. PPC) can use either single-number (1)
+# or dual-number (2) mode. Uncomment one of these lines to
+# override the default mode. Please see LJ_ARCH_NUMMODE in
+# lj_arch.h for details.
+set(LUAJIT_NUMMODE_VALUES 1 2)
+set(LUAJIT_NUMMODE_DEFAULT "")
+set(LUAJIT_NUMMODE ${LUAJIT_NUMMODE_DEFAULT} CACHE STRING
+  "Switch to single-number or dual-number mode."
+)
+# XXX: explicitly added empty string allows to disable this flag
+# in GUI.
+set_property(CACHE LUAJIT_NUMMODE PROPERTY STRINGS
+  ${LUAJIT_NUMMODE_DEFAULT} ${LUAJIT_NUMMODE_VALUES}
+)
+
+if(NOT LUAJIT_NUMMODE STREQUAL LUAJIT_NUMMODE_DEFAULT)
+  # Check that LUAJIT_NUMMODE value is correct.
+  # FIXME: In CMake 3.5 we'll be able to use IN_LIST here.
+  list(FIND LUAJIT_NUMMODE_VALUES ${LUAJIT_NUMMODE} LUAJIT_NUMMODE_INDEX)
+  if(LUAJIT_NUMMODE_INDEX EQUAL -1)
+    message(FATAL_ERROR "LUAJIT_NUMMODE must be '1' for single-number mode or '2' for dual-number mode.")
+  endif()
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_NUMMODE=${LUAJIT_NUMMODE})
+endif()
+
+# Enable GC64 mode for x64.
+option(LUAJIT_ENABLE_GC64 "GC64 mode for x64" OFF)
+if(LUAJIT_ENABLE_GC64)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_GC64)
+endif()
+
+# Disable memory profiler.
+option(LUAJIT_DISABLE_MEMPROF "LuaJIT memory profiler support" OFF)
+if(LUAJIT_DISABLE_MEMPROF)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_MEMPROF)
+endif()
+
+# Switch to harder (and slower) hash function when a collision
+# chain in the string hash table exceeds certain length.
+option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON)
+if(LUAJIT_SMART_STRINGS)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1)
+endif()
+
+# XXX: Note that most of the options below are NOT suitable for
+# benchmarking or release mode!
+
+# Use the system provided memory allocator (realloc) instead of
+# the bundled memory allocator. This is slower, but sometimes
+# helpful for debugging. This option cannot be enabled on x64
+# without GC64, since realloc usually doesn't return addresses in
+# the right address range. OTOH this option is mandatory for
+# Valgrind's memcheck tool on x64 and the only way to get useful
+# results from it for all other architectures.
+option(LUAJIT_USE_SYSMALLOC "System provided memory allocator (realloc)" OFF)
+if(LUAJIT_USE_SYSMALLOC)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_SYSMALLOC)
+endif()
+
+# This define is required to run LuaJIT under Valgrind. The
+# Valgrind header files must be installed. You should enable debug
+# information, too. Use --suppressions=lj.supp to avoid some false
+# positives.
+option(LUAJIT_USE_VALGRIND "Valgrind support" OFF)
+if(LUAJIT_USE_VALGRIND)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_VALGRIND)
+endif()
+
+# This is the client for the GDB JIT API. GDB 7.0 or higher is
+# required to make use of it. See lj_gdbjit.c for details.
+# Enabling this causes a non-negligible overhead, even when not
+# running under GDB.
+option(LUAJIT_USE_GDBJIT "GDB JIT support" OFF)
+if(LUAJIT_USE_GDBJIT)
+  AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_GDBJIT)
+endif()
+
+# Turn on assertions for the Lua/C API to debug problems with
+# lua_* calls. This is rather slow -- use only while developing C
+# libraries/embeddings.
+option(LUAJIT_USE_APICHECK "Assertions for the Lua/C API" OFF)
+if(LUAJIT_USE_APICHECK)
+  AppendFlags(TARGET_C_FLAGS -DLUA_USE_APICHECK)
+endif()
+
+# Turn on assertions for the whole LuaJIT VM. This significantly
+# slows down everything. Use only if you suspect a problem with
+# LuaJIT itself.
+option(LUAJIT_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF)
+if(LUAJIT_USE_ASSERT)
+  AppendFlags(TARGET_C_FLAGS -DLUA_USE_ASSERT)
+endif()
+
+# TODO: Implement a configuration option to enable ASAN.
+# There are two entries of LUAJIT_USE_ASAN define:
+# $ grep -rnF 'LUAJIT_USE_ASAN' .
+# ./src/lj_str.c:15:#if LUAJIT_USE_ASAN
+# ./src/host/buildvm.c:36:#if LUAJIT_USE_ASAN
+# At the same time this flag is not provided by LuaJIT original
+# build system (i.e. src/Makefile.original) so there are no
+# related compiler and linker flags passed. This should be done
+# the right way later.
+
+# --- Main source tree ---------------------------------------------------------
+
+add_subdirectory(src)
+
+# --- Auxiliary files ----------------------------------------------------------
+
+add_subdirectory(etc)
+
+# --- Tools --------------------------------------------------------------------
+
+add_subdirectory(tools)
diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
new file mode 100644
index 0000000..faaef6b
--- /dev/null
+++ b/cmake/LuaJITUtils.cmake
@@ -0,0 +1,31 @@
+function(LuaJITTestArch outvar strflags)
+  # XXX: <execute_process> simply splits the COMMAND argument by
+  # spaces with no further parsing. At the same time GCC is bad in
+  # argument handling, so let's help it a bit.
+  separate_arguments(TEST_C_FLAGS UNIX_COMMAND ${strflags})
+  execute_process(
+    COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM
+    WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
+    OUTPUT_VARIABLE TESTARCH
+  )
+  set(${outvar} ${TESTARCH} PARENT_SCOPE)
+endfunction()
+
+function(LuaJITArch outvar testarch)
+  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)
+    string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
+    if(FOUND EQUAL -1)
+      continue()
+    endif()
+    string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
+    set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
+    return()
+  endforeach()
+  message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture")
+endfunction()
+
+macro(AppendFlags flags)
+  foreach(flag ${ARGN})
+    set(${flags} "${${flags}} ${flag}")
+  endforeach()
+endmacro()
diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake
new file mode 100644
index 0000000..fa455bb
--- /dev/null
+++ b/cmake/MakeSourceList.cmake
@@ -0,0 +1,47 @@
+# Major portions taken verbatim or adapted from the uJIT.
+# Copyright (C) 2015-2019 IPONWEB Ltd.
+#
+# make_source_list provides a convenient way to define a list of sources
+# and get a list of absolute paths.
+#
+# Example usage:
+#
+#   make_source_list(SOURCES_CORE
+#     SOURCES
+#       main.c
+#       test.c
+#       subdir/test2.c
+#   )
+#
+# This will give you the list:
+#    "<...>/main.c;<...>/test.c;<...>/subdir/test2.c"
+# (where `<...>` is ${CMAKE_CURRENT_SOURCE_DIR}).
+#
+# Absolute paths in `SOURCES` list don't get ${CMAKE_CURRENT_SOURCE_DIR}
+# prepended to them.
+
+function(make_source_list list)
+  set(prefix ARG)
+  set(noValues)
+  set(singleValues)
+  set(multiValues SOURCES)
+
+  include(CMakeParseArguments) # if we update to CMake >= 3.5, can remove this line
+  cmake_parse_arguments(${prefix}
+                        "${noValues}"
+                        "${singleValues}"
+                        "${multiValues}"
+                        ${ARGN})
+
+  set(result_list "")
+
+  foreach(fn ${ARG_SOURCES})
+    if (IS_ABSOLUTE ${fn})
+      list(APPEND result_list "${fn}")
+    else()
+      list(APPEND result_list "${CMAKE_CURRENT_SOURCE_DIR}/${fn}")
+    endif()
+  endforeach()
+
+  set(${list} "${result_list}" PARENT_SCOPE)
+endfunction()
diff --git a/cmake/SetDynASMFlags.cmake b/cmake/SetDynASMFlags.cmake
new file mode 100644
index 0000000..9a920c3
--- /dev/null
+++ b/cmake/SetDynASMFlags.cmake
@@ -0,0 +1,130 @@
+# This module exposes following variables to the project:
+# * HOST_C_FLAGS
+# * DYNASM_ARCH
+# * DYNASM_FLAGS
+
+# XXX: buildvm includes core headers and thus has to be built
+# with the same flags and defines as the LuaJIT core itself.
+set(HOST_C_FLAGS)
+set(DYNASM_ARCH)
+set(DYNASM_FLAGS)
+
+LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS} ${HOST_CFLAGS}")
+LuaJITArch(LUAJIT_ARCH "${TESTARCH}")
+AppendFlags(HOST_C_FLAGS -DLUAJIT_TARGET=LUAJIT_ARCH_${LUAJIT_ARCH})
+
+# XXX: LUAJIT_ARCH equals to DYNASM_ARCH for the most case but
+# there are few exceptions to the rule.
+if(LUAJIT_ARCH STREQUAL "x64")
+  string(FIND "${TESTARCH}" "LJ_FR2 1" FOUND)
+  if(FOUND EQUAL -1)
+    set(DYNASM_ARCH x86)
+  else()
+    set(DYNASM_ARCH x64)
+  endif()
+elseif(LUAJIT_ARCH STREQUAL "ppc")
+  string(FIND "${TESTARCH}" "LJ_ARCH_PPC64" FOUND)
+  if(FOUND EQUAL -1)
+    set(DYNASM_ARCH ppc)
+  else()
+    set(DYNASM_ARCH ppc64)
+  endif()
+else()
+  set(DYNASM_ARCH ${LUAJIT_ARCH})
+endif()
+
+if(LUAJIT_ARCH STREQUAL "arm64")
+  string(FIND "${TESTARCH}" "__AARCH64EB__" FOUND)
+  if(NOT FOUND EQUAL -1)
+    AppendFlags(HOST_C_FLAGS -D__AARCH64EB__=1)
+  endif()
+elseif(LUAJIT_ARCH STREQUAL "ppc")
+  string(FIND "${TESTARCH}" "LJ_LE 1" FOUND)
+  if(NOT FOUND EQUAL -1)
+    AppendFlags(HOST_C_FLAGS -DLJ_ARCH_ENDIAN=LUAJIT_LE)
+  else()
+    AppendFlags(HOST_C_FLAGS -DLJ_ARCH_ENDIAN=LUAJIT_BE)
+  endif()
+  string(FIND "${TESTARCH}" "LJ_ARCH_SQRT 1" FOUND)
+  if(NOT FOUND EQUAL -1)
+    list(APPEND DYNASM_FLAGS -D SQRT)
+  endif()
+  string(FIND "${TESTARCH}" "LJ_ARCH_ROUND 1" FOUND)
+  if(NOT FOUND EQUAL -1)
+    list(APPEND DYNASM_FLAGS -D ROUND)
+  endif()
+  string(FIND "${TESTARCH}" "LJ_ARCH_PPC32ON64 1" FOUND)
+  if(NOT FOUND EQUAL -1)
+    list(APPEND DYNASM_FLAGS -D GPR64)
+  endif()
+elseif(LUAJIT_ARCH STREQUAL "mips")
+  string(FIND "${TESTARCH}" "MIPSEL" FOUND)
+  if(NOT FOUND EQUAL -1)
+    AppendFlags(HOST_C_FLAGS -D__MIPSEL__=1)
+  endif()
+endif()
+
+string(FIND "${TESTARCH}" "LJ_LE 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D ENDIAN_LE)
+else()
+  list(APPEND DYNASM_FLAGS -D ENDIAN_BE)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_ARCH_BITS 64" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D P64)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_HASJIT 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D JIT)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_HASFFI 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D FFI)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_DUALNUM 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D DUALNUM)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_ARCH_HASFPU 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D FPU)
+  AppendFlags(HOST_C_FLAGS -DLJ_ARCH_HASFPU=1)
+else()
+  AppendFlags(HOST_C_FLAGS -DLJ_ARCH_HASFPU=0)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_ABI_SOFTFP 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  AppendFlags(HOST_C_FLAGS -DLJ_ABI_SOFTFP=1)
+else()
+  list(APPEND DYNASM_FLAGS -D HFABI)
+  AppendFlags(HOST_C_FLAGS -DLJ_ABI_SOFTFP=0)
+endif()
+
+string(FIND "${TESTARCH}" "LJ_NO_UNWIND 1" FOUND)
+if(NOT FOUND EQUAL -1)
+  list(APPEND DYNASM_FLAGS -D NO_UNWIND)
+  AppendFlags(HOST_C_FLAGS -DLUAJIT_NO_UNWIND)
+endif()
+
+string(REGEX MATCH "LJ_ARCH_VERSION ([0-9]+)" LUAJIT_ARCH_VERSION ${TESTARCH})
+list(APPEND DYNASM_FLAGS -D VER=${CMAKE_MATCH_1})
+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
+  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_OSX)
+  elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_LINUX)
+  else() # FreeBSD.
+    AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_OTHER)
+  endif()
+endif()
+
+unset(LUAJIT_ARCH)
+unset(TESTARCH)
diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
new file mode 100644
index 0000000..260fc6b
--- /dev/null
+++ b/cmake/SetTargetFlags.cmake
@@ -0,0 +1,42 @@
+# This module exposes following variables to the project:
+# * BUILDVM_MODE
+# * TARGET_C_FLAGS
+# * TARGET_VM_FLAGS
+# * TARGET_BIN_FLAGS
+# * TARGET_SHARED_FLAGS
+# * TARGET_LIBS
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  set(BUILDVM_MODE machasm)
+else() # Linux and FreeBSD.
+  set(BUILDVM_MODE elfasm)
+endif()
+
+LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS}")
+LuaJITArch(LUAJIT_ARCH "${TESTARCH}")
+
+# Target-specific compiler options.
+#
+# x86/x64 only: For GCC 4.2 or higher and if you don't intend to
+# distribute the binaries to a different machine you could also
+# use: -march=native.
+if(LUAJIT_ARCH STREQUAL "x86")
+  AppendFlags(TARGET_C_FLAGS -march=i686 -msse -msse2 -mfpmath=sse)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  if(LUAJIT_ARCH STREQUAL "x64")
+    AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)
+    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
+  endif()
+  AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)
+else() # Linux and FreeBSD.
+  AppendFlags(TARGET_BIN_FLAGS -Wl,-E)
+  list(APPEND TARGET_LIBS dl)
+endif()
+
+# Auxilary flags for the VM core.
+# XXX: ASAN-related build flags are stored in CMAKE_C_FLAGS.
+set(TARGET_VM_FLAGS "${CMAKE_C_FLAGS} ${TARGET_C_FLAGS}")
+
+unset(TESTARCH)
diff --git a/cmake/SetVersion.cmake b/cmake/SetVersion.cmake
new file mode 100644
index 0000000..3f0247c
--- /dev/null
+++ b/cmake/SetVersion.cmake
@@ -0,0 +1,45 @@
+# Find, check and set LuaJIT's version from a VCS tag.
+# Major portions taken verbatim or adapted from the uJIT.
+# Copyright (C) 2015-2019 IPONWEB Ltd.
+
+function(SetVersion version majver minver patchver tweakver prerel)
+  find_package(Git QUIET REQUIRED)
+  if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND Git_FOUND)
+    # Read version from the project's VCS and store the result
+    # into version.
+    execute_process(
+      COMMAND ${GIT_EXECUTABLE} describe
+      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+      OUTPUT_VARIABLE vcs_tag)
+    string(STRIP "${vcs_tag}" vcs_tag)
+    message(STATUS "[SetVersion] Reading version from VCS: ${vcs_tag}")
+  else()
+    # Use default version since no git is found in the system or
+    # VCS directory is not found in repo root directory.
+    set(vcs_tag "v2.1.0-beta3-0-g0000000")
+    message(STATUS "[SetVersion] No VCS found, use default version: ${vcs_tag}")
+  endif()
+
+  set(${version} ${vcs_tag} PARENT_SCOPE)
+
+  # Match version_string against the version regex.
+  # Throw an error if it does not match. Otherwise populates
+  # variables:
+  # * majver:   First version number.
+  # * minver:   Second version number.
+  # * patchver: Third version number.
+  # * prerel:   Optional prerelease suffix.
+  # * tweakver: Fourth version number.
+  # Valid version examples:
+  # * v2.0.4-48-gfcc8244
+  # * v2.1.0-beta3-57-g2973518
+  if(vcs_tag MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(-(rc|beta)[0-9]+)?-([0-9]+)-g[0-9a-z]+$")
+    set(${majver}   ${CMAKE_MATCH_1} PARENT_SCOPE)
+    set(${minver}   ${CMAKE_MATCH_2} PARENT_SCOPE)
+    set(${patchver} ${CMAKE_MATCH_3} PARENT_SCOPE)
+    set(${tweakver} ${CMAKE_MATCH_6} PARENT_SCOPE)
+    set(${prerel}   ${CMAKE_MATCH_4} PARENT_SCOPE)
+  else()
+    message(FATAL_ERROR "[SetVersion] Malformed version string '${vcs_tag}'")
+  endif()
+endfunction()
diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
new file mode 100644
index 0000000..4a4c3cd
--- /dev/null
+++ b/etc/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Building supplementary materials for LuaJIT.
+
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+
+set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
+if(CMAKE_LIBRARY_ARCHITECTURE)
+  set(LUAJIT_PC_MULTILIB "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
+else()
+  set(LUAJIT_PC_MULTILIB "lib")
+endif()
+
+configure_file(luajit.pc.in luajit.pc @ONLY ESCAPE_QUOTES)
+
+install(FILES
+    luajit.1
+  DESTINATION share/man/man1
+  PERMISSIONS
+    OWNER_READ OWNER_WRITE
+    GROUP_READ
+    WORLD_READ
+  COMPONENT luajit
+)
+
+install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/luajit.pc
+  DESTINATION lib/pkgconfig
+  PERMISSIONS
+    OWNER_READ OWNER_WRITE
+    GROUP_READ
+    WORLD_READ
+  COMPONENT luajit
+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..8ada1a4
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,391 @@
+# Building LuaJIT core: bootstrapping, VM, runtime, JIT compiler.
+# Major portions taken verbatim or adapted from the uJIT.
+# Copyright (C) 2015-2019 IPONWEB Ltd.
+
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+
+enable_language(ASM)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+include(MakeSourceList)
+
+# --- Define source tree -------------------------------------------------------
+
+# Core runtime.
+make_source_list(SOURCES_RUNTIME
+  SOURCES
+    lj_api.c
+    lj_bc.c
+    lj_buf.c
+    lj_debug.c
+    lj_dispatch.c
+    lj_err.c
+    lj_func.c
+    lj_gc.c
+    lj_lib.c
+    lj_load.c
+    lj_mapi.c
+    lj_meta.c
+    lj_obj.c
+    lj_state.c
+    lj_str.c
+    lj_strfmt.c
+    lj_strfmt_num.c
+    lj_strscan.c
+    lj_tab.c
+    lj_udata.c
+    lj_vmevent.c
+    lib_aux.c
+    lib_init.c
+)
+
+# Lua frontend.
+make_source_list(SOURCES_FRONTEND
+  SOURCES
+    lj_bcread.c
+    lj_bcwrite.c
+    lj_lex.c
+    lj_parse.c
+)
+
+make_source_list(SOURCES_UTILS
+  SOURCES
+    lj_alloc.c
+    lj_char.c
+    lj_utils_leb128.c
+    lj_vmmath.c
+    lj_wbuf.c
+)
+
+make_source_list(SOURCES_PROFILER
+  SOURCES
+    lj_memprof.c
+    lj_profile.c
+)
+
+# Lua standard library + extensions by LuaJIT.
+make_source_list(SOURCES_LUA_LIB
+  # XXX: Please do not changes the order of the libraries
+  # (required by buildvm).
+  SOURCES
+    lib_base.c
+    lib_math.c
+    lib_bit.c
+    lib_string.c
+    lib_table.c
+    lib_io.c
+    lib_os.c
+    lib_package.c
+    lib_debug.c
+    lib_jit.c
+    lib_ffi.c
+    lib_misc.c
+)
+
+# JIT compiler, core part.
+make_source_list(SOURCES_JIT_CORE
+  SOURCES
+    lj_asm.c
+    lj_ffrecord.c
+    lj_ir.c
+    lj_mcode.c
+    lj_record.c
+    lj_snap.c
+    lj_trace.c
+)
+
+# JIT compiler, machine-independent optimisations.
+make_source_list(SOURCES_JIT_OPT
+  SOURCES
+    lj_opt_dce.c
+    lj_opt_fold.c
+    lj_opt_loop.c
+    lj_opt_mem.c
+    lj_opt_narrow.c
+    lj_opt_sink.c
+    lj_opt_split.c
+)
+
+make_source_list(SOURCES_FFI
+  SOURCES
+    lj_carith.c
+    lj_ccallback.c
+    lj_ccall.c
+    lj_cconv.c
+    lj_cdata.c
+    lj_clib.c
+    lj_cparse.c
+    lj_crecord.c
+    lj_ctype.c
+)
+
+make_source_list(SOURCES_JIT
+  SOURCES
+    ${SOURCES_JIT_CORE}
+    ${SOURCES_JIT_OPT}
+)
+
+# Everything except FFI and JIT.
+make_source_list(SOURCES_CORE_NO_JIT_FFI
+  SOURCES
+    ${SOURCES_RUNTIME}
+    ${SOURCES_LUA_LIB}
+    ${SOURCES_FRONTEND}
+    ${SOURCES_PROFILER}
+    ${SOURCES_UTILS}
+)
+
+set(SOURCES_CORE ${SOURCES_CORE_NO_JIT_FFI})
+
+if(LUAJIT_HAS_JIT)
+  list(APPEND SOURCES_CORE ${SOURCES_JIT})
+  if(LUAJIT_ENABLE_GDBJIT)
+    list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_gdbjit.c)
+  endif()
+endif()
+
+if(LUAJIT_HAS_FFI)
+  list(APPEND SOURCES_CORE ${SOURCES_FFI})
+  if(NOT LUAJIT_HAS_JIT)
+    # Needed for lj_mcode_sync.
+    list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_mcode.c)
+  endif()
+endif()
+
+make_source_list(CLI_SOURCES
+  SOURCES
+    luajit.c
+)
+
+# --- Set OS and arch specific flags -------------------------------------------
+
+include(SetTargetFlags)
+list(APPEND TARGET_LIBS m)
+
+# --- Prepare files generated by buildvm ---------------------------------------
+
+add_subdirectory(host)
+
+# VM assembly.
+add_custom_command(
+  OUTPUT lj_vm.S
+  COMMAND $<TARGET_FILE:buildvm> -m ${BUILDVM_MODE} -o lj_vm.S
+  DEPENDS buildvm
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Bytecode definitions.
+add_custom_command(
+  OUTPUT lj_bcdef.h
+  COMMAND $<TARGET_FILE:buildvm> -m bcdef -o lj_bcdef.h ${SOURCES_LUA_LIB}
+  DEPENDS buildvm ${SOURCES_LUA_LIB}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Fast function definitions.
+add_custom_command(
+  OUTPUT lj_ffdef.h
+  COMMAND $<TARGET_FILE:buildvm> -m ffdef -o lj_ffdef.h ${SOURCES_LUA_LIB}
+  DEPENDS buildvm ${SOURCES_LUA_LIB}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Library definitions.
+add_custom_command(
+  OUTPUT lj_libdef.h
+  COMMAND $<TARGET_FILE:buildvm> -m libdef -o lj_libdef.h ${SOURCES_LUA_LIB}
+  DEPENDS buildvm ${SOURCES_LUA_LIB}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Recorder definitions.
+add_custom_command(
+  OUTPUT lj_recdef.h
+  COMMAND $<TARGET_FILE:buildvm> -m recdef -o lj_recdef.h ${SOURCES_LUA_LIB}
+  DEPENDS buildvm ${SOURCES_LUA_LIB}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# Fold definitions.
+add_custom_command(
+  OUTPUT lj_folddef.h
+  COMMAND $<TARGET_FILE:buildvm> -m folddef -o lj_folddef.h
+          ${CMAKE_CURRENT_SOURCE_DIR}/lj_opt_fold.c
+  DEPENDS buildvm lj_opt_fold.c
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# VM definitions.
+add_custom_command(
+  OUTPUT jit/vmdef.lua
+  COMMAND ${CMAKE_COMMAND} -E make_directory jit
+  COMMAND $<TARGET_FILE:buildvm> -m vmdef -o jit/vmdef.lua ${SOURCES_LUA_LIB}
+  DEPENDS buildvm ${SOURCES_LUA_LIB}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_custom_target(
+  buildvm_output
+  DEPENDS lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
+          jit/vmdef.lua
+)
+
+# --- Generate core and VM object files ---------------------------------------
+
+# Virtual machine.
+add_library(vm_static OBJECT EXCLUDE_FROM_ALL lj_vm.S)
+add_library(vm_shared OBJECT EXCLUDE_FROM_ALL lj_vm.S)
+set_property(TARGET vm_shared APPEND PROPERTY
+  POSITION_INDEPENDENT_CODE ON
+)
+set_property(TARGET vm_static vm_shared APPEND PROPERTY
+  COMPILE_FLAGS "${TARGET_VM_FLAGS}"
+)
+
+# Platform core.
+add_library(core_static OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE})
+add_library(core_shared OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE})
+set_property(TARGET core_shared APPEND PROPERTY
+  POSITION_INDEPENDENT_CODE ON
+)
+set_property(TARGET core_static core_shared APPEND PROPERTY
+  COMPILE_FLAGS "${TARGET_C_FLAGS}"
+)
+target_include_directories(core_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(core_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+add_dependencies(core_static buildvm_output)
+add_dependencies(core_shared buildvm_output)
+
+# --- Generate output ----------------------------------------------------------
+
+# Compiling and linking library binaries (static, shared).
+
+set(LIB_OBJECTS_STATIC
+  $<TARGET_OBJECTS:vm_static>
+  $<TARGET_OBJECTS:core_static>
+)
+set(LIB_OBJECTS_SHARED
+  $<TARGET_OBJECTS:vm_shared>
+  $<TARGET_OBJECTS:core_shared>
+)
+
+add_library(libluajit_static STATIC EXCLUDE_FROM_ALL ${LIB_OBJECTS_STATIC})
+set_target_properties(libluajit_static PROPERTIES
+  OUTPUT_NAME "${LUAJIT_LIB_NAME}"
+  COMPILE_FLAGS "${TARGET_C_FLAGS}"
+  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+target_link_libraries(libluajit_static m)
+
+add_library(libluajit_shared SHARED EXCLUDE_FROM_ALL ${LIB_OBJECTS_SHARED})
+set_target_properties(libluajit_shared PROPERTIES
+  OUTPUT_NAME "${LUAJIT_LIB_NAME}"
+  COMPILE_FLAGS "${TARGET_C_FLAGS}"
+  LINK_FLAGS "${TARGET_SHARED_FLAGS}"
+  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+  VERSION "${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}.${LUAJIT_VERSION_PATCH}"
+  SOVERSION "${LUAJIT_VERSION_MAJOR}"
+)
+target_link_libraries(libluajit_shared ${TARGET_LIBS})
+
+# Compiling and linking CLIs.
+
+add_executable(luajit_static EXCLUDE_FROM_ALL ${CLI_SOURCES})
+set_target_properties(luajit_static PROPERTIES
+  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
+  COMPILE_FLAGS "${TARGET_C_FLAGS}"
+  LINK_FLAGS "${TARGET_BIN_FLAGS}"
+  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+target_include_directories(luajit_static PRIVATE
+  ${CMAKE_CURRENT_BINARY_DIR}
+)
+target_link_libraries(luajit_static libluajit_static ${TARGET_LIBS})
+
+add_executable(luajit_shared EXCLUDE_FROM_ALL ${CLI_SOURCES})
+set_target_properties(luajit_shared PROPERTIES
+  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
+  COMPILE_FLAGS "${TARGET_C_FLAGS}"
+  LINK_FLAGS "${TARGET_BIN_FLAGS}"
+  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+target_include_directories(luajit_shared PRIVATE
+  ${CMAKE_CURRENT_BINARY_DIR}
+)
+target_link_libraries(luajit_shared libluajit_shared ${TARGET_LIBS})
+
+if(NOT BUILDMODE STREQUAL "dynamic")
+  set(LIBLUAJIT_STATIC_DEPS libluajit_static)
+endif()
+if(NOT BUILDMODE STREQUAL "static")
+  set(LIBLUAJIT_SHARED_DEPS libluajit_shared)
+endif()
+set(LIBLUAJIT_DEPS ${LIBLUAJIT_STATIC_DEPS} ${LIBLUAJIT_SHARED_DEPS})
+
+if(BUILDMODE STREQUAL "dynamic")
+  set(LUAJIT_DEPS luajit_shared)
+else()
+  set(LUAJIT_DEPS luajit_static)
+endif()
+
+add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
+add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
+
+install(TARGETS ${LUAJIT_DEPS}
+  RUNTIME
+  DESTINATION bin
+  COMPONENT luajit
+)
+install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
+  ARCHIVE
+  DESTINATION lib
+  COMPONENT luajit
+)
+install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
+  LIBRARY
+  DESTINATION lib
+  COMPONENT luajit
+)
+
+install(FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/lua.h       # C API for Lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/lualib.h    # Lua standard libraries
+    ${CMAKE_CURRENT_SOURCE_DIR}/lauxlib.h   # Auxiliary library's C API
+    ${CMAKE_CURRENT_SOURCE_DIR}/luaconf.h   # Configuration header
+    ${CMAKE_CURRENT_SOURCE_DIR}/lua.hpp     # Convenience wrapper for C++
+    ${CMAKE_CURRENT_SOURCE_DIR}/luajit.h    # LuaJIT-specific header
+    ${CMAKE_CURRENT_SOURCE_DIR}/lmisclib.h  # Miscellaneous C API extensions
+  DESTINATION ${LUAJIT_INCLUDEDIR}
+  PERMISSIONS
+    OWNER_READ OWNER_WRITE
+    GROUP_READ
+    WORLD_READ
+  COMPONENT luajit
+)
+
+install(FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bc.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bcsave.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dump.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/p.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/v.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/zone.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x86.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x64.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64be.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_ppc.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mipsel.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64.lua
+    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64el.lua
+    ${CMAKE_CURRENT_BINARY_DIR}/jit/vmdef.lua
+  DESTINATION ${LUAJIT_DATAROOTDIR}/jit
+  PERMISSIONS
+    OWNER_READ OWNER_WRITE
+    GROUP_READ
+    WORLD_READ
+  COMPONENT luajit
+)
diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
new file mode 100644
index 0000000..fe2de5c
--- /dev/null
+++ b/src/host/CMakeLists.txt
@@ -0,0 +1,61 @@
+# Building the toolchain for LuaJIT VM preprocessing.
+
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+
+# FIXME: Both minilua and buildvm need to be build with the HOST_*
+# toolchain.
+
+# XXX: DynASM flags are set considering the target arch
+include(SetDynASMFlags)
+
+# --- Build minilua ------------------------------------------------------------
+
+# If left blank, minilua is built and used. You can supply an installed
+# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua.
+if(NOT HOST_LUA)
+  set(MINILUA minilua)
+  add_executable(${MINILUA} minilua.c)
+  target_link_libraries(${MINILUA} m)
+  set(HOST_LUA $<TARGET_FILE:${MINILUA}>)
+else()
+  separate_arguments(HOST_LUA UNIX_COMMAND ${HOST_LUA})
+endif()
+
+# --- Prepare dasm-ed VM description -------------------------------------------
+
+set(DYNASM_DIR ${PROJECT_SOURCE_DIR}/dynasm)
+set(DYNASM_DASC "${LUAJIT_SOURCE_DIR}/vm_${DYNASM_ARCH}.dasc")
+set(DYNASM ${HOST_LUA} ${DYNASM_DIR}/dynasm.lua)
+
+add_custom_command(
+  COMMENT "Generating buildvm_arch.h"
+  OUTPUT buildvm_arch.h
+  COMMAND ${DYNASM} ${DYNASM_FLAGS} -o buildvm_arch.h ${DYNASM_DASC}
+  DEPENDS ${MINILUA} ${DYNASM_DASC} ${DYNASM_DIR}/*.lua
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# --- Build buildvm ------------------------------------------------------------
+
+add_executable(buildvm EXCLUDE_FROM_ALL
+  buildvm.c
+  buildvm_asm.c
+  buildvm_fold.c
+  buildvm_lib.c
+  buildvm_peobj.c
+  # XXX: Unfortunately CMake is a crap. I failed to specify
+  # autogenerated host/buildvm_arch.h as a dependency for
+  # host/buildvm.c, so I simply explicitly mentioned it in this
+  # *sources* list.
+  buildvm_arch.h
+)
+set_source_files_properties(buildvm.c PROPERTIES
+  OBJECT_DEPENDS ${DYNASM_DIR}/dasm_*.h
+)
+set_target_properties(buildvm PROPERTIES
+  COMPILE_FLAGS "${HOST_C_FLAGS} ${TARGET_C_FLAGS}"
+)
+target_include_directories(buildvm PRIVATE
+  ${LUAJIT_BINARY_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}
+)
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 0000000..f9ffc5e
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1,77 @@
+# Building tools for developing with uJIT.
+# Major portions taken verbatim or adapted from the uJIT.
+# Copyright (C) 2015-2019 IPONWEB Ltd.
+
+# See the rationale in the root CMakeLists.txt
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+set(LUAJIT_TOOLS_DEPS)
+
+if(LUAJIT_DISABLE_MEMPROF)
+  message(STATUS "LuaJIT memory profiler support is disabled")
+else()
+  # XXX: Can use genex here since the value need to be evaluated
+  # on the configuration phase. Fortunately, we know the exact
+  # path where LuaJIT binary is located.
+  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
+  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
+
+  add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS
+    luajit-parse-memprof
+    memprof/humanize.lua
+    memprof/parse.lua
+    memprof.lua
+    utils/bufread.lua
+    utils/symtab.lua
+  )
+  list(APPEND LUAJIT_TOOLS_DEPS tools-parse-memprof)
+
+  install(FILES
+      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/humanize.lua
+      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/parse.lua
+    DESTINATION ${LUAJIT_DATAROOTDIR}/memprof
+    PERMISSIONS
+      OWNER_READ OWNER_WRITE
+      GROUP_READ
+      WORLD_READ
+    COMPONENT tools-parse-memprof
+  )
+  install(FILES
+      ${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua
+      ${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua
+    DESTINATION ${LUAJIT_DATAROOTDIR}/utils
+    PERMISSIONS
+      OWNER_READ OWNER_WRITE
+      GROUP_READ
+      WORLD_READ
+    COMPONENT tools-parse-memprof
+  )
+  install(FILES
+      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
+    DESTINATION ${LUAJIT_DATAROOTDIR}
+    PERMISSIONS
+      OWNER_READ OWNER_WRITE
+      GROUP_READ
+      WORLD_READ
+    COMPONENT tools-parse-memprof
+  )
+  install(CODE
+    # XXX: Since the auxiliary script need to be configured in
+    # other way it need to be reconfigured it prior to its
+    # installation. Unfortunately, we need to manually specify
+    # the installation path in <configure_file> command.
+    # Hope this script will be gone as a result of the issue below
+    # https://github.com/tarantool/tarantool/issues/5688.
+    "
+      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
+      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
+      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
+        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
+      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
+    "
+    COMPONENT tools-parse-memprof
+  )
+endif()
+
+add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})
-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
@ 2021-02-02 20:57 ` Igor Munkin via Tarantool-patches
  2021-02-08 15:05   ` Timur Safin via Tarantool-patches
  2021-02-14 18:48   ` Sergey Kaplun via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib* Igor Munkin via Tarantool-patches
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

This patch introduces a separate target to run all available tests. The
whole testing machinery is reworked much but the existing tests are left
mostly unchanged. However, considering the different ways to integrate
LuaJIT into the parent project, this machinery provides two new
configuration options:
* LUAJIT_USE_TEST: there might be a parent project integrating LuaJIT
  sources in its source tree as a third party library (e.g.
  https://github.com/tarantool/tarantool), so <test> target can be
  already reserved there. This option allows to omit <test> target
  configuration for LuaJIT to respect CMP0002 policy.
* LUAJIT_TEST_BINARY: if LuaJIT tests are used in parent project test
  routine, provide an option to choose which binary (i.e. Lua runtime)
  to be used for running them.

The latter option value is used as a dependency for tests, and its
default value is $<TARGET_FILE:${LUAJIT_DEPS}>. Unfortunately older
CMake can't expand the generator expression used in DEPENDS section of
<add_custom_(command|target)>. As a result the CMake minimum required
version is bumped to 3.1 project-wide. For more info see CMake Release
notes[1] for 3.1 version.

Finally, existing tests are grouped and moved to a separate directory
under the root test directory to make the further addition of other
available test suites in scope of tarantool/tarantool#4064 and
tarantool/tarantool#4473 easier.

Tarantool tests are implemented using Tarantool on-board TAP module[2],
that is moved to LuaJIT repository with a little changes to save Lua
chunks untouched. Other auxiliary files for Tarantool-specific testing
(such as *.skipcond, suite.ini), in turn, are removed.

[1]: https://cmake.org/cmake/help/latest/release/3.1.html#commands
[2]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/

Part of tarantool/tarantool#4862

Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 .gitignore                                    |   1 +
 CMakeLists.txt                                |  31 +-
 etc/CMakeLists.txt                            |   3 +-
 src/CMakeLists.txt                            |   7 +-
 src/host/CMakeLists.txt                       |   3 +-
 test/CMakeLists.txt                           |  31 +-
 test/gh-4427-ffi-sandwich.skipcond            |   7 -
 test/gh-4427-ffi-sandwich/CMakeLists.txt      |   1 -
 test/lj-flush-on-trace.skipcond               |   7 -
 test/lj-flush-on-trace/CMakeLists.txt         |   1 -
 test/misclib-getmetrics-capi.skipcond         |   7 -
 test/misclib-getmetrics-capi/CMakeLists.txt   |   1 -
 test/misclib-getmetrics-lapi.skipcond         |   7 -
 test/suite.ini                                |   6 -
 test/tarantool-tests/CMakeLists.txt           |  92 ++++++
 .../gh-3196-incorrect-string-length.test.lua  |   2 +-
 .../gh-4427-ffi-sandwich.test.lua             |  24 +-
 .../gh-4427-ffi-sandwich/CMakeLists.txt       |   1 +
 .../gh-4427-ffi-sandwich/libsandwich.c        |   0
 ...gh-4476-fix-string-find-recording.test.lua |   2 +-
 ...gh-4773-tonumber-fail-on-NUL-char.test.lua |   2 +-
 .../lj-494-table-chain-infinite-loop.test.lua |   2 +-
 ...lj-505-fold-no-strref-for-ptrdiff.test.lua |   2 +-
 .../lj-524-fold-conv-respect-src-irt.test.lua |   2 +-
 .../lj-flush-on-trace.test.lua                |  24 +-
 .../lj-flush-on-trace/CMakeLists.txt          |   1 +
 .../lj-flush-on-trace/libflush.c              |   0
 .../misclib-getmetrics-capi.test.lua          |   5 +-
 .../misclib-getmetrics-capi/CMakeLists.txt    |   1 +
 .../misclib-getmetrics-capi/testgetmetrics.c  |   0
 .../misclib-getmetrics-lapi.test.lua          |  10 +-
 .../misclib-memprof-lapi.test.lua             |  15 +-
 .../or-232-unsink-64-kptr.test.lua            |   0
 test/tarantool-tests/tap.lua                  | 306 ++++++++++++++++++
 test/tarantool-tests/utils.lua                |  43 +++
 test/utils.lua                                |  33 --
 tools/CMakeLists.txt                          |   2 +-
 37 files changed, 569 insertions(+), 113 deletions(-)
 delete mode 100644 test/gh-4427-ffi-sandwich.skipcond
 delete mode 100644 test/gh-4427-ffi-sandwich/CMakeLists.txt
 delete mode 100644 test/lj-flush-on-trace.skipcond
 delete mode 100644 test/lj-flush-on-trace/CMakeLists.txt
 delete mode 100644 test/misclib-getmetrics-capi.skipcond
 delete mode 100644 test/misclib-getmetrics-capi/CMakeLists.txt
 delete mode 100644 test/misclib-getmetrics-lapi.skipcond
 delete mode 100644 test/suite.ini
 create mode 100644 test/tarantool-tests/CMakeLists.txt
 rename test/{ => tarantool-tests}/gh-3196-incorrect-string-length.test.lua (94%)
 rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich.test.lua (70%)
 create mode 100644 test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
 rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich/libsandwich.c (100%)
 rename test/{ => tarantool-tests}/gh-4476-fix-string-find-recording.test.lua (99%)
 rename test/{ => tarantool-tests}/gh-4773-tonumber-fail-on-NUL-char.test.lua (95%)
 rename test/{ => tarantool-tests}/lj-494-table-chain-infinite-loop.test.lua (99%)
 rename test/{ => tarantool-tests}/lj-505-fold-no-strref-for-ptrdiff.test.lua (96%)
 rename test/{ => tarantool-tests}/lj-524-fold-conv-respect-src-irt.test.lua (95%)
 rename test/{ => tarantool-tests}/lj-flush-on-trace.test.lua (70%)
 create mode 100644 test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
 rename test/{ => tarantool-tests}/lj-flush-on-trace/libflush.c (100%)
 rename test/{ => tarantool-tests}/misclib-getmetrics-capi.test.lua (97%)
 create mode 100644 test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
 rename test/{ => tarantool-tests}/misclib-getmetrics-capi/testgetmetrics.c (100%)
 rename test/{ => tarantool-tests}/misclib-getmetrics-lapi.test.lua (98%)
 rename test/{ => tarantool-tests}/misclib-memprof-lapi.test.lua (86%)
 rename test/{ => tarantool-tests}/or-232-unsink-64-kptr.test.lua (100%)
 create mode 100644 test/tarantool-tests/tap.lua
 create mode 100644 test/tarantool-tests/utils.lua
 delete mode 100644 test/utils.lua

diff --git a/.gitignore b/.gitignore
index a21ee1c..35d2580 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ compile_commands.json
 install_manifest.txt
 luajit-parse-memprof
 luajit.pc
+tests.ok
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dba5d8..62ac369 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,8 @@
 
 # --- Initial setup ------------------------------------------------------------
 
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+# See the rationale below (near LUAJIT_TEST_BINARY variable).
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 project(LuaJIT C)
 
 #
@@ -259,3 +260,31 @@ add_subdirectory(etc)
 # --- Tools --------------------------------------------------------------------
 
 add_subdirectory(tools)
+
+# --- Testing source tree ------------------------------------------------------
+
+# Auxiliary options for testing.
+
+# FIXME: There might be a parent project integrating LuaJIT
+# sources in its source tree as a third party library
+# (e.g. https://github.com/tarantool/tarantool), so <test> target
+# can be already reserved there. This option allows to omit <test>
+# target configuration for LuaJIT to respect CMP0002 policy.
+option(LUAJIT_USE_TEST "Generate <test> target" ON)
+
+# FIXME: If LuaJIT is used in parent project, provide an option
+# to choose which binary to be used for running LuaJIT tests.
+# XXX: This variable is used as a dependency for tests, and its
+# default value is $<TARGET_FILE:${LUAJIT_DEPS}> assigned in <src>
+# directory CMakeLists. Unfortunately CMake fails with generator
+# expressions expansions used in <add_custom_(command|target)>.
+# As a result the minimal required CMake version is set to 3.1.
+# For more info see CMake Release notes for 3.1 version.
+# https://cmake.org/cmake/help/latest/release/3.1.html#commands
+# XXX: This options is moved below source tree processing since
+# the default binary target need to be generated.
+set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING
+  "Lua implementation to be used for tests. Default is luajit."
+)
+
+add_subdirectory(test)
diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
index 4a4c3cd..d54fa79 100644
--- a/etc/CMakeLists.txt
+++ b/etc/CMakeLists.txt
@@ -1,6 +1,7 @@
 # Building supplementary materials for LuaJIT.
 
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
 set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
 if(CMAKE_LIBRARY_ARCHITECTURE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8ada1a4..209b5f0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,8 @@
 # Major portions taken verbatim or adapted from the uJIT.
 # Copyright (C) 2015-2019 IPONWEB Ltd.
 
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
 enable_language(ASM)
 
@@ -329,6 +330,10 @@ else()
   set(LUAJIT_DEPS luajit_static)
 endif()
 
+# XXX: The variable is used in testing, so PARENT_SCOPE option
+# is obligatory.
+set(LUAJIT_BINARY $<TARGET_FILE:${LUAJIT_DEPS}> PARENT_SCOPE)
+
 add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
 add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
 
diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
index fe2de5c..011a630 100644
--- a/src/host/CMakeLists.txt
+++ b/src/host/CMakeLists.txt
@@ -1,6 +1,7 @@
 # Building the toolchain for LuaJIT VM preprocessing.
 
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
 # FIXME: Both minilua and buildvm need to be build with the HOST_*
 # toolchain.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index ec37580..f05dd90 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,3 +1,28 @@
-add_subdirectory(gh-4427-ffi-sandwich)
-add_subdirectory(lj-flush-on-trace)
-add_subdirectory(misclib-getmetrics-capi)
+# Running various test suites against LuaJIT.
+
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+add_subdirectory(tarantool-tests)
+
+add_custom_target(${PROJECT_NAME}-test DEPENDS
+  tarantool-tests
+)
+
+if(LUAJIT_USE_TEST)
+  if(POLICY CMP0037)
+    if(CMAKE_VERSION VERSION_LESS 3.11)
+      # cmake below 3.11 reserves name test. Use old policy.
+      # https://cmake.org/cmake/help/v3.11/release/3.11.html#other-changes
+      cmake_policy(SET CMP0037 OLD)
+    else()
+      # Starting from cmake 3.11 name test reserved in special
+      # cases and can be used as target name.
+      cmake_policy(SET CMP0037 NEW)
+    endif()
+  endif(POLICY CMP0037)
+
+  add_custom_target(test DEPENDS
+    ${PROJECT_NAME}-test
+  )
+endif()
diff --git a/test/gh-4427-ffi-sandwich.skipcond b/test/gh-4427-ffi-sandwich.skipcond
deleted file mode 100644
index 2a2ec4d..0000000
--- a/test/gh-4427-ffi-sandwich.skipcond
+++ /dev/null
@@ -1,7 +0,0 @@
-import platform
-
-# Disabled on FreeBSD due to #4819.
-if platform.system() == 'FreeBSD':
-    self.skip = 1
-
-# vim: set ft=python:
diff --git a/test/gh-4427-ffi-sandwich/CMakeLists.txt b/test/gh-4427-ffi-sandwich/CMakeLists.txt
deleted file mode 100644
index 995c6bb..0000000
--- a/test/gh-4427-ffi-sandwich/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-build_lualib(libsandwich libsandwich.c)
diff --git a/test/lj-flush-on-trace.skipcond b/test/lj-flush-on-trace.skipcond
deleted file mode 100644
index 2a2ec4d..0000000
--- a/test/lj-flush-on-trace.skipcond
+++ /dev/null
@@ -1,7 +0,0 @@
-import platform
-
-# Disabled on FreeBSD due to #4819.
-if platform.system() == 'FreeBSD':
-    self.skip = 1
-
-# vim: set ft=python:
diff --git a/test/lj-flush-on-trace/CMakeLists.txt b/test/lj-flush-on-trace/CMakeLists.txt
deleted file mode 100644
index a90452d..0000000
--- a/test/lj-flush-on-trace/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-build_lualib(libflush libflush.c)
diff --git a/test/misclib-getmetrics-capi.skipcond b/test/misclib-getmetrics-capi.skipcond
deleted file mode 100644
index 2a2ec4d..0000000
--- a/test/misclib-getmetrics-capi.skipcond
+++ /dev/null
@@ -1,7 +0,0 @@
-import platform
-
-# Disabled on FreeBSD due to #4819.
-if platform.system() == 'FreeBSD':
-    self.skip = 1
-
-# vim: set ft=python:
diff --git a/test/misclib-getmetrics-capi/CMakeLists.txt b/test/misclib-getmetrics-capi/CMakeLists.txt
deleted file mode 100644
index e7cc8f8..0000000
--- a/test/misclib-getmetrics-capi/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-build_lualib(testgetmetrics testgetmetrics.c)
diff --git a/test/misclib-getmetrics-lapi.skipcond b/test/misclib-getmetrics-lapi.skipcond
deleted file mode 100644
index 2a2ec4d..0000000
--- a/test/misclib-getmetrics-lapi.skipcond
+++ /dev/null
@@ -1,7 +0,0 @@
-import platform
-
-# Disabled on FreeBSD due to #4819.
-if platform.system() == 'FreeBSD':
-    self.skip = 1
-
-# vim: set ft=python:
diff --git a/test/suite.ini b/test/suite.ini
deleted file mode 100644
index 0b9d5e2..0000000
--- a/test/suite.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[default]
-core = app
-description = Luajit tests
-lua_libs = utils.lua
-is_parallel = True
-pretest_clean = True
diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
new file mode 100644
index 0000000..0be4b34
--- /dev/null
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -0,0 +1,92 @@
+# Test suite that has been moved from Tarantool repository in
+# scope of https://github.com/tarantool/tarantool/issues/4478.
+
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+find_program(PROVE prove)
+if(NOT PROVE)
+  message(WARNING "`prove' is not found, so tarantool-tests target is not generated")
+  return()
+endif()
+
+macro(BuildTestLib lib sources)
+  add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
+  target_include_directories(${lib} PRIVATE
+    ${LUAJIT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+  )
+  set_target_properties(${lib} PROPERTIES
+    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+    PREFIX ""
+  )
+
+  # XXX: This change affects current cmake variable scope and so
+  # a user should care to don't use it in a top level scope.
+  # The dynamic libraries are loaded with LuaJIT binary and use
+  # symbols from it. So it is totally OK to have unresolved
+  # symbols at build time.
+  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    set_target_properties(${lib} PROPERTIES
+      LINK_FLAGS "-undefined dynamic_lookup"
+    )
+  else()
+    # FIXME: Unfortunately there is no another way to suppress
+    # this linker option, so just strip it out from the flags.
+    string(REPLACE "-Wl,--no-undefined" ""
+      CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
+    )
+  endif()
+  # XXX: Append the lib to be built to the dependecy list.
+  # Unfortunately, CMake is a crap and there is no other way to
+  # extend the list in parent scope but join two strings with
+  # 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 interpreter 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 the
+  # list. I have no idea what is wrong with this tool, but 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)
+  # 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)
+endmacro()
+
+add_subdirectory(gh-4427-ffi-sandwich)
+add_subdirectory(lj-flush-on-trace)
+add_subdirectory(misclib-getmetrics-capi)
+
+# The part of memory profiler toolchain is located in tools
+# 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"
+)
+set(LUA_TEST_SUFFIX .test.lua)
+file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
+
+# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
+# with dependecies are set in scope of BuildTestLib macro.
+add_custom_command(
+  COMMENT "Running Tarantool tests"
+  OUTPUT tests.ok
+  DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS}
+  COMMAND
+  env
+    LUA_PATH="${LUA_PATH}\;\;"
+    LUA_CPATH="${LUA_CPATH}\;\;"
+    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
+    ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
+      --exec ${LUAJIT_TEST_BINARY}
+      --ext ${LUA_TEST_SUFFIX}
+      --failures --shuffle
+    && touch tests.ok
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_custom_target(tarantool-tests DEPENDS tests.ok)
diff --git a/test/gh-3196-incorrect-string-length.test.lua b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
similarity index 94%
rename from test/gh-3196-incorrect-string-length.test.lua
rename to test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
index f135de7..edb728f 100755
--- a/test/gh-3196-incorrect-string-length.test.lua
+++ b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 -- Miscellaneous test for LuaJIT bugs
 local tap = require('tap')
diff --git a/test/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
similarity index 70%
rename from test/gh-4427-ffi-sandwich.test.lua
rename to test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
index 9d5e50f..e9771e8 100755
--- a/test/gh-4427-ffi-sandwich.test.lua
+++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
@@ -1,22 +1,30 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 if #arg == 0 then
-  require('utils').selfrun(arg, {
+
+  local utils = require('utils')
+
+  -- Disabled on *BSD due to #4819.
+  utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
+
+  utils.selfrun(arg, {
     {
-      arg = {
+      arg  = {
         1, -- hotloop (arg[1])
         1, -- trigger (arg[2])
       },
-      res = tostring(3), -- hotloop + trigger + 1
-      msg = 'Trace is aborted',
+      test = 'is',
+      res  = tostring(3), -- hotloop + trigger + 1
+      msg  = 'Trace is aborted',
     },
     {
-      arg = {
+      arg  = {
         1, -- hotloop (arg[1])
         2, -- trigger (arg[2])
       },
-      res = 'Lua VM re-entrancy is detected while executing the trace',
-      msg = 'Trace is recorded',
+      test = 'like',
+      res  = 'Lua VM re%-entrancy is detected while executing the trace',
+      msg  = 'Trace is recorded',
     },
   })
 end
diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
new file mode 100644
index 0000000..5515567
--- /dev/null
+++ b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
@@ -0,0 +1 @@
+BuildTestLib(libsandwich libsandwich.c)
diff --git a/test/gh-4427-ffi-sandwich/libsandwich.c b/test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c
similarity index 100%
rename from test/gh-4427-ffi-sandwich/libsandwich.c
rename to test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c
diff --git a/test/gh-4476-fix-string-find-recording.test.lua b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
similarity index 99%
rename from test/gh-4476-fix-string-find-recording.test.lua
rename to test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
index fb55680..92a11d5 100755
--- a/test/gh-4476-fix-string-find-recording.test.lua
+++ b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 local tap = require('tap')
 
diff --git a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
similarity index 95%
rename from test/gh-4773-tonumber-fail-on-NUL-char.test.lua
rename to test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
index a660979..51e3142 100755
--- a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua
+++ b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 local tap = require('tap')
 
diff --git a/test/lj-494-table-chain-infinite-loop.test.lua b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
similarity index 99%
rename from test/lj-494-table-chain-infinite-loop.test.lua
rename to test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
index 314eb29..9c04ef6 100755
--- a/test/lj-494-table-chain-infinite-loop.test.lua
+++ b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 local tap = require('tap')
 
diff --git a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
similarity index 96%
rename from test/lj-505-fold-no-strref-for-ptrdiff.test.lua
rename to test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
index a82bafa..6b0d70b 100755
--- a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua
+++ b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 local tap = require('tap')
 
diff --git a/test/lj-524-fold-conv-respect-src-irt.test.lua b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
similarity index 95%
rename from test/lj-524-fold-conv-respect-src-irt.test.lua
rename to test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
index a232eea..fb92bee 100755
--- a/test/lj-524-fold-conv-respect-src-irt.test.lua
+++ b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
@@ -1,4 +1,4 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 local tap = require('tap')
 local ffi = require('ffi')
diff --git a/test/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua
similarity index 70%
rename from test/lj-flush-on-trace.test.lua
rename to test/tarantool-tests/lj-flush-on-trace.test.lua
index 0b3ccf4..f9a513f 100755
--- a/test/lj-flush-on-trace.test.lua
+++ b/test/tarantool-tests/lj-flush-on-trace.test.lua
@@ -1,22 +1,30 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 if #arg == 0 then
-  require('utils').selfrun(arg, {
+
+  local utils = require('utils')
+
+  -- Disabled on *BSD due to #4819.
+  utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
+
+  utils.selfrun(arg, {
     {
-      arg = {
+      arg  = {
         1, -- hotloop (arg[1])
         1, -- trigger (arg[2])
       },
-      res = 'OK',
-      msg = 'Trace is aborted',
+      test = 'is',
+      res  = 'OK',
+      msg  = 'Trace is aborted',
     },
     {
-      arg = {
+      arg  = {
         1, -- hotloop (arg[1])
         2, -- trigger (arg[2])
       },
-      res = 'JIT mode change is detected while executing the trace',
-      msg = 'Trace is recorded',
+      test = 'like',
+      res  = 'JIT mode change is detected while executing the trace',
+      msg  = 'Trace is recorded',
     },
   })
 end
diff --git a/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
new file mode 100644
index 0000000..91a18a6
--- /dev/null
+++ b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
@@ -0,0 +1 @@
+BuildTestLib(libflush libflush.c)
diff --git a/test/lj-flush-on-trace/libflush.c b/test/tarantool-tests/lj-flush-on-trace/libflush.c
similarity index 100%
rename from test/lj-flush-on-trace/libflush.c
rename to test/tarantool-tests/lj-flush-on-trace/libflush.c
diff --git a/test/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
similarity index 97%
rename from test/misclib-getmetrics-capi.test.lua
rename to test/tarantool-tests/misclib-getmetrics-capi.test.lua
index 1ad6958..c418e9f 100755
--- a/test/misclib-getmetrics-capi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
@@ -1,4 +1,7 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
+
+-- Disabled on *BSD due to #4819.
+require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819')
 
 local path = arg[0]:gsub('%.test%.lua', '')
 local suffix = package.cpath:match('?.(%a+);')
diff --git a/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
new file mode 100644
index 0000000..cff0096
--- /dev/null
+++ b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
@@ -0,0 +1 @@
+BuildTestLib(testgetmetrics testgetmetrics.c)
diff --git a/test/misclib-getmetrics-capi/testgetmetrics.c b/test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c
similarity index 100%
rename from test/misclib-getmetrics-capi/testgetmetrics.c
rename to test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c
diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
similarity index 98%
rename from test/misclib-getmetrics-lapi.test.lua
rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua
index 3b3d1f8..959293d 100755
--- a/test/misclib-getmetrics-lapi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
@@ -1,9 +1,12 @@
-#!/usr/bin/env tarantool
+#!/usr/bin/env luajit
 
 -- This is a part of tarantool/luajit testing suite.
 -- Major portions taken verbatim or adapted from the LuaVela testing suite.
 -- Copyright (C) 2015-2019 IPONWEB Ltd.
 
+-- Disabled on *BSD due to #4819.
+require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819')
+
 local tap = require('tap')
 
 local test = tap.test("lib-misc-getmetrics")
@@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest)
     subtest:plan(1)
 
     -- Force up garbage collect all dead objects.
-    collectgarbage("collect")
+    repeat
+        local count = collectgarbage("count")
+        collectgarbage("collect")
+    until collectgarbage("count") == count
 
     -- Bump getmetrics table and string keys allocation.
     local old_metrics = misc.getmetrics()
diff --git a/test/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua
similarity index 86%
rename from test/misclib-memprof-lapi.test.lua
rename to test/tarantool-tests/misclib-memprof-lapi.test.lua
index dd484f4..2b97212 100755
--- a/test/misclib-memprof-lapi.test.lua
+++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua
@@ -8,19 +8,14 @@ test:plan(9)
 jit.off()
 jit.flush()
 
--- FIXME: Launch tests with LUA_PATH enviroment variable.
-local path = arg[0]:gsub("[^/]+%.test%.lua", "")
-local path_suffix = "../tools/?.lua;"
-package.path = ("%s%s;"):format(path, path_suffix)..package.path
-
 local table_new = require "table.new"
 
 local bufread = require "utils.bufread"
 local memprof = require "memprof.parse"
 local symtab = require "utils.symtab"
 
-local TMP_BINFILE = arg[0]:gsub("[^/]+%.test%.lua", "%.%1.memprofdata.tmp.bin")
-local BAD_PATH = arg[0]:gsub("[^/]+%.test%.lua", "%1/memprofdata.tmp.bin")
+local TMP_BINFILE = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%.%1.memprofdata.tmp.bin")
+local BAD_PATH = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%1/memprofdata.tmp.bin")
 
 local function payload()
   -- Preallocate table to avoid table array part reallocations.
@@ -82,7 +77,7 @@ end
 
 -- Not a directory.
 local res, err, errno = misc.memprof.start(BAD_PATH)
-test:ok(res == nil and err:match("Not a directory"))
+test:ok(res == nil and err:match("No such file or directory"))
 test:ok(type(errno) == "number")
 
 -- Profiler is running.
@@ -125,9 +120,9 @@ local free = fill_ev_type(events, symbols, "free")
 -- the number of allocations.
 -- 1 event - alocation of table by itself + 1 allocation
 -- of array part as far it is bigger than LJ_MAX_COLOSIZE (16).
-test:ok(check_alloc_report(alloc, 27, 25, 2))
+test:ok(check_alloc_report(alloc, 22, 20, 2))
 -- 100 strings allocations.
-test:ok(check_alloc_report(alloc, 32, 25, 100))
+test:ok(check_alloc_report(alloc, 27, 20, 100))
 
 -- Collect all previous allocated objects.
 test:ok(free.INTERNAL.num == 102)
diff --git a/test/or-232-unsink-64-kptr.test.lua b/test/tarantool-tests/or-232-unsink-64-kptr.test.lua
similarity index 100%
rename from test/or-232-unsink-64-kptr.test.lua
rename to test/tarantool-tests/or-232-unsink-64-kptr.test.lua
diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
new file mode 100644
index 0000000..fd03132
--- /dev/null
+++ b/test/tarantool-tests/tap.lua
@@ -0,0 +1,306 @@
+--- tap.lua internal file.
+---
+--- The Test Anything Protocol vesion 13 producer.
+---
+
+-- Initializer FFI for <iscdata> check.
+local ffi = require('ffi')
+local NULL = ffi.new('void *')
+
+local function indent(chars)
+  return (' '):rep(chars)
+end
+
+local function traceback(level)
+  local trace = { }
+  level = level or 3
+  while true do
+    local info = debug.getinfo(level, 'nSl')
+    if not info then break end
+    table.insert(trace, {
+      source   = info.source,
+      src      = info.short_src,
+      line     = info.linedefined or 0,
+      what     = info.what,
+      name     = info.name,
+      namewhat = info.namewhat,
+      filename = info.source:sub(1, 1) == '@' and info.source:sub(2) or 'eval',
+    })
+    level = level + 1
+  end
+  return trace
+end
+
+local function diag(test, fmt, ...)
+  io.write(indent(4 * test.level), ('# %s\n'):format(fmt:format(...)))
+end
+
+local function ok(test, cond, message, extra)
+  test.total = test.total + 1
+  if cond then
+    io.write(indent(4 * test.level), ('ok - %s\n'):format(message))
+    return true
+  end
+
+  test.failed = test.failed + 1
+  io.write(indent(4 * test.level), ('not ok - %s\n'):format(message))
+
+  -- Dump extra contents added in outer space.
+  for key, value in pairs(extra or { }) do
+    io.write(indent(2 + 4 * test.level), ('%s:\t%s\n'):format(key, value))
+  end
+
+  if not test.trace then
+    return false
+  end
+
+  local trace = traceback()
+  local tindent = indent(4 + 4 * test.level)
+  io.write(tindent, ('filename:\t%s\n'):format(trace[#trace].filename))
+  io.write(tindent, ('line:\t%s\n'):format(trace[#trace].line))
+  for frameno, frame in ipairs(trace) do
+    io.write(tindent, ('frame #%d\n'):format(frameno))
+    local findent = indent(2) .. tindent
+    for key, value in pairs(frame) do
+      io.write(findent, ('%s:\t%s\n'):format(key, value))
+    end
+  end
+  return false
+end
+
+local function fail(test, message, extra)
+  return ok(test, false, message, extra)
+end
+
+local function skip(test, message, extra)
+  ok(test, true, message .. ' # skip', extra)
+end
+
+local function cmpdeeply(got, expected, extra)
+  if type(expected) == 'number' or type(got) == 'number' then
+    extra.got = got
+    extra.expected = expected
+    -- Handle NaN.
+    if got ~= got and expected ~= expected then
+      return true
+    end
+    return got == expected
+  end
+
+  if ffi.istype('bool', got) then got = (got == 1) end
+  if ffi.istype('bool', expected) then expected = (expected == 1) end
+
+  if extra.strict and type(got) ~= type(expected) then
+    extra.got = type(got)
+    extra.expected = type(expected)
+    return false
+  end
+
+  if type(got) ~= 'table' or type(expected) ~= 'table' then
+    extra.got = got
+    extra.expected = expected
+    return got == expected
+  end
+
+  local path = extra.path or '/'
+  local visited_keys = {}
+
+  for i, v in pairs(got) do
+    visited_keys[i] = true
+    extra.path = path .. '/' .. i
+    if not cmpdeeply(v, expected[i], extra) then
+      return false
+    end
+  end
+
+  -- Check if expected contains more keys then got.
+  for i, v in pairs(expected) do
+    if visited_keys[i] ~= true and (extra.strict or v ~= NULL) then
+      extra.expected = 'key ' .. tostring(i)
+      extra.got = 'nil'
+      return false
+    end
+  end
+
+  extra.path = path
+
+  return true
+end
+
+local function like(test, got, pattern, message, extra)
+  extra = extra or { }
+  extra.got = got
+  extra.expected = pattern
+  return ok(test, tostring(got):match(pattern) ~= nil, message, extra)
+end
+
+local function unlike(test, got, pattern, message, extra)
+  extra = extra or { }
+  extra.got = got
+  extra.expected = pattern
+  return ok(test, tostring(got):match(pattern) == nil, message, extra)
+end
+
+local function is(test, got, expected, message, extra)
+  extra = extra or { }
+  extra.got = got
+  extra.expected = expected
+  local rc = (test.strict == false or type(got) == type(expected))
+             and got == expected
+  return ok(test, rc, message, extra)
+end
+
+local function isnt(test, got, unexpected, message, extra)
+  extra = extra or { }
+  extra.got = got
+  extra.unexpected = unexpected
+  local rc = (test.strict == true and type(got) ~= type(unexpected))
+             or got ~= unexpected
+  return ok(test, rc, message, extra)
+end
+
+local function is_deeply(test, got, expected, message, extra)
+  extra = extra or { }
+  extra.got = got
+  extra.expected = expected
+  extra.strict = test.strict
+  return ok(test, cmpdeeply(got, expected, extra), message, extra)
+end
+
+local function isnil(test, v, message, extra)
+  return is(test, not v and v == nil and 'nil' or v, 'nil', message, extra)
+end
+
+local function isnumber(test, v, message, extra)
+  return is(test, type(v), 'number', message, extra)
+end
+
+local function isstring(test, v, message, extra)
+  return is(test, type(v), 'string', message, extra)
+end
+
+local function istable(test, v, message, extra)
+  return is(test, type(v), 'table', message, extra)
+end
+
+local function isboolean(test, v, message, extra)
+  return is(test, type(v), 'boolean', message, extra)
+end
+
+local function isfunction(test, v, message, extra)
+  return is(test, type(v), 'function', message, extra)
+end
+
+local function isudata(test, v, utype, message, extra)
+  extra = extra or { }
+  extra.expected = ('userdata<%s>'):format(utype)
+  if type(v) ~= 'userdata' then
+    extra.got = type(v)
+    return fail(test, message, extra)
+  end
+  extra.got = ('userdata<%s>'):format(getmetatable(v))
+  return ok(test, getmetatable(v) == utype, message, extra)
+end
+
+local function iscdata(test, v, ctype, message, extra)
+  extra = extra or { }
+  extra.expected = ffi.typeof(ctype)
+  if type(v) ~= 'cdata' then
+    extra.got = type(v)
+    return fail(test, message, extra)
+  end
+  extra.got = ffi.typeof(v)
+  return ok(test, ffi.istype(ctype, v), message, extra)
+end
+
+local test_mt
+
+local function new(parent, name, fun, ...)
+  local level = parent ~= nil and parent.level + 1 or 0
+  local test = setmetatable({
+    parent  = parent,
+    name    = name,
+    level   = level,
+    total   = 0,
+    failed  = 0,
+    planned = 0,
+    trace   = parent == nil and true or parent.trace,
+    strict  = false,
+  }, test_mt)
+  if fun == nil then
+    return test
+  end
+  test:diag('%s', test.name)
+  fun(test, ...)
+  test:diag('%s: end', test.name)
+  return test:check()
+end
+
+local function plan(test, planned)
+  test.planned = planned
+  io.write(indent(4 * test.level), ('1..%d\n'):format(planned))
+end
+
+local function check(test)
+  if test.checked then
+    error('check called twice')
+  end
+  test.checked = true
+  if test.planned ~= test.total then
+    if test.parent ~= nil then
+      ok(test.parent, false, 'bad plan', {
+        planned = test.planned,
+        run = test.total,
+      })
+    else
+      diag(test, ('bad plan: planned %d run %d')
+        :format(test.planned, test.total))
+    end
+  elseif test.failed > 0 then
+    if test.parent ~= nil then
+      ok(test.parent, false, 'failed subtests', {
+        failed = test.failed,
+        planned = test.planned,
+      })
+    else
+      diag(test, 'failed subtest: %d', test.failed)
+    end
+  else
+    if test.parent ~= nil then
+      ok(test.parent, true, test.name)
+    end
+  end
+  return test.planned == test.total and test.failed == 0
+end
+
+test_mt = {
+  __index = {
+    test       = new,
+    plan       = plan,
+    check      = check,
+    diag       = diag,
+    ok         = ok,
+    fail       = fail,
+    skip       = skip,
+    is         = is,
+    isnt       = isnt,
+    isnil      = isnil,
+    isnumber   = isnumber,
+    isstring   = isstring,
+    istable    = istable,
+    isboolean  = isboolean,
+    isfunction = isfunction,
+    isudata    = isudata,
+    iscdata    = iscdata,
+    is_deeply  = is_deeply,
+    like       = like,
+    unlike     = unlike,
+  }
+}
+
+return {
+  test = function(...)
+    io.write('TAP version 13\n')
+    return new(nil, ...)
+  end
+}
diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua
new file mode 100644
index 0000000..197b138
--- /dev/null
+++ b/test/tarantool-tests/utils.lua
@@ -0,0 +1,43 @@
+local M = { }
+
+local tap = require('tap')
+
+function M.selfrun(arg, checks)
+  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
+
+  test:plan(#checks)
+
+  local vars = {
+    LUABIN = arg[-1],
+    SCRIPT = arg[0],
+    PATH   = arg[0]:gsub('%.test%.lua', ''),
+    SUFFIX = package.cpath:match('?.(%a+);'),
+  }
+
+  local cmd = string.gsub('LUA_PATH="<PATH>/?.lua;$LUA_PATH" ' ..
+                          'LUA_CPATH="<PATH>/?.<SUFFIX>;$LUA_CPATH" ' ..
+                          'LD_LIBRARY_PATH=<PATH>:$LD_LIBRARY_PATH ' ..
+                          '<LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars)
+
+  for _, ch in pairs(checks) do
+    local testf = test[ch.test]
+    assert(testf, ("tap doesn't provide test.%s function"):format(ch.test))
+    local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg)))
+    local res = proc:read('*all'):gsub('^%s+', ''):gsub('%s+$', '')
+    -- XXX: explicitly pass <test> as an argument to <testf>
+    -- to emulate test:is(...), test:like(...), etc.
+    testf(test, res, ch.res, ch.msg)
+  end
+
+  os.exit(test:check() and 0 or 1)
+end
+
+function M.skipcond(condition, message)
+  if not condition then return end
+  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
+  test:plan(1)
+  test:skip(message)
+  os.exit(test:check() and 0 or 1)
+end
+
+return M
diff --git a/test/utils.lua b/test/utils.lua
deleted file mode 100644
index 707d6ef..0000000
--- a/test/utils.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-local M = { }
-
-local tap = require('tap')
-
-function M.selfrun(arg, checks)
-  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
-
-  test:plan(#checks)
-
-  local vars = {
-    LUABIN = arg[-1],
-    SCRIPT = arg[0],
-    PATH   = arg[0]:gsub('%.test%.lua', ''),
-    SUFFIX = package.cpath:match('?.(%a+);'),
-  }
-
-  local cmd = string.gsub('LUA_CPATH="$LUA_CPATH;<PATH>/?.<SUFFIX>" ' ..
-                          'LUA_PATH="$LUA_PATH;<PATH>/?.lua" ' ..
-                          'LD_LIBRARY_PATH=<PATH> ' ..
-                          '<LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars)
-
-  for _, ch in pairs(checks) do
-    local res
-    local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg)))
-    for s in proc:lines() do res = s end
-    assert(res, 'proc:lines failed')
-    test:is(res, ch.res, ch.msg)
-  end
-
-  os.exit(test:check() and 0 or 1)
-end
-
-return M
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index f9ffc5e..af3de33 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -2,7 +2,7 @@
 # Major portions taken verbatim or adapted from the uJIT.
 # Copyright (C) 2015-2019 IPONWEB Ltd.
 
-# See the rationale in the root CMakeLists.txt
+# See the rationale in the root CMakeLists.txt.
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
 set(LUAJIT_TOOLS_DEPS)
-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
                   ` (2 preceding siblings ...)
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake Igor Munkin via Tarantool-patches
@ 2021-02-02 20:57 ` Igor Munkin via Tarantool-patches
       [not found]   ` <012f01d6fe1a$a2aa6890$e7ff39b0$@tarantool.org>
  2021-02-14 19:16   ` Sergey Kaplun via Tarantool-patches
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake Igor Munkin via Tarantool-patches
  2021-02-28 22:04 ` [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
  5 siblings, 2 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Sergey Bronnikov; +Cc: tarantool-patches

Since the regular static analysis has not been enabled for the test
chunks in LuaJIT repository yet, the tests for recently implemented
features still produce luacheck warnings.

The most of the issues are fixed in scope of the commit
8fc103fb1a21c28185a1942e75d8d9485e3aade7 ('test: fix warnings spotted by
luacheck') and this patch fixes the remaining ones.

Fixes tarantool/tarantool#5631
Part of tarantool/tarantool#4862
Part of tarantool/tarantool#5470
Follows up tarantool/tarantool#5187

Reported-by: Sergey Bronnikov <sergeyb@tarantool.org>
Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 .../misclib-getmetrics-capi.test.lua          | 22 ++++++---------
 .../misclib-getmetrics-lapi.test.lua          | 28 +++++++++----------
 2 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/test/tarantool-tests/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
index c418e9f..d409ea9 100755
--- a/test/tarantool-tests/misclib-getmetrics-capi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
@@ -38,29 +38,29 @@ test:ok(testgetmetrics.objcount(function(iterations)
     }
 
     -- Separate objects creations to separate jit traces.
-    for i = 1, iterations do
-        table.insert(placeholder.str, tostring(i))
+    for _ = 1, iterations do
+        table.insert(placeholder.str, tostring(_))
     end
 
-    for i = 1, iterations do
-        table.insert(placeholder.tab, {i})
+    for _ = 1, iterations do
+        table.insert(placeholder.tab, {_})
     end
 
-    for i = 1, iterations do
+    for _ = 1, iterations do
         table.insert(placeholder.udata, newproxy())
     end
 
-    for i = 1, iterations do
+    for _ = 1, iterations do
         -- Check counting of VLA/VLS/aligned cdata.
         table.insert(placeholder.cdata, ffi.new("char[?]", 4))
     end
 
-    for i = 1, iterations do
+    for _ = 1, iterations do
         -- Check counting of non-VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("uint64_t", i))
+        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
     end
 
-    placeholder = nil
+    placeholder = nil -- luacheck: no unused
     -- Restore default jit settings.
     jit.opt.start(unpack(jit_opt_default))
 end))
@@ -69,15 +69,11 @@ end))
 test:ok(testgetmetrics.snap_restores(function()
     jit.opt.start(0, "hotloop=1")
 
-    local old_metrics = misc.getmetrics()
-
     local sum = 0
     for i = 1, 20 do
         sum = sum + i
     end
 
-    local new_metrics = misc.getmetrics()
-
     -- Restore default jit settings.
     jit.opt.start(unpack(jit_opt_default))
 
diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
index 959293d..d54caac 100755
--- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
@@ -58,10 +58,10 @@ test:test("gc-allocated-freed", function(subtest)
     until collectgarbage("count") == count
 
     -- Bump getmetrics table and string keys allocation.
-    local old_metrics = misc.getmetrics()
+    misc.getmetrics()
 
     -- Remember allocated size for getmetrics table.
-    old_metrics = misc.getmetrics()
+    local old_metrics = misc.getmetrics()
 
     collectgarbage("collect")
 
@@ -77,7 +77,7 @@ test:test("gc-allocated-freed", function(subtest)
     -- (such as concatenation, string.format, table.concat)
     -- while creating the string. Otherwise gc_freed/gc_allocated
     -- relations will not be so straightforward.
-    local str = string.sub("Hello, world", 1, 5)
+    local str = string.sub("Hello, world", 1, 5) -- luacheck: no unused
     collectgarbage("collect")
 
     new_metrics = misc.getmetrics()
@@ -196,29 +196,29 @@ test:test("objcount", function(subtest)
     }
 
     -- Separate objects creations to separate jit traces.
-    for i = 1, 1000 do
-        table.insert(placeholder.str, tostring(i))
+    for _ = 1, 1000 do
+        table.insert(placeholder.str, tostring(_))
     end
 
-    for i = 1, 1000 do
-        table.insert(placeholder.tab, {i})
+    for _ = 1, 1000 do
+        table.insert(placeholder.tab, {_})
     end
 
-    for i = 1, 1000 do
+    for _ = 1, 1000 do
         table.insert(placeholder.udata, newproxy())
     end
 
-    for i = 1, 1000 do
+    for _ = 1, 1000 do
         -- Check counting of VLA/VLS/aligned cdata.
         table.insert(placeholder.cdata, ffi.new("char[?]", 4))
     end
 
-    for i = 1, 1000 do
+    for _ = 1, 1000 do
         -- Check counting of non-VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("uint64_t", i))
+        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
     end
 
-    placeholder = nil
+    placeholder = nil -- luacheck: no unused
     collectgarbage("collect")
     local new_metrics = misc.getmetrics()
 
@@ -372,7 +372,7 @@ test:test("strhash", function(subtest)
     assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
     old_metrics = new_metrics
 
-    local str1  = "strhash".."_hit"
+    local _ = "strhash".."_hit"
 
     new_metrics = misc.getmetrics()
     assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 20)
@@ -384,7 +384,7 @@ test:test("strhash", function(subtest)
     assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
     old_metrics = new_metrics
 
-    local str2 = "new".."string"
+    local _ = "new".."string"
 
     new_metrics = misc.getmetrics()
     assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 19)
-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
                   ` (3 preceding siblings ...)
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib* Igor Munkin via Tarantool-patches
@ 2021-02-02 20:57 ` Igor Munkin via Tarantool-patches
  2021-02-04 22:52   ` Timur Safin via Tarantool-patches
  2021-02-14 19:32   ` Sergey Kaplun via Tarantool-patches
  2021-02-28 22:04 ` [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
  5 siblings, 2 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-02 20:57 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

This patch introduces a separate target to run luacheck against all Lua
chunks within LuaJIT repository except those explicitly ignored in
.luacheckrc. There is also a single additional change over the 'luajit'
std defaults: to suppress all false positives related to <misc>
namespace introduced in 5a61e1ab54b5c66bfebd836db1ac47996611e065 ('misc:
add C and Lua API for platform metrics'), this name is added to
<read_globals> list.

All Lua sources originally inherited from LuaJIT vanilla repository are
ignored, to leave them coherent with the upstream.

The new target is a dependency for the root <test> target.

Part of tarantool/tarantool#4862
Part of tarantool/tarantool#5470

Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 .gitignore          |  1 +
 .luacheckrc         | 11 +++++++++++
 test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 .luacheckrc

diff --git a/.gitignore b/.gitignore
index 35d2580..7902547 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ Makefile
 cmake_install.cmake
 compile_commands.json
 install_manifest.txt
+luacheck.ok
 luajit-parse-memprof
 luajit.pc
 tests.ok
diff --git a/.luacheckrc b/.luacheckrc
new file mode 100644
index 0000000..0a5d001
--- /dev/null
+++ b/.luacheckrc
@@ -0,0 +1,11 @@
+-- Use the default LuaJIT globals.
+std = 'luajit'
+-- This fork also introduces a new global for misc API namespace.
+read_globals = { 'misc' }
+
+-- These files are inherited from the vanilla LuaJIT and need to
+-- be coherent with the upstream.
+exclude_files = {
+  'dynasm/',
+  'src/',
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f05dd90..c89efc2 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -3,6 +3,36 @@
 # See the rationale in the root CMakeLists.txt.
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
+find_program(LUACHECK luacheck)
+if(LUACHECK)
+  set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
+  set(LUACHECK_OK ${CMAKE_CURRENT_BINARY_DIR}/luacheck.ok)
+  file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
+  add_custom_command(
+    COMMENT "Running luacheck static analysis"
+    OUTPUT ${LUACHECK_OK}
+    DEPENDS ${LUACHECK} ${LUACHECK_RC} ${LUACHECK_DEPS}
+    COMMAND
+      ${LUACHECK} ${PROJECT_SOURCE_DIR}
+        --codes
+        --config ${LUACHECK_RC}
+      && touch ${LUACHECK_OK}
+      # XXX: Filenames in .luacheckrc are considered relative to
+      # the working directory, hence luacheck should be run in the
+      # project root directory.
+      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+  )
+else()
+  add_custom_command(
+    COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is dummy"
+    OUTPUT luacheck.ok
+    COMMAND touch luacheck.ok
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+  )
+endif()
+
+add_custom_target(${PROJECT_NAME}-luacheck DEPENDS luacheck.ok)
+
 add_subdirectory(tarantool-tests)
 
 add_custom_target(${PROJECT_NAME}-test DEPENDS
@@ -24,5 +54,6 @@ if(LUAJIT_USE_TEST)
 
   add_custom_target(test DEPENDS
     ${PROJECT_NAME}-test
+    ${PROJECT_NAME}-luacheck
   )
 endif()
-- 
2.25.0


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake Igor Munkin via Tarantool-patches
@ 2021-02-04 22:52   ` Timur Safin via Tarantool-patches
  2021-02-08 15:57     ` Igor Munkin via Tarantool-patches
  2021-02-14 19:32   ` Sergey Kaplun via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-04 22:52 UTC (permalink / raw)
  To: 'Igor Munkin', 'Sergey Kaplun'; +Cc: tarantool-patches

LGTM as obvious!

: From: Igor Munkin <imun@tarantool.org>
: Subject: [PATCH luajit 5/5] test: run luacheck static analysis via CMake
: 
: This patch introduces a separate target to run luacheck against all Lua
: chunks within LuaJIT repository except those explicitly ignored in
: .luacheckrc. There is also a single additional change over the 'luajit'
: std defaults: to suppress all false positives related to <misc>
: namespace introduced in 5a61e1ab54b5c66bfebd836db1ac47996611e065 ('misc:
: add C and Lua API for platform metrics'), this name is added to
: <read_globals> list.
: 
: All Lua sources originally inherited from LuaJIT vanilla repository are
: ignored, to leave them coherent with the upstream.
: 
: The new target is a dependency for the root <test> target.
: 
: Part of tarantool/tarantool#4862
: Part of tarantool/tarantool#5470
: 
: Signed-off-by: Igor Munkin <imun@tarantool.org>
: ---
:  .gitignore          |  1 +
:  .luacheckrc         | 11 +++++++++++
:  test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
:  3 files changed, 43 insertions(+)
:  create mode 100644 .luacheckrc
: 
: diff --git a/.gitignore b/.gitignore
: index 35d2580..7902547 100644
: --- a/.gitignore
: +++ b/.gitignore
: @@ -17,6 +17,7 @@ Makefile
:  cmake_install.cmake
:  compile_commands.json
:  install_manifest.txt
: +luacheck.ok
:  luajit-parse-memprof
:  luajit.pc
:  tests.ok
: diff --git a/.luacheckrc b/.luacheckrc
: new file mode 100644
: index 0000000..0a5d001
: --- /dev/null
: +++ b/.luacheckrc
: @@ -0,0 +1,11 @@
: +-- Use the default LuaJIT globals.
: +std = 'luajit'
: +-- This fork also introduces a new global for misc API namespace.
: +read_globals = { 'misc' }
: +
: +-- These files are inherited from the vanilla LuaJIT and need to
: +-- be coherent with the upstream.
: +exclude_files = {
: +  'dynasm/',
: +  'src/',
: +}
: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
: index f05dd90..c89efc2 100644
: --- a/test/CMakeLists.txt
: +++ b/test/CMakeLists.txt
: @@ -3,6 +3,36 @@
:  # See the rationale in the root CMakeLists.txt.
:  cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
: 
: +find_program(LUACHECK luacheck)
: +if(LUACHECK)
: +  set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
: +  set(LUACHECK_OK ${CMAKE_CURRENT_BINARY_DIR}/luacheck.ok)
: +  file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
: +  add_custom_command(
: +    COMMENT "Running luacheck static analysis"
: +    OUTPUT ${LUACHECK_OK}
: +    DEPENDS ${LUACHECK} ${LUACHECK_RC} ${LUACHECK_DEPS}
: +    COMMAND
: +      ${LUACHECK} ${PROJECT_SOURCE_DIR}
: +        --codes
: +        --config ${LUACHECK_RC}
: +      && touch ${LUACHECK_OK}
: +      # XXX: Filenames in .luacheckrc are considered relative to
: +      # the working directory, hence luacheck should be run in the
: +      # project root directory.
: +      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
: +  )
: +else()
: +  add_custom_command(
: +    COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is
: dummy"
: +    OUTPUT luacheck.ok
: +    COMMAND touch luacheck.ok
: +    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
: +  )
: +endif()
: +
: +add_custom_target(${PROJECT_NAME}-luacheck DEPENDS luacheck.ok)
: +
:  add_subdirectory(tarantool-tests)
: 
:  add_custom_target(${PROJECT_NAME}-test DEPENDS
: @@ -24,5 +54,6 @@ if(LUAJIT_USE_TEST)
: 
:    add_custom_target(test DEPENDS
:      ${PROJECT_NAME}-test
: +    ${PROJECT_NAME}-luacheck
:    )
:  endif()
: --
: 2.25.0



^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
@ 2021-02-04 22:53   ` Timur Safin via Tarantool-patches
  2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
  2021-02-09 11:38   ` Sergey Kaplun via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-04 22:53 UTC (permalink / raw)
  To: 'Igor Munkin', 'Sergey Kaplun'; +Cc: tarantool-patches

LGTM as rather simple rename (with few touches here and there)!

: From: Igor Munkin <imun@tarantool.org>
: Subject: [PATCH luajit 1/5] build: preserve the original build system
: 
: Since the build machinery is going to be ported to CMake there would be
: Makefile names clashing. This change renames the original build system
: (and a couple of auxiliary files requiring configuring) to keep all this
: machinery working.
: 
: As a result of these changes one need to explicitly specify the Makefile
: in the build command:
: | make -f Makefile.original <options>
: 
: Needed for tarantool/tarantool#4862
: 
: Signed-off-by: Igor Munkin <imun@tarantool.org>
: ---
:  Makefile => Makefile.original               | 44 +++++++++++++--------
:  etc/{luajit.pc => luajit.pc.in}             |  4 +-
:  src/{Makefile.dep => Makefile.dep.original} |  0
:  src/{Makefile => Makefile.original}         |  4 +-
:  tools/luajit-parse-memprof                  |  9 -----
:  tools/luajit-parse-memprof.in               |  6 +++
:  6 files changed, 38 insertions(+), 29 deletions(-)
:  rename Makefile => Makefile.original (85%)
:  rename etc/{luajit.pc => luajit.pc.in} (91%)
:  rename src/{Makefile.dep => Makefile.dep.original} (100%)
:  rename src/{Makefile => Makefile.original} (99%)
:  delete mode 100755 tools/luajit-parse-memprof
:  create mode 100644 tools/luajit-parse-memprof.in
: 
: diff --git a/Makefile b/Makefile.original
: similarity index 85%
: rename from Makefile
: rename to Makefile.original
: index 61967df..b85d4bf 100644
: --- a/Makefile
: +++ b/Makefile.original
: @@ -85,10 +85,10 @@ INSTALL_X= install -m 0755
:  INSTALL_F= install -m 0644
:  UNINSTALL= $(RM)
:  LDCONFIG= ldconfig -n
: -SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
: -            -e "s|^multilib=.*|multilib=$(MULTILIB)|"
: -SED_TMEMPROF= sed -e "s|^TOOL_DIR=.*|TOOL_DIR=$(INSTALL_TOOLSLIB)|" \
: -                  -e "s|^LUAJIT_BIN=.*|LUAJIT_BIN=$(INSTALL_T)|"
: +SED_PC= sed -e "s|@LUAJIT_PC_PREFIX@|$(PREFIX)|" \
: +            -e "s|@LUAJIT_PC_MULTILIB@|$(MULTILIB)|"
: +SED_TMEMPROF= sed -e "s|@LUAJIT_TOOLS_DIR@|$(INSTALL_TOOLSLIB)|" \
: +                  -e "s|@LUAJIT_TOOLS_BIN@|$(INSTALL_T)|"
: 
:  FILE_T= luajit
:  FILE_A= libluajit.a
: @@ -123,9 +123,9 @@ endif
: 
:  INSTALL_DEP= src/luajit
: 
: -default all $(INSTALL_DEP):
: +default all $(INSTALL_DEP): tools
:  	@echo "==== Building LuaJIT $(VERSION) ===="
: -	$(MAKE) -C src
: +	$(MAKE) -C src -f Makefile.original
:  	@echo "==== Successfully built LuaJIT $(VERSION) ===="
: 
:  install: $(INSTALL_DEP)
: @@ -140,17 +140,17 @@ install: $(INSTALL_DEP)
:  	  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \
:  	  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :
:  	cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)
: -	cd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \
: -	  $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \
: -	  $(RM) $(FILE_PC).tmp
: +	cd etc && $(SED_PC) $(FILE_PC).in > $(FILE_PC) && \
: +	  $(INSTALL_F) $(FILE_PC) $(INSTALL_PC) && \
: +	  $(RM) $(FILE_PC)
:  	cd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)
:  	cd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)
:  	cd tools/utils && $(INSTALL_F) $(FILES_UTILSLIB) $(INSTALL_UTILSLIB)
:  	cd tools/memprof && $(INSTALL_F) $(FILES_MEMPROFLIB)
: $(INSTALL_MEMPROFLIB)
:  	cd tools && $(INSTALL_F) $(FILES_TOOLSLIB) $(INSTALL_TOOLSLIB)
: -	cd tools && $(SED_TMEMPROF) $(FILE_TMEMPROF) > $(FILE_TMEMPROF).tmp &&
: \
: -	  $(INSTALL_X) $(FILE_TMEMPROF).tmp $(INSTALL_TMEMPROF) && \
: -	  $(RM) $(FILE_TMEMPROF).tmp
: +	cd tools && $(SED_TMEMPROF) $(FILE_TMEMPROF).in > $(FILE_TMEMPROF) &&
: \
: +	  $(INSTALL_X) $(FILE_TMEMPROF) $(INSTALL_TMEMPROF) && \
: +	  $(RM) $(FILE_TMEMPROF)
:  	@echo "==== Successfully installed LuaJIT $(VERSION) to $(PREFIX)
: ===="
:  	@echo ""
:  	@echo "Note: the development releases deliberately do NOT install a
: symlink for luajit"
: @@ -185,13 +185,25 @@ uninstall:
: 
: 
: ############################################################################
: ##
: 
: -amalg:
: +amalg: tools
:  	@echo "Building LuaJIT $(VERSION)"
: -	$(MAKE) -C src amalg
: +	$(MAKE) -C src -f Makefile.original amalg
: 
:  clean:
: -	$(MAKE) -C src clean
: +	$(RM) tools/$(FILE_TMEMPROF)
: +	$(MAKE) -C src -f Makefile.original clean
: 
: -.PHONY: all install amalg clean
: +tools: tools/$(FILE_TMEMPROF)
: +
: +# FIXME: This is an ugly hack to manually configure an auxiliary
: +# tools/luajit-parse-memprof. I hope this file will have gone away
: +# in scope of https://github.com/tarantool/tarantool/issues/5688.
: +tools/$(FILE_TMEMPROF):
: +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
: +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
: +	     $@.in > $@
: +	@chmod +x $@
: +
: +.PHONY: all install amalg clean tools
: 
: 
: ############################################################################
: ##
: diff --git a/etc/luajit.pc b/etc/luajit.pc.in
: similarity index 91%
: rename from etc/luajit.pc
: rename to etc/luajit.pc.in
: index a78f174..f32385d 100644
: --- a/etc/luajit.pc
: +++ b/etc/luajit.pc.in
: @@ -5,8 +5,8 @@ relver=0
:  version=${majver}.${minver}.${relver}-beta3
:  abiver=5.1
: 
: -prefix=/usr/local
: -multilib=lib
: +prefix=@LUAJIT_PC_PREFIX@
: +multilib=@LUAJIT_PC_MULTILIB@
:  exec_prefix=${prefix}
:  libdir=${exec_prefix}/${multilib}
:  libname=luajit-${abiver}
: diff --git a/src/Makefile.dep b/src/Makefile.dep.original
: similarity index 100%
: rename from src/Makefile.dep
: rename to src/Makefile.dep.original
: diff --git a/src/Makefile b/src/Makefile.original
: similarity index 99%
: rename from src/Makefile
: rename to src/Makefile.original
: index 825b01c..502504c 100644
: --- a/src/Makefile
: +++ b/src/Makefile.original
: @@ -624,7 +624,7 @@ depend:
:  	      -e "s|^\([^l ]\)|host/\1|" \
:  	      -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
:  	      -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
: -	      -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
: +	      -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep.original
:  	@for file in $(ALL_HDRGEN); do \
:  	  test -s $$file || $(HOST_RM) $$file; \
:  	  done
: @@ -699,7 +699,7 @@ $(HOST_O): %.o: %.c
:  	$(E) "HOSTCC    $@"
:  	$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
: 
: -include Makefile.dep
: +include Makefile.dep.original
: 
: 
: ############################################################################
: ##
:  # Target file rules.
: diff --git a/tools/luajit-parse-memprof b/tools/luajit-parse-memprof
: deleted file mode 100755
: index c814301..0000000
: --- a/tools/luajit-parse-memprof
: +++ /dev/null
: @@ -1,9 +0,0 @@
: -#!/bin/bash
: -#
: -# Launcher for memprof parser.
: -
: -# This two variables are replaced on installing.
: -TOOL_DIR=$(dirname `readlink -f $0`)
: -LUAJIT_BIN=$TOOL_DIR/../src/luajit
: -
: -LUA_PATH="$TOOL_DIR/?.lua;;" $LUAJIT_BIN $TOOL_DIR/memprof.lua $@
: diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
: new file mode 100644
: index 0000000..8867202
: --- /dev/null
: +++ b/tools/luajit-parse-memprof.in
: @@ -0,0 +1,6 @@
: +#!/bin/bash
: +#
: +# Launcher for memprof parser.
: +
: +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
: +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
: --
: 2.25.0



^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
@ 2021-02-04 22:53   ` Timur Safin via Tarantool-patches
  2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
  2021-02-11 19:23   ` Sergey Kaplun via Tarantool-patches
  2021-02-13  3:47   ` Sergey Kaplun via Tarantool-patches
  2 siblings, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-04 22:53 UTC (permalink / raw)
  To: 'Igor Munkin', 'Sergey Kaplun'; +Cc: tarantool-patches

Few preliminary observations below...

: From: Igor Munkin <imun@tarantool.org>
: Subject: [PATCH luajit 2/5] build: replace GNU Make with CMake
: 
...

: 
: diff --git a/.gitignore b/.gitignore
: index 1a07bf7..a21ee1c 100644
: --- a/.gitignore
: +++ b/.gitignore
: @@ -1,5 +1,5 @@
:  *.[oa]
: -*.so
: +*.so*
:  *.obj
:  *.lib
:  *.exp
: @@ -9,3 +9,13 @@
:  *.dmp
:  *.swp
:  .tags
: +
: +# CMake generated artefacts
: +CMakeCache.txt
: +CMakeFiles
: +Makefile
: +cmake_install.cmake
: +compile_commands.json
: +install_manifest.txt
: +luajit-parse-memprof
: +luajit.pc

Uh-oh, this ugly hack would be handled by single exclusion
build*/
if we would all use the same (idiomatic) approach for out-of-source
build. But we do not yet accustomed to that, so... never mind!

: diff --git a/CMakeLists.txt b/CMakeLists.txt
: new file mode 100644
: index 0000000..0dba5d8
: --- /dev/null
: +++ b/CMakeLists.txt
: @@ -0,0 +1,261 @@
: +# LuaJIT -- interpreter and JIT compiler for Lua language.
: +# This is the main entry point for building, testing and
: +# packaging the project.
: +# Major portions taken verbatim or adapted from the uJIT.
: +# Copyright (C) 2015-2019 IPONWEB Ltd.

2019, IPONWEB?

...
: +# --- Fine-tuning cmake environment ---------------------------------------
: -----
: +
: +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
: +set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Could you please remove this enforcement of CMAKE_EXPORT_COMPILE_COMMANDS here?
Agreed that this is always a good idea to generate compile_commands.json. But 
disagreed that we should enforce it automatically. This is developer choice to 
either generate or not this compile database. (And it's slowing down a bit cmake
generation phase on big projects. Which is not yet case here, but in any case)

...
: +
: +# Features from Lua 5.2 that are unlikely to break existing code
: +# are enabled by default. Some other features that *might* break
: +# some existing code (e.g. __pairs or os.execute() return values)
: +# can be enabled here.
: +# XXX: this does not provide full compatibility with Lua 5.2 at
: +# this time.
: +option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
: +if(LUAJIT_LUA52COMPAT)
: +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT)
: +endif()

I do not know whether we do care that much about consistency of an option names
or not care? But worth to mention that all other options do have ENABLE/DISABLE
or HAS prefix in similar contexts, but here we do not use it that way, and it's
simple LUAJIT_LUA52COMPAT. What about LUAJIT_ENABLE_LUA52COMPAT as it's 
passed to compile options? (Not insist, but worth to note)


: +
: +# Disable the JIT compiler, i.e. turn LuaJIT into a pure
: +# interpreter.
: +option(LUAJIT_DISABLE_JIT "JIT support" OFF)
: +if(LUAJIT_DISABLE_JIT)
: +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_JIT)
: +endif()
: +set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT)
: +

...

: +# Enable GC64 mode for x64.
: +option(LUAJIT_ENABLE_GC64 "GC64 mode for x64" OFF)
: +if(LUAJIT_ENABLE_GC64)
: +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_GC64)
: +endif()
: +
: +# Disable memory profiler.
: +option(LUAJIT_DISABLE_MEMPROF "LuaJIT memory profiler support" OFF)
: +if(LUAJIT_DISABLE_MEMPROF)
: +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_MEMPROF)
: +endif()
: +
: +# Switch to harder (and slower) hash function when a collision
: +# chain in the string hash table exceeds certain length.
: +option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON)
: +if(LUAJIT_SMART_STRINGS)
: +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1)
: +endif()

The same note about lack of ENABLE prefix in the option name.

: +
: +# Turn on assertions for the whole LuaJIT VM. This significantly
: +# slows down everything. Use only if you suspect a problem with
: +# LuaJIT itself.
: +option(LUAJIT_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF)
: +if(LUAJIT_USE_ASSERT)
: +  AppendFlags(TARGET_C_FLAGS -DLUA_USE_ASSERT)
: +endif()
: +


: --- /dev/null
: +++ b/cmake/LuaJITUtils.cmake
: @@ -0,0 +1,31 @@
...
: diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake
: new file mode 100644
: index 0000000..fa455bb
: --- /dev/null
: +++ b/cmake/MakeSourceList.cmake
: @@ -0,0 +1,47 @@
: +# Major portions taken verbatim or adapted from the uJIT.
: +# Copyright (C) 2015-2019 IPONWEB Ltd.
: +#
: +# make_source_list provides a convenient way to define a list of sources
: +# and get a list of absolute paths.
: +#
: +# Example usage:
: +#
: +#   make_source_list(SOURCES_CORE
: +#     SOURCES
: +#       main.c
: +#       test.c
: +#       subdir/test2.c
: +#   )
: +#
: +# This will give you the list:
: +#    "<...>/main.c;<...>/test.c;<...>/subdir/test2.c"
: +# (where `<...>` is ${CMAKE_CURRENT_SOURCE_DIR}).
: +#
: +# Absolute paths in `SOURCES` list don't get ${CMAKE_CURRENT_SOURCE_DIR}
: +# prepended to them.
: +

Very convenient macro below! Much respect to author!

: +function(make_source_list list)
: +  set(prefix ARG)
: +  set(noValues)
: +  set(singleValues)
: +  set(multiValues SOURCES)
: +
: +  include(CMakeParseArguments) # if we update to CMake >= 3.5, can remove
: this line
: +  cmake_parse_arguments(${prefix}
: +                        "${noValues}"
: +                        "${singleValues}"
: +                        "${multiValues}"
: +                        ${ARGN})
: +
: +  set(result_list "")
: +
: +  foreach(fn ${ARG_SOURCES})
: +    if (IS_ABSOLUTE ${fn})
: +      list(APPEND result_list "${fn}")
: +    else()
: +      list(APPEND result_list "${CMAKE_CURRENT_SOURCE_DIR}/${fn}")
: +    endif()
: +  endforeach()
: +
: +  set(${list} "${result_list}" PARENT_SCOPE)
: +endfunction()
...

: diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
: new file mode 100644
: index 0000000..260fc6b
: --- /dev/null
: +++ b/cmake/SetTargetFlags.cmake
: @@ -0,0 +1,42 @@
...
: +
: +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS}")
: +LuaJITArch(LUAJIT_ARCH "${TESTARCH}")
: +
: +# Target-specific compiler options.
: +#
: +# x86/x64 only: For GCC 4.2 or higher and if you don't intend to
: +# distribute the binaries to a different machine you could also
: +# use: -march=native.
: +if(LUAJIT_ARCH STREQUAL "x86")
: +  AppendFlags(TARGET_C_FLAGS -march=i686 -msse -msse2 -mfpmath=sse)
: +endif()

FWIW -msse2 implicitly assumes -msse but if that way it used to be
in makefiles than so be it. Don't need to "improve" it.
...


: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
: new file mode 100644
: index 0000000..8ada1a4
: --- /dev/null
: +++ b/src/CMakeLists.txt
: @@ -0,0 +1,391 @@
: +# Building LuaJIT core: bootstrapping, VM, runtime, JIT compiler.
: +# Major portions taken verbatim or adapted from the uJIT.
: +# Copyright (C) 2015-2019 IPONWEB Ltd.

2019 IPONWEB?

: +
: +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
: +
...

: +
: +include(SetTargetFlags)
: +list(APPEND TARGET_LIBS m)

${TARGET_LIBS} below used as space separated list of words, it's probably
bad idea to operate with it as list, because we end up in trace with something
like

  ./third_party/luajit/src/CMakeLists.txt(302):  target_include_directories(luajit_static PRIVATE ./build/third_party/luajit/src )
  ./third_party/luajit/src/CMakeLists.txt(305):  target_link_libraries(luajit_static libluajit_static dl;m )


...

: +# Compiling and linking CLIs.
: +
: +add_executable(luajit_static EXCLUDE_FROM_ALL ${CLI_SOURCES})
: +set_target_properties(luajit_static PROPERTIES
: +  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
: +  COMPILE_FLAGS "${TARGET_C_FLAGS}"
: +  LINK_FLAGS "${TARGET_BIN_FLAGS}"
: +  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
: +)
: +target_include_directories(luajit_static PRIVATE
: +  ${CMAKE_CURRENT_BINARY_DIR}
: +)
: +target_link_libraries(luajit_static libluajit_static ${TARGET_LIBS})
: +
: +add_executable(luajit_shared EXCLUDE_FROM_ALL ${CLI_SOURCES})
: +set_target_properties(luajit_shared PROPERTIES
: +  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
: +  COMPILE_FLAGS "${TARGET_C_FLAGS}"
: +  LINK_FLAGS "${TARGET_BIN_FLAGS}"
: +  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
: +)
: +target_include_directories(luajit_shared PRIVATE
: +  ${CMAKE_CURRENT_BINARY_DIR}
: +)
: +target_link_libraries(luajit_shared libluajit_shared ${TARGET_LIBS})
: +
: +if(NOT BUILDMODE STREQUAL "dynamic")
: +  set(LIBLUAJIT_STATIC_DEPS libluajit_static)
: +endif()
: +if(NOT BUILDMODE STREQUAL "static")
: +  set(LIBLUAJIT_SHARED_DEPS libluajit_shared)
: +endif()
: +set(LIBLUAJIT_DEPS ${LIBLUAJIT_STATIC_DEPS} ${LIBLUAJIT_SHARED_DEPS})
: +
: +if(BUILDMODE STREQUAL "dynamic")
: +  set(LUAJIT_DEPS luajit_shared)
: +else()
: +  set(LUAJIT_DEPS luajit_static)
: +endif()
: +
: +add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
: +add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
: +
: +install(TARGETS ${LUAJIT_DEPS}
: +  RUNTIME
: +  DESTINATION bin
: +  COMPONENT luajit
: +)

Here we have reasonable cmake complain:

  -- Configuring done
  WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but
  an install rule has been provided for it.  CMake does not define behavior for this case.
  WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default
  but an install rule has been provided for it.  CMake does not define behavior for this case.

There is no much point to install ${LIBLUAJIT_STATIC_DEPS} or ${LIBLUAJIT_SHARED_DEPS} if we have 
excluded luajit_static and/or libluajit_shared from target all dependencies via EXCLUDE_FROM_ALL.

: +install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
: +  ARCHIVE
: +  DESTINATION lib
: +  COMPONENT luajit
: +)
: +install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
: +  LIBRARY
: +  DESTINATION lib
: +  COMPONENT luajit
: +)
: +


: diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
: new file mode 100644
: index 0000000..f9ffc5e
: --- /dev/null
: +++ b/tools/CMakeLists.txt
: @@ -0,0 +1,77 @@
: +# Building tools for developing with uJIT.
: +# Major portions taken verbatim or adapted from the uJIT.
: +# Copyright (C) 2015-2019 IPONWEB Ltd.

2019 IPONWEB?

: +
: +# See the rationale in the root CMakeLists.txt
: +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
: +
: +set(LUAJIT_TOOLS_DEPS)
: +
: +if(LUAJIT_DISABLE_MEMPROF)
: +  message(STATUS "LuaJIT memory profiler support is disabled")
: +else()
: +  # XXX: Can use genex here since the value need to be evaluated
: +  # on the configuration phase. Fortunately, we know the exact
: +  # path where LuaJIT binary is located.
: +  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
: +  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
: +  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY
: ESCAPE_QUOTES)
: +
: +  add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS
: +    luajit-parse-memprof
: +    memprof/humanize.lua
: +    memprof/parse.lua
: +    memprof.lua
: +    utils/bufread.lua
: +    utils/symtab.lua
: +  )
: +  list(APPEND LUAJIT_TOOLS_DEPS tools-parse-memprof)
: +
: +  install(FILES
: +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/humanize.lua
: +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/parse.lua
: +    DESTINATION ${LUAJIT_DATAROOTDIR}/memprof
: +    PERMISSIONS
: +      OWNER_READ OWNER_WRITE
: +      GROUP_READ
: +      WORLD_READ
: +    COMPONENT tools-parse-memprof
: +  )
: +  install(FILES
: +      ${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua
: +      ${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua
: +    DESTINATION ${LUAJIT_DATAROOTDIR}/utils
: +    PERMISSIONS
: +      OWNER_READ OWNER_WRITE
: +      GROUP_READ
: +      WORLD_READ
: +    COMPONENT tools-parse-memprof
: +  )
: +  install(FILES
: +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
: +    DESTINATION ${LUAJIT_DATAROOTDIR}
: +    PERMISSIONS
: +      OWNER_READ OWNER_WRITE
: +      GROUP_READ
: +      WORLD_READ
: +    COMPONENT tools-parse-memprof
: +  )
: +  install(CODE
: +    # XXX: Since the auxiliary script need to be configured in
: +    # other way it need to be reconfigured it prior to its
: +    # installation. Unfortunately, we need to manually specify
: +    # the installation path in <configure_file> command.
: +    # Hope this script will be gone as a result of the issue below
: +    # https://github.com/tarantool/tarantool/issues/5688.
: +    "
: +      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
: +      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
: +      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
: +        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY
: ESCAPE_QUOTES)
: +      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-
: parse-memprof\")
: +    "
: +    COMPONENT tools-parse-memprof
: +  )

Шайтан!

: +endif()
: +
: +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})
: --
: 2.25.0

Regards,
Timur


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake Igor Munkin via Tarantool-patches
@ 2021-02-08 15:05   ` Timur Safin via Tarantool-patches
  2021-02-08 16:29     ` Igor Munkin via Tarantool-patches
  2021-02-14 18:48   ` Sergey Kaplun via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-08 15:05 UTC (permalink / raw)
  To: 'Igor Munkin', 'Sergey Kaplun'; +Cc: tarantool-patches

Some code changes proposals below...

: From: Igor Munkin <imun@tarantool.org>
: Subject: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
: 
: diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-
: tests/CMakeLists.txt
: new file mode 100644
: index 0000000..0be4b34
: --- /dev/null
: +++ b/test/tarantool-tests/CMakeLists.txt
: @@ -0,0 +1,92 @@
: +# Test suite that has been moved from Tarantool repository in
: +# scope of https://github.com/tarantool/tarantool/issues/4478.
: +
: +# See the rationale in the root CMakeLists.txt.
: +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
: +
: +find_program(PROVE prove)
: +if(NOT PROVE)
: +  message(WARNING "`prove' is not found, so tarantool-tests target is not
: generated")
: +  return()
: +endif()
: +
: +macro(BuildTestLib lib sources)
: +  add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
: +  target_include_directories(${lib} PRIVATE
: +    ${LUAJIT_SOURCE_DIR}
: +    ${CMAKE_CURRENT_SOURCE_DIR}
: +  )
...
: +  # XXX: Append the lib to be built to the dependecy list.
: +  # Unfortunately, CMake is a crap and there is no other way to
: +  # extend the list in parent scope but join two strings with
: +  # semicolon. If one finds the normal way to make it work, feel
: +  # free to reach me.
: +  set(TESTLIBS "${lib};${TESTLIBS}" PARENT_SCOPE)

I don't like this. It reminds me of bad examples of this note
in the libev code like "this is so uncontrollably lame" which
actually distract users. We should rather put comments in more
neutral way (IMVHO). 

: +  # Add the directory where the lib is built to the LUA_CPATH
: +  # environment variable, so interpreter 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 the
: +  # list. I have no idea what is wrong with this tool, but 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)
: +  # 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)
: +endmacro()
: +
: +add_subdirectory(gh-4427-ffi-sandwich)
: +add_subdirectory(lj-flush-on-trace)
: +add_subdirectory(misclib-getmetrics-capi)

I liked you introduced globs for test files addition (blow), 
but unfortunately you didn't complete this with subdirectory addition

Please see my proposed patch (with reworded comments and new macro) here https://gist.github.com/tsafin/6c7505c0c764ab2b474667bf0d65fb45.

: +
: +# The part of memory profiler toolchain is located in tools
: +# 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"
: +)
: +set(LUA_TEST_SUFFIX .test.lua)
: +file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
: +
: +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
: +# with dependecies are set in scope of BuildTestLib macro.
: +add_custom_command(
: +  COMMENT "Running Tarantool tests"
: +  OUTPUT tests.ok
: +  DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS}
: +  COMMAND
: +  env
: +    LUA_PATH="${LUA_PATH}\;\;"
: +    LUA_CPATH="${LUA_CPATH}\;\;"
: +    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
: +    ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
: +      --exec ${LUAJIT_TEST_BINARY}
: +      --ext ${LUA_TEST_SUFFIX}
: +      --failures --shuffle
: +    && touch tests.ok
: +  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
: +)
: +
: +add_custom_target(tarantool-tests DEPENDS tests.ok)

The major part of suggested patch is like this one:

--------------------------------------------------
-add_subdirectory(gh-4427-ffi-sandwich)
-add_subdirectory(lj-flush-on-trace)
-add_subdirectory(misclib-getmetrics-capi)
+macro(add_all_subdirectories)
+    file(GLOB entries RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*")
+    foreach(entry ${entries})
+        if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${entry})
+            add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${entry})
+        endif()
+    endforeach()
+endmacro()
+
+add_all_subdirectories()
-------------------------------------------------

Regards,
Timur


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
       [not found]     ` <2c495492-50f4-acfd-ad66-2cb44abb5fa1@tarantool.org>
@ 2021-02-08 15:40       ` Sergey Bronnikov via Tarantool-patches
  2021-02-08 15:58       ` Igor Munkin via Tarantool-patches
  1 sibling, 0 replies; 46+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2021-02-08 15:40 UTC (permalink / raw)
  To: 'Igor Munkin', Timur Safin, 'Sergey Kaplun',
	tarantool-patches

+ tarantool-patches

On 08.02.2021 18:19, Sergey Bronnikov wrote:
> Thanks for the patch!
>
> LGTM
>
>> : -----Original Message-----
>> : From: Tarantool-patches 
>> <tarantool-patches-bounces@dev.tarantool.org> On
>> : Behalf Of Igor Munkin via Tarantool-patches
>> : Subject: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings 
>> found
>> : with luacheck in misclib*
>> :
>> : Since the regular static analysis has not been enabled for the test
>> : chunks in LuaJIT repository yet, the tests for recently implemented
>> : features still produce luacheck warnings.
>> :
>> : The most of the issues are fixed in scope of the commit
>> : 8fc103fb1a21c28185a1942e75d8d9485e3aade7 ('test: fix warnings 
>> spotted by
>> : luacheck') and this patch fixes the remaining ones.
>> :
>> : Fixes tarantool/tarantool#5631
>> : Part of tarantool/tarantool#4862
>> : Part of tarantool/tarantool#5470
>> : Follows up tarantool/tarantool#5187
>> :
>> : Reported-by: Sergey Bronnikov <sergeyb@tarantool.org>
>> : Signed-off-by: Igor Munkin <imun@tarantool.org>
>> : ---
>> :  .../misclib-getmetrics-capi.test.lua          | 22 ++++++---------
>> :  .../misclib-getmetrics-lapi.test.lua          | 28 
>> +++++++++----------
>> :  2 files changed, 23 insertions(+), 27 deletions(-)
>> :
>> : diff --git a/test/tarantool-tests/misclib-getmetrics-capi.test.lua
>> : b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
>> : index c418e9f..d409ea9 100755
>> : --- a/test/tarantool-tests/misclib-getmetrics-capi.test.lua
>> : +++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
>> : @@ -38,29 +38,29 @@ 
>> test:ok(testgetmetrics.objcount(function(iterations)
>> :      }
>> :
>> :      -- Separate objects creations to separate jit traces.
>> : -    for i = 1, iterations do
>> : -        table.insert(placeholder.str, tostring(i))
>> : +    for _ = 1, iterations do
>> : +        table.insert(placeholder.str, tostring(_))
>> :      end
>> :
>> : -    for i = 1, iterations do
>> : -        table.insert(placeholder.tab, {i})
>> : +    for _ = 1, iterations do
>> : +        table.insert(placeholder.tab, {_})
>> :      end
>> :
>> : -    for i = 1, iterations do
>> : +    for _ = 1, iterations do
>> :          table.insert(placeholder.udata, newproxy())
>> :      end
>> :
>> : -    for i = 1, iterations do
>> : +    for _ = 1, iterations do
>> :          -- Check counting of VLA/VLS/aligned cdata.
>> :          table.insert(placeholder.cdata, ffi.new("char[?]", 4))
>> :      end
>> :
>> : -    for i = 1, iterations do
>> : +    for _ = 1, iterations do
>> :          -- Check counting of non-VLA/VLS/aligned cdata.
>> : -        table.insert(placeholder.cdata, ffi.new("uint64_t", i))
>> : +        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
>> :      end
>> :
>> : -    placeholder = nil
>> : +    placeholder = nil -- luacheck: no unused
>> :      -- Restore default jit settings.
>> :      jit.opt.start(unpack(jit_opt_default))
>> :  end))
>> : @@ -69,15 +69,11 @@ end))
>> :  test:ok(testgetmetrics.snap_restores(function()
>> :      jit.opt.start(0, "hotloop=1")
>> :
>> : -    local old_metrics = misc.getmetrics()
>> : -
>> :      local sum = 0
>> :      for i = 1, 20 do
>> :          sum = sum + i
>> :      end
>> :
>> : -    local new_metrics = misc.getmetrics()
>> : -
>> :      -- Restore default jit settings.
>> :      jit.opt.start(unpack(jit_opt_default))
>> :
>> : diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
>> : b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
>> : index 959293d..d54caac 100755
>> : --- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
>> : +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
>> : @@ -58,10 +58,10 @@ test:test("gc-allocated-freed", function(subtest)
>> :      until collectgarbage("count") == count
>> :
>> :      -- Bump getmetrics table and string keys allocation.
>> : -    local old_metrics = misc.getmetrics()
>> : +    misc.getmetrics()
>> :
>> :      -- Remember allocated size for getmetrics table.
>> : -    old_metrics = misc.getmetrics()
>> : +    local old_metrics = misc.getmetrics()
>> :
>> :      collectgarbage("collect")
>> :
>> : @@ -77,7 +77,7 @@ test:test("gc-allocated-freed", function(subtest)
>> :      -- (such as concatenation, string.format, table.concat)
>> :      -- while creating the string. Otherwise gc_freed/gc_allocated
>> :      -- relations will not be so straightforward.
>> : -    local str = string.sub("Hello, world", 1, 5)
>> : +    local str = string.sub("Hello, world", 1, 5) -- luacheck: no 
>> unused
>> :      collectgarbage("collect")
>> :
>> :      new_metrics = misc.getmetrics()
>> : @@ -196,29 +196,29 @@ test:test("objcount", function(subtest)
>> :      }
>> :
>> :      -- Separate objects creations to separate jit traces.
>> : -    for i = 1, 1000 do
>> : -        table.insert(placeholder.str, tostring(i))
>> : +    for _ = 1, 1000 do
>> : +        table.insert(placeholder.str, tostring(_))
>> :      end
>> :
>> : -    for i = 1, 1000 do
>> : -        table.insert(placeholder.tab, {i})
>> : +    for _ = 1, 1000 do
>> : +        table.insert(placeholder.tab, {_})
>> :      end
>> :
>> : -    for i = 1, 1000 do
>> : +    for _ = 1, 1000 do
>> :          table.insert(placeholder.udata, newproxy())
>> :      end
>> :
>> : -    for i = 1, 1000 do
>> : +    for _ = 1, 1000 do
>> :          -- Check counting of VLA/VLS/aligned cdata.
>> :          table.insert(placeholder.cdata, ffi.new("char[?]", 4))
>> :      end
>> :
>> : -    for i = 1, 1000 do
>> : +    for _ = 1, 1000 do
>> :          -- Check counting of non-VLA/VLS/aligned cdata.
>> : -        table.insert(placeholder.cdata, ffi.new("uint64_t", i))
>> : +        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
>> :      end
>> :
>> : -    placeholder = nil
>> : +    placeholder = nil -- luacheck: no unused
>> :      collectgarbage("collect")
>> :      local new_metrics = misc.getmetrics()
>> :
>> : @@ -372,7 +372,7 @@ test:test("strhash", function(subtest)
>> :      assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
>> :      old_metrics = new_metrics
>> :
>> : -    local str1  = "strhash".."_hit"
>> : +    local _ = "strhash".."_hit"
>> :
>> :      new_metrics = misc.getmetrics()
>> :      assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 20)
>> : @@ -384,7 +384,7 @@ test:test("strhash", function(subtest)
>> :      assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
>> :      old_metrics = new_metrics
>> :
>> : -    local str2 = "new".."string"
>> : +    local _ = "new".."string"
>> :
>> :      new_metrics = misc.getmetrics()
>> :      assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 19)
>> : --
>> : 2.25.0
>>
>>

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
@ 2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 15:56 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

Thanks for your review!

On 05.02.21, Timur Safin wrote:
> LGTM as rather simple rename (with few touches here and there)!

Added your tag:
| Reviewed-by: Timur Safin <tsafin@tarantool.org>

> 

<snipped>

> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
@ 2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
  2021-02-09 13:55       ` Timur Safin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 15:56 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

Thanks for your review!

On 05.02.21, Timur Safin wrote:
> Few preliminary observations below...
> 
> : From: Igor Munkin <imun@tarantool.org>
> : Subject: [PATCH luajit 2/5] build: replace GNU Make with CMake
> : 
> ...
> 
> : 
> : diff --git a/.gitignore b/.gitignore
> : index 1a07bf7..a21ee1c 100644
> : --- a/.gitignore
> : +++ b/.gitignore
> : @@ -1,5 +1,5 @@
> :  *.[oa]
> : -*.so
> : +*.so*
> :  *.obj
> :  *.lib
> :  *.exp
> : @@ -9,3 +9,13 @@
> :  *.dmp
> :  *.swp
> :  .tags
> : +
> : +# CMake generated artefacts
> : +CMakeCache.txt
> : +CMakeFiles
> : +Makefile
> : +cmake_install.cmake
> : +compile_commands.json
> : +install_manifest.txt
> : +luajit-parse-memprof
> : +luajit.pc
> 
> Uh-oh, this ugly hack would be handled by single exclusion
> build*/
> if we would all use the same (idiomatic) approach for out-of-source
> build. But we do not yet accustomed to that, so... never mind!

I personally prefer mechanisms to policies: this approach allows one to
freely name so called <build> directory on his own e.g. <bindir>,
<tuta-lejit-sborka>, or even <qkrq>, that is my favourite one.
Furthermore this approach allows to ignore CMake output for both
out-of-source and in-source build. Such configuration is much more
flexible, IMHO, and leads to a neglible and well localized changes in
.gitignore. But, nevermind ;)

> 
> : diff --git a/CMakeLists.txt b/CMakeLists.txt
> : new file mode 100644
> : index 0000000..0dba5d8
> : --- /dev/null
> : +++ b/CMakeLists.txt
> : @@ -0,0 +1,261 @@
> : +# LuaJIT -- interpreter and JIT compiler for Lua language.
> : +# This is the main entry point for building, testing and
> : +# packaging the project.
> : +# Major portions taken verbatim or adapted from the uJIT.
> : +# Copyright (C) 2015-2019 IPONWEB Ltd.
> 
> 2019, IPONWEB?

This weekend Anton finally merged my PR[1] with the bump of copyright
year, so these notes have to be fixed now. As for the flower box per se,
you can see this practice is widely used by Mike for the sources adapted
of taken verbatim from PUC-Rio Lua sources. This is a nice gesture to
mention the origin of the work we incorporated from the public domain
into our trunk.

Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62ac369..1b1234b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,8 @@
 # This is the main entry point for building, testing and
 # packaging the project.
 # Major portions taken verbatim or adapted from the uJIT.
-# Copyright (C) 2015-2019 IPONWEB Ltd.
+# Copyright (C) 2020-2021 LuaVela Authors.
+# Copyright (C) 2015-2020 IPONWEB Ltd.
 
 # --- Initial setup ------------------------------------------------------------
 

================================================================================

> 
> ...
> : +# --- Fine-tuning cmake environment ---------------------------------------
> : -----
> : +
> : +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
> : +set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
> 
> Could you please remove this enforcement of CMAKE_EXPORT_COMPILE_COMMANDS here?
> Agreed that this is always a good idea to generate compile_commands.json. But 
> disagreed that we should enforce it automatically. This is developer choice to 
> either generate or not this compile database. (And it's slowing down a bit cmake
> generation phase on big projects. Which is not yet case here, but in any case)

Nice remark, thanks! Dropped this line, squashed, force-pushed to the
branch. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b1234b..9e0c0f4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,7 +31,6 @@ endif()
 # --- Fine-tuning cmake environment --------------------------------------------
 
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
 include(LuaJITUtils)
 include(SetVersion)

================================================================================

I'm not sure whether <compile_commands.json> entry should be also
removed from .gitignore, so please mention this explicitly if it should.

> 
> ...
> : +
> : +# Features from Lua 5.2 that are unlikely to break existing code
> : +# are enabled by default. Some other features that *might* break
> : +# some existing code (e.g. __pairs or os.execute() return values)
> : +# can be enabled here.
> : +# XXX: this does not provide full compatibility with Lua 5.2 at
> : +# this time.
> : +option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
> : +if(LUAJIT_LUA52COMPAT)
> : +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT)
> : +endif()
> 
> I do not know whether we do care that much about consistency of an option names
> or not care? But worth to mention that all other options do have ENABLE/DISABLE
> or HAS prefix in similar contexts, but here we do not use it that way, and it's
> simple LUAJIT_LUA52COMPAT. What about LUAJIT_ENABLE_LUA52COMPAT as it's 
> passed to compile options? (Not insist, but worth to note)

Oops, nice catch, thanks! For the record: yes, we do care, at least for
now. Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e0c0f4..af9f8e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -133,8 +133,8 @@ set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI)
 # can be enabled here.
 # XXX: this does not provide full compatibility with Lua 5.2 at
 # this time.
-option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
-if(LUAJIT_LUA52COMPAT)
+option(LUAJIT_ENABLE_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
+if(LUAJIT_ENABLE_LUA52COMPAT)
   AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT)
 endif()
 

================================================================================

> 

<snipped>

> : +
> : +# Switch to harder (and slower) hash function when a collision
> : +# chain in the string hash table exceeds certain length.
> : +option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON)
> : +if(LUAJIT_SMART_STRINGS)
> : +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1)
> : +endif()
> 
> The same note about lack of ENABLE prefix in the option name.

Well, again: we do care about consistency. Unfortunately, this option is
provided only in our fork, so the inconsistency you're talking about was
messed up years ago. I propose to port the build system as is now with
no changes in the option names, but this is a nice point to refactor
them and make them consistent in scope of a separate issue. Thoughts?

> 

<snipped>

> : --- /dev/null
> : +++ b/cmake/LuaJITUtils.cmake
> : @@ -0,0 +1,31 @@
> ...
> : diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake
> : new file mode 100644
> : index 0000000..fa455bb
> : --- /dev/null
> : +++ b/cmake/MakeSourceList.cmake
> : @@ -0,0 +1,47 @@
> : +# Major portions taken verbatim or adapted from the uJIT.
> : +# Copyright (C) 2015-2019 IPONWEB Ltd.
> : +#
> : +# make_source_list provides a convenient way to define a list of sources
> : +# and get a list of absolute paths.
> : +#
> : +# Example usage:
> : +#
> : +#   make_source_list(SOURCES_CORE
> : +#     SOURCES
> : +#       main.c
> : +#       test.c
> : +#       subdir/test2.c
> : +#   )
> : +#
> : +# This will give you the list:
> : +#    "<...>/main.c;<...>/test.c;<...>/subdir/test2.c"
> : +# (where `<...>` is ${CMAKE_CURRENT_SOURCE_DIR}).
> : +#
> : +# Absolute paths in `SOURCES` list don't get ${CMAKE_CURRENT_SOURCE_DIR}
> : +# prepended to them.
> : +
> 
> Very convenient macro below! Much respect to author!

Kudos to Elias Daler (I have already expressed my gratitude to him)!

> 

<snipped>

> 
> : diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> : new file mode 100644
> : index 0000000..260fc6b
> : --- /dev/null
> : +++ b/cmake/SetTargetFlags.cmake
> : @@ -0,0 +1,42 @@
> ...
> : +
> : +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS}")
> : +LuaJITArch(LUAJIT_ARCH "${TESTARCH}")
> : +
> : +# Target-specific compiler options.
> : +#
> : +# x86/x64 only: For GCC 4.2 or higher and if you don't intend to
> : +# distribute the binaries to a different machine you could also
> : +# use: -march=native.
> : +if(LUAJIT_ARCH STREQUAL "x86")
> : +  AppendFlags(TARGET_C_FLAGS -march=i686 -msse -msse2 -mfpmath=sse)
> : +endif()
> 
> FWIW -msse2 implicitly assumes -msse but if that way it used to be
> in makefiles than so be it. Don't need to "improve" it.

Yes, I tried to move everything making as few changes as possible. I believe
there are lots of places to be "modernized" later.

> ...
> 
> 
> : diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> : new file mode 100644
> : index 0000000..8ada1a4
> : --- /dev/null
> : +++ b/src/CMakeLists.txt
> : @@ -0,0 +1,391 @@
> : +# Building LuaJIT core: bootstrapping, VM, runtime, JIT compiler.
> : +# Major portions taken verbatim or adapted from the uJIT.
> : +# Copyright (C) 2015-2019 IPONWEB Ltd.
> 
> 2019 IPONWEB?

Ditto. Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 209b5f0..5724c8b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,7 @@
 # Building LuaJIT core: bootstrapping, VM, runtime, JIT compiler.
 # Major portions taken verbatim or adapted from the uJIT.
-# Copyright (C) 2015-2019 IPONWEB Ltd.
+# Copyright (C) 2020-2021 LuaVela Authors.
+# Copyright (C) 2015-2020 IPONWEB Ltd.
 
 # See the rationale in the root CMakeLists.txt.
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

================================================================================

> 

<snipped>

> 
> : +
> : +include(SetTargetFlags)
> : +list(APPEND TARGET_LIBS m)
> 
> ${TARGET_LIBS} below used as space separated list of words, it's probably
> bad idea to operate with it as list, because we end up in trace with something
> like
> 
>   ./third_party/luajit/src/CMakeLists.txt(302):  target_include_directories(luajit_static PRIVATE ./build/third_party/luajit/src )
>   ./third_party/luajit/src/CMakeLists.txt(305):  target_link_libraries(luajit_static libluajit_static dl;m )
> 

Hm, I'm not quite sure what is broken by such usage, but everything is
OK when I run <make> with VERBOSE=1. Here is the related part:
| $ make VERBOSE=1
| <...>
| [100%] Linking C executable luajit
| cd /tarantool-luajit/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/luajit_static.dir/link.txt --verbose=1
| /usr/bin/cc  -fomit-frame-pointer -fno-stack-protector -Wall  -rdynamic  -Wl,-E CMakeFiles/luajit_static.dir/luajit.c.o  -o luajit  libluajit.a -ldl -lm 
| make[2]: Leaving directory '/tarantool-luajit'
| [100%] Built target luajit_static
| <...>

> 

<snipped>

> : +# Compiling and linking CLIs.
> : +
> : +add_executable(luajit_static EXCLUDE_FROM_ALL ${CLI_SOURCES})
> : +set_target_properties(luajit_static PROPERTIES
> : +  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
> : +  COMPILE_FLAGS "${TARGET_C_FLAGS}"
> : +  LINK_FLAGS "${TARGET_BIN_FLAGS}"
> : +  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
> : +)
> : +target_include_directories(luajit_static PRIVATE
> : +  ${CMAKE_CURRENT_BINARY_DIR}
> : +)
> : +target_link_libraries(luajit_static libluajit_static ${TARGET_LIBS})
> : +
> : +add_executable(luajit_shared EXCLUDE_FROM_ALL ${CLI_SOURCES})
> : +set_target_properties(luajit_shared PROPERTIES
> : +  OUTPUT_NAME "${LUAJIT_CLI_NAME}"
> : +  COMPILE_FLAGS "${TARGET_C_FLAGS}"
> : +  LINK_FLAGS "${TARGET_BIN_FLAGS}"
> : +  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
> : +)
> : +target_include_directories(luajit_shared PRIVATE
> : +  ${CMAKE_CURRENT_BINARY_DIR}
> : +)
> : +target_link_libraries(luajit_shared libluajit_shared ${TARGET_LIBS})
> : +
> : +if(NOT BUILDMODE STREQUAL "dynamic")
> : +  set(LIBLUAJIT_STATIC_DEPS libluajit_static)
> : +endif()
> : +if(NOT BUILDMODE STREQUAL "static")
> : +  set(LIBLUAJIT_SHARED_DEPS libluajit_shared)
> : +endif()
> : +set(LIBLUAJIT_DEPS ${LIBLUAJIT_STATIC_DEPS} ${LIBLUAJIT_SHARED_DEPS})
> : +
> : +if(BUILDMODE STREQUAL "dynamic")
> : +  set(LUAJIT_DEPS luajit_shared)
> : +else()
> : +  set(LUAJIT_DEPS luajit_static)
> : +endif()
> : +
> : +add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
> : +add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
> : +
> : +install(TARGETS ${LUAJIT_DEPS}
> : +  RUNTIME
> : +  DESTINATION bin
> : +  COMPONENT luajit
> : +)
> 
> Here we have reasonable cmake complain:
> 
>   -- Configuring done
>   WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but
>   an install rule has been provided for it.  CMake does not define behavior for this case.
>   WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default
>   but an install rule has been provided for it.  CMake does not define behavior for this case.
> 

Well, I have no warning at all on my machine...
| $ cmake .
| -- The C compiler identification is GNU 8.3.0
| -- Check for working C compiler: /usr/bin/cc
| -- Check for working C compiler: /usr/bin/cc -- works
| -- Detecting C compiler ABI info
| -- Detecting C compiler ABI info - done
| -- Detecting C compile features
| -- Detecting C compile features - done
| -- [SetVersion] Reading version from VCS: v2.1.0-beta3-79-ge616d62
| -- The ASM compiler identification is GNU
| -- Found assembler: /usr/bin/cc
| -- Configuring done
| -- Generating done
| -- Build files have been written to: /tarantool-luajit

> There is no much point to install ${LIBLUAJIT_STATIC_DEPS} or ${LIBLUAJIT_SHARED_DEPS} if we have 
> excluded luajit_static and/or libluajit_shared from target all dependencies via EXCLUDE_FROM_ALL.

... however, I looked to the docs[2] and there is mentioned the fact
such behaviour is not defined and user is responsible to ensure whether
the corresponding artefacts are built prior to installing them. I
believed this machinery can be done on CMake side, but I forgot that
CMake is a crap. Wrapped all install rules with if/endif, squashed,
force-pushed to the branch. Diff is below:

================================================================================

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5724c8b..51e97a6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -338,21 +338,35 @@ set(LUAJIT_BINARY $<TARGET_FILE:${LUAJIT_DEPS}> PARENT_SCOPE)
 add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
 add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
 
-install(TARGETS ${LUAJIT_DEPS}
-  RUNTIME
-  DESTINATION bin
-  COMPONENT luajit
-)
-install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
-  ARCHIVE
-  DESTINATION lib
-  COMPONENT luajit
-)
-install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
-  LIBRARY
-  DESTINATION lib
-  COMPONENT luajit
-)
+# Unfortunately, CMake provides no guarantees for install commands
+# used for the targets excluded from <all> and obligues user to
+# handle this manually on his side. Hence check whether the
+# targets used below are presented for the chosen build mode.
+# See more info in CMake docs below:
+# https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html
+if(TARGET ${LUAJIT_DEPS})
+  install(TARGETS ${LUAJIT_DEPS}
+    RUNTIME
+    DESTINATION bin
+    COMPONENT luajit
+  )
+endif()
+
+if(TARGET ${LIBLUAJIT_STATIC_DEPS})
+  install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
+    ARCHIVE
+    DESTINATION lib
+    COMPONENT luajit
+  )
+endif()
+
+if(TARGET ${LIBLUAJIT_SHARED_DEPS})
+  install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
+    LIBRARY
+    DESTINATION lib
+    COMPONENT luajit
+  )
+endif()
 
 install(FILES
     ${CMAKE_CURRENT_SOURCE_DIR}/lua.h       # C API for Lua

================================================================================

> 
> : +install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
> : +  ARCHIVE
> : +  DESTINATION lib
> : +  COMPONENT luajit
> : +)
> : +install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
> : +  LIBRARY
> : +  DESTINATION lib
> : +  COMPONENT luajit
> : +)
> : +

<snipped>

> : diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> : new file mode 100644
> : index 0000000..f9ffc5e
> : --- /dev/null
> : +++ b/tools/CMakeLists.txt
> : @@ -0,0 +1,77 @@
> : +# Building tools for developing with uJIT.
> : +# Major portions taken verbatim or adapted from the uJIT.
> : +# Copyright (C) 2015-2019 IPONWEB Ltd.
> 
> 2019 IPONWEB?

Ditto. Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index af3de33..60535cd 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -1,6 +1,7 @@
 # Building tools for developing with uJIT.
 # Major portions taken verbatim or adapted from the uJIT.
-# Copyright (C) 2015-2019 IPONWEB Ltd.
+# Copyright (C) 2020-2021 LuaVela Authors.
+# Copyright (C) 2015-2020 IPONWEB Ltd.
 
 # See the rationale in the root CMakeLists.txt.
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

================================================================================

> 
> : +
> : +# See the rationale in the root CMakeLists.txt
> : +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> : +
> : +set(LUAJIT_TOOLS_DEPS)
> : +
> : +if(LUAJIT_DISABLE_MEMPROF)
> : +  message(STATUS "LuaJIT memory profiler support is disabled")
> : +else()
> : +  # XXX: Can use genex here since the value need to be evaluated
> : +  # on the configuration phase. Fortunately, we know the exact
> : +  # path where LuaJIT binary is located.
> : +  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
> : +  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> : +  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY
> : ESCAPE_QUOTES)
> : +
> : +  add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS
> : +    luajit-parse-memprof
> : +    memprof/humanize.lua
> : +    memprof/parse.lua
> : +    memprof.lua
> : +    utils/bufread.lua
> : +    utils/symtab.lua
> : +  )
> : +  list(APPEND LUAJIT_TOOLS_DEPS tools-parse-memprof)
> : +
> : +  install(FILES
> : +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/humanize.lua
> : +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof/parse.lua
> : +    DESTINATION ${LUAJIT_DATAROOTDIR}/memprof
> : +    PERMISSIONS
> : +      OWNER_READ OWNER_WRITE
> : +      GROUP_READ
> : +      WORLD_READ
> : +    COMPONENT tools-parse-memprof
> : +  )
> : +  install(FILES
> : +      ${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua
> : +      ${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua
> : +    DESTINATION ${LUAJIT_DATAROOTDIR}/utils
> : +    PERMISSIONS
> : +      OWNER_READ OWNER_WRITE
> : +      GROUP_READ
> : +      WORLD_READ
> : +    COMPONENT tools-parse-memprof
> : +  )
> : +  install(FILES
> : +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
> : +    DESTINATION ${LUAJIT_DATAROOTDIR}
> : +    PERMISSIONS
> : +      OWNER_READ OWNER_WRITE
> : +      GROUP_READ
> : +      WORLD_READ
> : +    COMPONENT tools-parse-memprof
> : +  )
> : +  install(CODE
> : +    # XXX: Since the auxiliary script need to be configured in
> : +    # other way it need to be reconfigured it prior to its
> : +    # installation. Unfortunately, we need to manually specify
> : +    # the installation path in <configure_file> command.
> : +    # Hope this script will be gone as a result of the issue below
> : +    # https://github.com/tarantool/tarantool/issues/5688.
> : +    "
> : +      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
> : +      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
> : +      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
> : +        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY
> : ESCAPE_QUOTES)
> : +      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-
> : parse-memprof\")
> : +    "
> : +    COMPONENT tools-parse-memprof
> : +  )
> 
> Шайтан!

Спасибо, я старался сделать этот кусок таким образом, чтобы он
мотивировать в срочном порядке сделать 5688.

Waytan it is! \m/

> 
> : +endif()
> : +
> : +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})
> : --
> : 2.25.0
> 
> Regards,
> Timur
> 

I also fixed all other occurences related to "2019, IPONWEB?" comments.
Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake
index fa455bb..393777c 100644
--- a/cmake/MakeSourceList.cmake
+++ b/cmake/MakeSourceList.cmake
@@ -1,5 +1,6 @@
 # Major portions taken verbatim or adapted from the uJIT.
-# Copyright (C) 2015-2019 IPONWEB Ltd.
+# Copyright (C) 2020-2021 LuaVela Authors.
+# Copyright (C) 2015-2020 IPONWEB Ltd.
 #
 # make_source_list provides a convenient way to define a list of sources
 # and get a list of absolute paths.
diff --git a/cmake/SetVersion.cmake b/cmake/SetVersion.cmake
index 3f0247c..ed5815d 100644
--- a/cmake/SetVersion.cmake
+++ b/cmake/SetVersion.cmake
@@ -1,6 +1,7 @@
 # Find, check and set LuaJIT's version from a VCS tag.
 # Major portions taken verbatim or adapted from the uJIT.
-# Copyright (C) 2015-2019 IPONWEB Ltd.
+# Copyright (C) 2020-2021 LuaVela Authors.
+# Copyright (C) 2015-2020 IPONWEB Ltd.
 
 function(SetVersion version majver minver patchver tweakver prerel)
   find_package(Git QUIET REQUIRED)

================================================================================

[1]: https://github.com/luavela/luavela/pull/36
[2]: https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake
  2021-02-04 22:52   ` Timur Safin via Tarantool-patches
@ 2021-02-08 15:57     ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 15:57 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

Thanks for your review!

On 05.02.21, Timur Safin wrote:
> LGTM as obvious!

Added your tag:
| Reviewed-by: Timur Safin <tsafin@tarantool.org>

> 

<snipped>

> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
       [not found]   ` <012f01d6fe1a$a2aa6890$e7ff39b0$@tarantool.org>
@ 2021-02-08 15:57     ` Igor Munkin via Tarantool-patches
       [not found]     ` <2c495492-50f4-acfd-ad66-2cb44abb5fa1@tarantool.org>
  1 sibling, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 15:57 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

Thanks for your review!

On 08.02.21, Timur Safin wrote:
> Well, nobody has asked me, abut this particular 
> Patch, but if you were worrying about missing my reply here then

Your reply is not missing, but is highly valuable!

> 
> LGTM

Hence added your tag:
| Reviewed-by: Timur Safin <tsafin@tarantool.org>

> 
> Timur
> 

<snipped>

> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
       [not found]     ` <2c495492-50f4-acfd-ad66-2cb44abb5fa1@tarantool.org>
  2021-02-08 15:40       ` Sergey Bronnikov via Tarantool-patches
@ 2021-02-08 15:58       ` Igor Munkin via Tarantool-patches
  1 sibling, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 15:58 UTC (permalink / raw)
  To: Sergey Bronnikov; +Cc: tarantool-patches

Sergey,

Thanks for your review!

On 08.02.21, Sergey Bronnikov wrote:
> Thanks for the patch!
> 

Added your tag:
| Reviewed-by: Sergey Bronnikov <sergeyb@tarantool.org>

> LGTM
> 

<snipped>


-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-08 15:05   ` Timur Safin via Tarantool-patches
@ 2021-02-08 16:29     ` Igor Munkin via Tarantool-patches
  2021-02-09  8:16       ` Timur Safin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-08 16:29 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

Thanks for your review!

On 08.02.21, Timur Safin wrote:
> Some code changes proposals below...
> 
> : From: Igor Munkin <imun@tarantool.org>
> : Subject: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
> : 
> : diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-
> : tests/CMakeLists.txt
> : new file mode 100644
> : index 0000000..0be4b34
> : --- /dev/null
> : +++ b/test/tarantool-tests/CMakeLists.txt
> : @@ -0,0 +1,92 @@
> : +# Test suite that has been moved from Tarantool repository in
> : +# scope of https://github.com/tarantool/tarantool/issues/4478.
> : +
> : +# See the rationale in the root CMakeLists.txt.
> : +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> : +
> : +find_program(PROVE prove)
> : +if(NOT PROVE)
> : +  message(WARNING "`prove' is not found, so tarantool-tests target is not
> : generated")
> : +  return()
> : +endif()
> : +
> : +macro(BuildTestLib lib sources)
> : +  add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
> : +  target_include_directories(${lib} PRIVATE
> : +    ${LUAJIT_SOURCE_DIR}
> : +    ${CMAKE_CURRENT_SOURCE_DIR}
> : +  )
> ...
> : +  # XXX: Append the lib to be built to the dependecy list.
> : +  # Unfortunately, CMake is a crap and there is no other way to
> : +  # extend the list in parent scope but join two strings with
> : +  # semicolon. If one finds the normal way to make it work, feel
> : +  # free to reach me.
> : +  set(TESTLIBS "${lib};${TESTLIBS}" PARENT_SCOPE)
> 
> I don't like this. It reminds me of bad examples of this note
> in the libev code like "this is so uncontrollably lame" which
> actually distract users. We should rather put comments in more
> neutral way (IMVHO). 

Unfortunately... CMake is a crap and I can't fix it. Well, honestly I
don't want to fix it. But you're right: I can fix all these comments
(athough I don't really want to). I have no idea how to express this in
a more neutral way, so I propose the following:
1. s/CMake is a crap/there is no convenient way to make it in CMake/g.
2. Leave everything else unchanged.

This is not only emotions. Such comments prevent one from unintentional
refactoring of such fragile places with no failures and also from
bothering the oldies with the questions kinda "dude, why is this done so
badly". In other words, primarily I have left this for the history.

If you're OK, then I'll fix the way described above.

> 
> : +  # Add the directory where the lib is built to the LUA_CPATH
> : +  # environment variable, so interpreter 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 the
> : +  # list. I have no idea what is wrong with this tool, but 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)
> : +  # 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)
> : +endmacro()
> : +
> : +add_subdirectory(gh-4427-ffi-sandwich)
> : +add_subdirectory(lj-flush-on-trace)
> : +add_subdirectory(misclib-getmetrics-capi)
> 
> I liked you introduced globs for test files addition (blow), 
> but unfortunately you didn't complete this with subdirectory addition

I have thought about it for some time, and I have a strong rationale (at
least for me) to not introducing such change: this doesn't work whether
there are directories inside containing no tests. Furthermore, we're
going to re-implement several C tests, so I would like to leave
everything as it is (if you don't mind) and return to this place later.

> 
> Please see my proposed patch (with reworded comments and new macro) here https://gist.github.com/tsafin/6c7505c0c764ab2b474667bf0d65fb45.
> 

<snipped>

> 
> Regards,
> Timur
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-08 16:29     ` Igor Munkin via Tarantool-patches
@ 2021-02-09  8:16       ` Timur Safin via Tarantool-patches
  2021-02-09  8:43         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-09  8:16 UTC (permalink / raw)
  To: 'Igor Munkin'; +Cc: tarantool-patches

: From: Igor Munkin <imun@tarantool.org>
: Subject: Re: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
: 
: Timur,
: 
: Thanks for your review!
: 
: >
: > I don't like this. It reminds me of bad examples of this note
: > in the libev code like "this is so uncontrollably lame" which
: > actually distract users. We should rather put comments in more
: > neutral way (IMVHO).
: 
: Unfortunately... CMake is a crap and I can't fix it. Well, honestly I
: don't want to fix it. But you're right: I can fix all these comments
: (athough I don't really want to). I have no idea how to express this in
: a more neutral way, so I propose the following:
: 1. s/CMake is a crap/there is no convenient way to make it in CMake/g.
: 2. Leave everything else unchanged.

Hmm, ok.

: 
: This is not only emotions. Such comments prevent one from unintentional
: refactoring of such fragile places with no failures and also from
: bothering the oldies with the questions kinda "dude, why is this done so
: badly". In other words, primarily I have left this for the history.
: 
: If you're OK, then I'll fix the way described above.
: 
: >
: > : +  # Add the directory where the lib is built to the LUA_CPATH
: > : +  # environment variable, so interpreter 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 the
: > : +  # list. I have no idea what is wrong with this tool, but 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)
: > : +  # 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)
: > : +endmacro()
: > : +
: > : +add_subdirectory(gh-4427-ffi-sandwich)
: > : +add_subdirectory(lj-flush-on-trace)
: > : +add_subdirectory(misclib-getmetrics-capi)
: >
: > I liked you introduced globs for test files addition (blow),
: > but unfortunately you didn't complete this with subdirectory addition
: 
: I have thought about it for some time, and I have a strong rationale (at
: least for me) to not introducing such change: this doesn't work whether
: there are directories inside containing no tests. Furthermore, we're
: going to re-implement several C tests, so I would like to leave
: everything as it is (if you don't mind) and return to this place later.

Ok, if you plan to refactor it, because today it looks inconsistent a bit.

: 
: >
: > Please see my proposed patch (with reworded comments and new macro) here
: https://gist.github.com/tsafin/6c7505c0c764ab2b474667bf0d65fb45.
: >
: 
: <snipped>
: 
: >
: > Regards,
: > Timur
: >
: 
: --
: Best regards,
: IM

Regards,
Timur


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-09  8:16       ` Timur Safin via Tarantool-patches
@ 2021-02-09  8:43         ` Igor Munkin via Tarantool-patches
  2021-02-09 13:59           ` Timur Safin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-09  8:43 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

On 09.02.21, Timur Safin wrote:
> : From: Igor Munkin <imun@tarantool.org>
> : Subject: Re: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
> : 
> : Timur,
> : 
> : Thanks for your review!
> : 
> : >
> : > I don't like this. It reminds me of bad examples of this note
> : > in the libev code like "this is so uncontrollably lame" which
> : > actually distract users. We should rather put comments in more
> : > neutral way (IMVHO).
> : 
> : Unfortunately... CMake is a crap and I can't fix it. Well, honestly I
> : don't want to fix it. But you're right: I can fix all these comments
> : (athough I don't really want to). I have no idea how to express this in
> : a more neutral way, so I propose the following:
> : 1. s/CMake is a crap/there is no convenient way to make it in CMake/g.
> : 2. Leave everything else unchanged.
> 
> Hmm, ok.

Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
index 011a630..59094d0 100644
--- a/src/host/CMakeLists.txt
+++ b/src/host/CMakeLists.txt
@@ -44,7 +44,7 @@ add_executable(buildvm EXCLUDE_FROM_ALL
   buildvm_fold.c
   buildvm_lib.c
   buildvm_peobj.c
-  # XXX: Unfortunately CMake is a crap. I failed to specify
+  # XXX: Unfortunately, there is no convenient way to specify
   # autogenerated host/buildvm_arch.h as a dependency for
   # host/buildvm.c, so I simply explicitly mentioned it in this
   # *sources* list.
diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index 0be4b34..5345e12 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -38,8 +38,8 @@ macro(BuildTestLib lib sources)
     )
   endif()
   # XXX: Append the lib to be built to the dependecy list.
-  # Unfortunately, CMake is a crap and there is no other way to
-  # extend the list in parent scope but join two strings with
+  # Unfortunately, there is no convenient way in CMake to extend
+  # the list in parent scope other than join two strings with
   # semicolon. If one finds the normal way to make it work, feel
   # free to reach me.
   set(TESTLIBS "${lib};${TESTLIBS}" PARENT_SCOPE)

================================================================================

Small exercise for self-check:
| $ grep -rF 'CMake is a crap' | wc -l
| 0

> 
> : 
> : This is not only emotions. Such comments prevent one from unintentional
> : refactoring of such fragile places with no failures and also from
> : bothering the oldies with the questions kinda "dude, why is this done so
> : badly". In other words, primarily I have left this for the history.
> : 
> : If you're OK, then I'll fix the way described above.
> : 
> : >
> : > : +  # Add the directory where the lib is built to the LUA_CPATH
> : > : +  # environment variable, so interpreter 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 the
> : > : +  # list. I have no idea what is wrong with this tool, but 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)
> : > : +  # 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)
> : > : +endmacro()
> : > : +
> : > : +add_subdirectory(gh-4427-ffi-sandwich)
> : > : +add_subdirectory(lj-flush-on-trace)
> : > : +add_subdirectory(misclib-getmetrics-capi)
> : >
> : > I liked you introduced globs for test files addition (blow),
> : > but unfortunately you didn't complete this with subdirectory addition
> : 
> : I have thought about it for some time, and I have a strong rationale (at
> : least for me) to not introducing such change: this doesn't work whether
> : there are directories inside containing no tests. Furthermore, we're
> : going to re-implement several C tests, so I would like to leave
> : everything as it is (if you don't mind) and return to this place later.
> 
> Ok, if you plan to refactor it, because today it looks inconsistent a bit.

I personally also don't like to explicitly mention new auxiliary libs in
tests: it makes backporting harder, it broke CI several times, so we
will definitely refactor the current approach after incorporating other
tests in public domain[1].

> 
> : 
> : >
> : > Please see my proposed patch (with reworded comments and new macro) here
> : https://gist.github.com/tsafin/6c7505c0c764ab2b474667bf0d65fb45.
> : >
> : 
> : <snipped>
> : 
> : >
> : > Regards,
> : > Timur
> : >
> : 
> : --
> : Best regards,
> : IM
> 
> Regards,
> Timur
> 

[1]: https://github.com/tarantool/tarantool/issues/4473

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
@ 2021-02-09 11:38   ` Sergey Kaplun via Tarantool-patches
  2021-02-09 12:47     ` Igor Munkin via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-09 11:38 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!
LGTM, except 4 comments about memory profiler parser below.

On 02.02.21, Igor Munkin wrote:
> Since the build machinery is going to be ported to CMake there would be
> Makefile names clashing. This change renames the original build system
> (and a couple of auxiliary files requiring configuring) to keep all this
> machinery working.
> 
> As a result of these changes one need to explicitly specify the Makefile
> in the build command:
> | make -f Makefile.original <options>
> 
> Needed for tarantool/tarantool#4862
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
>  Makefile => Makefile.original               | 44 +++++++++++++--------
>  etc/{luajit.pc => luajit.pc.in}             |  4 +-
>  src/{Makefile.dep => Makefile.dep.original} |  0
>  src/{Makefile => Makefile.original}         |  4 +-
>  tools/luajit-parse-memprof                  |  9 -----
>  tools/luajit-parse-memprof.in               |  6 +++
>  6 files changed, 38 insertions(+), 29 deletions(-)
>  rename Makefile => Makefile.original (85%)
>  rename etc/{luajit.pc => luajit.pc.in} (91%)
>  rename src/{Makefile.dep => Makefile.dep.original} (100%)
>  rename src/{Makefile => Makefile.original} (99%)
>  delete mode 100755 tools/luajit-parse-memprof
>  create mode 100644 tools/luajit-parse-memprof.in
> 
> diff --git a/Makefile b/Makefile.original
> similarity index 85%
> rename from Makefile
> rename to Makefile.original
> index 61967df..b85d4bf 100644
> --- a/Makefile
> +++ b/Makefile.original
> @@ -85,10 +85,10 @@ INSTALL_X= install -m 0755

<snipped>

> @@ -185,13 +185,25 @@ uninstall:
>  
>  ##############################################################################
>  
> -amalg:
> +amalg: tools
>  	@echo "Building LuaJIT $(VERSION)"
> -	$(MAKE) -C src amalg
> +	$(MAKE) -C src -f Makefile.original amalg
>  
>  clean:
> -	$(MAKE) -C src clean
> +	$(RM) tools/$(FILE_TMEMPROF)
> +	$(MAKE) -C src -f Makefile.original clean
>  
> -.PHONY: all install amalg clean
> +tools: tools/$(FILE_TMEMPROF)
> +
> +# FIXME: This is an ugly hack to manually configure an auxiliary
> +# tools/luajit-parse-memprof. I hope this file will have gone away

1. I suggest the following rewording ("I hope" is too personal :)):
s/I hope this file will have gone away/This file should go away/

> +# in scope of https://github.com/tarantool/tarantool/issues/5688.
> +tools/$(FILE_TMEMPROF):
> +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \

2. @LUAJIT_BIN@ looks more convenient, doesn't it?

> +	     $@.in > $@
> +	@chmod +x $@
> +
> +.PHONY: all install amalg clean tools
>  
>  ##############################################################################
> diff --git a/etc/luajit.pc b/etc/luajit.pc.in
> similarity index 91%
> rename from etc/luajit.pc
> rename to etc/luajit.pc.in
> index a78f174..f32385d 100644
> --- a/etc/luajit.pc
> +++ b/etc/luajit.pc.in
> @@ -5,8 +5,8 @@ relver=0

<snipped>

> diff --git a/src/Makefile.dep b/src/Makefile.dep.original
> similarity index 100%
> rename from src/Makefile.dep
> rename to src/Makefile.dep.original
> diff --git a/src/Makefile b/src/Makefile.original
> similarity index 99%
> rename from src/Makefile
> rename to src/Makefile.original
> index 825b01c..502504c 100644
> --- a/src/Makefile
> +++ b/src/Makefile.original

<snipped>

> diff --git a/tools/luajit-parse-memprof b/tools/luajit-parse-memprof
> deleted file mode 100755

<snipped>

> diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> new file mode 100644
> index 0000000..8867202
> --- /dev/null
> +++ b/tools/luajit-parse-memprof.in
> @@ -0,0 +1,6 @@
> +#!/bin/bash
> +#
> +# Launcher for memprof parser.
> +
> +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
> +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@

3. Unfortunately, your solution doesn't work for me:

| $ git log --oneline -n1
| 7badb7e (HEAD) build: preserve the original build system
| $ make -f Makefile.original  -j
| ==== Building LuaJIT 2.1.0-beta3 ====
| ...
| ==== Successfully built LuaJIT 2.1.0-beta3 ====

Side note: I suppose it is nothing bad to add corresponding lines about
tools building. At least it simplifies build debugging.
Feel free to ignore.

| $ tools/luajit-parse-memprof /tmp/memprof_memleak.bin; echo -e "\n"; cat tools/luajit-parse-memprof
| tools/luajit-parse-memprof: line 5: /home/burii/reviews/luajit/cmake/tools/memprof.lua: Permission denied
|
| #!/bin/bash
| #
| # Launcher for memprof parser.
|
| LUA_PATH="/home/burii/reviews/luajit/cmake/tools/?.lua;;" \
|          /home/burii/reviews/luajit/cmake/tools/memprof.lua $@

This patch is working for me. But I am not bash|make guru :).

| diff --git a/Makefile.original b/Makefile.original
| index b85d4bf..877398a 100644
| --- a/Makefile.original
| +++ b/Makefile.original
| @@ -199,8 +199,8 @@ tools: tools/$(FILE_TMEMPROF)
|  # tools/luajit-parse-memprof. I hope this file will have gone away
|  # in scope of https://github.com/tarantool/tarantool/issues/5688.
|  tools/$(FILE_TMEMPROF):
| -        @sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
| -             -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
| +        @sed -e "s|@LUAJIT_TOOLS_DIR@|`realpath tools`|" \
| +             -e "s|@LUAJIT_TOOLS_BIN@|`realpath src/luajit`|" \
|               $@.in > $@
|          @chmod +x $@
|  

4. Please, create separate commit to tools-related changes.
Also, I suppose, it would be nice to add <tools/luajit-parse-memprof>
to <.gitignore> as far as it's generated. These lines may be confusing:

| $ git status
| HEAD detached at 7badb7e
| Untracked files:
|   (use "git add <file>..." to include in what will be committed)
|         tools/luajit-parse-memprof

> -- 
> 2.25.0
> 

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-09 11:38   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-09 12:47     ` Igor Munkin via Tarantool-patches
  2021-02-09 14:45       ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-09 12:47 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for your review!

On 09.02.21, Sergey Kaplun wrote:
> Hi, Igor!
> 
> Thanks for the patch!
> LGTM, except 4 comments about memory profiler parser below.

I have several questions, so postponed your Ack a bit.

> 
> On 02.02.21, Igor Munkin wrote:
> > Since the build machinery is going to be ported to CMake there would be
> > Makefile names clashing. This change renames the original build system
> > (and a couple of auxiliary files requiring configuring) to keep all this
> > machinery working.
> > 
> > As a result of these changes one need to explicitly specify the Makefile
> > in the build command:
> > | make -f Makefile.original <options>
> > 
> > Needed for tarantool/tarantool#4862
> > 
> > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > ---
> >  Makefile => Makefile.original               | 44 +++++++++++++--------
> >  etc/{luajit.pc => luajit.pc.in}             |  4 +-
> >  src/{Makefile.dep => Makefile.dep.original} |  0
> >  src/{Makefile => Makefile.original}         |  4 +-
> >  tools/luajit-parse-memprof                  |  9 -----
> >  tools/luajit-parse-memprof.in               |  6 +++
> >  6 files changed, 38 insertions(+), 29 deletions(-)
> >  rename Makefile => Makefile.original (85%)
> >  rename etc/{luajit.pc => luajit.pc.in} (91%)
> >  rename src/{Makefile.dep => Makefile.dep.original} (100%)
> >  rename src/{Makefile => Makefile.original} (99%)
> >  delete mode 100755 tools/luajit-parse-memprof
> >  create mode 100644 tools/luajit-parse-memprof.in
> > 
> > diff --git a/Makefile b/Makefile.original
> > similarity index 85%
> > rename from Makefile
> > rename to Makefile.original
> > index 61967df..b85d4bf 100644
> > --- a/Makefile
> > +++ b/Makefile.original
> > @@ -85,10 +85,10 @@ INSTALL_X= install -m 0755
> 
> <snipped>
> 
> > @@ -185,13 +185,25 @@ uninstall:
> >  
> >  ##############################################################################
> >  
> > -amalg:
> > +amalg: tools
> >  	@echo "Building LuaJIT $(VERSION)"
> > -	$(MAKE) -C src amalg
> > +	$(MAKE) -C src -f Makefile.original amalg
> >  
> >  clean:
> > -	$(MAKE) -C src clean
> > +	$(RM) tools/$(FILE_TMEMPROF)
> > +	$(MAKE) -C src -f Makefile.original clean
> >  
> > -.PHONY: all install amalg clean
> > +tools: tools/$(FILE_TMEMPROF)
> > +
> > +# FIXME: This is an ugly hack to manually configure an auxiliary
> > +# tools/luajit-parse-memprof. I hope this file will have gone away
> 
> 1. I suggest the following rewording ("I hope" is too personal :)):
> s/I hope this file will have gone away/This file should go away/

Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/Makefile.original b/Makefile.original
index b85d4bf..c3172f0 100644
--- a/Makefile.original
+++ b/Makefile.original
@@ -196,8 +196,8 @@ clean:
 tools: tools/$(FILE_TMEMPROF)
 
 # FIXME: This is an ugly hack to manually configure an auxiliary
-# tools/luajit-parse-memprof. I hope this file will have gone away
-# in scope of https://github.com/tarantool/tarantool/issues/5688.
+# tools/luajit-parse-memprof. This file should go away in scope of
+# https://github.com/tarantool/tarantool/issues/5688.
 tools/$(FILE_TMEMPROF):
 	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
 	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \

================================================================================

> 
> > +# in scope of https://github.com/tarantool/tarantool/issues/5688.
> > +tools/$(FILE_TMEMPROF):
> > +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> 
> 2. @LUAJIT_BIN@ looks more convenient, doesn't it?

It doesn't for me. Why does the current naming look inconvenient to you?

> 
> > +	     $@.in > $@
> > +	@chmod +x $@
> > +
> > +.PHONY: all install amalg clean tools
> >  
> >  ##############################################################################

<snipped>

> > diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> > new file mode 100644
> > index 0000000..8867202
> > --- /dev/null
> > +++ b/tools/luajit-parse-memprof.in
> > @@ -0,0 +1,6 @@
> > +#!/bin/bash
> > +#
> > +# Launcher for memprof parser.
> > +
> > +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
> > +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
> 
> 3. Unfortunately, your solution doesn't work for me:

Crap, I believe I've fixed this.

> 
> | $ git log --oneline -n1
> | 7badb7e (HEAD) build: preserve the original build system
> | $ make -f Makefile.original  -j
> | ==== Building LuaJIT 2.1.0-beta3 ====
> | ...
> | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> 
> Side note: I suppose it is nothing bad to add corresponding lines about
> tools building. At least it simplifies build debugging.
> Feel free to ignore.

One can adjust this for debugging. Otherwise there is no need to see
this output. We can use those hacks with Q/E, but I hope this part will
have gone in the nearest future.

> 
> | $ tools/luajit-parse-memprof /tmp/memprof_memleak.bin; echo -e "\n"; cat tools/luajit-parse-memprof
> | tools/luajit-parse-memprof: line 5: /home/burii/reviews/luajit/cmake/tools/memprof.lua: Permission denied
> |
> | #!/bin/bash
> | #
> | # Launcher for memprof parser.
> |
> | LUA_PATH="/home/burii/reviews/luajit/cmake/tools/?.lua;;" \
> |          /home/burii/reviews/luajit/cmake/tools/memprof.lua $@
> 
> This patch is working for me. But I am not bash|make guru :).

Heh, try your patch on a clean repo: unfortunately it works neither. The
root cause is the lack of <src/luajit> on configuration phase. I added
the corresponding dependency for this rule. Fixed, squashed,
force-pushed to the branch. Diff is below:

================================================================================

diff --git a/Makefile.original b/Makefile.original
index c3172f0..33dc2ed 100644
--- a/Makefile.original
+++ b/Makefile.original
@@ -198,7 +198,7 @@ tools: tools/$(FILE_TMEMPROF)
 # FIXME: This is an ugly hack to manually configure an auxiliary
 # tools/luajit-parse-memprof. This file should go away in scope of
 # https://github.com/tarantool/tarantool/issues/5688.
-tools/$(FILE_TMEMPROF):
+tools/$(FILE_TMEMPROF): src/luajit
 	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
 	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
 	     $@.in > $@

================================================================================

After this patch everything is fine.

> 
> | diff --git a/Makefile.original b/Makefile.original
> | index b85d4bf..877398a 100644
> | --- a/Makefile.original
> | +++ b/Makefile.original
> | @@ -199,8 +199,8 @@ tools: tools/$(FILE_TMEMPROF)
> |  # tools/luajit-parse-memprof. I hope this file will have gone away
> |  # in scope of https://github.com/tarantool/tarantool/issues/5688.
> |  tools/$(FILE_TMEMPROF):
> | -        @sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> | -             -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> | +        @sed -e "s|@LUAJIT_TOOLS_DIR@|`realpath tools`|" \
> | +             -e "s|@LUAJIT_TOOLS_BIN@|`realpath src/luajit`|" \
> |               $@.in > $@
> |          @chmod +x $@
> |  
> 
> 4. Please, create separate commit to tools-related changes.

For what?

> Also, I suppose, it would be nice to add <tools/luajit-parse-memprof>
> to <.gitignore> as far as it's generated. These lines may be confusing:

This is added in the next patch, but I'm not against moving it to this
one. Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/.gitignore b/.gitignore
index 1a07bf7..fc9c31e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,6 @@
 *.dmp
 *.swp
 .tags
+
+# Configured runner for LuaJIT memprof parser
+tools/luajit-parse-memprof

================================================================================

> 
> | $ git status
> | HEAD detached at 7badb7e
> | Untracked files:
> |   (use "git add <file>..." to include in what will be committed)
> |         tools/luajit-parse-memprof
> 
> > -- 
> > 2.25.0
> > 
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
@ 2021-02-09 13:55       ` Timur Safin via Tarantool-patches
  2021-02-09 15:09         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-09 13:55 UTC (permalink / raw)
  To: 'Igor Munkin'; +Cc: tarantool-patches

LGTM, if you need a shorter answer, but there are some further comments below...


: From: Igor Munkin <imun@tarantool.org>
: Subject: Re: [PATCH luajit 2/5] build: replace GNU Make with CMake
: 
: > : +
: > : +# CMake generated artefacts
: > : +CMakeCache.txt
: > : +CMakeFiles
: > : +Makefile
: > : +cmake_install.cmake
: > : +compile_commands.json
: > : +install_manifest.txt
: > : +luajit-parse-memprof
: > : +luajit.pc
: >
: > Uh-oh, this ugly hack would be handled by single exclusion
: > build*/
: > if we would all use the same (idiomatic) approach for out-of-source
: > build. But we do not yet accustomed to that, so... never mind!
: 
: I personally prefer mechanisms to policies: this approach allows one to
: freely name so called <build> directory on his own e.g. <bindir>,
: <tuta-lejit-sborka>, or even <qkrq>, that is my favourite one.
: Furthermore this approach allows to ignore CMake output for both
: out-of-source and in-source build. Such configuration is much more
: flexible, IMHO, and leads to a neglible and well localized changes in
: .gitignore. But, nevermind ;)

Ok, most of those names are generic enough as generated by cmake,
so it's a good idea to exclude them. 
...
: 
: > : +
: > : +# Switch to harder (and slower) hash function when a collision
: > : +# chain in the string hash table exceeds certain length.
: > : +option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON)
: > : +if(LUAJIT_SMART_STRINGS)
: > : +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1)
: > : +endif()
: >
: > The same note about lack of ENABLE prefix in the option name.
: 
: Well, again: we do care about consistency. Unfortunately, this option is
: provided only in our fork, so the inconsistency you're talking about was
: messed up years ago. I propose to port the build system as is now with
: no changes in the option names, but this is a nice point to refactor
: them and make them consistent in scope of a separate issue. Thoughts?

Ok, then leave them as is. This patchset supposed to be refactoring of 
what is already there. 
...
: >
: > FWIW -msse2 implicitly assumes -msse but if that way it used to be
: > in makefiles than so be it. Don't need to "improve" it.
: 
: Yes, I tried to move everything making as few changes as possible. I believe
: there are lots of places to be "modernized" later.

Yup, we should leave it as is today.
...
: 
: >
: > : +
: > : +include(SetTargetFlags)
: > : +list(APPEND TARGET_LIBS m)
: >
: > ${TARGET_LIBS} below used as space separated list of words, it's probably
: > bad idea to operate with it as list, because we end up in trace with
: something
: > like
: >
: >   ./third_party/luajit/src/CMakeLists.txt(302):
: target_include_directories(luajit_static PRIVATE
: ./build/third_party/luajit/src )
: >   ./third_party/luajit/src/CMakeLists.txt(305):
: target_link_libraries(luajit_static libluajit_static dl;m )
: >
: 
: Hm, I'm not quite sure what is broken by such usage, but everything is
: OK when I run <make> with VERBOSE=1. Here is the related part:
: | $ make VERBOSE=1
: | <...>
: | [100%] Linking C executable luajit
: | cd /tarantool-luajit/src && /usr/bin/cmake -E cmake_link_script
: CMakeFiles/luajit_static.dir/link.txt --verbose=1
: | /usr/bin/cc  -fomit-frame-pointer -fno-stack-protector -Wall  -rdynamic  -
: Wl,-E CMakeFiles/luajit_static.dir/luajit.c.o  -o luajit  libluajit.a -ldl -
: lm
: | make[2]: Leaving directory '/tarantool-luajit'
: | [100%] Built target luajit_static
: | <...>

Ok then, that's probably means that target_link_libraries() is expecting list 
at that place, and this works as expected. So, never mind. 
...
: >
: > Here we have reasonable cmake complain:
: >
: >   -- Configuring done
: >   WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be
: built by default but
: >   an install rule has been provided for it.  CMake does not define
: behavior for this case.
: >   WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not
: be built by default
: >   but an install rule has been provided for it.  CMake does not define
: behavior for this case.
: >
: 
: Well, I have no warning at all on my machine...

It's cmake 3.13.4 here, may be warning is version dependent. 

: | $ cmake .
: | -- The C compiler identification is GNU 8.3.0
: | -- Check for working C compiler: /usr/bin/cc
: | -- Check for working C compiler: /usr/bin/cc -- works
: | -- Detecting C compiler ABI info
: | -- Detecting C compiler ABI info - done
: | -- Detecting C compile features
: | -- Detecting C compile features - done
: | -- [SetVersion] Reading version from VCS: v2.1.0-beta3-79-ge616d62
: | -- The ASM compiler identification is GNU
: | -- Found assembler: /usr/bin/cc
: | -- Configuring done
: | -- Generating done
: | -- Build files have been written to: /tarantool-luajit
: 
: > There is no much point to install ${LIBLUAJIT_STATIC_DEPS} or
: ${LIBLUAJIT_SHARED_DEPS} if we have
: > excluded luajit_static and/or libluajit_shared from target all
: dependencies via EXCLUDE_FROM_ALL.
: 
: ... however, I looked to the docs[2] and there is mentioned the fact
: such behaviour is not defined and user is responsible to ensure whether
: the corresponding artefacts are built prior to installing them. I
: believed this machinery can be done on CMake side, but I forgot that
: CMake is a crap. Wrapped all install rules with if/endif, squashed,
: force-pushed to the branch. Diff is below:
: 
: ============================================================================
: ====
: 
: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
: index 5724c8b..51e97a6 100644
: --- a/src/CMakeLists.txt
: +++ b/src/CMakeLists.txt
: @@ -338,21 +338,35 @@ set(LUAJIT_BINARY $<TARGET_FILE:${LUAJIT_DEPS}>
: PARENT_SCOPE)
:  add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
:  add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
: 
: -install(TARGETS ${LUAJIT_DEPS}
: -  RUNTIME
: -  DESTINATION bin
: -  COMPONENT luajit
: -)
: -install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
: -  ARCHIVE
: -  DESTINATION lib
: -  COMPONENT luajit
: -)
: -install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
: -  LIBRARY
: -  DESTINATION lib
: -  COMPONENT luajit
: -)
: +# Unfortunately, CMake provides no guarantees for install commands
: +# used for the targets excluded from <all> and obligues user to
: +# handle this manually on his side. Hence check whether the
: +# targets used below are presented for the chosen build mode.
: +# See more info in CMake docs below:
: +# https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html
: +if(TARGET ${LUAJIT_DEPS})
: +  install(TARGETS ${LUAJIT_DEPS}
: +    RUNTIME
: +    DESTINATION bin
: +    COMPONENT luajit
: +  )
: +endif()
: +
: +if(TARGET ${LIBLUAJIT_STATIC_DEPS})
: +  install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
: +    ARCHIVE
: +    DESTINATION lib
: +    COMPONENT luajit
: +  )
: +endif()
: +
: +if(TARGET ${LIBLUAJIT_SHARED_DEPS})
: +  install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
: +    LIBRARY
: +    DESTINATION lib
: +    COMPONENT luajit
: +  )
: +endif()

Noice!


Best Regards,
Timur


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-09  8:43         ` Igor Munkin via Tarantool-patches
@ 2021-02-09 13:59           ` Timur Safin via Tarantool-patches
  2021-02-09 15:10             ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Timur Safin via Tarantool-patches @ 2021-02-09 13:59 UTC (permalink / raw)
  To: 'Igor Munkin'; +Cc: tarantool-patches

LGTM. 
Modulo my usual note about 2nd comment about cmake. But you may already has it
fixed in your branch till this moment...


: From: Igor Munkin <imun@tarantool.org>
: Subject: Re: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
: 
: > :
: > : Unfortunately... CMake is a crap and I can't fix it. Well, honestly I
: > : don't want to fix it. But you're right: I can fix all these comments
: > : (athough I don't really want to). I have no idea how to express this in
: > : a more neutral way, so I propose the following:
: > : 1. s/CMake is a crap/there is no convenient way to make it in CMake/g.
: > : 2. Leave everything else unchanged.
: >
: > Hmm, ok.
: 
: Fixed, squashed, force-pushed to the branch. Diff is below:

Nice! Thank you! But there is 2nd one...

: 
: >
: > :
: > : This is not only emotions. Such comments prevent one from unintentional
: > : refactoring of such fragile places with no failures and also from
: > : bothering the oldies with the questions kinda "dude, why is this done so
: > : badly". In other words, primarily I have left this for the history.
: > :
: > : If you're OK, then I'll fix the way described above.
: > :
: > : >
: > : > : +  # Add the directory where the lib is built to the LUA_CPATH
: > : > : +  # environment variable, so interpreter 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 the
: > : > : +  # list. I have no idea what is wrong with this tool, 

About this one       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

: > : > : +  but I found
: > : > : +  # a single working solution to make LUA_CPATH be a string via
: > : > : +  # "escaping" the semicolon right in string interpolation.
: > : > : +  set(LUA_CPATH
: > : > :
: > :

Regards,
Timur


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-09 12:47     ` Igor Munkin via Tarantool-patches
@ 2021-02-09 14:45       ` Sergey Kaplun via Tarantool-patches
  2021-02-09 15:28         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-09 14:45 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

On 09.02.21, Igor Munkin wrote:
> Sergey,
> 
> Thanks for your review!
> 
> On 09.02.21, Sergey Kaplun wrote:
> > Hi, Igor!
> > 
> > Thanks for the patch!
> > LGTM, except 4 comments about memory profiler parser below.
> 
> I have several questions, so postponed your Ack a bit.

No problem.

> 
> > 
> > On 02.02.21, Igor Munkin wrote:
> > > Since the build machinery is going to be ported to CMake there would be
> > > Makefile names clashing. This change renames the original build system
> > > (and a couple of auxiliary files requiring configuring) to keep all this
> > > machinery working.
> > > 
> > > As a result of these changes one need to explicitly specify the Makefile
> > > in the build command:
> > > | make -f Makefile.original <options>
> > > 
> > > Needed for tarantool/tarantool#4862
> > > 
> > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > ---
> > >  Makefile => Makefile.original               | 44 +++++++++++++--------
> > >  etc/{luajit.pc => luajit.pc.in}             |  4 +-
> > >  src/{Makefile.dep => Makefile.dep.original} |  0
> > >  src/{Makefile => Makefile.original}         |  4 +-
> > >  tools/luajit-parse-memprof                  |  9 -----
> > >  tools/luajit-parse-memprof.in               |  6 +++
> > >  6 files changed, 38 insertions(+), 29 deletions(-)
> > >  rename Makefile => Makefile.original (85%)
> > >  rename etc/{luajit.pc => luajit.pc.in} (91%)
> > >  rename src/{Makefile.dep => Makefile.dep.original} (100%)
> > >  rename src/{Makefile => Makefile.original} (99%)
> > >  delete mode 100755 tools/luajit-parse-memprof
> > >  create mode 100644 tools/luajit-parse-memprof.in
> > > 
> > > diff --git a/Makefile b/Makefile.original
> > > similarity index 85%
> > > rename from Makefile
> > > rename to Makefile.original
> > > index 61967df..b85d4bf 100644
> > > --- a/Makefile
> > > +++ b/Makefile.original
> > > @@ -85,10 +85,10 @@ INSTALL_X= install -m 0755
> > 
> > <snipped>
> > 
> > > @@ -185,13 +185,25 @@ uninstall:
> > >  
> > >  ##############################################################################
> > >  
> > > -amalg:
> > > +amalg: tools
> > >  	@echo "Building LuaJIT $(VERSION)"
> > > -	$(MAKE) -C src amalg
> > > +	$(MAKE) -C src -f Makefile.original amalg
> > >  
> > >  clean:
> > > -	$(MAKE) -C src clean
> > > +	$(RM) tools/$(FILE_TMEMPROF)
> > > +	$(MAKE) -C src -f Makefile.original clean
> > >  
> > > -.PHONY: all install amalg clean
> > > +tools: tools/$(FILE_TMEMPROF)
> > > +
> > > +# FIXME: This is an ugly hack to manually configure an auxiliary
> > > +# tools/luajit-parse-memprof. I hope this file will have gone away
> > 
> > 1. I suggest the following rewording ("I hope" is too personal :)):
> > s/I hope this file will have gone away/This file should go away/
> 
> Fixed, squashed, force-pushed to the branch. Diff is below:

Thanks!

> 
> ================================================================================
> 
> diff --git a/Makefile.original b/Makefile.original
> index b85d4bf..c3172f0 100644
> --- a/Makefile.original
> +++ b/Makefile.original
> @@ -196,8 +196,8 @@ clean:
>  tools: tools/$(FILE_TMEMPROF)
>  
>  # FIXME: This is an ugly hack to manually configure an auxiliary
> -# tools/luajit-parse-memprof. I hope this file will have gone away
> -# in scope of https://github.com/tarantool/tarantool/issues/5688.
> +# tools/luajit-parse-memprof. This file should go away in scope of
> +# https://github.com/tarantool/tarantool/issues/5688.
>  tools/$(FILE_TMEMPROF):
>  	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
>  	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> 
> ================================================================================
> 
> > 
> > > +# in scope of https://github.com/tarantool/tarantool/issues/5688.
> > > +tools/$(FILE_TMEMPROF):
> > > +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > > +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > 
> > 2. @LUAJIT_BIN@ looks more convenient, doesn't it?
> 
> It doesn't for me. Why does the current naming look inconvenient to you?

What does LUAJIT_TOOLS_BIN mean? I confused by TOOLS part.

> 
> > 
> > > +	     $@.in > $@
> > > +	@chmod +x $@
> > > +
> > > +.PHONY: all install amalg clean tools
> > >  
> > >  ##############################################################################
> 
> <snipped>
> 
> > > diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> > > new file mode 100644
> > > index 0000000..8867202
> > > --- /dev/null
> > > +++ b/tools/luajit-parse-memprof.in
> > > @@ -0,0 +1,6 @@
> > > +#!/bin/bash
> > > +#
> > > +# Launcher for memprof parser.
> > > +
> > > +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
> > > +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
> > 
> > 3. Unfortunately, your solution doesn't work for me:
> 
> Crap, I believe I've fixed this.
> 
> > 
> > | $ git log --oneline -n1
> > | 7badb7e (HEAD) build: preserve the original build system
> > | $ make -f Makefile.original  -j
> > | ==== Building LuaJIT 2.1.0-beta3 ====
> > | ...
> > | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> > 
> > Side note: I suppose it is nothing bad to add corresponding lines about
> > tools building. At least it simplifies build debugging.
> > Feel free to ignore.
> 
> One can adjust this for debugging. Otherwise there is no need to see
> this output. We can use those hacks with Q/E, but I hope this part will
> have gone in the nearest future.

OK, never mind.

> 
> > 
> > | $ tools/luajit-parse-memprof /tmp/memprof_memleak.bin; echo -e "\n"; cat tools/luajit-parse-memprof
> > | tools/luajit-parse-memprof: line 5: /home/burii/reviews/luajit/cmake/tools/memprof.lua: Permission denied
> > |
> > | #!/bin/bash
> > | #
> > | # Launcher for memprof parser.
> > |
> > | LUA_PATH="/home/burii/reviews/luajit/cmake/tools/?.lua;;" \
> > |          /home/burii/reviews/luajit/cmake/tools/memprof.lua $@
> > 
> > This patch is working for me. But I am not bash|make guru :).
> 
> Heh, try your patch on a clean repo: unfortunately it works neither. The
> root cause is the lack of <src/luajit> on configuration phase. I added

Hmm, it's weird. `realpath` manual declares:
| all but the last component must exist
To be honest, I don't understand why it fails even in the first version
-- obviously, <src> exists.
Anyway, LGTM.

> the corresponding dependency for this rule. Fixed, squashed,
> force-pushed to the branch. Diff is below:
> 
> ================================================================================
> 
> diff --git a/Makefile.original b/Makefile.original
> index c3172f0..33dc2ed 100644
> --- a/Makefile.original
> +++ b/Makefile.original
> @@ -198,7 +198,7 @@ tools: tools/$(FILE_TMEMPROF)
>  # FIXME: This is an ugly hack to manually configure an auxiliary
>  # tools/luajit-parse-memprof. This file should go away in scope of
>  # https://github.com/tarantool/tarantool/issues/5688.
> -tools/$(FILE_TMEMPROF):
> +tools/$(FILE_TMEMPROF): src/luajit
>  	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
>  	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
>  	     $@.in > $@
> 
> ================================================================================
> 
> After this patch everything is fine.
> 
> > 
> > | diff --git a/Makefile.original b/Makefile.original
> > | index b85d4bf..877398a 100644
> > | --- a/Makefile.original
> > | +++ b/Makefile.original
> > | @@ -199,8 +199,8 @@ tools: tools/$(FILE_TMEMPROF)
> > |  # tools/luajit-parse-memprof. I hope this file will have gone away
> > |  # in scope of https://github.com/tarantool/tarantool/issues/5688.
> > |  tools/$(FILE_TMEMPROF):
> > | -        @sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > | -             -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > | +        @sed -e "s|@LUAJIT_TOOLS_DIR@|`realpath tools`|" \
> > | +             -e "s|@LUAJIT_TOOLS_BIN@|`realpath src/luajit`|" \
> > |               $@.in > $@
> > |          @chmod +x $@
> > |  
> > 
> > 4. Please, create separate commit to tools-related changes.
> 
> For what?

I don't understand existing of these changes (but I like them :))
from commit message. Is it mentioned in the following part?

| (and a couple of auxiliary files requiring configuring)

Is it better to mention directly tools files here instead "auxiliary"?

> 
> > Also, I suppose, it would be nice to add <tools/luajit-parse-memprof>
> > to <.gitignore> as far as it's generated. These lines may be confusing:
> 
> This is added in the next patch, but I'm not against moving it to this
> one. Fixed, squashed, force-pushed to the branch. Diff is below:

Thanks! But one nitpick, feel free to ignore.

> 
> ================================================================================
> 
> diff --git a/.gitignore b/.gitignore
> index 1a07bf7..fc9c31e 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -9,3 +9,6 @@
>  *.dmp
>  *.swp
>  .tags
> +
> +# Configured runner for LuaJIT memprof parser

Nit: s/parser/parser./
Feel free to ignore.

> +tools/luajit-parse-memprof
> 
> ================================================================================
> 
> > 
> > | $ git status
> > | HEAD detached at 7badb7e
> > | Untracked files:
> > |   (use "git add <file>..." to include in what will be committed)
> > |         tools/luajit-parse-memprof
> > 
> > > -- 
> > > 2.25.0
> > > 
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> -- 
> Best regards,
> IM

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-09 13:55       ` Timur Safin via Tarantool-patches
@ 2021-02-09 15:09         ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-09 15:09 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

On 09.02.21, Timur Safin wrote:
> LGTM, if you need a shorter answer, but there are some further comments below...

Thanks, added your tag:
| Reviewed-by: Timur Safin <tsafin@tarantool.org>

> 

<snipped>

> 
> Best Regards,
> Timur
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-09 13:59           ` Timur Safin via Tarantool-patches
@ 2021-02-09 15:10             ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-09 15:10 UTC (permalink / raw)
  To: Timur Safin; +Cc: tarantool-patches

Timur,

On 09.02.21, Timur Safin wrote:
> LGTM. 

Thanks, added your tag:
| Reviewed-by: Timur Safin <tsafin@tarantool.org>

> Modulo my usual note about 2nd comment about cmake. But you may already has it
> fixed in your branch till this moment...
> 
> 
> : From: Igor Munkin <imun@tarantool.org>
> : Subject: Re: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
> : 
> : > :
> : > : Unfortunately... CMake is a crap and I can't fix it. Well, honestly I
> : > : don't want to fix it. But you're right: I can fix all these comments
> : > : (athough I don't really want to). I have no idea how to express this in
> : > : a more neutral way, so I propose the following:
> : > : 1. s/CMake is a crap/there is no convenient way to make it in CMake/g.
> : > : 2. Leave everything else unchanged.
> : >
> : > Hmm, ok.
> : 
> : Fixed, squashed, force-pushed to the branch. Diff is below:
> 
> Nice! Thank you! But there is 2nd one...
> 
> : 
> : >
> : > :
> : > : This is not only emotions. Such comments prevent one from unintentional
> : > : refactoring of such fragile places with no failures and also from
> : > : bothering the oldies with the questions kinda "dude, why is this done so
> : > : badly". In other words, primarily I have left this for the history.
> : > :
> : > : If you're OK, then I'll fix the way described above.
> : > :
> : > : >
> : > : > : +  # Add the directory where the lib is built to the LUA_CPATH
> : > : > : +  # environment variable, so interpreter 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 the
> : > : > : +  # list. I have no idea what is wrong with this tool, 
> 
> About this one       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Re-built comments with -UFLAME -UTOXIC, here are the changes:

================================================================================

diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index 5345e12..a7af807 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -46,10 +46,10 @@ macro(BuildTestLib lib sources)
   # Add the directory where the lib is built to the LUA_CPATH
   # environment variable, so interpreter 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 the
-  # list. I have no idea what is wrong with this tool, but I found
-  # a single working solution to make LUA_CPATH be a string via
-  # "escaping" the semicolon right in string interpolation.
+  # 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)
   # Also add this directory to LD_LIBRARY_PATH environment
   # variable, so FFI machinery can find and load it.

================================================================================

Squashed, force-pushed to the branch.

> 
> : > : > : +  but I found
> : > : > : +  # a single working solution to make LUA_CPATH be a string via
> : > : > : +  # "escaping" the semicolon right in string interpolation.
> : > : > : +  set(LUA_CPATH
> : > : > :
> : > :
> 
> Regards,
> Timur
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-09 14:45       ` Sergey Kaplun via Tarantool-patches
@ 2021-02-09 15:28         ` Igor Munkin via Tarantool-patches
  2021-02-10  9:35           ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-09 15:28 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

On 09.02.21, Sergey Kaplun wrote:
> Igor,
> 
> On 09.02.21, Igor Munkin wrote:
> > Sergey,
> > 
> > Thanks for your review!
> > 
> > On 09.02.21, Sergey Kaplun wrote:
> > > Hi, Igor!
> > > 
> > > Thanks for the patch!
> > > LGTM, except 4 comments about memory profiler parser below.

Added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

> > 
> > I have several questions, so postponed your Ack a bit.
> 
> No problem.
> 
> > 
> > > 
> > > On 02.02.21, Igor Munkin wrote:
> > > > Since the build machinery is going to be ported to CMake there would be
> > > > Makefile names clashing. This change renames the original build system
> > > > (and a couple of auxiliary files requiring configuring) to keep all this
> > > > machinery working.
> > > > 
> > > > As a result of these changes one need to explicitly specify the Makefile
> > > > in the build command:
> > > > | make -f Makefile.original <options>
> > > > 
> > > > Needed for tarantool/tarantool#4862
> > > > 
> > > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > > ---
> > > >  Makefile => Makefile.original               | 44 +++++++++++++--------
> > > >  etc/{luajit.pc => luajit.pc.in}             |  4 +-
> > > >  src/{Makefile.dep => Makefile.dep.original} |  0
> > > >  src/{Makefile => Makefile.original}         |  4 +-
> > > >  tools/luajit-parse-memprof                  |  9 -----
> > > >  tools/luajit-parse-memprof.in               |  6 +++
> > > >  6 files changed, 38 insertions(+), 29 deletions(-)
> > > >  rename Makefile => Makefile.original (85%)
> > > >  rename etc/{luajit.pc => luajit.pc.in} (91%)
> > > >  rename src/{Makefile.dep => Makefile.dep.original} (100%)
> > > >  rename src/{Makefile => Makefile.original} (99%)
> > > >  delete mode 100755 tools/luajit-parse-memprof
> > > >  create mode 100644 tools/luajit-parse-memprof.in
> > > > 
> > > > diff --git a/Makefile b/Makefile.original
> > > > similarity index 85%
> > > > rename from Makefile
> > > > rename to Makefile.original
> > > > index 61967df..b85d4bf 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile.original

<snipped>

> > > > +# in scope of https://github.com/tarantool/tarantool/issues/5688.
> > > > +tools/$(FILE_TMEMPROF):
> > > > +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > > > +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > > 
> > > 2. @LUAJIT_BIN@ looks more convenient, doesn't it?
> > 
> > It doesn't for me. Why does the current naming look inconvenient to you?
> 
> What does LUAJIT_TOOLS_BIN mean? I confused by TOOLS part.

It means a LuaJIT binary used for tools, so one can distinct them if
necessary. As an additional bonus, the commands are well-aligned :)

> 
> > 
> > > 
> > > > +	     $@.in > $@
> > > > +	@chmod +x $@
> > > > +
> > > > +.PHONY: all install amalg clean tools
> > > >  
> > > >  ##############################################################################
> > 
> > <snipped>
> > 
> > > > diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> > > > new file mode 100644
> > > > index 0000000..8867202
> > > > --- /dev/null
> > > > +++ b/tools/luajit-parse-memprof.in
> > > > @@ -0,0 +1,6 @@
> > > > +#!/bin/bash
> > > > +#
> > > > +# Launcher for memprof parser.
> > > > +
> > > > +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
> > > > +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
> > > 
> > > 3. Unfortunately, your solution doesn't work for me:
> > 
> > Crap, I believe I've fixed this.
> > 
> > > 
> > > | $ git log --oneline -n1
> > > | 7badb7e (HEAD) build: preserve the original build system
> > > | $ make -f Makefile.original  -j
> > > | ==== Building LuaJIT 2.1.0-beta3 ====
> > > | ...
> > > | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> > > 
> > > Side note: I suppose it is nothing bad to add corresponding lines about
> > > tools building. At least it simplifies build debugging.
> > > Feel free to ignore.
> > 
> > One can adjust this for debugging. Otherwise there is no need to see
> > this output. We can use those hacks with Q/E, but I hope this part will
> > have gone in the nearest future.
> 
> OK, never mind.
> 
> > 
> > > 
> > > | $ tools/luajit-parse-memprof /tmp/memprof_memleak.bin; echo -e "\n"; cat tools/luajit-parse-memprof
> > > | tools/luajit-parse-memprof: line 5: /home/burii/reviews/luajit/cmake/tools/memprof.lua: Permission denied
> > > |
> > > | #!/bin/bash
> > > | #
> > > | # Launcher for memprof parser.
> > > |
> > > | LUA_PATH="/home/burii/reviews/luajit/cmake/tools/?.lua;;" \
> > > |          /home/burii/reviews/luajit/cmake/tools/memprof.lua $@
> > > 
> > > This patch is working for me. But I am not bash|make guru :).
> > 
> > Heh, try your patch on a clean repo: unfortunately it works neither. The
> > root cause is the lack of <src/luajit> on configuration phase. I added
> 
> Hmm, it's weird. `realpath` manual declares:
> | all but the last component must exist
> To be honest, I don't understand why it fails even in the first version
> -- obviously, <src> exists.

But <src/luajit> does not -- that's the point.

> Anyway, LGTM.
> 
> > the corresponding dependency for this rule. Fixed, squashed,
> > force-pushed to the branch. Diff is below:
> > 
> > ================================================================================
> > 
> > diff --git a/Makefile.original b/Makefile.original
> > index c3172f0..33dc2ed 100644
> > --- a/Makefile.original
> > +++ b/Makefile.original
> > @@ -198,7 +198,7 @@ tools: tools/$(FILE_TMEMPROF)
> >  # FIXME: This is an ugly hack to manually configure an auxiliary
> >  # tools/luajit-parse-memprof. This file should go away in scope of
> >  # https://github.com/tarantool/tarantool/issues/5688.
> > -tools/$(FILE_TMEMPROF):
> > +tools/$(FILE_TMEMPROF): src/luajit
> >  	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> >  	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> >  	     $@.in > $@
> > 
> > ================================================================================
> > 
> > After this patch everything is fine.
> > 
> > > 
> > > | diff --git a/Makefile.original b/Makefile.original
> > > | index b85d4bf..877398a 100644
> > > | --- a/Makefile.original
> > > | +++ b/Makefile.original
> > > | @@ -199,8 +199,8 @@ tools: tools/$(FILE_TMEMPROF)
> > > |  # tools/luajit-parse-memprof. I hope this file will have gone away
> > > |  # in scope of https://github.com/tarantool/tarantool/issues/5688.
> > > |  tools/$(FILE_TMEMPROF):
> > > | -        @sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > > | -             -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > > | +        @sed -e "s|@LUAJIT_TOOLS_DIR@|`realpath tools`|" \
> > > | +             -e "s|@LUAJIT_TOOLS_BIN@|`realpath src/luajit`|" \
> > > |               $@.in > $@
> > > |          @chmod +x $@
> > > |  
> > > 
> > > 4. Please, create separate commit to tools-related changes.
> > 
> > For what?
> 
> I don't understand existing of these changes (but I like them :))
> from commit message. Is it mentioned in the following part?

Yes.

> 
> | (and a couple of auxiliary files requiring configuring)
> 
> Is it better to mention directly tools files here instead "auxiliary"?

No, since luajit.pc is also adjusted. I guess changes are mostly minimal
(but a bit hacky) to move them to a separate patch.

> 
> > 
> > > Also, I suppose, it would be nice to add <tools/luajit-parse-memprof>
> > > to <.gitignore> as far as it's generated. These lines may be confusing:
> > 
> > This is added in the next patch, but I'm not against moving it to this
> > one. Fixed, squashed, force-pushed to the branch. Diff is below:
> 
> Thanks! But one nitpick, feel free to ignore.
> 
> > 
> > ================================================================================
> > 
> > diff --git a/.gitignore b/.gitignore
> > index 1a07bf7..fc9c31e 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -9,3 +9,6 @@
> >  *.dmp
> >  *.swp
> >  .tags
> > +
> > +# Configured runner for LuaJIT memprof parser
> 
> Nit: s/parser/parser./
> Feel free to ignore.

Thanks, fixed.

> 
> > +tools/luajit-parse-memprof
> > 
> > ================================================================================
> > 
> > > 
> > > | $ git status
> > > | HEAD detached at 7badb7e
> > > | Untracked files:
> > > |   (use "git add <file>..." to include in what will be committed)
> > > |         tools/luajit-parse-memprof
> > > 
> > > > -- 
> > > > 2.25.0
> > > > 
> > > 
> > > -- 
> > > Best regards,
> > > Sergey Kaplun
> > 
> > -- 
> > Best regards,
> > IM
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system
  2021-02-09 15:28         ` Igor Munkin via Tarantool-patches
@ 2021-02-10  9:35           ` Sergey Kaplun via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-10  9:35 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

LGTM. Just some side notes below.

On 09.02.21, Igor Munkin wrote:
> Sergey,
> 
> On 09.02.21, Sergey Kaplun wrote:
> > Igor,
> > 
> > On 09.02.21, Igor Munkin wrote:
> > > Sergey,
> > > 
> > > Thanks for your review!
> > > 
> > > On 09.02.21, Sergey Kaplun wrote:
> > > > Hi, Igor!
> > > > 
> > > > Thanks for the patch!
> > > > LGTM, except 4 comments about memory profiler parser below.
> 
> Added your tag:
> | Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

Thanks!

> 
> > > 
> > > I have several questions, so postponed your Ack a bit.
> > 
> > No problem.
> > 
> > > 
> > > > 
> > > > On 02.02.21, Igor Munkin wrote:
> > > > > Since the build machinery is going to be ported to CMake there would be
> > > > > Makefile names clashing. This change renames the original build system
> > > > > (and a couple of auxiliary files requiring configuring) to keep all this
> > > > > machinery working.
> > > > > 
> > > > > As a result of these changes one need to explicitly specify the Makefile
> > > > > in the build command:
> > > > > | make -f Makefile.original <options>
> > > > > 
> > > > > Needed for tarantool/tarantool#4862
> > > > > 
> > > > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > > > ---
> > > > >  Makefile => Makefile.original               | 44 +++++++++++++--------
> > > > >  etc/{luajit.pc => luajit.pc.in}             |  4 +-
> > > > >  src/{Makefile.dep => Makefile.dep.original} |  0
> > > > >  src/{Makefile => Makefile.original}         |  4 +-
> > > > >  tools/luajit-parse-memprof                  |  9 -----
> > > > >  tools/luajit-parse-memprof.in               |  6 +++
> > > > >  6 files changed, 38 insertions(+), 29 deletions(-)
> > > > >  rename Makefile => Makefile.original (85%)
> > > > >  rename etc/{luajit.pc => luajit.pc.in} (91%)
> > > > >  rename src/{Makefile.dep => Makefile.dep.original} (100%)
> > > > >  rename src/{Makefile => Makefile.original} (99%)
> > > > >  delete mode 100755 tools/luajit-parse-memprof
> > > > >  create mode 100644 tools/luajit-parse-memprof.in
> > > > > 
> > > > > diff --git a/Makefile b/Makefile.original
> > > > > similarity index 85%
> > > > > rename from Makefile
> > > > > rename to Makefile.original
> > > > > index 61967df..b85d4bf 100644
> > > > > --- a/Makefile
> > > > > +++ b/Makefile.original
> 
> <snipped>
> 
> > > > > +# in scope of https://github.com/tarantool/tarantool/issues/5688.
> > > > > +tools/$(FILE_TMEMPROF):
> > > > > +	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > > > > +	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > > > 
> > > > 2. @LUAJIT_BIN@ looks more convenient, doesn't it?
> > > 
> > > It doesn't for me. Why does the current naming look inconvenient to you?
> > 
> > What does LUAJIT_TOOLS_BIN mean? I confused by TOOLS part.
> 
> It means a LuaJIT binary used for tools, so one can distinct them if
> necessary. As an additional bonus, the commands are well-aligned :)

Really nice :)

> 

<snipped>

> > > > > diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> > > > > new file mode 100644
> > > > > index 0000000..8867202
> > > > > --- /dev/null
> > > > > +++ b/tools/luajit-parse-memprof.in
> > > > > @@ -0,0 +1,6 @@
> > > > > +#!/bin/bash
> > > > > +#
> > > > > +# Launcher for memprof parser.
> > > > > +
> > > > > +LUA_PATH="@LUAJIT_TOOLS_DIR@/?.lua;;" \
> > > > > +	@LUAJIT_TOOLS_BIN@ @LUAJIT_TOOLS_DIR@/memprof.lua $@
> > > > 
> > > > 3. Unfortunately, your solution doesn't work for me:
> > > 
> > > Crap, I believe I've fixed this.
> > > 
> > > > 
> > > > | $ git log --oneline -n1
> > > > | 7badb7e (HEAD) build: preserve the original build system
> > > > | $ make -f Makefile.original  -j
> > > > | ==== Building LuaJIT 2.1.0-beta3 ====
> > > > | ...
> > > > | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> > > > 
> > > > Side note: I suppose it is nothing bad to add corresponding lines about
> > > > tools building. At least it simplifies build debugging.
> > > > Feel free to ignore.
> > > 
> > > One can adjust this for debugging. Otherwise there is no need to see
> > > this output. We can use those hacks with Q/E, but I hope this part will
> > > have gone in the nearest future.
> > 
> > OK, never mind.
> > 
> > > 
> > > > 
> > > > | $ tools/luajit-parse-memprof /tmp/memprof_memleak.bin; echo -e "\n"; cat tools/luajit-parse-memprof
> > > > | tools/luajit-parse-memprof: line 5: /home/burii/reviews/luajit/cmake/tools/memprof.lua: Permission denied
> > > > |
> > > > | #!/bin/bash
> > > > | #
> > > > | # Launcher for memprof parser.
> > > > |
> > > > | LUA_PATH="/home/burii/reviews/luajit/cmake/tools/?.lua;;" \
> > > > |          /home/burii/reviews/luajit/cmake/tools/memprof.lua $@
> > > > 
> > > > This patch is working for me. But I am not bash|make guru :).
> > > 
> > > Heh, try your patch on a clean repo: unfortunately it works neither. The
> > > root cause is the lack of <src/luajit> on configuration phase. I added
> > 
> > Hmm, it's weird. `realpath` manual declares:
> > | all but the last component must exist
> > To be honest, I don't understand why it fails even in the first version
> > -- obviously, <src> exists.
> 
> But <src/luajit> does not -- that's the point.

I thought so too at the beginning, but when test it:

| $ realpath reviews/blabla && ls $_
| /home/burii/reviews/blabla
| ls: cannot access 'reviews/blabla': No such file or directory

Like manual declares.
Anyway, we can discuss it offline :)

> 
> > Anyway, LGTM.
> > 
> > > the corresponding dependency for this rule. Fixed, squashed,
> > > force-pushed to the branch. Diff is below:
> > > 
> > > ================================================================================
> > > 
> > > diff --git a/Makefile.original b/Makefile.original
> > > index c3172f0..33dc2ed 100644
> > > --- a/Makefile.original
> > > +++ b/Makefile.original
> > > @@ -198,7 +198,7 @@ tools: tools/$(FILE_TMEMPROF)
> > >  # FIXME: This is an ugly hack to manually configure an auxiliary
> > >  # tools/luajit-parse-memprof. This file should go away in scope of
> > >  # https://github.com/tarantool/tarantool/issues/5688.
> > > -tools/$(FILE_TMEMPROF):
> > > +tools/$(FILE_TMEMPROF): src/luajit
> > >  	@sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > >  	     -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > >  	     $@.in > $@
> > > 
> > > ================================================================================
> > > 
> > > After this patch everything is fine.
> > > 
> > > > 
> > > > | diff --git a/Makefile.original b/Makefile.original
> > > > | index b85d4bf..877398a 100644
> > > > | --- a/Makefile.original
> > > > | +++ b/Makefile.original
> > > > | @@ -199,8 +199,8 @@ tools: tools/$(FILE_TMEMPROF)
> > > > |  # tools/luajit-parse-memprof. I hope this file will have gone away
> > > > |  # in scope of https://github.com/tarantool/tarantool/issues/5688.
> > > > |  tools/$(FILE_TMEMPROF):
> > > > | -        @sed -e "s|@LUAJIT_TOOLS_DIR@|$(realpath tools)|" \
> > > > | -             -e "s|@LUAJIT_TOOLS_BIN@|$(realpath src/luajit)|" \
> > > > | +        @sed -e "s|@LUAJIT_TOOLS_DIR@|`realpath tools`|" \
> > > > | +             -e "s|@LUAJIT_TOOLS_BIN@|`realpath src/luajit`|" \
> > > > |               $@.in > $@
> > > > |          @chmod +x $@
> > > > |  
> > > > 
> > > > 4. Please, create separate commit to tools-related changes.
> > > 
> > > For what?
> > 
> > I don't understand existing of these changes (but I like them :))
> > from commit message. Is it mentioned in the following part?
> 
> Yes.
> 
> > 
> > | (and a couple of auxiliary files requiring configuring)
> > 
> > Is it better to mention directly tools files here instead "auxiliary"?
> 
> No, since luajit.pc is also adjusted. I guess changes are mostly minimal
> (but a bit hacky) to move them to a separate patch.

OK.

> 
> > 
> > > 
> > > > Also, I suppose, it would be nice to add <tools/luajit-parse-memprof>
> > > > to <.gitignore> as far as it's generated. These lines may be confusing:
> > > 
> > > This is added in the next patch, but I'm not against moving it to this
> > > one. Fixed, squashed, force-pushed to the branch. Diff is below:
> > 
> > Thanks! But one nitpick, feel free to ignore.
> > 
> > > 
> > > ================================================================================
> > > 
> > > diff --git a/.gitignore b/.gitignore
> > > index 1a07bf7..fc9c31e 100644
> > > --- a/.gitignore
> > > +++ b/.gitignore
> > > @@ -9,3 +9,6 @@
> > >  *.dmp
> > >  *.swp
> > >  .tags
> > > +
> > > +# Configured runner for LuaJIT memprof parser
> > 
> > Nit: s/parser/parser./
> > Feel free to ignore.
> 
> Thanks, fixed.
> 
> > 
> > > +tools/luajit-parse-memprof
> > > 
> > > ================================================================================
> > > 
> > > > 
> > > > | $ git status
> > > > | HEAD detached at 7badb7e
> > > > | Untracked files:
> > > > |   (use "git add <file>..." to include in what will be committed)
> > > > |         tools/luajit-parse-memprof
> > > > 
> > > > > -- 
> > > > > 2.25.0
> > > > > 
> > > > 
> > > > -- 
> > > > Best regards,
> > > > Sergey Kaplun
> > > 
> > > -- 
> > > Best regards,
> > > IM
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> -- 
> Best regards,
> IM

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
@ 2021-02-11 19:23   ` Sergey Kaplun via Tarantool-patches
  2021-02-16 15:28     ` Igor Munkin via Tarantool-patches
  2021-02-13  3:47   ` Sergey Kaplun via Tarantool-patches
  2 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-11 19:23 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!

Appreciate your hard work! Thanks for the verbose comments!
The building process is faster now!
I'm sorry: I can't see your GUI innovations, unfortunately. :(

I've looked into branch version.
Please consider my comments below.

On 02.02.21, Igor Munkin wrote:
> In scope of this patch the LuaJIT build system is partially ported from

Typo: s/In scope/In the scope/

> GNU Make to CMake. These changes provides CMake build system only for

Typo: s/provides/provide/

> the following OS: GNU/Linux, OSX, FreeBSD. For other platrforms use the

Typo: s/platrforms/platforms/

> old build system (see the recipe in the previous commit).

This paragraph describes only supported OS. There is no description of
supported build system options.
IINM there is no cross-compiling support, stripping debug info, amalgam
build for now, it should be mentioned in the commit message too.

> 
> Several components of the new build system such as automatic version
> detection, source files list generation and some recipes for
> CMakeLists.txt are taken verbatim or adapted from LuaVela repository.
> 
> Part of tarantool/tarantool#4862
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---

Side note: This is not related to the patch directly but what about
Tarantool COPYRIGHT notice in the LuaJIT code and inside new cmake files
in particular?

>  .gitignore                 |  12 +-
>  CMakeLists.txt             | 261 +++++++++++++++++++++++++
>  cmake/LuaJITUtils.cmake    |  31 +++
>  cmake/MakeSourceList.cmake |  47 +++++
>  cmake/SetDynASMFlags.cmake | 130 ++++++++++++
>  cmake/SetTargetFlags.cmake |  42 ++++
>  cmake/SetVersion.cmake     |  45 +++++
>  etc/CMakeLists.txt         |  32 +++
>  src/CMakeLists.txt         | 391 +++++++++++++++++++++++++++++++++++++
>  src/host/CMakeLists.txt    |  61 ++++++
>  tools/CMakeLists.txt       |  77 ++++++++
>  11 files changed, 1128 insertions(+), 1 deletion(-)
>  create mode 100644 CMakeLists.txt
>  create mode 100644 cmake/LuaJITUtils.cmake
>  create mode 100644 cmake/MakeSourceList.cmake
>  create mode 100644 cmake/SetDynASMFlags.cmake
>  create mode 100644 cmake/SetTargetFlags.cmake
>  create mode 100644 cmake/SetVersion.cmake
>  create mode 100644 etc/CMakeLists.txt
>  create mode 100644 src/CMakeLists.txt
>  create mode 100644 src/host/CMakeLists.txt
>  create mode 100644 tools/CMakeLists.txt

Side note: should we update <doc/install.html> (change Makefile ->
Makefile.original)? Looks more related to the previous patch.

> 
> diff --git a/.gitignore b/.gitignore
> index 1a07bf7..a21ee1c 100644
> --- a/.gitignore
> +++ b/.gitignore

<snipped>

> diff --git a/CMakeLists.txt b/CMakeLists.txt
> new file mode 100644
> index 0000000..0dba5d8
> --- /dev/null
> +++ b/CMakeLists.txt
> @@ -0,0 +1,261 @@
> +# LuaJIT -- interpreter and JIT compiler for Lua language.
> +# This is the main entry point for building, testing and
> +# packaging the project.
> +# Major portions taken verbatim or adapted from the uJIT.
> +# Copyright (C) 2015-2019 IPONWEB Ltd.
> +
> +# --- Initial setup ------------------------------------------------------------
> +
> +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> +project(LuaJIT C)
> +
> +#

Nit: Comment style is inconsistent. Feel free to ignore.

> +# XXX: Originally CMake machinery is introduced to make LuaJIT
> +# testing self-sufficient. Since there are only few systems

Typo: s/only few systems/only a few systems/

> +# covered with the tests in our CI, there is no need to support

Typo: s/covered with/covered by/

> +# others for now and the original build system can be used.
> +#
> +
> +if(NOT(
> +   CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
> +   CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
> +   CMAKE_SYSTEM_NAME STREQUAL "FreeBSD"
> +))
> +  message(FATAL_ERROR
> +    "Please use the old build system:\n\tmake -f Makefile.original <options>"
> +  )
> +endif()
> +
> +# --- Fine-tuning cmake environment --------------------------------------------
> +
> +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
> +set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
> +
> +include(LuaJITUtils)
> +include(SetVersion)
> +
> +# --- Variables to be exported to child scopes ---------------------------------
> +
> +SetVersion(
> +  LUAJIT_VERSION
> +  LUAJIT_VERSION_MAJOR
> +  LUAJIT_VERSION_MINOR
> +  LUAJIT_VERSION_PATCH
> +  LUAJIT_VERSION_TWEAK
> +  LUAJIT_PRERELEASE
> +)
> +
> +set(LUAJIT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
> +set(LUAJIT_BINARY_DIR "${PROJECT_BINARY_DIR}/src")
> +
> +# Names of the CLI binaries.
> +set(LUAJIT_CLI_NAME "luajit")
> +set(LUAJIT_LIB_NAME "luajit")
> +
> +# Specialized install paths.
> +set(LUAJIT_DATAROOTDIR
> +  share/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}.${LUAJIT_VERSION_PATCH}${LUAJIT_PRERELEASE}
> +)
> +set(LUAJIT_INCLUDEDIR
> +  include/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}
> +)
> +
> +set(BUILDMODE_VALUES mixed static dynamic)

See nothing bad to transfer comments described each option here.

> +list(GET BUILDMODE_VALUES 0 BUILDMODE_DEFAULT)
> +set(BUILDMODE ${BUILDMODE_DEFAULT} CACHE STRING
> +  "Build mode. Choose one of the following: ${BUILDMODE_VALUES}."
> +)
> +set_property(CACHE BUILDMODE PROPERTY STRINGS ${BUILDMODE_VALUES})
> +
> +# Check that BUILDMODE value is correct.
> +# FIXME: In CMake 3.5 we'll be able to use IN_LIST here.
> +list(FIND BUILDMODE_VALUES ${BUILDMODE} BUILDMODE_INDEX)
> +if(BUILDMODE_INDEX EQUAL -1)
> +  message(FATAL_ERROR "BUILDMODE must be one of the following: ${BUILDMODE_VALUES}.")
> +endif()
> +
> +# --- Compilation flags setup --------------------------------------------------
> +
> +if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
> +  AppendFlags(TARGET_C_FLAGS -DLUA_ROOT='"${CMAKE_INSTALL_PREFIX}"')

In Makefile.original I see the following check inside this branch:

| ifneq (/usr,$(PREFIX))
|   TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
| endif

Is it related to unsupported build systems?

I've found some warnings on macOS in the configuration stage, that looks
related:

| CMake Warning (dev):
|   Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
|   --help-policy CMP0042" for policy details.  Use the cmake_policy command to
|   set the policy and suppress this warning.
|
|   MACOSX_RPATH is not specified for the following targets:
|
|    libluajit_shared
|
| This warning is for project developers.  Use -Wno-dev to suppress it.

Version of macOS:
| $ uname -a
| Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

> +endif()
> +
> +if(CMAKE_LIBRARY_ARCHITECTURE)
> +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> +endif()

What about `LUA_LMULTILIB`?

Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
like it does in Makefile.original?

> +
> +# Since the assembler part does NOT maintain a frame pointer, it's
> +# pointless to slow down the C part by not omitting it. Debugging,
> +# tracebacks and unwinding are not affected -- the assembler part
> +# has frame unwind information and GCC emits it where needed (x64)
> +# or with -g.
> +AppendFlags(CMAKE_C_FLAGS -fomit-frame-pointer -fno-stack-protector)
> +
> +# Re-defined to benefit from expanding macros in gdb.

Typo: s/Re-defined/Redefined/

> +set(CMAKE_C_FLAGS_DEBUG "-g -ggdb3")
> +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g -ggdb3")

Side note: Yes!!! Finally, we don't need to rewrite all macroses
by our own in console when debugging.
This is a good one!

> +# Re-defined since default cmake release optimization level is O3.

Typo: s/Re-defined/Redefined/

> +set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
> +
> +AppendFlags(CMAKE_C_FLAGS -Wall)
> +option(LUAJIT_ENABLE_WARNINGS "Build LuaJIT with warnings enabled" OFF)

Nit: This confused me a little. All warnings already enabled. This flag
enables extra warnings. I may be change like the following:
s/LUAJIT_ENABLE_WARNINGS/LUAJIT_ENABLE_EXTRA_WARNINGS/
s/warnings/extra warnings/
or
s/LUAJIT_ENABLE_WARNINGS/LUAJIT_ENABLE_MORE_WARNINGS/
s/warnings/more warnings/
Feel free to ignore.

> +if(LUAJIT_ENABLE_WARNINGS)
> +  AppendFlags(CMAKE_C_FLAGS
> +    -Wextra
> +    -Wdeclaration-after-statement
> +    -Wpointer-arith
> +    -Wredundant-decls
> +    -Wshadow
> +  )
> +endif()
> +
> +# Auxilary flags for main targets (libraries, binaries).

Typo: s/Auxilary/Auxiliary/

> +AppendFlags(TARGET_C_FLAGS
> +  -D_FILE_OFFSET_BITS=64
> +  -D_LARGEFILE_SOURCE
> +  -U_FORTIFY_SOURCE
> +)
> +
> +# Permanently disable the FFI extension to reduce the size of the
> +# LuaJIT executable. But please consider that the FFI library is
> +# compiled-in, but NOT loaded by default. It only allocates any
> +# memory, if you actually make use of it.
> +option(LUAJIT_DISABLE_FFI "FFI support" OFF)
> +if(LUAJIT_DISABLE_FFI)
> +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_FFI)
> +endif()
> +set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI)

Don't get your point here. `set()` does not support any expressions
as I've known from [1][2]. This just always defines `LUAJIT_HAS_FFI`.

> +
> +# Features from Lua 5.2 that are unlikely to break existing code
> +# are enabled by default. Some other features that *might* break
> +# some existing code (e.g. __pairs or os.execute() return values)
> +# can be enabled here.
> +# XXX: this does not provide full compatibility with Lua 5.2 at
> +# this time.
> +option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF)
> +if(LUAJIT_LUA52COMPAT)

This has been already fixed on branch, thanks!

> +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT)
> +endif()
> +
> +# Disable the JIT compiler, i.e. turn LuaJIT into a pure
> +# interpreter.
> +option(LUAJIT_DISABLE_JIT "JIT support" OFF)
> +if(LUAJIT_DISABLE_JIT)
> +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_JIT)
> +endif()
> +set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT)

Ditto.

> +
> +# Some architectures (e.g. PPC) can use either single-number (1)
> +# or dual-number (2) mode. Uncomment one of these lines to

Nit: See nothing to uncomment :). May be change it?

> +# override the default mode. Please see LJ_ARCH_NUMMODE in
> +# lj_arch.h for details.
> +set(LUAJIT_NUMMODE_VALUES 1 2)
> +set(LUAJIT_NUMMODE_DEFAULT "")
> +set(LUAJIT_NUMMODE ${LUAJIT_NUMMODE_DEFAULT} CACHE STRING
> +  "Switch to single-number or dual-number mode."
> +)
> +# XXX: explicitly added empty string allows to disable this flag
> +# in GUI.
> +set_property(CACHE LUAJIT_NUMMODE PROPERTY STRINGS
> +  ${LUAJIT_NUMMODE_DEFAULT} ${LUAJIT_NUMMODE_VALUES}
> +)

<snipped>

> +# Switch to harder (and slower) hash function when a collision
> +# chain in the string hash table exceeds certain length.

Typo: s/certain length/a certain length/

> +option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON)
> +if(LUAJIT_SMART_STRINGS)
> +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1)
> +endif()
> +

Nit: It would be nice to see "Debugging support" section here like for
other sections like "Main source tree" or so on.
Feel free to ignore.

> +# XXX: Note that most of the options below are NOT suitable for
> +# benchmarking or release mode!

<snipped>

> +# Turn on assertions for the Lua/C API to debug problems with
> +# lua_* calls. This is rather slow -- use only while developing C
> +# libraries/embeddings.
> +option(LUAJIT_USE_APICHECK "Assertions for the Lua/C API" OFF)
> +if(LUAJIT_USE_APICHECK)
> +  AppendFlags(TARGET_C_FLAGS -DLUA_USE_APICHECK)
> +endif()

Hmm, as for me looks more user friendly not to change option names here.
Just leave `LUA_USE_APICHECK` here.
I've already singed wings on it, when run Lua/LuaJIT/lua-Harness
tests! Yeees, I'd not looked at Cmake warnings carefully :(

> +
> +# Turn on assertions for the whole LuaJIT VM. This significantly
> +# slows down everything. Use only if you suspect a problem with
> +# LuaJIT itself.
> +option(LUAJIT_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF)
> +if(LUAJIT_USE_ASSERT)
> +  AppendFlags(TARGET_C_FLAGS -DLUA_USE_ASSERT)
> +endif()

Ditto.

> +
> +# TODO: Implement a configuration option to enable ASAN.
> +# There are two entries of LUAJIT_USE_ASAN define:
> +# $ grep -rnF 'LUAJIT_USE_ASAN' .
> +# ./src/lj_str.c:15:#if LUAJIT_USE_ASAN
> +# ./src/host/buildvm.c:36:#if LUAJIT_USE_ASAN
> +# At the same time this flag is not provided by LuaJIT original
> +# build system (i.e. src/Makefile.original) so there are no
> +# related compiler and linker flags passed. This should be done
> +# the right way later.

Good catch! I decide to check what else is missing. Here are some other
options (sorry, for that dump, just want to save it anywhere):
| $ grep -rnF 'LUAJIT_CTYPE_CHECK_ANCHOR'
| src/lj_ctype.c:139:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
| src/lj_ctype.c:159:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR

| $ grep -rnF 'LUAJIT_DEBUG_RA'
| src/lj_asm.c:192:/* #define LUAJIT_DEBUG_RA */
| src/lj_asm.c:194:#ifdef LUAJIT_DEBUG_RA

| $ grep -rnF 'LUAJIT_DISABLE_DEBUGINFO'
| src/lj_parse.c:1397:#ifndef LUAJIT_DISABLE_DEBUGINFO
| src/lj_parse.c:2700:#ifdef LUAJIT_DISABLE_DEBUGINFO
| Binary file src/.lj_parse.c.swp matches
| src/lj_memprof.c:102:  ** -DLUAJIT_DISABLE_DEBUGINFO flag.

| $ grep -rnF 'LUAJIT_DISABLE_PROFILE'
| src/lj_arch.h:501:#if defined(LUAJIT_DISABLE_PROFILE)

| $ grep -rnF 'LUAJIT_DISABLE_VMEVENT'
| src/lj_trace.c:796:#ifndef LUAJIT_DISABLE_VMEVENT
| src/lj_vmevent.h:33:#ifdef LUAJIT_DISABLE_VMEVENT
| src/lib_jit.c:118:#ifdef LUAJIT_DISABLE_VMEVENT

| $ grep -rnF 'LUAJIT_ENABLE_CHECKHOOK'
| src/lj_record.c:2621:#ifdef LUAJIT_ENABLE_CHECKHOOK

| $ grep -rnF 'LUAJIT_ENABLE_TABLE_BUMP'
| src/lj_record.c:259:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:1179:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:1477:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:1523:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:1874:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:2321:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_record.c:2544:#ifdef LUAJIT_ENABLE_TABLE_BUMP
| src/lj_jit.h:455:#ifdef LUAJIT_ENABLE_TABLE_BUMP

| $ grep -rnF 'LUAJIT_NO_UNALIGNED'
| src/lj_def.h:287:#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)

| $ grep -rnF 'LUAJIT_USE_PERFTOOLS'
| src/lj_trace.c:85:#ifdef LUAJIT_USE_PERFTOOLS
| src/lj_trace.c:163:#ifdef LUAJIT_USE_PERFTOOLS

| $ grep -rnF 'LUAJIT_UNWIND_EXTERNAL'
| doc/extensions.html:402:<td class="excplatform">ARM <tt>-DLUAJIT_UNWIND_EXTERNAL</tt></td>
| src/lj_err.c:53:** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled
| src/lj_err.c:64:#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND
| src/lj_err.c:521:  ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every*

They not all related to debugging (AFAICT only `LUAJIT_USE_PERFTOOLS`,
`LUAJIT_CTYPE_CHECK_ANCHOR` and `LUAJIT_DEBUG_RA`), more to configure.
May be it is better to create separate issue(s) for all these options?

> +
> +# --- Main source tree ---------------------------------------------------------

<snipped>

> diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> new file mode 100644
> index 0000000..faaef6b
> --- /dev/null
> +++ b/cmake/LuaJITUtils.cmake
> @@ -0,0 +1,31 @@
> +function(LuaJITTestArch outvar strflags)
> +  # XXX: <execute_process> simply splits the COMMAND argument by
> +  # spaces with no further parsing. At the same time GCC is bad in
> +  # argument handling, so let's help it a bit.
> +  separate_arguments(TEST_C_FLAGS UNIX_COMMAND ${strflags})

Nit: TESTARCH_C_FLAGS looks more verbose to me. Just TEST seems to be
referring to testing.
Feel free to ignore.

Nit: Also, it would be nice to see comments here, why do we use this
approach instead use of CMAKE_HOST_SYSTEM_PROCESSOR variable (is set by
`uname -p`).
Feel free to ignore.
> +  execute_process(
> +    COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM

May be it will better to provide not default compiler here?
It will be easier to adjust cross compiling with this.

> +    WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
> +    OUTPUT_VARIABLE TESTARCH
> +  )
> +  set(${outvar} ${TESTARCH} PARENT_SCOPE)
> +endfunction()
> +
> +function(LuaJITArch outvar testarch)
> +  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)

I occur the following error, when build inside Docker emulating
aarch64 (`FROM arm64v8/centos`):

| Error: pointer size mismatch in cross-build.
| Try: make HOST_CC="gcc -m32" CROSS=...
|
| make[2]: *** [src/CMakeFiles/vm_static.dir/build.make:62: src/lj_vm.S] Error 1
| make[1]: *** [CMakeFiles/Makefile2:193: src/CMakeFiles/vm_static.dir/all] Error 2
| make[1]: *** Waiting for unfinished jobs....
| Error: pointer size mismatch in cross-build.
| Try: make HOST_CC="gcc -m32" CROSS=...
|
| make[2]: *** [src/CMakeFiles/vm_shared.dir/build.make:62: src/lj_vm.S] Error 1
| make[1]: *** [CMakeFiles/Makefile2:394: src/CMakeFiles/vm_shared.dir/all] Error 2

All OK with the old Makefile:

| $ make -f Makefile.original -j
| ==== Building LuaJIT 2.1.0-beta3 ====
| ...
| ==== Successfully built LuaJIT 2.1.0-beta3 ====

Content of <src/host/CMakeFiles/buildvm.dir/build.make>:
| src/host/buildvm_arch.h: dynasm/*.lua
|         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/luajit/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating buildvm_arch.h"
|         cd /luajit/src/host && /luajit/src/host/minilua /luajit/dynasm/dynasm.lua -D ENDIAN_LE -D P64 -D JIT -D FFI -D DUALNUM -D FPU -D HFABI -D VER=80 -o buildvm_arch.h /luajit/src/vm_arm.dasc

vm_arm.dasc instead vm_arm64.dasc here.

All because LJ_TARGET_ARM matched before LJ_TARGET_ARM64 in the line
below. And it works for MIPS, because of different order :)
Swap arches and leave comments about an order, please.

Nit: As far as we can't organize this CPU arches in alphabetical order
I propose reverse-alphabetical ;):

| X86 X64 PPC MIPS64 MIPS ARM64 ARM

Feel free to ignore (it's more a joke).

> +    string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
> +    if(FOUND EQUAL -1)
> +      continue()

`continue()` command was introduced in 3.2 CMake version
according to [1]. So even 3.1 version is not enough.

This is a result for verision 3.0.2.
| CMake Error at cmake/LuaJITUtils.cmake:18 (continue):
|   Unknown CMake command "continue".
| Call Stack (most recent call first):
|   cmake/SetTargetFlags.cmake:16 (LuaJITArch)
|   src/CMakeLists.txt:164 (include)
|
|
| -- Configuring incomplete, errors occurred!

Please, add `cmake_minimum_required()` command to the top, or do not use
`continue()` command.

> +    endif()
> +    string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
> +    set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
> +    return()
> +  endforeach()
> +  message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture")

It would be nice to check return status from <lj_arch.h> preprocessing
command. On ppc64 inside Docker (`FROM ppc64le/debian`) configuration
ends successfully, arch detected as "ppc64":

| lj_arch.h:436:2: error: #error "No support for PowerPC 64 bit mode (yet)"
|  #error "No support for PowerPC 64 bit mode (yet)"
|   ^~~~~
| lj_arch.h:436:2: error: #error "No support for PowerPC 64 bit mode (yet)"
|  #error "No support for PowerPC 64 bit mode (yet)"
|   ^~~~~
| -- Configuring done
| WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| -- Generating done
| -- Build files have been written to: /luajit

> +endfunction()

<snipped>

> diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake
> new file mode 100644
> index 0000000..fa455bb
> --- /dev/null
> +++ b/cmake/MakeSourceList.cmake
> @@ -0,0 +1,47 @@

<snipped>

> +  include(CMakeParseArguments) # if we update to CMake >= 3.5, can remove this line

Nit: Please move comment to the previous line with the following
changes:
s/if/If/; s/this/the next/; s/line/line./.
Feel free to ignore.

> +  cmake_parse_arguments(${prefix}

<snipped>

> diff --git a/cmake/SetDynASMFlags.cmake b/cmake/SetDynASMFlags.cmake
> new file mode 100644
> index 0000000..9a920c3
> --- /dev/null
> +++ b/cmake/SetDynASMFlags.cmake
> @@ -0,0 +1,130 @@
> +# This module exposes following variables to the project:

Side note: Nice approach, I like it!

> +# * HOST_C_FLAGS
> +# * DYNASM_ARCH
> +# * DYNASM_FLAGS
> +
> +# XXX: buildvm includes core headers and thus has to be built
> +# with the same flags and defines as the LuaJIT core itself.
> +set(HOST_C_FLAGS)
> +set(DYNASM_ARCH)
> +set(DYNASM_FLAGS)
> +
> +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS} ${HOST_CFLAGS}")

Nit: Looks like it is necessary to use <Makefile.original> to define
LUAJIT_TARGET directly? I think that should be mentioned in the commit
message too.
Feel free to ignore.

> +LuaJITArch(LUAJIT_ARCH "${TESTARCH}")
> +AppendFlags(HOST_C_FLAGS -DLUAJIT_TARGET=LUAJIT_ARCH_${LUAJIT_ARCH})
> +
> +# XXX: LUAJIT_ARCH equals to DYNASM_ARCH for the most case but

Typo: /case/cases,/

> +# there are few exceptions to the rule.

<snipped>

> diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> new file mode 100644
> index 0000000..260fc6b
> --- /dev/null
> +++ b/cmake/SetTargetFlags.cmake
> @@ -0,0 +1,42 @@
> +# This module exposes following variables to the project:
> +# * BUILDVM_MODE
> +# * TARGET_C_FLAGS
> +# * TARGET_VM_FLAGS
> +# * TARGET_BIN_FLAGS
> +# * TARGET_SHARED_FLAGS
> +# * TARGET_LIBS
> +

<snipped>

> +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> +  if(LUAJIT_ARCH STREQUAL "x64")
> +    AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)
> +    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
> +  endif()
> +  AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)

Are -dynamiclib and -fPIC flags forced set by CMake?
Also, I don't find -install_name -compatibility_version -current_version
flags. Are they insignificant?

I got warnings from linker in the build stage on macOS:

| $ uname -a
| Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

| ld: warning: -seg1addr not 16384 byte aligned, rounding up
| /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols
| [ 98%] Built target libluajit_shared
| /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols

Is it related to this?

> +else() # Linux and FreeBSD.
> +  AppendFlags(TARGET_BIN_FLAGS -Wl,-E)
> +  list(APPEND TARGET_LIBS dl)
> +endif()
> +
> +# Auxilary flags for the VM core.

Typo: s/Auxilary/Auxiliary/

> +# XXX: ASAN-related build flags are stored in CMAKE_C_FLAGS.
> +set(TARGET_VM_FLAGS "${CMAKE_C_FLAGS} ${TARGET_C_FLAGS}")
> +
> +unset(TESTARCH)

Looks like you forgot to unset LUAJIT_ARCH. Or to add it in the header
note.

> diff --git a/cmake/SetVersion.cmake b/cmake/SetVersion.cmake
> new file mode 100646
> index 0000000..3f0247c
> --- /dev/null
> +++ b/cmake/SetVersion.cmake
> @@ -0,0 +1,45 @@
> +# Find, check and set LuaJIT's version from a VCS tag.
> +# Major portions taken verbatim or adapted from the uJIT.
> +# Copyright (C) 2015-2019 IPONWEB Ltd.
> +
> +function(SetVersion version majver minver patchver tweakver prerel)
> +  find_package(Git QUIET REQUIRED)
> +  if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND Git_FOUND)
> +    # Read version from the project's VCS and store the result
> +    # into version.
> +    execute_process(
> +      COMMAND ${GIT_EXECUTABLE} describe
> +      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
> +      OUTPUT_VARIABLE vcs_tag)
> +    string(STRIP "${vcs_tag}" vcs_tag)
> +    message(STATUS "[SetVersion] Reading version from VCS: ${vcs_tag}")
> +  else()
> +    # Use default version since no git is found in the system or
> +    # VCS directory is not found in repo root directory.

Typo: s/in repo root/in the repo root/

> +    set(vcs_tag "v2.1.0-beta3-0-g0000000")
> +    message(STATUS "[SetVersion] No VCS found, use default version: ${vcs_tag}")
> +  endif()

<snipped>

> diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
> new file mode 100644
> index 0000000..4a4c3cd
> --- /dev/null
> +++ b/etc/CMakeLists.txt
> @@ -0,0 +1,32 @@

<snipped>

> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> new file mode 100644
> index 0000000..8ada1a4
> --- /dev/null
> +++ b/src/CMakeLists.txt
> @@ -0,0 +1,391 @@

<snipped>

> +make_source_list(SOURCES_UTILS
> +  SOURCES
> +    lj_alloc.c
> +    lj_char.c
> +    lj_utils_leb128.c
> +    lj_vmmath.c
> +    lj_wbuf.c

Looks like there is no need to compile <lj_utils_leb128.c> and
<lj_wbuf.c>, when the memory profiler is disabled.

> +)
> +
> +make_source_list(SOURCES_PROFILER
> +  SOURCES
> +    lj_memprof.c
> +    lj_profile.c
> +)
> +
> +# Lua standard library + extensions by LuaJIT.
> +make_source_list(SOURCES_LUA_LIB
> +  # XXX: Please do not changes the order of the libraries

Typo: s/changes/change/

> +  # (required by buildvm).
> +  SOURCES
> +    lib_base.c
> +    lib_math.c
> +    lib_bit.c
> +    lib_string.c
> +    lib_table.c
> +    lib_io.c
> +    lib_os.c
> +    lib_package.c
> +    lib_debug.c
> +    lib_jit.c
> +    lib_ffi.c
> +    lib_misc.c
> +)
> +
> +# JIT compiler, core part.
> +make_source_list(SOURCES_JIT_CORE
> +  SOURCES
> +    lj_asm.c
> +    lj_ffrecord.c
> +    lj_ir.c
> +    lj_mcode.c
> +    lj_record.c
> +    lj_snap.c
> +    lj_trace.c
> +)
> +
> +# JIT compiler, machine-independent optimisations.

Typo: s/optimisations/optimizations/

> +make_source_list(SOURCES_JIT_OPT
> +  SOURCES
> +    lj_opt_dce.c
> +    lj_opt_fold.c
> +    lj_opt_loop.c
> +    lj_opt_mem.c
> +    lj_opt_narrow.c
> +    lj_opt_sink.c
> +    lj_opt_split.c
> +)

<snipped>

> +# Everything except FFI and JIT.
> +make_source_list(SOURCES_CORE_NO_JIT_FFI
> +  SOURCES
> +    ${SOURCES_RUNTIME}
> +    ${SOURCES_LUA_LIB}
> +    ${SOURCES_FRONTEND}
> +    ${SOURCES_PROFILER}
> +    ${SOURCES_UTILS}
> +)
> +
> +set(SOURCES_CORE ${SOURCES_CORE_NO_JIT_FFI})
> +
> +if(LUAJIT_HAS_JIT)

Here `LUAJIT_HAS_JIT` is "NOT LUAJIT_DISABLE_JIT" (or just
"LUAJIT_DISABLE_JIT"), so this branch is always taken.

> +  list(APPEND SOURCES_CORE ${SOURCES_JIT})
> +  if(LUAJIT_ENABLE_GDBJIT)
> +    list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_gdbjit.c)
> +  endif()
> +endif()
> +
> +if(LUAJIT_HAS_FFI)

Ditto.

> +  list(APPEND SOURCES_CORE ${SOURCES_FFI})
> +  if(NOT LUAJIT_HAS_JIT)
> +    # Needed for lj_mcode_sync.
> +    list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_mcode.c)
> +  endif()
> +endif()
> +

<snipped>

> +add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS})
> +add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS})
> +

Just highlight typo from the branch version.
| # Unfortunately, CMake provides no guarantees for install commands
| # used for the targets excluded from <all> and obligues user to

Typo: s/obligues/obliges/

| # handle this manually on his side. Hence check whether the
| # targets used below are presented for the chosen build mode.
| # See more info in CMake docs below:
| # https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html

This warnings are annoying (cmake version is 3.13.4):

| -- Found assembler: /usr/bin/cc
| -- Configuring done
| WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.

Can we suppress them?

> +install(TARGETS ${LUAJIT_DEPS}

The development releases of LuaJIT deliberately are not installed like
"luajit", but "luajit-2.1.0-beta3". Do we want to change this behaviour?

> +  RUNTIME
> +  DESTINATION bin
> +  COMPONENT luajit
> +)
> +install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
> +  ARCHIVE
> +  DESTINATION lib
> +  COMPONENT luajit
> +)
> +install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
> +  LIBRARY
> +  DESTINATION lib
> +  COMPONENT luajit
> +)
> +

<snipped>

> +
> +install(FILES
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bc.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bcsave.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dump.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/p.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/v.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/zone.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x86.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x64.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64be.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_ppc.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mipsel.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64.lua
> +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64el.lua
> +    ${CMAKE_CURRENT_BINARY_DIR}/jit/vmdef.lua

Nit: Is order important? Why are they not listed in alphabetical order?
Feel free to ignore.

> +  DESTINATION ${LUAJIT_DATAROOTDIR}/jit
> +  PERMISSIONS
> +    OWNER_READ OWNER_WRITE
> +    GROUP_READ
> +    WORLD_READ
> +  COMPONENT luajit
> +)

As I read from [4] CMake does not provide a default way to uninstall
installed files. But fortunately there is an example how doing it
in [4] directly. I think it is good to implement this part for
backward compatibility (especially, we have all prerequisites).

> diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
> new file mode 100644
> index 0000000..fe2de5c
> --- /dev/null
> +++ b/src/host/CMakeLists.txt
> @@ -0,0 +1,61 @@
> +# Building the toolchain for LuaJIT VM preprocessing.
> +
> +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> +
> +# FIXME: Both minilua and buildvm need to be build with the HOST_*

Sorry, I don't get it. What is the HOST_* toolchain?

> +# toolchain.
> +
> +# XXX: DynASM flags are set considering the target arch

Typo: s/arch/arch./.

> +include(SetDynASMFlags)
> +
> +# --- Build minilua ------------------------------------------------------------
> +

<snipped>

> diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> new file mode 100644
> index 0000000..f9ffc5e
> --- /dev/null
> +++ b/tools/CMakeLists.txt
> @@ -0,0 +1,77 @@
> +# Building tools for developing with uJIT.
> +# Major portions taken verbatim or adapted from the uJIT.
> +# Copyright (C) 2015-2019 IPONWEB Ltd.
> +
> +# See the rationale in the root CMakeLists.txt
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> +
> +set(LUAJIT_TOOLS_DEPS)
> +
> +if(LUAJIT_DISABLE_MEMPROF)
> +  message(STATUS "LuaJIT memory profiler support is disabled")
> +else()
> +  # XXX: Can use genex here since the value need to be evaluated
> +  # on the configuration phase. Fortunately, we know the exact

Typo: s/on/in/

> +  # path where LuaJIT binary is located.
> +  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
> +  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> +  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> +

<snipped>

> +  install(FILES
> +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
> +    DESTINATION ${LUAJIT_DATAROOTDIR}
> +    PERMISSIONS
> +      OWNER_READ OWNER_WRITE
> +      GROUP_READ
> +      WORLD_READ
> +    COMPONENT tools-parse-memprof
> +  )
> +  install(CODE

Is it reasonable to install memrpof tooling for not supported arches?
Yes, it's already working in that way, but maybe it is redundant.

> +    # XXX: Since the auxiliary script need to be configured in
> +    # other way it need to be reconfigured it prior to its
> +    # installation. Unfortunately, we need to manually specify

Nit: I propose to reformulate and split the first sentence like the
following:

| XXX: The auxiliary script needs to be configured for use in
| repository directly. In another way it needs to be reconfigured
| prior to installation.

Feel free to ignore.

> +    # the installation path in <configure_file> command.
> +    # Hope this script will be gone as a result of the issue below
> +    # https://github.com/tarantool/tarantool/issues/5688.
> +    "
> +      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
> +      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
> +      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
> +        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> +      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
> +    "
> +    COMPONENT tools-parse-memprof
> +  )

The result file is not executable.

> +endif()
> +
> +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})

Side note: why don't you provide custom `tools` target for memprof like
in the previous patch?

> -- 
> 2.25.0
> 

[1]: https://stackoverflow.com/questions/41773161/negate-boolean-variable-in-cmake
[2]: https://cmake.org/pipermail/cmake/2015-July/061116.html
[3]: https://cmake.org/cmake/help/latest/command/continue.html
[4]: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
  2021-02-04 22:53   ` Timur Safin via Tarantool-patches
  2021-02-11 19:23   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-13  3:47   ` Sergey Kaplun via Tarantool-patches
  2021-02-16 15:32     ` Igor Munkin via Tarantool-patches
  2 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-13  3:47 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, again!

On 02.02.21, Igor Munkin wrote:
> In scope of this patch the LuaJIT build system is partially ported from
> GNU Make to CMake. These changes provides CMake build system only for
> the following OS: GNU/Linux, OSX, FreeBSD. For other platrforms use the
> old build system (see the recipe in the previous commit).

Sorry, forgot to ask in my previous letter: Does it mean that we should
support two versions: Make and CMake?
After all, if something breaks old build Makefile becomes useless.

<snipped>

> -- 
> 2.25.0
> 

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake Igor Munkin via Tarantool-patches
  2021-02-08 15:05   ` Timur Safin via Tarantool-patches
@ 2021-02-14 18:48   ` Sergey Kaplun via Tarantool-patches
  2021-02-19 19:04     ` Igor Munkin via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-14 18:48 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!
Finally LuaJIT-related tests become separated from Tarantool build
system!

I've looked at the branch version.
Please consider my comments below.

On 02.02.21, Igor Munkin wrote:
> This patch introduces a separate target to run all available tests. The
> whole testing machinery is reworked much but the existing tests are left

Typo: s/much but/much, but/

> mostly unchanged. However, considering the different ways to integrate
> LuaJIT into the parent project, this machinery provides two new
> configuration options:
> * LUAJIT_USE_TEST: there might be a parent project integrating LuaJIT
>   sources in its source tree as a third party library (e.g.
>   https://github.com/tarantool/tarantool), so <test> target can be
>   already reserved there. This option allows to omit <test> target
>   configuration for LuaJIT to respect CMP0002 policy.
> * LUAJIT_TEST_BINARY: if LuaJIT tests are used in parent project test
>   routine, provide an option to choose which binary (i.e. Lua runtime)
>   to be used for running them.
> 
> The latter option value is used as a dependency for tests, and its
> default value is $<TARGET_FILE:${LUAJIT_DEPS}>. Unfortunately older

Typo: s/Unfortunately older/Unfortunately, older/

> CMake can't expand the generator expression used in DEPENDS section of

Typo? s/in DEPENDS section/in the DEPENDS section/

> <add_custom_(command|target)>. As a result the CMake minimum required
> version is bumped to 3.1 project-wide. For more info see CMake Release

Typo: s/info see/info, see/

> notes[1] for 3.1 version.
> 
> Finally, existing tests are grouped and moved to a separate directory
> under the root test directory to make the further addition of other
> available test suites in scope of tarantool/tarantool#4064 and
> tarantool/tarantool#4473 easier.
> 
> Tarantool tests are implemented using Tarantool on-board TAP module[2],
> that is moved to LuaJIT repository with a little changes to save Lua

Typo: s/a little changes/little changes/

> chunks untouched. Other auxiliary files for Tarantool-specific testing
> (such as *.skipcond, suite.ini), in turn, are removed.
> 
> [1]: https://cmake.org/cmake/help/latest/release/3.1.html#commands
> [2]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
> 
> Part of tarantool/tarantool#4862
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---

Side note: What kind of quotes is preferable for our code style in
LuaJIT?
The new <tap.lua> module is written with single quotes, but a lot of
code inside LuaJIT uses double quotes (see <src/jit/*.lua>, for
example). Also, as far as you've already changed indentation it will be
nice do not stop there and fix quotes and change `{ }` to `{}` as usual.

Side note: (this is more like discussion question) -- do we really need
to use Tarantool's <tap.lua> module here? I provide some
dissatisfactions, but as I say below, we can't just change this
module API because we want (if you remove this module from Tarantool
and save it only here).
If it is saved untouchable in Tarantool repo I see no reason to
avoid replacing it with another one more suitable (if we want) or
improving it. Amount of tests is really small now and it can be easily
adapted. May be we should take a look at Lua test-modules like [1] and
[2].

>  .gitignore                                    |   1 +
>  CMakeLists.txt                                |  31 +-
>  etc/CMakeLists.txt                            |   3 +-
>  src/CMakeLists.txt                            |   7 +-
>  src/host/CMakeLists.txt                       |   3 +-
>  test/CMakeLists.txt                           |  31 +-
>  test/gh-4427-ffi-sandwich.skipcond            |   7 -
>  test/gh-4427-ffi-sandwich/CMakeLists.txt      |   1 -
>  test/lj-flush-on-trace.skipcond               |   7 -
>  test/lj-flush-on-trace/CMakeLists.txt         |   1 -
>  test/misclib-getmetrics-capi.skipcond         |   7 -
>  test/misclib-getmetrics-capi/CMakeLists.txt   |   1 -
>  test/misclib-getmetrics-lapi.skipcond         |   7 -
>  test/suite.ini                                |   6 -
>  test/tarantool-tests/CMakeLists.txt           |  92 ++++++
>  .../gh-3196-incorrect-string-length.test.lua  |   2 +-
>  .../gh-4427-ffi-sandwich.test.lua             |  24 +-
>  .../gh-4427-ffi-sandwich/CMakeLists.txt       |   1 +
>  .../gh-4427-ffi-sandwich/libsandwich.c        |   0
>  ...gh-4476-fix-string-find-recording.test.lua |   2 +-
>  ...gh-4773-tonumber-fail-on-NUL-char.test.lua |   2 +-
>  .../lj-494-table-chain-infinite-loop.test.lua |   2 +-
>  ...lj-505-fold-no-strref-for-ptrdiff.test.lua |   2 +-
>  .../lj-524-fold-conv-respect-src-irt.test.lua |   2 +-
>  .../lj-flush-on-trace.test.lua                |  24 +-
>  .../lj-flush-on-trace/CMakeLists.txt          |   1 +
>  .../lj-flush-on-trace/libflush.c              |   0
>  .../misclib-getmetrics-capi.test.lua          |   5 +-
>  .../misclib-getmetrics-capi/CMakeLists.txt    |   1 +
>  .../misclib-getmetrics-capi/testgetmetrics.c  |   0
>  .../misclib-getmetrics-lapi.test.lua          |  10 +-
>  .../misclib-memprof-lapi.test.lua             |  15 +-
>  .../or-232-unsink-64-kptr.test.lua            |   0
>  test/tarantool-tests/tap.lua                  | 306 ++++++++++++++++++
>  test/tarantool-tests/utils.lua                |  43 +++
>  test/utils.lua                                |  33 --
>  tools/CMakeLists.txt                          |   2 +-
>  37 files changed, 569 insertions(+), 113 deletions(-)
>  delete mode 100644 test/gh-4427-ffi-sandwich.skipcond
>  delete mode 100644 test/gh-4427-ffi-sandwich/CMakeLists.txt
>  delete mode 100644 test/lj-flush-on-trace.skipcond
>  delete mode 100644 test/lj-flush-on-trace/CMakeLists.txt
>  delete mode 100644 test/misclib-getmetrics-capi.skipcond
>  delete mode 100644 test/misclib-getmetrics-capi/CMakeLists.txt
>  delete mode 100644 test/misclib-getmetrics-lapi.skipcond
>  delete mode 100644 test/suite.ini
>  create mode 100644 test/tarantool-tests/CMakeLists.txt
>  rename test/{ => tarantool-tests}/gh-3196-incorrect-string-length.test.lua (94%)
>  rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich.test.lua (70%)
>  create mode 100644 test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
>  rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich/libsandwich.c (100%)
>  rename test/{ => tarantool-tests}/gh-4476-fix-string-find-recording.test.lua (99%)
>  rename test/{ => tarantool-tests}/gh-4773-tonumber-fail-on-NUL-char.test.lua (95%)
>  rename test/{ => tarantool-tests}/lj-494-table-chain-infinite-loop.test.lua (99%)
>  rename test/{ => tarantool-tests}/lj-505-fold-no-strref-for-ptrdiff.test.lua (96%)
>  rename test/{ => tarantool-tests}/lj-524-fold-conv-respect-src-irt.test.lua (95%)
>  rename test/{ => tarantool-tests}/lj-flush-on-trace.test.lua (70%)
>  create mode 100644 test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
>  rename test/{ => tarantool-tests}/lj-flush-on-trace/libflush.c (100%)
>  rename test/{ => tarantool-tests}/misclib-getmetrics-capi.test.lua (97%)
>  create mode 100644 test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
>  rename test/{ => tarantool-tests}/misclib-getmetrics-capi/testgetmetrics.c (100%)
>  rename test/{ => tarantool-tests}/misclib-getmetrics-lapi.test.lua (98%)
>  rename test/{ => tarantool-tests}/misclib-memprof-lapi.test.lua (86%)
>  rename test/{ => tarantool-tests}/or-232-unsink-64-kptr.test.lua (100%)
>  create mode 100644 test/tarantool-tests/tap.lua
>  create mode 100644 test/tarantool-tests/utils.lua
>  delete mode 100644 test/utils.lua
> 
> diff --git a/.gitignore b/.gitignore
> index a21ee1c..35d2580 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -19,3 +19,4 @@ compile_commands.json

<snipped>

> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 0dba5d8..62ac369 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -6,7 +6,8 @@

<snipped>

> @@ -259,3 +260,31 @@ add_subdirectory(etc)
>  # --- Tools --------------------------------------------------------------------
>  
>  add_subdirectory(tools)
> +
> +# --- Testing source tree ------------------------------------------------------
> +
> +# Auxiliary options for testing.
> +
> +# FIXME: There might be a parent project integrating LuaJIT
> +# sources in its source tree as a third party library
> +# (e.g. https://github.com/tarantool/tarantool), so <test> target
> +# can be already reserved there. This option allows to omit <test>
> +# target configuration for LuaJIT to respect CMP0002 policy.
> +option(LUAJIT_USE_TEST "Generate <test> target" ON)
> +
> +# FIXME: If LuaJIT is used in parent project, provide an option
> +# to choose which binary to be used for running LuaJIT tests.
> +# XXX: This variable is used as a dependency for tests, and its
> +# default value is $<TARGET_FILE:${LUAJIT_DEPS}> assigned in <src>
> +# directory CMakeLists. Unfortunately CMake fails with generator
> +# expressions expansions used in <add_custom_(command|target)>.
> +# As a result the minimal required CMake version is set to 3.1.
> +# For more info see CMake Release notes for 3.1 version.

Typo: s/info see/info, see/

> +# https://cmake.org/cmake/help/latest/release/3.1.html#commands
> +# XXX: This options is moved below source tree processing since

Typo: s/options/option/

> +# the default binary target need to be generated.
> +set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING
> +  "Lua implementation to be used for tests. Default is luajit."

Nit: In my opinion "Default is 'luajit'." is better here.
Feel free to ignore.

> +)
> +
> +add_subdirectory(test)
> diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
> index 4a4c3cd..d54fa79 100644
> --- a/etc/CMakeLists.txt
> +++ b/etc/CMakeLists.txt
> @@ -1,6 +1,7 @@
>  # Building supplementary materials for LuaJIT.
>  
> -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> +# See the rationale in the root CMakeLists.txt.
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

Why is the minimum required version for this module/subdirectory
increased?

>  
>  set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
>  if(CMAKE_LIBRARY_ARCHITECTURE)
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> index 8ada1a4..209b5f0 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -2,7 +2,8 @@

<snipped>

> diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
> index fe2de5c..011a630 100644
> --- a/src/host/CMakeLists.txt
> +++ b/src/host/CMakeLists.txt
> @@ -1,6 +1,7 @@
>  # Building the toolchain for LuaJIT VM preprocessing.
>  
> -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> +# See the rationale in the root CMakeLists.txt.
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

Ditto.

>  
>  # FIXME: Both minilua and buildvm need to be build with the HOST_*
>  # toolchain.
> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
> index ec37580..f05dd90 100644
> --- a/test/CMakeLists.txt
> +++ b/test/CMakeLists.txt
> @@ -1,3 +1,28 @@
> -add_subdirectory(gh-4427-ffi-sandwich)
> -add_subdirectory(lj-flush-on-trace)
> -add_subdirectory(misclib-getmetrics-capi)
> +# Running various test suites against LuaJIT.
> +
> +# See the rationale in the root CMakeLists.txt.
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> +
> +add_subdirectory(tarantool-tests)
> +
> +add_custom_target(${PROJECT_NAME}-test DEPENDS
> +  tarantool-tests
> +)
> +
> +if(LUAJIT_USE_TEST)
> +  if(POLICY CMP0037)
> +    if(CMAKE_VERSION VERSION_LESS 3.11)
> +      # cmake below 3.11 reserves name test. Use old policy.

Typo? s/name/the name/
Nit: for me 'test' looks clearer here.
Feel free to ignore.

> +      # https://cmake.org/cmake/help/v3.11/release/3.11.html#other-changes
> +      cmake_policy(SET CMP0037 OLD)
> +    else()
> +      # Starting from cmake 3.11 name test reserved in special

Ditto.

> +      # cases and can be used as target name.

Typo? /target name/the target name/

> +      cmake_policy(SET CMP0037 NEW)
> +    endif()
> +  endif(POLICY CMP0037)
> +
> +  add_custom_target(test DEPENDS
> +    ${PROJECT_NAME}-test
> +  )
> +endif()
> diff --git a/test/gh-4427-ffi-sandwich.skipcond b/test/gh-4427-ffi-sandwich.skipcond
> deleted file mode 100644
> index 2a2ec4d..0000000
> --- a/test/gh-4427-ffi-sandwich.skipcond
> +++ /dev/null
> @@ -1,7 +0,0 @@

<snipped>

> diff --git a/test/gh-4427-ffi-sandwich/CMakeLists.txt b/test/gh-4427-ffi-sandwich/CMakeLists.txt
> deleted file mode 100644
> index 995c6bb..0000000
> --- a/test/gh-4427-ffi-sandwich/CMakeLists.txt
> +++ /dev/null
> @@ -1 +0,0 @@
> -build_lualib(libsandwich libsandwich.c)
> diff --git a/test/lj-flush-on-trace.skipcond b/test/lj-flush-on-trace.skipcond
> deleted file mode 100644
> index 2a2ec4d..0000000
> --- a/test/lj-flush-on-trace.skipcond
> +++ /dev/null
> @@ -1,7 +0,0 @@

<snipped>

> diff --git a/test/lj-flush-on-trace/CMakeLists.txt b/test/lj-flush-on-trace/CMakeLists.txt
> deleted file mode 100644
> index a90452d..0000000
> --- a/test/lj-flush-on-trace/CMakeLists.txt
> +++ /dev/null
> @@ -1 +0,0 @@
> -build_lualib(libflush libflush.c)
> diff --git a/test/misclib-getmetrics-capi.skipcond b/test/misclib-getmetrics-capi.skipcond
> deleted file mode 100644
> index 2a2ec4d..0000000
> --- a/test/misclib-getmetrics-capi.skipcond
> +++ /dev/null
> @@ -1,7 +0,0 @@

<snipped>

> diff --git a/test/misclib-getmetrics-capi/CMakeLists.txt b/test/misclib-getmetrics-capi/CMakeLists.txt
> deleted file mode 100644
> index e7cc8f8..0000000
> --- a/test/misclib-getmetrics-capi/CMakeLists.txt
> +++ /dev/null
> @@ -1 +0,0 @@
> -build_lualib(testgetmetrics testgetmetrics.c)
> diff --git a/test/misclib-getmetrics-lapi.skipcond b/test/misclib-getmetrics-lapi.skipcond
> deleted file mode 100644
> index 2a2ec4d..0000000
> --- a/test/misclib-getmetrics-lapi.skipcond
> +++ /dev/null
> @@ -1,7 +0,0 @@

<snipped>

> diff --git a/test/suite.ini b/test/suite.ini
> deleted file mode 100644
> index 0b9d5e2..0000000
> --- a/test/suite.ini
> +++ /dev/null
> @@ -1,6 +0,0 @@

<snipped>

> diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> new file mode 100644
> index 0000000..0be4b34
> --- /dev/null
> +++ b/test/tarantool-tests/CMakeLists.txt
> @@ -0,0 +1,92 @@
> +# Test suite that has been moved from Tarantool repository in
> +# scope of https://github.com/tarantool/tarantool/issues/4478.
> +
> +# See the rationale in the root CMakeLists.txt.
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> +
> +find_program(PROVE prove)
> +if(NOT PROVE)
> +  message(WARNING "`prove' is not found, so tarantool-tests target is not generated")
> +  return()
> +endif()
> +
> +macro(BuildTestLib lib sources)

Nit: BuildTestCLib or BuildTestLuaCLib is more verbose for me.
Feel free to ignore.

> +  add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
> +  target_include_directories(${lib} PRIVATE
> +    ${LUAJIT_SOURCE_DIR}
> +    ${CMAKE_CURRENT_SOURCE_DIR}
> +  )
> +  set_target_properties(${lib} PROPERTIES
> +    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
> +    PREFIX ""
> +  )
> +
> +  # XXX: This change affects current cmake variable scope and so

Typo: s/current/the current/

> +  # a user should care to don't use it in a top level scope.
> +  # The dynamic libraries are loaded with LuaJIT binary and use
> +  # symbols from it. So it is totally OK to have unresolved
> +  # symbols at build time.
> +  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> +    set_target_properties(${lib} PROPERTIES
> +      LINK_FLAGS "-undefined dynamic_lookup"
> +    )
> +  else()
> +    # FIXME: Unfortunately there is no another way to suppress

Typo: s/Unfortunately/Unfortunately,/

> +    # this linker option, so just strip it out from the flags.
> +    string(REPLACE "-Wl,--no-undefined" ""
> +      CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
> +    )
> +  endif()
> +  # XXX: Append the lib to be built to the dependecy list.

Typo: s/dependecy/dependency/

> +  # Unfortunately, CMake is a crap and there is no other way to
> +  # extend the list in parent scope but join two strings with
> +  # 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 interpreter can find and load it.

Typo: s/interpreter/the interpreter/

> +  # XXX: Here we see the other side of the coin. If one joins two
> +  # strings with semicolon, the value automatically becomes the
> +  # list. I have no idea what is wrong with this tool, but 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)
> +  # 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)
> +endmacro()
> +
> +add_subdirectory(gh-4427-ffi-sandwich)
> +add_subdirectory(lj-flush-on-trace)
> +add_subdirectory(misclib-getmetrics-capi)
> +
> +# The part of memory profiler toolchain is located in tools

Typo: s/of memory profiler/of the memory profiler/

> +# 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

Side note: Eeeh, it will be nicier to extend this part only for this
test, but too much extra movement is necessary for that.
The best is the enemy of the good. (c)

> +  "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua"
> +)
> +set(LUA_TEST_SUFFIX .test.lua)
> +file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
> +
> +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
> +# with dependecies are set in scope of BuildTestLib macro.
> +add_custom_command(
> +  COMMENT "Running Tarantool tests"
> +  OUTPUT tests.ok
> +  DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS}
> +  COMMAND
> +  env
> +    LUA_PATH="${LUA_PATH}\;\;"
> +    LUA_CPATH="${LUA_CPATH}\;\;"
> +    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
> +    ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
> +      --exec ${LUAJIT_TEST_BINARY}
> +      --ext ${LUA_TEST_SUFFIX}
> +      --failures --shuffle

See nothing bad to add `--verbose` option here. It's better to see the
name of the single test, not the test file only.

> +    && touch tests.ok
> +  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
> +)
> +
> +add_custom_target(tarantool-tests DEPENDS tests.ok)
> diff --git a/test/gh-3196-incorrect-string-length.test.lua b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> similarity index 94%
> rename from test/gh-3196-incorrect-string-length.test.lua
> rename to test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> index f135de7..edb728f 100755
> --- a/test/gh-3196-incorrect-string-length.test.lua
> +++ b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> @@ -1,4 +1,4 @@
> -#!/usr/bin/env tarantool
> +#!/usr/bin/env luajit

I think, that this line unnecessary, as much as an executable format of
the file. Same thoughts about all test files below.

>  
>  -- Miscellaneous test for LuaJIT bugs
>  local tap = require('tap')
> diff --git a/test/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> similarity index 70%
> rename from test/gh-4427-ffi-sandwich.test.lua
> rename to test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> index 9d5e50f..e9771e8 100755
> --- a/test/gh-4427-ffi-sandwich.test.lua
> +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> @@ -1,22 +1,30 @@
> -#!/usr/bin/env tarantool
> +#!/usr/bin/env luajit
>  
>  if #arg == 0 then
> -  require('utils').selfrun(arg, {
> +
> +  local utils = require('utils')
> +
> +  -- Disabled on *BSD due to #4819.
> +  utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> +
> +  utils.selfrun(arg, {
>      {
> -      arg = {
> +      arg  = {

This alignment is beauty, but unnecessary, please drop these changes.
Same remarks for the changes below.

>          1, -- hotloop (arg[1])

Side note: this may be not arg[1] or so on for Tarantool or pure LuaJIT
with additional flags. But good for now, so whatever.

>          1, -- trigger (arg[2])
>        },
> -      res = tostring(3), -- hotloop + trigger + 1
> -      msg = 'Trace is aborted',
> +      test = 'is',
> +      res  = tostring(3), -- hotloop + trigger + 1
> +      msg  = 'Trace is aborted',
>      },
>      {
> -      arg = {
> +      arg  = {
>          1, -- hotloop (arg[1])
>          2, -- trigger (arg[2])
>        },
> -      res = 'Lua VM re-entrancy is detected while executing the trace',
> -      msg = 'Trace is recorded',
> +      test = 'like',

What does it mean?

> +      res  = 'Lua VM re%-entrancy is detected while executing the trace',

This % is redundant.

> +      msg  = 'Trace is recorded',
>      },
>    })
>  end
> diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
> new file mode 100644
> index 0000000..5515567
> --- /dev/null
> +++ b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
> @@ -0,0 +1 @@
> +BuildTestLib(libsandwich libsandwich.c)
> diff --git a/test/gh-4427-ffi-sandwich/libsandwich.c b/test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c
> similarity index 100%
> rename from test/gh-4427-ffi-sandwich/libsandwich.c
> rename to test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c
> diff --git a/test/gh-4476-fix-string-find-recording.test.lua b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
> similarity index 99%
> rename from test/gh-4476-fix-string-find-recording.test.lua
> rename to test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
> index fb55680..92a11d5 100755
> --- a/test/gh-4476-fix-string-find-recording.test.lua
> +++ b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua
> @@ -1,4 +1,4 @@

<snipped>

> diff --git a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
> similarity index 95%
> rename from test/gh-4773-tonumber-fail-on-NUL-char.test.lua
> rename to test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
> index a660979..51e3142 100755
> --- a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua
> +++ b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua
> @@ -1,4 +1,4 @@

<snipped>

> diff --git a/test/lj-494-table-chain-infinite-loop.test.lua b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
> similarity index 99%
> rename from test/lj-494-table-chain-infinite-loop.test.lua
> rename to test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
> index 314eb29..9c04ef6 100755
> --- a/test/lj-494-table-chain-infinite-loop.test.lua
> +++ b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
> @@ -1,4 +1,4 @@

<snipped>

> diff --git a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
> similarity index 96%
> rename from test/lj-505-fold-no-strref-for-ptrdiff.test.lua
> rename to test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
> index a82bafa..6b0d70b 100755
> --- a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua
> +++ b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua
> @@ -1,4 +1,4 @@

<snipped>

> diff --git a/test/lj-524-fold-conv-respect-src-irt.test.lua b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
> similarity index 95%
> rename from test/lj-524-fold-conv-respect-src-irt.test.lua
> rename to test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
> index a232eea..fb92bee 100755
> --- a/test/lj-524-fold-conv-respect-src-irt.test.lua
> +++ b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
> @@ -1,4 +1,4 @@

<snipped>

> diff --git a/test/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua
> similarity index 70%
> rename from test/lj-flush-on-trace.test.lua
> rename to test/tarantool-tests/lj-flush-on-trace.test.lua
> index 0b3ccf4..f9a513f 100755
> --- a/test/lj-flush-on-trace.test.lua
> +++ b/test/tarantool-tests/lj-flush-on-trace.test.lua
> @@ -1,22 +1,30 @@
> -#!/usr/bin/env tarantool
> +#!/usr/bin/env luajit
>  
>  if #arg == 0 then
> -  require('utils').selfrun(arg, {
> +
> +  local utils = require('utils')
> +
> +  -- Disabled on *BSD due to #4819.
> +  utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> +
> +  utils.selfrun(arg, {
>      {
> -      arg = {
> +      arg  = {
>          1, -- hotloop (arg[1])
>          1, -- trigger (arg[2])
>        },
> -      res = 'OK',
> -      msg = 'Trace is aborted',
> +      test = 'is',

What does 'is' mean?

> +      res  = 'OK',
> +      msg  = 'Trace is aborted',
>      },
>      {
> -      arg = {
> +      arg  = {
>          1, -- hotloop (arg[1])
>          2, -- trigger (arg[2])
>        },
> -      res = 'JIT mode change is detected while executing the trace',
> -      msg = 'Trace is recorded',
> +      test = 'like',

Ditto.

> +      res  = 'JIT mode change is detected while executing the trace',
> +      msg  = 'Trace is recorded',
>      },
>    })
>  end
> diff --git a/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
> new file mode 100644
> index 0000000..91a18a6
> --- /dev/null
> +++ b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
> @@ -0,0 +1 @@
> +BuildTestLib(libflush libflush.c)
> diff --git a/test/lj-flush-on-trace/libflush.c b/test/tarantool-tests/lj-flush-on-trace/libflush.c
> similarity index 100%
> rename from test/lj-flush-on-trace/libflush.c
> rename to test/tarantool-tests/lj-flush-on-trace/libflush.c
> diff --git a/test/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
> similarity index 97%
> rename from test/misclib-getmetrics-capi.test.lua
> rename to test/tarantool-tests/misclib-getmetrics-capi.test.lua
> index 1ad6958..c418e9f 100755
> --- a/test/misclib-getmetrics-capi.test.lua
> +++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
> @@ -1,4 +1,7 @@

<snipped>

> diff --git a/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
> new file mode 100644
> index 0000000..cff0096
> --- /dev/null
> +++ b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
> @@ -0,0 +1 @@
> +BuildTestLib(testgetmetrics testgetmetrics.c)
> diff --git a/test/misclib-getmetrics-capi/testgetmetrics.c b/test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c
> similarity index 100%
> rename from test/misclib-getmetrics-capi/testgetmetrics.c
> rename to test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c
> diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> similarity index 98%
> rename from test/misclib-getmetrics-lapi.test.lua
> rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> index 3b3d1f8..959293d 100755
> --- a/test/misclib-getmetrics-lapi.test.lua
> +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> @@ -1,9 +1,12 @@
> -#!/usr/bin/env tarantool
> +#!/usr/bin/env luajit
>  
>  -- This is a part of tarantool/luajit testing suite.
>  -- Major portions taken verbatim or adapted from the LuaVela testing suite.
>  -- Copyright (C) 2015-2019 IPONWEB Ltd.
>  
> +-- Disabled on *BSD due to #4819.
> +require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> +
>  local tap = require('tap')
>  
>  local test = tap.test("lib-misc-getmetrics")
> @@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest)
>      subtest:plan(1)
>  
>      -- Force up garbage collect all dead objects.

Please, add comments about testing as a third party for the Tarantool
and GC finalizers to describe this change.

> -    collectgarbage("collect")
> +    repeat
> +        local count = collectgarbage("count")
> +        collectgarbage("collect")
> +    until collectgarbage("count") == count
>  
>      -- Bump getmetrics table and string keys allocation.
>      local old_metrics = misc.getmetrics()
> diff --git a/test/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua
> similarity index 86%
> rename from test/misclib-memprof-lapi.test.lua
> rename to test/tarantool-tests/misclib-memprof-lapi.test.lua
> index dd484f4..2b97212 100755
> --- a/test/misclib-memprof-lapi.test.lua
> +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua
> @@ -8,19 +8,14 @@ test:plan(9)
>  jit.off()
>  jit.flush()
>  
> --- FIXME: Launch tests with LUA_PATH enviroment variable.
> -local path = arg[0]:gsub("[^/]+%.test%.lua", "")
> -local path_suffix = "../tools/?.lua;"
> -package.path = ("%s%s;"):format(path, path_suffix)..package.path
> -

Side note: Nice, thanks!

>  local table_new = require "table.new"
>  
>  local bufread = require "utils.bufread"
>  local memprof = require "memprof.parse"
>  local symtab = require "utils.symtab"
>  
> -local TMP_BINFILE = arg[0]:gsub("[^/]+%.test%.lua", "%.%1.memprofdata.tmp.bin")
> -local BAD_PATH = arg[0]:gsub("[^/]+%.test%.lua", "%1/memprofdata.tmp.bin")
> +local TMP_BINFILE = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%.%1.memprofdata.tmp.bin")
> +local BAD_PATH = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%1/memprofdata.tmp.bin")
>  
>  local function payload()
>    -- Preallocate table to avoid table array part reallocations.
> @@ -82,7 +77,7 @@ end
>  
>  -- Not a directory.
>  local res, err, errno = misc.memprof.start(BAD_PATH)
> -test:ok(res == nil and err:match("Not a directory"))
> +test:ok(res == nil and err:match("No such file or directory"))
>  test:ok(type(errno) == "number")
>  
>  -- Profiler is running.
> @@ -125,9 +120,9 @@ local free = fill_ev_type(events, symbols, "free")
>  -- the number of allocations.
>  -- 1 event - alocation of table by itself + 1 allocation
>  -- of array part as far it is bigger than LJ_MAX_COLOSIZE (16).
> -test:ok(check_alloc_report(alloc, 27, 25, 2))
> +test:ok(check_alloc_report(alloc, 22, 20, 2))
>  -- 100 strings allocations.
> -test:ok(check_alloc_report(alloc, 32, 25, 100))
> +test:ok(check_alloc_report(alloc, 27, 20, 100))
>  
>  -- Collect all previous allocated objects.
>  test:ok(free.INTERNAL.num == 102)
> diff --git a/test/or-232-unsink-64-kptr.test.lua b/test/tarantool-tests/or-232-unsink-64-kptr.test.lua
> similarity index 100%
> rename from test/or-232-unsink-64-kptr.test.lua
> rename to test/tarantool-tests/or-232-unsink-64-kptr.test.lua
> diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua

Side note: firstly I thought that <tap.lua> will be clashing with tap
inside other suites, but these conflicts will be easily resolved by
LUA_PATH.

> new file mode 100644
> index 0000000..fd03132
> --- /dev/null
> +++ b/test/tarantool-tests/tap.lua

Feel free to stop me from refactoring anytime, but I try to dump all my
thoughts about this module now to be referred later.

Side note: It's a pity that there is no such module as Perl's Test::Deep [3]
in Lua (or at least I haven't seen one).

> @@ -0,0 +1,306 @@
> +--- tap.lua internal file.
> +---
> +--- The Test Anything Protocol vesion 13 producer.
> +---
> +
> +-- Initializer FFI for <iscdata> check.

This comment is misleading a bit, NULL usage is important too.

> +local ffi = require('ffi')
> +local NULL = ffi.new('void *')

Nit: What if LuaJIT is built without FFI?

> +
> +local function indent(chars)
> +  return (' '):rep(chars)
> +end
> +
> +local function traceback(level)
> +  local trace = { }

Nit: s/{ }/{}/ here and below.

> +  level = level or 3

Why 3? Please add the comment about this here.
Also, please mention about LuaJIT behaviour here (traceback not
reporting tail call) -- that's why traceback is one and the same for
`ok()` and `fail()` functions.

> +  while true do
> +    local info = debug.getinfo(level, 'nSl')
> +    if not info then break end

Nit: split this line to three.
Feel free to ignore.

> +    table.insert(trace, {
> +      source   = info.source,
> +      src      = info.short_src,
> +      line     = info.linedefined or 0,
> +      what     = info.what,
> +      name     = info.name,
> +      namewhat = info.namewhat,
> +      filename = info.source:sub(1, 1) == '@' and info.source:sub(2) or 'eval',

What does 'eval' mean?

Side note: Also `filename` looks redundant as far as `source` exists,
but break current API is not encouraged...

> +    })
> +    level = level + 1
> +  end
> +  return trace
> +end
> +
> +local function diag(test, fmt, ...)
> +  io.write(indent(4 * test.level), ('# %s\n'):format(fmt:format(...)))
> +end
> +
> +local function ok(test, cond, message, extra)
> +  test.total = test.total + 1
> +  if cond then
> +    io.write(indent(4 * test.level), ('ok - %s\n'):format(message))
> +    return true
> +  end
> +
> +  test.failed = test.failed + 1
> +  io.write(indent(4 * test.level), ('not ok - %s\n'):format(message))

Nit: 4 * test.level repeated several times. May be encapsulated inside
`local cur_level` variable.
Feel free to ignore.

> +
> +  -- Dump extra contents added in outer space.
> +  for key, value in pairs(extra or { }) do
> +    io.write(indent(2 + 4 * test.level), ('%s:\t%s\n'):format(key, value))
> +  end
> +
> +  if not test.trace then

Thanks for the simplifying this code chunk! I've pried into
<tarantool/src/lua/tap.lua> sources, and you really enhance it
gracefully!

> +    return false
> +  end
> +
> +  local trace = traceback()

Nit: Looks like this chunk can be separated inside one function
`dump_traceback()` back or whatever.
Feel free to ignore.

> +  local tindent = indent(4 + 4 * test.level)
> +  io.write(tindent, ('filename:\t%s\n'):format(trace[#trace].filename))
> +  io.write(tindent, ('line:\t%s\n'):format(trace[#trace].line))
> +  for frameno, frame in ipairs(trace) do
> +    io.write(tindent, ('frame #%d\n'):format(frameno))

Nit: Looks inconsistent with other output.

| io.write(tindent, ('frameno: #%d\n'):format(frameno))

hits better, in my opinion.

Looks like it will be good to add the function that does something like:

| io.write(indent, ('%s:\t%s\n'):format(key, value))

Feel free to ignore.

> +    local findent = indent(2) .. tindent

Nit: s/ .. /../
Here and below.

> +    for key, value in pairs(frame) do
> +      io.write(findent, ('%s:\t%s\n'):format(key, value))
> +    end
> +  end
> +  return false
> +end

<snipped>

> +local function cmpdeeply(got, expected, extra)
> +  if type(expected) == 'number' or type(got) == 'number' then
> +    extra.got = got
> +    extra.expected = expected
> +    -- Handle NaN.
> +    if got ~= got and expected ~= expected then
> +      return true
> +    end
> +    return got == expected
> +  end
> +
> +  if ffi.istype('bool', got) then got = (got == 1) end
> +  if ffi.istype('bool', expected) then expected = (expected == 1) end
> +
> +  if extra.strict and type(got) ~= type(expected) then
> +    extra.got = type(got)
> +    extra.expected = type(expected)
> +    return false
> +  end
> +
> +  if type(got) ~= 'table' or type(expected) ~= 'table' then
> +    extra.got = got
> +    extra.expected = expected
> +    return got == expected
> +  end
> +
> +  local path = extra.path or '/'

This `path` in `extra` field looks unusable, please drop it.

> +  local visited_keys = {}
> +
> +  for i, v in pairs(got) do

Nit: `k` instead `i` looks more convenient.

> +    visited_keys[i] = true

This is not good enough, visited keys should be cashed better:

| tarantool> local test = tap.test("<T>") local t1 = {1, 2, 3} t1[4] = {t1} local t2 = {1, 2, 3} t2[4] = {t2} return test:is_deeply(t1, t2), t1, t2
| TAP version 13
| ---
| - error: stack overflow

> +    extra.path = path .. '/' .. i
> +    if not cmpdeeply(v, expected[i], extra) then
> +      return false
> +    end
> +  end
> +
> +  -- Check if expected contains more keys then got.
> +  for i, v in pairs(expected) do

Ditto: `i` -> `k`.

> +    if visited_keys[i] ~= true and (extra.strict or v ~= NULL) then
> +      extra.expected = 'key ' .. tostring(i)
> +      extra.got = 'nil'
> +      return false
> +    end
> +  end
> +
> +  extra.path = path
> +
> +  return true
> +end

<snipped>

> +local function is(test, got, expected, message, extra)
> +  extra = extra or { }
> +  extra.got = got
> +  extra.expected = expected
> +  local rc = (test.strict == false or type(got) == type(expected))

Nit: It is nice to leave the comment here to provide description why
just `==` is not enough. Also, I don't like this behaviour -- it
disrespects `eq` metamethod, and there is not mentioned in the doc [4].

> +             and got == expected
> +  return ok(test, rc, message, extra)
> +end
> +
> +local function isnt(test, got, unexpected, message, extra)
> +  extra = extra or { }
> +  extra.got = got
> +  extra.unexpected = unexpected
> +  local rc = (test.strict == true and type(got) ~= type(unexpected))

Ditto.

> +             or got ~= unexpected
> +  return ok(test, rc, message, extra)
> +end
> +
> +local function is_deeply(test, got, expected, message, extra)
> +  extra = extra or { }
> +  extra.got = got
> +  extra.expected = expected
> +  extra.strict = test.strict
> +  return ok(test, cmpdeeply(got, expected, extra), message, extra)
> +end
> +
> +local function isnil(test, v, message, extra)
> +  return is(test, not v and v == nil and 'nil' or v, 'nil', message, extra)

Looks like type(v) 'nil' is enough. Or please add a comment why it is
necessary.

> +end
> +
> +local function isnumber(test, v, message, extra)
> +  return is(test, type(v), 'number', message, extra)
> +end
> +
> +local function isstring(test, v, message, extra)
> +  return is(test, type(v), 'string', message, extra)
> +end
> +
> +local function istable(test, v, message, extra)
> +  return is(test, type(v), 'table', message, extra)
> +end
> +
> +local function isboolean(test, v, message, extra)
> +  return is(test, type(v), 'boolean', message, extra)
> +end
> +
> +local function isfunction(test, v, message, extra)
> +  return is(test, type(v), 'function', message, extra)
> +end
> +
> +local function isudata(test, v, utype, message, extra)

Side note: Looks like it does not test type(v) equals "udata", that's
inconsistent with other checkers. But changing it equals to break
backward compatibility.

> +  extra = extra or { }
> +  extra.expected = ('userdata<%s>'):format(utype)
> +  if type(v) ~= 'userdata' then
> +    extra.got = type(v)
> +    return fail(test, message, extra)
> +  end
> +  extra.got = ('userdata<%s>'):format(getmetatable(v))
> +  return ok(test, getmetatable(v) == utype, message, extra)

Does it assume that compared udata-s should have the same metatable?

> +end
> +
> +local function iscdata(test, v, ctype, message, extra)

Ditto about inconsistency.

> +  extra = extra or { }
> +  extra.expected = ffi.typeof(ctype)
> +  if type(v) ~= 'cdata' then
> +    extra.got = type(v)
> +    return fail(test, message, extra)
> +  end
> +  extra.got = ffi.typeof(v)
> +  return ok(test, ffi.istype(ctype, v), message, extra)
> +end
> +
> +local test_mt

Nit: Why is it declared here, not inside the `new()` function?

> +
> +local function new(parent, name, fun, ...)

Side note: Why so serious :}?

> +  local level = parent ~= nil and parent.level + 1 or 0
> +  local test = setmetatable({
> +    parent  = parent,
> +    name    = name,
> +    level   = level,
> +    total   = 0,
> +    failed  = 0,
> +    planned = 0,
> +    trace   = parent == nil and true or parent.trace,
> +    strict  = false,

What does strict mean and how it can be changed?
I see nothing bad to copy some rationale from documentation [5] here
as comments for each field.

> +  }, test_mt)
> +  if fun == nil then
> +    return test
> +  end
> +  test:diag('%s', test.name)
> +  fun(test, ...)
> +  test:diag('%s: end', test.name)
> +  return test:check()
> +end
> +
> +local function plan(test, planned)
> +  test.planned = planned
> +  io.write(indent(4 * test.level), ('1..%d\n'):format(planned))

Side note: I like approach from Perl's Test::More with the `done_testing()`
function [6]. It is useful for bazaar-like developers and projects,
when tests are written fast, spontaneous and they don't care about plan
counting and updating. Just reflecting...

> +end
> +
> +local function check(test)
> +  if test.checked then
> +    error('check called twice')

Nit: eror_level = 2 is better here in my opinion.
Feel free to ignore.

> +  end
> +  test.checked = true
> +  if test.planned ~= test.total then
> +    if test.parent ~= nil then
> +      ok(test.parent, false, 'bad plan', {
> +        planned = test.planned,
> +        run = test.total,
> +      })
> +    else
> +      diag(test, ('bad plan: planned %d run %d')
> +        :format(test.planned, test.total))
> +    end
> +  elseif test.failed > 0 then
> +    if test.parent ~= nil then
> +      ok(test.parent, false, 'failed subtests', {
> +        failed = test.failed,
> +        planned = test.planned,
> +      })
> +    else
> +      diag(test, 'failed subtest: %d', test.failed)
> +    end
> +  else
> +    if test.parent ~= nil then
> +      ok(test.parent, true, test.name)
> +    end
> +  end

Nit: looks like `if test.parent ~= nil` can be taken out for branches.
Feel free to ignore.

> +  return test.planned == test.total and test.failed == 0
> +end
> +
> +test_mt = {
> +  __index = {
> +    test       = new,
> +    plan       = plan,
> +    check      = check,
> +    diag       = diag,
> +    ok         = ok,
> +    fail       = fail,
> +    skip       = skip,
> +    is         = is,
> +    isnt       = isnt,
> +    isnil      = isnil,
> +    isnumber   = isnumber,
> +    isstring   = isstring,
> +    istable    = istable,
> +    isboolean  = isboolean,
> +    isfunction = isfunction,
> +    isudata    = isudata,
> +    iscdata    = iscdata,
> +    is_deeply  = is_deeply,
> +    like       = like,
> +    unlike     = unlike,
> +  }
> +}
> +
> +return {
> +  test = function(...)
> +    io.write('TAP version 13\n')
> +    return new(nil, ...)
> +  end
> +}
> diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua
> new file mode 100644
> index 0000000..197b138
> --- /dev/null
> +++ b/test/tarantool-tests/utils.lua
> @@ -0,0 +1,43 @@
> +local M = { }
> +
> +local tap = require('tap')
> +
> +function M.selfrun(arg, checks)
> +  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
> +
> +  test:plan(#checks)
> +
> +  local vars = {
> +    LUABIN = arg[-1],
> +    SCRIPT = arg[0],
> +    PATH   = arg[0]:gsub('%.test%.lua', ''),
> +    SUFFIX = package.cpath:match('?.(%a+);'),
> +  }
> +
> +  local cmd = string.gsub('LUA_PATH="<PATH>/?.lua;$LUA_PATH" ' ..

Why do you use that way instead <CMakeLists.txt> configuration?

> +                          'LUA_CPATH="<PATH>/?.<SUFFIX>;$LUA_CPATH" ' ..
> +                          'LD_LIBRARY_PATH=<PATH>:$LD_LIBRARY_PATH ' ..
> +                          '<LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars)
> +
> +  for _, ch in pairs(checks) do
> +    local testf = test[ch.test]
> +    assert(testf, ("tap doesn't provide test.%s function"):format(ch.test))
> +    local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg)))
> +    local res = proc:read('*all'):gsub('^%s+', ''):gsub('%s+$', '')

Are these spaces important?

> +    -- XXX: explicitly pass <test> as an argument to <testf>
> +    -- to emulate test:is(...), test:like(...), etc.
> +    testf(test, res, ch.res, ch.msg)
> +  end
> +
> +  os.exit(test:check() and 0 or 1)
> +end

<snipped>

> diff --git a/test/utils.lua b/test/utils.lua
> deleted file mode 100644
> index 707d6ef..0000000
> --- a/test/utils.lua
> +++ /dev/null
> @@ -1,33 +0,0 @@

<snipped>

> diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> index f9ffc5e..af3de33 100644
> --- a/tools/CMakeLists.txt
> +++ b/tools/CMakeLists.txt
> @@ -2,7 +2,7 @@
>  # Major portions taken verbatim or adapted from the uJIT.
>  # Copyright (C) 2015-2019 IPONWEB Ltd.
>  
> -# See the rationale in the root CMakeLists.txt
> +# See the rationale in the root CMakeLists.txt.

This is already fixed on branch! Thanks!

>  cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
>  
>  set(LUAJIT_TOOLS_DEPS)
> -- 
> 2.25.0
> 

[1]: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/
[2]: https://fperrad.frama.io/lua-TestMore/
[3]: https://metacpan.org/pod/Test::Deep
[4]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/#taptest-is
[5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
[6]: https://perldoc.perl.org/Test::More#done_testing

-- 
Best regards,
Sergey Kaplun


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib* Igor Munkin via Tarantool-patches
       [not found]   ` <012f01d6fe1a$a2aa6890$e7ff39b0$@tarantool.org>
@ 2021-02-14 19:16   ` Sergey Kaplun via Tarantool-patches
  2021-02-16 15:29     ` Igor Munkin via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-14 19:16 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!

Looks like I was late for the ball and you got two LGTMs, but here’s my
two cents on the matter, because I've been mentioned. Feel free to
ignore my nitpicks.

LGTM, except two nitpicks below.

On 02.02.21, Igor Munkin wrote:
> Since the regular static analysis has not been enabled for the test
> chunks in LuaJIT repository yet, the tests for recently implemented
> features still produce luacheck warnings.
> 
> The most of the issues are fixed in scope of the commit
> 8fc103fb1a21c28185a1942e75d8d9485e3aade7 ('test: fix warnings spotted by
> luacheck') and this patch fixes the remaining ones.
> 
> Fixes tarantool/tarantool#5631

Nit: Looks like 'Closes' or even 'Part of' (considering the next patch),
not 'Fixes'.
Also, After this patch there are tons of misc-related warnings
by the luacheсk without config. So, I think that this patch should be
squashed with the next one.
Feel free to ignore.

> Part of tarantool/tarantool#4862
> Part of tarantool/tarantool#5470
> Follows up tarantool/tarantool#5187
> 
> Reported-by: Sergey Bronnikov <sergeyb@tarantool.org>
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
>  .../misclib-getmetrics-capi.test.lua          | 22 ++++++---------
>  .../misclib-getmetrics-lapi.test.lua          | 28 +++++++++----------
>  2 files changed, 23 insertions(+), 27 deletions(-)
> 
> diff --git a/test/tarantool-tests/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
> index c418e9f..d409ea9 100755
> --- a/test/tarantool-tests/misclib-getmetrics-capi.test.lua
> +++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
> @@ -38,29 +38,29 @@ test:ok(testgetmetrics.objcount(function(iterations)
>      }
>  
>      -- Separate objects creations to separate jit traces.
> -    for i = 1, iterations do
> -        table.insert(placeholder.str, tostring(i))
> +    for _ = 1, iterations do
> +        table.insert(placeholder.str, tostring(_))
>      end
>  
> -    for i = 1, iterations do
> -        table.insert(placeholder.tab, {i})
> +    for _ = 1, iterations do
> +        table.insert(placeholder.tab, {_})
>      end
>  
> -    for i = 1, iterations do
> +    for _ = 1, iterations do
>          table.insert(placeholder.udata, newproxy())
>      end
>  
> -    for i = 1, iterations do
> +    for _ = 1, iterations do
>          -- Check counting of VLA/VLS/aligned cdata.
>          table.insert(placeholder.cdata, ffi.new("char[?]", 4))
>      end
>  
> -    for i = 1, iterations do
> +    for _ = 1, iterations do

Side note: this change is not necessary for the patch, but the code looks
more consistent. So, it is good, thanks!

>          -- Check counting of non-VLA/VLS/aligned cdata.
> -        table.insert(placeholder.cdata, ffi.new("uint64_t", i))
> +        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
>      end
>  

<snipped>

> diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> index 959293d..d54caac 100755
> --- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> @@ -58,10 +58,10 @@ test:test("gc-allocated-freed", function(subtest)
>      until collectgarbage("count") == count
>  
>      -- Bump getmetrics table and string keys allocation.
> -    local old_metrics = misc.getmetrics()
> +    misc.getmetrics()

Side note: This is a very elegant solution! Cool!

>  
>      -- Remember allocated size for getmetrics table.
> -    old_metrics = misc.getmetrics()
> +    local old_metrics = misc.getmetrics()

<snipped>

> @@ -372,7 +372,7 @@ test:test("strhash", function(subtest)
>      assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
>      old_metrics = new_metrics
>  
> -    local str1  = "strhash".."_hit"
> +    local _ = "strhash".."_hit"
>  
>      new_metrics = misc.getmetrics()
>      assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 20)
> @@ -384,7 +384,7 @@ test:test("strhash", function(subtest)
>      assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
>      old_metrics = new_metrics
>  
> -    local str2 = "new".."string"
> +    local _ = "new".."string"

Nit: this `local` is redundant.
Feel free to ignore.

>  
>      new_metrics = misc.getmetrics()
>      assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 19)
> -- 
> 2.25.0
> 

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake Igor Munkin via Tarantool-patches
  2021-02-04 22:52   ` Timur Safin via Tarantool-patches
@ 2021-02-14 19:32   ` Sergey Kaplun via Tarantool-patches
  2021-02-19 19:14     ` Igor Munkin via Tarantool-patches
  1 sibling, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-14 19:32 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!
Nice to see all LuaJIT-related stuff inside its repo!

LGTM, except few questions below.

On 02.02.21, Igor Munkin wrote:
> This patch introduces a separate target to run luacheck against all Lua
> chunks within LuaJIT repository except those explicitly ignored in
> .luacheckrc. There is also a single additional change over the 'luajit'
> std defaults: to suppress all false positives related to <misc>

Typo: defaults are standards already. 'std' or 'defatults' is redundant
here.

> namespace introduced in 5a61e1ab54b5c66bfebd836db1ac47996611e065 ('misc:
> add C and Lua API for platform metrics'), this name is added to
> <read_globals> list.
> 
> All Lua sources originally inherited from LuaJIT vanilla repository are
> ignored, to leave them coherent with the upstream.
> 
> The new target is a dependency for the root <test> target.
> 

Nit: Looks like you should mention tarantool/tarantool#5631 here.
Or squash it with the previous patch.
See rationale here [1].
Feel free to ignore.

> Part of tarantool/tarantool#4862
> Part of tarantool/tarantool#5470
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
>  .gitignore          |  1 +
>  .luacheckrc         | 11 +++++++++++
>  test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+)
>  create mode 100644 .luacheckrc
> 
> diff --git a/.gitignore b/.gitignore
> index 35d2580..7902547 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -17,6 +17,7 @@ Makefile

<snipped>

> diff --git a/.luacheckrc b/.luacheckrc
> new file mode 100644
> index 0000000..0a5d001
> --- /dev/null
> +++ b/.luacheckrc
> @@ -0,0 +1,11 @@

<snipped>

> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
> index f05dd90..c89efc2 100644
> --- a/test/CMakeLists.txt
> +++ b/test/CMakeLists.txt
> @@ -3,6 +3,36 @@
>  # See the rationale in the root CMakeLists.txt.
>  cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

Side note: Why this version?

>  
> +find_program(LUACHECK luacheck)
> +if(LUACHECK)
> +  set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
> +  set(LUACHECK_OK ${CMAKE_CURRENT_BINARY_DIR}/luacheck.ok)
> +  file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
> +  add_custom_command(
> +    COMMENT "Running luacheck static analysis"
> +    OUTPUT ${LUACHECK_OK}
> +    DEPENDS ${LUACHECK} ${LUACHECK_RC} ${LUACHECK_DEPS}

Why are `${LUACHECK}` and `${LUACHECK_RC}` are mentioned?

> +    COMMAND
> +      ${LUACHECK} ${PROJECT_SOURCE_DIR}
> +        --codes
> +        --config ${LUACHECK_RC}
> +      && touch ${LUACHECK_OK}
> +      # XXX: Filenames in .luacheckrc are considered relative to
> +      # the working directory, hence luacheck should be run in the
> +      # project root directory.
> +      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
> +  )

<snipped>

> -- 
> 2.25.0
> 

[1]: https://lists.tarantool.org/tarantool-patches/20210214191626.GF9361@root/T/#md50dbe78c52523ca739f2751d96c61edcf2e7a36

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-11 19:23   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-16 15:28     ` Igor Munkin via Tarantool-patches
  2021-02-18  9:56       ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-16 15:28 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for your review!

On 11.02.21, Sergey Kaplun wrote:
> Hi, Igor!
> 
> Thanks for the patch!
> 
> Appreciate your hard work! Thanks for the verbose comments!
> The building process is faster now!
> I'm sorry: I can't see your GUI innovations, unfortunately. :(
> 
> I've looked into branch version.
> Please consider my comments below.

I've fixed all typos you've mentioned, so I left only those I haven't or
have changed in a different way.

> 
> On 02.02.21, Igor Munkin wrote:
> > In scope of this patch the LuaJIT build system is partially ported from
> 
> Typo: s/In scope/In the scope/

I strongly doubt. Neither you, nor me: Within.

> 

<snipped>

> > old build system (see the recipe in the previous commit).
> 
> This paragraph describes only supported OS. There is no description of
> supported build system options.
> IINM there is no cross-compiling support, stripping debug info, amalgam
> build for now, it should be mentioned in the commit message too.

Here is the new wording for this section:
| Within this patch the LuaJIT build system is partially ported from GNU
| Make to CMake. These changes provide CMake build system for all
| supported host architectures but only for the following OS: GNU/Linux,
| OSX, FreeBSD. For other platrforms and specific builds (such as 'amalg',
| stripped binary and shared library, cross-compiling support) use the old
| build system (see the recipe in the previous commit).

> 
> > 
> > Several components of the new build system such as automatic version
> > detection, source files list generation and some recipes for
> > CMakeLists.txt are taken verbatim or adapted from LuaVela repository.
> > 
> > Part of tarantool/tarantool#4862
> > 
> > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > ---
> 
> Side note: This is not related to the patch directly but what about
> Tarantool COPYRIGHT notice in the LuaJIT code and inside new cmake files
> in particular?

We definitely need to make such activity, but I have no idea how to do
it a right way. Let's postpone it and discuss later, if you don't mind.

> 
> >  .gitignore                 |  12 +-
> >  CMakeLists.txt             | 261 +++++++++++++++++++++++++
> >  cmake/LuaJITUtils.cmake    |  31 +++
> >  cmake/MakeSourceList.cmake |  47 +++++
> >  cmake/SetDynASMFlags.cmake | 130 ++++++++++++
> >  cmake/SetTargetFlags.cmake |  42 ++++
> >  cmake/SetVersion.cmake     |  45 +++++
> >  etc/CMakeLists.txt         |  32 +++
> >  src/CMakeLists.txt         | 391 +++++++++++++++++++++++++++++++++++++
> >  src/host/CMakeLists.txt    |  61 ++++++
> >  tools/CMakeLists.txt       |  77 ++++++++
> >  11 files changed, 1128 insertions(+), 1 deletion(-)
> >  create mode 100644 CMakeLists.txt
> >  create mode 100644 cmake/LuaJITUtils.cmake
> >  create mode 100644 cmake/MakeSourceList.cmake
> >  create mode 100644 cmake/SetDynASMFlags.cmake
> >  create mode 100644 cmake/SetTargetFlags.cmake
> >  create mode 100644 cmake/SetVersion.cmake
> >  create mode 100644 etc/CMakeLists.txt
> >  create mode 100644 src/CMakeLists.txt
> >  create mode 100644 src/host/CMakeLists.txt
> >  create mode 100644 tools/CMakeLists.txt
> 
> Side note: should we update <doc/install.html> (change Makefile ->
> Makefile.original)? Looks more related to the previous patch.

OK, fixed, squashed with the previous commit. Here is the diff:

================================================================================

diff --git a/doc/install.html b/doc/install.html
index c491c60..b2e4753 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -164,9 +164,9 @@ hold all user-configurable settings:
 </p>
 <ul>
 <li><tt>src/luaconf.h</tt> sets some configuration variables.</li>
-<li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX
+<li><tt>Makefile.original</tt> has settings for <b>installing</b> LuaJIT (POSIX
 only).</li>
-<li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT
+<li><tt>src/Makefile.original</tt> has settings for <b>compiling</b> LuaJIT
 under POSIX, MinGW or Cygwin.</li>
 <li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with
 MSVC or WinSDK.</li>
@@ -228,7 +228,7 @@ variable is not set, then it's forced to <tt>10.4</tt>.
 </p>
 <h3>Installing LuaJIT</h3>
 <p>
-The top-level Makefile installs LuaJIT by default under
+The top-level Makefile.original installs LuaJIT by default under
 <tt>/usr/local</tt>, i.e. the executable ends up in
 <tt>/usr/local/bin</tt> and so on. You need root privileges
 to write to this path. So, assuming sudo is installed on your system,
@@ -366,7 +366,7 @@ target OS differ, or you'll get assembler or linker errors:
 </p>
 <ul>
 <li>E.g. if you're compiling on a Windows or OSX host for embedded Linux or Android, you need to add <tt>TARGET_SYS=Linux</tt> to the examples below.</li>
-<li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.</li>
+<li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile.original</tt> and use <tt>TARGET_SYS=Other</tt>.</li>
 <li>Don't forget to specify the same <tt>TARGET_SYS</tt> for the install step, too.</li>
 </ul>
 <p>
@@ -647,7 +647,7 @@ the paths needed to locate the shared library.</li>
 to a shadow tree instead of the root tree of the build system.</li>
 <li><tt>MULTILIB</tt> sets the architecture-specific library path component
 for multilib systems. The default is <tt>lib</tt>.</li>
-<li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt>
+<li>Have a look at the top-level <tt>Makefile.original</tt> and <tt>src/Makefile.original</tt>
 for additional variables to tweak. The following variables <em>may</em> be
 overridden, but it's <em>not</em> recommended, except for special needs
 like cross-builds:

================================================================================

NB: I haven't break the lines intentionally to make the diff minimal.

> 

<snipped>

> > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > new file mode 100644
> > index 0000000..0dba5d8
> > --- /dev/null
> > +++ b/CMakeLists.txt
> > @@ -0,0 +1,261 @@
> > +# LuaJIT -- interpreter and JIT compiler for Lua language.
> > +# This is the main entry point for building, testing and
> > +# packaging the project.
> > +# Major portions taken verbatim or adapted from the uJIT.
> > +# Copyright (C) 2015-2019 IPONWEB Ltd.
> > +
> > +# --- Initial setup ------------------------------------------------------------
> > +
> > +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> > +project(LuaJIT C)
> > +
> > +#
> 
> Nit: Comment style is inconsistent. Feel free to ignore.

Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index af9f8e4..e5be172 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,12 +11,10 @@
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 project(LuaJIT C)
 
-#
 # XXX: Originally CMake machinery is introduced to make LuaJIT
 # testing self-sufficient. Since there are only few systems
 # covered with the tests in our CI, there is no need to support
 # others for now and the original build system can be used.
-#
 
 if(NOT(
    CMAKE_SYSTEM_NAME STREQUAL "Linux" OR

================================================================================

> 
> > +# XXX: Originally CMake machinery is introduced to make LuaJIT
> > +# testing self-sufficient. Since there are only few systems
> 
> Typo: s/only few systems/only a few systems/

No, I want to emphasize the amount, so the article changes the meaning.

> 

<snipped>

> > +
> > +set(BUILDMODE_VALUES mixed static dynamic)
> 
> See nothing bad to transfer comments described each option here.

Added, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e5be172..786dbe0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,14 @@ set(LUAJIT_INCLUDEDIR
   include/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}
 )
 
+# Mixed mode creates a static + dynamic library and a statically
+# linked luajit. Static mode creates a static library and a
+# statically linked luajit. Dynamic mode creates a dynamic library
+# and a dynamically linked luajit.
+# XXX: dynamically linked executable will only run when the
+# library is installed!
 set(BUILDMODE_VALUES mixed static dynamic)
+# The default build mode is mixed mode on POSIX.
 list(GET BUILDMODE_VALUES 0 BUILDMODE_DEFAULT)
 set(BUILDMODE ${BUILDMODE_DEFAULT} CACHE STRING
   "Build mode. Choose one of the following: ${BUILDMODE_VALUES}."

================================================================================

> 
> > +list(GET BUILDMODE_VALUES 0 BUILDMODE_DEFAULT)

<snipped>

> > +# --- Compilation flags setup --------------------------------------------------
> > +
> > +if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
> > +  AppendFlags(TARGET_C_FLAGS -DLUA_ROOT='"${CMAKE_INSTALL_PREFIX}"')
> 
> In Makefile.original I see the following check inside this branch:
> 
> | ifneq (/usr,$(PREFIX))
> |   TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
> | endif
> 
> Is it related to unsupported build systems?

AFAICS, it is. Anyway, if you're having troubles, feel free to share.

> 
> I've found some warnings on macOS in the configuration stage, that looks
> related:
> 
> | CMake Warning (dev):
> |   Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
> |   --help-policy CMP0042" for policy details.  Use the cmake_policy command to
> |   set the policy and suppress this warning.
> |
> |   MACOSX_RPATH is not specified for the following targets:
> |
> |    libluajit_shared
> |
> | This warning is for project developers.  Use -Wno-dev to suppress it.
> 
> Version of macOS:
> | $ uname -a
> | Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
> 

I've seen this warning, and have tried almost all combinations of the
MACOS_RPATH, CMP0042, and target options -- nothing has helped. BTW,
this warning breaks nothing for me (on my old Mac). If this bothers you,
please report your issues. If you have a solution, please share it.

> > +endif()
> > +
> > +if(CMAKE_LIBRARY_ARCHITECTURE)
> > +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> > +endif()
> 
> What about `LUA_LMULTILIB`?
> 
> Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
> like it does in Makefile.original?

DESTDIR is supported out of the box in CMake. MULTILIB is "autodetected"
via CMake[1] (I hope, but never tried). Regardging LMULTILIB, I have no
idea what its purpose is. Do you?

> 
> > +

<snipped>

> > +AppendFlags(CMAKE_C_FLAGS -Wall)
> > +option(LUAJIT_ENABLE_WARNINGS "Build LuaJIT with warnings enabled" OFF)
> 
> Nit: This confused me a little. All warnings already enabled. This flag
> enables extra warnings. I may be change like the following:
> s/LUAJIT_ENABLE_WARNINGS/LUAJIT_ENABLE_EXTRA_WARNINGS/
> s/warnings/extra warnings/
> or
> s/LUAJIT_ENABLE_WARNINGS/LUAJIT_ENABLE_MORE_WARNINGS/
> s/warnings/more warnings/
> Feel free to ignore.

Honestly, I don't want a huge option name. Let's return to the subj in
scope of the options revision that we discussed with Timur nearby.

Ignoring for now.

> 

<snipped>

> > +# Permanently disable the FFI extension to reduce the size of the
> > +# LuaJIT executable. But please consider that the FFI library is
> > +# compiled-in, but NOT loaded by default. It only allocates any
> > +# memory, if you actually make use of it.
> > +option(LUAJIT_DISABLE_FFI "FFI support" OFF)
> > +if(LUAJIT_DISABLE_FFI)
> > +  AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_FFI)
> > +endif()
> > +set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI)
> 
> Don't get your point here. `set()` does not support any expressions
> as I've known from [1][2]. This just always defines `LUAJIT_HAS_FFI`.

OMG, CMake is the greatest shit in the world. I just dropped these
auxiliary variables, squashed with the previous commit. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a1536ed..13208d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -130,7 +130,6 @@ option(LUAJIT_DISABLE_FFI "FFI support" OFF)
 if(LUAJIT_DISABLE_FFI)
   AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_FFI)
 endif()
-set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI)
 
 # Features from Lua 5.2 that are unlikely to break existing code
 # are enabled by default. Some other features that *might* break
@@ -149,7 +148,6 @@ option(LUAJIT_DISABLE_JIT "JIT support" OFF)
 if(LUAJIT_DISABLE_JIT)
   AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_JIT)
 endif()
-set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT)
 
 # Some architectures (e.g. PPC) can use either single-number (1)
 # or dual-number (2) mode. Please see LJ_ARCH_NUMMODE in lj_arch.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index df9b85d..e70b786 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -140,17 +140,20 @@ make_source_list(SOURCES_CORE_NO_JIT_FFI
 
 set(SOURCES_CORE ${SOURCES_CORE_NO_JIT_FFI})
 
-if(LUAJIT_HAS_JIT)
+# Build JIT sources if JIT support is enabled.
+if(NOT LUAJIT_DISABLE_JIT)
   list(APPEND SOURCES_CORE ${SOURCES_JIT})
   if(LUAJIT_ENABLE_GDBJIT)
     list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_gdbjit.c)
   endif()
 endif()
 
-if(LUAJIT_HAS_FFI)
+# Build FFI sources if FFI support is enabled.
+if(NOT LUAJIT_DISABLE_FFI)
   list(APPEND SOURCES_CORE ${SOURCES_FFI})
-  if(NOT LUAJIT_HAS_JIT)
-    # Needed for lj_mcode_sync.
+  # Build lj_mcode.c if JIT support is disabled since
+  # <lj_mcode_sync> is used in src/lj_ccallback.c.
+  if(LUAJIT_DISABLE_JIT)
     list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_mcode.c)
   endif()
 endif()

================================================================================

> 

<snipped>

> 
> > +
> > +# Some architectures (e.g. PPC) can use either single-number (1)
> > +# or dual-number (2) mode. Uncomment one of these lines to
> 
> Nit: See nothing to uncomment :). May be change it?

*Кхъ*. Removed :)

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca03fda..cea0a53 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -152,9 +152,8 @@ endif()
 set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT)
 
 # Some architectures (e.g. PPC) can use either single-number (1)
-# or dual-number (2) mode. Uncomment one of these lines to
-# override the default mode. Please see LJ_ARCH_NUMMODE in
-# lj_arch.h for details.
+# or dual-number (2) mode. Please see LJ_ARCH_NUMMODE in lj_arch.h
+# for details.
 set(LUAJIT_NUMMODE_VALUES 1 2)
 set(LUAJIT_NUMMODE_DEFAULT "")
 set(LUAJIT_NUMMODE ${LUAJIT_NUMMODE_DEFAULT} CACHE STRING

================================================================================

> 

<snipped>

> 
> Nit: It would be nice to see "Debugging support" section here like for
> other sections like "Main source tree" or so on.
> Feel free to ignore.

These are in "Compilation flags setup" section.

Ignoring.

> 

<snipped>

> 
> > +# Turn on assertions for the Lua/C API to debug problems with
> > +# lua_* calls. This is rather slow -- use only while developing C
> > +# libraries/embeddings.
> > +option(LUAJIT_USE_APICHECK "Assertions for the Lua/C API" OFF)
> > +if(LUAJIT_USE_APICHECK)
> > +  AppendFlags(TARGET_C_FLAGS -DLUA_USE_APICHECK)
> > +endif()
> 
> Hmm, as for me looks more user friendly not to change option names here.
> Just leave `LUA_USE_APICHECK` here.
> I've already singed wings on it, when run Lua/LuaJIT/lua-Harness
> tests! Yeees, I'd not looked at Cmake warnings carefully :(

Renamed these flags, but the new naming is more consistent, so we'll
revert it back in scope of build options refactoring. Diff is below:

================================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25d86c0..673cf36 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -230,16 +230,16 @@ endif()
 # Turn on assertions for the Lua/C API to debug problems with
 # lua_* calls. This is rather slow -- use only while developing C
 # libraries/embeddings.
-option(LUAJIT_USE_APICHECK "Assertions for the Lua/C API" OFF)
-if(LUAJIT_USE_APICHECK)
+option(LUA_USE_APICHECK "Assertions for the Lua/C API" OFF)
+if(LUA_USE_APICHECK)
   AppendFlags(TARGET_C_FLAGS -DLUA_USE_APICHECK)
 endif()
 
 # Turn on assertions for the whole LuaJIT VM. This significantly
 # slows down everything. Use only if you suspect a problem with
 # LuaJIT itself.
-option(LUAJIT_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF)
-if(LUAJIT_USE_ASSERT)
+option(LUA_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF)
+if(LUA_USE_ASSERT)
   AppendFlags(TARGET_C_FLAGS -DLUA_USE_ASSERT)
 endif()
 

================================================================================

> 

<snipped>

> 
> > +
> > +# TODO: Implement a configuration option to enable ASAN.
> > +# There are two entries of LUAJIT_USE_ASAN define:
> > +# $ grep -rnF 'LUAJIT_USE_ASAN' .
> > +# ./src/lj_str.c:15:#if LUAJIT_USE_ASAN
> > +# ./src/host/buildvm.c:36:#if LUAJIT_USE_ASAN
> > +# At the same time this flag is not provided by LuaJIT original
> > +# build system (i.e. src/Makefile.original) so there are no
> > +# related compiler and linker flags passed. This should be done
> > +# the right way later.
> 
> Good catch! I decide to check what else is missing. Here are some other
> options (sorry, for that dump, just want to save it anywhere):
> | $ grep -rnF 'LUAJIT_CTYPE_CHECK_ANCHOR'
> | src/lj_ctype.c:139:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
> | src/lj_ctype.c:159:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
> 
> | $ grep -rnF 'LUAJIT_DEBUG_RA'
> | src/lj_asm.c:192:/* #define LUAJIT_DEBUG_RA */
> | src/lj_asm.c:194:#ifdef LUAJIT_DEBUG_RA

I tried only this one, while debugging the RENAME issue.
It would be nice to export it.

> 
> | $ grep -rnF 'LUAJIT_DISABLE_DEBUGINFO'
> | src/lj_parse.c:1397:#ifndef LUAJIT_DISABLE_DEBUGINFO
> | src/lj_parse.c:2700:#ifdef LUAJIT_DISABLE_DEBUGINFO
> | Binary file src/.lj_parse.c.swp matches
> | src/lj_memprof.c:102:  ** -DLUAJIT_DISABLE_DEBUGINFO flag.
> 
> | $ grep -rnF 'LUAJIT_DISABLE_PROFILE'
> | src/lj_arch.h:501:#if defined(LUAJIT_DISABLE_PROFILE)
> 
> | $ grep -rnF 'LUAJIT_DISABLE_VMEVENT'
> | src/lj_trace.c:796:#ifndef LUAJIT_DISABLE_VMEVENT
> | src/lj_vmevent.h:33:#ifdef LUAJIT_DISABLE_VMEVENT
> | src/lib_jit.c:118:#ifdef LUAJIT_DISABLE_VMEVENT
> 
> | $ grep -rnF 'LUAJIT_ENABLE_CHECKHOOK'
> | src/lj_record.c:2621:#ifdef LUAJIT_ENABLE_CHECKHOOK
> 
> | $ grep -rnF 'LUAJIT_ENABLE_TABLE_BUMP'
> | src/lj_record.c:259:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:1179:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:1477:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:1523:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:1874:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:2321:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_record.c:2544:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> | src/lj_jit.h:455:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> 
> | $ grep -rnF 'LUAJIT_NO_UNALIGNED'
> | src/lj_def.h:287:#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
> 
> | $ grep -rnF 'LUAJIT_USE_PERFTOOLS'
> | src/lj_trace.c:85:#ifdef LUAJIT_USE_PERFTOOLS
> | src/lj_trace.c:163:#ifdef LUAJIT_USE_PERFTOOLS
> 
> | $ grep -rnF 'LUAJIT_UNWIND_EXTERNAL'
> | doc/extensions.html:402:<td class="excplatform">ARM <tt>-DLUAJIT_UNWIND_EXTERNAL</tt></td>
> | src/lj_err.c:53:** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled
> | src/lj_err.c:64:#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND
> | src/lj_err.c:521:  ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every*
> 
> They not all related to debugging (AFAICT only `LUAJIT_USE_PERFTOOLS`,
> `LUAJIT_CTYPE_CHECK_ANCHOR` and `LUAJIT_DEBUG_RA`), more to configure.
> May be it is better to create separate issue(s) for all these options?

Feel free to do it :)

> 

<snipped>

> 
> > diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> > new file mode 100644
> > index 0000000..faaef6b
> > --- /dev/null
> > +++ b/cmake/LuaJITUtils.cmake
> > @@ -0,0 +1,31 @@
> > +function(LuaJITTestArch outvar strflags)
> > +  # XXX: <execute_process> simply splits the COMMAND argument by
> > +  # spaces with no further parsing. At the same time GCC is bad in
> > +  # argument handling, so let's help it a bit.
> > +  separate_arguments(TEST_C_FLAGS UNIX_COMMAND ${strflags})
> 
> Nit: TESTARCH_C_FLAGS looks more verbose to me. Just TEST seems to be
> referring to testing.
> Feel free to ignore.

Renamed, squashed with the previous commit. Here is the diff:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index faaef6b..1769675 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -2,9 +2,9 @@ function(LuaJITTestArch outvar strflags)
   # XXX: <execute_process> simply splits the COMMAND argument by
   # spaces with no further parsing. At the same time GCC is bad in
   # argument handling, so let's help it a bit.
-  separate_arguments(TEST_C_FLAGS UNIX_COMMAND ${strflags})
+  separate_arguments(TESTARCH_C_FLAGS UNIX_COMMAND ${strflags})
   execute_process(
-    COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM
+    COMMAND ${CMAKE_C_COMPILER} ${TESTARCH_C_FLAGS} -E lj_arch.h -dM
     WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
     OUTPUT_VARIABLE TESTARCH
   )

================================================================================

> 
> Nit: Also, it would be nice to see comments here, why do we use this
> approach instead use of CMAKE_HOST_SYSTEM_PROCESSOR variable (is set by
> `uname -p`).
> Feel free to ignore.

I have no clear explanation of these and I definitely don't want to
write a bullshit in the comments, so I will either add TODO here if you
insist, or ignore this one.

> > +  execute_process(
> > +    COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM
> 
> May be it will better to provide not default compiler here?
> It will be easier to adjust cross compiling with this.

I don't get this, but as we discussed before cross compiling activity is
out of the scope of this issue.

> 
> > +    WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
> > +    OUTPUT_VARIABLE TESTARCH
> > +  )
> > +  set(${outvar} ${TESTARCH} PARENT_SCOPE)
> > +endfunction()
> > +
> > +function(LuaJITArch outvar testarch)
> > +  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)
> 
> I occur the following error, when build inside Docker emulating
> aarch64 (`FROM arm64v8/centos`):
> 
> | Error: pointer size mismatch in cross-build.
> | Try: make HOST_CC="gcc -m32" CROSS=...
> |
> | make[2]: *** [src/CMakeFiles/vm_static.dir/build.make:62: src/lj_vm.S] Error 1
> | make[1]: *** [CMakeFiles/Makefile2:193: src/CMakeFiles/vm_static.dir/all] Error 2
> | make[1]: *** Waiting for unfinished jobs....
> | Error: pointer size mismatch in cross-build.
> | Try: make HOST_CC="gcc -m32" CROSS=...
> |
> | make[2]: *** [src/CMakeFiles/vm_shared.dir/build.make:62: src/lj_vm.S] Error 1
> | make[1]: *** [CMakeFiles/Makefile2:394: src/CMakeFiles/vm_shared.dir/all] Error 2
> 
> All OK with the old Makefile:
> 
> | $ make -f Makefile.original -j
> | ==== Building LuaJIT 2.1.0-beta3 ====
> | ...
> | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> 
> Content of <src/host/CMakeFiles/buildvm.dir/build.make>:
> | src/host/buildvm_arch.h: dynasm/*.lua
> |         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/luajit/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating buildvm_arch.h"
> |         cd /luajit/src/host && /luajit/src/host/minilua /luajit/dynasm/dynasm.lua -D ENDIAN_LE -D P64 -D JIT -D FFI -D DUALNUM -D FPU -D HFABI -D VER=80 -o buildvm_arch.h /luajit/src/vm_arm.dasc
> 
> vm_arm.dasc instead vm_arm64.dasc here.

Oops.

> 
> All because LJ_TARGET_ARM matched before LJ_TARGET_ARM64 in the line
> below. And it works for MIPS, because of different order :)
> Swap arches and leave comments about an order, please.

Neat, many thanks for testing and investigation! Fixed, squashed,
force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index 1769675..0a662f7 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -12,7 +12,7 @@ function(LuaJITTestArch outvar strflags)
 endfunction()
 
 function(LuaJITArch outvar testarch)
-  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)
+  foreach(TRYARCH X64 X86 ARM64 ARM PPC MIPS64 MIPS)
     string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
     if(FOUND EQUAL -1)
       continue()

================================================================================

> 
> Nit: As far as we can't organize this CPU arches in alphabetical order
> I propose reverse-alphabetical ;):

God, please, no...

> 
> | X86 X64 PPC MIPS64 MIPS ARM64 ARM
> 
> Feel free to ignore (it's more a joke).

Not funny, dude...

> 
> > +    string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
> > +    if(FOUND EQUAL -1)
> > +      continue()
> 
> `continue()` command was introduced in 3.2 CMake version
> according to [1]. So even 3.1 version is not enough.

Shit, that can't be true... But thanks for checking it!

> 
> This is a result for verision 3.0.2.
> | CMake Error at cmake/LuaJITUtils.cmake:18 (continue):
> |   Unknown CMake command "continue".
> | Call Stack (most recent call first):
> |   cmake/SetTargetFlags.cmake:16 (LuaJITArch)
> |   src/CMakeLists.txt:164 (include)
> |
> |
> | -- Configuring incomplete, errors occurred!
> 
> Please, add `cmake_minimum_required()` command to the top, or do not use

Hell no, I'll just rewrite this part and leave *non-toxic* comment about
it. When CMake will be updated in Tarantool next time, we'll refactor
this part. But not today.

> `continue()` command.

Reimplemented, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index 0a662f7..2c4a27e 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -14,12 +14,18 @@ endfunction()
 function(LuaJITArch outvar testarch)
   foreach(TRYARCH X64 X86 ARM64 ARM PPC MIPS64 MIPS)
     string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
-    if(FOUND EQUAL -1)
-      continue()
+    # FIXME: <continue> is introduced in CMake version 3.2, but
+    # the minimum required version now is 3.1. This is not such a
+    # vital feature, so it's not used now. However, when CMake
+    # version is bumped next time, it's better to rewrite this
+    # part using <continue> for "early return".
+    # For more info see CMake Release notes for 3.2 version.
+    # https://cmake.org/cmake/help/latest/release/3.2.html#commands
+    if(NOT FOUND EQUAL -1)
+      string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
+      set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
+      return()
     endif()
-    string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
-    set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
-    return()
   endforeach()
   message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture")
 endfunction()

================================================================================

> 
> > +    endif()
> > +    string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
> > +    set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
> > +    return()
> > +  endforeach()
> > +  message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture")
> 
> It would be nice to check return status from <lj_arch.h> preprocessing
> command. On ppc64 inside Docker (`FROM ppc64le/debian`) configuration
> ends successfully, arch detected as "ppc64":
> 
> | lj_arch.h:436:2: error: #error "No support for PowerPC 64 bit mode (yet)"
> |  #error "No support for PowerPC 64 bit mode (yet)"
> |   ^~~~~
> | lj_arch.h:436:2: error: #error "No support for PowerPC 64 bit mode (yet)"
> |  #error "No support for PowerPC 64 bit mode (yet)"
> |   ^~~~~
> | -- Configuring done
> | WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | -- Generating done
> | -- Build files have been written to: /luajit

Nice! Added, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index 2c4a27e..be0a8b7 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -7,8 +7,15 @@ function(LuaJITTestArch outvar strflags)
     COMMAND ${CMAKE_C_COMPILER} ${TESTARCH_C_FLAGS} -E lj_arch.h -dM
     WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
     OUTPUT_VARIABLE TESTARCH
+    RESULT_VARIABLE TESTARCH_RC
   )
-  set(${outvar} ${TESTARCH} PARENT_SCOPE)
+  if(TESTARCH_RC EQUAL 0)
+    set(${outvar} ${TESTARCH} PARENT_SCOPE)
+  else()
+    # XXX: Yield a special value (an empty string) to respect the
+    # failed preprocessor routine and then fail arch detection.
+    set(${outvar} "" PARENT_SCOPE)
+  endif()
 endfunction()
 
 function(LuaJITArch outvar testarch)

================================================================================

> 
> > +endfunction()
> 

<snipped>

> 
> > diff --git a/cmake/SetDynASMFlags.cmake b/cmake/SetDynASMFlags.cmake
> > new file mode 100644
> > index 0000000..9a920c3
> > --- /dev/null
> > +++ b/cmake/SetDynASMFlags.cmake
> > @@ -0,0 +1,130 @@
> > +# This module exposes following variables to the project:
> 
> Side note: Nice approach, I like it!
> 
> > +# * HOST_C_FLAGS
> > +# * DYNASM_ARCH
> > +# * DYNASM_FLAGS
> > +
> > +# XXX: buildvm includes core headers and thus has to be built
> > +# with the same flags and defines as the LuaJIT core itself.
> > +set(HOST_C_FLAGS)
> > +set(DYNASM_ARCH)
> > +set(DYNASM_FLAGS)
> > +
> > +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS} ${HOST_CFLAGS}")
> 
> Nit: Looks like it is necessary to use <Makefile.original> to define
> LUAJIT_TARGET directly? I think that should be mentioned in the commit
> message too.

Sorry, don't get this one.

> Feel free to ignore.
> 

<snipped>

> 
> > diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> > new file mode 100644
> > index 0000000..260fc6b
> > --- /dev/null
> > +++ b/cmake/SetTargetFlags.cmake

<snipped>

> 
> Are -dynamiclib and -fPIC flags forced set by CMake?
> Also, I don't find -install_name -compatibility_version -current_version
> flags. Are they insignificant?

Could you please share the corresponding part of "make VERBOSE=1"? These
variables should be set by CMake.

> 
> I got warnings from linker in the build stage on macOS:
> 
> | $ uname -a
> | Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
> 
> | ld: warning: -seg1addr not 16384 byte aligned, rounding up
> | /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols
> | [ 98%] Built target libluajit_shared
> | /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols
> 
> Is it related to this?

No, you'll see this if you run <ar> with no suppressing its output. The
same issue is also presented for lj_gdbjit.c when GDBJIT support is
disabled.

> 

<snipped>

> 
> > +# XXX: ASAN-related build flags are stored in CMAKE_C_FLAGS.
> > +set(TARGET_VM_FLAGS "${CMAKE_C_FLAGS} ${TARGET_C_FLAGS}")
> > +
> > +unset(TESTARCH)
> 
> Looks like you forgot to unset LUAJIT_ARCH. Or to add it in the header
> note.

The former, thanks!

> 

<snipped>

> 
> > diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> > new file mode 100644
> > index 0000000..8ada1a4
> > --- /dev/null
> > +++ b/src/CMakeLists.txt
> > @@ -0,0 +1,391 @@
> 
> <snipped>
> 
> > +make_source_list(SOURCES_UTILS
> > +  SOURCES
> > +    lj_alloc.c
> > +    lj_char.c
> > +    lj_utils_leb128.c
> > +    lj_vmmath.c
> > +    lj_wbuf.c
> 
> Looks like there is no need to compile <lj_utils_leb128.c> and
> <lj_wbuf.c>, when the memory profiler is disabled.

There is no need, but strictly saying both units are not strictly
related to memprof, but rather providing a standalone functionality. So,
I leave it unchanged.

> 

<snipped>

> 
> | # handle this manually on his side. Hence check whether the
> | # targets used below are presented for the chosen build mode.
> | # See more info in CMake docs below:
> | # https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html
> 
> This warnings are annoying (cmake version is 3.13.4):

Did you try the latest version of the patchset? All these <install>
rules are moved under condition after Timur comment.

> 
> | -- Found assembler: /usr/bin/cc
> | -- Configuring done
> | WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> 
> Can we suppress them?
> 
> > +install(TARGETS ${LUAJIT_DEPS}
> 
> The development releases of LuaJIT deliberately are not installed like
> "luajit", but "luajit-2.1.0-beta3". Do we want to change this behaviour?

What do you mean by that? Could you please provide an example?

> 
> > +  RUNTIME
> > +  DESTINATION bin
> > +  COMPONENT luajit
> > +)
> > +install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
> > +  ARCHIVE
> > +  DESTINATION lib
> > +  COMPONENT luajit
> > +)
> > +install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
> > +  LIBRARY
> > +  DESTINATION lib
> > +  COMPONENT luajit
> > +)
> > +
> 
> <snipped>
> 
> > +
> > +install(FILES
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bc.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/bcsave.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dump.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/p.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/v.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/zone.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x86.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x64.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64be.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_ppc.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mipsel.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64.lua
> > +    ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64el.lua
> > +    ${CMAKE_CURRENT_BINARY_DIR}/jit/vmdef.lua
> 
> Nit: Is order important? Why are they not listed in alphabetical order?
> Feel free to ignore.

Reordered, squashed, force-pushed to the branch.

> 
> > +  DESTINATION ${LUAJIT_DATAROOTDIR}/jit
> > +  PERMISSIONS
> > +    OWNER_READ OWNER_WRITE
> > +    GROUP_READ
> > +    WORLD_READ
> > +  COMPONENT luajit
> > +)
> 
> As I read from [4] CMake does not provide a default way to uninstall
> installed files. But fortunately there is an example how doing it
> in [4] directly. I think it is good to implement this part for
> backward compatibility (especially, we have all prerequisites).

OK, but I adjusted it a bit:

================================================================================

diff --git a/.gitignore b/.gitignore
index a21ee1c..2103a30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ CMakeCache.txt
 CMakeFiles
 Makefile
 cmake_install.cmake
+cmake_uninstall.cmake
 compile_commands.json
 install_manifest.txt
 luajit-parse-memprof
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16a9d5b..6bba9f4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -261,3 +261,16 @@ add_subdirectory(etc)
 # --- Tools --------------------------------------------------------------------
 
 add_subdirectory(tools)
+
+# --- Misc rules ---------------------------------------------------------------
+
+# XXX: Implement <uninstall> target using the following recipe:
+# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
+if(NOT TARGET uninstall)
+  configure_file(${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in
+    cmake_uninstall.cmake @ONLY ESCAPE_QUOTES)
+
+  add_custom_target(uninstall
+    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
+  )
+endif()
diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in
new file mode 100644
index 0000000..fc3b885
--- /dev/null
+++ b/cmake/cmake_uninstall.cmake.in
@@ -0,0 +1,24 @@
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif()
+
+# XXX: This loop removes only entries from install_manifest.txt,
+# but do nothing for the directories created while installation.
+# Honestly, the recipe is awful, but is better than nothing.
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    execute_process(
+      COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
+      RESULT_VARIABLE REMOVE_RC
+      OUTPUT_QUIET
+    )
+    if(NOT "${REMOVE_RC}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif()
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif()
+endforeach()

================================================================================

> 
> > diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
> > new file mode 100644
> > index 0000000..fe2de5c
> > --- /dev/null
> > +++ b/src/host/CMakeLists.txt
> > @@ -0,0 +1,61 @@
> > +# Building the toolchain for LuaJIT VM preprocessing.
> > +
> > +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> > +
> > +# FIXME: Both minilua and buildvm need to be build with the HOST_*
> 
> Sorry, I don't get it. What is the HOST_* toolchain?

HOST_CC, HOST_CFLAGS, HOST_LDFLAGS, HOST_LIBS, HOST_SYS -- see
<src/Makefile.original> for more details.

> 
> > +# toolchain.
> > +
> > +# XXX: DynASM flags are set considering the target arch
> 

<snipped>

> 
> > diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> > new file mode 100644
> > index 0000000..f9ffc5e
> > --- /dev/null
> > +++ b/tools/CMakeLists.txt
> > @@ -0,0 +1,77 @@
> > +# Building tools for developing with uJIT.
> > +# Major portions taken verbatim or adapted from the uJIT.
> > +# Copyright (C) 2015-2019 IPONWEB Ltd.
> > +
> > +# See the rationale in the root CMakeLists.txt
> > +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> > +
> > +set(LUAJIT_TOOLS_DEPS)
> > +
> > +if(LUAJIT_DISABLE_MEMPROF)
> > +  message(STATUS "LuaJIT memory profiler support is disabled")
> > +else()
> > +  # XXX: Can use genex here since the value need to be evaluated
> > +  # on the configuration phase. Fortunately, we know the exact
> 
> Typo: s/on/in/

Niether of these. 'at' or 'while' are fine (I chose the former).

> 
> > +  # path where LuaJIT binary is located.
> > +  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
> > +  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> > +  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> > +
> 
> <snipped>
> 
> > +  install(FILES
> > +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
> > +    DESTINATION ${LUAJIT_DATAROOTDIR}
> > +    PERMISSIONS
> > +      OWNER_READ OWNER_WRITE
> > +      GROUP_READ
> > +      WORLD_READ
> > +    COMPONENT tools-parse-memprof
> > +  )
> > +  install(CODE
> 
> Is it reasonable to install memrpof tooling for not supported arches?
> Yes, it's already working in that way, but maybe it is redundant.

I see no problem: this part works fine on all hosts, so you can take the
binary dump and parse it anywhere.

> 
> > +    # XXX: Since the auxiliary script need to be configured in
> > +    # other way it need to be reconfigured it prior to its
> > +    # installation. Unfortunately, we need to manually specify
> 
> Nit: I propose to reformulate and split the first sentence like the
> following:
> 
> | XXX: The auxiliary script needs to be configured for use in
> | repository directly. In another way it needs to be reconfigured
> | prior to installation.
> 
> Feel free to ignore.

See the changes below.

> 
> > +    # the installation path in <configure_file> command.
> > +    # Hope this script will be gone as a result of the issue below
> > +    # https://github.com/tarantool/tarantool/issues/5688.
> > +    "
> > +      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
> > +      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
> > +      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
> > +        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> > +      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
> > +    "
> > +    COMPONENT tools-parse-memprof
> > +  )
> 
> The result file is not executable.

Shit. BTW, the one generated above in bindir is neither. You can't
imagine how I reproach myself about approving this file addition. It's
like a vermiform appendix that we can't cut off right now. I've made the
template executable though this is nonsense but I failed to find another
normal solution. Anyway, I left the comment regarding it, squashed with
the previous commit. Here is the diff for both comments above:

================================================================================

diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 60535cd..cb49bdc 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -16,6 +16,13 @@ else()
   # path where LuaJIT binary is located.
   set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
   set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+  # XXX: Unfortunately, there is no convenient way to set
+  # particular permissions to the output file via CMake.
+  # Furthermore, I even failed to copy the given file to the same
+  # path to change its permissions. After looking at the docs, I
+  # realized that the valid solution would be too monstrous for
+  # such a simple task. As a result I've made the template itself
+  # executable, so the issue is resolved.
   configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
 
   add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS
@@ -58,18 +65,24 @@ else()
     COMPONENT tools-parse-memprof
   )
   install(CODE
-    # XXX: Since the auxiliary script need to be configured in
-    # other way it need to be reconfigured it prior to its
-    # installation. Unfortunately, we need to manually specify
-    # the installation path in <configure_file> command.
-    # Hope this script will be gone as a result of the issue below
+    # XXX: The auxiliary script needs to be configured for to be
+    # used in repository directly. It also need to be reconfigured
+    # prior to its installation. The temporary <configure_file>
+    # output is stored to the project build directory and removed
+    # later after being installed. This script will have gone as a
+    # result of the issue:
     # https://github.com/tarantool/tarantool/issues/5688.
     "
+      set(LJPM_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof)
       set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
       set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
       configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
-        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
-      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
+        ${PROJECT_BINARY_DIR}/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
+      file(INSTALL ${PROJECT_BINARY_DIR}/luajit-parse-memprof
+        DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+        USE_SOURCE_PERMISSIONS
+      )
+      file(REMOVE ${PROJECT_BINARY_DIR}/luajit-parse-memprof)
     "
     COMPONENT tools-parse-memprof
   )
diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
old mode 100644
new mode 100755

================================================================================

> 
> > +endif()
> > +
> > +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})
> 
> Side note: why don't you provide custom `tools` target for memprof like
> in the previous patch?

For what? In the previous patch there was an additional work to do, that
is a dependency for the main targets, so I grouped it into a separate
target.

> 
> > -- 
> > 2.25.0
> > 
> 
> [1]: https://stackoverflow.com/questions/41773161/negate-boolean-variable-in-cmake
> [2]: https://cmake.org/pipermail/cmake/2015-July/061116.html
> [3]: https://cmake.org/cmake/help/latest/command/continue.html
> [4]: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
> 
> -- 
> Best regards,
> Sergey Kaplun

[1]: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LIBRARY_ARCHITECTURE.html

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
  2021-02-14 19:16   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-16 15:29     ` Igor Munkin via Tarantool-patches
  2021-02-16 16:36       ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-16 15:29 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for the review!

On 14.02.21, Sergey Kaplun wrote:
> Hi, Igor!
> 
> Thanks for the patch!
> 
> Looks like I was late for the ball and you got two LGTMs, but here’s my

No, you were not!

> two cents on the matter, because I've been mentioned. Feel free to
> ignore my nitpicks.
> 
> LGTM, except two nitpicks below.

Added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

> 
> On 02.02.21, Igor Munkin wrote:
> > Since the regular static analysis has not been enabled for the test
> > chunks in LuaJIT repository yet, the tests for recently implemented
> > features still produce luacheck warnings.
> > 
> > The most of the issues are fixed in scope of the commit
> > 8fc103fb1a21c28185a1942e75d8d9485e3aade7 ('test: fix warnings spotted by
> > luacheck') and this patch fixes the remaining ones.
> > 
> > Fixes tarantool/tarantool#5631
> 
> Nit: Looks like 'Closes' or even 'Part of' (considering the next patch),
> not 'Fixes'.

Why? Sergey pointed out the warnings. The sources and the related
warnings are *fixed*. So 'Fixes' looks the most suitable here.

> Also, After this patch there are tons of misc-related warnings
> by the luacheсk without config. So, I think that this patch should be
> squashed with the next one.

Yes, these changes are not atomic. I can simply reorder the patches, if
you insist, but I definitely don't want to squash them into a single
one. The reason is that one is about "enabling" the regular check for
LuaJIT-related sources (#5470), but as a result of the applying
metrics-related series, the introduced chunks have broken luacheck
again. The new warnings are reported in a separate issue (#5631).

> Feel free to ignore.
> 
> > Part of tarantool/tarantool#4862
> > Part of tarantool/tarantool#5470
> > Follows up tarantool/tarantool#5187
> > 
> > Reported-by: Sergey Bronnikov <sergeyb@tarantool.org>
> > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > ---
> >  .../misclib-getmetrics-capi.test.lua          | 22 ++++++---------
> >  .../misclib-getmetrics-lapi.test.lua          | 28 +++++++++----------
> >  2 files changed, 23 insertions(+), 27 deletions(-)
> > 

<snipped>

> > diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > index 959293d..d54caac 100755
> > --- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua

<snipped>

> > @@ -384,7 +384,7 @@ test:test("strhash", function(subtest)
> >      assert(new_metrics.strhash_miss - old_metrics.strhash_miss == 0)
> >      old_metrics = new_metrics
> >  
> > -    local str2 = "new".."string"
> > +    local _ = "new".."string"
> 
> Nit: this `local` is redundant.
> Feel free to ignore.

There is little sense in storing both strings into a separate local
slots, but the code looks kinda "consistent".

Ignoring.

> 
> >  
> >      new_metrics = misc.getmetrics()
> >      assert(new_metrics.strhash_hit - old_metrics.strhash_hit == 19)
> > -- 
> > 2.25.0
> > 
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-13  3:47   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-16 15:32     ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-16 15:32 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

On 13.02.21, Sergey Kaplun wrote:
> Hi, again!
> 
> On 02.02.21, Igor Munkin wrote:
> > In scope of this patch the LuaJIT build system is partially ported from
> > GNU Make to CMake. These changes provides CMake build system only for
> > the following OS: GNU/Linux, OSX, FreeBSD. For other platrforms use the
> > old build system (see the recipe in the previous commit).
> 
> Sorry, forgot to ask in my previous letter: Does it mean that we should
> support two versions: Make and CMake?

Yes, otherwise I would simply drop everything in the first commit.

> After all, if something breaks old build Makefile becomes useless.
> 
> <snipped>
> 
> > -- 
> > 2.25.0
> > 
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib*
  2021-02-16 15:29     ` Igor Munkin via Tarantool-patches
@ 2021-02-16 16:36       ` Sergey Kaplun via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-16 16:36 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

On 16.02.21, Igor Munkin wrote:
> Sergey,
> 
> Thanks for the review!
> 
> On 14.02.21, Sergey Kaplun wrote:
> > Hi, Igor!
> > 
> > Thanks for the patch!
> > 
> > Looks like I was late for the ball and you got two LGTMs, but here’s my
> 
> No, you were not!
> 
> > two cents on the matter, because I've been mentioned. Feel free to
> > ignore my nitpicks.
> > 
> > LGTM, except two nitpicks below.
> 
> Added your tag:
> | Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

Thanks!

> 
> > 
> > On 02.02.21, Igor Munkin wrote:
> > > Since the regular static analysis has not been enabled for the test
> > > chunks in LuaJIT repository yet, the tests for recently implemented
> > > features still produce luacheck warnings.
> > > 
> > > The most of the issues are fixed in scope of the commit
> > > 8fc103fb1a21c28185a1942e75d8d9485e3aade7 ('test: fix warnings spotted by
> > > luacheck') and this patch fixes the remaining ones.
> > > 
> > > Fixes tarantool/tarantool#5631
> > 
> > Nit: Looks like 'Closes' or even 'Part of' (considering the next patch),
> > not 'Fixes'.
> 
> Why? Sergey pointed out the warnings. The sources and the related
> warnings are *fixed*. So 'Fixes' looks the most suitable here.
> 
> > Also, After this patch there are tons of misc-related warnings
> > by the luacheсk without config. So, I think that this patch should be
> > squashed with the next one.
> 
> Yes, these changes are not atomic. I can simply reorder the patches, if
> you insist, but I definitely don't want to squash them into a single
> one. The reason is that one is about "enabling" the regular check for
> LuaJIT-related sources (#5470), but as a result of the applying
> metrics-related series, the introduced chunks have broken luacheck
> again. The new warnings are reported in a separate issue (#5631).

OK, LGTM.

> 
> > Feel free to ignore.
> > 
> > > Part of tarantool/tarantool#4862
> > > Part of tarantool/tarantool#5470
> > > Follows up tarantool/tarantool#5187
> > > 
> > > Reported-by: Sergey Bronnikov <sergeyb@tarantool.org>
> > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > ---
> > >  .../misclib-getmetrics-capi.test.lua          | 22 ++++++---------
> > >  .../misclib-getmetrics-lapi.test.lua          | 28 +++++++++----------
> > >  2 files changed, 23 insertions(+), 27 deletions(-)
> > > 
> 
> <snipped>
> 
> > > diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > index 959293d..d54caac 100755
> > > --- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua

<snipped>

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

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-16 15:28     ` Igor Munkin via Tarantool-patches
@ 2021-02-18  9:56       ` Sergey Kaplun via Tarantool-patches
  2021-02-20 19:18         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-18  9:56 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

Thanks for the explanations!

On 16.02.21, Igor Munkin wrote:
> Sergey,
> 
> Thanks for your review!
> 
> On 11.02.21, Sergey Kaplun wrote:
> > Hi, Igor!
> > 
> > Thanks for the patch!
> > 
> > Appreciate your hard work! Thanks for the verbose comments!
> > The building process is faster now!
> > I'm sorry: I can't see your GUI innovations, unfortunately. :(
> > 
> > I've looked into branch version.
> > Please consider my comments below.
> 
> I've fixed all typos you've mentioned, so I left only those I haven't or
> have changed in a different way.
> 
> > 
> > On 02.02.21, Igor Munkin wrote:
> > > In scope of this patch the LuaJIT build system is partially ported from
> > 
> > Typo: s/In scope/In the scope/
> 
> I strongly doubt. Neither you, nor me: Within.

It's picture-perfect: win-win.

> 
> > 
> 
> <snipped>
> 
> > > old build system (see the recipe in the previous commit).
> > 
> > This paragraph describes only supported OS. There is no description of
> > supported build system options.
> > IINM there is no cross-compiling support, stripping debug info, amalgam
> > build for now, it should be mentioned in the commit message too.
> 
> Here is the new wording for this section:
> | Within this patch the LuaJIT build system is partially ported from GNU
> | Make to CMake. These changes provide CMake build system for all
> | supported host architectures but only for the following OS: GNU/Linux,

Typo: s/architectures but/architectures, but/

> | OSX, FreeBSD. For other platrforms and specific builds (such as 'amalg',

Typo: s/platrforms/platforms/

> | stripped binary and shared library, cross-compiling support) use the old
> | build system (see the recipe in the previous commit).
> 
> > 
> > > 
> > > Several components of the new build system such as automatic version
> > > detection, source files list generation and some recipes for
> > > CMakeLists.txt are taken verbatim or adapted from LuaVela repository.
> > > 
> > > Part of tarantool/tarantool#4862
> > > 
> > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > ---
> > 
> > Side note: This is not related to the patch directly but what about
> > Tarantool COPYRIGHT notice in the LuaJIT code and inside new cmake files
> > in particular?
> 
> We definitely need to make such activity, but I have no idea how to do
> it a right way. Let's postpone it and discuss later, if you don't mind.

Yes, of course. May be I create the ticket?

> 
> > 
> > >  .gitignore                 |  12 +-
> > >  CMakeLists.txt             | 261 +++++++++++++++++++++++++
> > >  cmake/LuaJITUtils.cmake    |  31 +++
> > >  cmake/MakeSourceList.cmake |  47 +++++
> > >  cmake/SetDynASMFlags.cmake | 130 ++++++++++++
> > >  cmake/SetTargetFlags.cmake |  42 ++++
> > >  cmake/SetVersion.cmake     |  45 +++++
> > >  etc/CMakeLists.txt         |  32 +++
> > >  src/CMakeLists.txt         | 391 +++++++++++++++++++++++++++++++++++++
> > >  src/host/CMakeLists.txt    |  61 ++++++
> > >  tools/CMakeLists.txt       |  77 ++++++++
> > >  11 files changed, 1128 insertions(+), 1 deletion(-)
> > >  create mode 100644 CMakeLists.txt
> > >  create mode 100644 cmake/LuaJITUtils.cmake
> > >  create mode 100644 cmake/MakeSourceList.cmake
> > >  create mode 100644 cmake/SetDynASMFlags.cmake
> > >  create mode 100644 cmake/SetTargetFlags.cmake
> > >  create mode 100644 cmake/SetVersion.cmake
> > >  create mode 100644 etc/CMakeLists.txt
> > >  create mode 100644 src/CMakeLists.txt
> > >  create mode 100644 src/host/CMakeLists.txt
> > >  create mode 100644 tools/CMakeLists.txt

<snipped>

> > > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > > new file mode 100644
> > > index 0000000..0dba5d8
> > > --- /dev/null
> > > +++ b/CMakeLists.txt
> > > @@ -0,0 +1,261 @@

<snipped>

> > > +# XXX: Originally CMake machinery is introduced to make LuaJIT
> > > +# testing self-sufficient. Since there are only few systems
> > 
> > Typo: s/only few systems/only a few systems/
> 
> No, I want to emphasize the amount, so the article changes the meaning.

Copy that, thank you!

> 
> > 
> 

<snipped>

> > > +# --- Compilation flags setup --------------------------------------------------
> > > +
> > > +if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
> > > +  AppendFlags(TARGET_C_FLAGS -DLUA_ROOT='"${CMAKE_INSTALL_PREFIX}"')
> > 
> > In Makefile.original I see the following check inside this branch:
> > 
> > | ifneq (/usr,$(PREFIX))
> > |   TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
> > | endif
> > 
> > Is it related to unsupported build systems?
> 
> AFAICS, it is. Anyway, if you're having troubles, feel free to share.

I've not found anyone. We will create an issue if necessary.

> 
> > 
> > I've found some warnings on macOS in the configuration stage, that looks
> > related:
> > 
> > | CMake Warning (dev):
> > |   Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
> > |   --help-policy CMP0042" for policy details.  Use the cmake_policy command to
> > |   set the policy and suppress this warning.
> > |
> > |   MACOSX_RPATH is not specified for the following targets:
> > |
> > |    libluajit_shared
> > |
> > | This warning is for project developers.  Use -Wno-dev to suppress it.
> > 
> > Version of macOS:
> > | $ uname -a
> > | Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
> > 
> 
> I've seen this warning, and have tried almost all combinations of the
> MACOS_RPATH, CMP0042, and target options -- nothing has helped. BTW,
> this warning breaks nothing for me (on my old Mac). If this bothers you,
> please report your issues. If you have a solution, please share it.

Hmm, it vanishes at the last branch version, congratulations :).

> 
> > > +endif()
> > > +
> > > +if(CMAKE_LIBRARY_ARCHITECTURE)
> > > +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> > > +endif()
> > 
> > What about `LUA_LMULTILIB`?
> > 
> > Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
> > like it does in Makefile.original?
> 
> DESTDIR is supported out of the box in CMake. MULTILIB is "autodetected"
> via CMake[1] (I hope, but never tried). Regardging LMULTILIB, I have no
> idea what its purpose is. Do you?

To configure default CPATH, IINM, see luaconf.h for details.

> 

| option(LUAJIT_USE_VALGRIND "Valgrind support" OFF)
| if(LUAJIT_USE_VALGRIND)
|   AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_VALGRIND)
| endif()

Nit: I see the compilation error (predictable) when this option is ON,
but valgrind is not installed. May be add some checks at configuration
phase?

Feel free to ignore.

<snipped>

> > > +# TODO: Implement a configuration option to enable ASAN.
> > > +# There are two entries of LUAJIT_USE_ASAN define:
> > > +# $ grep -rnF 'LUAJIT_USE_ASAN' .
> > > +# ./src/lj_str.c:15:#if LUAJIT_USE_ASAN
> > > +# ./src/host/buildvm.c:36:#if LUAJIT_USE_ASAN
> > > +# At the same time this flag is not provided by LuaJIT original
> > > +# build system (i.e. src/Makefile.original) so there are no
> > > +# related compiler and linker flags passed. This should be done
> > > +# the right way later.
> > 
> > Good catch! I decide to check what else is missing. Here are some other
> > options (sorry, for that dump, just want to save it anywhere):
> > | $ grep -rnF 'LUAJIT_CTYPE_CHECK_ANCHOR'
> > | src/lj_ctype.c:139:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
> > | src/lj_ctype.c:159:#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
> > 
> > | $ grep -rnF 'LUAJIT_DEBUG_RA'
> > | src/lj_asm.c:192:/* #define LUAJIT_DEBUG_RA */
> > | src/lj_asm.c:194:#ifdef LUAJIT_DEBUG_RA
> 
> I tried only this one, while debugging the RENAME issue.
> It would be nice to export it.
> 
> > 
> > | $ grep -rnF 'LUAJIT_DISABLE_DEBUGINFO'
> > | src/lj_parse.c:1397:#ifndef LUAJIT_DISABLE_DEBUGINFO
> > | src/lj_parse.c:2700:#ifdef LUAJIT_DISABLE_DEBUGINFO
> > | Binary file src/.lj_parse.c.swp matches
> > | src/lj_memprof.c:102:  ** -DLUAJIT_DISABLE_DEBUGINFO flag.
> > 
> > | $ grep -rnF 'LUAJIT_DISABLE_PROFILE'
> > | src/lj_arch.h:501:#if defined(LUAJIT_DISABLE_PROFILE)
> > 
> > | $ grep -rnF 'LUAJIT_DISABLE_VMEVENT'
> > | src/lj_trace.c:796:#ifndef LUAJIT_DISABLE_VMEVENT
> > | src/lj_vmevent.h:33:#ifdef LUAJIT_DISABLE_VMEVENT
> > | src/lib_jit.c:118:#ifdef LUAJIT_DISABLE_VMEVENT
> > 
> > | $ grep -rnF 'LUAJIT_ENABLE_CHECKHOOK'
> > | src/lj_record.c:2621:#ifdef LUAJIT_ENABLE_CHECKHOOK
> > 
> > | $ grep -rnF 'LUAJIT_ENABLE_TABLE_BUMP'
> > | src/lj_record.c:259:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:1179:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:1477:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:1523:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:1874:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:2321:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_record.c:2544:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > | src/lj_jit.h:455:#ifdef LUAJIT_ENABLE_TABLE_BUMP
> > 
> > | $ grep -rnF 'LUAJIT_NO_UNALIGNED'
> > | src/lj_def.h:287:#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
> > 
> > | $ grep -rnF 'LUAJIT_USE_PERFTOOLS'
> > | src/lj_trace.c:85:#ifdef LUAJIT_USE_PERFTOOLS
> > | src/lj_trace.c:163:#ifdef LUAJIT_USE_PERFTOOLS
> > 
> > | $ grep -rnF 'LUAJIT_UNWIND_EXTERNAL'
> > | doc/extensions.html:402:<td class="excplatform">ARM <tt>-DLUAJIT_UNWIND_EXTERNAL</tt></td>
> > | src/lj_err.c:53:** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled
> > | src/lj_err.c:64:#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND
> > | src/lj_err.c:521:  ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every*
> > 
> > They not all related to debugging (AFAICT only `LUAJIT_USE_PERFTOOLS`,
> > `LUAJIT_CTYPE_CHECK_ANCHOR` and `LUAJIT_DEBUG_RA`), more to configure.
> > May be it is better to create separate issue(s) for all these options?
> 
> Feel free to do it :)

OK, after this patch set will be merged to master.

> 
> > 
> 
> <snipped>
> 
> > 
> > > diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> > > new file mode 100644
> > > index 0000000..faaef6b
> > > --- /dev/null
> > > +++ b/cmake/LuaJITUtils.cmake
> > > @@ -0,0 +1,31 @@

<snipped>

> > Nit: Also, it would be nice to see comments here, why do we use this
> > approach instead use of CMAKE_HOST_SYSTEM_PROCESSOR variable (is set by
> > `uname -p`).
> > Feel free to ignore.
> 
> I have no clear explanation of these and I definitely don't want to
> write a bullshit in the comments, so I will either add TODO here if you
> insist, or ignore this one.

Add TODO, please. Just to mention this.

> 
> > > +  execute_process(
> > > +    COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM
> > 
> > May be it will better to provide not default compiler here?
> > It will be easier to adjust cross compiling with this.
> 
> I don't get this, but as we discussed before cross compiling activity is
> out of the scope of this issue.

OK, good.

> 
> > 
> > > +    WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
> > > +    OUTPUT_VARIABLE TESTARCH
> > > +  )
> > > +  set(${outvar} ${TESTARCH} PARENT_SCOPE)
> > > +endfunction()
> > > +
> > > +function(LuaJITArch outvar testarch)
> > > +  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)
> > 
> > I occur the following error, when build inside Docker emulating
> > aarch64 (`FROM arm64v8/centos`):
> > 
> > | Error: pointer size mismatch in cross-build.
> > | Try: make HOST_CC="gcc -m32" CROSS=...
> > |
> > | make[2]: *** [src/CMakeFiles/vm_static.dir/build.make:62: src/lj_vm.S] Error 1
> > | make[1]: *** [CMakeFiles/Makefile2:193: src/CMakeFiles/vm_static.dir/all] Error 2
> > | make[1]: *** Waiting for unfinished jobs....
> > | Error: pointer size mismatch in cross-build.
> > | Try: make HOST_CC="gcc -m32" CROSS=...
> > |
> > | make[2]: *** [src/CMakeFiles/vm_shared.dir/build.make:62: src/lj_vm.S] Error 1
> > | make[1]: *** [CMakeFiles/Makefile2:394: src/CMakeFiles/vm_shared.dir/all] Error 2
> > 
> > All OK with the old Makefile:
> > 
> > | $ make -f Makefile.original -j
> > | ==== Building LuaJIT 2.1.0-beta3 ====
> > | ...
> > | ==== Successfully built LuaJIT 2.1.0-beta3 ====
> > 
> > Content of <src/host/CMakeFiles/buildvm.dir/build.make>:
> > | src/host/buildvm_arch.h: dynasm/*.lua
> > |         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/luajit/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating buildvm_arch.h"
> > |         cd /luajit/src/host && /luajit/src/host/minilua /luajit/dynasm/dynasm.lua -D ENDIAN_LE -D P64 -D JIT -D FFI -D DUALNUM -D FPU -D HFABI -D VER=80 -o buildvm_arch.h /luajit/src/vm_arm.dasc
> > 
> > vm_arm.dasc instead vm_arm64.dasc here.
> 
> Oops.
> 
> > 
> > All because LJ_TARGET_ARM matched before LJ_TARGET_ARM64 in the line
> > below. And it works for MIPS, because of different order :)
> > Swap arches and leave comments about an order, please.
> 
> Neat, many thanks for testing and investigation! Fixed, squashed,
> force-pushed to the branch. Diff is below:
> 
> ================================================================================
> 
> diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> index 1769675..0a662f7 100644
> --- a/cmake/LuaJITUtils.cmake
> +++ b/cmake/LuaJITUtils.cmake
> @@ -12,7 +12,7 @@ function(LuaJITTestArch outvar strflags)
>  endfunction()
>  
>  function(LuaJITArch outvar testarch)
> -  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)

Please add a comment. Just to notice.

> +  foreach(TRYARCH X64 X86 ARM64 ARM PPC MIPS64 MIPS)
>      string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
>      if(FOUND EQUAL -1)
>        continue()
> 
> ================================================================================

<snipped>

> > > +    string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
> > > +    if(FOUND EQUAL -1)
> > > +      continue()
> > 
> > `continue()` command was introduced in 3.2 CMake version
> > according to [1]. So even 3.1 version is not enough.
> 
> Shit, that can't be true... But thanks for checking it!
> 
> > 
> > This is a result for verision 3.0.2.
> > | CMake Error at cmake/LuaJITUtils.cmake:18 (continue):
> > |   Unknown CMake command "continue".
> > | Call Stack (most recent call first):
> > |   cmake/SetTargetFlags.cmake:16 (LuaJITArch)
> > |   src/CMakeLists.txt:164 (include)
> > |
> > |
> > | -- Configuring incomplete, errors occurred!
> > 
> > Please, add `cmake_minimum_required()` command to the top, or do not use
> 
> Hell no, I'll just rewrite this part and leave *non-toxic* comment about
> it. When CMake will be updated in Tarantool next time, we'll refactor
> this part. But not today.

Yep, thank you!

> 
> > `continue()` command.
> 
> Reimplemented, squashed, force-pushed to the branch. Diff is below:
> 
> ================================================================================
> 
> diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> index 0a662f7..2c4a27e 100644
> --- a/cmake/LuaJITUtils.cmake
> +++ b/cmake/LuaJITUtils.cmake
> @@ -14,12 +14,18 @@ endfunction()
>  function(LuaJITArch outvar testarch)
>    foreach(TRYARCH X64 X86 ARM64 ARM PPC MIPS64 MIPS)
>      string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
> -    if(FOUND EQUAL -1)
> -      continue()
> +    # FIXME: <continue> is introduced in CMake version 3.2, but
> +    # the minimum required version now is 3.1. This is not such a
> +    # vital feature, so it's not used now. However, when CMake
> +    # version is bumped next time, it's better to rewrite this
> +    # part using <continue> for "early return".
> +    # For more info see CMake Release notes for 3.2 version.

Typo: s/For more info see/For more info, see/

> +    # https://cmake.org/cmake/help/latest/release/3.2.html#commands
> +    if(NOT FOUND EQUAL -1)
> +      string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
> +      set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
> +      return()
>      endif()
> -    string(TOLOWER ${TRYARCH} LUAJIT_ARCH)
> -    set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE)
> -    return()
>    endforeach()
>    message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture")
>  endfunction()
> 
> ================================================================================

<snipped>

> > > diff --git a/cmake/SetDynASMFlags.cmake b/cmake/SetDynASMFlags.cmake
> > > new file mode 100644
> > > index 0000000..9a920c3
> > > --- /dev/null
> > > +++ b/cmake/SetDynASMFlags.cmake
> > > @@ -0,0 +1,130 @@
> > > +# This module exposes following variables to the project:
> > 
> > Side note: Nice approach, I like it!
> > 
> > > +# * HOST_C_FLAGS
> > > +# * DYNASM_ARCH
> > > +# * DYNASM_FLAGS
> > > +
> > > +# XXX: buildvm includes core headers and thus has to be built
> > > +# with the same flags and defines as the LuaJIT core itself.
> > > +set(HOST_C_FLAGS)
> > > +set(DYNASM_ARCH)
> > > +set(DYNASM_FLAGS)
> > > +
> > > +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS} ${HOST_CFLAGS}")
> > 
> > Nit: Looks like it is necessary to use <Makefile.original> to define
> > LUAJIT_TARGET directly? I think that should be mentioned in the commit
> > message too.
> 
> Sorry, don't get this one.

The question was about way to declare -DLUAJIT_TARGET=LUAJIT_ARCH_X86.
But it can be done with CMAKE_C_FLAGS, IINM. Never mind.

> 
> > Feel free to ignore.
> > 
> 
> <snipped>
> 
> > 
> > > diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> > > new file mode 100644
> > > index 0000000..260fc6b
> > > --- /dev/null
> > > +++ b/cmake/SetTargetFlags.cmake
> 

I add some comments to the following chunk.

| +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
| +  if(LUAJIT_ARCH STREQUAL "x64")

Side note: I have a linking error with the original Makefile
without `MACOSX_DEPLOYMENT_TARGET` specification:
|| LINK      luajit
|| Undefined symbols for architecture x86_64:
||   "__Unwind_DeleteException", referenced from:
||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
||   "__Unwind_GetCFA", referenced from:
||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
||   "__Unwind_RaiseException", referenced from:
||       _lj_err_throw in libluajit.a(lj_err.o)
||   "__Unwind_SetGR", referenced from:
||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
||   "__Unwind_SetIP", referenced from:
||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
|| ld: symbol(s) not found for architecture x86_64

But nothing with CMake...
Nonetheless, I suggest to safe the old Makefile behaviour to specify
the minimum OS version (see [1]):
===================================================================
diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
index c8bcded..d54e295 100644
--- a/cmake/SetTargetFlags.cmake
+++ b/cmake/SetTargetFlags.cmake
@@ -25,6 +25,9 @@ if(LUAJIT_ARCH STREQUAL "x86")
 endif()
 
 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  if (NOT $ENV{MACOSX_DEPLOYMENT_TARGET})
+    set(ENV{MACOSX_DEPLOYMENT_TARGET} 10.4)
+  endif()
   if(LUAJIT_ARCH STREQUAL "x64")
     AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)
     AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
===================================================================

Feel free to ignore.

| +    AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)

Here are description from Mike for this flags, please add this comment.

|| commit f76e5a311ba543ae174acd3b585fb672fde8a3b5
|| Author: Mike Pall <mike>
|| Date:   Thu Mar 4 16:27:42 2010 +0100
||
||     Allocate 32 bit memory on OSX/x64 with mmap() hinting.
||
||     Must set -pagezero_size, otherwise the lower 4GB are blocked.

| +    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)

Also I've found that this line produces warnings from linker like:

|| ld: warning: -seg1addr not 16384 byte aligned, rounding up

So, I suggest the following solution for cmake and for the original
Makefile (just add 8Kb):
===================================================================
diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
index c8bcded..d0eefab 100644
--- a/cmake/SetTargetFlags.cmake
+++ b/cmake/SetTargetFlags.cmake
@@ -27,7 +27,7 @@ endif()
 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   if(LUAJIT_ARCH STREQUAL "x64")
     AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)
-    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
+    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4c000)
   endif()
   AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)
 else() # Linux and FreeBSD.
diff --git a/src/Makefile.original b/src/Makefile.original
index 502504c..34988db 100644
--- a/src/Makefile.original
+++ b/src/Makefile.original
@@ -328,7 +328,7 @@ ifeq (Darwin,$(TARGET_SYS))
   TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
   ifeq (x64,$(TARGET_LJARCH))
     TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
-    TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
+    TARGET_XSHLDFLAGS+= -image_base 7fff04c4c000
   endif
 else
 ifeq (iOS,$(TARGET_SYS))
===================================================================
| +  endif()
| +  AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)

> 
> > 
> > Are -dynamiclib and -fPIC flags forced set by CMake?
> > Also, I don't find -install_name -compatibility_version -current_version
> > flags. Are they insignificant?
> 
> Could you please share the corresponding part of "make VERBOSE=1"? These
> variables should be set by CMake.

Thanks for the tip-off. Nothing is missing, but -compatibility_version
is "2.0.0" instead of "2.1". Is that OK?

> 
> > 
> > I got warnings from linker in the build stage on macOS:
> > 
> > | $ uname -a
> > | Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
> > 
> > | ld: warning: -seg1addr not 16384 byte aligned, rounding up
> > | /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols
> > | [ 98%] Built target libluajit_shared
> > | /Library/Developer/CommandLineTools/usr/bin/ranlib: file: libluajit.a(lj_opt_split.c.o) has no symbols
> > 
> > Is it related to this?
> 
> No, you'll see this if you run <ar> with no suppressing its output. The
> same issue is also presented for lj_gdbjit.c when GDBJIT support is
> disabled.

Thanks, please see the patch to suppress superfluous randlib warnings about
"*.a" having no symbols on MacOSX. Mike just ignoring them by
`2>/dev/null` :)
===================================================================
diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
index c8bcded..1fcdeea 100644
--- a/cmake/SetTargetFlags.cmake
+++ b/cmake/SetTargetFlags.cmake
@@ -30,6 +30,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
     AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
   endif()
   AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)
+  set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> rcusS <TARGET> <LINK_FLAGS> <OBJECTS>")
+  set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
 else() # Linux and FreeBSD.
   AppendFlags(TARGET_BIN_FLAGS -Wl,-E)
   list(APPEND TARGET_LIBS dl)
===================================================================

But may be this is not the best plase for this (it is not about flags).

Feel free to change and reword all these comments (here and above) on
your own.

> 
> > 

<snipped>

> > > diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> > > new file mode 100644
> > > index 0000000..8ada1a4
> > > --- /dev/null
> > > +++ b/src/CMakeLists.txt
> > > @@ -0,0 +1,391 @@
> > 
> > <snipped>
> > 
> > > +make_source_list(SOURCES_UTILS
> > > +  SOURCES
> > > +    lj_alloc.c
> > > +    lj_char.c
> > > +    lj_utils_leb128.c
> > > +    lj_vmmath.c
> > > +    lj_wbuf.c
> > 
> > Looks like there is no need to compile <lj_utils_leb128.c> and
> > <lj_wbuf.c>, when the memory profiler is disabled.
> 
> There is no need, but strictly saying both units are not strictly
> related to memprof, but rather providing a standalone functionality. So,
> I leave it unchanged.

Good.

> 
> > 
> 
> <snipped>
> 
> > 
> > | # handle this manually on his side. Hence check whether the
> > | # targets used below are presented for the chosen build mode.
> > | # See more info in CMake docs below:
> > | # https://cmake.org/cmake/help/v3.1/prop_tgt/EXCLUDE_FROM_ALL.html
> > 
> > This warnings are annoying (cmake version is 3.13.4):
> 
> Did you try the latest version of the patchset? All these <install>
> rules are moved under condition after Timur comment.

Yes, just check it again inside Docker with arm64.
How can I provide more debug info?

| # cmake .
| ...
| WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
| ...

> 
> > 
> > | -- Found assembler: /usr/bin/cc
> > | -- Configuring done
> > | WARNING: Target "luajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> > | WARNING: Target "libluajit_static" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> > | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> > | WARNING: Target "libluajit_shared" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
> > 
> > Can we suppress them?
> > 
> > > +install(TARGETS ${LUAJIT_DEPS}
> > 
> > The development releases of LuaJIT deliberately are not installed like
> > "luajit", but "luajit-2.1.0-beta3". Do we want to change this behaviour?
> 
> What do you mean by that? Could you please provide an example?

Sure.

Instalation via CMake:

| $ cmake -DCMAKE_INSTALL_PREFIX="/tmp/testinstall" . && make -j && make install
| -- Installing: /tmp/testinstall/bin/luajit
| -- Installing: /tmp/testinstall/lib/libluajit.a
| -- Installing: /tmp/testinstall/lib/libluajit.so.2.1.0
| -- Up-to-date: /tmp/testinstall/lib/libluajit.so.2
| -- Up-to-date: /tmp/testinstall/lib/libluajit.so

Via the original Makefile:

| make -f Makefile.original install
| cd src && install -m 0755 luajit /tmp/testinstall//bin/luajit-2.1.0-beta3
                                        This is the difference ^^^^^^^^^^^^
| cd src && test -f libluajit.a && install -m 0644 libluajit.a /tmp/testinstall//lib/libluajit-5.1.a || :
| rm -f /tmp/testinstall//lib/libluajit-5.1.so.2.1.0 /tmp/testinstall//lib/libluajit-5.1.so /tmp/testinstall//lib/libluajit-5.1.so.2
| cd src && test -f libluajit.so && \
|   install -m 0755 libluajit.so /tmp/testinstall//lib/libluajit-5.1.so.2.1.0 && \
|   ldconfig -n /tmp/testinstall//lib && \
|   ln -sf libluajit-5.1.so.2.1.0 /tmp/testinstall//lib/libluajit-5.1.so && \
|   ln -sf libluajit-5.1.so.2.1.0 /tmp/testinstall//lib/libluajit-5.1.so.2 || :

Also there is the following note:

| Note: the development releases deliberately do NOT install a symlink for luajit
| You can do this now by running these commands (with sudo):
|
|   ln -sf luajit-2.1.0-beta3 /tmp/testinstall//bin/luajit
|   ln -sf luajit-2.1.0-beta3-parse-memprof /tmp/testinstall//bin/luajit-parse-memprof

Same for our memprof appendix.

> 
> > 
> > > +  RUNTIME
> > > +  DESTINATION bin
> > > +  COMPONENT luajit
> > > +)
> > > +install(TARGETS ${LIBLUAJIT_STATIC_DEPS}
> > > +  ARCHIVE
> > > +  DESTINATION lib
> > > +  COMPONENT luajit
> > > +)
> > > +install(TARGETS ${LIBLUAJIT_SHARED_DEPS}
> > > +  LIBRARY
> > > +  DESTINATION lib
> > > +  COMPONENT luajit
> > > +)
> > > +

<snipped>

> > 
> > > +  DESTINATION ${LUAJIT_DATAROOTDIR}/jit
> > > +  PERMISSIONS
> > > +    OWNER_READ OWNER_WRITE
> > > +    GROUP_READ
> > > +    WORLD_READ
> > > +  COMPONENT luajit
> > > +)
> > 
> > As I read from [4] CMake does not provide a default way to uninstall
> > installed files. But fortunately there is an example how doing it
> > in [4] directly. I think it is good to implement this part for
> > backward compatibility (especially, we have all prerequisites).
> 
> OK, but I adjusted it a bit:
> 
> ================================================================================
> 
> diff --git a/.gitignore b/.gitignore
> index a21ee1c..2103a30 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -15,6 +15,7 @@ CMakeCache.txt
>  CMakeFiles
>  Makefile
>  cmake_install.cmake
> +cmake_uninstall.cmake
>  compile_commands.json
>  install_manifest.txt
>  luajit-parse-memprof
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 16a9d5b..6bba9f4 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -261,3 +261,16 @@ add_subdirectory(etc)
>  # --- Tools --------------------------------------------------------------------
>  
>  add_subdirectory(tools)
> +
> +# --- Misc rules ---------------------------------------------------------------
> +
> +# XXX: Implement <uninstall> target using the following recipe:
> +# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
> +if(NOT TARGET uninstall)
> +  configure_file(${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in
> +    cmake_uninstall.cmake @ONLY ESCAPE_QUOTES)
> +
> +  add_custom_target(uninstall
> +    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
> +  )
> +endif()
> diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in
> new file mode 100644
> index 0000000..fc3b885
> --- /dev/null
> +++ b/cmake/cmake_uninstall.cmake.in
> @@ -0,0 +1,24 @@
> +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
> +  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
> +endif()
> +
> +# XXX: This loop removes only entries from install_manifest.txt,
> +# but do nothing for the directories created while installation.

Side note: original `make uninstall` looks similar -- leaves several
amount of ghost-directories.

> +# Honestly, the recipe is awful, but is better than nothing.

We can refactor it later if you want.

<snipped>

> > > diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> > > new file mode 100644
> > > index 0000000..f9ffc5e
> > > --- /dev/null
> > > +++ b/tools/CMakeLists.txt
> > > @@ -0,0 +1,77 @@
> > > +# Building tools for developing with uJIT.

Nit: uJIT or LuaJIT?

> > > +# Major portions taken verbatim or adapted from the uJIT.
> > > +# Copyright (C) 2015-2019 IPONWEB Ltd.
> > > +
> > > +# See the rationale in the root CMakeLists.txt
> > > +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> > > +
> > > +set(LUAJIT_TOOLS_DEPS)
> > > +
> > > +if(LUAJIT_DISABLE_MEMPROF)
> > > +  message(STATUS "LuaJIT memory profiler support is disabled")
> > > +else()
> > > +  # XXX: Can use genex here since the value need to be evaluated
> > > +  # on the configuration phase. Fortunately, we know the exact
> > 
> > Typo: s/on/in/
> 
> Niether of these. 'at' or 'while' are fine (I chose the former).

Perfect!

> 
> > 
> > > +  # path where LuaJIT binary is located.
> > > +  set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
> > > +  set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> > > +  configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> > > +
> > 
> > <snipped>
> > 
> > > +  install(FILES
> > > +      ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua
> > > +    DESTINATION ${LUAJIT_DATAROOTDIR}
> > > +    PERMISSIONS
> > > +      OWNER_READ OWNER_WRITE
> > > +      GROUP_READ
> > > +      WORLD_READ
> > > +    COMPONENT tools-parse-memprof
> > > +  )
> > > +  install(CODE
> > 
> > Is it reasonable to install memrpof tooling for not supported arches?
> > Yes, it's already working in that way, but maybe it is redundant.
> 
> I see no problem: this part works fine on all hosts, so you can take the
> binary dump and parse it anywhere.

Only if symtab and memprof version is the same, but it's OK.

> 
> > 
> > > +    # XXX: Since the auxiliary script need to be configured in
> > > +    # other way it need to be reconfigured it prior to its
> > > +    # installation. Unfortunately, we need to manually specify
> > 
> > Nit: I propose to reformulate and split the first sentence like the
> > following:
> > 
> > | XXX: The auxiliary script needs to be configured for use in
> > | repository directly. In another way it needs to be reconfigured
> > | prior to installation.
> > 
> > Feel free to ignore.
> 
> See the changes below.
> 
> > 
> > > +    # the installation path in <configure_file> command.
> > > +    # Hope this script will be gone as a result of the issue below
> > > +    # https://github.com/tarantool/tarantool/issues/5688.
> > > +    "
> > > +      set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
> > > +      set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
> > > +      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
> > > +        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> > > +      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
> > > +    "
> > > +    COMPONENT tools-parse-memprof
> > > +  )
> > 
> > The result file is not executable.
> 
> Shit. BTW, the one generated above in bindir is neither. You can't
> imagine how I reproach myself about approving this file addition. It's
> like a vermiform appendix that we can't cut off right now. I've made the
> template executable though this is nonsense but I failed to find another
> normal solution. Anyway, I left the comment regarding it, squashed with
> the previous commit. Here is the diff for both comments above:

There is no use to cry over spilt milk. Without this we probably would
hear nothing from our dear customers about this feature.
I reckon on doing this soon after integration of testing suite and
memory profiler bugfixes.

> 
> ================================================================================
> 
> diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> index 60535cd..cb49bdc 100644
> --- a/tools/CMakeLists.txt
> +++ b/tools/CMakeLists.txt
> @@ -16,6 +16,13 @@ else()
>    # path where LuaJIT binary is located.
>    set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME})
>    set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> +  # XXX: Unfortunately, there is no convenient way to set
> +  # particular permissions to the output file via CMake.
> +  # Furthermore, I even failed to copy the given file to the same
> +  # path to change its permissions. After looking at the docs, I
> +  # realized that the valid solution would be too monstrous for
> +  # such a simple task. As a result I've made the template itself
> +  # executable, so the issue is resolved.

*Kхъ* :).

>    configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES)
>  
>    add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS
> @@ -58,18 +65,24 @@ else()
>      COMPONENT tools-parse-memprof
>    )
>    install(CODE
> -    # XXX: Since the auxiliary script need to be configured in
> -    # other way it need to be reconfigured it prior to its
> -    # installation. Unfortunately, we need to manually specify
> -    # the installation path in <configure_file> command.
> -    # Hope this script will be gone as a result of the issue below
> +    # XXX: The auxiliary script needs to be configured for to be
> +    # used in repository directly. It also need to be reconfigured

Typo? s/repository/the repository/
Typo: s/need/needs/

> +    # prior to its installation. The temporary <configure_file>
> +    # output is stored to the project build directory and removed

Typo? s/to/in/

> +    # later after being installed. This script will have gone as a
> +    # result of the issue:
>      # https://github.com/tarantool/tarantool/issues/5688.
>      "
> +      set(LJPM_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof)

See no usage of this variable.

>        set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME})
>        set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR})
>        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in
> -        ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> -      message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\")
> +        ${PROJECT_BINARY_DIR}/luajit-parse-memprof @ONLY ESCAPE_QUOTES)
> +      file(INSTALL ${PROJECT_BINARY_DIR}/luajit-parse-memprof
> +        DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
> +        USE_SOURCE_PERMISSIONS
> +      )
> +      file(REMOVE ${PROJECT_BINARY_DIR}/luajit-parse-memprof)
>      "
>      COMPONENT tools-parse-memprof
>    )
> diff --git a/tools/luajit-parse-memprof.in b/tools/luajit-parse-memprof.in
> old mode 100644
> new mode 100755
> 
> ================================================================================
> 
> > 
> > > +endif()
> > > +
> > > +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS})
> > 
> > Side note: why don't you provide custom `tools` target for memprof like
> > in the previous patch?
> 
> For what? In the previous patch there was an additional work to do, that
> is a dependency for the main targets, so I grouped it into a separate
> target.

OK, hope this problems will vanish with a -[tm] flag.

This is a comment for the previous patch. Just place it here to avoid of
spam messages.

When I try `make -f Makefile.original -j`, I see the following warning:

| make: Circular src/luajit <- tools dependency dropped.

Also, I found that amalg build is broken. I propose the following patch:

===================================================================
diff --git a/Makefile.original b/Makefile.original
index 33dc2ed..8d8f4ff 100644
--- a/Makefile.original
+++ b/Makefile.original
@@ -123,9 +123,10 @@ endif
 
 INSTALL_DEP= src/luajit
 
-default all $(INSTALL_DEP): tools
+default all $(INSTALL_DEP):
 	@echo "==== Building LuaJIT $(VERSION) ===="
 	$(MAKE) -C src -f Makefile.original
+	$(MAKE) -f Makefile.original tools
 	@echo "==== Successfully built LuaJIT $(VERSION) ===="
 
 install: $(INSTALL_DEP)
@@ -185,9 +186,10 @@ uninstall:
 
 ##############################################################################
 
-amalg: tools
+amalg:
 	@echo "Building LuaJIT $(VERSION)"
 	$(MAKE) -C src -f Makefile.original amalg
+	$(MAKE) -f Makefile.original tools
 
 clean:
 	$(RM) tools/$(FILE_TMEMPROF)
diff --git a/src/Makefile.original b/src/Makefile.original
index 502504c..031f077 100644
--- a/src/Makefile.original
+++ b/src/Makefile.original
@@ -606,14 +606,14 @@ default all:	$(TARGET_T)
 
 amalg:
 	@grep "^[+|]" ljamalg.c
-	$(MAKE) all "LJCORE_O=ljamalg.o"
+	$(MAKE) -f Makefile.original all "LJCORE_O=ljamalg.o"
 
 clean:
 	$(HOST_RM) $(ALL_RM)
 
 libbc:
 	./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
-	$(MAKE) all
+	$(MAKE) -f Makefile.original all
 
 depend:
 	@for file in $(ALL_HDRGEN); do \
===================================================================

> 
> > 
> > > -- 
> > > 2.25.0
> > > 
> > 
> > [1]: https://stackoverflow.com/questions/41773161/negate-boolean-variable-in-cmake
> > [2]: https://cmake.org/pipermail/cmake/2015-July/061116.html
> > [3]: https://cmake.org/cmake/help/latest/command/continue.html
> > [4]: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> [1]: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LIBRARY_ARCHITECTURE.html
> 
> -- 
> Best regards,
> IM

[1]: https://cmake.org/cmake/help/v3.14/envvar/MACOSX_DEPLOYMENT_TARGET.html

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-14 18:48   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-19 19:04     ` Igor Munkin via Tarantool-patches
  2021-02-27 13:50       ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-19 19:04 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for the patch!

On 14.02.21, Sergey Kaplun wrote:
> Hi, Igor!
> 

<snipped>

> > CMake can't expand the generator expression used in DEPENDS section of
> 
> Typo? s/in DEPENDS section/in the DEPENDS section/

This is the common section name, not the particular section.

> 

<snipped>

> > Tarantool tests are implemented using Tarantool on-board TAP module[2],
> > that is moved to LuaJIT repository with a little changes to save Lua
> 
> Typo: s/a little changes/little changes/

No, I don't want to emphasize the amount, but rather the fact the chunks
are almost untouched.

> 

<snipped>

> 
> Side note: What kind of quotes is preferable for our code style in
> LuaJIT?

This is an open question for the LuaJIT style guide. I personally prefer
single until I have to use double ones.

> The new <tap.lua> module is written with single quotes, but a lot of
> code inside LuaJIT uses double quotes (see <src/jit/*.lua>, for
> example). Also, as far as you've already changed indentation it will be
> nice do not stop there and fix quotes and change `{ }` to `{}` as usual.

Fixed all new occurrences.

> 
> Side note: (this is more like discussion question) -- do we really need
> to use Tarantool's <tap.lua> module here? I provide some
> dissatisfactions, but as I say below, we can't just change this
> module API because we want (if you remove this module from Tarantool
> and save it only here).
> If it is saved untouchable in Tarantool repo I see no reason to
> avoid replacing it with another one more suitable (if we want) or
> improving it. Amount of tests is really small now and it can be easily
> adapted. May be we should take a look at Lua test-modules like [1] and
> [2].

I'm totally for lua-TestMore. We can try to port everything to its tap,
when it has been incorporated to the trunk.

> 

<snipped>

> > diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
> > index 4a4c3cd..d54fa79 100644
> > --- a/etc/CMakeLists.txt
> > +++ b/etc/CMakeLists.txt
> > @@ -1,6 +1,7 @@
> >  # Building supplementary materials for LuaJIT.
> >  
> > -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
> > +# See the rationale in the root CMakeLists.txt.
> > +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> 
> Why is the minimum required version for this module/subdirectory
> increased?

To make it consistent project-wide, obviously. I totally don't want to
check every damn shit per-CMakeLists.txt like genex support, <continue>
and others, so now we can freely consider only 3.1.3 docs on cmake.org.

> 
> >  
> >  set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
> >  if(CMAKE_LIBRARY_ARCHITECTURE)

<snipped>

> > diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> > new file mode 100644
> > index 0000000..0be4b34
> > --- /dev/null
> > +++ b/test/tarantool-tests/CMakeLists.txt
> > @@ -0,0 +1,92 @@
> > +# Test suite that has been moved from Tarantool repository in
> > +# scope of https://github.com/tarantool/tarantool/issues/4478.
> > +
> > +# See the rationale in the root CMakeLists.txt.
> > +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> > +
> > +find_program(PROVE prove)
> > +if(NOT PROVE)
> > +  message(WARNING "`prove' is not found, so tarantool-tests target is not generated")
> > +  return()
> > +endif()
> > +
> > +macro(BuildTestLib lib sources)
> 
> Nit: BuildTestCLib or BuildTestLuaCLib is more verbose for me.
> Feel free to ignore.

Technicaly these libraries are not fully implemented via Lua C API, so I
chose the first one. Diff is below:

================================================================================

diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index a7af807..c7a4ccc 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -10,7 +10,7 @@ if(NOT PROVE)
   return()
 endif()
 
-macro(BuildTestLib lib sources)
+macro(BuildTestCLib lib sources)
   add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
   target_include_directories(${lib} PRIVATE
     ${LUAJIT_SOURCE_DIR}
diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
index 5515567..f2be549 100644
--- a/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
+++ b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt
@@ -1 +1 @@
-BuildTestLib(libsandwich libsandwich.c)
+BuildTestCLib(libsandwich libsandwich.c)
diff --git a/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
index 91a18a6..16f1aa8 100644
--- a/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
+++ b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt
@@ -1 +1 @@
-BuildTestLib(libflush libflush.c)
+BuildTestCLib(libflush libflush.c)
diff --git a/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
index cff0096..60eb5bb 100644
--- a/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
+++ b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt
@@ -1 +1 @@
-BuildTestLib(testgetmetrics testgetmetrics.c)
+BuildTestCLib(testgetmetrics testgetmetrics.c)

================================================================================

> 

<snipped>

> > +  # Unfortunately, CMake is a crap and there is no other way to
> > +  # extend the list in parent scope but join two strings with
> > +  # 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 interpreter can find and load it.
> 
> Typo: s/interpreter/the interpreter/

Changed to LuaJIT.

> 

<snipped>

> > +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
> > +# with dependecies are set in scope of BuildTestLib macro.
> > +add_custom_command(
> > +  COMMENT "Running Tarantool tests"
> > +  OUTPUT tests.ok
> > +  DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS}
> > +  COMMAND
> > +  env
> > +    LUA_PATH="${LUA_PATH}\;\;"
> > +    LUA_CPATH="${LUA_CPATH}\;\;"
> > +    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
> > +    ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
> > +      --exec ${LUAJIT_TEST_BINARY}
> > +      --ext ${LUA_TEST_SUFFIX}
> > +      --failures --shuffle
> 
> See nothing bad to add `--verbose` option here. It's better to see the
> name of the single test, not the test file only.

No. It spoils the output too much. I propose the following change:

================================================================================

diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index c7a4ccc..9c9dabf 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -68,8 +68,13 @@ set(LUA_PATH
   "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua"
 )
 set(LUA_TEST_SUFFIX .test.lua)
+set(LUA_TEST_FLAGS --failures --shuffle)
 file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
 
+if(CMAKE_VERBOSE_MAKEFILE)
+  list(APPEND LUA_TEST_FLAGS --verbose)
+endif()
+
 # LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
 # with dependecies are set in scope of BuildTestLib macro.
 add_custom_command(
@@ -84,7 +89,7 @@ add_custom_command(
     ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
       --exec ${LUAJIT_TEST_BINARY}
       --ext ${LUA_TEST_SUFFIX}
-      --failures --shuffle
+      ${LUA_TEST_FLAGS}
     && touch tests.ok
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )

================================================================================

If you're OK with it, I'll apply these changes to the branch.

> 
> > +    && touch tests.ok
> > +  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
> > +)
> > +
> > +add_custom_target(tarantool-tests DEPENDS tests.ok)
> > diff --git a/test/gh-3196-incorrect-string-length.test.lua b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> > similarity index 94%
> > rename from test/gh-3196-incorrect-string-length.test.lua
> > rename to test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> > index f135de7..edb728f 100755
> > --- a/test/gh-3196-incorrect-string-length.test.lua
> > +++ b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua
> > @@ -1,4 +1,4 @@
> > -#!/usr/bin/env tarantool
> > +#!/usr/bin/env luajit
> 
> I think, that this line unnecessary, as much as an executable format of
> the file. Same thoughts about all test files below.

Removed all shebangs and x permissions.

> 
> >  
> >  -- Miscellaneous test for LuaJIT bugs
> >  local tap = require('tap')
> > diff --git a/test/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> > similarity index 70%
> > rename from test/gh-4427-ffi-sandwich.test.lua
> > rename to test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> > index 9d5e50f..e9771e8 100755
> > --- a/test/gh-4427-ffi-sandwich.test.lua
> > +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> > @@ -1,22 +1,30 @@
> > -#!/usr/bin/env tarantool
> > +#!/usr/bin/env luajit
> >  
> >  if #arg == 0 then
> > -  require('utils').selfrun(arg, {
> > +
> > +  local utils = require('utils')
> > +
> > +  -- Disabled on *BSD due to #4819.
> > +  utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> > +
> > +  utils.selfrun(arg, {
> >      {
> > -      arg = {
> > +      arg  = {
> 
> This alignment is beauty, but unnecessary, please drop these changes.
> Same remarks for the changes below.

Removed.

> 
> >          1, -- hotloop (arg[1])
> 
> Side note: this may be not arg[1] or so on for Tarantool or pure LuaJIT
> with additional flags. But good for now, so whatever.
> 
> >          1, -- trigger (arg[2])
> >        },
> > -      res = tostring(3), -- hotloop + trigger + 1
> > -      msg = 'Trace is aborted',
> > +      test = 'is',
> > +      res  = tostring(3), -- hotloop + trigger + 1
> > +      msg  = 'Trace is aborted',
> >      },
> >      {
> > -      arg = {
> > +      arg  = {
> >          1, -- hotloop (arg[1])
> >          2, -- trigger (arg[2])
> >        },
> > -      res = 'Lua VM re-entrancy is detected while executing the trace',
> > -      msg = 'Trace is recorded',
> > +      test = 'like',
> 
> What does it mean?

The type of test used for verification: either pattern matching ('like')
or exact match ('is').

> 
> > +      res  = 'Lua VM re%-entrancy is detected while executing the trace',
> 
> This % is redundant.

Any proof for it?

> 
> > +      msg  = 'Trace is recorded',
> >      },
> >    })
> >  end

<snipped>

> > diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > similarity index 98%
> > rename from test/misclib-getmetrics-lapi.test.lua
> > rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > index 3b3d1f8..959293d 100755
> > --- a/test/misclib-getmetrics-lapi.test.lua
> > +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua

<snipped>

> > @@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest)
> >      subtest:plan(1)
> >  
> >      -- Force up garbage collect all dead objects.
> 
> Please, add comments about testing as a third party for the Tarantool
> and GC finalizers to describe this change.

Well, isn't everything described above? We are forcing GC to collect
*all* dead objects. In other words until collectgarbage("count") return
value changes.

> 
> > -    collectgarbage("collect")
> > +    repeat
> > +        local count = collectgarbage("count")
> > +        collectgarbage("collect")
> > +    until collectgarbage("count") == count
> >  
> >      -- Bump getmetrics table and string keys allocation.
> >      local old_metrics = misc.getmetrics()

<snipped>

> > diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
> 
> Side note: firstly I thought that <tap.lua> will be clashing with tap
> inside other suites, but these conflicts will be easily resolved by
> LUA_PATH.
> 
> > new file mode 100644
> > index 0000000..fd03132
> > --- /dev/null
> > +++ b/test/tarantool-tests/tap.lua
> 
> Feel free to stop me from refactoring anytime, but I try to dump all my
> thoughts about this module now to be referred later.
> 
> Side note: It's a pity that there is no such module as Perl's Test::Deep [3]
> in Lua (or at least I haven't seen one).
> 
> > @@ -0,0 +1,306 @@
> > +--- tap.lua internal file.
> > +---
> > +--- The Test Anything Protocol vesion 13 producer.
> > +---
> > +
> > +-- Initializer FFI for <iscdata> check.
> 
> This comment is misleading a bit, NULL usage is important too.

Removed.

> 
> > +local ffi = require('ffi')
> > +local NULL = ffi.new('void *')
> 
> Nit: What if LuaJIT is built without FFI?

Lol, these tests do not respect such configuration. I have the following
change to support testing with FFI disabled, but most of the tests are
simply skipped.

================================================================================

diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
index 149bd9a..17b4852 100644
--- a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
+++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
@@ -5,6 +5,9 @@ if #arg == 0 then
   -- Disabled on *BSD due to #4819.
   utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
 
+  utils.skipcond(not pcall(require, 'ffi'),
+                 'Disabled due to the lack of FFI support')
+
   utils.selfrun(arg, {
     {
       arg = {
diff --git a/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
index 9c04ef6..f478516 100644
--- a/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
+++ b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua
@@ -1,5 +1,8 @@
 #!/usr/bin/env luajit
 
+require('utils').skipcond(not pcall(require, 'ffi'),
+                          'Disabled due to the lack of FFI support')
+
 local tap = require('tap')
 
 local test = tap.test("lj-494-table-chain-infinite-loop")
diff --git a/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
index cd0f0f0..adce712 100644
--- a/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
+++ b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua
@@ -1,3 +1,5 @@
+require('utils').skipcond(not pcall(require, 'ffi'),
+                          'Disabled due to the lack of FFI support')
 local tap = require('tap')
 local ffi = require('ffi')
 
diff --git a/test/tarantool-tests/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua
index 46fee53..4c665f2 100644
--- a/test/tarantool-tests/lj-flush-on-trace.test.lua
+++ b/test/tarantool-tests/lj-flush-on-trace.test.lua
@@ -5,6 +5,9 @@ if #arg == 0 then
   -- Disabled on *BSD due to #4819.
   utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
 
+  utils.skipcond(not pcall(require, 'ffi'),
+                 'Disabled due to the lack of FFI support')
+
   utils.selfrun(arg, {
     {
       arg = {
diff --git a/test/tarantool-tests/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
index ef93597..785b2c6 100644
--- a/test/tarantool-tests/misclib-getmetrics-capi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua
@@ -23,45 +23,49 @@ test:ok(testgetmetrics.base())
 test:ok(testgetmetrics.gc_allocated_freed())
 test:ok(testgetmetrics.gc_steps())
 
-test:ok(testgetmetrics.objcount(function(iterations)
-    local ffi = require("ffi")
-
-    jit.opt.start(0)
-
-    local placeholder = {
-        str = {},
-        tab = {},
-        udata = {},
-        cdata = {},
-    }
-
-    -- Separate objects creations to separate jit traces.
-    for _ = 1, iterations do
-        table.insert(placeholder.str, tostring(_))
-    end
-
-    for _ = 1, iterations do
-        table.insert(placeholder.tab, {_})
-    end
-
-    for _ = 1, iterations do
-        table.insert(placeholder.udata, newproxy())
-    end
-
-    for _ = 1, iterations do
-        -- Check counting of VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("char[?]", 4))
-    end
-
-    for _ = 1, iterations do
-        -- Check counting of non-VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
-    end
-
-    placeholder = nil -- luacheck: no unused
-    -- Restore default jit settings.
-    jit.opt.start(unpack(jit_opt_default))
-end))
+if pcall(require, "ffi") then
+    test:ok(testgetmetrics.objcount(function(iterations)
+        local ffi = require("ffi")
+
+        jit.opt.start(0)
+
+        local placeholder = {
+            str = {},
+            tab = {},
+            udata = {},
+            cdata = {},
+        }
+
+        -- Separate objects creations to separate jit traces.
+        for _ = 1, iterations do
+            table.insert(placeholder.str, tostring(_))
+        end
+
+        for _ = 1, iterations do
+            table.insert(placeholder.tab, {_})
+        end
+
+        for _ = 1, iterations do
+            table.insert(placeholder.udata, newproxy())
+        end
+
+        for _ = 1, iterations do
+            -- Check counting of VLA/VLS/aligned cdata.
+            table.insert(placeholder.cdata, ffi.new("char[?]", 4))
+        end
+
+        for _ = 1, iterations do
+            -- Check counting of non-VLA/VLS/aligned cdata.
+            table.insert(placeholder.cdata, ffi.new("uint64_t", _))
+        end
+
+        placeholder = nil -- luacheck: no unused
+        -- Restore default jit settings.
+        jit.opt.start(unpack(jit_opt_default))
+    end))
+else
+    test:skip('Disabled due to the lack of FFI support')
+end
 
 -- Compiled loop with a direct exit to the interpreter.
 test:ok(testgetmetrics.snap_restores(function()
diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
index a005781..faffe5c 100644
--- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
@@ -175,69 +175,73 @@ test:test("gc-steps", function(subtest)
     subtest:is(newm.gc_steps_finalize, 0)
 end)
 
-test:test("objcount", function(subtest)
-    subtest:plan(4)
-    local ffi = require("ffi")
+if pcall(require, "ffi") then
+    test:test("objcount", function(subtest)
+        subtest:plan(4)
+        local ffi = require("ffi")
 
-    jit.opt.start(0)
+        jit.opt.start(0)
 
-    -- Remove all dead objects.
-    collectgarbage("collect")
-
-    local old_metrics = misc.getmetrics()
-
-    local placeholder = {
-        str = {},
-        tab = {},
-        udata = {},
-        cdata = {},
-    }
+        -- Remove all dead objects.
+        collectgarbage("collect")
 
-    -- Separate objects creations to separate jit traces.
-    for _ = 1, 1000 do
-        table.insert(placeholder.str, tostring(_))
-    end
+        local old_metrics = misc.getmetrics()
 
-    for _ = 1, 1000 do
-        table.insert(placeholder.tab, {_})
-    end
+        local placeholder = {
+            str = {},
+            tab = {},
+            udata = {},
+            cdata = {},
+        }
 
-    for _ = 1, 1000 do
-        table.insert(placeholder.udata, newproxy())
-    end
+        -- Separate objects creations to separate jit traces.
+        for _ = 1, 1000 do
+            table.insert(placeholder.str, tostring(_))
+        end
 
-    for _ = 1, 1000 do
-        -- Check counting of VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("char[?]", 4))
-    end
+        for _ = 1, 1000 do
+            table.insert(placeholder.tab, {_})
+        end
 
-    for _ = 1, 1000 do
-        -- Check counting of non-VLA/VLS/aligned cdata.
-        table.insert(placeholder.cdata, ffi.new("uint64_t", _))
-    end
+        for _ = 1, 1000 do
+            table.insert(placeholder.udata, newproxy())
+        end
 
-    placeholder = nil -- luacheck: no unused
-    collectgarbage("collect")
-    local new_metrics = misc.getmetrics()
+        for _ = 1, 1000 do
+            -- Check counting of VLA/VLS/aligned cdata.
+            table.insert(placeholder.cdata, ffi.new("char[?]", 4))
+        end
 
-    -- Check that amount of objects not increased.
-    subtest:is(new_metrics.gc_strnum, old_metrics.gc_strnum,
-               "strnum don't change")
-    -- When we call getmetrics, we create table for metrics first.
-    -- So, when we save old_metrics there are x + 1 tables,
-    -- when we save new_metrics there are x + 2 tables, because
-    -- old table hasn't been collected yet (it is still
-    -- reachable).
-    subtest:is(new_metrics.gc_tabnum - old_metrics.gc_tabnum, 1,
-               "tabnum don't change")
-    subtest:is(new_metrics.gc_udatanum, old_metrics.gc_udatanum,
-               "udatanum don't change")
-    subtest:is(new_metrics.gc_cdatanum, old_metrics.gc_cdatanum,
-               "cdatanum don't change")
+        for _ = 1, 1000 do
+            -- Check counting of non-VLA/VLS/aligned cdata.
+            table.insert(placeholder.cdata, ffi.new("uint64_t", _))
+        end
 
-    -- Restore default jit settings.
-    jit.opt.start(unpack(jit_opt_default))
-end)
+        placeholder = nil -- luacheck: no unused
+        collectgarbage("collect")
+        local new_metrics = misc.getmetrics()
+
+        -- Check that amount of objects not increased.
+        subtest:is(new_metrics.gc_strnum, old_metrics.gc_strnum,
+                   "strnum don't change")
+        -- When we call getmetrics, we create table for metrics first.
+        -- So, when we save old_metrics there are x + 1 tables,
+        -- when we save new_metrics there are x + 2 tables, because
+        -- old table hasn't been collected yet (it is still
+        -- reachable).
+        subtest:is(new_metrics.gc_tabnum - old_metrics.gc_tabnum, 1,
+                   "tabnum don't change")
+        subtest:is(new_metrics.gc_udatanum, old_metrics.gc_udatanum,
+                   "udatanum don't change")
+        subtest:is(new_metrics.gc_cdatanum, old_metrics.gc_cdatanum,
+                   "cdatanum don't change")
+
+        -- Restore default jit settings.
+        jit.opt.start(unpack(jit_opt_default))
+    end)
+else
+    test:skip('Disabled due to the lack of FFI support')
+end
 
 test:test("snap-restores-direct-loop", function(subtest)
     -- Compiled loop with a direct exit to the interpreter.
diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua
index 7bfcb4d..f05d7e6 100644
--- a/test/tarantool-tests/misclib-memprof-lapi.test.lua
+++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua
@@ -1,3 +1,8 @@
+-- XXX: utils.bufread unconditionally loads FFI, so the test can't
+-- proceed if FFI support is not enabled.
+require('utils').skipcond(not pcall(require, 'ffi'),
+                          'Disabled due to the lack of FFI support')
+
 local tap = require("tap")
 
 local test = tap.test("misc-memprof-lapi")
diff --git a/test/tarantool-tests/or-232-unsink-64-kptr.test.lua b/test/tarantool-tests/or-232-unsink-64-kptr.test.lua
index fc8acaa..b4e0778 100644
--- a/test/tarantool-tests/or-232-unsink-64-kptr.test.lua
+++ b/test/tarantool-tests/or-232-unsink-64-kptr.test.lua
@@ -1,3 +1,6 @@
+require('utils').skipcond(not pcall(require, 'ffi'),
+                          'Disabled due to the lack of FFI support')
+
 local tap = require('tap')
 
 local test = tap.test("or-232-unsink-64-kptr")
diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index f0730c0..46e3bd1 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -4,8 +4,8 @@
 ---
 
 -- Initializer FFI for <iscdata> check.
-local ffi = require('ffi')
-local NULL = ffi.new('void *')
+local hasffi, ffi = pcall(require, 'ffi')
+local NULL = hasffi and ffi.new('void *')
 
 local function indent(chars)
   return (' '):rep(chars)
@@ -204,6 +204,9 @@ end
 
 local function iscdata(test, v, ctype, message, extra)
   extra = extra or {}
+  if not hasffi then
+    return fail(test, message, extra)
+  end
   extra.expected = ffi.typeof(ctype)
   if type(v) ~= 'cdata' then
     extra.got = type(v)

================================================================================

BTW, nothing works also if LuaJIT is build with JIT support disabled.
Furthermore, I believe LuaJIT suite also doesn't fit to this particular
configuration. I propose to adjust the tests in scope of another issue,
if you want.

> 

<snipped>

> 
> > +  level = level or 3
> 
> Why 3? Please add the comment about this here.
> Also, please mention about LuaJIT behaviour here (traceback not
> reporting tail call) -- that's why traceback is one and the same for
> `ok()` and `fail()` functions.

Added the following comment:

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index 29af3b9..41e918c 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -15,6 +15,14 @@ end
 
 local function traceback(level)
   local trace = {}
+  -- The default level is 3 since at this point you have the
+  -- following frame layout
+  -- frame #0: <debug.getinfo> (its call is below)
+  -- frame #1: <traceback> (this function)
+  -- frame #2: <ok> (the "dominator" function for all assertions)
+  -- XXX: all exported assertions call <ok> function using tail
+  -- call (i.e. "return ok(...)"), so frame #3 contains the
+  -- assertion function used in the test chunk.
   level = level or 3
   while true do
     local info = debug.getinfo(level, "nSl")

================================================================================

> 

<snipped>

> > +    table.insert(trace, {
> > +      source   = info.source,
> > +      src      = info.short_src,
> > +      line     = info.linedefined or 0,
> > +      what     = info.what,
> > +      name     = info.name,
> > +      namewhat = info.namewhat,
> > +      filename = info.source:sub(1, 1) == '@' and info.source:sub(2) or 'eval',
> 
> What does 'eval' mean?

AFAICS, the code executed via -e flag: in that case source is the line
passed via this flag.

> 

<snipped>

> > +local function ok(test, cond, message, extra)
> > +  test.total = test.total + 1
> > +  if cond then
> > +    io.write(indent(4 * test.level), ('ok - %s\n'):format(message))
> > +    return true
> > +  end
> > +
> > +  test.failed = test.failed + 1
> > +  io.write(indent(4 * test.level), ('not ok - %s\n'):format(message))
> 
> Nit: 4 * test.level repeated several times. May be encapsulated inside
> `local cur_level` variable.
> Feel free to ignore.

I reimplemented <indent> function a bit. The changes are below:

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index 3fe6910..41e918c 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -7,8 +7,10 @@
 local ffi = require("ffi")
 local NULL = ffi.new("void *")
 
-local function indent(chars)
-  return (" "):rep(chars)
+local function indent(level, size)
+  -- Use the default indent size if none is specified.
+  size = tonumber(size) or 4
+  return (" "):rep(level * size)
 end
 
 local function traceback(level)
@@ -42,22 +44,23 @@ local function traceback(level)
 end
 
 local function diag(test, fmt, ...)
-  io.write(indent(4 * test.level), ("# %s\n"):format(fmt:format(...)))
+  io.write(indent(test.level), ("# %s\n"):format(fmt:format(...)))
 end
 
 local function ok(test, cond, message, extra)
   test.total = test.total + 1
   if cond then
-    io.write(indent(4 * test.level), ("ok - %s\n"):format(message))
+    io.write(indent(test.level), ("ok - %s\n"):format(message))
     return true
   end
 
   test.failed = test.failed + 1
-  io.write(indent(4 * test.level), ("not ok - %s\n"):format(message))
+  io.write(indent(test.level), ("not ok - %s\n"):format(message))
 
   -- Dump extra contents added in outer space.
   for key, value in pairs(extra or {}) do
-    io.write(indent(2 + 4 * test.level), ("%s:\t%s\n"):format(key, value))
+    -- XXX: Use "half indent" to dump <extra> fields.
+    io.write(indent(test.level + 0.5), ("%s:\t%s\n"):format(key, value))
   end
 
   if not test.trace then
@@ -65,12 +68,13 @@ local function ok(test, cond, message, extra)
   end
 
   local trace = traceback()
-  local tindent = indent(4 + 4 * test.level)
+  local tindent = indent(test.level + 1)
   io.write(tindent, ("filename:\t%s\n"):format(trace[#trace].filename))
   io.write(tindent, ("line:\t%s\n"):format(trace[#trace].line))
   for frameno, frame in ipairs(trace) do
     io.write(tindent, ("frame #%d\n"):format(frameno))
-    local findent = indent(2) .. tindent
+    -- XXX: Use "half indent" to dump <frame> fiels.
+    local findent = indent(0.5) .. tindent
     for key, value in pairs(frame) do
       io.write(findent, ("%s:\t%s\n"):format(key, value))
     end
@@ -257,7 +261,7 @@ end
 
 local function plan(test, planned)
   test.planned = planned
-  io.write(indent(4 * test.level), ("1..%d\n"):format(planned))
+  io.write(indent(test.level), ("1..%d\n"):format(planned))
 end
 
 local function check(test)

================================================================================

> 

<snipped>

> 
> > +    return false
> > +  end
> > +
> > +  local trace = traceback()
> 
> Nit: Looks like this chunk can be separated inside one function
> `dump_traceback()` back or whatever.
> Feel free to ignore.

Don't get this nit.

> 
> > +  local tindent = indent(4 + 4 * test.level)
> > +  io.write(tindent, ('filename:\t%s\n'):format(trace[#trace].filename))
> > +  io.write(tindent, ('line:\t%s\n'):format(trace[#trace].line))
> > +  for frameno, frame in ipairs(trace) do
> > +    io.write(tindent, ('frame #%d\n'):format(frameno))
> 
> Nit: Looks inconsistent with other output.
> 
> | io.write(tindent, ('frameno: #%d\n'):format(frameno))
> 
> hits better, in my opinion.
> 
> Looks like it will be good to add the function that does something like:

You missed there is a space instead of the tab in the output above. This
is done intentionally.

> 
> | io.write(indent, ('%s:\t%s\n'):format(key, value))
> 
> Feel free to ignore.

Ignoring.

> 
> > +    local findent = indent(2) .. tindent
> 
> Nit: s/ .. /../
> Here and below.

We have already discussed it: this is a binary op, so it should be
wrapped with the spaces like other binary ops. You argument "this is how
it is used in LuaJIT sources" doesn't work here, since concat is wrapped
with spaces in almost all test files (except ones introduced by you).

Ignoring.

> 

<snipped>

> 
> > +local function cmpdeeply(got, expected, extra)
> > +  if type(expected) == 'number' or type(got) == 'number' then
> > +    extra.got = got
> > +    extra.expected = expected
> > +    -- Handle NaN.
> > +    if got ~= got and expected ~= expected then
> > +      return true
> > +    end
> > +    return got == expected
> > +  end
> > +
> > +  if ffi.istype('bool', got) then got = (got == 1) end
> > +  if ffi.istype('bool', expected) then expected = (expected == 1) end
> > +
> > +  if extra.strict and type(got) ~= type(expected) then
> > +    extra.got = type(got)
> > +    extra.expected = type(expected)
> > +    return false
> > +  end
> > +
> > +  if type(got) ~= 'table' or type(expected) ~= 'table' then
> > +    extra.got = got
> > +    extra.expected = expected
> > +    return got == expected
> > +  end
> > +
> > +  local path = extra.path or '/'
> 
> This `path` in `extra` field looks unusable, please drop it.

Why do you think so? It allows to distinguish the path with missing keys
or invalid values. Anyway, I've reimplemented it a bit.

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index ce563fb..a5ac31a 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -159,12 +159,12 @@ local function is_deeply(test, got, expected, message, extra)
     end
     seen[got] = true
 
-    local path = extra.path or "/"
+    local path = extra.path or "obj"
     local has = {}
 
     for k, v in pairs(got) do
       has[k] = true
-      extra.path = path .. "/" .. k
+      extra.path = path .. "." .. k
       if not cmpdeeply(v, expected[k], extra) then
         return false
       end
@@ -173,6 +173,7 @@ local function is_deeply(test, got, expected, message, extra)
     -- Check if expected contains more keys then got.
     for k, v in pairs(expected) do
       if has[k] ~= true and (extra.strict or v ~= NULL) then
+        extra.path = path .. "." .. k
         extra.expected = "key " .. tostring(k)
         extra.got = "nil"
         return false

================================================================================

> 

<snipped>

> > +    visited_keys[i] = true

I believe this doesn't handle your case. This variable is introduced for
checking whether there are extra keys in <expected> table.

> 
> This is not good enough, visited keys should be cashed better:
> 
> | tarantool> local test = tap.test("<T>") local t1 = {1, 2, 3} t1[4] = {t1} local t2 = {1, 2, 3} t2[4] = {t2} return test:is_deeply(t1, t2), t1, t2
> | TAP version 13
> | ---
> | - error: stack overflow

Anyway, nice catch, thanks! Fixed this, diff is below:

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index f13e1b7..44e731f 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -88,58 +88,6 @@ local function skip(test, message, extra)
   ok(test, true, message .. " # skip", extra)
 end
 
-local function cmpdeeply(got, expected, extra)
-  if type(expected) == "number" or type(got) == "number" then
-    extra.got = got
-    extra.expected = expected
-    -- Handle NaN.
-    if got ~= got and expected ~= expected then
-      return true
-    end
-    return got == expected
-  end
-
-  if ffi.istype("bool", got) then got = (got == 1) end
-  if ffi.istype("bool", expected) then expected = (expected == 1) end
-
-  if extra.strict and type(got) ~= type(expected) then
-    extra.got = type(got)
-    extra.expected = type(expected)
-    return false
-  end
-
-  if type(got) ~= "table" or type(expected) ~= "table" then
-    extra.got = got
-    extra.expected = expected
-    return got == expected
-  end
-
-  local path = extra.path or "obj"
-  local visited_keys = {}
-
-  for i, v in pairs(got) do
-    visited_keys[i] = true
-    extra.path = path .. "." .. i
-    if not cmpdeeply(v, expected[i], extra) then
-      return false
-    end
-  end
-
-  -- Check if expected contains more keys then got.
-  for i, v in pairs(expected) do
-    if visited_keys[i] ~= true and (extra.strict or v ~= NULL) then
-      extra.path = path .. "." .. i
-      extra.expected = "key " .. tostring(i)
-      extra.got = "nil"
-      return false
-    end
-  end
-
-  extra.path = path
-
-  return true
-end
-
 local function like(test, got, pattern, message, extra)
   extra = extra or {}
   extra.got = got
@@ -177,6 +125,66 @@ local function is_deeply(test, got, expected, message, extra)
   extra.got = got
   extra.expected = expected
   extra.strict = test.strict
+
+  local seen = {}
+  local function cmpdeeply(got, expected, extra) --luacheck: ignore
+    if type(expected) == "number" or type(got) == "number" then
+      extra.got = got
+      extra.expected = expected
+      -- Handle NaN.
+      if got ~= got and expected ~= expected then
+        return true
+      end
+      return got == expected
+    end
+
+    if ffi.istype("bool", got) then got = (got == 1) end
+    if ffi.istype("bool", expected) then expected = (expected == 1) end
+
+    if extra.strict and type(got) ~= type(expected) then
+      extra.got = type(got)
+      extra.expected = type(expected)
+      return false
+    end
+
+    if type(got) ~= "table" or type(expected) ~= "table" then
+      extra.got = got
+      extra.expected = expected
+      return got == expected
+    end
+
+    -- Stop if tables are equal or <got> has been already seen.
+    if got == expected or seen[got] then
+      return true
+    end
+    seen[got] = true
+
+    local path = extra.path or "obj"
+    local has = {}
+
+    for k, v in pairs(got) do
+      has[k] = true
+      extra.path = path .. "." .. k
+      if not cmpdeeply(v, expected[k], extra) then
+        return false
+      end
+    end
+
+    -- Check if expected contains more keys then got.
+    for k, v in pairs(expected) do
+      if has[k] ~= true and (extra.strict or v ~= NULL) then
+        extra.path = path .. "." .. k
+        extra.expected = "key " .. tostring(k)
+        extra.got = "nil"
+        return false
+      end
+    end
+
+    extra.path = path
+
+    return true
+  end
+
   return ok(test, cmpdeeply(got, expected, extra), message, extra)
 end
 

================================================================================

> 
> > +    extra.path = path .. '/' .. i
> > +    if not cmpdeeply(v, expected[i], extra) then
> > +      return false
> > +    end
> > +  end
> > +
> > +  -- Check if expected contains more keys then got.
> > +  for i, v in pairs(expected) do

<snipped>

> > +local function is(test, got, expected, message, extra)
> > +  extra = extra or { }
> > +  extra.got = got
> > +  extra.expected = expected
> > +  local rc = (test.strict == false or type(got) == type(expected))
> 
> Nit: It is nice to leave the comment here to provide description why
> just `==` is not enough. Also, I don't like this behaviour -- it
> disrespects `eq` metamethod, and there is not mentioned in the doc [4].

In what sense this "disrespects" eq metamethod? Unfortunately, these
docs are quite bad...

> 
> > +             and got == expected
> > +  return ok(test, rc, message, extra)
> > +end
> > +
> > +local function isnt(test, got, unexpected, message, extra)
> > +  extra = extra or { }
> > +  extra.got = got
> > +  extra.unexpected = unexpected
> > +  local rc = (test.strict == true and type(got) ~= type(unexpected))
> 
> Ditto.
> 
> > +             or got ~= unexpected
> > +  return ok(test, rc, message, extra)
> > +end
> > +
> > +local function is_deeply(test, got, expected, message, extra)
> > +  extra = extra or { }
> > +  extra.got = got
> > +  extra.expected = expected
> > +  extra.strict = test.strict
> > +  return ok(test, cmpdeeply(got, expected, extra), message, extra)
> > +end
> > +
> > +local function isnil(test, v, message, extra)
> > +  return is(test, not v and v == nil and 'nil' or v, 'nil', message, extra)
> 
> Looks like type(v) 'nil' is enough. Or please add a comment why it is
> necessary.

You're right, these are just artefacts. Fixed, squashed, force-pushed to
the branch. Diff is below:

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index 9aa823f..44e731f 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -189,7 +189,7 @@ local function is_deeply(test, got, expected, message, extra)
 end
 
 local function isnil(test, v, message, extra)
-  return is(test, not v and v == nil and "nil" or v, "nil", message, extra)
+  return is(test, type(v), "nil", message, extra)
 end
 
 local function isnumber(test, v, message, extra)

================================================================================

> 
> > +end
> > +
> > +local function isnumber(test, v, message, extra)
> > +  return is(test, type(v), 'number', message, extra)
> > +end
> > +
> > +local function isstring(test, v, message, extra)
> > +  return is(test, type(v), 'string', message, extra)
> > +end
> > +
> > +local function istable(test, v, message, extra)
> > +  return is(test, type(v), 'table', message, extra)
> > +end
> > +
> > +local function isboolean(test, v, message, extra)
> > +  return is(test, type(v), 'boolean', message, extra)
> > +end
> > +
> > +local function isfunction(test, v, message, extra)
> > +  return is(test, type(v), 'function', message, extra)
> > +end
> > +
> > +local function isudata(test, v, utype, message, extra)
> 
> Side note: Looks like it does not test type(v) equals "udata", that's

Em, what?..

> inconsistent with other checkers. But changing it equals to break
> backward compatibility.

With what? BTW, it is already broken after the changes in <isnil>.

> 
> > +  extra = extra or { }
> > +  extra.expected = ('userdata<%s>'):format(utype)
> > +  if type(v) ~= 'userdata' then

... Here it is.

> > +    extra.got = type(v)
> > +    return fail(test, message, extra)
> > +  end
> > +  extra.got = ('userdata<%s>'):format(getmetatable(v))
> > +  return ok(test, getmetatable(v) == utype, message, extra)
> 
> Does it assume that compared udata-s should have the same metatable?

Otherwise there is nothing else to compare. BTW, I strongly doubt this
is rather useful.

> 
> > +end
> > +
> > +local function iscdata(test, v, ctype, message, extra)
> 
> Ditto about inconsistency.

Still don't get what inconsistency you're talking about.

> 
> > +  extra = extra or { }
> > +  extra.expected = ffi.typeof(ctype)
> > +  if type(v) ~= 'cdata' then
> > +    extra.got = type(v)
> > +    return fail(test, message, extra)
> > +  end
> > +  extra.got = ffi.typeof(v)
> > +  return ok(test, ffi.istype(ctype, v), message, extra)
> > +end
> > +
> > +local test_mt
> 
> Nit: Why is it declared here, not inside the `new()` function?

It is used in new function as an upvalue and is filled with the methods
later. If I declared it inside the <new> function it would be either
global or not visible outside of the function.

> 
> > +
> > +local function new(parent, name, fun, ...)
> 
> Side note: Why so serious :}?
> 
> > +  local level = parent ~= nil and parent.level + 1 or 0
> > +  local test = setmetatable({
> > +    parent  = parent,
> > +    name    = name,
> > +    level   = level,
> > +    total   = 0,
> > +    failed  = 0,
> > +    planned = 0,
> > +    trace   = parent == nil and true or parent.trace,
> > +    strict  = false,
> 
> What does strict mean and how it can be changed?

Em, in a quite simple way?
| test.strict = true

> I see nothing bad to copy some rationale from documentation [5] here
> as comments for each field.

I found no rationale there, could you please specify the places you want
to clarify in a more accurate way?

> 
> > +  }, test_mt)
> > +  if fun == nil then
> > +    return test
> > +  end
> > +  test:diag('%s', test.name)
> > +  fun(test, ...)
> > +  test:diag('%s: end', test.name)
> > +  return test:check()
> > +end

<snipped>

> > +local function check(test)
> > +  if test.checked then
> > +    error('check called twice')
> 
> Nit: eror_level = 2 is better here in my opinion.
> Feel free to ignore.

Unfortunately, nothing's changed:

================================================================================

$ luajit t.lua
luajit: ./tap.lua:261: check called twice
stack traceback:
	[C]: in function 'error'
	./tap.lua:261: in function 'check'
	t.lua:9: in main chunk
	[C]: at 0x5563639c4eb0
TAP version 13
1..1
ok - nil
$ git stash pop
<snipped>
$ git diff
diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index e2149a7..575e7bd 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -258,7 +258,7 @@ end
 
 local function check(test)
   if test.checked then
-    error('check called twice')
+    error('check called twice', 2)
   end
   test.checked = true
   if test.planned ~= test.total then
$ luajit t.lua
luajit: t.lua:9: check called twice
stack traceback:
	[C]: in function 'error'
	./tap.lua:261: in function 'check'
	t.lua:9: in main chunk
	[C]: at 0x55cea3cfceb0
TAP version 13
1..1
ok - nil

================================================================================

Please correct me if I've done something wrong. Ignoring for now.

> 
> > +  end
> > +  test.checked = true
> > +  if test.planned ~= test.total then
> > +    if test.parent ~= nil then
> > +      ok(test.parent, false, 'bad plan', {
> > +        planned = test.planned,
> > +        run = test.total,
> > +      })
> > +    else
> > +      diag(test, ('bad plan: planned %d run %d')
> > +        :format(test.planned, test.total))
> > +    end
> > +  elseif test.failed > 0 then
> > +    if test.parent ~= nil then
> > +      ok(test.parent, false, 'failed subtests', {
> > +        failed = test.failed,
> > +        planned = test.planned,
> > +      })
> > +    else
> > +      diag(test, 'failed subtest: %d', test.failed)
> > +    end
> > +  else
> > +    if test.parent ~= nil then
> > +      ok(test.parent, true, test.name)
> > +    end
> > +  end
> 
> Nit: looks like `if test.parent ~= nil` can be taken out for branches.
> Feel free to ignore.

It can, but such change doesn't worth it.

Ignoring.

> 
> > +  return test.planned == test.total and test.failed == 0
> > +end
> > +
> > +test_mt = {
> > +  __index = {
> > +    test       = new,
> > +    plan       = plan,
> > +    check      = check,
> > +    diag       = diag,
> > +    ok         = ok,
> > +    fail       = fail,
> > +    skip       = skip,
> > +    is         = is,
> > +    isnt       = isnt,
> > +    isnil      = isnil,
> > +    isnumber   = isnumber,
> > +    isstring   = isstring,
> > +    istable    = istable,
> > +    isboolean  = isboolean,
> > +    isfunction = isfunction,
> > +    isudata    = isudata,
> > +    iscdata    = iscdata,
> > +    is_deeply  = is_deeply,
> > +    like       = like,
> > +    unlike     = unlike,
> > +  }
> > +}
> > +
> > +return {
> > +  test = function(...)
> > +    io.write('TAP version 13\n')
> > +    return new(nil, ...)
> > +  end
> > +}
> > diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua
> > new file mode 100644
> > index 0000000..197b138
> > --- /dev/null
> > +++ b/test/tarantool-tests/utils.lua
> > @@ -0,0 +1,43 @@
> > +local M = { }
> > +
> > +local tap = require('tap')
> > +
> > +function M.selfrun(arg, checks)
> > +  local test = tap.test(arg[0]:match('/?(.+)%.test%.lua'))
> > +
> > +  test:plan(#checks)
> > +
> > +  local vars = {
> > +    LUABIN = arg[-1],
> > +    SCRIPT = arg[0],
> > +    PATH   = arg[0]:gsub('%.test%.lua', ''),
> > +    SUFFIX = package.cpath:match('?.(%a+);'),
> > +  }
> > +
> > +  local cmd = string.gsub('LUA_PATH="<PATH>/?.lua;$LUA_PATH" ' ..
> 
> Why do you use that way instead <CMakeLists.txt> configuration?

To make the tests using <selfrun> to be executed as a standalone script.

> 
> > +                          'LUA_CPATH="<PATH>/?.<SUFFIX>;$LUA_CPATH" ' ..
> > +                          'LD_LIBRARY_PATH=<PATH>:$LD_LIBRARY_PATH ' ..
> > +                          '<LUABIN> 2>&1 <SCRIPT>', '%<(%w+)>', vars)
> > +
> > +  for _, ch in pairs(checks) do
> > +    local testf = test[ch.test]
> > +    assert(testf, ("tap doesn't provide test.%s function"):format(ch.test))
> > +    local proc = io.popen((cmd .. (' %s'):rep(#ch.arg)):format(unpack(ch.arg)))
> > +    local res = proc:read('*all'):gsub('^%s+', ''):gsub('%s+$', '')
> 
> Are these spaces important?

Yes they are, if one uses exact match ('is') assertion.

> 
> > +    -- XXX: explicitly pass <test> as an argument to <testf>
> > +    -- to emulate test:is(...), test:like(...), etc.
> > +    testf(test, res, ch.res, ch.msg)
> > +  end
> > +
> > +  os.exit(test:check() and 0 or 1)
> > +end

<snipped>

> > -- 
> > 2.25.0
> > 
> 
> [1]: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/
> [2]: https://fperrad.frama.io/lua-TestMore/
> [3]: https://metacpan.org/pod/Test::Deep
> [4]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/#taptest-is
> [5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
> [6]: https://perldoc.perl.org/Test::More#done_testing
> 
> -- 
> Best regards,
> Sergey Kaplun
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake
  2021-02-14 19:32   ` Sergey Kaplun via Tarantool-patches
@ 2021-02-19 19:14     ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-19 19:14 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for your review!

On 14.02.21, Sergey Kaplun wrote:
> Hi, Igor!
> 
> Thanks for the patch!
> Nice to see all LuaJIT-related stuff inside its repo!
> 
> LGTM, except few questions below.

Added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

> 
> On 02.02.21, Igor Munkin wrote:
> > This patch introduces a separate target to run luacheck against all Lua
> > chunks within LuaJIT repository except those explicitly ignored in
> > .luacheckrc. There is also a single additional change over the 'luajit'
> > std defaults: to suppress all false positives related to <misc>
> 
> Typo: defaults are standards already. 'std' or 'defatults' is redundant
> here.

No. std is the attribute of .luacheckrc. The value of this attribute is
'luajit'. The defaults of the chosen std requires an additional change.

> 
> > namespace introduced in 5a61e1ab54b5c66bfebd836db1ac47996611e065 ('misc:
> > add C and Lua API for platform metrics'), this name is added to
> > <read_globals> list.
> > 
> > All Lua sources originally inherited from LuaJIT vanilla repository are
> > ignored, to leave them coherent with the upstream.
> > 
> > The new target is a dependency for the root <test> target.
> > 
> 
> Nit: Looks like you should mention tarantool/tarantool#5631 here.
> Or squash it with the previous patch.
> See rationale here [1].
> Feel free to ignore.

Answered here[1].

Ignoring.

> 
> > Part of tarantool/tarantool#4862
> > Part of tarantool/tarantool#5470
> > 
> > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > ---
> >  .gitignore          |  1 +
> >  .luacheckrc         | 11 +++++++++++
> >  test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
> >  3 files changed, 43 insertions(+)
> >  create mode 100644 .luacheckrc
> > 

<snipped>

> > diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
> > index f05dd90..c89efc2 100644
> > --- a/test/CMakeLists.txt
> > +++ b/test/CMakeLists.txt
> > @@ -3,6 +3,36 @@
> >  # See the rationale in the root CMakeLists.txt.
> >  cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> 
> Side note: Why this version?

Answered here[2].

> 
> >  
> > +find_program(LUACHECK luacheck)
> > +if(LUACHECK)
> > +  set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
> > +  set(LUACHECK_OK ${CMAKE_CURRENT_BINARY_DIR}/luacheck.ok)
> > +  file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
> > +  add_custom_command(
> > +    COMMENT "Running luacheck static analysis"
> > +    OUTPUT ${LUACHECK_OK}
> > +    DEPENDS ${LUACHECK} ${LUACHECK_RC} ${LUACHECK_DEPS}
> 
> Why are `${LUACHECK}` and `${LUACHECK_RC}` are mentioned?

To prevent target from running when strictly required luacheck or
.luacheckrc is missing.

> 
> > +    COMMAND
> > +      ${LUACHECK} ${PROJECT_SOURCE_DIR}
> > +        --codes
> > +        --config ${LUACHECK_RC}
> > +      && touch ${LUACHECK_OK}
> > +      # XXX: Filenames in .luacheckrc are considered relative to
> > +      # the working directory, hence luacheck should be run in the
> > +      # project root directory.
> > +      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
> > +  )
> 
> <snipped>
> 
> > -- 
> > 2.25.0
> > 
> 
> [1]: https://lists.tarantool.org/tarantool-patches/20210214191626.GF9361@root/T/#md50dbe78c52523ca739f2751d96c61edcf2e7a36
> 
> -- 
> Best regards,
> Sergey Kaplun

[1]:
https://lists.tarantool.org/tarantool-patches/cover.1612291495.git.imun@tarantool.org/T/#m817b6d754030b10f5b90f7602906496da10ee59f
[2]:
https://lists.tarantool.org/tarantool-patches/cover.1612291495.git.imun@tarantool.org/T/#m17cec88647c4defe2afee689dcba8d03b8b660d7

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-18  9:56       ` Sergey Kaplun via Tarantool-patches
@ 2021-02-20 19:18         ` Igor Munkin via Tarantool-patches
  2021-02-27 10:48           ` Sergey Kaplun via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-20 19:18 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

On 18.02.21, Sergey Kaplun wrote:
> Igor,
> 
> Thanks for the explanations!
> 

<snipped>

> > > Side note: This is not related to the patch directly but what about
> > > Tarantool COPYRIGHT notice in the LuaJIT code and inside new cmake files
> > > in particular?
> > 
> > We definitely need to make such activity, but I have no idea how to do
> > it a right way. Let's postpone it and discuss later, if you don't mind.
> 
> Yes, of course. May be I create the ticket?

Let's discuss it in our LuaJIT group at first and then create a ticket
with the resolution and plan.

> 

<snipped>

> 
> > > > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > > > new file mode 100644
> > > > index 0000000..0dba5d8
> > > > --- /dev/null
> > > > +++ b/CMakeLists.txt

<snipped>

> > > > +if(CMAKE_LIBRARY_ARCHITECTURE)
> > > > +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> > > > +endif()
> > > 
> > > What about `LUA_LMULTILIB`?
> > > 
> > > Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
> > > like it does in Makefile.original?
> > 
> > DESTDIR is supported out of the box in CMake. MULTILIB is "autodetected"
> > via CMake[1] (I hope, but never tried). Regardging LMULTILIB, I have no
> > idea what its purpose is. Do you?
> 
> To configure default CPATH, IINM, see luaconf.h for details.

My fault, ask you in a different way: how do you suppose to use it?

> 
> > 
> 
> | option(LUAJIT_USE_VALGRIND "Valgrind support" OFF)
> | if(LUAJIT_USE_VALGRIND)
> |   AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_VALGRIND)
> | endif()
> 
> Nit: I see the compilation error (predictable) when this option is ON,
> but valgrind is not installed. May be add some checks at configuration
> phase?
> 
> Feel free to ignore.

The original build system also checks nothing. You can create a ticket
to implement it in CMake (or rather in both build systems).

Ignoring for now.

> 

<snipped>

> > > > diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> > > > new file mode 100644
> > > > index 0000000..faaef6b
> > > > --- /dev/null
> > > > +++ b/cmake/LuaJITUtils.cmake

<snipped>

> > > Nit: Also, it would be nice to see comments here, why do we use this
> > > approach instead use of CMAKE_HOST_SYSTEM_PROCESSOR variable (is set by
> > > `uname -p`).
> > > Feel free to ignore.
> > 
> > I have no clear explanation of these and I definitely don't want to
> > write a bullshit in the comments, so I will either add TODO here if you
> > insist, or ignore this one.
> 
> Add TODO, please. Just to mention this.

Added TODO, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index 8ee4c26..2400fa5 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -3,6 +3,8 @@ function(LuaJITTestArch outvar strflags)
   # spaces with no further parsing. At the same time GCC is bad in
   # argument handling, so let's help it a bit.
   separate_arguments(TESTARCH_C_FLAGS UNIX_COMMAND ${strflags})
+  # TODO: It would be nice to drop a few words, why do we use this
+  # approach instead of CMAKE_HOST_SYSTEM_PROCESSOR variable.
   execute_process(
     COMMAND ${CMAKE_C_COMPILER} ${TESTARCH_C_FLAGS} -E lj_arch.h -dM
     WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}

================================================================================

> 

<snipped>

> > > 
> > > Content of <src/host/CMakeFiles/buildvm.dir/build.make>:
> > > | src/host/buildvm_arch.h: dynasm/*.lua
> > > |         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/luajit/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating buildvm_arch.h"
> > > |         cd /luajit/src/host && /luajit/src/host/minilua /luajit/dynasm/dynasm.lua -D ENDIAN_LE -D P64 -D JIT -D FFI -D DUALNUM -D FPU -D HFABI -D VER=80 -o buildvm_arch.h /luajit/src/vm_arm.dasc
> > > 
> > > vm_arm.dasc instead vm_arm64.dasc here.
> > 
> > Oops.
> > 
> > > 
> > > All because LJ_TARGET_ARM matched before LJ_TARGET_ARM64 in the line
> > > below. And it works for MIPS, because of different order :)
> > > Swap arches and leave comments about an order, please.
> > 
> > Neat, many thanks for testing and investigation! Fixed, squashed,
> > force-pushed to the branch. Diff is below:
> > 
> > ================================================================================
> > 
> > diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
> > index 1769675..0a662f7 100644
> > --- a/cmake/LuaJITUtils.cmake
> > +++ b/cmake/LuaJITUtils.cmake
> > @@ -12,7 +12,7 @@ function(LuaJITTestArch outvar strflags)
> >  endfunction()
> >  
> >  function(LuaJITArch outvar testarch)
> > -  foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS)
> 
> Please add a comment. Just to notice.

Added the comment, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake
index 2400fa5..f52ce10 100644
--- a/cmake/LuaJITUtils.cmake
+++ b/cmake/LuaJITUtils.cmake
@@ -21,6 +21,7 @@ function(LuaJITTestArch outvar strflags)
 endfunction()
 
 function(LuaJITArch outvar testarch)
+  # XXX: Please do not change the order of the architectures.
   foreach(TRYARCH X64 X86 ARM64 ARM PPC MIPS64 MIPS)
     string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND)
     # FIXME: <continue> is introduced in CMake version 3.2, but

================================================================================

> 

<snipped>

> > > > diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> > > > new file mode 100644
> > > > index 0000000..260fc6b
> > > > --- /dev/null
> > > > +++ b/cmake/SetTargetFlags.cmake
> > 
> 
> I add some comments to the following chunk.
> 
> | +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> | +  if(LUAJIT_ARCH STREQUAL "x64")
> 
> Side note: I have a linking error with the original Makefile
> without `MACOSX_DEPLOYMENT_TARGET` specification:
> || LINK      luajit
> || Undefined symbols for architecture x86_64:
> ||   "__Unwind_DeleteException", referenced from:
> ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> ||   "__Unwind_GetCFA", referenced from:
> ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> ||   "__Unwind_RaiseException", referenced from:
> ||       _lj_err_throw in libluajit.a(lj_err.o)
> ||   "__Unwind_SetGR", referenced from:
> ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> ||   "__Unwind_SetIP", referenced from:
> ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> || ld: symbol(s) not found for architecture x86_64
> 
> But nothing with CMake...
> Nonetheless, I suggest to safe the old Makefile behaviour to specify
> the minimum OS version (see [1]):

There is no error in CMake. This behaviour is dropped in LuaJIT in scope
of this patch[1]. Why do we need to add this to CMake?

> 

<snipped>

> Feel free to ignore.

Ignoring.

> 
> | +    AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000)
> 
> Here are description from Mike for this flags, please add this comment.
> 
> || commit f76e5a311ba543ae174acd3b585fb672fde8a3b5
> || Author: Mike Pall <mike>
> || Date:   Thu Mar 4 16:27:42 2010 +0100
> ||
> ||     Allocate 32 bit memory on OSX/x64 with mmap() hinting.
> ||
> ||     Must set -pagezero_size, otherwise the lower 4GB are blocked.

Added, thanks.

> 
> | +    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
> 
> Also I've found that this line produces warnings from linker like:
> 
> || ld: warning: -seg1addr not 16384 byte aligned, rounding up
> 
> So, I suggest the following solution for cmake and for the original
> Makefile (just add 8Kb):

There is the same value in the build system of the vanilla LuaJIT[2], so
I leave everything intact. BTW, I see no warning on my Mac.

> 

<snipped>

> > 
> > > 
> > > Are -dynamiclib and -fPIC flags forced set by CMake?
> > > Also, I don't find -install_name -compatibility_version -current_version
> > > flags. Are they insignificant?
> > 
> > Could you please share the corresponding part of "make VERBOSE=1"? These
> > variables should be set by CMake.
> 
> Thanks for the tip-off. Nothing is missing, but -compatibility_version
> is "2.0.0" instead of "2.1". Is that OK?

I see. There are the following <set_target_properties> parameters:
* VERSION[3] -- responsible for '-current_version' on Mac
* SOVERSION[4] -- responsible for '-compatibility_version' on Mac

I faced no problems with the current values of these variables, but if
you have any, please let me know. I believe the fix will be a small
if-else block with a huge comment that CMake is a shit.

> 

<snipped>

> > > Is it related to this?
> > 
> > No, you'll see this if you run <ar> with no suppressing its output. The
> > same issue is also presented for lj_gdbjit.c when GDBJIT support is
> > disabled.
> 
> Thanks, please see the patch to suppress superfluous randlib warnings about
> "*.a" having no symbols on MacOSX. Mike just ignoring them by
> `2>/dev/null` :)
> ===================================================================
> diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> index c8bcded..1fcdeea 100644
> --- a/cmake/SetTargetFlags.cmake
> +++ b/cmake/SetTargetFlags.cmake
> @@ -30,6 +30,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
>      AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
>    endif()
>    AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup)
> +  set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> rcusS <TARGET> <LINK_FLAGS> <OBJECTS>")
> +  set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
>  else() # Linux and FreeBSD.
>    AppendFlags(TARGET_BIN_FLAGS -Wl,-E)
>    list(APPEND TARGET_LIBS dl)
> ===================================================================
> 
> But may be this is not the best plase for this (it is not about flags).
> 
> Feel free to change and reword all these comments (here and above) on
> your own.

I don't know why you are so bothered with these warnings and want to
hack <ar> command invocation. If this bothers you a lot, then simply
*try to fix the problem* instead of *masking it*. The fix is quite small
and easy:

================================================================================

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 54f2941..809aac6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,6 +12,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 include(MakeSourceList)
 
+# --- Set OS and arch specific flags -------------------------------------------
+
+include(SetTargetFlags)
+include(SetDynASMFlags)
+
 # --- Define source tree -------------------------------------------------------
 
 # Core runtime.
@@ -106,7 +111,6 @@ make_source_list(SOURCES_JIT_OPT
     lj_opt_mem.c
     lj_opt_narrow.c
     lj_opt_sink.c
-    lj_opt_split.c
 )
 
 make_source_list(SOURCES_FFI
@@ -146,6 +150,19 @@ if(NOT LUAJIT_DISABLE_JIT)
   if(LUAJIT_ENABLE_GDBJIT)
     list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_gdbjit.c)
   endif()
+  # The support provided within src/lj_opt_split.c is required
+  # only for soft-float targets or for 32 bit CPUs which lack
+  # native 64 bit integer operations (the FFI is currently the
+  # only emitter for 64 bit integer instructions).
+  # Detect the target by the set DYNASM_FLAGS.
+  list(FIND DYNASM_FLAGS FPU HASFPU)
+  list(FIND DYNASM_FLAGS P64 HASP64)
+  # XXX: The CMake condition below should be the same as the
+  # following #ifdef condition (LJ_HASJIT is already 'true'):
+  # #if LJ_HASJIT && (LJ_SOFTFP || (LJ_32 && LJ_HASFFI))
+  if(HASFPU LESS 0 OR HASP64 LESS 0 AND NOT LUAJIT_DISABLE_FFI)
+    list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_opt_split.c)
+  endif()
 endif()
 
 # Build FFI sources if FFI support is enabled.
@@ -163,10 +180,6 @@ make_source_list(CLI_SOURCES
     luajit.c
 )
 
-# --- Set OS and arch specific flags -------------------------------------------
-
-include(SetTargetFlags)
-
 # --- Prepare files generated by buildvm ---------------------------------------
 
 add_subdirectory(host)
diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
index c00587f..e01db87 100644
--- a/src/host/CMakeLists.txt
+++ b/src/host/CMakeLists.txt
@@ -6,9 +6,6 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 # FIXME: Both minilua and buildvm need to be build with the HOST_*
 # toolchain.
 
-# XXX: DynASM flags are set considering the target arch.
-include(SetDynASMFlags)
-
 # --- Build minilua ------------------------------------------------------------
 
 # If left blank, minilua is built and used. You can supply an installed

================================================================================

Does this change worth it? I don't know. At least it *solves* the
warning, not *masks* it.

> 

<snipped>

> > > > diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> > > > new file mode 100644
> > > > index 0000000..8ada1a4
> > > > --- /dev/null
> > > > +++ b/src/CMakeLists.txt

<snipped>

> > > This warnings are annoying (cmake version is 3.13.4):
> > 
> > Did you try the latest version of the patchset? All these <install>
> > rules are moved under condition after Timur comment.
> 
> Yes, just check it again inside Docker with arm64.

Well, then I have no idea what is wrong with it. In the last version the
install rule is not created if there is no corresponding target.

> How can I provide more debug info?
> 

<snipped>

> > > 
> > > Can we suppress them?

I don't know if we can. Try just to close your eyes :)

> > > 
> > > > +install(TARGETS ${LUAJIT_DEPS}
> > > 
> > > The development releases of LuaJIT deliberately are not installed like
> > > "luajit", but "luajit-2.1.0-beta3". Do we want to change this behaviour?
> > 
> > What do you mean by that? Could you please provide an example?
> 
> Sure.

OK, now I get it. No, I don't want to mess with this shit and I have no
idea why Mike wants to. Anyway, if one needs such complex installation
it can use the original build system.

> 

<snipped>

> > 
> > Shit. BTW, the one generated above in bindir is neither. You can't
> > imagine how I reproach myself about approving this file addition. It's
> > like a vermiform appendix that we can't cut off right now. I've made the
> > template executable though this is nonsense but I failed to find another
> > normal solution. Anyway, I left the comment regarding it, squashed with
> > the previous commit. Here is the diff for both comments above:
> 
> There is no use to cry over spilt milk. Without this we probably would
> hear nothing from our dear customers about this feature.

But customers do not use this runner, we don't even provide it in the
packages. So nobody (except might be you) uses it now.

> I reckon on doing this soon after integration of testing suite and
> memory profiler bugfixes.

Nice, thanks!

> 

<snipped>

> > > 
> > > Side note: why don't you provide custom `tools` target for memprof like
> > > in the previous patch?
> > 
> > For what? In the previous patch there was an additional work to do, that
> > is a dependency for the main targets, so I grouped it into a separate
> > target.
> 
> OK, hope this problems will vanish with a -[tm] flag.
> 
> This is a comment for the previous patch. Just place it here to avoid of
> spam messages.
> 
> When I try `make -f Makefile.original -j`, I see the following warning:
> 
> | make: Circular src/luajit <- tools dependency dropped.

Yes, there is a primitive circular dependency, that Make can solve by
itself. I see no problem in this warning and totally don't want to spoil
the Makefile more.

> 
> Also, I found that amalg build is broken. I propose the following patch:

Thanks, I've fixed amalg build with your change. Diff is below:

================================================================================

diff --git a/src/Makefile.original b/src/Makefile.original
index 502504c..031f077 100644
--- a/src/Makefile.original
+++ b/src/Makefile.original
@@ -606,14 +606,14 @@ default all:	$(TARGET_T)
 
 amalg:
 	@grep "^[+|]" ljamalg.c
-	$(MAKE) all "LJCORE_O=ljamalg.o"
+	$(MAKE) -f Makefile.original all "LJCORE_O=ljamalg.o"
 
 clean:
 	$(HOST_RM) $(ALL_RM)
 
 libbc:
 	./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
-	$(MAKE) all
+	$(MAKE) -f Makefile.original all
 
 depend:
 	@for file in $(ALL_HDRGEN); do \

================================================================================

> 

<snipped>

> 
> > 
> > > 
> > > > -- 
> > > > 2.25.0
> > > > 
> > > 
> > > [1]: https://stackoverflow.com/questions/41773161/negate-boolean-variable-in-cmake
> > > [2]: https://cmake.org/pipermail/cmake/2015-July/061116.html
> > > [3]: https://cmake.org/cmake/help/latest/command/continue.html
> > > [4]: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
> > > 
> > > -- 
> > > Best regards,
> > > Sergey Kaplun
> > 
> > [1]: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LIBRARY_ARCHITECTURE.html
> > 
> > -- 
> > Best regards,
> > IM
> 
> [1]: https://cmake.org/cmake/help/v3.14/envvar/MACOSX_DEPLOYMENT_TARGET.html
> 
> -- 
> Best regards,
> Sergey Kaplun

[1]: https://github.com/LuaJIT/LuaJIT/commit/8961a92
[2]: https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/Makefile#L327
[3]: https://cmake.org/cmake/help/latest/prop_tgt/VERSION.html#mach-o-versions
[4]: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html#mach-o-versions

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-20 19:18         ` Igor Munkin via Tarantool-patches
@ 2021-02-27 10:48           ` Sergey Kaplun via Tarantool-patches
  2021-02-28 18:18             ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-27 10:48 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

LGTM, except a few nitpicks regarding to the commit message.

On 20.02.21, Igor Munkin wrote:
> Sergey,
> 

<snipped>

> > > > > +if(CMAKE_LIBRARY_ARCHITECTURE)
> > > > > +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> > > > > +endif()
> > > > 
> > > > What about `LUA_LMULTILIB`?
> > > > 
> > > > Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
> > > > like it does in Makefile.original?
> > > 
> > > DESTDIR is supported out of the box in CMake. MULTILIB is "autodetected"
> > > via CMake[1] (I hope, but never tried). Regardging LMULTILIB, I have no
> > > idea what its purpose is. Do you?
> > 
> > To configure default CPATH, IINM, see luaconf.h for details.
> 
> My fault, ask you in a different way: how do you suppose to use it?

For example, if I want to separate directories with Lua libraries and C
libraries. May be it is the superfluous customization. If you think so,
please add the notice that this option is not implemented in CMake, and
users should use original Makefile.

> 

<snipped>

> 
> > > > > diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> > > > > new file mode 100644
> > > > > index 0000000..260fc6b
> > > > > --- /dev/null
> > > > > +++ b/cmake/SetTargetFlags.cmake
> > > 
> > 
> > I add some comments to the following chunk.
> > 
> > | +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> > | +  if(LUAJIT_ARCH STREQUAL "x64")
> > 
> > Side note: I have a linking error with the original Makefile
> > without `MACOSX_DEPLOYMENT_TARGET` specification:
> > || LINK      luajit
> > || Undefined symbols for architecture x86_64:
> > ||   "__Unwind_DeleteException", referenced from:
> > ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> > ||   "__Unwind_GetCFA", referenced from:
> > ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> > ||   "__Unwind_RaiseException", referenced from:
> > ||       _lj_err_throw in libluajit.a(lj_err.o)
> > ||   "__Unwind_SetGR", referenced from:
> > ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> > ||   "__Unwind_SetIP", referenced from:
> > ||       _lj_err_unwind_dwarf in libluajit.a(lj_err.o)
> > || ld: symbol(s) not found for architecture x86_64
> > 
> > But nothing with CMake...
> > Nonetheless, I suggest to safe the old Makefile behaviour to specify
> > the minimum OS version (see [1]):
> 
> There is no error in CMake. This behaviour is dropped in LuaJIT in scope
> of this patch[1]. Why do we need to add this to CMake?

I think, because it may influence configuration of the toolchain and
flags. Let's return to this later if it really will become a problem.

> 
> > 
> 
> <snipped>
> 
> > Feel free to ignore.
> 
> Ignoring.
> 
> > 

<snipped>

> 
> > 
> > | +    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
> > 
> > Also I've found that this line produces warnings from linker like:
> > 
> > || ld: warning: -seg1addr not 16384 byte aligned, rounding up
> > 
> > So, I suggest the following solution for cmake and for the original
> > Makefile (just add 8Kb):
> 
> There is the same value in the build system of the vanilla LuaJIT[2], so
> I leave everything intact. BTW, I see no warning on my Mac.

This is why I mentioned Darwin version and add corresponding patch for
the old Makefile too. Anyway, the linker can handle this by itself, so
lets drop this as is. We can return to this with a new issue (inside our
or LuaJIT repo).

> 

<snipped>

> > 
> > > 
> > > > 
> > > > > -- 
> > > > > 2.25.0
> > > > > 
> > > > 
> > > > [1]: https://stackoverflow.com/questions/41773161/negate-boolean-variable-in-cmake
> > > > [2]: https://cmake.org/pipermail/cmake/2015-July/061116.html
> > > > [3]: https://cmake.org/cmake/help/latest/command/continue.html
> > > > [4]: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
> > > > 
> > > > -- 
> > > > Best regards,
> > > > Sergey Kaplun
> > > 
> > > [1]: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LIBRARY_ARCHITECTURE.html
> > > 
> > > -- 
> > > Best regards,
> > > IM
> > 
> > [1]: https://cmake.org/cmake/help/v3.14/envvar/MACOSX_DEPLOYMENT_TARGET.html
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> [1]: https://github.com/LuaJIT/LuaJIT/commit/8961a92
> [2]: https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/Makefile#L327
> [3]: https://cmake.org/cmake/help/latest/prop_tgt/VERSION.html#mach-o-versions
> [4]: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html#mach-o-versions
> 
> -- 
> Best regards,
> IM

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-19 19:04     ` Igor Munkin via Tarantool-patches
@ 2021-02-27 13:50       ` Sergey Kaplun via Tarantool-patches
  2021-02-28 18:18         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 46+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2021-02-27 13:50 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Igor,

On 19.02.21, Igor Munkin wrote:
> Sergey,
> 
> Thanks for the patch!
> 
> On 14.02.21, Sergey Kaplun wrote:
> > Hi, Igor!
> > 

<snipped>

> > Side note: (this is more like discussion question) -- do we really need
> > to use Tarantool's <tap.lua> module here? I provide some
> > dissatisfactions, but as I say below, we can't just change this
> > module API because we want (if you remove this module from Tarantool
> > and save it only here).
> > If it is saved untouchable in Tarantool repo I see no reason to
> > avoid replacing it with another one more suitable (if we want) or
> > improving it. Amount of tests is really small now and it can be easily
> > adapted. May be we should take a look at Lua test-modules like [1] and
> > [2].
> 
> I'm totally for lua-TestMore. We can try to port everything to its tap,
> when it has been incorporated to the trunk.

OK, we may discuss this offline. For now, IINM, tap.lua inside Tarantool
is not the same as tap.lua inside LuaJIT. Please correct me if I'm
wrong.

The fixes LGTM, but I still don't get why we don't create a separate
repository for the "third party" module tap.lua instead of managing 2
versions of it manually. Or why we won't replace it here with
lua-TestMore just now to avoid to do our job twice. Moreover, probably
we will not have time to do this later, I afraid.

Also, I should remember, that if we want to support 2 versions of this
module in Tarantool and in LuaJIT, it *may* not work in the same way
when we run tests under Tarantool binary, as it works for the LuaJIT
binary (thanks for the manually preload modules).

This is why I strongly disagree with its usage here instead
third-party dependency or other module usage. But it is very
subjectively. Feel free to ignore.

> 
> > 

<snipped>

> > > diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> > > new file mode 100644
> > > index 0000000..0be4b34
> > > --- /dev/null
> > > +++ b/test/tarantool-tests/CMakeLists.txt
> > > @@ -0,0 +1,92 @@

<snipped>

> > > +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
> > > +# with dependecies are set in scope of BuildTestLib macro.
> > > +add_custom_command(
> > > +  COMMENT "Running Tarantool tests"
> > > +  OUTPUT tests.ok
> > > +  DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS}
> > > +  COMMAND
> > > +  env
> > > +    LUA_PATH="${LUA_PATH}\;\;"
> > > +    LUA_CPATH="${LUA_CPATH}\;\;"
> > > +    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
> > > +    ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
> > > +      --exec ${LUAJIT_TEST_BINARY}
> > > +      --ext ${LUA_TEST_SUFFIX}
> > > +      --failures --shuffle
> > 
> > See nothing bad to add `--verbose` option here. It's better to see the
> > name of the single test, not the test file only.
> 
> No. It spoils the output too much. I propose the following change:
> 
> ================================================================================
> 
> diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> index c7a4ccc..9c9dabf 100644
> --- a/test/tarantool-tests/CMakeLists.txt
> +++ b/test/tarantool-tests/CMakeLists.txt
> @@ -68,8 +68,13 @@ set(LUA_PATH
>    "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua"
>  )
>  set(LUA_TEST_SUFFIX .test.lua)
> +set(LUA_TEST_FLAGS --failures --shuffle)
>  file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
>  
> +if(CMAKE_VERBOSE_MAKEFILE)
> +  list(APPEND LUA_TEST_FLAGS --verbose)
> +endif()
> +
>  # LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
>  # with dependecies are set in scope of BuildTestLib macro.
>  add_custom_command(
> @@ -84,7 +89,7 @@ add_custom_command(
>      ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
>        --exec ${LUAJIT_TEST_BINARY}
>        --ext ${LUA_TEST_SUFFIX}
> -      --failures --shuffle
> +      ${LUA_TEST_FLAGS}
>      && touch tests.ok
>    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
>  )
> 
> ================================================================================
> 
> If you're OK with it, I'll apply these changes to the branch.

Yep.

> 

<snipped>

> > >          1, -- hotloop (arg[1])
> > >          2, -- trigger (arg[2])
> > >        },
> > > -      res = 'Lua VM re-entrancy is detected while executing the trace',
> > > -      msg = 'Trace is recorded',
> > > +      test = 'like',
> > 
> > What does it mean?
> 
> The type of test used for verification: either pattern matching ('like')
> or exact match ('is').
> 
> > 
> > > +      res  = 'Lua VM re%-entrancy is detected while executing the trace',
> > 
> > This % is redundant.
> 
> Any proof for it?

Sorry, my bad. But very unobvious that it's a regex result (for the
first look).

> 
> > 
> > > +      msg  = 'Trace is recorded',
> > >      },
> > >    })
> > >  end
> 
> <snipped>
> 
> > > diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > similarity index 98%
> > > rename from test/misclib-getmetrics-lapi.test.lua
> > > rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > index 3b3d1f8..959293d 100755
> > > --- a/test/misclib-getmetrics-lapi.test.lua
> > > +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> 
> <snipped>
> 
> > > @@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest)
> > >      subtest:plan(1)
> > >  
> > >      -- Force up garbage collect all dead objects.
> > 
> > Please, add comments about testing as a third party for the Tarantool
> > and GC finalizers to describe this change.
> 
> Well, isn't everything described above? We are forcing GC to collect
> *all* dead objects. In other words until collectgarbage("count") return
> value changes.

Yes, but it is not necessary at all for LuaJIT itself -- there are no
cdata finalizers above to be running so it looks like only one
`collectgarbage()` is enough. But this is not true for the Tarantool.

> 
> > 
> > > -    collectgarbage("collect")
> > > +    repeat
> > > +        local count = collectgarbage("count")
> > > +        collectgarbage("collect")
> > > +    until collectgarbage("count") == count
> > >  
> > >      -- Bump getmetrics table and string keys allocation.
> > >      local old_metrics = misc.getmetrics()
> 
> <snipped>
> 
> > > diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
> > 
> > Side note: firstly I thought that <tap.lua> will be clashing with tap
> > inside other suites, but these conflicts will be easily resolved by
> > LUA_PATH.
> > 
> > > new file mode 100644
> > > index 0000000..fd03132
> > > --- /dev/null
> > > +++ b/test/tarantool-tests/tap.lua
> > 
> > Feel free to stop me from refactoring anytime, but I try to dump all my
> > thoughts about this module now to be referred later.
> > 
> > Side note: It's a pity that there is no such module as Perl's Test::Deep [3]
> > in Lua (or at least I haven't seen one).

<snipped>

> > > +local ffi = require('ffi')
> > > +local NULL = ffi.new('void *')
> > 
> > Nit: What if LuaJIT is built without FFI?
> 
> Lol, these tests do not respect such configuration. I have the following
> change to support testing with FFI disabled, but most of the tests are
> simply skipped.
> 
> ================================================================================

<snipped>

> ================================================================================
> 
> BTW, nothing works also if LuaJIT is build with JIT support disabled.
> Furthermore, I believe LuaJIT suite also doesn't fit to this particular
> configuration. I propose to adjust the tests in scope of another issue,
> if you want.

Yes, sure. Though, I doubt that it will be done soon :).

> 

<snipped>

> > 
> > > +    return false
> > > +  end
> > > +
> > > +  local trace = traceback()
> > 
> > Nit: Looks like this chunk can be separated inside one function
> > `dump_traceback()` back or whatever.
> > Feel free to ignore.
> 
> Don't get this nit.

It's about refactoring. I suggest to move this chunk (dumped traceback)
inside the other (new) function and just call this function here.
In my opinion, it increases code readability.
Feel free to ignore.

> 
> > 
> > > +  local tindent = indent(4 + 4 * test.level)
> > > +  io.write(tindent, ('filename:\t%s\n'):format(trace[#trace].filename))
> > > +  io.write(tindent, ('line:\t%s\n'):format(trace[#trace].line))
> > > +  for frameno, frame in ipairs(trace) do
> > > +    io.write(tindent, ('frame #%d\n'):format(frameno))
> > 

<snipped>

> > > +    visited_keys[i] = true
> 
> I believe this doesn't handle your case. This variable is introduced for
> checking whether there are extra keys in <expected> table.
> 
> > 
> > This is not good enough, visited keys should be cashed better:
> > 
> > | tarantool> local test = tap.test("<T>") local t1 = {1, 2, 3} t1[4] = {t1} local t2 = {1, 2, 3} t2[4] = {t2} return test:is_deeply(t1, t2), t1, t2
> > | TAP version 13
> > | ---
> > | - error: stack overflow
> 
> Anyway, nice catch, thanks! Fixed this, diff is below:
> 
> ================================================================================

<snipped>

> ================================================================================

Thanks for the fixes. Will we add corresponding patch to tap.lua inside
Tarantool?

> 
> > 
> > > +    extra.path = path .. '/' .. i
> > > +    if not cmpdeeply(v, expected[i], extra) then
> > > +      return false
> > > +    end
> > > +  end
> > > +
> > > +  -- Check if expected contains more keys then got.
> > > +  for i, v in pairs(expected) do
> 
> <snipped>
> 
> > > +local function is(test, got, expected, message, extra)
> > > +  extra = extra or { }
> > > +  extra.got = got
> > > +  extra.expected = expected
> > > +  local rc = (test.strict == false or type(got) == type(expected))
> > 
> > Nit: It is nice to leave the comment here to provide description why
> > just `==` is not enough. Also, I don't like this behaviour -- it
> > disrespects `eq` metamethod, and there is not mentioned in the doc [4].
> 
> In what sense this "disrespects" eq metamethod? Unfortunately, these
> docs are quite bad...

Sorry, I meant that `got == expected` is enough. But I forgot about FFI
semantics, FFI cast, and that with FFI "different types" are not enough
to say that objects are different. Just ignore this comment.

> 
> > 
> > > +             and got == expected
> > > +  return ok(test, rc, message, extra)
> > > +end
> > > +
> > > +local function isnt(test, got, unexpected, message, extra)
> > > +  extra = extra or { }
> > > +  extra.got = got
> > > +  extra.unexpected = unexpected
> > > +  local rc = (test.strict == true and type(got) ~= type(unexpected))
> > 
> > Ditto.
> > 
> > > +             or got ~= unexpected

<snipped>

> > > +local function isnumber(test, v, message, extra)
> > > +  return is(test, type(v), 'number', message, extra)
> > > +end
> > > +
> > > +local function isstring(test, v, message, extra)
> > > +  return is(test, type(v), 'string', message, extra)
> > > +end
> > > +
> > > +local function istable(test, v, message, extra)
> > > +  return is(test, type(v), 'table', message, extra)
> > > +end
> > > +
> > > +local function isboolean(test, v, message, extra)
> > > +  return is(test, type(v), 'boolean', message, extra)
> > > +end
> > > +
> > > +local function isfunction(test, v, message, extra)
> > > +  return is(test, type(v), 'function', message, extra)
> > > +end
> > > +
> > > +local function isudata(test, v, utype, message, extra)
> > 
> > Side note: Looks like it does not test type(v) equals "udata", that's
> 
> Em, what?..

Why this chunk is not enough?
| return is(test, type(v), 'userdata', message, extra)

And check utype by the other function.

> 
> > inconsistent with other checkers. But changing it equals to break
> > backward compatibility.
> 
> With what? BTW, it is already broken after the changes in <isnil>.

If tap.lua inside Tarantool is not the same as tap.lua inside LuaJIT
this comment is irrelevant. Please correct me if I'm wrong.

> 
> > 
> > > +  extra = extra or { }
> > > +  extra.expected = ('userdata<%s>'):format(utype)
> > > +  if type(v) ~= 'userdata' then
> 
> ... Here it is.
> 
> > > +    extra.got = type(v)
> > > +    return fail(test, message, extra)
> > > +  end
> > > +  extra.got = ('userdata<%s>'):format(getmetatable(v))
> > > +  return ok(test, getmetatable(v) == utype, message, extra)
> > 
> > Does it assume that compared udata-s should have the same metatable?
> 
> Otherwise there is nothing else to compare. BTW, I strongly doubt this
> is rather useful.

Me too!

> 
> > 
> > > +end
> > > +
> > > +local function iscdata(test, v, ctype, message, extra)
> > 
> > Ditto about inconsistency.
> 
> Still don't get what inconsistency you're talking about.

See the explanation above.

> 

<snipped>

> > > +  local level = parent ~= nil and parent.level + 1 or 0
> > > +  local test = setmetatable({
> > > +    parent  = parent,
> > > +    name    = name,
> > > +    level   = level,
> > > +    total   = 0,
> > > +    failed  = 0,
> > > +    planned = 0,
> > > +    trace   = parent == nil and true or parent.trace,
> > > +    strict  = false,
> > 
> > What does strict mean and how it can be changed?
> 
> Em, in a quite simple way?
> | test.strict = true

I confused with mixing kinda "private" and "public" fields.
It's OK to change `test.strict`, but it is bad idea to change
`test.failed` spontaneously.

> 
> > I see nothing bad to copy some rationale from documentation [5] here
> > as comments for each field.
> 
> I found no rationale there, could you please specify the places you want
> to clarify in a more accurate way?

I tell about the following description:

| Set `taptest.strict=true` if `taptest:is()` and `taptest:isnt()` and
| `taptest:is_deeply()` must be compared strictly with `nil`. Set
| `taptest.strict=false` if `nil` and `box.NULL` both have the same
| effect. The default is `false`. For example, if and only if
| `taptest.strict=true` has happened, then
| `taptest:is_deeply({a = box.NULL}, {})` will return `false`.


> 
> > 
> > > +  }, test_mt)
> > > +  if fun == nil then
> > > +    return test
> > > +  end
> > > +  test:diag('%s', test.name)
> > > +  fun(test, ...)
> > > +  test:diag('%s: end', test.name)
> > > +  return test:check()
> > > +end
> 
> <snipped>
> 
> > > +local function check(test)
> > > +  if test.checked then
> > > +    error('check called twice')
> > 
> > Nit: eror_level = 2 is better here in my opinion.
> > Feel free to ignore.
> 
> Unfortunately, nothing's changed:

The first line is changed.

> 
> ================================================================================
> 
> $ luajit t.lua
> luajit: ./tap.lua:261: check called twice
          ^^^^^^^^^^^^^
Before.

> stack traceback:
> 	[C]: in function 'error'
> 	./tap.lua:261: in function 'check'
> 	t.lua:9: in main chunk
> 	[C]: at 0x5563639c4eb0
> TAP version 13
> 1..1
> ok - nil
> $ git stash pop
> <snipped>
> $ git diff
> diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
> index e2149a7..575e7bd 100644
> --- a/test/tarantool-tests/tap.lua
> +++ b/test/tarantool-tests/tap.lua
> @@ -258,7 +258,7 @@ end
>  
>  local function check(test)
>    if test.checked then
> -    error('check called twice')
> +    error('check called twice', 2)
>    end
>    test.checked = true
>    if test.planned ~= test.total then
> $ luajit t.lua
> luajit: t.lua:9: check called twice
          ^^^^^^^
After.

> stack traceback:
> 	[C]: in function 'error'
> 	./tap.lua:261: in function 'check'
> 	t.lua:9: in main chunk
> 	[C]: at 0x55cea3cfceb0
> TAP version 13
> 1..1
> ok - nil
> 
> ================================================================================
> 
> Please correct me if I've done something wrong. Ignoring for now.

All's good.

> 
> > 

<snipped>

> > > diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua
> > > new file mode 100644
> > > index 0000000..197b138
> > > --- /dev/null
> > > +++ b/test/tarantool-tests/utils.lua
> > > @@ -0,0 +1,43 @@

<snipped>

> > > -- 
> > > 2.25.0
> > > 
> > 
> > [1]: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/
> > [2]: https://fperrad.frama.io/lua-TestMore/
> > [3]: https://metacpan.org/pod/Test::Deep
> > [4]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/#taptest-is
> > [5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
> > [6]: https://perldoc.perl.org/Test::More#done_testing
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> > 
> 
> -- 
> Best regards,
> IM

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake
  2021-02-27 10:48           ` Sergey Kaplun via Tarantool-patches
@ 2021-02-28 18:18             ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-28 18:18 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

On 27.02.21, Sergey Kaplun wrote:
> Igor,
> 
> LGTM, except a few nitpicks regarding to the commit message.

Thanks, added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

> 

<snipped>

> > > > > > +if(CMAKE_LIBRARY_ARCHITECTURE)
> > > > > > +  AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"')
> > > > > > +endif()
> > > > > 
> > > > > What about `LUA_LMULTILIB`?
> > > > > 
> > > > > Side note: should we provide `DESTDIR` or/and `MULTILIB` control variable
> > > > > like it does in Makefile.original?
> > > > 
> > > > DESTDIR is supported out of the box in CMake. MULTILIB is "autodetected"
> > > > via CMake[1] (I hope, but never tried). Regardging LMULTILIB, I have no
> > > > idea what its purpose is. Do you?
> > > 
> > > To configure default CPATH, IINM, see luaconf.h for details.
> > 
> > My fault, ask you in a different way: how do you suppose to use it?
> 
> For example, if I want to separate directories with Lua libraries and C
> libraries. May be it is the superfluous customization. If you think so,
> please add the notice that this option is not implemented in CMake, and
> users should use original Makefile.

I added the notice and reworded the commit message the following way.
Hope it covers all your nits regarding new build system NYIs.
| build: replace GNU Make with CMake
|
| Within this patch the LuaJIT build system is partially ported from GNU
| Make to CMake. These changes provide CMake build system for all
| supported host architectures, but only for the following OS: GNU/Linux,
| OSX, FreeBSD. For other platforms, environment tweaking and specific
| builds (such as 'amalg', stripped binary and shared library,
| cross-compiling support) use the old build system (see the recipe in the
| previous commit).
|
| Several components of the new build system such as automatic version
| detection, source files list generation and some recipes for
| CMakeLists.txt are taken verbatim or adapted from LuaVela repository.
|
| Part of tarantool/tarantool#4862

> 

<snipped>

> 
> > 
> > > 
> > > | +    AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000)
> > > 
> > > Also I've found that this line produces warnings from linker like:
> > > 
> > > || ld: warning: -seg1addr not 16384 byte aligned, rounding up
> > > 
> > > So, I suggest the following solution for cmake and for the original
> > > Makefile (just add 8Kb):
> > 
> > There is the same value in the build system of the vanilla LuaJIT[2], so
> > I leave everything intact. BTW, I see no warning on my Mac.
> 
> This is why I mentioned Darwin version and add corresponding patch for
> the old Makefile too. Anyway, the linker can handle this by itself, so
> lets drop this as is. We can return to this with a new issue (inside our
> or LuaJIT repo).

You can start with creating an issue in LuaJIT queue, if the problem is
reproduced with vanilla build system.

> 

<snipped>

> > > > 
> > > > [1]: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LIBRARY_ARCHITECTURE.html

<snipped>

> > [2]: https://github.com/LuaJIT/LuaJIT/blob/v2.1/src/Makefile#L327

<snipped>

> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake
  2021-02-27 13:50       ` Sergey Kaplun via Tarantool-patches
@ 2021-02-28 18:18         ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-28 18:18 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for your review, added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

On 27.02.21, Sergey Kaplun wrote:
> Igor,
> 

<snipped>

> > > Side note: (this is more like discussion question) -- do we really need
> > > to use Tarantool's <tap.lua> module here? I provide some
> > > dissatisfactions, but as I say below, we can't just change this
> > > module API because we want (if you remove this module from Tarantool
> > > and save it only here).
> > > If it is saved untouchable in Tarantool repo I see no reason to
> > > avoid replacing it with another one more suitable (if we want) or
> > > improving it. Amount of tests is really small now and it can be easily
> > > adapted. May be we should take a look at Lua test-modules like [1] and
> > > [2].
> > 
> > I'm totally for lua-TestMore. We can try to port everything to its tap,
> > when it has been incorporated to the trunk.
> 
> OK, we may discuss this offline. For now, IINM, tap.lua inside Tarantool
> is not the same as tap.lua inside LuaJIT. Please correct me if I'm
> wrong.

After the changes you requested -- yes, they are different.

> 
> The fixes LGTM, but I still don't get why we don't create a separate
> repository for the "third party" module tap.lua instead of managing 2
> versions of it manually. Or why we won't replace it here with
> lua-TestMore just now to avoid to do our job twice. Moreover, probably
> we will not have time to do this later, I afraid.

The answer is quite simple. There was no a requirement to reimplement
Tarantool tests in terms of the engine. There was a requirement to make
them self-sufficient and break the tie described in the issue. Both you
and Timur have already reviewed rather big changeset, hence while
working on #4862 I tried to reduce the AOE.

There are no external dependencies in LuaJIT for now and this is great.
There are no alternative TAP engines in repo for now, unfortunately.
What is more important: there is no other suites than the one originally
moved from Tarantool and using its TAP module. It has been working quite
well for more than a year[1] and I see no reason to reimplement testing
using another external TAP. Besides, I remember we discussed this
several times while talking about adopting other available suites.

Yes, you mentioned one bug (that has not been pointed for many years...
it means either nobody is using this assertion routine or nobody uses
self-recursive tables in tests) and several minor things bothering you.
I've fixed everything as you wanted and now you are asking about the
sense of doing this... I have nothing to say here, but to checkout the
patchset to the trunk if you don't mind.

Anyway, I guess you can freely rewrite everything using another TAP
engine in scope of lua-Harness issue[2]. Even if we don't want to make
our fork depend on Test.More, there is a minimal TAP library used when
Test.More is not available. Hope you'll like it more than Tarantool's.

> 
> Also, I should remember, that if we want to support 2 versions of this
> module in Tarantool and in LuaJIT, it *may* not work in the same way
> when we run tests under Tarantool binary, as it works for the LuaJIT
> binary (thanks for the manually preload modules).

If you see any misbehaviour, please point this out. I see everything
working fine right now.

> 
> This is why I strongly disagree with its usage here instead
> third-party dependency or other module usage. But it is very
> subjectively. Feel free to ignore.

I hope I've answered everything above. BTW, I personally against a
single third-party dependency instead of a tiny module provided via
self-sufficient Lua file in the trunk.

Ignoring.

> 

<snipped>

> > > > diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> > > > new file mode 100644
> > > > index 0000000..0be4b34
> > > > --- /dev/null
> > > > +++ b/test/tarantool-tests/CMakeLists.txt
> > > > @@ -0,0 +1,92 @@

<snipped>

> > > See nothing bad to add `--verbose` option here. It's better to see the
> > > name of the single test, not the test file only.
> > 
> > No. It spoils the output too much. I propose the following change:
> > 
> > ================================================================================
> > 
> > diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> > index c7a4ccc..9c9dabf 100644
> > --- a/test/tarantool-tests/CMakeLists.txt
> > +++ b/test/tarantool-tests/CMakeLists.txt
> > @@ -68,8 +68,13 @@ set(LUA_PATH
> >    "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua"
> >  )
> >  set(LUA_TEST_SUFFIX .test.lua)
> > +set(LUA_TEST_FLAGS --failures --shuffle)
> >  file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX})
> >  
> > +if(CMAKE_VERBOSE_MAKEFILE)
> > +  list(APPEND LUA_TEST_FLAGS --verbose)
> > +endif()
> > +
> >  # LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
> >  # with dependecies are set in scope of BuildTestLib macro.
> >  add_custom_command(
> > @@ -84,7 +89,7 @@ add_custom_command(
> >      ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
> >        --exec ${LUAJIT_TEST_BINARY}
> >        --ext ${LUA_TEST_SUFFIX}
> > -      --failures --shuffle
> > +      ${LUA_TEST_FLAGS}
> >      && touch tests.ok
> >    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
> >  )
> > 
> > ================================================================================
> > 
> > If you're OK with it, I'll apply these changes to the branch.
> 
> Yep.

Applied.

> 

<snipped>

> > > > diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > > similarity index 98%
> > > > rename from test/misclib-getmetrics-lapi.test.lua
> > > > rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > > > index 3b3d1f8..959293d 100755
> > > > --- a/test/misclib-getmetrics-lapi.test.lua
> > > > +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
> > 
> > <snipped>
> > 
> > > > @@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest)
> > > >      subtest:plan(1)
> > > >  
> > > >      -- Force up garbage collect all dead objects.
> > > 
> > > Please, add comments about testing as a third party for the Tarantool
> > > and GC finalizers to describe this change.
> > 
> > Well, isn't everything described above? We are forcing GC to collect
> > *all* dead objects. In other words until collectgarbage("count") return
> > value changes.
> 
> Yes, but it is not necessary at all for LuaJIT itself -- there are no
> cdata finalizers above to be running so it looks like only one
> `collectgarbage()` is enough. But this is not true for the Tarantool.

OK, adjusted the comment.

================================================================================

diff --git a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
index a005781..fd253ae 100644
--- a/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
+++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua
@@ -49,7 +49,8 @@ end)
 test:test("gc-allocated-freed", function(subtest)
     subtest:plan(1)
 
-    -- Force up garbage collect all dead objects.
+    -- Force up garbage collect all dead objects (even those
+    -- resurrected or postponed for custom finalization).
     repeat
         local count = collectgarbage("count")
         collectgarbage("collect")

================================================================================

> 

<snipped>

> > > > diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
> > > 
> > > Side note: firstly I thought that <tap.lua> will be clashing with tap
> > > inside other suites, but these conflicts will be easily resolved by
> > > LUA_PATH.
> > > 
> > > > new file mode 100644
> > > > index 0000000..fd03132
> > > > --- /dev/null
> > > > +++ b/test/tarantool-tests/tap.lua

<snipped>

> > > > +  local trace = traceback()
> > > 
> > > Nit: Looks like this chunk can be separated inside one function
> > > `dump_traceback()` back or whatever.
> > > Feel free to ignore.
> > 
> > Don't get this nit.
> 
> It's about refactoring. I suggest to move this chunk (dumped traceback)
> inside the other (new) function and just call this function here.
> In my opinion, it increases code readability.
> Feel free to ignore.

As you can see, everything related to io.* is placed within the
following functions:
* <new> wrapper
* <plan>
* <diag>
* <ok>

The most of io.* usage is enclosed within the latter one (unfortunately,
there is no way to gather it a single spot), so if there is something
bad with TAP format it's likely an error in <ok> routine and there is no
need to seek for all other places. So no, IMHO, it does not increase
code readability and further maintenance.

Ignoring.

> 

<snipped>

> 
> Thanks for the fixes. Will we add corresponding patch to tap.lua inside
> Tarantool?

Feel free to open an issue against Tarantool TAP module.

> 

<snipped>

> > > > +local function isudata(test, v, utype, message, extra)
> > > 
> > > Side note: Looks like it does not test type(v) equals "udata", that's
> > 
> > Em, what?..
> 
> Why this chunk is not enough?
> | return is(test, type(v), 'userdata', message, extra)
> 
> And check utype by the other function.

Because it is another helper inherited from Tarantool TAP module.
If you need a new metatable-agnostic one, feel free to file an issue to
the queue.

> 
> > 
> > > inconsistent with other checkers. But changing it equals to break
> > > backward compatibility.
> > 
> > With what? BTW, it is already broken after the changes in <isnil>.
> 
> If tap.lua inside Tarantool is not the same as tap.lua inside LuaJIT
> this comment is irrelevant. Please correct me if I'm wrong.

I've pointed above that <isnil> works in a different way as a result of
the changes you've requested.

> 

<snipped>

> 
> > > > +  local level = parent ~= nil and parent.level + 1 or 0
> > > > +  local test = setmetatable({
> > > > +    parent  = parent,
> > > > +    name    = name,
> > > > +    level   = level,
> > > > +    total   = 0,
> > > > +    failed  = 0,
> > > > +    planned = 0,
> > > > +    trace   = parent == nil and true or parent.trace,
> > > > +    strict  = false,
> > > 
> > > What does strict mean and how it can be changed?
> > 
> > Em, in a quite simple way?
> > | test.strict = true
> 
> I confused with mixing kinda "private" and "public" fields.
> It's OK to change `test.strict`, but it is bad idea to change
> `test.failed` spontaneously.

Selectio naturalis: do not change the value that is not meant to be
changed. Otherwise, you're "sam sebe zlobniy buratino".

> 
> > 
> > > I see nothing bad to copy some rationale from documentation [5] here
> > > as comments for each field.
> > 
> > I found no rationale there, could you please specify the places you want
> > to clarify in a more accurate way?
> 
> I tell about the following description:
> 
> | Set `taptest.strict=true` if `taptest:is()` and `taptest:isnt()` and
> | `taptest:is_deeply()` must be compared strictly with `nil`. Set
> | `taptest.strict=false` if `nil` and `box.NULL` both have the same
> | effect. The default is `false`. For example, if and only if
> | `taptest.strict=true` has happened, then
> | `taptest:is_deeply({a = box.NULL}, {})` will return `false`.
> 

OK, added the comment.

================================================================================

diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua
index 134b501..acbf5f1 100644
--- a/test/tarantool-tests/tap.lua
+++ b/test/tarantool-tests/tap.lua
@@ -248,6 +248,13 @@ local function new(parent, name, fun, ...)
     failed  = 0,
     planned = 0,
     trace   = parent == nil and true or parent.trace,
+    -- Set test.strict = true if test:is, test:isnt and
+    -- test:is_deeply must be compared strictly with nil.
+    -- Set test.strict = false if nil and box.NULL both have the
+    -- same effect. The default is false. For example, if and only
+    -- if test.strict = true has happened, then the following
+    -- assertion will return false.
+    -- test:is_deeply({a = box.NULL}, {})
     strict  = false,
   }, test_mt)
   if fun == nil then

================================================================================

> 
> > 
> > > 
> > > > +  }, test_mt)
> > > > +  if fun == nil then
> > > > +    return test
> > > > +  end
> > > > +  test:diag('%s', test.name)
> > > > +  fun(test, ...)
> > > > +  test:diag('%s: end', test.name)
> > > > +  return test:check()
> > > > +end
> > 
> > <snipped>
> > 
> > > > +local function check(test)
> > > > +  if test.checked then
> > > > +    error('check called twice')
> > > 
> > > Nit: eror_level = 2 is better here in my opinion.
> > > Feel free to ignore.
> > 
> > Unfortunately, nothing's changed:
> 
> The first line is changed.

Now I see, thanks! Applied the changes.

> 

<snipped>

> 
> > > > -- 
> > > > 2.25.0
> > > > 
> > > 
> > > [1]: https://luaunit.readthedocs.io/en/luaunit_v3_2_1/
> > > [2]: https://fperrad.frama.io/lua-TestMore/
> > > [3]: https://metacpan.org/pod/Test::Deep
> > > [4]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/#taptest-is
> > > [5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
> > > [6]: https://perldoc.perl.org/Test::More#done_testing
> > > 
> > > -- 
> > > Best regards,
> > > Sergey Kaplun
> > > 
> > 
> > -- 
> > Best regards,
> > IM
> 
> -- 
> Best regards,
> Sergey Kaplun

[1]: https://github.com/tarantool/luajit/commit/8343862
[2]: https://github.com/tarantool/tarantool/issues/5844

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment
  2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
                   ` (4 preceding siblings ...)
  2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake Igor Munkin via Tarantool-patches
@ 2021-02-28 22:04 ` Igor Munkin via Tarantool-patches
  5 siblings, 0 replies; 46+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2021-02-28 22:04 UTC (permalink / raw)
  To: Sergey Kaplun, Timur Safin; +Cc: tarantool-patches

I've checked the patchset into all long-term branches in
tarantool/luajit and bumped a new version in 1.10, 2.6, 2.7 and master.

NB: there is no separate commit with submodule bump, since there are
many change in LuaJIT build system in Tarantool repo too. For more info
see this series[1].

On 02.02.21, Igor Munkin wrote:
> This series moves LuaJIT-related parts of Tarantool testing machinery to
> LuaJIT repository. For this purpose the build system is partially ported
> to CMake. To avoid Makefiles name clashing the original build system is
> renamed to keep it working. As a result of these changes one need to
> explicitly specify the Makefile in the build command:
> | make -f Makefile.original <options>
> 
> These changes provides CMake build system only for the following OS:
> GNU/Linux, OSX, FreeBSD. For other platrforms use the old build system.
> 
> To run all available tests a separate target is introduced. The whole
> testing machinery is reworked much but the existing tests are left
> mostly unchanged. However, considering the way LuaJIT is integrated
> into Tarantool, this machinery provides two new configuration options:
> * LUAJIT_USE_TEST: to omit <test> target configuration for LuaJIT to
>   respect CMP0002 policy.
> * LUAJIT_TEST_BINARY: to choose which binary (i.e. Lua runtime) to be
>   used for running them.
> 
> The latter option value is used as a dependency for tests, and its
> default value is $<TARGET_FILE:${LUAJIT_DEPS}>. Unfortunately older
> CMake can't expand the generator expression used in DEPENDS section of
> <add_custom_(command|target)>. As a result the CMake minimum required
> version is bumped to 3.1 project-wide[1]. For more info see CMake Release
> notes[2] for 3.1 version.
> 
> Finally, existing tests are grouped and moved to a separate directory
> under the root test directory to make the further addition of other
> available test suites in scope of #4064[3] and #4473[4] easier.
> 
> Tarantool tests are implemented using Tarantool on-board TAP module[5],
> that is moved to LuaJIT repository with a little changes to save Lua
> chunks untouched. Other auxiliary files for Tarantool-specific testing
> (such as *.skipcond, suite.ini), in turn, are removed.
> 
> To run static analysis for Lua chunks a separate target is introduced.
> In scope of this target luacheck is run against all Lua chunks within
> LuaJIT repository except those inherited from LuaJIT vanilla repository,
> to leave them coherent with the upstream.
> 
> Since the regular static analysis has not been enabled for the test
> chunks in LuaJIT repository yet, the tests for recently implemented
> features still produce luacheck warnings. The most of the issues are
> fixed in scope of the commit 8fc103fb1a21c28185a1942e75d8d9485e3aade7
> ('test: fix warnings spotted by luacheck') and the last patch fixes the
> remaining ones.
> 
> [1]: https://lists.tarantool.org/tarantool-patches/20210127130947.yw5sdswpokujblyr@tarantool.org/T/#t
> [2]: https://cmake.org/cmake/help/latest/release/3.1.html#commands
> [3]: https://github.com/tarantool/tarantool/issues/4064
> [4]: https://github.com/tarantool/tarantool/issues/4473
> [5]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/
> 
> Branch: https://github.com/tarantool/luajit/tree/imun/gh-4862-cmake
> Issues:
> * https://github.com/tarantool/tarantool/issues/4862
> * https://github.com/tarantool/tarantool/issues/5470
> * https://github.com/tarantool/tarantool/issues/5631
> 
> Igor Munkin (5):
>   build: preserve the original build system
>   build: replace GNU Make with CMake
>   test: run LuaJIT tests via CMake
>   test: fix warnings found with luacheck in misclib*
>   test: run luacheck static analysis via CMake
> 

<snipped>

> 
> -- 
> 2.25.0
> 

[1]: https://lists.tarantool.org/tarantool-patches/20210227135610.GD6842@root/T/#t

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2021-02-28 22:04 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 20:57 [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches
2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 1/5] build: preserve the original build system Igor Munkin via Tarantool-patches
2021-02-04 22:53   ` Timur Safin via Tarantool-patches
2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
2021-02-09 11:38   ` Sergey Kaplun via Tarantool-patches
2021-02-09 12:47     ` Igor Munkin via Tarantool-patches
2021-02-09 14:45       ` Sergey Kaplun via Tarantool-patches
2021-02-09 15:28         ` Igor Munkin via Tarantool-patches
2021-02-10  9:35           ` Sergey Kaplun via Tarantool-patches
2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake Igor Munkin via Tarantool-patches
2021-02-04 22:53   ` Timur Safin via Tarantool-patches
2021-02-08 15:56     ` Igor Munkin via Tarantool-patches
2021-02-09 13:55       ` Timur Safin via Tarantool-patches
2021-02-09 15:09         ` Igor Munkin via Tarantool-patches
2021-02-11 19:23   ` Sergey Kaplun via Tarantool-patches
2021-02-16 15:28     ` Igor Munkin via Tarantool-patches
2021-02-18  9:56       ` Sergey Kaplun via Tarantool-patches
2021-02-20 19:18         ` Igor Munkin via Tarantool-patches
2021-02-27 10:48           ` Sergey Kaplun via Tarantool-patches
2021-02-28 18:18             ` Igor Munkin via Tarantool-patches
2021-02-13  3:47   ` Sergey Kaplun via Tarantool-patches
2021-02-16 15:32     ` Igor Munkin via Tarantool-patches
2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake Igor Munkin via Tarantool-patches
2021-02-08 15:05   ` Timur Safin via Tarantool-patches
2021-02-08 16:29     ` Igor Munkin via Tarantool-patches
2021-02-09  8:16       ` Timur Safin via Tarantool-patches
2021-02-09  8:43         ` Igor Munkin via Tarantool-patches
2021-02-09 13:59           ` Timur Safin via Tarantool-patches
2021-02-09 15:10             ` Igor Munkin via Tarantool-patches
2021-02-14 18:48   ` Sergey Kaplun via Tarantool-patches
2021-02-19 19:04     ` Igor Munkin via Tarantool-patches
2021-02-27 13:50       ` Sergey Kaplun via Tarantool-patches
2021-02-28 18:18         ` Igor Munkin via Tarantool-patches
2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 4/5] test: fix warnings found with luacheck in misclib* Igor Munkin via Tarantool-patches
     [not found]   ` <012f01d6fe1a$a2aa6890$e7ff39b0$@tarantool.org>
2021-02-08 15:57     ` Igor Munkin via Tarantool-patches
     [not found]     ` <2c495492-50f4-acfd-ad66-2cb44abb5fa1@tarantool.org>
2021-02-08 15:40       ` Sergey Bronnikov via Tarantool-patches
2021-02-08 15:58       ` Igor Munkin via Tarantool-patches
2021-02-14 19:16   ` Sergey Kaplun via Tarantool-patches
2021-02-16 15:29     ` Igor Munkin via Tarantool-patches
2021-02-16 16:36       ` Sergey Kaplun via Tarantool-patches
2021-02-02 20:57 ` [Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake Igor Munkin via Tarantool-patches
2021-02-04 22:52   ` Timur Safin via Tarantool-patches
2021-02-08 15:57     ` Igor Munkin via Tarantool-patches
2021-02-14 19:32   ` Sergey Kaplun via Tarantool-patches
2021-02-19 19:14     ` Igor Munkin via Tarantool-patches
2021-02-28 22:04 ` [Tarantool-patches] [PATCH luajit 0/5] Self-sufficient LuaJIT testing environment Igor Munkin via Tarantool-patches

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