Port lgi-check.sh to C

Previously, the lgi check used the normal Lua interpreter to check if
lgi is installed. However, nothing ensures/requires that awesome is
built against the same Lua version as the Lua interpreter. This means
that if lgi is only available for some Lua version, then the check could
succeed even though awesome would later fail to start. Also, the check
might have failed even though awesome would not have any problems
finding lgi.

This commit replaces lgi-check.sh by a small C program which does the
same thing. This ensures that the same Lua version is used as awesome
will be using.

There are some places that still use the Lua interpreter: Example tests
(run through the Lua interpreter directly) and unit tests (run through
busted). For unit tests, this should not make much of a difference and
example tests might later get similar treatment.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-06-13 15:02:55 +02:00
parent 93d5007c20
commit ddc51cf38c
5 changed files with 75 additions and 43 deletions

View File

@ -147,10 +147,6 @@ target_link_libraries(${PROJECT_AWE_NAME}
${AWESOME_REQUIRED_LDFLAGS}
${AWESOME_OPTIONAL_LDFLAGS})
# check for lgi and the needed gobject introspection files
add_custom_target(lgi-check ALL
COMMAND ${SOURCE_DIR}/build-utils/lgi-check.sh)
# {{{ Generated sources
# atoms
file(MAKE_DIRECTORY ${BUILD_DIR}/common)

View File

@ -351,6 +351,16 @@ endif()
#}}}
# {{{ Check for LGI
add_executable(lgi-check build-utils/lgi-check.c)
target_link_libraries(lgi-check ${LUA_LIBRARIES})
target_include_directories(lgi-check PRIVATE ${LUA_INCLUDE_DIR})
add_custom_target(lgi-check-run ALL
COMMAND lgi-check
DEPENDS lgi-check
COMMENT "Checking for LGI...")
# }}}
# {{{ Generate some aggregated documentation from lua script
file(MAKE_DIRECTORY ${BUILD_DIR}/script_files/)
@ -359,7 +369,7 @@ add_custom_command(
OUTPUT ${BUILD_DIR}/docs/06-appearance.md
COMMAND lua ${SOURCE_DIR}/docs/06-appearance.md.lua
${BUILD_DIR}/docs/06-appearance.md
DEPENDS lgi-check
DEPENDS lgi-check-run
)
add_custom_command(

63
build-utils/lgi-check.c Normal file
View File

@ -0,0 +1,63 @@
/*
* lgi-check.c - Check that LGI is available
*
* Copyright © 2017 Uli Schlachter <psychon@znc.in>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>
#include <stdlib.h>
const char commands[] =
"print(string.format('Building for %s.', jit and jit.version or _VERSION))\n"
"local lgi_version = require('lgi.version')\n"
"print(string.format('Found lgi %s.', lgi_version))\n"
"_, _, major_minor, patch = string.find(lgi_version, '^(%d%.%d)%.(%d)')\n"
"if tonumber(major_minor) < 0.8 or (tonumber(major_minor) == 0.8 and tonumber(patch) < 0) then\n"
" error(string.format('lgi is too old, need at least version %s, got %s.',\n"
" '0.8.0', require('lgi.version')))\n"
"end\n"
"lgi = require('lgi')\n"
"assert(lgi.cairo, lgi.Pango, lgi.PangoCairo, lgi.GLib, lgi.Gio)\n"
;
int main()
{
int result = 0;
const char *env = "AWESOME_IGNORE_LGI";
lua_State *L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dostring(L, commands))
{
fprintf(stderr, "Error: %s\n",
lua_tostring(L, -1));
fprintf(stderr, "\n\n WARNING\n =======\n\n"
" The lgi check failed.\n"
" Awesome needs lgi to run.\n"
" Add %s=1 to your environment to continue.\n\n\n",
env);
if (getenv(env) == NULL)
result = 1;
}
lua_close(L);
return result;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,37 +0,0 @@
#!/bin/sh
die()
{
exec >&2
echo
echo
echo " WARNING"
echo " ======="
echo
echo " The lgi check failed."
echo " The Lua GObject introspection package is just a runtime dependency, so it is not"
echo " necessary for building awesome. However, awesome needs it to run."
echo " Add AWESOME_IGNORE_LGI=1 to your environment to continue."
echo
echo
if [ "x$AWESOME_IGNORE_LGI" = "x1" ]
then
exit 0
fi
exit 1
}
# Check if we have lgi
lua -e 'require("lgi")' || die
# Check the version number.
# Keep this in sync with lib/gears/surface.lua and .travis.yml (LGIVER)!
lua -e '_, _, major_minor, patch = string.find(require("lgi.version"), "^(%d%.%d)%.(%d)");
if tonumber(major_minor) < 0.8 or (tonumber(major_minor) == 0.8 and tonumber(patch) < 0) then
error(string.format("lgi is too old, need at least version %s, got %s.",
"0.8.0", require("lgi.version"))) end' || die
# Check for the needed gi files
lua -e 'l = require("lgi") assert(l.cairo, l.Pango, l.PangoCairo, l.GLib, l.Gio)' || die
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -12,7 +12,7 @@ local color = nil
local gdebug = require("gears.debug")
local hierarchy = require("wibox.hierarchy")
-- Keep this in sync with build-utils/lgi-check.sh!
-- Keep this in sync with build-utils/lgi-check.c!
local ver_major, ver_minor, ver_patch = string.match(require('lgi.version'), '(%d)%.(%d)%.(%d)')
if tonumber(ver_major) <= 0 and (tonumber(ver_minor) < 8 or (tonumber(ver_minor) == 8 and tonumber(ver_patch) < 0)) then
error("lgi too old, need at least version 0.8.0")