summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-17 23:23:10 +0800
committerruki <[email protected]>2019-02-18 10:09:01 +0800
commit7feefff1352d470cb10b3b0117f2a418a8bccdf9 (patch)
tree1765584a1919ab0f1ea5e83451c07afcb95dd79a
parent3d5bb63eab591dbb5f7ad9ac69894fe84e537751 (diff)
add keyvalues for scope info
-rw-r--r--xmake/core/base/interpreter.lua7
-rw-r--r--xmake/core/base/scopeinfo.lua103
2 files changed, 102 insertions, 8 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index ba7dc908f..e7dd5079d 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -531,13 +531,14 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter)
-- get the root scope info of the given scope kind, e.g. root.target
local results = {}
+ local scope_opt = {interpreter = self, remove_repeat = remove_repeat, enable_filter = enable_filter}
if scope_kind and scope_kind:startswith("root.") then
local root_scope = scopes._ROOT[scope_kind:sub(6)]
if root_scope then
results = self:_handle(root_scope, remove_repeat, enable_filter)
end
- return scopeinfo.new(scope_kind, results, self)
+ return scopeinfo.new(scope_kind, results, scope_opt)
-- get the root scope info without scope kind
elseif scope_kind == "root" or scope_kind == nil then
@@ -546,7 +547,7 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter)
if root_scope then
results = self:_handle(root_scope, remove_repeat, enable_filter)
end
- return scopeinfo.new(scope_kind, results, self)
+ return scopeinfo.new(scope_kind, results, scope_opt)
-- get the results of the given scope kind
elseif scope_kind then
@@ -580,7 +581,7 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter)
end
-- add this scope
- results[scope_name] = scopeinfo.new(scope_kind, self:_handle(scope_values, remove_repeat, enable_filter), self)
+ results[scope_name] = scopeinfo.new(scope_kind, self:_handle(scope_values, remove_repeat, enable_filter), scope_opt)
end
end
end
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index ebbf41b1c..7dedab11d 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -34,11 +34,14 @@ local table = require("base/table")
local utils = require("base/utils")
-- new an instance
-function _instance.new(kind, info, interpreter)
+function _instance.new(kind, info, opt)
+ opt = opt or {}
local instance = table.inherit(_instance)
instance._KIND = kind or "root"
instance._INFO = info
- instance._INTERPRETER = interpreter
+ instance._INTERPRETER = opt.interpreter
+ instance._REMOVE_REPEAT = opt.remove_repeat
+ instance._ENABLE_FILTER = opt.enable_filter
return instance
end
@@ -58,7 +61,15 @@ function _instance:_api_type(name)
end
end
--- TODO do filter
+-- handle the api values
+function _instance:_api_handle_values(values)
+ local interp = self:interpreter()
+ if interp then
+ values = interp:_handle(values, self._REMOVE_REPEAT, self._ENABLE_FILTER)
+ end
+ return values
+end
+
-- set the api values to the scope info
function _instance:_api_set_values(name, ...)
@@ -74,8 +85,11 @@ function _instance:_api_set_values(name, ...)
extra_config = nil
end
+ -- handle values
+ local handled_values = self:_api_handle_values(values)
+
-- save values
- scope[name] = values
+ scope[name] = handled_values
-- save extra config
if extra_config then
@@ -102,8 +116,11 @@ function _instance:_api_add_values(name, ...)
extra_config = nil
end
+ -- handle values
+ local handled_values = self:_api_handle_values(values)
+
-- save values
- scope[name] = table.join2(scope[name] or {}, values)
+ scope[name] = table.join2(scope[name] or {}, handled_values)
-- save extra config
if extra_config then
@@ -115,6 +132,82 @@ function _instance:_api_add_values(name, ...)
end
end
+-- set the api values to the scope info
+function _instance:_api_set_keyvalues(name, key, ...)
+
+ -- get the scope info
+ local scope = self._INFO
+
+ -- get extra config
+ local values = {...}
+ local extra_config = values[#values]
+ if table.is_dictionary(extra_config) then
+ table.remove(values)
+ else
+ extra_config = nil
+ end
+
+ -- handle values
+ local handled_values = self:_api_handle_values(values)
+
+ -- save values to "name"
+ scope[name] = scope[name] or {}
+ scope[name][key] = handled_values
+
+ -- save values to "name.key"
+ local name_key = name .. "." .. key
+ scope[name_key] = handled_values
+
+ -- fix override attributes
+ scope["__override_" .. name] = false
+ scope["__override_" .. name_key] = true
+
+ -- save extra config
+ if extra_config then
+ scope["__extra_" .. name_key] = scope["__extra_" .. name_key] or {}
+ local extrascope = scope["__extra_" .. name_key]
+ for _, value in ipairs(values) do
+ extrascope[value] = extra_config
+ end
+ end
+end
+
+-- add the api values to the scope info
+function _instance:_api_add_keyvalues(name, key, ...)
+
+ -- get the scope info
+ local scope = self._INFO
+
+ -- get extra config
+ local values = {...}
+ local extra_config = values[#values]
+ if table.is_dictionary(extra_config) then
+ table.remove(values)
+ else
+ extra_config = nil
+ end
+
+ -- handle values
+ local handled_values = self:_api_handle_values(values)
+
+ -- save values to "name"
+ scope[name] = scope[name] or {}
+ scope[name][key] = table.join2(scope[name][key] or {}, handled_values)
+
+ -- save values to "name.key"
+ local name_key = name .. "." .. key
+ scope[name_key] = scope[name][key]
+
+ -- save extra config
+ if extra_config then
+ scope["__extra_" .. name_key] = scope["__extra_" .. name_key] or {}
+ local extrascope = scope["__extra_" .. name_key]
+ for _, value in ipairs(values) do
+ extrascope[value] = extra_config
+ end
+ end
+end
+
-- get the scope kind
function _instance:kind()
return self._KIND