unittest: Move nil checks to Gcc:preprocess

This commit is contained in:
ZyX 2017-01-03 16:25:04 +03:00
parent 0d7b779cab
commit 2151ddbd73
3 changed files with 24 additions and 28 deletions

View File

@ -221,10 +221,6 @@ local function standalone(...) -- luacheck: ignore
local raw = Preprocess.preprocess('', arg[1]) local raw = Preprocess.preprocess('', arg[1])
if raw == nil then
print("ERROR: Preprocess.preprocess() returned empty")
end
local formatted local formatted
if #arg == 2 and arg[2] == 'no' then if #arg == 2 and arg[2] == 'no' then
formatted = raw formatted = raw

View File

@ -69,14 +69,7 @@ local function cimport(...)
end end
local body = nil local body = nil
for _ = 1, 10 do body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths))
body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths))
if body ~= nil then break end
end
if body == nil then
print("ERROR: helpers.lua: Preprocess.preprocess() returned empty")
end
-- format it (so that the lines are "unique" statements), also filter out -- format it (so that the lines are "unique" statements), also filter out
-- Objective-C blocks -- Objective-C blocks

View File

@ -146,6 +146,19 @@ function Gcc:dependencies(hdr)
end end
end end
local function repeated_call(cmd)
for _ = 1, 10 do
local stream = io.popen(cmd)
local ret = stream:read('*a')
stream:close()
if ret then
return ret
end
end
print('ERROR: preprocess.lua: Failed to execute ' .. cmd .. ': nil return after 10 attempts')
return nil
end
-- returns a stream representing a preprocessed form of the passed-in headers. -- returns a stream representing a preprocessed form of the passed-in headers.
-- Don't forget to close the stream by calling the close() method on it. -- Don't forget to close the stream by calling the close() method on it.
function Gcc:preprocess(previous_defines, ...) function Gcc:preprocess(previous_defines, ...)
@ -159,28 +172,22 @@ function Gcc:preprocess(previous_defines, ...)
pseudoheader_file:flush() pseudoheader_file:flush()
pseudoheader_file:close() pseudoheader_file:close()
local defines = table.concat(self.preprocessor_extra_flags, ' ') local defines = table.concat(self.preprocessor_extra_flags, ' ')
local cmd = ("echo $hdr | " .. local cmd_base = self.path .. " " .. defines .. " -std=c99"
tostring(self.path) ..
" " .. local def_cmd = (cmd_base .. " -dM -E " .. shell_quote(pseudoheader_fname))
tostring(defines) .. local defines = repeated_call(def_cmd)
" -std=c99 -P -E " .. shell_quote(pseudoheader_fname))
local def_cmd = ("echo $hdr | " ..
tostring(self.path) ..
" " ..
tostring(defines) ..
" -std=c99 -dM -E " .. shell_quote(pseudoheader_fname))
local def_stream = io.popen(def_cmd)
local defines = def_stream:read('*a')
def_stream:close()
-- lfs = require("lfs") -- lfs = require("lfs")
-- print("CWD: #{lfs.currentdir!}") -- print("CWD: #{lfs.currentdir!}")
-- print("CMD: #{cmd}") -- print("CMD: #{cmd}")
-- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CWD: #{lfs.currentdir!}\n")
-- io.stderr\write("CMD: #{cmd}\n") -- io.stderr\write("CMD: #{cmd}\n")
local stream = io.popen(cmd) local decl_cmd = (cmd_base .. " -P -E " .. shell_quote(pseudoheader_fname))
local declarations = stream:read('*a') local declarations = repeated_call(decl_cmd)
stream:close()
os.remove(pseudoheader_fname) os.remove(pseudoheader_fname)
assert(declarations and defines)
return declarations, defines return declarations, defines
end end