Build/Utilities/requireAbs.lua
J Reece Wilson 431fe2afc5 [*] Linux Fixes
[*] Update readme
[*] Fix single arch sln regression
2022-03-20 08:08:03 +00:00

52 lines
1.5 KiB
Lua

_auRequireTable = {}
function auRequireAbs(path, invalidate)
-- this is stupid
return auRequire(_G.path.getrelative(Aurora.Settings.sAbsScripts, path), nil, invalidate)
end
function auRequire(relPath, subdir, invalidate)
-- this is stupid
local buildScripts = auGetAuroraRoot()
local premakeRequireRootCWD = Aurora.Settings.sAbsScripts
if (not subdir) then
buildScripts = premakeRequireRootCWD
else
buildScripts = buildScripts .. subdir
end
buildScripts = os.realpath(buildScripts) .. "/"
if (os.isdir(buildScripts .. relPath)) then
relPath = relPath .. (relPath:match("/[^/]*$") or ("/".. relPath)) .. ".lua"
end
if (not relPath:ends(".lua")) then
relPath = "/" .. relPath .. ".lua"
end
relPath = _G.path.translate(relPath)
if (not os.isfile(buildScripts .. relPath)) then
auFatal("Script not found: ", relPath)
end
local realPath = os.realpath(buildScripts .. relPath)
-- premake should support modules.loaded[modname] (iirc), but either way, i'm being extra safe
-- we once used rel paths with require so this was required
-- invalidation requests don't seem to make much sense, but they can stay in a hint
-- wont remove this for.now
local cache = _auRequireTable[realPath]
if (cache and not invalidate) then
return cache
end
local result = require(realPath:sub(1, #realPath - 4))
_auRequireTable[realPath] = result
return result
end