Here are a few patches I applied to get the Lua bindings to build correctly with different versions of Lua. I am not particularly happy with generating all the test scripts just for the shebang line. Since it has been a while since I had to edit autoconf/automake, this was the best I could come up with. Cheers, -Hilko
Hilko Bengen
2012-Dec-13 19:44 UTC
[Libguestfs] [PATCH 1/3] Use pkg-config to determine Lua version, parameters
--- configure.ac | 19 +++++++++++-------- lua/Makefile.am | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 691f7a5..0d8a081 100644 --- a/configure.ac +++ b/configure.ac @@ -1259,26 +1259,29 @@ fi AM_CONDITIONAL([HAVE_ERLANG], [test "x$ERLANG" != "xno" && test "x$ERLC" != "xno"]) dnl Lua -LUA=no AC_ARG_ENABLE([lua], AS_HELP_STRING([--disable-lua], [disable Lua language bindings]), [], [enable_lua=yes]) AS_IF([test "x$enable_lua" != "xno"],[ - LUA AC_CHECK_PROG([LUA],[lua],[lua],[no]) - AC_CHECK_HEADER([lua.h],[have_lua_h=yes]) - AC_CHECK_HEADER([lauxlib.h],[have_lauxlib_h=yes]) - AC_CHECK_LIB([lua],[lua_checkstack],[have_lua_lib=yes]) - AS_IF([test "x$LUA" != "xno"],[ AC_MSG_CHECKING([for Lua version]) LUA_VERSION=`$LUA -e 'print(_VERSION)' | awk '{print $2}'` AC_MSG_RESULT([$LUA_VERSION]) - AC_SUBST([LUA_VERSION]) + PKG_CHECK_MODULES([LUA], [lua$LUA_VERSION], + [ + AC_SUBST([LUA_CFLAGS]) + AC_SUBST([LUA_LIBS]) + AC_SUBST([LUA_VERSION]) + AC_DEFINE([HAVE_LUA],[1],[Lua library found at compile time]) + ], + [AC_MSG_WARN([pkg-info for lua$LUA_VERSION not found])] + ) ]) ]) -AM_CONDITIONAL([HAVE_LUA], [test "x$LUA" != "xno" && test "x$have_lua_h" = "xyes" && test "x$have_lauxlib_h" = "xyes" && test "x$have_lua_lib" = "xyes"]) +AM_CONDITIONAL([HAVE_LUA], + [test "x$LUA_LIBS" != "x"]) dnl Check for Perl modules needed by Perl virt tools (virt-df, etc.) AS_IF([test "x$PERL" != "xno"], diff --git a/lua/Makefile.am b/lua/Makefile.am index be78c6a..9b0f7de 100644 --- a/lua/Makefile.am +++ b/lua/Makefile.am @@ -40,7 +40,8 @@ libluaguestfs_la_SOURCES = lua-guestfs.c libluaguestfs_la_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - -I$(top_srcdir)/src -I$(top_builddir)/src + -I$(top_srcdir)/src -I$(top_builddir)/src \ + $(LUA_CFLAGS) libluaguestfs_la_LIBADD = $(top_builddir)/src/libguestfs.la libluaguestfs_la_LDFLAGS = -avoid-version -shared -- 1.7.10.4
Hilko Bengen
2012-Dec-13 19:44 UTC
[Libguestfs] [PATCH 2/3] Use LUA variable to determine with which Lua version the tests are run
--- lua/run-bindtests | 4 ++- lua/tests/010-load.lua | 19 ----------- lua/tests/010-load.lua.in | 19 +++++++++++ lua/tests/015-globals.lua | 26 --------------- lua/tests/015-globals.lua.in | 26 +++++++++++++++ lua/tests/020-create.lua | 21 ------------ lua/tests/020-create.lua.in | 21 ++++++++++++ lua/tests/025-create-flags.lua | 21 ------------ lua/tests/025-create-flags.lua.in | 21 ++++++++++++ lua/tests/027-create-multiple.lua | 32 ------------------ lua/tests/027-create-multiple.lua.in | 32 ++++++++++++++++++ lua/tests/030-config.lua | 40 ---------------------- lua/tests/030-config.lua.in | 40 ++++++++++++++++++++++ lua/tests/050-lvcreate.lua | 46 ------------------------- lua/tests/050-lvcreate.lua.in | 46 +++++++++++++++++++++++++ lua/tests/060-readdir.lua | 61 ---------------------------------- lua/tests/060-readdir.lua.in | 61 ++++++++++++++++++++++++++++++++++ lua/tests/070-optargs.lua | 25 -------------- lua/tests/070-optargs.lua.in | 25 ++++++++++++++ lua/tests/400-events.lua | 53 ----------------------------- lua/tests/400-events.lua.in | 53 +++++++++++++++++++++++++++++ lua/tests/400-progress.lua | 44 ------------------------ lua/tests/400-progress.lua.in | 44 ++++++++++++++++++++++++ lua/tests/900-errors.lua | 37 --------------------- lua/tests/900-errors.lua.in | 37 +++++++++++++++++++++ run.in | 1 + 26 files changed, 429 insertions(+), 426 deletions(-) delete mode 100755 lua/tests/010-load.lua create mode 100755 lua/tests/010-load.lua.in delete mode 100755 lua/tests/015-globals.lua create mode 100755 lua/tests/015-globals.lua.in delete mode 100755 lua/tests/020-create.lua create mode 100755 lua/tests/020-create.lua.in delete mode 100755 lua/tests/025-create-flags.lua create mode 100755 lua/tests/025-create-flags.lua.in delete mode 100755 lua/tests/027-create-multiple.lua create mode 100755 lua/tests/027-create-multiple.lua.in delete mode 100755 lua/tests/030-config.lua create mode 100755 lua/tests/030-config.lua.in delete mode 100755 lua/tests/050-lvcreate.lua create mode 100755 lua/tests/050-lvcreate.lua.in delete mode 100755 lua/tests/060-readdir.lua create mode 100755 lua/tests/060-readdir.lua.in delete mode 100755 lua/tests/070-optargs.lua create mode 100755 lua/tests/070-optargs.lua.in delete mode 100755 lua/tests/400-events.lua create mode 100755 lua/tests/400-events.lua.in delete mode 100755 lua/tests/400-progress.lua create mode 100755 lua/tests/400-progress.lua.in delete mode 100755 lua/tests/900-errors.lua create mode 100755 lua/tests/900-errors.lua.in diff --git a/lua/run-bindtests b/lua/run-bindtests index 170e45b..fd2e67f 100755 --- a/lua/run-bindtests +++ b/lua/run-bindtests @@ -16,5 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -lua bindtests.lua > bindtests.tmp +set -e + +$LUA $srcdir/bindtests.lua > bindtests.tmp diff -u $srcdir/../bindtests bindtests.tmp diff --git a/lua/tests/010-load.lua b/lua/tests/010-load.lua deleted file mode 100755 index 4443e32..0000000 --- a/lua/tests/010-load.lua +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -require "guestfs" diff --git a/lua/tests/010-load.lua.in b/lua/tests/010-load.lua.in new file mode 100755 index 0000000..3e7dfcc --- /dev/null +++ b/lua/tests/010-load.lua.in @@ -0,0 +1,19 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +require "guestfs" diff --git a/lua/tests/015-globals.lua b/lua/tests/015-globals.lua deleted file mode 100755 index 9733ef5..0000000 --- a/lua/tests/015-globals.lua +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -assert (G._COPYRIGHT) -print ("_COPYRIGHT = ", G._COPYRIGHT) -assert (G._DESCRIPTION) -print ("_DESCRIPTION = ", G._DESCRIPTION) -assert (G._VERSION) -print ("_VERSION = ", G._VERSION) diff --git a/lua/tests/015-globals.lua.in b/lua/tests/015-globals.lua.in new file mode 100755 index 0000000..9d056c2 --- /dev/null +++ b/lua/tests/015-globals.lua.in @@ -0,0 +1,26 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +assert (G._COPYRIGHT) +print ("_COPYRIGHT = ", G._COPYRIGHT) +assert (G._DESCRIPTION) +print ("_DESCRIPTION = ", G._DESCRIPTION) +assert (G._VERSION) +print ("_VERSION = ", G._VERSION) diff --git a/lua/tests/020-create.lua b/lua/tests/020-create.lua deleted file mode 100755 index b7e748d..0000000 --- a/lua/tests/020-create.lua +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () diff --git a/lua/tests/020-create.lua.in b/lua/tests/020-create.lua.in new file mode 100755 index 0000000..7940177 --- /dev/null +++ b/lua/tests/020-create.lua.in @@ -0,0 +1,21 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () diff --git a/lua/tests/025-create-flags.lua b/lua/tests/025-create-flags.lua deleted file mode 100755 index 08865c7..0000000 --- a/lua/tests/025-create-flags.lua +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create { environment = 0 } diff --git a/lua/tests/025-create-flags.lua.in b/lua/tests/025-create-flags.lua.in new file mode 100755 index 0000000..68d04eb --- /dev/null +++ b/lua/tests/025-create-flags.lua.in @@ -0,0 +1,21 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create { environment = 0 } diff --git a/lua/tests/027-create-multiple.lua b/lua/tests/027-create-multiple.lua deleted file mode 100755 index a3f8c8c..0000000 --- a/lua/tests/027-create-multiple.lua +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g1 = G.create () -local g2 = G.create () -local g3 = G.create () - --- Check that each handle is independent. -g1:set_path ("1") -g2:set_path ("2") -g3:set_path ("3") - -assert (g1:get_path () == "1", "incorrect path in g1, expected '1'") -assert (g2:get_path () == "2", "incorrect path in g2, expected '2'") -assert (g3:get_path () == "3", "incorrect path in g3, expected '3'") diff --git a/lua/tests/027-create-multiple.lua.in b/lua/tests/027-create-multiple.lua.in new file mode 100755 index 0000000..b11bdd9 --- /dev/null +++ b/lua/tests/027-create-multiple.lua.in @@ -0,0 +1,32 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g1 = G.create () +local g2 = G.create () +local g3 = G.create () + +-- Check that each handle is independent. +g1:set_path ("1") +g2:set_path ("2") +g3:set_path ("3") + +assert (g1:get_path () == "1", "incorrect path in g1, expected '1'") +assert (g2:get_path () == "2", "incorrect path in g2, expected '2'") +assert (g3:get_path () == "3", "incorrect path in g3, expected '3'") diff --git a/lua/tests/030-config.lua b/lua/tests/030-config.lua deleted file mode 100755 index d70528c..0000000 --- a/lua/tests/030-config.lua +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -local verbose = g:get_verbose () -g:set_verbose (true) -g:set_verbose (verbose) - -g:set_autosync (false) -g:set_autosync (true) - -g:set_path (".") -assert (g:get_path () == ".") - -g:add_drive ("/dev/null") - -local version = g:version () -for k,v in pairs (version) do - print(k,v) -end - -g:close () diff --git a/lua/tests/030-config.lua.in b/lua/tests/030-config.lua.in new file mode 100755 index 0000000..7ff5b4f --- /dev/null +++ b/lua/tests/030-config.lua.in @@ -0,0 +1,40 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +local verbose = g:get_verbose () +g:set_verbose (true) +g:set_verbose (verbose) + +g:set_autosync (false) +g:set_autosync (true) + +g:set_path (".") +assert (g:get_path () == ".") + +g:add_drive ("/dev/null") + +local version = g:version () +for k,v in pairs (version) do + print(k,v) +end + +g:close () diff --git a/lua/tests/050-lvcreate.lua b/lua/tests/050-lvcreate.lua deleted file mode 100755 index 9fd5bec..0000000 --- a/lua/tests/050-lvcreate.lua +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -file = io.open ("test.img", "w") -file:seek ("set", 500 * 1024 * 1024) -file:write (' ') -file:close () - -g:add_drive ("test.img") - -g:launch () - -g:pvcreate ("/dev/sda") -g:vgcreate ("VG", {"/dev/sda"}) -g:lvcreate ("LV1", "VG", 200) -g:lvcreate ("LV2", "VG", 200) - -local lvs = g:lvs () -assert (table.getn (lvs) == 2 and - lvs[1] == "/dev/VG/LV1" and lvs[2] == "/dev/VG/LV2", - "g:lvs returned incorrect result") - -g:shutdown () - -g:close () - -os.remove ("test.img") diff --git a/lua/tests/050-lvcreate.lua.in b/lua/tests/050-lvcreate.lua.in new file mode 100755 index 0000000..8cc9541 --- /dev/null +++ b/lua/tests/050-lvcreate.lua.in @@ -0,0 +1,46 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +file = io.open ("test.img", "w") +file:seek ("set", 500 * 1024 * 1024) +file:write (' ') +file:close () + +g:add_drive ("test.img") + +g:launch () + +g:pvcreate ("/dev/sda") +g:vgcreate ("VG", {"/dev/sda"}) +g:lvcreate ("LV1", "VG", 200) +g:lvcreate ("LV2", "VG", 200) + +local lvs = g:lvs () +assert (table.getn (lvs) == 2 and + lvs[1] == "/dev/VG/LV1" and lvs[2] == "/dev/VG/LV2", + "g:lvs returned incorrect result") + +g:shutdown () + +g:close () + +os.remove ("test.img") diff --git a/lua/tests/060-readdir.lua b/lua/tests/060-readdir.lua deleted file mode 100755 index b148137..0000000 --- a/lua/tests/060-readdir.lua +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -file = io.open ("test.img", "w") -file:seek ("set", 10 * 1024 * 1024) -file:write (' ') -file:close () - -g:add_drive ("test.img") - -g:launch () - -g:part_disk ("/dev/sda", "mbr") -g:mkfs ("ext2", "/dev/sda1") -g:mount ("/dev/sda1", "/") -g:mkdir ("/p") -g:touch ("/q") - -local dirs = g:readdir ("/") - -function print_dirs(dirs) - for i,dentry in ipairs (dirs) do - for k,v in pairs (dentry) do - print(i, k, v) - end - end -end - -print_dirs (dirs) -table.sort (dirs, function (a,b) return a["name"] < b["name"] end) -print_dirs (dirs) - --- Slots 1, 2, 3 contain "." and ".." and "lost+found" respectively. - -assert (dirs[4]["name"] == "p", "incorrect name in slot 4") -assert (dirs[5]["name"] == "q", "incorrect name in slot 5") - -g:shutdown () - -g:close () - -os.remove ("test.img") diff --git a/lua/tests/060-readdir.lua.in b/lua/tests/060-readdir.lua.in new file mode 100755 index 0000000..fed485d --- /dev/null +++ b/lua/tests/060-readdir.lua.in @@ -0,0 +1,61 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +file = io.open ("test.img", "w") +file:seek ("set", 10 * 1024 * 1024) +file:write (' ') +file:close () + +g:add_drive ("test.img") + +g:launch () + +g:part_disk ("/dev/sda", "mbr") +g:mkfs ("ext2", "/dev/sda1") +g:mount ("/dev/sda1", "/") +g:mkdir ("/p") +g:touch ("/q") + +local dirs = g:readdir ("/") + +function print_dirs(dirs) + for i,dentry in ipairs (dirs) do + for k,v in pairs (dentry) do + print(i, k, v) + end + end +end + +print_dirs (dirs) +table.sort (dirs, function (a,b) return a["name"] < b["name"] end) +print_dirs (dirs) + +-- Slots 1, 2, 3 contain "." and ".." and "lost+found" respectively. + +assert (dirs[4]["name"] == "p", "incorrect name in slot 4") +assert (dirs[5]["name"] == "q", "incorrect name in slot 5") + +g:shutdown () + +g:close () + +os.remove ("test.img") diff --git a/lua/tests/070-optargs.lua b/lua/tests/070-optargs.lua deleted file mode 100755 index 00559a1..0000000 --- a/lua/tests/070-optargs.lua +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -g:add_drive ("/dev/null") -g:add_drive ("/dev/null", { readonly = true }) -g:add_drive ("/dev/null", { format = "raw", readonly = false }) diff --git a/lua/tests/070-optargs.lua.in b/lua/tests/070-optargs.lua.in new file mode 100755 index 0000000..543e517 --- /dev/null +++ b/lua/tests/070-optargs.lua.in @@ -0,0 +1,25 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +g:add_drive ("/dev/null") +g:add_drive ("/dev/null", { readonly = true }) +g:add_drive ("/dev/null", { format = "raw", readonly = false }) diff --git a/lua/tests/400-events.lua b/lua/tests/400-events.lua deleted file mode 100755 index c17bdc2..0000000 --- a/lua/tests/400-events.lua +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -for i, v in ipairs (G.event_all) do - print (i, v) -end - -local g = G.create () - -function log_callback (g, event, eh, flags, buf, array) - io.write (string.format ("lua event logged: event=%s eh=%d buf='%s'\n", - event, eh, buf)) -end - -close_invoked = 0 -function close_callback (g, event, eh, flags, buf, array) - close_invoked = close_invoked+1 - log_callback (g, event, eh, flags, buf, array) -end - --- Register an event callback for all log messages. -g:set_event_callback (log_callback, { "appliance", "library", "trace" }) - --- Register an event callback for the close event. -g:set_event_callback (close_callback, "close") - --- Make sure we see some messages. -g:set_trace (true) -g:set_verbose (true) - --- Do some stuff. -g:add_drive_ro ("/dev/null") - --- Close the handle. The close callback should be invoked. -g:close () -assert (close_invoked == 1, "close callback was not invoked") diff --git a/lua/tests/400-events.lua.in b/lua/tests/400-events.lua.in new file mode 100755 index 0000000..8693f24 --- /dev/null +++ b/lua/tests/400-events.lua.in @@ -0,0 +1,53 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +for i, v in ipairs (G.event_all) do + print (i, v) +end + +local g = G.create () + +function log_callback (g, event, eh, flags, buf, array) + io.write (string.format ("lua event logged: event=%s eh=%d buf='%s'\n", + event, eh, buf)) +end + +close_invoked = 0 +function close_callback (g, event, eh, flags, buf, array) + close_invoked = close_invoked+1 + log_callback (g, event, eh, flags, buf, array) +end + +-- Register an event callback for all log messages. +g:set_event_callback (log_callback, { "appliance", "library", "trace" }) + +-- Register an event callback for the close event. +g:set_event_callback (close_callback, "close") + +-- Make sure we see some messages. +g:set_trace (true) +g:set_verbose (true) + +-- Do some stuff. +g:add_drive_ro ("/dev/null") + +-- Close the handle. The close callback should be invoked. +g:close () +assert (close_invoked == 1, "close callback was not invoked") diff --git a/lua/tests/400-progress.lua b/lua/tests/400-progress.lua deleted file mode 100755 index 293a463..0000000 --- a/lua/tests/400-progress.lua +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -g:add_drive ("/dev/null") -g:launch () - -calls = 0 -function cb () - calls = calls+1 -end - -eh = g:set_event_callback (cb, "progress") -assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") -assert (calls > 0, "progress callback was not invoked") - -calls = 0 -g:delete_event_callback (eh) -assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") -assert (calls == 0, "progress callback was invoked when deleted") - -g:set_event_callback (cb, "progress") -assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") -assert (calls > 0, "progress callback was not invoked") - -g:close () diff --git a/lua/tests/400-progress.lua.in b/lua/tests/400-progress.lua.in new file mode 100755 index 0000000..1f5031e --- /dev/null +++ b/lua/tests/400-progress.lua.in @@ -0,0 +1,44 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +g:add_drive ("/dev/null") +g:launch () + +calls = 0 +function cb () + calls = calls+1 +end + +eh = g:set_event_callback (cb, "progress") +assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") +assert (calls > 0, "progress callback was not invoked") + +calls = 0 +g:delete_event_callback (eh) +assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") +assert (calls == 0, "progress callback was invoked when deleted") + +g:set_event_callback (cb, "progress") +assert (g:debug ("progress", {"5"}) == "ok", "debug progress command failed") +assert (calls > 0, "progress callback was not invoked") + +g:close () diff --git a/lua/tests/900-errors.lua b/lua/tests/900-errors.lua deleted file mode 100755 index c560f7f..0000000 --- a/lua/tests/900-errors.lua +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/lua --- libguestfs Lua bindings -*- lua -*- --- Copyright (C) 2012 Red Hat Inc. --- --- 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. - -local G = require "guestfs" - -local g = G.create () - -code, err = pcall (function (fn) g:add_drive (fn) end, "/NOTSUCHFILE") -assert (not code) - --- The default __tostring function will convert the error to either: --- --- "%s", msg --- or: --- "%s: %s", msg, strerror (err) --- --- We are expecting the second case here, but since the libguestfs --- code calls perrorf, the string version of ENOENT is already --- included in 'msg' and so appears twice here. -local str = tostring (err) -assert (str == "/NOTSUCHFILE: No such file or directory: No such file or directory", - string.format ("unexpected error string: %s", str)) diff --git a/lua/tests/900-errors.lua.in b/lua/tests/900-errors.lua.in new file mode 100755 index 0000000..dbf8462 --- /dev/null +++ b/lua/tests/900-errors.lua.in @@ -0,0 +1,37 @@ +#!/usr/bin/env @LUA@ +-- libguestfs Lua bindings -*- lua -*- +-- Copyright (C) 2012 Red Hat Inc. +-- +-- 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. + +local G = require "guestfs" + +local g = G.create () + +code, err = pcall (function (fn) g:add_drive (fn) end, "/NOTSUCHFILE") +assert (not code) + +-- The default __tostring function will convert the error to either: +-- +-- "%s", msg +-- or: +-- "%s: %s", msg, strerror (err) +-- +-- We are expecting the second case here, but since the libguestfs +-- code calls perrorf, the string version of ENOENT is already +-- included in 'msg' and so appears twice here. +local str = tostring (err) +assert (str == "/NOTSUCHFILE: No such file or directory: No such file or directory", + string.format ("unexpected error string: %s", str)) diff --git a/run.in b/run.in index ec0b018..9d4a6b1 100755 --- a/run.in +++ b/run.in @@ -108,6 +108,7 @@ fi export CLASSPATH # For Lua. +export LUA=@LUA@ if [ -z "$LUA_CPATH" ]; then LUA_CPATH="$b/lua/?.so" else -- 1.7.10.4
Hilko Bengen
2012-Dec-13 19:44 UTC
[Libguestfs] [PATCH 3/3] Add ifdefs for Lua 5.2 compatibility
--- generator/lua.ml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/generator/lua.ml b/generator/lua.ml index 7461cbd..3626ce8 100644 --- a/generator/lua.ml +++ b/generator/lua.ml @@ -48,6 +48,10 @@ let generate_lua_c () #include <lua.h> #include <lauxlib.h> +#if LUA_VERSION_NUM >= 502 +#define lua_objlen lua_rawlen +#endif + #include <guestfs.h> #define GUESTFS_LUA_HANDLE \"guestfs handle\" @@ -904,11 +908,19 @@ luaopen_guestfs (lua_State *L) /* Create metatable. */ luaL_newmetatable (L, GUESTFS_LUA_HANDLE); +#if LUA_VERSION_NUM >= 502 + luaL_setfuncs (L, metamethods, 0); +#else luaL_register (L, NULL, metamethods); +#endif /* Create methods table. */ lua_newtable (L); +#if LUA_VERSION_NUM >= 502 + luaL_setfuncs (L, methods, 0); +#else luaL_register (L, NULL, methods); +#endif /* Set __index field of metatable to point to methods table. */ lua_setfield (L, -2, \"__index\"); @@ -918,7 +930,11 @@ luaopen_guestfs (lua_State *L) /* Create module functions table. */ lua_newtable (L); +#if LUA_VERSION_NUM >= 502 + luaL_setfuncs (L, functions, 0); +#else luaL_register (L, NULL, functions); +#endif /* Globals in the module namespace. */ lua_pushliteral (L, \"event_all\"); -- 1.7.10.4
Seemingly Similar Threads
- [PATCH 0/8] python: PEP 8 fixes
- [PATCH 1/2] Revert "ruby: Run tests one at a time, instead of in parallel."
- [PATCH] Rust bindings: Implement Event features
- Re: [PATCH] Rust bindings: Implement Event features
- [PATCH 0/4] ocaml: Allow Guestfs.t handle to be garbage collected.