Fixed a bug when including the same project in multiple workspaces, when using the includeexternal API. Based on discussion in #122

This commit is contained in:
Sam Surtees 2015-08-25 23:57:05 +10:00
parent d2290fc742
commit 23d2c04e2b
4 changed files with 38 additions and 3 deletions

View File

@ -221,6 +221,20 @@
end
--
-- Finds the correct premake script filename to be run.
--
-- @param fname
-- The filename of the script to run.
-- @return
-- The correct location and filename of the script to run.
--
function premake.findProjectScript(fname)
return os.locate(fname, fname .. ".lua", path.join(fname, "premake5.lua"), path.join(fname, "premake4.lua"))
end
---
-- "Immediate If" - returns one of the two values depending on the value
-- of the provided condition. Note that both the true and false expressions

View File

@ -76,12 +76,15 @@
---
-- Register a general-purpose includeExternal() call which works just like
-- include(), but marks any containers created while evaluating the included
-- scripts as external.
-- scripts as external. It also, loads the file regardless of how many times
-- it has been loaded already.
---
function includeexternal(fname)
local fullPath = premake.findProjectScript(fname)
api._isIncludingExternal = true
include(fname)
fname = fullPath or fname
dofile(fname)
api._isIncludingExternal = nil
end

View File

@ -48,7 +48,7 @@
io._includedFiles = {}
function include(fname)
local fullPath = os.locate(fname, fname .. ".lua", path.join(fname, "premake5.lua"), path.join(fname, "premake4.lua"))
local fullPath = premake.findProjectScript(fname)
fname = fullPath or fname
if not io._includedFiles[fname] then
io._includedFiles[fname] = true

View File

@ -46,3 +46,21 @@
include (_TESTS_DIR .. "/../tests/folder/premake5.lua")
test.isequal("ok", premake.captured())
end
function suite.includeexternal_runs()
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("ok", premake.captured())
end
function suite.includeexternal_runsAfterInclude()
include (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("okok", premake.captured())
end
function suite.includeexternal_runsTwiceAfterInclude()
include (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("okokok", premake.captured())
end