Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improved include error messages #2265

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,11 @@
local compiled_chunk
local res = os.locate(fname, with_ext, p5, p4)
if res == nil then
local caller = filelineinfo(3)
premake.error(caller .. ": Cannot find neither " .. table.implode({fname, with_ext, p5, p4}, "", "", " nor "))
premake.error("Cannot find neither " .. table.implode({fname, with_ext, p5, p4}, "", "", " nor "))
else
compiled_chunk, err = loadfile(res)
if err ~= nil then
local caller = filelineinfo(3)
premake.error(caller .. ": Error loading '" .. fname .. ": " .. err)
premake.error("Error loading '" .. fname .. ": " .. err)
end
end
return res, compiled_chunk
Expand Down
25 changes: 20 additions & 5 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,26 @@
---

function includeexternal(fname)
fname, compiled_chunk = p.findProjectScript(fname)
local wasIncludingExternal = api._isIncludingExternal
api._isIncludingExternal = true
compiled_chunk()
api._isIncludingExternal = wasIncludingExternal
local findOK, foundFnameOrErr, compiled_chunk = pcall(function () return p.findProjectScript(fname) end)
if findOK then
local wasIncludingExternal = api._isIncludingExternal
api._isIncludingExternal = true
local callOK, res = pcall(compiled_chunk)
api._isIncludingExternal = wasIncludingExternal

if callOK then
-- res is the return value of the script
return res
else
local err = res
local caller = filelineinfo(2)
premake.error(caller .. ": includeexternal(" .. fname .. ") execution error: " .. err)
end
else
local err = foundFnameOrErr
local caller = filelineinfo(2)
premake.error(caller .. ": includeexternal(" .. fname .. ") not found or failed to load: " .. err)
end
end

p.alias(_G, "includeexternal", "includeExternal")
Expand Down
29 changes: 18 additions & 11 deletions src/base/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,25 @@
io._includedFiles = {}

function include(fname)
local actualFname, compiled_chunk = premake.findProjectScript(fname)
if not io._includedFiles[actualFname] then
io._includedFiles[actualFname] = true
local success, res = pcall(compiled_chunk)
if success then
-- res is the return value of the script
return res
else
-- res is the error message
local caller = filelineinfo(2)
premake.error(caller .. ": Error executing '" .. fname .. ": " .. res)
local findOK, foundFnameOrErr, compiled_chunk = pcall(function () return premake.findProjectScript(fname) end)
if findOK then
local actualFname = foundFnameOrErr
if not io._includedFiles[actualFname] then
io._includedFiles[actualFname] = true
local callOK, res = pcall(compiled_chunk)
if callOK then
-- res is the return value of the script
return res
else
local err = res
local caller = filelineinfo(2)
premake.error(caller .. ": include(" .. fname .. ") execution error: " .. err)
end
end
else
local err = foundFnameOrErr
local caller = filelineinfo(2)
premake.error(caller .. ": include(" .. fname .. ") not found or failed to load: " .. err)
end
end

Expand Down