diff options
| author | ruki <[email protected]> | 2017-08-14 15:35:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-14 15:35:43 +0800 |
| commit | 06aaf7d5a583fd5a6574661e4b58fbd9f431817a (patch) | |
| tree | 42742b32d29d776c9420e201e7b9095d9f54317f | |
| parent | dba45d143d8aff047da82cbe1a881056e6e4bc00 (diff) | |
fix target deps
| -rw-r--r-- | CHANGELOG.md | 10 | ||||
| -rw-r--r-- | core/src/demo/xmake.lua | 2 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 20 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 18 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 20 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 5 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 30 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 5 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 7 |
11 files changed, 87 insertions, 35 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 91260b983..d57bd6580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Improve `add_files` to configure the compile option of the given files +### Bugs fixed + +* Fix target deps + ## v2.1.5 ### New features @@ -317,7 +321,7 @@ ### Bugs fixed * Fix api bug for `set_installscript` -* Fix install bug for windows x86_64 +* Fix install bug for windows `x86_64` * Fix relative path bug <h1 id="中文"></h1> @@ -330,6 +334,10 @@ * 改进`add_files`,支持对files粒度进行编译选项的各种配置,更加灵活。 +### Bugs修复 + +* 修复目标级联依赖问题 + ## v2.1.5 ### 新特性 diff --git a/core/src/demo/xmake.lua b/core/src/demo/xmake.lua index 520241669..57453a87e 100644 --- a/core/src/demo/xmake.lua +++ b/core/src/demo/xmake.lua @@ -2,7 +2,7 @@ target("demo") -- add deps - add_deps("sv", "luajit", "xmake") + add_deps("xmake") -- make as a binary set_kind("binary") diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index acc71ed46..cf40ab3c3 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -28,6 +28,3 @@ target("xmake") -- add cfunc add_cfunc("API", "readline", nil, {"readline/readline.h"}, "readline") - if is_mode("coverage") then - add_cxflags("-coverage", "-fprofile-arcs", "-ftest-coverage") - end diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index ccfd39c44..ac933812d 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -29,7 +29,7 @@ import("core.tool.compiler") import("object") -- is modified? -function _is_modified(target, depfile, buildinfo, linker_instance) +function _is_modified(target, depfile, buildinfo, program, linkflags) -- this target and it's deps are not modified? local modified = buildinfo.rebuild or buildinfo.modified[target:name()] @@ -51,12 +51,12 @@ function _is_modified(target, depfile, buildinfo, linker_instance) end -- the program has been modified? - if linker_instance:program() ~= depinfo.program then + if program ~= depinfo.program then return true end -- the flags has been modified? - return os.args(linker_instance:linkflags({target = target})) ~= os.args(depinfo.flags) + return os.args(linkflags) ~= os.args(depinfo.flags) end -- build target from sources @@ -68,9 +68,15 @@ function _build_from_objects(target, buildinfo) -- load linker instance local linker_instance = linker.load(target:targetkind(), target:sourcekinds()) + -- get program + local program = linker_instance:program() + + -- get link flags + local linkflags = linker_instance:linkflags({target = target}) + -- this target and it's deps are not modified? local depfile = target:depfile() - local modified = _is_modified(target, depfile, buildinfo, linker_instance) + local modified = _is_modified(target, depfile, buildinfo, program, linkflags) if not modified then return end @@ -104,14 +110,14 @@ function _build_from_objects(target, buildinfo) -- trace verbose info if verbose then - print(linker_instance:linkcmd(objectfiles, targetfile, {target = target})) + print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags})) end -- link it - assert(linker_instance:link(objectfiles, targetfile, {target = target})) + assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags})) -- save program and flags to the dependent file - io.save(depfile, {program = linker_instance:program(), flags = linker_instance:linkflags({target = target})}) + io.save(depfile, {program = program, flags = linkflags}) end -- build target from sources diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 368fdacb3..fac2184bb 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -51,12 +51,12 @@ function _is_modified(target, depfile, buildinfo, linker_instance) end -- the program has been modified? - if linker_instance:program() ~= depinfo.program then + if program ~= depinfo.program then return true end -- the flags has been modified? - return os.args(linker_instance:linkflags({target = target})) ~= os.args(depinfo.flags) + return os.args(linkflags) ~= os.args(depinfo.flags) end -- build target from objects @@ -68,9 +68,15 @@ function _build_from_objects(target, buildinfo) -- load linker instance local linker_instance = linker.load(target:targetkind(), target:sourcekinds()) + -- get program + local program = linker_instance:program() + + -- get link flags + local linkflags = linker_instance:linkflags({target = target}) + -- this target and it's deps are not modified? local depfile = target:depfile() - local modified = _is_modified(target, depfile, buildinfo, linker_instance) + local modified = _is_modified(target, depfile, buildinfo, program, linkflags) if not modified then return end @@ -117,14 +123,14 @@ function _build_from_objects(target, buildinfo) -- trace verbose info if verbose then - print(linker_instance:linkcmd(objectfiles, targetfile, {target = target})) + print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags})) end -- link it - assert(linker_instance:link(objectfiles, targetfile, {target = target})) + assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags})) -- save program and flags to the dependent file - io.save(depfile, {program = linker_instance:program(), flags = linker_instance:linkflags({target = target})}) + io.save(depfile, {program = program, flags = linkflags}) end -- build target from sources diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index 105022486..e4d7c8553 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -29,7 +29,7 @@ import("core.tool.compiler") import("object") -- is modified? -function _is_modified(target, depfile, buildinfo, linker_instance) +function _is_modified(target, depfile, buildinfo, program, linkflags) -- this target and it's deps are not modified? local modified = buildinfo.rebuild or buildinfo.modified[target:name()] @@ -51,12 +51,12 @@ function _is_modified(target, depfile, buildinfo, linker_instance) end -- the program has been modified? - if linker_instance:program() ~= depinfo.program then + if program ~= depinfo.program then return true end -- the flags has been modified? - return os.args(linker_instance:linkflags({target = target})) ~= os.args(depinfo.flags) + return os.args(linkflags) ~= os.args(depinfo.flags) end -- build target from objects @@ -68,9 +68,15 @@ function _build_from_objects(target, buildinfo) -- load linker instance local linker_instance = linker.load(target:targetkind(), target:sourcekinds()) + -- get program + local program = linker_instance:program() + + -- get link flags + local linkflags = linker_instance:linkflags({target = target}) + -- this target and it's deps are not modified? local depfile = target:depfile() - local modified = _is_modified(target, depfile, buildinfo, linker_instance) + local modified = _is_modified(target, depfile, buildinfo, program, linkflags) if not modified then return end @@ -117,14 +123,14 @@ function _build_from_objects(target, buildinfo) -- trace verbose info if verbose then - print(linker_instance:linkcmd(objectfiles, targetfile, {target = target})) + print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags})) end -- link it - assert(linker_instance:link(objectfiles, targetfile, {target = target})) + assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags})) -- save program and flags to the dependent file - io.save(depfile, {program = linker_instance:program(), flags = linker_instance:linkflags({target = target})}) + io.save(depfile, {program = program, flags = linkflags}) end -- build target from sources diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index a9e8d0d7e..76cafc3f3 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 pairs(target:deps()) do + for _, dep in ipairs(target:orderdeps()) do _run(dep) end end diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 314af0c40..ea5d7f98c 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -294,6 +294,11 @@ function option:deps() return self._DEPS end +-- get option order deps +function option:orderdeps() + return self._ORDERDEPS +end + -- get the option name function option:name() return self._NAME diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index d57721d76..5d9170e1e 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -401,6 +401,22 @@ function project.get(name) end end +-- load deps for option and target +function project._load_deps(target, targets, deps, orderdeps) + + -- get dep targets + for _, dep in ipairs(table.wrap(target:get("deps"))) do + local deptarget = targets[dep] + if deptarget then + project._load_deps(deptarget, targets, deps, orderdeps) + if not deps[dep] then + deps[dep] = deptarget + table.insert(orderdeps, deptarget) + end + end + end +end + -- load targets function project._load_targets() @@ -434,10 +450,9 @@ function project._load_targets() -- load and attach target deps for _, target in pairs(targets) do - target._DEPS = {} - for _, dep in ipairs(table.wrap(target:get("deps"))) do - target._DEPS[dep] = targets[dep] - end + target._DEPS = target._DEPS or {} + target._ORDERDEPS = target._ORDERDEPS or {} + project._load_deps(target, targets, target._DEPS, target._ORDERDEPS) end -- enter toolchains environment @@ -517,10 +532,9 @@ function project._load_options(disable_filter) -- load and attach options deps for _, opt in pairs(options) do - opt._DEPS = {} - for _, dep in ipairs(table.wrap(opt:get("deps"))) do - opt._DEPS[dep] = options[dep] - end + opt._DEPS = opt._DEPS or {} + opt._ORDERDEPS = opt._ORDERDEPS or {} + project._load_deps(opt, options, opt._DEPS, opt._ORDERDEPS) end -- ok? diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index eac740619..2e98206c6 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -164,6 +164,11 @@ function target:deps() return self._DEPS end +-- get target order deps +function target:orderdeps() + return self._ORDERDEPS +end + -- is phony target? function target:isphony() diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 84ef22838..e648a67d0 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -176,7 +176,12 @@ end function builder:_addflags_from_targetdeps(results, target, flagname) -- for all target deps - for _, dep in pairs(target:deps()) do + local orderdeps = target:orderdeps() + local total = #orderdeps + for idx, _ in ipairs(orderdeps) do + + -- reverse deps order for links + local dep = orderdeps[total + 1 - idx] -- is static or shared target library? link it local depkind = dep:get("kind") |
