Skip to content

Commit

Permalink
重新支持config
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Feb 27, 2024
1 parent 3849555 commit b22aac1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions scripts/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function m.assert(cond, fmt, ...)
if not cond then
fatal(fmt:format(...))
end
return cond
end
function m.fatal(fmt, ...)
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return "1.6"
return "1.7"
1 change: 1 addition & 0 deletions scripts/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local ATTRIBUTE <const> = {
links = AttributeStrings,
frameworks = AttributeStrings,
deps = AttributeStrings,
confs = AttributeStrings,
-- globs
inputs = AttributeGlobs,
sources = AttributeGlobs,
Expand Down
30 changes: 27 additions & 3 deletions scripts/writer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local cc
local m = {}
local loaded_target = {}
local loaded_rule = {}
local loaded_conf = {}
local scripts = {}
local visited = {}

Expand Down Expand Up @@ -91,6 +92,12 @@ local function reslove_attributes(g, l)
local l_rootdir = normalize_rootdir(g.workdir, l.rootdir or g.rootdir)
local t = {}
workspace.push_attributes(t, g)
if l.confs then
for _, conf in ipairs(l.confs) do
local conf_attribute = log.assert(loaded_conf[conf], "unknown conf `%s`", conf)
workspace.push_attributes(t, conf_attribute)
end
end
workspace.resolve_attributes(t, l, l_rootdir)
t.workdir = g.workdir
t.rootdir = l_rootdir
Expand All @@ -101,6 +108,12 @@ local function reslove_attributes_nolink(g, l)
local l_rootdir = normalize_rootdir(g.workdir, l.rootdir or g.rootdir)
local t = {}
workspace.push_attributes(t, g, true)
if l.confs then
for _, conf in ipairs(l.confs) do
local conf_attribute = log.assert(loaded_conf[conf], "unknown conf `%s`", conf)
workspace.push_attributes(t, conf_attribute, true)
end
end
workspace.resolve_attributes(t, l, l_rootdir)
t.workdir = g.workdir
t.rootdir = l_rootdir
Expand Down Expand Up @@ -893,9 +906,20 @@ function api.rule(global_attribute, name)
end
end

function api.conf(global_attribute, attribute)
local root = normalize_rootdir(global_attribute.workdir, attribute.rootdir or global_attribute.rootdir)
workspace.resolve_attributes(global_attribute, attribute, root)
function api.conf(global_attribute, name)
if type(name) == "table" then
local local_attribute = name
local root = normalize_rootdir(global_attribute.workdir, local_attribute.rootdir or global_attribute.rootdir)
workspace.resolve_attributes(global_attribute, local_attribute, root)
else
log.assert(type(name) == "string", "Name is not a string.")
return function (local_attribute)
local root = normalize_rootdir(global_attribute.workdir, local_attribute.rootdir or global_attribute.rootdir)
local attribute = {}
workspace.resolve_attributes(attribute, local_attribute, root)
loaded_conf[name] = attribute
end
end
end

function api:has(name)
Expand Down

0 comments on commit b22aac1

Please sign in to comment.