Skip to content

Commit

Permalink
Merge pull request #2066 from Jarod42/improve_include_error_message
Browse files Browse the repository at this point in the history
Improve error message of `include`
  • Loading branch information
nickclark2016 committed Aug 9, 2023
2 parents c135248 + 33e2a66 commit bcbe8ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@
--

function premake.findProjectScript(fname)
return os.locate(fname, fname .. ".lua", path.join(fname, "premake5.lua"), path.join(fname, "premake4.lua"))
local with_ext = fname .. ".lua"
local p5 = path.join(fname, "premake5.lua")
local p4 = path.join(fname, "premake4.lua")

local res = os.locate(fname, with_ext, p5, p4)
if res == nil then
premake.error("Cannot find either " .. table.implode({fname, with_ext, p5, p4}, "", "", " or "))
end
return res
end


Expand Down
3 changes: 1 addition & 2 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@
---

function includeexternal(fname)
local fullPath = p.findProjectScript(fname)
fname = p.findProjectScript(fname)
local wasIncludingExternal = api._isIncludingExternal
api._isIncludingExternal = true
fname = fullPath or fname
dofile(fname)
api._isIncludingExternal = wasIncludingExternal
end
Expand Down
3 changes: 1 addition & 2 deletions src/base/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
io._includedFiles = {}

function include(fname)
local fullPath = premake.findProjectScript(fname)
fname = fullPath or fname
fname = premake.findProjectScript(fname)
if not io._includedFiles[fname] then
io._includedFiles[fname] = true
return dofile(fname)
Expand Down

0 comments on commit bcbe8ea

Please sign in to comment.