summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-17 22:18:17 +0800
committerruki <[email protected]>2019-02-18 10:09:01 +0800
commit3d5bb63eab591dbb5f7ad9ac69894fe84e537751 (patch)
treea7b4fde7b0d4b1b7cd7774525c1c8f3995d3b745
parent8e9016cc9c2ff0ad97427d22c7ea6d7349e12e57 (diff)
add values for scope info
-rw-r--r--xmake/core/base/interpreter.lua24
-rw-r--r--xmake/core/base/scopeinfo.lua123
-rw-r--r--xmake/core/project/target.lua13
3 files changed, 147 insertions, 13 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index fe957ef3c..ba7dc908f 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -537,7 +537,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)
+ return scopeinfo.new(scope_kind, results, self)
-- get the root scope info without scope kind
elseif scope_kind == "root" or scope_kind == nil then
@@ -546,7 +546,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)
+ return scopeinfo.new(scope_kind, results, self)
-- get the results of the given scope kind
elseif scope_kind then
@@ -580,7 +580,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))
+ results[scope_name] = scopeinfo.new(scope_kind, self:_handle(scope_values, remove_repeat, enable_filter), self)
end
end
end
@@ -792,11 +792,7 @@ end
-- the root api will affect these scopes
--
function interpreter:rootscope_set(scope_kind)
-
- -- check
assert(self and self._PRIVATE)
-
- -- set it
self._PRIVATE._ROOTSCOPE = scope_kind
end
@@ -815,6 +811,11 @@ function interpreter:apis(scope_kind)
end
end
+-- get api definitions
+function interpreter:api_definitions()
+ return self._API_DEFINITIONS
+end
+
-- register api
--
-- interp:api_register(nil, "apiroot", function () end)
@@ -1489,9 +1490,10 @@ end
-- @endcode
--
function interpreter:api_define(apis)
-
- -- register language apis
+
+ -- register apis
local scopes = {}
+ local definitions = self._API_DEFINITIONS or {}
for apitype, apifuncs in pairs(apis) do
for _, apifunc in ipairs(apifuncs) do
@@ -1507,6 +1509,9 @@ function interpreter:api_define(apis)
apifunc = apifunc[1]
end
+ -- register api definition, "scope.apiname" => "apitype"
+ definitions[apifunc] = apitype
+
-- get api function
local apiscope = nil
local funcname = nil
@@ -1555,6 +1560,7 @@ function interpreter:api_define(apis)
end
end
end
+ self._API_DEFINITIONS = definitions
end
-- the builtin api: set_xmakever()
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 2ab0e2788..ebbf41b1c 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -34,13 +34,87 @@ local table = require("base/table")
local utils = require("base/utils")
-- new an instance
-function _instance.new(kind, info)
+function _instance.new(kind, info, interpreter)
local instance = table.inherit(_instance)
instance._KIND = kind or "root"
instance._INFO = info
+ instance._INTERPRETER = interpreter
return instance
end
+-- get apis
+function _instance:_apis()
+ local interp = self:interpreter()
+ if interp then
+ return interp:api_definitions()
+ end
+end
+
+-- get the given api type
+function _instance:_api_type(name)
+ local apis = self:_apis()
+ if apis then
+ return apis[self:kind() .. '.' .. name]
+ end
+end
+
+-- TODO do filter
+-- set the api values to the scope info
+function _instance:_api_set_values(name, ...)
+
+ -- 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
+
+ -- save values
+ scope[name] = values
+
+ -- save extra config
+ if extra_config then
+ scope["__extra_" .. name] = scope["__extra_" .. name] or {}
+ local extrascope = scope["__extra_" .. name]
+ 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_values(name, ...)
+
+ -- 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
+
+ -- save values
+ scope[name] = table.join2(scope[name] or {}, values)
+
+ -- save extra config
+ if extra_config then
+ scope["__extra_" .. name] = scope["__extra_" .. name] or {}
+ local extrascope = scope["__extra_" .. name]
+ for _, value in ipairs(values) do
+ extrascope[value] = extra_config
+ end
+ end
+end
+
-- get the scope kind
function _instance:kind()
return self._KIND
@@ -56,6 +130,11 @@ function _instance:info()
return self._INFO
end
+-- get interpreter
+function _instance:interpreter()
+ return self._INTERPRETER
+end
+
-- get the scope info from the given name
function _instance:get(name)
return self._INFO[name]
@@ -66,9 +145,47 @@ function _instance:set(name, value)
self._INFO[name] = value
end
+-- set the api value to the scope info
+function _instance:apival_set(name, ...)
+ if type(name) == "string" then
+ local api_type = self:_api_type("set_" .. name)
+ if api_type then
+ local set_xxx = self["_api_set_" .. api_type]
+ if set_xxx then
+ set_xxx(self, name, ...)
+ else
+ os.raise("unknown apitype(%s) for %s:set(%s, ...)", api_type, self:kind(), name)
+ end
+ else
+ os.raise("unknown api(%s) for %s:set(%s, ...)", name, self:kind(), name)
+ end
+ else
+ -- TODO
+ end
+end
+
+-- add the api value to the scope info
+function _instance:apival_add(name, ...)
+ if type(name) == "string" then
+ local api_type = self:_api_type("add_" .. name)
+ if api_type then
+ local add_xxx = self["_api_add_" .. api_type]
+ if add_xxx then
+ add_xxx(self, name, ...)
+ else
+ os.raise("unknown apitype(%s) for %s:add(%s, ...)", api_type, self:kind(), name)
+ end
+ else
+ os.raise("unknown api(%s) for %s:add(%s, ...)", name, self:kind(), name)
+ end
+ else
+ -- TODO
+ end
+end
+
-- new an scope instance
-function scopeinfo.new(name, info)
- return _instance.new(name, info)
+function scopeinfo.new(...)
+ return _instance.new(...)
end
-- return module
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 66ed1c331..607d57346 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -333,6 +333,11 @@ function target:get(name)
end
-- set the value to the target info
+function target:set(name, ...)
+ self._INFO:apival_set(name, ...)
+end
+
+--[[
function target:set(name_or_info, ...)
-- set values to the given key?
@@ -378,9 +383,14 @@ function target:set(name_or_info, ...)
self:set(name, info)
end
end
-end
+end]]
-- add the value to the target info
+function target:add(name, ...)
+ self._INFO:apival_add(name, ...)
+end
+
+--[[
function target:add(name_or_info, ...)
-- add values to the given key?
@@ -424,6 +434,7 @@ function target:add(name_or_info, ...)
end
end
end
+]]
-- get user private data
function target:data(name)