Merge pull request #860 from LuaAndC/build-pkg-file-dereference

build-pkg: improve launching file tool
This commit is contained in:
Tony Theodore 2015-09-17 16:10:13 +10:00
commit bec5b6c734
1 changed files with 17 additions and 23 deletions

View File

@ -282,31 +282,25 @@ end
local function checkFile(file, pkg)
-- if it is PE32 file, it must have '.exe' in name
local ext = file:sub(-4):lower()
local file_type0 = trim(shell(('file %q'):format(file)))
local file_type = file_type0:match('^[^:]+: (.*)$')
if file_type then
local symlink = file_type:match('symbolic link')
if ext == '.bin' then
-- can be an executable or something else (font)
elseif ext == '.exe' then
if not file_type:match('PE32') and not symlink then
log('File %s (%s) is %q. Remove .exe',
file, pkg, file_type)
end
elseif ext == '.dll' then
if not file_type:match('PE32.*DLL') and not symlink then
log('File %s (%s) is %q. Remove .dll',
file, pkg, file_type)
end
else
if file_type:match('PE32') then
log('File %s (%s) is %q. Add exe or dll',
file, pkg, file_type)
end
local cmd = 'file --dereference --brief %q'
local file_type = trim(shell(cmd:format(file)))
if ext == '.bin' then
-- can be an executable or something else (font)
elseif ext == '.exe' then
if not file_type:match('PE32') then
log('File %s (%s) is %q. Remove .exe',
file, pkg, file_type)
end
elseif ext == '.dll' then
if not file_type:match('PE32.*DLL') then
log('File %s (%s) is %q. Remove .dll',
file, pkg, file_type)
end
else
log("Can't get type of file %s (%s). file says %q",
file, pkg, file_type0)
if file_type:match('PE32') then
log('File %s (%s) is %q. Add exe or dll',
file, pkg, file_type)
end
end
for _, t in ipairs(TARGETS) do
if t ~= target and file:match(t) then