From 161004a02370b9f44d7cfc424c91caf23dcd006d Mon Sep 17 00:00:00 2001 From: Yaroslav Shumakov Date: Sat, 2 Apr 2022 10:53:44 +0300 Subject: [PATCH] Use cmake build instead make --- .github/workflows/publish.yml | 6 +-- .github/workflows/test_on_push.yaml | 13 ++++-- CMakeLists.txt | 63 +++++++++++++++++++++++++++++ Makefile | 29 ------------- cmake/FindTarantool.cmake | 52 ++++++++++++++++++++++++ deps.sh | 8 ++++ graphql-scm-1.rockspec | 20 ++++----- graphql/VERSION.lua.in | 3 ++ graphql/init.lua | 7 +++- test/unit/graphql_test.lua | 5 ++- 10 files changed, 156 insertions(+), 50 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 cmake/FindTarantool.cmake create mode 100755 deps.sh create mode 100644 graphql/VERSION.lua.in diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b6d2ac8..2e980ed 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,13 +16,13 @@ jobs: tarantool-version: '2.8' - run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV - - run: echo "return { VERSION = '"$TAG"-1' }" > graphql/init.lua - run: tarantoolctl rocks new_version --tag $TAG - - run: tarantoolctl rocks pack graphql-$TAG-1.rockspec + - run: tarantoolctl rocks make graphql-${{ env.TAG }}-1.rockspec + - run: tarantoolctl rocks pack graphql ${{ env.TAG }} - uses: tarantool/rocks.tarantool.org/github-action@master with: auth: ${{ secrets.ROCKS_AUTH }} files: | graphql-${{ env.TAG }}-1.rockspec - graphql-${{ env.TAG }}-1.src.rock \ No newline at end of file + graphql-${{ env.TAG }}-1.all.rock diff --git a/.github/workflows/test_on_push.yaml b/.github/workflows/test_on_push.yaml index 9f84f7b..ee2b97f 100644 --- a/.github/workflows/test_on_push.yaml +++ b/.github/workflows/test_on_push.yaml @@ -21,10 +21,17 @@ jobs: tarantool-version: ${{ matrix.tarantool-version }} - name: Install dependencies - run: make .rocks + shell: bash + run: ./deps.sh + + - name: Build + run: tarantoolctl rocks make - name: Run linter - run: make lint + run: .rocks/bin/luacheck . - name: Run tests - run: make test + run: | + rm -f tmp/luacov* + .rocks/bin/luatest --verbose --coverage --shuffle group + .rocks/bin/luacov . && grep -A999 '^Summary' tmp/luacov.report.out diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..754a2c1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) + +project(graphql C) + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) + +# Find Tarantool and Lua dependencies +set(TARANTOOL_FIND_REQUIRED ON) +find_package(Tarantool) +include_directories(${TARANTOOL_INCLUDE_DIRS}) + +file(GLOB_RECURSE LUA_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/graphql/*.lua" +) + + +## VERSION #################################################################### +############################################################################### + +execute_process( + COMMAND git describe --tags --always + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE GIT_DESCRIBE + ERROR_QUIET +) + +if (NOT GIT_DESCRIBE) + set(GIT_DESCRIBE "unknown") +endif() + +configure_file ( + "${PROJECT_SOURCE_DIR}/graphql/VERSION.lua.in" + "${CMAKE_CURRENT_BINARY_DIR}/graphql/VERSION.lua" +) + + +## Testing #################################################################### +############################################################################### + +enable_testing() + +add_test( + NAME lint + COMMAND luacheck . + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +## Install #################################################################### +############################################################################### + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME} + DESTINATION ${TARANTOOL_INSTALL_LUADIR} + PATTERN "*.in" EXCLUDE +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/graphql/VERSION.lua + DESTINATION ${TARANTOOL_INSTALL_LUADIR}/${PROJECT_NAME}/ +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 5422048..0000000 --- a/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -SHELL := /bin/bash - -.PHONY: .rocks -.rocks: graphql-scm-1.rockspec Makefile - tarantoolctl rocks make - tarantoolctl rocks install luatest 0.5.5 - tarantoolctl rocks install luacov 0.13.0 - tarantoolctl rocks install luacheck 0.26.0 - -.PHONY: lint -lint: - if [ ! -d ".rocks" ]; then make .rocks; fi - .rocks/bin/luacheck . - -.PHONY: test -test: - if [ ! -d ".rocks" ]; then make .rocks; fi - rm -f tmp/luacov* - .rocks/bin/luatest --verbose --coverage --shuffle group - .rocks/bin/luacov . && grep -A999 '^Summary' tmp/luacov.report.out - -.PHONY: clean -clean: - rm -rf .rocks - -.PHONY: build -build: - if [ ! -d ".rocks" ]; then make .rocks; fi - tarantoolctl rocks pack graphql scm-1 diff --git a/cmake/FindTarantool.cmake b/cmake/FindTarantool.cmake new file mode 100644 index 0000000..dfe9f2d --- /dev/null +++ b/cmake/FindTarantool.cmake @@ -0,0 +1,52 @@ +# Define GNU standard installation directories +include(GNUInstallDirs) + +macro(extract_definition name output input) + string(REGEX MATCH "#define[\t ]+${name}[\t ]+\"([^\"]*)\"" + _t "${input}") + string(REGEX REPLACE "#define[\t ]+${name}[\t ]+\"(.*)\"" "\\1" + ${output} "${_t}") +endmacro() + +find_path(TARANTOOL_INCLUDE_DIR tarantool/module.h + HINTS ${TARANTOOL_DIR} ENV TARANTOOL_DIR + PATH_SUFFIXES include +) + +if(TARANTOOL_INCLUDE_DIR) + set(_config "-") + file(READ "${TARANTOOL_INCLUDE_DIR}/tarantool/module.h" _config0) + string(REPLACE "\\" "\\\\" _config ${_config0}) + unset(_config0) + extract_definition(PACKAGE_VERSION TARANTOOL_VERSION ${_config}) + extract_definition(INSTALL_PREFIX _install_prefix ${_config}) + unset(_config) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TARANTOOL + REQUIRED_VARS TARANTOOL_INCLUDE_DIR VERSION_VAR TARANTOOL_VERSION) +if(TARANTOOL_FOUND) + set(TARANTOOL_INCLUDE_DIRS "${TARANTOOL_INCLUDE_DIR}" + "${TARANTOOL_INCLUDE_DIR}/tarantool/" + CACHE PATH "Include directories for Tarantool") + set(TARANTOOL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/tarantool" + CACHE PATH "Directory for storing Lua modules written in Lua") + set(TARANTOOL_INSTALL_LUADIR "${CMAKE_INSTALL_DATADIR}/tarantool" + CACHE PATH "Directory for storing Lua modules written in C") + set(TARANTOOL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}" + CACHE PATH "Directory for storing Lua scripts") + + if (NOT TARANTOOL_FIND_QUIETLY AND NOT FIND_TARANTOOL_DETAILS) + set(FIND_TARANTOOL_DETAILS ON CACHE INTERNAL "Details about TARANTOOL") + message(STATUS "Tarantool LUADIR is ${TARANTOOL_INSTALL_LUADIR}") + message(STATUS "Tarantool LIBDIR is ${TARANTOOL_INSTALL_LIBDIR}") + message(STATUS "Tarantool BINDIR is ${TARANTOOL_INSTALL_BINDIR}") + endif () +endif() +mark_as_advanced( + TARANTOOL_INCLUDE_DIRS + TARANTOOL_INSTALL_LIBDIR + TARANTOOL_INSTALL_LUADIR + TARANTOOL_INSTALL_BINDIR +) diff --git a/deps.sh b/deps.sh new file mode 100755 index 0000000..7e47496 --- /dev/null +++ b/deps.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Call this script to install dependencies + +set -e + +tarantoolctl rocks install luatest 0.5.7 +tarantoolctl rocks install luacov 0.13.0 +tarantoolctl rocks install luacheck 0.26.0 diff --git a/graphql-scm-1.rockspec b/graphql-scm-1.rockspec index 4e6cec9..f942cc4 100644 --- a/graphql-scm-1.rockspec +++ b/graphql-scm-1.rockspec @@ -18,17 +18,11 @@ dependencies = { } build = { - type = 'builtin', - modules = { - ['graphql.execute'] = 'graphql/execute.lua', - ['graphql.introspection'] = 'graphql/introspection.lua', - ['graphql.parse'] = 'graphql/parse.lua', - ['graphql.query_util'] = 'graphql/query_util.lua', - ['graphql.rules'] = 'graphql/rules.lua', - ['graphql.schema'] = 'graphql/schema.lua', - ['graphql.types'] = 'graphql/types.lua', - ['graphql.util'] = 'graphql/util.lua', - ['graphql.validate'] = 'graphql/validate.lua', - ['graphql.validate_variables'] = 'graphql/validate_variables.lua', - } + type = 'cmake', + variables = { + TARANTOOL_DIR = '$(TARANTOOL_DIR)', + TARANTOOL_INSTALL_LIBDIR = '$(LIBDIR)', + TARANTOOL_INSTALL_LUADIR = '$(LUADIR)', + TARANTOOL_INSTALL_BINDIR = '$(BINDIR)', + } } diff --git a/graphql/VERSION.lua.in b/graphql/VERSION.lua.in new file mode 100644 index 0000000..9baca9a --- /dev/null +++ b/graphql/VERSION.lua.in @@ -0,0 +1,3 @@ +#!/usr/bin/env tarantool + +return "@GIT_DESCRIBE@" diff --git a/graphql/init.lua b/graphql/init.lua index 1a82ec2..2269bd1 100644 --- a/graphql/init.lua +++ b/graphql/init.lua @@ -1 +1,6 @@ -return { VERSION = 'scm-1' } \ No newline at end of file +local ok, VERSION = pcall(require, 'graphql.VERSION') +if not ok then + VERSION = 'unknown' +end + +return { VERSION = VERSION } diff --git a/test/unit/graphql_test.lua b/test/unit/graphql_test.lua index 6ba0b15..61f72b7 100644 --- a/test/unit/graphql_test.lua +++ b/test/unit/graphql_test.lua @@ -1090,5 +1090,8 @@ function g.test_util_find_by_name() end g.test_version = function() - t.assert_equals(require('graphql').VERSION, 'scm-1') + local handle = io.popen('git describe --tags --always') + local version = handle:read("*a"):gsub('\n*', '') + handle:close() + t.assert_equals(require('graphql').VERSION, version) end