diff options
| author | ruki <[email protected]> | 2017-07-18 11:28:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-18 11:28:12 +0800 |
| commit | f681b5830054511484277bdf82838cd5bb7a9b66 (patch) | |
| tree | dc62de31a9f8b5b5be8e83e2f8a8bee1e411226f | |
| parent | a4648568818b4b5b3598e6c7d5179b5d720a8c94 (diff) | |
add option and target dep api
| -rw-r--r-- | xmake/actions/run/main.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 26 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 29 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 6 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 2 |
6 files changed, 39 insertions, 34 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 571c5d10e..5127e8b68 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -74,7 +74,7 @@ end function _run_deps(target) -- run target deps - for _, dep in ipairs(target:deps()) do + for _, dep in pairs(target:deps()) do _run(dep) end end diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index c413640ca..daee85a69 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -147,7 +147,7 @@ function option:_check() end -- trace - utils.cprint("checking for the %s ... %s", name, utils.ifelse(self:is_enabled(), "${green}ok", "${red}no")) + utils.cprint("checking for the %s ... %s", name, utils.ifelse(self:enabled(), "${green}ok", "${red}no")) if not ok then os.raise(errors) end @@ -213,11 +213,6 @@ function option:set_value(value) self:_flush() end --- this option is enabled? -function option:is_enabled() - return config.get(self:name()) -end - -- clear the option status and need recheck it function option:clear() @@ -231,14 +226,19 @@ function option:clear() self:_flush() end +-- this option is enabled? +function option:enabled() + return config.get(self:name()) +end + -- enable or disable this option -function option:enable(is_enabled) +function option:enable(enabled) -- enable or disable this option? - config.set(self:name(), is_enabled) + config.set(self:name(), enabled) -- save or clear this option in cache - if is_enabled then + if enabled then self:_save() else self:_clear() @@ -285,6 +285,14 @@ function option:add(name_or_info, ...) end end +-- get the given dependent option +function option:dep(name) + local deps = self:deps() + if deps then + return deps[name] + end +end + -- get option deps function option:deps() return self._DEPS diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 40663b0d0..1d9251c45 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -355,23 +355,6 @@ function project._interpreter() return interp end --- load target deps -function project._load_deps(target, targets) - - -- get dep targets - local deptargets = {} - for _, dep in ipairs(table.wrap(target:get("deps"))) do - local deptarget = targets[dep] - if deptarget then - table.join2(deptargets, project._load_deps(deptarget, targets)) - table.insert(deptargets, deptarget) - end - end - - -- ok? - return table.unique(deptargets) -end - -- load targets function project._load_targets() @@ -405,7 +388,10 @@ function project._load_targets() -- load and attach target deps for _, target in pairs(targets) do - target._DEPS = project._load_deps(target, targets) + target._DEPS = {} + for _, dep in ipairs(table.wrap(target:get("deps"))) do + target._DEPS[dep] = targets[dep] + end end -- enter toolchains environment @@ -485,7 +471,10 @@ function project._load_options(disable_filter) -- load and attach options deps for _, opt in pairs(options) do - opt._DEPS = project._load_deps(opt, options) + opt._DEPS = {} + for _, dep in ipairs(table.wrap(opt:get("deps"))) do + opt._DEPS[dep] = options[dep] + end end -- ok? @@ -630,7 +619,7 @@ function project.menu() -- arrange options by category local options_by_category = {} - for _, opt in ipairs(options) do + for _, opt in pairs(options) do -- make the category local category = "default" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ee56708a9..971b85cd6 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -148,6 +148,14 @@ function target:linkflags() return self:linker():linkflags({target = self}) end +-- get the given dependent option +function target:dep(name) + local deps = self:deps() + if deps then + return deps[name] + end +end + -- get target deps function target:deps() return self._DEPS diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 4d1b574b3..b9e1d248e 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -70,10 +70,10 @@ function sandbox_core_project.check() if opt then -- check deps of this option first - for _, dep in ipairs(opt:deps()) do - if not checked[dep:name()] then + for depname, dep in pairs(opt:deps()) do + if not checked[depname] then dep:check() - checked[dep:name()] = true + checked[depname] = true end end diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 5e01233db..bec875325 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -154,7 +154,7 @@ end function builder:_addflags_from_targetdeps(results, target, flagname) -- for all target deps - for _, dep in ipairs(target:deps()) do + for _, dep in pairs(target:deps()) do -- is static or shared target library? link it local depkind = dep:get("kind") |
