From ddc51cf38c9159205132b732276c353311fb13e8 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 13 Jun 2017 15:02:55 +0200 Subject: [PATCH] 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 --- CMakeLists.txt | 4 --- awesomeConfig.cmake | 12 +++++++- build-utils/lgi-check.c | 63 ++++++++++++++++++++++++++++++++++++++++ build-utils/lgi-check.sh | 37 ----------------------- lib/gears/surface.lua | 2 +- 5 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 build-utils/lgi-check.c delete mode 100755 build-utils/lgi-check.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 916a28ac5..a3f0bfc37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index a2a9c8602..944f6f893 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -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( diff --git a/build-utils/lgi-check.c b/build-utils/lgi-check.c new file mode 100644 index 000000000..9d7a2261e --- /dev/null +++ b/build-utils/lgi-check.c @@ -0,0 +1,63 @@ +/* + * lgi-check.c - Check that LGI is available + * + * Copyright © 2017 Uli Schlachter + * + * 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 +#include +#include +#include +#include + +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 diff --git a/build-utils/lgi-check.sh b/build-utils/lgi-check.sh deleted file mode 100755 index cbc7ec2a9..000000000 --- a/build-utils/lgi-check.sh +++ /dev/null @@ -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 diff --git a/lib/gears/surface.lua b/lib/gears/surface.lua index 1edfcd19a..2f7c52cfa 100644 --- a/lib/gears/surface.lua +++ b/lib/gears/surface.lua @@ -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")