summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-14 17:10:32 +0800
committerruki <[email protected]>2020-11-14 17:10:32 +0800
commit76dc49d6ea92fa8d22f24725de7e661f55bce3ca (patch)
tree07f553884a5a5d9eaa5746f4ab33403c213aa2c6
parent5643311ff8d29840261853b4b21c653d169b0b8f (diff)
fix dry-run build
-rw-r--r--xmake/actions/build/build.lua2
-rw-r--r--xmake/actions/build/kinds/binary.lua5
-rw-r--r--xmake/actions/build/kinds/shared.lua23
-rw-r--r--xmake/actions/build/kinds/static.lua24
-rw-r--r--xmake/modules/core/project/depend.lua12
-rw-r--r--xmake/modules/private/action/build/object.lua21
6 files changed, 52 insertions, 35 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 2b6953ceb..0e32dc847 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -139,7 +139,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
end
-- clean target if rebuild
- if option.get("rebuild") then
+ if option.get("rebuild") and not option.get("dry-run") then
_clean_target(target)
end
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index 38fb73bc6..e641dcb66 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -49,6 +49,7 @@ function _do_link_target(target, opt)
table.insert(depfiles, dep:targetfile())
end
end
+ local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
@@ -68,11 +69,11 @@ function _do_link_target(target, opt)
end
-- link it
- if not option.get("dry-run") then
+ if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
- end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles})
+ end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles, always_changed = dryrun})
end
-- on link the given target
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 2a07ad779..0ed91cdb7 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -49,19 +49,22 @@ function _do_link_target(target, opt)
table.insert(depfiles, dep:targetfile())
end
end
+ local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
-- TODO make headers (deprecated)
- local srcheaders, dstheaders = target:headers()
- if srcheaders and dstheaders then
- local i = 1
- for _, srcheader in ipairs(srcheaders) do
- local dstheader = dstheaders[i]
- if dstheader then
- os.cp(srcheader, dstheader)
+ if not dryrun then
+ local srcheaders, dstheaders = target:headers()
+ if srcheaders and dstheaders then
+ local i = 1
+ for _, srcheader in ipairs(srcheaders) do
+ local dstheader = dstheaders[i]
+ if dstheader then
+ os.cp(srcheader, dstheader)
+ end
+ i = i + 1
end
- i = i + 1
end
end
@@ -81,11 +84,11 @@ function _do_link_target(target, opt)
end
-- link it
- if not option.get("dry-run") then
+ if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
- end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles})
+ end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles, always_changed = dryrun})
end
-- on link the given target
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 0b34f68ea..9fe39e1b5 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -49,23 +49,25 @@ function _do_link_target(target, opt)
table.insert(depfiles, dep:targetfile())
end
end
+ local dryrun = option.get("dry-run")
local depvalues = {linkinst:program(), linkflags}
depend.on_changed(function ()
-- TODO make headers (deprecated)
- local srcheaders, dstheaders = target:headers()
- if srcheaders and dstheaders then
- local i = 1
- for _, srcheader in ipairs(srcheaders) do
- local dstheader = dstheaders[i]
- if dstheader then
- os.cp(srcheader, dstheader)
+ if not dryrun then
+ local srcheaders, dstheaders = target:headers()
+ if srcheaders and dstheaders then
+ local i = 1
+ for _, srcheader in ipairs(srcheaders) do
+ local dstheader = dstheaders[i]
+ if dstheader then
+ os.cp(srcheader, dstheader)
+ end
+ i = i + 1
end
- i = i + 1
end
end
-
-- the target file
local targetfile = target:targetfile()
@@ -82,11 +84,11 @@ function _do_link_target(target, opt)
end
-- link it
- if not option.get("dry-run") then
+ if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
end
- end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles})
+ end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles, always_changed = dryrun})
end
-- on link the given target
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index 05065e0b0..f55e0bdfc 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -150,12 +150,20 @@ end
--
-- end, {dependfile = "/xx/xx",
-- values = {compinst:program(), compflags},
--- files = {sourcefile, ...}})
+-- files = {sourcefile, ...},
+-- always_changed = false})
--
function on_changed(callback, opt)
- -- get files
+ -- init option
opt = opt or {}
+
+ -- always changed? we only do callback directly
+ if opt.always_changed then
+ return callback()
+ end
+
+ -- get files
assert(opt.files, "depend.on_changed(): please set files list!")
-- get dependfile
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index 357c58aea..9164ee08c 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -44,11 +44,14 @@ function _do_build_file(target, sourcefile, opt)
-- load dependent info
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ -- dry run?
+ local dryrun = option.get("dry-run")
+
-- need build this object?
-- @note we use mtime(dependfile) instead of mtime(objectfile) to ensure the object file is is fully compiled.
-- @see https://github.com/xmake-io/xmake/issues/748
local depvalues = {compinst:program(), compflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(dependfile), values = depvalues}) then
+ if not dryrun and not depend.is_changed(dependinfo, {lastmtime = os.mtime(dependfile), values = depvalues}) then
return
end
@@ -68,17 +71,17 @@ function _do_build_file(target, sourcefile, opt)
-- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows
print(compinst:compcmd(sourcefile, objectfile, {compflags = compflags, rawargs = true}))
end
+ if not dryrun then
- -- compile it
- dependinfo.files = {}
- if not option.get("dry-run") then
+ -- do compile
+ dependinfo.files = {}
assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags}))
- end
- -- update files and values to the dependent file
- dependinfo.values = depvalues
- table.join2(dependinfo.files, sourcefile, target:pcoutputfile("cxx") or {}, target:pcoutputfile("c"))
- depend.save(dependinfo, dependfile)
+ -- update files and values to the dependent file
+ dependinfo.values = depvalues
+ table.join2(dependinfo.files, sourcefile, target:pcoutputfile("cxx") or {}, target:pcoutputfile("c"))
+ depend.save(dependinfo, dependfile)
+ end
end
-- build object