diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index 130be76ba..8def17f6d 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -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 diff --git a/src/base/api.lua b/src/base/api.lua index 9fac4ec04..01d82d2b9 100755 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -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") diff --git a/src/base/globals.lua b/src/base/globals.lua index d46ca00b6..a4b813ab2 100644 --- a/src/base/globals.lua +++ b/src/base/globals.lua @@ -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