Skip to content

Commit

Permalink
tests: don't rely on an external luarocks installation
Browse files Browse the repository at this point in the history
Build & install the testsuite dependencies ourselves.
  • Loading branch information
benoit-pierre committed Oct 4, 2024
1 parent c88c952 commit 1e45429
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $(BASE_PREFIX)clean:
rm -rf $(OUTPUT_DIR)

$(BASE_PREFIX)distclean:
rm -rf $(dir $(filter $(KOR_BASE)/build/%,$(OUTPUT_DIR))) $(wildcard $(THIRDPARTY_DIR)/*/build)
rm -rf $(dir $(filter $(KOR_BASE)/build/%,$(OUTPUT_DIR))) $(wildcard $(THIRDPARTY_DIR)/*/build $(THIRDPARTY_DIR)/spec/*/build)

info:
$(strip $(build_info))
Expand Down Expand Up @@ -190,7 +190,7 @@ cache-key: $(KOR_BASE)/Makefile $(KOR_BASE)/cache-key.base

define BINARY_PATHS
$(filter-out
$(addprefix $(OUTPUT_DIR)/,cmake staging thirdparty),
$(addprefix $(OUTPUT_DIR)/,cmake spec staging thirdparty),
$(wildcard $(OUTPUT_DIR)/*))
endef

Expand Down
13 changes: 5 additions & 8 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ endif
OUTPUT_DIR ?= $(KOR_BASE)/build/$(MACHINE)
CMAKE_DIR = $(OUTPUT_DIR)/cmake
STAGING_DIR = $(OUTPUT_DIR)/staging
SPEC_ROCKS_DIR = $(OUTPUT_DIR)/spec/rocks

BUILD_ENTRYPOINT = $(CMAKE_DIR)/build.ninja

Expand Down Expand Up @@ -763,13 +764,7 @@ endif

THIRDPARTY_DIR = $(KOR_BASE)/thirdparty

LUAROCKS_BINARY := $(firstword $(shell command -v luarocks luarocks-5.1))
ifneq (,$(LUAROCKS_BINARY))
# Detect versioned LR 3 binary, see koreader-base/pull/1003
ifneq (,$(shell $(LUAROCKS_BINARY) --help | grep -Eo -- --lua-version))
LUAROCKS_BINARY += --lua-version=5.1
endif
endif
LUAROCKS_BINARY := $(abspath $(STAGING_DIR)/bin/luarocks)

# Dynamic libraries must be compiled with "-shared" and "-fPIC".
# (And we enforce PIC everywhere via CFLAGS/CXXFLAGS).
Expand Down Expand Up @@ -927,6 +922,7 @@ set(VECTO_CFLAGS "$(VECTO_CFLAGS)")
set(BASE_DIR $(abspath $(KOR_BASE)))
set(OUTPUT_DIR $(abspath $(OUTPUT_DIR)))
set(STAGING_DIR $(abspath $(STAGING_DIR)))
set(SPEC_ROCKS_DIR $(abspath $(SPEC_ROCKS_DIR)))
set(THIRDPARTY_DIR $(abspath $(THIRDPARTY_DIR)))

set(MAKE $(MAKE))
Expand Down Expand Up @@ -1079,7 +1075,8 @@ ifneq (,$(EMULATE_READER))

define busted_fn
busted() {(
eval "$$($(LUAROCKS_BINARY) path)";
export LUA_CPATH='./?.so;$(abspath $(SPEC_ROCKS_DIR)/lib/lua/5.1/?.so)'
export LUA_PATH='./?.lua;$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?.lua);$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?/init.lua)'
export TESSDATA_DIR="$$PWD/data";
./luajit -e 'require "busted.runner" {standalone = false}' /dev/null
--exclude-tags=notest
Expand Down
26 changes: 26 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ declare_project(thirdparty/luajit)
# luajson
declare_project(thirdparty/luajson)

# luarocks
declare_project(thirdparty/luarocks DEPENDS luajit EXCLUDE_FROM_ALL)

# luasec
declare_project(thirdparty/luasec DEPENDS luajit luasocket openssl)

Expand Down Expand Up @@ -405,6 +408,29 @@ declare_project(thirdparty/zsync2 DEPENDS curl openssl zlib ${EXCLUDE_FROM_ALL})

# }}}

# TESTSUITE DEPENDENCIES. {{{

if(EMULATE_READER)
add_custom_target(spec-rocks)
foreach(PRJ
busted
dkjson
lua-term
lua_cliargs
luafilesystem
luassert
luasystem
mediator_lua
penlight
say
)
declare_project(thirdparty/spec/${PRJ} DEPENDS luarocks)
add_dependencies(spec-rocks ${PRJ})
endforeach()
endif()

# }}}

# Koreader executables and libs.
# NOTE: thirdparty dependencies are manually handled later
# for finer control (see `cmake/koreader/CMakeLists.txt`
Expand Down
6 changes: 6 additions & 0 deletions thirdparty/cmake_modules/koenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ extract_archive() { (
# Of course `cmake -E tar` does not support `--strip-components=n`,
# so we need to use a temporary directory and move things around…
rm -rf "${sourcedir}" "${sourcedir}.tmp" || return 1
case "${archive}" in
*.src.rock)
# Luarocks source rock, there's no need to extract it.
return 0
;;
esac
mkdir "${sourcedir}.tmp" || return 1
oldpwd="${PWD}"
cd "${sourcedir}.tmp"
Expand Down
58 changes: 58 additions & 0 deletions thirdparty/cmake_modules/koreader_external_project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,61 @@ function(external_project)
)

endfunction()

function(luarocks_external_project URL MD5)

# Arguments.
cmake_parse_arguments(
PARSE_ARGV 2
# Prefix.
""
# Options.
""
# One value keywords.
"ROCKSPEC;TREE"
# Multi-value keywords.
""
)
if(_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "unparsed arguments: ${_UNPARSED_ARGUMENTS}")
endif()
if(NOT DEFINED _TREE)
set(_TREE ${STAGING_DIR})
endif()

# Build command.
if(DEFINED _ROCKSPEC)
# Build in source tree.
set(BINARY_DIR ${SOURCE_DIR})
endif()
list(APPEND BUILD_CMD COMMAND ${STAGING_DIR}/bin/luarocks --tree ${BINARY_DIR}/dist)
if(URL MATCHES [=[/([a-z0-9_-]+)-(([0-9]+)(\.[0-9]+)*-[0-9]+)\.src\.rock$]=])
# From source rock (e.g https://luarocks.org/manifests/lunarmodules/say-1.4.1-3.src.rock).
set(NAME ${CMAKE_MATCH_1})
set(VERSION ${CMAKE_MATCH_2})
list(APPEND BUILD_CMD build ${DOWNLOAD_DIR}/${NAME}-${VERSION}.src.rock)
else()
if(NOT DEFINED _ROCKSPEC)
message(FATAL_ERROR "missing ROCKSPEC for luarocks project: ${PROJECT_NAME}")
endif()
list(APPEND BUILD_CMD make ${_ROCKSPEC})
endif()
list(APPEND BUILD_CMD --deps-mode none --force-fast --no-doc --no-manifest)

# Install command.
list(APPEND INSTALL_CMD COMMAND mkdir -p ${SPEC_ROCKS_DIR})
list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} -E copy_directory ${BINARY_DIR}/dist ${_TREE})

# External project.
external_project(
DOWNLOAD URL ${MD5} ${URL}
BUILD_COMMAND ${BUILD_CMD}
INSTALL_COMMAND ${INSTALL_CMD}
)

endfunction()

function(spec_rock)
cmake_parse_arguments(PARSE_ARGV 0 "" "" "" "")
luarocks_external_project(${_UNPARSED_ARGUMENTS} TREE ${SPEC_ROCKS_DIR})
endfunction()
26 changes: 26 additions & 0 deletions thirdparty/luarocks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build in source tree.
set(BINARY_DIR ${SOURCE_DIR})

list(APPEND CFG_CMD COMMAND
./configure
--prefix=${STAGING_DIR}
--with-lua=${STAGING_DIR}
)

list(APPEND BUILD_CMD COMMAND make)

list(APPEND INSTALL_CMD COMMAND make install)

# Try to use our compilation flags.
set(LIBFLAGS ${DYNLIB_LDFLAGS})
foreach(VAR CC CFLAGS LIBFLAGS)
list(APPEND INSTALL_CMD COMMAND ${STAGING_DIR}/bin/luarocks config -- ${VAR} "${${VAR}}")
endforeach()

external_project(
DOWNLOAD URL ab95865ced3c123908bd2f1fe6843606
https://github.com/luarocks/luarocks/archive/refs/tags/v3.11.1.tar.gz
CONFIGURE_COMMAND ${CFG_CMD}
BUILD_COMMAND ${BUILD_CMD}
INSTALL_COMMAND ${INSTALL_CMD}
)
4 changes: 4 additions & 0 deletions thirdparty/spec/busted/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/lunarmodules/busted-2.2.0-1.src.rock
85aa90d2d9d0213fcd8528bc489a3519
)
4 changes: 4 additions & 0 deletions thirdparty/spec/dkjson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/dhkolf/dkjson-2.8-1.src.rock
4d002b7591658983248f8214e9459e1d
)
5 changes: 5 additions & 0 deletions thirdparty/spec/lua-term/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spec_rock(
https://github.com/hoelzro/lua-term/archive/0.08.tar.gz
672b60c1e856129891fe29e23632c032
ROCKSPEC lua-term-0.8-1.rockspec
)
4 changes: 4 additions & 0 deletions thirdparty/spec/lua_cliargs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/lunarmodules/lua_cliargs-3.0-2.src.rock
cca85e869fac1b42252692693aed0333
)
4 changes: 4 additions & 0 deletions thirdparty/spec/luafilesystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/hisham/luafilesystem-1.8.0-1.src.rock
93bd2cbd66d6fc25ff89920ef9293c6e
)
4 changes: 4 additions & 0 deletions thirdparty/spec/luassert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/lunarmodules/luassert-1.9.0-1.src.rock
0df52010a5a5f728da0b9b7615a82da6
)
4 changes: 4 additions & 0 deletions thirdparty/spec/luasystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/lunarmodules/luasystem-0.4.4-1.src.rock
608a105f844a052e0055800d80e925f8
)
5 changes: 5 additions & 0 deletions thirdparty/spec/mediator_lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spec_rock(
https://github.com/Olivine-Labs/mediator_lua/archive/v1.1.2-0.tar.gz
3ef01fc6ced99f6e4c2a229e91c459bf
ROCKSPEC mediator_lua-1.1.2-0.rockspec
)
4 changes: 4 additions & 0 deletions thirdparty/spec/penlight/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/tieske/penlight-1.14.0-2.src.rock
ab64b4b635e2514db64b4eabfd9d2220
)
4 changes: 4 additions & 0 deletions thirdparty/spec/say/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec_rock(
https://luarocks.org/manifests/lunarmodules/say-1.4.1-3.src.rock
3b776612edf1e659b2a1e95698597e44
)

0 comments on commit 1e45429

Please sign in to comment.