Skip to content

Commit

Permalink
Change cache to only work on the persisted, global dependency tables
Browse files Browse the repository at this point in the history
Using the local dependency table caused some unforseen issues when used across projects
  • Loading branch information
Foereaper committed Aug 16, 2024
1 parent c5b09a8 commit 8b0ff7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Dependencies/dxcompiler/dxcompiler.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
local dep = Solution.Util.CreateDepTable("dxcompiler", {})

Solution.Util.CreateDep(dep.Name, dep.Dependencies, function()
local cachedData = Solution.Util.GetDepCache(dep, "cache")
local cachedData = Solution.Util.GetDepCache(dep.Name, "cache")

local libPath, lib
if cachedData then
libPath, lib = cachedData.libPaths, cachedData.libs
else
libPath = iif(os.istarget("windows"), dep.Path .. "/lib/windows", dep.Path .. "/lib/linux")
lib = iif(os.istarget("windows"), libPath .. "/dxcompiler.lib", libPath .. "/dxcompiler")
Solution.Util.SetDepCache(dep, "cache", { libPaths = libPath, libs = lib })
Solution.Util.SetDepCache(dep.Name, "cache", { libPaths = libPath, libs = lib })
print(Solution.Util.GetDepCache(dep.Name, "cache"))
end

Solution.Util.SetLibDirs(libPath)
Expand Down
13 changes: 5 additions & 8 deletions Dependencies/glfw/glfw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Solution.Util.CreateStaticLib(dep.Name, Solution.Projects.Current.BinDir, dep.De
Solution.Util.SetIncludes(dep.Path)
end)

local function populateDepCache(dep)
local cachedData = Solution.Util.GetDepCache(dep, "cache")
local function populateDepCache(depName)
local cachedData = Solution.Util.GetDepCache(depName, "cache")

if not cachedData then
local def = { "GLFW_INCLUDE_VULKAN", "_CRT_SECURE_NO_WARNINGS" }
Expand All @@ -129,20 +129,17 @@ local function populateDepCache(dep)
Solution.Util.MergeIntoTable(link, { "pthread" })
end
cachedData = { defines = def, links = link }
Solution.Util.SetDepCache(dep, "cache", cachedData)
Solution.Util.SetDepCache(depName, "cache", cachedData)
end

return cachedData
end

Solution.Util.CreateDep(dep.NameLow, dep.Dependencies, function()
-- get our own internal dependency table, and not the parent one
local depTable = Solution.Util.GetDepTable(dep.NameLow)

-- get our own local cache
local cachedData = Solution.Util.GetDepCache(depTable, "cache")
local cachedData = Solution.Util.GetDepCache(dep.NameLow, "cache")
if not cachedData then
cachedData = populateDepCache(depTable)
cachedData = populateDepCache(dep.NameLow)
end

local defines, links = cachedData.defines, cachedData.links
Expand Down
4 changes: 2 additions & 2 deletions Dependencies/vulkan/vulkan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ end
local dep = Solution.Util.CreateDepTable("vulkan", {})

Solution.Util.CreateDep(dep.Name, dep.Dependencies, function()
local cachedData = Solution.Util.GetDepCache(dep, "cache")
local cachedData = Solution.Util.GetDepCache(dep.Name, "cache")

local includeDirs, libs
if cachedData then
includeDirs, libs = cachedData.includes, cachedData.libs
else
includeDirs, libs = getVulkanInfo()
Solution.Util.SetDepCache(dep, "cache", { includes = includeDirs, libs = libs })
Solution.Util.SetDepCache(dep.Name, "cache", { includes = includeDirs, libs = libs })
end

Solution.Util.SetIncludes(includeDirs)
Expand Down
8 changes: 5 additions & 3 deletions Premake/ProjectUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Solution.Util.CreateModuleTable = function(name, dependencies)
end

Solution.Util.CreateDepTable = function(name, dependencies)
local dependency = { Name = name, Cache = {} }
local dependency = { Name = name }

dependency.NameLow = string.lower(dependency.Name)
dependency.Path = path.getabsolute(dependency.NameLow .. "/", Solution.Projects.Current.DependencyDir)
Expand All @@ -108,12 +108,14 @@ Solution.Util.GetDepTable = function(depName)
end

-- Cache a value inside the dep table
Solution.Util.SetDepCache = function(dep, key, data)
Solution.Util.SetDepCache = function(depName, key, data)
local dep = Solution.Util.GetDepTable(depName)
dep.Cache[key] = data
end

-- Retrieve a cached value from the dep table, or return nil if not cached
Solution.Util.GetDepCache = function(dep, key)
Solution.Util.GetDepCache = function(depName, key)
local dep = Solution.Util.GetDepTable(depName)
if dep.Cache[key] then
return dep.Cache[key]
end
Expand Down

0 comments on commit 8b0ff7c

Please sign in to comment.