Skip to content

Commit

Permalink
支持config
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Mar 24, 2023
1 parent 83ec364 commit ad76002
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/version.lua
@@ -1 +1 @@
return "1.1"
return "1.2"
35 changes: 34 additions & 1 deletion scripts/writer.lua
Expand Up @@ -11,9 +11,10 @@ local cc
local m = {}
local loaded_target = {}
local loaded_rule = {}
local loaded_config = {}
local scripts = {}

local file_type = {
local file_type <const> = {
cxx = "cxx",
cpp = "cxx",
cc = "cxx",
Expand Down Expand Up @@ -206,6 +207,25 @@ local function reslove_attributes(g, loc)
local r = {}
reslove_table(g_rootdir, r, g)
reslove_table(l_rootdir, r, loc)
if r.configs then
for _, name in ipairs(r.configs) do
local config = assert(loaded_config[name], ("can`t find config `%s`"):format(name))
for k, v in pairs(config) do
if type(k) ~= "string" then
goto continue
end
if ATTRIBUTE[k] == PlatformAttribute then
goto continue
end
r[k] = r[k] or {}
push_string(r[k], v)
if #r[k] == 0 then
r[k] = nil
end
::continue::
end
end
end
--TODO: remove it
push_args(r, loc, l_rootdir)
r.workdir = g.workdir
Expand Down Expand Up @@ -570,6 +590,11 @@ local function generate_rule(attribute, name)
ninja:rule(name, table.concat(command, " "), kwargs)
end

local function generate_config(attribute, name)
assert(loaded_config[name] == nil, ("config `%s`: redefinition."):format(name))
loaded_config[name] = attribute
end

local function getImplicitInputs(name, attribute)
local res = {}
if attribute.deps then
Expand Down Expand Up @@ -988,6 +1013,14 @@ function api.rule(global_attribute, name)
end
end

function api.config(global_attribute, name)
assert(type(name) == "string", "Name is not a string.")
return function (local_attribute)
local attribute = reslove_attributes(global_attribute, local_attribute)
generate_config(attribute, name)
end
end

for rule, genfunc in pairs(GEN) do
api[rule] = function (global_attribute, name)
if type(name) == "table" then
Expand Down

0 comments on commit ad76002

Please sign in to comment.