Skip to content

Commit

Permalink
Add dependency caching and helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Aug 16, 2024
1 parent 4bb8c7f commit a0a1afa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Dependencies/libpqxx/Libpqxx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ Solution.Util.CreateStaticLib(dep.Name, Solution.Projects.Current.BinDir, dep.De
end)

Solution.Util.CreateDep(dep.NameLow, dep.Dependencies, function()
local baseDir = dep.Path .. "/Libpqxx"
local _, _, foundLibs = getPostgresInfo()
Solution.Util.SetIncludes({baseDir .. "/include"})
local foundLibs = Solution.Util.GetDepCache(dep.NameLow, "cache")
if not foundLibs then
local _, _, foundLibs = getPostgresInfo()
Solution.Util.SetDepCache(dep.NameLow, "cache", foundLibs)
end

Solution.Util.SetIncludes({dep.Path .. "/Libpqxx/include"})
Solution.Util.SetLinks({ dep.Name, foundLibs })
end)
35 changes: 34 additions & 1 deletion Premake/ProjectUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ Solution.Util.CreateDepTable = function(name, dependencies)
return dependency
end

Solution.Util.GetDepTable = function(depName)
local depInternalName = "Dependency-" .. depName
local dep = _G[depInternalName]
if (dep == nil) then
Solution.Util.PrintError("Tried to fetch undeclared dependency '" .. depName .. "'")
end

return dep
end

-- Cache a value inside the dep table
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(depName, key)
local dep = Solution.Util.GetDepTable(depName)
if dep.Cache[key] then
return dep.Cache[key]
end

return nil
end

Solution.Util.IncludeSubmodule = function(name, rootDir, binDir)
local submoduleRootDir = path.getabsolute("Submodules/".. name .. "/", rootDir)
local submoduleBuildDir = path.getabsolute("Build/".. name .. "/", rootDir)
Expand Down Expand Up @@ -295,7 +321,8 @@ Solution.Util.CreateDep = function(name, dependencies, callback)
local dependencyTable =
{
Callback = callback,
Dependencies = dependencies
Dependencies = dependencies,
Cache = {}
}

_G[internalName] = dependencyTable
Expand Down Expand Up @@ -406,6 +433,12 @@ Solution.Util.ClearFilter = function()
filter { }
end

Solution.Util.MergeIntoTable = function(t, x)
for _, v in pairs(x) do
table.insert(t, v)
end
end

if InitBuildSettings == nil then
function InitBuildSettings(silentFailOnDuplicateSetting)
if BuildSettings == nil then
Expand Down
2 changes: 1 addition & 1 deletion Submodules/Engine

0 comments on commit a0a1afa

Please sign in to comment.