Skip to content

Use cmake build instead builtin #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
graphql-${{ env.TAG }}-1.all.rock
13 changes: 10 additions & 3 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}/
)
29 changes: 0 additions & 29 deletions Makefile

This file was deleted.

52 changes: 52 additions & 0 deletions cmake/FindTarantool.cmake
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions deps.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 7 additions & 13 deletions graphql-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
}
}
3 changes: 3 additions & 0 deletions graphql/VERSION.lua.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env tarantool

return "@GIT_DESCRIBE@"
7 changes: 6 additions & 1 deletion graphql/init.lua
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
return { VERSION = 'scm-1' }
local ok, VERSION = pcall(require, 'graphql.VERSION')
if not ok then
VERSION = 'unknown'
end

return { VERSION = VERSION }
5 changes: 4 additions & 1 deletion test/unit/graphql_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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