Commit e04573b0 authored by Amadeu Andrade Barbosa Junior's avatar Amadeu Andrade Barbosa Junior
Browse files

Atualizando o assistente 'check-lib-deps' (verificação das bibliotecas

dependentes) que respeitava uma antiga organização de diretórios. 
Fiz uma refatoração mais completa para buscar bibliotecas 
dependentes a partir de uma instalação openbus 
(considera-se <installdir>/libpath/TEC_UNAME).

* installer.lua : OPENBUS-95 Integração com assistente de
verificação de libs para garantir que o pacote que está sendo 
instalado não possui problemas quanto a carga dinâmica das 
bibliotecas. A verificação é realizada sobre o pacote descompactado
do openbus, antes de prosseguir à etapa de configuração.

* platforms.lua : criando um novo campo 'dylibext' que indica a
extensão das bibliotecas dinâmicas

* util.lua : parse_args agora permite o uso com argumentos vazios.

OBS: mantive um exemplo de código no check-lib-deps para rodá-lo
independente do instalador (descomentar para usar manualmente).

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@85949 ae0415b3-e90b-0410-900d-d0be9363c56b
parent c3aa7559
-- Saving important variables from LuaVM
local package_path = package.path
local package_cpath = package.cpath
package.path = "?.lua;../?.lua;" .. package.path
require "tools.config"
local string = require "tools.split"
local platforms = require "tools.platforms"
local util = require "tools.util"
module("tools.check-lib-deps",package.seeall)
local checker = {}
-- Checks libraries dependencies in an OpenBus installation
function checker:libraries_deps(openbus_home)
assert(type(openbus_home) == "string", "ERROR: Check libraries function receives a nil parameter.")
local function rollback()
-- Recovering important variables to LuaVM
package.path = package_path
package.cpath = package_cpath
end
local msg = "[ checker:libraries_deps ] "
local libpath = openbus_home.."/libpath/"..TEC_UNAME
package.path = ""
local myplat = platforms[TEC_SYSNAME]
assert(type(myplat.dylibext) == "string", "ERROR: Missing dynamic libraries extension information on 'platforms'.")
local posix = require "posix"
print(msg.."assuming that libraries has '"..myplat.dylibext.."' extension.")
print(msg.."assuming OpenBus installation: "..openbus_home)
print(msg.."assuming additional path for libs: "..libpath)
package.cpath = package.cpath .. ";"..
-- posix module uses an unusual lua_open name!
libpath .."/libl?."..myplat.dylibext..";"..
-- others openbus libs uses lib<name>.<dylibext>
libpath .."/lib?."..myplat.dylibext..";"
assert(os.getenv("OPENBUS_HOME"), "OPENBUS_HOME env var not defined")
assert(os.getenv("TEC_SYSNAME"), "TEC_SYSNAME env var not defined")
-- trying load the posix module
local posix = require "posix"
local OPENBUS_HOME = os.getenv("OPENBUS_HOME")
-- how tecmake identifies my platform
local myplat = os.getenv("TEC_SYSNAME")
local misses = {}
local libpath_files = posix.dir(libpath)
if not libpath_files then
rollback()
return nil, {}, "ERROR: Invalid OpenBus path for your platform."
end
-- testing all dynamic library files
for _,file in ipairs(libpath_files) do
local fullname = libpath.."/"..file
if fullname:find("."..myplat.dylibext) then
--print("DEBUG: looking for "..file.." dynamic dependencies")
local miss = myplat:missing_libraries(fullname)
-- parse plat format to represent the unknown symbols
-- good for more information about the miss library
-- parse plat format to represent the unknown symbols
-- print("DEBUG: all symbols:")
-- s = platforms[myplat]:unknown_symbols(FILE)
-- print(s)
-- print("DEBUG: all unknown symbols:")
-- s = platforms[myplat]:unknown_symbols(fullname)
-- print(s)
misses = {}
libpath = posix.dir(OPENBUS_HOME.."/libpath")
for _,file in ipairs(libpath) do
if file:find(".so") then
-- check against the dynamic libraries
print("DEBUG: looking for "..file.." dynamic dependencies")
local miss = platforms[myplat]:missing_libraries(file)
if miss then
table.insert(misses,{name = file, miss = miss})
if miss then
-- second check: trying use openbus libpath (that can being installed!!)
local willbefine = myplat:search_ldlibpath(file,libpath)
if not willbefine then
table.insert(misses,{name = file, miss = miss})
end
end
end
end
-- return nil if we got misses
if #misses > 0 then
return nil, misses, "ERROR: Check if your system variable for dynamic "..
"libraries is right."
else
print(msg.."done!")
return true
end
end
print("DEBUG: missing dependencies")
for name,miss in pairs(misses) do
print(" missing for ",name)
table.foreach(miss,print)
-- SAMPLE of a main function that could receive OPENBUS_HOME by arg table
function checker:start(openbus_home)
-- Call the checker
local ok, misses, errmsg = self:libraries_deps(openbus_home)
-- Presents the results
if not ok then
for i,t in ipairs(misses) do
if #t.miss > 0 then
print(" ERROR: missing for ",t.name)
table.foreach(t.miss,print)
end
end
return nil, errmsg
else
return true, "Library dependencies check DONE."
end
end
--------------------------------------------------------------------------------
-- Main code -------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Allow be loaded from console
--~ if arg then
--~ -- Parsing arguments
--~ local arguments = util.parse_args(arg,[[
--~ --help : show this help
--~ --openbus=directory : use 'directory' as OpenBus installation ]],true)
--~ print("Searching missing dependencies...")
--~ assert(start(arguments.openbus or os.getenv("OPENBUS_HOME")))
--~ end
return checker
......@@ -177,8 +177,8 @@ if arguments.package then
extract_cmd = extract_cmd .. "tar -C ".. TMPDIR .." -x metadata.tar.gz && "
extract_cmd = extract_cmd .. "gzip -c -d ".. TMPDIR .."/metadata.tar.gz |"
extract_cmd = extract_cmd .. "tar -C ".. TMPDIR .." -x"
assert(os.execute(extract_cmd) == 0, "ERROR: '".. arguments.package ..
"' is not a valid package! Please contact the administrator!")
assert(os.execute(extract_cmd) == 0, "ERROR: '".. arguments.package .."'"..
" is not a valid package! Please contact the administrator!")
-- Unpacking the openbus-<<release>>_plat.tar.gz package
-- Grant to user's configure_action functions that could operate over an
......@@ -186,6 +186,14 @@ if arguments.package then
assert(os.execute("gzip -c -d "..arguments.package.." |tar -C ".. TMPDIR .." -x") == 0)
print(INSTALL, "Unpack DONE.")
-- Verifying the openbus libraries consistency for this system
print(INSTALL, "Searching missing dependencies...")
local libchecker = require "tools.check-lib-deps"
local ok, msg = libchecker:start(TMPDIR)
if not ok then error(msg.."\n '"..arguments.package.."'"..
" is not a valid package! Please contact the administrator!")
else print(INSTALL,msg) end
print(CONFIG, "Configuring the package based on package metadata")
-- Configure main step, using all .template of this package metadata
local files = myplat.exec(myplat.cmd.ls .. TMPDIR .."/metadata/")
......
......@@ -6,6 +6,8 @@ local print,io = print,io
module("platforms")
platforms = {
dylibext = "so",
cmd = { install = "cp -Rf ", make = "make ", mkdir = "mkdir -p ", rm = "rm -rf ", ls = "ls " },
exec = function(cmd)
local pipe = io.popen(cmd,"r")
local stdout = pipe:read("*a")
......@@ -26,16 +28,19 @@ platforms = {
end
return realpath
end,
cmd = { install = "cp -Rf ", make = "make ", mkdir = "mkdir -p ", rm = "rm -rf ", ls = "ls " },
}
platforms.Linux = {
platforms.Linux = {
dylibext = platforms.dylibext,
cmd = { install = "cp -L -Rf ", make = "make ", mkdir = "mkdir -p ", rm = "rm -rf ", ls = "ls " },
exec = platforms.exec,
unknown_symbols = function(self,file)
return self.exec("nm -f sysv -u -D ".. file .. " |awk -F'|' '/UND/ {print $1}'"):gsub("^%d*$","")
end,
search_ldlibpath = function(self,file)
return platforms:search_ldlibpath(file,"/lib:/usr/lib:/usr/local/lib:/lib32:/lib64:/usr/lib32:/usr/lib64")
search_ldlibpath = function(self,file,dir)
if dir and not dir:find(":$") then dir = dir:gsub("$",":")
else dir = "" end
local libpath = dir.."/lib:/usr/lib:/usr/local/lib:/lib32:/lib64:/usr/lib32:/usr/lib64"
return platforms:search_ldlibpath(file,libpath)
end,
-- sample ldd output on Linux:
-- linux-gate.so.1 => (0xffffe000)
......@@ -57,17 +62,25 @@ platforms.Linux = {
end
line = f()
end
return miss
if #miss == 0 then
return false
else
return miss
end
end,
}
platforms.SunOS = {
platforms.SunOS = {
dylibext = platforms.dylibext,
exec = platforms.exec,
cmd = platforms.cmd,
unknown_symbols = function(self,file)
return self.exec("nm -f sysv -u ".. file .. " |awk -F'|' '/UNDEF/ {print $8}'"):gsub("^%d*$","")
end,
search_ldlibpath = function(self,file)
return platforms:search_ldlibpath(file,"/lib:/usr/lib:/usr/sfw/lib:/usr/local/lib")
search_ldlibpath = function(self,file,dir)
if dir and not dir:find(":$") then dir = dir:gsub("$",":")
else dir = "" end
local libpath = dir.."/lib:/usr/lib:/usr/sfw/lib:/usr/local/lib"
return platforms:search_ldlibpath(file,libpath)
end,
-- sample ldd output on Solaris:
-- libcrypto.so.0.9.9 => (file not found)
......@@ -79,13 +92,17 @@ platforms.SunOS = {
missing_libraries = platforms.Linux.missing_libraries
}
platforms.IRIX = {
dylibext = platforms.dylibext,
exec = platforms.exec,
cmd = { install = "cp -Rf ", make = "gmake ", mkdir = "mkdir -p ", rm = "rm -rf ", ls = "ls "},
unknown_symbols = function(self,file)
return self.exec("nm -u ".. file .. " |awk -F'|' '/UNDEF/ {print $8}'"):gsub("^%d*$","")
end,
search_ldlibpath = function(self,file)
return platforms:search_ldlibpath(file,"/usr/lib:/usr/lib32:/usr/lib64:/usr/freeware/lib32")
search_ldlibpath = function(self,file,dir)
if dir and not dir:find(":$") then dir = dir:gsub("$",":")
else dir = "" end
local libpath = dir.."/usr/lib:/usr/lib32:/usr/lib64:/usr/freeware/lib32"
return platforms:search_ldlibpath(file,libpath)
end,
missing_libraries = function(self,file)
local str = self.exec("elfdump -Dl ".. file)
......@@ -99,17 +116,25 @@ platforms.IRIX = {
end
line = f()
end
return miss
if #miss == 0 then
return false
else
return miss
end
end,
}
platforms.Darwin = {
dylibext = "dylib",
exec = platforms.exec,
cmd = platforms.Linux.cmd,
unknown_symbols = function(self,file)
return self.exec("nm -u ".. file)
end,
search_ldlibpath = function(self,file)
return platforms:search_ldlibpath(file,"/usr/lib","DYLD_LIBRARY_PATH")
search_ldlibpath = function(self,file,dir)
if dir and not dir:find(":$") then dir = dir:gsub("$",":")
else dir = "" end
local libpath = dir.."/usr/lib"
return platforms:search_ldlibpath(file,libpath,"DYLD_LIBRARY_PATH")
end,
missing_libraries = function(self,file)
local str = self.exec("otool -L ".. file)
......@@ -130,17 +155,22 @@ platforms.Darwin = {
end
line = f()
end
return miss
if #miss == 0 then
return false
else
return miss
end
end,
}
--~ platforms.Windows = {
--~ exec = platforms.exec, -- Lua provides pipe semantic
--~ dylibext = "dll",
--~ cmd = {
--~ install = "xcopy /E /H ", -- xcopy don't copy orig dir also, only subdirs
--~ make = "nmake ",
--~ mkdir = "mkdir ",
--~ ls = "dir ",
--~ }
--~ },
--~ exec = platforms.exec, -- Lua provides pipe semantic on Windows too!
--~ }
return platforms
......@@ -96,7 +96,7 @@ function close_log()
end
-- Parsing arguments and returns a 'table[option]=value'
function parse_args(arg, usage_msg)
function parse_args(arg, usage_msg, allowempty)
assert(type(arg)=="table","ERROR: Missing arguments! This program should be loaded from console.")
local arguments = {}
local patt="%-?%-?(%w+)(=?)(.*)"
......@@ -106,7 +106,7 @@ function parse_args(arg, usage_msg)
Valid OPTIONS:
]] ..usage_msg
if not (arg[1]) then print(usage_msg) ; os.exit(1) end
if not (arg[1]) and not allowempty then print(usage_msg) ; os.exit(1) end
for i,param in ipairs(arg) do
local opt,_,value = param:match(patt)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment