diff options
| author | ruki <[email protected]> | 2019-01-07 22:50:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-07 11:02:37 +0800 |
| commit | 530d13f8933458cc34b06c50dd80dee6671d1568 (patch) | |
| tree | 1eeca4d905f819d5de813cff362a362897fb08ff | |
| parent | 76cf129b49dba3abd63de5610900265c63603458 (diff) | |
get the given option from target
| -rw-r--r-- | xmake/actions/config/configheader.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 22 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 74 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 10 |
4 files changed, 67 insertions, 43 deletions
diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua index 4d816c0cb..0480077ff 100644 --- a/xmake/actions/config/configheader.lua +++ b/xmake/actions/config/configheader.lua @@ -74,7 +74,7 @@ function _make_for_target(target) local undefines = table.copy(target:get("undefines_h")) -- make the defines for options - for _, opt in ipairs(target:options()) do + for _, opt in ipairs(target:orderopts()) do table.join2(defines, opt:get("defines_h")) table.join2(defines, opt:get("defines_h_if_ok")) -- deprecated table.join2(undefines, opt:get("undefines_h")) @@ -82,7 +82,7 @@ function _make_for_target(target) end -- make the defines for packages - for _, pkg in ipairs(target:packages()) do + for _, pkg in ipairs(target:orderpkgs()) do table.join2(defines, pkg:get("defines_h")) table.join2(undefines, pkg:get("undefines_h")) end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 31019db59..de22b200f 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -559,28 +559,6 @@ function project._load_options(disable_filter) local options = {} for optionname, optioninfo in pairs(results) do - -- TODO - -- load it from cache first (@note will discard scripts) - --[[ - local instance = option.load(optionname) - if instance then - - -- patch scripts (e.g. on_check ..) - for k, v in pairs(optioninfo) do - if type(v) == "function" then - instance:set(k, v) - end - end - else - - -- init a option instance - instance = table.inherit(option) - - -- save name and info - instance._NAME = optionname - instance._INFO = optioninfo - end]] - -- init a option instance local instance = table.inherit(option) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 045fa5ded..3c639861a 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -448,7 +448,7 @@ function target:deps() return self._DEPS end --- get target order deps +-- get target ordered deps function target:orderdeps() return self._ORDERDEPS end @@ -476,7 +476,7 @@ function target:rules() return self._RULES end --- get target order rules +-- get target ordered rules function target:orderules() return self._ORDERULES end @@ -498,21 +498,44 @@ function target:isphony() return not targetkind or targetkind == "phony" end --- get the options -function target:options() +-- get the enabled option +function target:opt(name) + return self:opts()[name] +end + +-- get the enabled options +function target:opts() + + -- attempt to get it from cache first + if self._OPTS_ENABLED then + return self._OPTS_ENABLED + end + + -- load options if be enabled + self._OPTS_ENABLED = {} + for _, opt in ipairs(self:orderopts()) do + self._OPTS_ENABLED[opt:name()] = opt + end + + -- get it + return self._OPTS_ENABLED +end + +-- get the enabled ordered options +function target:orderopts() -- attempt to get it from cache first - if self._OPTIONS then - return self._OPTIONS + if self._ORDEROPTS_ENABLED then + return self._ORDEROPTS_ENABLED end -- load options if be enabled - self._OPTIONS = {} + self._ORDEROPTS_ENABLED = {} for _, name in ipairs(table.wrap(self:get("options"))) do local opt = nil if config.get(name) then opt = option.load(name) end if opt then - table.insert(self._OPTIONS, opt) + table.insert(self._ORDEROPTS_ENABLED, opt) end end @@ -522,27 +545,50 @@ function target:options() local opt = nil if config.get(name) then opt = option.load(name) end if opt then - table.insert(self._OPTIONS, opt) + table.insert(self._ORDEROPTS_ENABLED, opt) end end end -- get it - return self._OPTIONS + return self._ORDEROPTS_ENABLED +end + +-- get the enabled package +function target:pkg(name) + return self:pkgs()[name] +end + +-- get the enabled packages +function target:pkgs() + + -- attempt to get it from cache first + if self._PKGS_ENABLED then + return self._PKGS_ENABLED + end + + -- load packages if be enabled + self._PKGS_ENABLED = {} + for _, pkg in ipairs(self:orderpkgs()) do + self._PKGS_ENABLED[pkg:name()] = pkg + end + + -- get it + return self._PKGS_ENABLED end -- get the required packages -function target:packages() - if not self._PACKAGES_ENABLED then +function target:orderpkgs() + if not self._ORDERPKGS_ENABLED then local packages = {} for _, pkg in ipairs(self._PACKAGES) do if pkg:enabled() then table.insert(packages, pkg) end end - self._PACKAGES_ENABLED = packages + self._ORDERPKGS_ENABLED = packages end - return self._PACKAGES_ENABLED + return self._ORDERPKGS_ENABLED end -- get the config info of the given package diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index cf5a486b1..69335a9e5 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -117,7 +117,7 @@ end -- inherts from target packages function builder:_inherit_from_targetpkgs(values, target, name) - for _, pkg in ipairs(target:packages()) do + for _, pkg in ipairs(target:orderpkgs()) do -- uses them instead of the builtin configs if exists extra package config -- e.g. `add_packages("xxx", {links = "xxx"})` local configinfo = target:pkgconfig(pkg:name()) @@ -134,7 +134,7 @@ end function builder:_inherit_from_target(values, target, name) table.join2(values, target:get(name)) if target:type() == "target" then - for _, opt in ipairs(target:options()) do + for _, opt in ipairs(target:orderopts()) do table.join2(values, opt:get(name)) end self:_inherit_from_targetpkgs(values, target, name) @@ -252,12 +252,12 @@ function builder:_addflags_from_target(flags, target) if target:type() == "target" then -- add flags from options - for _, opt in ipairs(target:options()) do + for _, opt in ipairs(target:orderopts()) do self:_addflags_from_option(targetflags, opt) end -- add flags from packages - for _, pkg in ipairs(target:packages()) do + for _, pkg in ipairs(target:orderpkgs()) do self:_addflags_from_package(targetflags, pkg) end end @@ -343,7 +343,7 @@ function builder:_addflags_from_language(flags, target, getters) -- is target? get flagvalues of the attached options and packages local results = {} if target:type() == "target" then - for _, opt in ipairs(target:options()) do + for _, opt in ipairs(target:orderopts()) do table.join2(results, table.wrap(opt:get(name))) end self:_inherit_from_targetpkgs(results, target, name) |
