summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-14 12:51:00 +0800
committerruki <[email protected]>2020-03-14 12:51:00 +0800
commit31e29aff46694de65721781f8e5085d3a4041ea9 (patch)
tree1cf979c6bf025b301f47febe90b9f9bcea956ede
parent53c89b38d5b41c199e1431184e96235566c6dcc4 (diff)
fix repeat objectfiles
-rw-r--r--tests/apis/rules/xmake.lua10
-rw-r--r--xmake/core/project/target.lua15
2 files changed, 20 insertions, 5 deletions
diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua
index 712a055ef..2b3413922 100644
--- a/tests/apis/rules/xmake.lua
+++ b/tests/apis/rules/xmake.lua
@@ -25,7 +25,10 @@ rule("c code")
before_build_file(function (target, sourcefile)
print("before_build_file: ", sourcefile)
end)
- on_build_file(function (target, sourcefile)
+ on_build_file(function (target, sourcefile, opt)
+ import("core.theme.theme")
+ local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
+ cprint(progress_prefix .. "compiling.$(mode) %s", opt.progress, sourcefile)
local objectfile_o = os.tmpfile() .. ".o"
local sourcefile_c = os.tmpfile() .. ".c"
os.cp(sourcefile, sourcefile_c)
@@ -143,3 +146,8 @@ target("test")
add_files("src/man/*.in", {rule = "man"})
add_files("src/index.md")
add_files("src/test.c.in", {rule = "c code"})
+
+ on_load(function (target)
+ print(target:sourcefiles())
+ print(target:objectfiles())
+ end)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index cb486a025..c6dca9f94 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1069,22 +1069,29 @@ function _instance:objectfiles()
-- get object files from source batches
local objectfiles = {}
+ local batchcount = 0
for _, sourcebatch in pairs(self:sourcebatches()) do
table.join2(objectfiles, sourcebatch.objectfiles)
+ batchcount = batchcount + 1
end
+ -- some object files may be repeat and appear link errors if multi-batches exists, so we need remove all repeat object files
+ -- e.g. add_files("src/*.c", {rules = {"rule1", "rule2"}})
+ local remove_repeat = batchcount > 1
+
-- get object files from all dependent targets (object kind)
if self:orderdeps() then
- local remove_repeat = false
for _, dep in ipairs(self:orderdeps()) do
if dep:targetkind() == "object" then
table.join2(objectfiles, dep:objectfiles())
remove_repeat = true
end
end
- if remove_repeat then
- objectfiles = table.unique(objectfiles)
- end
+ end
+
+ -- remove repeat object files
+ if remove_repeat then
+ objectfiles = table.unique(objectfiles)
end
-- cache it