Commit 766b7655 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

processing order directives in policy files

parent fbb68587
......@@ -141,24 +141,46 @@ function PolicySet:load()
local input = {}
local source = {}
local required = {}
local polnames = {}
local policies = {}
local function require(name, fname)
if policies[name] then return end
table.insert(polnames, name)
policies[name] = self:loadJSON(name, fname)
for i, iname in util.listpairs(policies[name].import) do
for i, pol in ipairs(list(self.autodirs)) do require(unpack(pol)) end
local pending = {}
local imported = {}
local function import(name, fname)
local function import(name)
if util.contains(imported, name) then return end
if util.contains(required, name) then
error('Circular import: '
if util.contains(pending, name) then
error('Circular ordering directives: '
table.insert(pending, name)
local data = policies[name]
local data = self:loadJSON(name, fname)
local after = util.list(data.after or data.import)
for pname, policy in pairs(policies) do
if util.contains(util.list(policy.before), name) then
table.insert(after, pname)
for i, pname in ipairs(after) do import(pname) end
table.insert(required, name)
for i, iname in util.listpairs(data.import) do import(iname) end
table.insert(imported, name)
for cls, objs in pairs(data) do
if not util.contains({'description', 'import'},
if not util.contains({'description', 'import', 'after', 'before'},
cls) then
if not source[cls] then source[cls] = {} end
......@@ -181,9 +203,10 @@ function PolicySet:load()
for i, pol in ipairs(list(self.autodirs)) do import(unpack(pol)) end
for i, name in ipairs(polnames) do import(name) end
return, source, imported)
return, source, polnames)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment