Add cycle detection, because it was ruining my day. Allow targets to be stored
in a file called build-<target>.lua to allow better dividing up of build rules (to break cycles).
This commit is contained in:
parent
e0b8bd221d
commit
10746f8b97
|
@ -17,6 +17,7 @@ local globals
|
||||||
local cwd = "."
|
local cwd = "."
|
||||||
local vars = {}
|
local vars = {}
|
||||||
local parente = {}
|
local parente = {}
|
||||||
|
local loadingstack = {}
|
||||||
|
|
||||||
-- Forward references
|
-- Forward references
|
||||||
local loadtarget
|
local loadtarget
|
||||||
|
@ -66,6 +67,16 @@ local function concat(...)
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Test table membership (crudely).
|
||||||
|
local function contains(needle, haystack)
|
||||||
|
for _, k in ipairs(haystack) do
|
||||||
|
if (k == needle) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function inherit(high, low)
|
local function inherit(high, low)
|
||||||
local o = {}
|
local o = {}
|
||||||
setmetatable(o, {
|
setmetatable(o, {
|
||||||
|
@ -351,6 +362,12 @@ local function templateexpand(list, vars)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadbuildfile(filename)
|
local function loadbuildfile(filename)
|
||||||
|
if contains(filename, loadingstack) then
|
||||||
|
error(string.format("build file cycle; '%s' refers to itself indirectly; stack is: %s %s",
|
||||||
|
filename, asstring(loadingstack), filename))
|
||||||
|
end
|
||||||
|
|
||||||
|
loadingstack[#loadingstack+1] = filename
|
||||||
if not buildfiles[filename] then
|
if not buildfiles[filename] then
|
||||||
buildfiles[filename] = true
|
buildfiles[filename] = true
|
||||||
|
|
||||||
|
@ -376,6 +393,7 @@ local function loadbuildfile(filename)
|
||||||
chunk()
|
chunk()
|
||||||
cwd = oldcwd
|
cwd = oldcwd
|
||||||
end
|
end
|
||||||
|
loadingstack[#loadingstack] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
loadtarget = function(targetname)
|
loadtarget = function(targetname)
|
||||||
|
@ -411,7 +429,12 @@ loadtarget = function(targetname)
|
||||||
filepart = cwd
|
filepart = cwd
|
||||||
end
|
end
|
||||||
local filename = concatpath(filepart, "/build.lua")
|
local filename = concatpath(filepart, "/build.lua")
|
||||||
loadbuildfile(concatpath(filename))
|
if posix.access(filename, "r") then
|
||||||
|
loadbuildfile(filename)
|
||||||
|
else
|
||||||
|
filename = concatpath(filepart, "/build-"..targetpart..".lua")
|
||||||
|
loadbuildfile(filename)
|
||||||
|
end
|
||||||
|
|
||||||
target = targets[targetname]
|
target = targets[targetname]
|
||||||
if not target then
|
if not target then
|
||||||
|
|
Loading…
Reference in a new issue