diff options
| author | ruki <[email protected]> | 2019-02-17 23:57:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-18 10:09:01 +0800 |
| commit | fe2584406d733ad09c6bd930a187da8b5b902bff (patch) | |
| tree | fe6e8f4c653e9e8d5864104099271381359ef60f | |
| parent | 7feefff1352d470cb10b3b0117f2a418a8bccdf9 (diff) | |
add pathes for scope info
| -rw-r--r-- | xmake/core/base/interpreter.lua | 17 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 85 |
2 files changed, 69 insertions, 33 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index e7dd5079d..94cea2979 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -348,30 +348,15 @@ end -- translate api pathes function interpreter:_api_translate_pathes(values) - - -- check - assert(self and self._PRIVATE) - - -- the current file - local curfile = self._PRIVATE._CURFILE - assert(curfile) - - -- the current directory - local curdir = path.directory(curfile) - assert(curdir) - - -- translate the relative path local results = {} for _, p in ipairs(values) do assert(type(p) == "string", "invalid path value: " .. tostring(p)) if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then - table.insert(results, path.relative(path.absolute(p, curdir), self._PRIVATE._ROOTDIR)) + table.insert(results, path.relative(path.absolute(p, self:scriptdir()), self:rootdir())) else table.insert(results, p) end end - - -- ok? return results end diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 7dedab11d..e8208dc3e 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -62,7 +62,7 @@ function _instance:_api_type(name) end -- handle the api values -function _instance:_api_handle_values(values) +function _instance:_api_handle(values) local interp = self:interpreter() if interp then values = interp:_handle(values, self._REMOVE_REPEAT, self._ENABLE_FILTER) @@ -70,6 +70,22 @@ function _instance:_api_handle_values(values) return values end +-- save api source info, .e.g call api() in sourcefile:linenumber +function _instance:_api_save_sourceinfo_to_scope(scope, apiname, values) + + -- save api source info, .e.g call api() in sourcefile:linenumber + local sourceinfo = debug.getinfo(5, "Sl") + if sourceinfo then + scope["__sourceinfo_" .. apiname] = scope["__sourceinfo_" .. apiname] or {} + local sourcescope = scope["__sourceinfo_" .. apiname] + for _, value in ipairs(values) do + if type(value) == "string" then + sourcescope[value] = {file = sourceinfo.short_src or sourceinfo.source, line = sourceinfo.currentline} + end + end + end +end + -- set the api values to the scope info function _instance:_api_set_values(name, ...) @@ -86,7 +102,7 @@ function _instance:_api_set_values(name, ...) end -- handle values - local handled_values = self:_api_handle_values(values) + local handled_values = self:_api_handle(values) -- save values scope[name] = handled_values @@ -116,11 +132,8 @@ 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 {}, handled_values) + scope[name] = self:_api_handle(table.join2(table.wrap(scope[name]), values)) -- save extra config if extra_config then @@ -132,7 +145,7 @@ function _instance:_api_add_values(name, ...) end end --- set the api values to the scope info +-- set the api key-values to the scope info function _instance:_api_set_keyvalues(name, key, ...) -- get the scope info @@ -147,16 +160,13 @@ function _instance:_api_set_keyvalues(name, key, ...) 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 + scope[name][key] = self:_api_handle(values) -- save values to "name.key" local name_key = name .. "." .. key - scope[name_key] = handled_values + scope[name_key] = scope[name][key] -- fix override attributes scope["__override_" .. name] = false @@ -172,7 +182,7 @@ function _instance:_api_set_keyvalues(name, key, ...) end end --- add the api values to the scope info +-- add the api key-values to the scope info function _instance:_api_add_keyvalues(name, key, ...) -- get the scope info @@ -187,12 +197,9 @@ function _instance:_api_add_keyvalues(name, key, ...) 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) + scope[name][key] = self:_api_handle(table.join2(table.wrap(scope[name][key]), values)) -- save values to "name.key" local name_key = name .. "." .. key @@ -208,6 +215,50 @@ function _instance:_api_add_keyvalues(name, key, ...) end end +-- set the api pathes to the scope info +function _instance:_api_set_pathes(name, ...) + + -- get the scope info + local scope = self._INFO +end + +-- add the api pathes to the scope info +function _instance:_api_add_pathes(name, ...) + + -- get the scope info + local scope = self._INFO + + -- get interpreter + local interp = self:interpreter() + + -- 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 + + -- translate pathes + local pathes = interp:_api_translate_pathes(values) + + -- save values + scope[name] = self:_api_handle(table.join2(table.wrap(scope[name]), pathes)) + + -- save extra config + if extra_config then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + for _, value in ipairs(pathes) do + extrascope[value] = extra_config + end + end + + -- save api source info, .e.g call api() in sourcefile:linenumber + self:_api_save_sourceinfo_to_scope(scope, name, pathes) +end + -- get the scope kind function _instance:kind() return self._KIND |
