summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-10-26 22:47:08 +0800
committerruki <[email protected]>2018-10-26 10:42:49 +0800
commitbc3459d5969a9f8956c2387f04bd6519650532ad (patch)
tree17c967c715c55669607db879a8edbbe05f034f60
parentfc38095c1ead23191a6911d448950e6f6ab6e00b (diff)
improve compilation dependences
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/actions/build/kinds/binary.lua25
-rw-r--r--xmake/actions/build/kinds/shared.lua41
-rw-r--r--xmake/actions/build/kinds/static.lua30
-rw-r--r--xmake/modules/core/project/depend.lua12
5 files changed, 63 insertions, 47 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6327f4802..ff25aed0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
### Changes
* [#229](https://github.com/tboox/xmake/issues/229): Improve to select toolset for vcproj plugin
+* Improve compilation dependences
## v2.2.2
@@ -505,6 +506,7 @@
### 改进
* [#229](https://github.com/tboox/xmake/issues/229): 改进vs toolset选择已经vcproj工程文件生成
+* 改进编译依赖,对源文件列表的改动进行依赖判断
## v2.2.2
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index 092731449..fe8e4a446 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -45,12 +45,6 @@ function _build_from_objects(target, buildinfo)
local dependfile = target:dependfile()
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
- -- need build this target?
- local depvalues = {linkinst:program(), linkflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
- return
- end
-
-- expand object files with *.o/obj
local objectfiles = {}
for _, objectfile in ipairs(target:objectfiles()) do
@@ -64,6 +58,18 @@ function _build_from_objects(target, buildinfo)
end
end
+ -- need build this target?
+ local depfiles = target:objectfiles()
+ for _, dep in pairs(target:deps()) do
+ if dep:targetkind() == "static" then
+ table.insert(depfiles, dep:targetfile())
+ end
+ end
+ local depvalues = {linkinst:program(), linkflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles}) then
+ return
+ end
+
-- the target file
local targetfile = target:targetfile()
@@ -90,13 +96,8 @@ function _build_from_objects(target, buildinfo)
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
+ dependinfo.files = depfiles
dependinfo.values = depvalues
- dependinfo.files = target:objectfiles()
- for _, dep in pairs(target:deps()) do
- if dep:targetkind() == "static" then
- table.insert(dependinfo.files, dep:targetfile())
- end
- end
depend.save(dependinfo, dependfile)
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 6e9140d13..176373773 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -45,9 +45,28 @@ function _build_from_objects(target, buildinfo)
local dependfile = target:dependfile()
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ -- expand object files with *.o/obj
+ local objectfiles = {}
+ for _, objectfile in ipairs(target:objectfiles()) do
+ if objectfile:find("%*") then
+ local matchfiles = os.match(objectfile)
+ if matchfiles then
+ table.join2(objectfiles, matchfiles)
+ end
+ else
+ table.insert(objectfiles, objectfile)
+ end
+ end
+
-- need build this target?
+ local depfiles = target:objectfiles()
+ for _, dep in pairs(target:deps()) do
+ if dep:targetkind() == "static" then
+ table.insert(depfiles, dep:targetfile())
+ end
+ end
local depvalues = {linkinst:program(), linkflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles}) then
return
end
@@ -64,19 +83,6 @@ function _build_from_objects(target, buildinfo)
end
end
- -- expand object files with *.o/obj
- local objectfiles = {}
- for _, objectfile in ipairs(target:objectfiles()) do
- if objectfile:find("%*") then
- local matchfiles = os.match(objectfile)
- if matchfiles then
- table.join2(objectfiles, matchfiles)
- end
- else
- table.insert(objectfiles, objectfile)
- end
- end
-
-- the target file
local targetfile = target:targetfile()
@@ -103,13 +109,8 @@ function _build_from_objects(target, buildinfo)
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
+ dependinfo.files = depfiles
dependinfo.values = depvalues
- dependinfo.files = target:objectfiles()
- for _, dep in pairs(target:deps()) do
- if dep:targetkind() == "static" then
- table.insert(dependinfo.files, dep:targetfile())
- end
- end
depend.save(dependinfo, dependfile)
end
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index e50be8b78..8e93ab310 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -45,9 +45,23 @@ function _build_from_objects(target, buildinfo)
local dependfile = target:dependfile()
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ -- expand object files with *.o/obj
+ local objectfiles = {}
+ for _, objectfile in ipairs(target:objectfiles()) do
+ if objectfile:find("%*") then
+ local matchfiles = os.match(objectfile)
+ if matchfiles then
+ table.join2(objectfiles, matchfiles)
+ end
+ else
+ table.insert(objectfiles, objectfile)
+ end
+ end
+
-- need build this target?
+ local depfiles = target:objectfiles()
local depvalues = {linkinst:program(), linkflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles}) then
return
end
@@ -64,18 +78,6 @@ function _build_from_objects(target, buildinfo)
end
end
- -- expand object files with *.o/obj
- local objectfiles = {}
- for _, objectfile in ipairs(target:objectfiles()) do
- if objectfile:find("%*") then
- local matchfiles = os.match(objectfile)
- if matchfiles then
- table.join2(objectfiles, matchfiles)
- end
- else
- table.insert(objectfiles, objectfile)
- end
- end
-- the target file
local targetfile = target:targetfile()
@@ -103,8 +105,8 @@ function _build_from_objects(target, buildinfo)
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
+ dependinfo.files = depfiles
dependinfo.values = depvalues
- dependinfo.files = target:objectfiles()
depend.save(dependinfo, dependfile)
end
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index 277601506..aa2dc7afa 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -60,7 +60,7 @@ function is_changed(dependinfo, opt)
lastmtime = lastmtime or opt.lastmtime or 0
-- source and header files have been changed?
- if os.mtime(file) > lastmtime then
+ if not os.isfile(file) or os.mtime(file) > lastmtime then
-- mark this file as changed
_g.file_results[file] = true
@@ -98,4 +98,14 @@ function is_changed(dependinfo, opt)
end
end
end
+
+ -- check the dependent files list are changed?
+ local optfiles = opt.files
+ if optfiles then
+ for idx, file in ipairs(files) do
+ if file ~= optfiles[idx] then
+ return true
+ end
+ end
+ end
end