diff options
| author | ruki <[email protected]> | 2019-02-15 23:59:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-18 10:09:01 +0800 |
| commit | e9639a1d7ef67477ba12b740e38a5d5b4f774865 (patch) | |
| tree | 451a064cf6a0ab9497278ff8af0bf3ca01f9ab02 | |
| parent | 7f7e2806ac8a10133f564ad5bbb163dc4e0327d1 (diff) | |
add scope info for interpreter
| -rw-r--r-- | xmake/core/base/interpreter.lua | 13 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 75 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 29 | ||||
| -rw-r--r-- | xmake/core/language/language.lua | 36 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 15 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 34 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 33 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 14 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 9 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 24 | ||||
| -rw-r--r-- | xmake/core/theme/theme.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/package/manager/xmake/find_package.lua | 8 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 2 |
13 files changed, 170 insertions, 138 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 458d71b30..b916a4aa3 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -31,6 +31,7 @@ local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") +local scopeinfo = require("base/scopeinfo") local sandbox = require("sandbox/sandbox") -- traceback @@ -485,8 +486,8 @@ function interpreter:_filter(values) return results end --- handle scope -function interpreter:_handle(scope, remove_repeat, enable_filter) +-- get scope info +function interpreter:_scopeinfo(scope_kind, scope, remove_repeat, enable_filter) -- check assert(scope) @@ -511,7 +512,7 @@ function interpreter:_handle(scope, remove_repeat, enable_filter) -- update it results[name] = values end - return results + return scopeinfo.new(scope_kind, results) end -- make results @@ -534,7 +535,7 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter) local root_scope = scopes._ROOT[scope_kind:sub(6)] if root_scope then - results = self:_handle(root_scope, remove_repeat, enable_filter) + results = self:_scopeinfo(scope_kind, root_scope, remove_repeat, enable_filter) end -- get the root results without scope kind @@ -542,7 +543,7 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter) local root_scope = scopes._ROOT["__rootkind"] if root_scope then - results = self:_handle(root_scope, remove_repeat, enable_filter) + results = self:_scopeinfo(scope_kind, root_scope, remove_repeat, enable_filter) end -- get the results of the given scope kind @@ -579,7 +580,7 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter) end -- add this scope - results[scope_name] = self:_handle(scope_values, remove_repeat, enable_filter) + results[scope_name] = self:_scopeinfo(scope_kind, scope_values, remove_repeat, enable_filter) end end return results diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua new file mode 100644 index 000000000..2ab0e2788 --- /dev/null +++ b/xmake/core/base/scopeinfo.lua @@ -0,0 +1,75 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file scopeinfo.lua +-- + +-- define module +local scopeinfo = scopeinfo or {} +local _instance = _instance or {} + +-- load modules +local io = require("base/io") +local os = require("base/os") +local path = require("base/path") +local table = require("base/table") +local utils = require("base/utils") + +-- new an instance +function _instance.new(kind, info) + local instance = table.inherit(_instance) + instance._KIND = kind or "root" + instance._INFO = info + return instance +end + +-- get the scope kind +function _instance:kind() + return self._KIND +end + +-- is root scope? +function _instance:is_root() + return self:kind() == "root" +end + +-- get all scope info +function _instance:info() + return self._INFO +end + +-- get the scope info from the given name +function _instance:get(name) + return self._INFO[name] +end + +-- set the value to the scope info +function _instance:set(name, value) + self._INFO[name] = value +end + +-- new an scope instance +function scopeinfo.new(name, info) + return _instance.new(name, info) +end + +-- return module +return scopeinfo diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 55cd47590..6795ac3b3 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -239,13 +239,14 @@ function task._bind(tasks, interp) assert(interp) -- bind sandbox for menus - for _, taskinfo in pairs(tasks) do + for _, taskinst in pairs(tasks) do - -- has menu? - if taskinfo.menu then + -- has task menu? + local taskmenu = taskinst:get("menu") + if taskmenu then -- translate options - local options = taskinfo.menu.options + local options = taskmenu.options if options then -- make full options @@ -267,7 +268,7 @@ function task._bind(tasks, interp) -- update the options options = options_full - taskinfo.menu.options = options_full + taskmenu.options = options_full -- bind sandbox for scripts in option for _, opt in ipairs(options) do @@ -364,16 +365,9 @@ end -- new a task instance function task.new(name, info) - - -- init a task instance local instance = table.inherit(task) - assert(instance) - - -- save name and info instance._NAME = name instance._INFO = info - - -- ok? return instance end @@ -433,8 +427,9 @@ function task.menu(tasks) local menu = {} for taskname, taskinst in pairs(tasks) do - -- has menu? - if taskinst:get("menu") then + -- has task menu? + local taskmenu = taskinst:get("menu") + if taskmenu then -- main? if taskinst:get("category") == "main" then @@ -443,7 +438,7 @@ function task.menu(tasks) menu.main = function () -- translate main menu - local mainmenu, errors = task._translate_menu(taskinst:get("menu")) + local mainmenu, errors = task._translate_menu(taskmenu) if not mainmenu then os.raise(errors) end @@ -473,7 +468,7 @@ function task.menu(tasks) -- delay to load task menu menu[taskname] = function () - local taskmenu, errors = task._translate_menu(taskinst:get("menu")) + local taskmenu, errors = task._translate_menu(taskmenu) if not taskmenu then os.raise(errors) end @@ -488,7 +483,7 @@ end -- get the task info function task:get(name) - return self._INFO[name] + return self._INFO:get(name) end -- get the task name diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index b3c653afc..a30045bd2 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -38,16 +38,10 @@ local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) - - -- new an instance - local instance = table.inherit(_instance) - - -- init instance - instance._NAME = name - instance._INFO = info - instance._ROOTDIR = rootdir - - -- ok + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir return instance end @@ -55,7 +49,7 @@ end function _instance:get(name) -- the info - local info = self._INFO + local info = self._INFO:info() -- get if from info first local value = info[name] @@ -82,7 +76,7 @@ end -- get the language menu function _instance:menu() - return self._INFO.menu + return self._INFO:get("menu") end -- get the language name @@ -115,12 +109,12 @@ end -- get the source kinds function _instance:sourcekinds() - return self._INFO.sourcekinds + return self._INFO:get("sourcekinds") end -- get the source flags function _instance:sourceflags() - return self._INFO.sourceflags + return self._INFO:get("sourceflags") end -- get the target kinds (targetkind => linkerkind) @@ -129,7 +123,7 @@ end -- {binary = "ld", static = "ar", shared = "sh"} -- function _instance:targetkinds() - return self._INFO.targetkinds + return self._INFO:get("targetkinds") end -- get the target flags (targetkind => linkerflag) @@ -138,9 +132,7 @@ end -- {binary = "ldflags", static = "arflags", shared = "shflags"} -- function _instance:targetflags() - - -- get it - return self._INFO.targetflags + return self._INFO:get("targetflags") end -- get the mixing kinds for linker @@ -149,14 +141,12 @@ end -- {"cc", "cxx"} -- function _instance:mixingkinds() - - -- get it - return self._INFO.mixingkinds + return self._INFO:get("mixingkinds") end -- get the language kinds function _instance:langkinds() - return self._INFO.langkinds + return self._INFO:get("langkinds") end -- get the name flags @@ -169,7 +159,7 @@ function _instance:nameflags() -- get nameflags local results = {} - for targetkind, nameflags in pairs(table.wrap(self._INFO.nameflags)) do + for targetkind, nameflags in pairs(table.wrap(self._INFO:get("nameflags"))) do -- make tool info local toolinfo = results[targetkind] or {} diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index cae402f3d..87c075439 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -33,6 +33,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") +local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") local config = require("project/config") @@ -43,15 +44,9 @@ local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info) - - -- new an instance local instance = table.inherit(_instance) - - -- init instance - instance._NAME = name - instance._INFO = info - - -- ok + instance._NAME = name + instance._INFO = info return instance end @@ -59,7 +54,7 @@ end function _instance:get(name) -- get it from info first - local value = self._INFO[name] + local value = self._INFO:get(name) if value ~= nil then return value end @@ -838,7 +833,7 @@ function package.load_from_system(packagename) end -- new an instance - local instance, errors = _instance.new(packagename, packageinfo) + local instance, errors = _instance.new(packagename, scopeinfo.new("package", packageinfo)) if not instance then return nil, errors end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 8a189da49..2b8d029bf 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -38,16 +38,10 @@ local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) - - -- new an instance - local instance = table.inherit(_instance) - - -- init instance - instance._NAME = name - instance._INFO = info - instance._ROOTDIR = rootdir - - -- ok + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir return instance end @@ -58,27 +52,27 @@ end -- set the value to the platform info function _instance:set(name, ...) - self._INFO[name] = table.unwrap({...}) + self._INFO:set(name, table.unwrap({...})) end -- add the value to the platform info function _instance:add(name, ...) local info = table.wrap(self._INFO[name]) - self._INFO[name] = table.unwrap(table.join(info, ...)) + self._INFO:set(name, table.unwrap(table.join(info, ...))) end -- get the platform configuration function _instance:get(name) -- attempt to get the static configure value - local value = self._INFO[name] + local value = self._INFO:get(name) if value ~= nil then return value end -- lazy loading platform if get other configuration if not self._LOADED and not self:_is_builtin_conf(name) then - local on_load = self._INFO.load + local on_load = self._INFO:get("load") if on_load then local ok, errors = sandbox.load(on_load, self) if not ok then @@ -89,33 +83,33 @@ function _instance:get(name) end -- get other platform info - return self._INFO[name] + return self._INFO:get(name) end -- get the platform os function _instance:os() - return self._INFO.os + return self._INFO:get("os") end -- get the platform menu function _instance:menu() -- @note do not use self:get("menu") to avoid loading platform early - return self._INFO.menu + return self._INFO:get("menu") end -- get the platform hosts function _instance:hosts() - return self._INFO.hosts + return self._INFO:get("hosts") end -- get the platform archs function _instance:archs() - return self._INFO.archs + return self._INFO:get("archs") end -- get the platform script function _instance:script(name) - return self._INFO[name] + return self._INFO:get(name) end -- get user private data diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index ca25cdb97..be0d8ba16 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -34,6 +34,7 @@ local table = require("base/table") local utils = require("base/utils") local baseoption = require("base/option") local global = require("base/global") +local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") local cache = require("project/cache") @@ -46,15 +47,9 @@ local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info) - - -- new an instance local instance = table.inherit(_instance) - - -- init instance - instance._NAME = name - instance._INFO = info - - -- ok + instance._NAME = name + instance._INFO = info return instance end @@ -67,7 +62,7 @@ function _instance:_save() self:set("check_before", nil) -- save option - option._cache():set(self:name(), self._INFO) + option._cache():set(self:name(), self:info()) end -- clear the option info for cache @@ -285,9 +280,9 @@ function _instance:enable(enabled, opt) end end --- dump this option -function _instance:dump() - table.dump(self._INFO) +-- get the option info +function _instance:info() + return self._INFO:info() end -- get the type: option @@ -296,8 +291,8 @@ function _instance:type() end -- get the option info -function _instance:get(infoname) - return self._INFO[infoname] +function _instance:get(name) + return self._INFO:get(name) end -- set the value to the option info @@ -305,9 +300,9 @@ function _instance:set(name_or_info, ...) if type(name_or_info) == "string" then local args = ... if args ~= nil then - self._INFO[name_or_info] = table.unwrap(table.unique(table.join(...))) + self._INFO:set(name_or_info, table.unwrap(table.unique(table.join(...)))) else - self._INFO[name_or_info] = nil + self._INFO:set(name_or_info, nil) end elseif table.is_dictionary(name_or_info) then for name, info in pairs(table.join(name_or_info, ...)) do @@ -319,8 +314,8 @@ end -- add the value to the option info function _instance:add(name_or_info, ...) if type(name_or_info) == "string" then - local info = table.wrap(self._INFO[name_or_info]) - self._INFO[name_or_info] = table.unwrap(table.unique(table.join(info, ...))) + local info = table.wrap(self._INFO:get(name_or_info)) + self._INFO:set(name_or_info, table.unwrap(table.unique(table.join(info, ...)))) elseif table.is_dictionary(name_or_info) then for name, info in pairs(table.join(name_or_info, ...)) do self:add(name, info) @@ -490,7 +485,7 @@ function option.load(name) if info == nil then return end - return option.new(name, info) + return option.new(name, scopeinfo.new("option", info)) end -- save all options to the cache file diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index a0ea2b064..1e0403fc3 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -301,7 +301,7 @@ end -- get the project info from the given name function project.get(name) - return project._INFO and project._INFO[name] or nil + return project._INFO and project._INFO:get(name) or nil end -- load the project file @@ -340,8 +340,8 @@ function project._load(force) end -- save the root info - for name, value in pairs(rootinfo_target) do - rootinfo["target." .. name] = value + for name, value in pairs(rootinfo_target:info()) do + rootinfo:set("target." .. name, value) end project._INFO = rootinfo @@ -605,17 +605,17 @@ function project._load_options(disable_filter) for _, packageinfo in pairs(packageinfos) do local linkdirs = {} local includedirs = {} - for _, linkdir in ipairs(table.wrap(packageinfo.linkdirs)) do + for _, linkdir in ipairs(table.wrap(packageinfo:get("linkdirs"))) do table.insert(linkdirs, path.is_absolute(linkdir) and linkdir or path.join(rootdir, linkdir)) end - for _, includedir in ipairs(table.wrap(packageinfo.includedirs)) do + for _, includedir in ipairs(table.wrap(packageinfo:get("includedirs"))) do table.insert(includedirs, path.is_absolute(includedir) and includedir or path.join(rootdir, includedir)) end if #linkdirs > 0 then - packageinfo.linkdirs = linkdirs + packageinfo:set("linkdirs", linkdirs) end if #includedirs > 0 then - packageinfo.includedirs = includedirs + packageinfo:set("includedirs", includedirs) end end table.join2(results, packageinfos) diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 4e75366ee..0b691144e 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -200,22 +200,15 @@ end -- new a rule instance function rule.new(name, info) - - -- init a rule instance local instance = table.inherit(rule) - assert(instance) - - -- save name and info instance._NAME = name instance._INFO = info - - -- ok? return instance end -- get the rule info function rule:get(name) - return self._INFO[name] + return self._INFO:get(name) end -- get the rule name diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index c80a83c10..66ed1c331 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -329,7 +329,7 @@ end -- get the target info function target:get(name) - return self._INFO[name] + return self._INFO:get(name) end -- set the value to the target info @@ -350,15 +350,15 @@ function target:set(name_or_info, ...) -- set values local name = name_or_info if #values > 0 then - self._INFO[name] = table.unwrap(table.unique(table.join(unpack(values)))) + self._INFO:set(name, table.unwrap(table.unique(table.join(unpack(values))))) else - self._INFO[name] = nil + self._INFO:set(name, nil) end -- save extra config if extra_config then - self._INFO["__extra_" .. name] = self._INFO["__extra_" .. name] or {} - local extrascope = self._INFO["__extra_" .. name] + self._INFO:set("__extra_" .. name, self._INFO:get("__extra_" .. name) or {}) + local extrascope = self._INFO:get("__extra_" .. name) for _, value in ipairs(values) do extrascope[value] = extra_config end @@ -397,13 +397,13 @@ function target:add(name_or_info, ...) -- add values local name = name_or_info - local info = table.wrap(self._INFO[name]) - self._INFO[name] = table.unwrap(table.unique(table.join(info, unpack(values)))) + local info = table.wrap(self._INFO:get(name)) + self._INFO:set(name, table.unwrap(table.unique(table.join(info, unpack(values))))) -- save extra config if extra_config then - self._INFO["__extra_" .. name] = self._INFO["__extra_" .. name] or {} - local extrascope = self._INFO["__extra_" .. name] + self._INFO:set("__extra_" .. name, self._INFO:get("__extra_" .. name) or {}) + local extrascope = self._INFO:get("__extra_" .. name) for _, value in ipairs(values) do extrascope[value] = extra_config end @@ -477,9 +477,9 @@ function target:values_add(name, ...) self:add("values." .. name, ...) end --- dump this target -function target:dump() - table.dump(self._INFO) +-- get the target info +function target:info() + return self._INFO:info() end -- get the type: option diff --git a/xmake/core/theme/theme.lua b/xmake/core/theme/theme.lua index e5c109ae5..35dd18b7b 100644 --- a/xmake/core/theme/theme.lua +++ b/xmake/core/theme/theme.lua @@ -35,16 +35,10 @@ local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) - - -- new an instance - local instance = table.inherit(_instance) - - -- init instance - instance._NAME = name - instance._INFO = info - instance._ROOTDIR = rootdir - - -- ok + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir return instance end @@ -55,7 +49,7 @@ end -- get the theme configuration function _instance:get(name) - return self._INFO[name] + return self._INFO:get(name) end -- the interpreter diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua index a1a29e9cd..cb00d5756 100644 --- a/xmake/modules/package/manager/xmake/find_package.lua +++ b/xmake/modules/package/manager/xmake/find_package.lua @@ -211,7 +211,7 @@ function _find_package_from_packagedirs(name, opt) -- get linkdirs local linkdirs = {} - for _, linkdir in ipairs(packageinfo.linkdirs) do + for _, linkdir in ipairs(packageinfo:get("linkdirs")) do table.insert(linkdirs, path.join(packagepath, linkdir)) end if #linkdirs == 0 then @@ -220,7 +220,7 @@ function _find_package_from_packagedirs(name, opt) -- find library local result = nil - for _, link in ipairs(packageinfo.links) do + for _, link in ipairs(packageinfo:get("links")) do local libinfo = find_library(link, linkdirs) if libinfo then result = result or {} @@ -232,11 +232,11 @@ function _find_package_from_packagedirs(name, opt) -- inherit other package info if result then result.includedirs = {} - for _, includedir in ipairs(packageinfo.includedirs) do + for _, includedir in ipairs(packageinfo:get("includedirs")) do table.insert(result.includedirs, path.join(packagepath, includedir)) end for _, infoname in ipairs({"defines", "languages", "warnings"}) do - result[infoname] = packageinfo[infoname] + result[infoname] = packageinfo:get(infoname) end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 8416a0041..384a2ded5 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -548,7 +548,7 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc elseif sourcekind == "mrc" then for _, info in ipairs(sourceinfo) do local objectfile = path.relative(path.absolute(info.objectfile), vcxprojdir) - vcxprojfile:print("<ResourceOutputFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ResourceOutputFileName>",info.mode, info.arch, objectfile) + vcxprojfile:print("<ResourceOutputFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ResourceOutputFileName>", info.mode, info.arch, objectfile) end -- for *.c/cpp files |
