From f73c27a7dc82fce369e4ee9df38cb3ef2793b5bf Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 7 Feb 2020 02:46:24 +0100 Subject: [PATCH] Premake: Add include guard to make sure dependencies do not include themselves in an infinite chain when two components depend on each other --- premake5.lua | 31 +++++++++++++++++++++++++++++++ src/Crypto.lua | 19 ++++++++++++------- src/Linker.lua | 9 ++++++--- src/ObjCommon.lua | 27 ++++++++++++++++----------- src/ObjLoading.lua | 33 +++++++++++++++++++-------------- src/ObjWriting.lua | 31 ++++++++++++++++++------------- src/Unlinker.lua | 9 ++++++--- src/Utils.lua | 13 +++++++++---- src/ZoneCode.lua | 11 +++++++---- src/ZoneCodeGenerator.lua | 5 ++++- src/ZoneCommon.lua | 23 +++++++++++++++-------- src/ZoneLoading.lua | 27 ++++++++++++++++----------- src/ZoneWriting.lua | 27 ++++++++++++++++----------- test/ZoneCodeGeneratorTests.lua | 5 ++++- test/ZoneCommonTests.lua | 5 ++++- thirdparty/libtomcrypt.lua | 19 ++++++++++++------- thirdparty/libtommath.lua | 13 +++++++++---- thirdparty/minilzo.lua | 13 +++++++++---- thirdparty/minizip.lua | 17 +++++++++++------ thirdparty/salsa20.lua | 13 +++++++++---- thirdparty/zlib.lua | 20 ++++++++++++-------- 21 files changed, 245 insertions(+), 125 deletions(-) diff --git a/premake5.lua b/premake5.lua index fedcb17d..e27ad52b 100644 --- a/premake5.lua +++ b/premake5.lua @@ -19,6 +19,37 @@ function TestFolder() return path.getrelative(os.getcwd(), _TestFolder) end +-- Functions for including projects +References = { + includeList = {}, + linkList = {} +} + +function References:include(name) + result = self.includeList[name] == nil + + if result then + self.includeList[name] = true + end + + return result +end + +function References:link(name) + result = self.linkList[name] == nil + + if result then + self.linkList[name] = true + end + + return result +end + +function References:reset() + self.includeList = {} + self.linkList = {} +end + -- Target Directories TargetDirectoryBin = "%{wks.location}/bin/%{cfg.buildcfg}_%{cfg.platform}" TargetDirectoryLib = "%{wks.location}/lib/%{cfg.buildcfg}_%{cfg.platform}" diff --git a/src/Crypto.lua b/src/Crypto.lua index 78495fef..7718b09d 100644 --- a/src/Crypto.lua +++ b/src/Crypto.lua @@ -1,16 +1,20 @@ Crypto = {} function Crypto:include() - includedirs { - path.join(ProjectFolder(), "Crypto") - } + if References:include("Crypto") then + includedirs { + path.join(ProjectFolder(), "Crypto") + } + end end function Crypto:link() - libtomcrypt:link() - libtommath:link() - salsa20:link() - links "Crypto" + if References:link("Crypto") then + libtomcrypt:link() + libtommath:link() + salsa20:link() + links "Crypto" + end end function Crypto:use() @@ -18,6 +22,7 @@ function Crypto:use() end function Crypto:project() + References:reset() local folder = ProjectFolder(); project "Crypto" diff --git a/src/Linker.lua b/src/Linker.lua index ab117f46..ab8999c6 100644 --- a/src/Linker.lua +++ b/src/Linker.lua @@ -1,9 +1,11 @@ Linker = {} function Linker:include() - includedirs { - path.join(ProjectFolder(), "Linker") - } + if References:include("Linker") then + includedirs { + path.join(ProjectFolder(), "Linker") + } + end end function Linker:link() @@ -15,6 +17,7 @@ function Linker:use() end function Linker:project() + References:reset() local folder = ProjectFolder(); project "Linker" diff --git a/src/ObjCommon.lua b/src/ObjCommon.lua index 93dccfea..57ba9d0b 100644 --- a/src/ObjCommon.lua +++ b/src/ObjCommon.lua @@ -1,20 +1,24 @@ ObjCommon = {} function ObjCommon:include() - ZoneCommon:include() - minizip:include() - includedirs { - path.join(ProjectFolder(), "ObjCommon") - } + if References:include("ObjCommon") then + ZoneCommon:include() + minizip:include() + includedirs { + path.join(ProjectFolder(), "ObjCommon") + } + end end function ObjCommon:link() - Utils:link() - ZoneCommon:link() - minizip:link() - links { - "ObjCommon" - } + if References:link("ObjCommon") then + Utils:link() + ZoneCommon:link() + minizip:link() + links { + "ObjCommon" + } + end end function ObjCommon:use() @@ -22,6 +26,7 @@ function ObjCommon:use() end function ObjCommon:project() + References:reset() local folder = ProjectFolder(); project "ObjCommon" diff --git a/src/ObjLoading.lua b/src/ObjLoading.lua index 69f2bf47..32301f37 100644 --- a/src/ObjLoading.lua +++ b/src/ObjLoading.lua @@ -1,23 +1,27 @@ ObjLoading = {} function ObjLoading:include() - ObjCommon:include() - ZoneCommon:include() - includedirs { - path.join(ProjectFolder(), "ObjLoading") - } + if References:include("ObjLoading") then + ObjCommon:include() + ZoneCommon:include() + includedirs { + path.join(ProjectFolder(), "ObjLoading") + } + end end function ObjLoading:link() - Utils:link() - ObjCommon:link() - ZoneCommon:link() - minilzo:link() - minizip:link() - zlib:link() - links { - "ObjLoading" - } + if References:link("ObjLoading") then + Utils:link() + ObjCommon:link() + ZoneCommon:link() + minilzo:link() + minizip:link() + zlib:link() + links { + "ObjLoading" + } + end end function ObjLoading:use() @@ -25,6 +29,7 @@ function ObjLoading:use() end function ObjLoading:project() + References:reset() local folder = ProjectFolder(); project "ObjLoading" diff --git a/src/ObjWriting.lua b/src/ObjWriting.lua index 0dc7fa73..4dfe0e99 100644 --- a/src/ObjWriting.lua +++ b/src/ObjWriting.lua @@ -1,22 +1,26 @@ ObjWriting = {} function ObjWriting:include() - ObjCommon:include() - ZoneCommon:include() - includedirs { - path.join(ProjectFolder(), "ObjWriting") - } + if References:include("ObjWriting") then + ObjCommon:include() + ZoneCommon:include() + includedirs { + path.join(ProjectFolder(), "ObjWriting") + } + end end function ObjWriting:link() - Utils:link() - ObjCommon:link() - ZoneCommon:link() - minilzo:link() - minizip:link() - links { - "ObjWriting" - } + if References:link("ObjWriting") then + Utils:link() + ObjCommon:link() + ZoneCommon:link() + minilzo:link() + minizip:link() + links { + "ObjWriting" + } + end end function ObjWriting:use() @@ -24,6 +28,7 @@ function ObjWriting:use() end function ObjWriting:project() + References:reset() local folder = ProjectFolder(); project "ObjWriting" diff --git a/src/Unlinker.lua b/src/Unlinker.lua index 9c4a9c0d..bb97a46a 100644 --- a/src/Unlinker.lua +++ b/src/Unlinker.lua @@ -1,9 +1,11 @@ Unlinker = {} function Unlinker:include() - includedirs { - path.join(ProjectFolder(), "Unlinker") - } + if References:include("Unlinker") then + includedirs { + path.join(ProjectFolder(), "Unlinker") + } + end end function Unlinker:link() @@ -15,6 +17,7 @@ function Unlinker:use() end function Unlinker:project() + References:reset() local folder = ProjectFolder(); project "Unlinker" diff --git a/src/Utils.lua b/src/Utils.lua index 92cb03d2..a0ac964b 100644 --- a/src/Utils.lua +++ b/src/Utils.lua @@ -1,13 +1,17 @@ Utils = {} function Utils:include() - includedirs { - path.join(ProjectFolder(), "Utils") - } + if References:include("Utils") then + includedirs { + path.join(ProjectFolder(), "Utils") + } + end end function Utils:link() - links "Utils" + if References:link("Utils") then + links "Utils" + end end function Utils:use() @@ -15,6 +19,7 @@ function Utils:use() end function Utils:project() + References:reset() local folder = ProjectFolder(); project "Utils" diff --git a/src/ZoneCode.lua b/src/ZoneCode.lua index a03e4185..7f6c3cbf 100644 --- a/src/ZoneCode.lua +++ b/src/ZoneCode.lua @@ -108,10 +108,12 @@ function ZoneCode:allWriteFiles() end function ZoneCode:include() - includedirs { - path.join(ProjectFolder(), "ZoneCode"), - "%{wks.location}/src/ZoneCode" - } + if References:include("ZoneCode") then + includedirs { + path.join(ProjectFolder(), "ZoneCode"), + "%{wks.location}/src/ZoneCode" + } + end end function ZoneCode:link() @@ -123,6 +125,7 @@ function ZoneCode:use() end function ZoneCode:project() + References:reset() local folder = ProjectFolder(); project "ZoneCode" diff --git a/src/ZoneCodeGenerator.lua b/src/ZoneCodeGenerator.lua index 6b35fd9d..baf5cc3c 100644 --- a/src/ZoneCodeGenerator.lua +++ b/src/ZoneCodeGenerator.lua @@ -5,7 +5,9 @@ function ZoneCodeGenerator:include() end function ZoneCodeGenerator:link() - links "ZoneCodeGenerator" + if References:link("ZoneCodeGenerator") then + links "ZoneCodeGenerator" + end end function ZoneCodeGenerator:use() @@ -13,6 +15,7 @@ function ZoneCodeGenerator:use() end function ZoneCodeGenerator:project() + References:reset() local folder = ProjectFolder(); project "ZoneCodeGenerator" diff --git a/src/ZoneCommon.lua b/src/ZoneCommon.lua index 5231d6e6..3ae750b1 100644 --- a/src/ZoneCommon.lua +++ b/src/ZoneCommon.lua @@ -1,17 +1,23 @@ ZoneCommon = {} function ZoneCommon:include() - Utils:include() - includedirs { - path.join(ProjectFolder(), "ZoneCommon") - } + if References:include("ZoneCommon") then + Utils:include() + ObjCommon:include() + includedirs { + path.join(ProjectFolder(), "ZoneCommon") + } + end end function ZoneCommon:link() - Utils:link() - links { - "ZoneCommon" - } + if References:link("ZoneCommon") then + Utils:link() + ObjCommon:link() + links { + "ZoneCommon" + } + end end function ZoneCommon:use() @@ -19,6 +25,7 @@ function ZoneCommon:use() end function ZoneCommon:project() + References:reset() local folder = ProjectFolder(); project "ZoneCommon" diff --git a/src/ZoneLoading.lua b/src/ZoneLoading.lua index e8cea1b1..dd4aa0ac 100644 --- a/src/ZoneLoading.lua +++ b/src/ZoneLoading.lua @@ -1,20 +1,24 @@ ZoneLoading = {} function ZoneLoading:include() - ZoneCommon:include() - includedirs { - path.join(ProjectFolder(), "ZoneLoading") - } + if References:include("ZoneLoading") then + ZoneCommon:include() + includedirs { + path.join(ProjectFolder(), "ZoneLoading") + } + end end function ZoneLoading:link() - Crypto:link() - Utils:link() - ZoneCommon:link() - zlib:link() - links { - "ZoneLoading" - } + if References:link("ZoneLoading") then + Crypto:link() + Utils:link() + ZoneCommon:link() + zlib:link() + links { + "ZoneLoading" + } + end end function ZoneLoading:use() @@ -22,6 +26,7 @@ function ZoneLoading:use() end function ZoneLoading:project() + References:reset() local folder = ProjectFolder(); project "ZoneLoading" diff --git a/src/ZoneWriting.lua b/src/ZoneWriting.lua index badcc466..77c6e464 100644 --- a/src/ZoneWriting.lua +++ b/src/ZoneWriting.lua @@ -1,20 +1,24 @@ ZoneWriting = {} function ZoneWriting:include() - ZoneCommon:include() - includedirs { - path.join(ProjectFolder(), "ZoneWriting") - } + if References:include("ZoneWriting") then + ZoneCommon:include() + includedirs { + path.join(ProjectFolder(), "ZoneWriting") + } + end end function ZoneWriting:link() - Crypto:link() - Utils:link() - ZoneCommon:link() - zlib:link() - links { - "ZoneWriting" - } + if References:link("ZoneWriting") then + Crypto:link() + Utils:link() + ZoneCommon:link() + zlib:link() + links { + "ZoneWriting" + } + end end function ZoneWriting:use() @@ -22,6 +26,7 @@ function ZoneWriting:use() end function ZoneWriting:project() + References:reset() local folder = ProjectFolder(); project "ZoneWriting" diff --git a/test/ZoneCodeGeneratorTests.lua b/test/ZoneCodeGeneratorTests.lua index 46f734d1..676b25ab 100644 --- a/test/ZoneCodeGeneratorTests.lua +++ b/test/ZoneCodeGeneratorTests.lua @@ -5,7 +5,9 @@ function ZoneCodeGeneratorTests:include() end function ZoneCodeGeneratorTests:link() - links "ZoneCommonTests" + if References:link("ZoneCodeGeneratorTests") then + links "ZoneCodeGeneratorTests" + end end function ZoneCodeGeneratorTests:use() @@ -13,6 +15,7 @@ function ZoneCodeGeneratorTests:use() end function ZoneCodeGeneratorTests:project() + References:reset() local folder = TestFolder(); project "ZoneCodeGeneratorTests" diff --git a/test/ZoneCommonTests.lua b/test/ZoneCommonTests.lua index 7c7eec6e..cb6c0f78 100644 --- a/test/ZoneCommonTests.lua +++ b/test/ZoneCommonTests.lua @@ -5,7 +5,9 @@ function ZoneCommonTests:include() end function ZoneCommonTests:link() - links "ZoneCommonTests" + if References:link("ZoneCommonTests") then + links "ZoneCommonTests" + end end function ZoneCommonTests:use() @@ -13,6 +15,7 @@ function ZoneCommonTests:use() end function ZoneCommonTests:project() + References:reset() local folder = TestFolder(); project "ZoneCommonTests" diff --git a/thirdparty/libtomcrypt.lua b/thirdparty/libtomcrypt.lua index 77eac0d3..749878ec 100644 --- a/thirdparty/libtomcrypt.lua +++ b/thirdparty/libtomcrypt.lua @@ -1,17 +1,21 @@ libtomcrypt = {} function libtomcrypt:include() - defines{ - "LTM_DESC" - } + if References:include("libtomcrypt") then + defines{ + "LTM_DESC" + } - includedirs { - path.join(ThirdPartyFolder(), "libtomcrypt/src/headers") - } + includedirs { + path.join(ThirdPartyFolder(), "libtomcrypt/src/headers") + } + end end function libtomcrypt:link() - links "libtomcrypt" + if References:link("libtomcrypt") then + links "libtomcrypt" + end end function libtomcrypt:use() @@ -19,6 +23,7 @@ function libtomcrypt:use() end function libtomcrypt:project() + References:reset() local folder = ThirdPartyFolder(); project "libtomcrypt" diff --git a/thirdparty/libtommath.lua b/thirdparty/libtommath.lua index 3ae0fa88..1d50d07c 100644 --- a/thirdparty/libtommath.lua +++ b/thirdparty/libtommath.lua @@ -1,13 +1,17 @@ libtommath = {} function libtommath:include() - includedirs { - path.join(ThirdPartyFolder(), "libtommath") - } + if References:include("libtommath") then + includedirs { + path.join(ThirdPartyFolder(), "libtommath") + } + end end function libtommath:link() - links "libtommath" + if References:link("libtommath") then + links "libtommath" + end end function libtommath:use() @@ -15,6 +19,7 @@ function libtommath:use() end function libtommath:project() + References:reset() local folder = ThirdPartyFolder(); project "libtommath" diff --git a/thirdparty/minilzo.lua b/thirdparty/minilzo.lua index ac758c39..2b5f434b 100644 --- a/thirdparty/minilzo.lua +++ b/thirdparty/minilzo.lua @@ -1,13 +1,17 @@ minilzo = {} function minilzo:include() - includedirs { - path.join(ThirdPartyFolder(), "minilzo") - } + if References:include("minilzo") then + includedirs { + path.join(ThirdPartyFolder(), "minilzo") + } + end end function minilzo:link() - links "minilzo" + if References:link("minilzo") then + links "minilzo" + end end function minilzo:use() @@ -15,6 +19,7 @@ function minilzo:use() end function minilzo:project() + References:reset() local folder = ThirdPartyFolder(); project "minilzo" diff --git a/thirdparty/minizip.lua b/thirdparty/minizip.lua index 104da35f..a84f9f3c 100644 --- a/thirdparty/minizip.lua +++ b/thirdparty/minizip.lua @@ -1,15 +1,19 @@ minizip = {} function minizip:include() - zlib:include() - includedirs { - path.join(ThirdPartyFolder(), "zlib/contrib/minizip") - } + if References:include("minizip") then + zlib:include() + includedirs { + path.join(ThirdPartyFolder(), "zlib/contrib/minizip") + } + end end function minizip:link() - zlib:link() - links "minizip" + if References:link("minizip") then + zlib:link() + links "minizip" + end end function minizip:use() @@ -17,6 +21,7 @@ function minizip:use() end function minizip:project() + References:reset() local folder = ThirdPartyFolder(); project "minizip" diff --git a/thirdparty/salsa20.lua b/thirdparty/salsa20.lua index d447faa0..0db3d7c2 100644 --- a/thirdparty/salsa20.lua +++ b/thirdparty/salsa20.lua @@ -1,13 +1,17 @@ salsa20 = {} function salsa20:include() - includedirs { - path.join(ThirdPartyFolder(), "salsa20") - } + if References:include("salsa20") then + includedirs { + path.join(ThirdPartyFolder(), "salsa20") + } + end end function salsa20:link() - links "salsa20" + if References:link("salsa20") then + links "salsa20" + end end function salsa20:use() @@ -15,6 +19,7 @@ function salsa20:use() end function salsa20:project() + References:reset() local folder = ThirdPartyFolder(); project "salsa20" diff --git a/thirdparty/zlib.lua b/thirdparty/zlib.lua index 64e19896..acd4fd6e 100644 --- a/thirdparty/zlib.lua +++ b/thirdparty/zlib.lua @@ -1,18 +1,21 @@ zlib = {} function zlib:include() + if References:include("zlib") then + defines { + "ZLIB_CONST" + } - defines { - "ZLIB_CONST" - } - - includedirs { - path.join(ThirdPartyFolder(), "zlib") - } + includedirs { + path.join(ThirdPartyFolder(), "zlib") + } + end end function zlib:link() - links "zlib" + if References:link("zlib") then + links "zlib" + end end function zlib:use() @@ -20,6 +23,7 @@ function zlib:use() end function zlib:project() + References:reset() local folder = ThirdPartyFolder(); project "zlib"