Skip to content

Show error messages from broken includes #2264

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

Merged
Merged
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
14 changes: 10 additions & 4 deletions src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@
local p5 = path.join(fname, "premake5.lua")
local p4 = path.join(fname, "premake4.lua")

local compiled_chunk
local res = os.locate(fname, with_ext, p5, p4)
res = res or fname
local compiled_chunk = loadfile(res)
if compiled_chunk == nil then
premake.error("Cannot find either " .. table.implode({fname, with_ext, p5, p4}, "", "", " or "))
if res == nil then
local caller = filelineinfo(3)
premake.error(caller .. ": 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)
end
end
return res, compiled_chunk
end
Expand Down
16 changes: 12 additions & 4 deletions src/base/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@
io._includedFiles = {}

function include(fname)
fname, compiled_chunk = premake.findProjectScript(fname)
if not io._includedFiles[fname] then
io._includedFiles[fname] = true
return compiled_chunk()
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)
end
end
end

Expand Down