summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-08 22:52:49 +0800
committerruki <[email protected]>2018-05-08 11:16:55 +0800
commitb5333b27b79f7cabbdc8d75356b2de118f9ea744 (patch)
treef4cb719e259ae64b6a48ab35a425eb0db76cd3ab
parentc61545b0275b64c8b0294ce69e635e30475a2239 (diff)
improve build deps
-rw-r--r--tests/projects/c/static_library/src/interface.c2
-rw-r--r--xmake/actions/build/builder.lua7
-rw-r--r--xmake/actions/build/kinds/binary.lua17
-rw-r--r--xmake/actions/build/kinds/object.lua23
-rw-r--r--xmake/actions/build/kinds/shared.lua17
-rw-r--r--xmake/actions/build/kinds/static.lua17
-rw-r--r--xmake/actions/build/main.lua4
-rw-r--r--xmake/modules/core/project/depend.lua11
-rw-r--r--xmake/rules/qt/xmake.lua33
9 files changed, 73 insertions, 58 deletions
diff --git a/tests/projects/c/static_library/src/interface.c b/tests/projects/c/static_library/src/interface.c
index 8ed513871..598d07560 100644
--- a/tests/projects/c/static_library/src/interface.c
+++ b/tests/projects/c/static_library/src/interface.c
@@ -1,5 +1,5 @@
#include "interface.h"
-
+
int add(int a, int b)
{
return a + b;
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index b8ad09fdc..d69322da1 100644
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -84,7 +84,7 @@ function _build_target(target)
}
-- clean target if rebuild
- if _g.rebuild then
+ if option.get("rebuild") then
_clean_target(target)
end
@@ -164,7 +164,7 @@ function _stat_target_count(targetname)
end
-- build
-function build(targetname, rebuild)
+function build(targetname)
-- enter toolchains environment
environment.enter("toolchains")
@@ -172,9 +172,6 @@ function build(targetname, rebuild)
-- stat targets count
_stat_target_count(targetname)
- -- mark as rebuild
- _g.rebuild = rebuild
-
-- clear finished states
_g.finished = {}
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index 2408ef8a3..528fc5502 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -36,21 +36,18 @@ function _build_from_objects(target, buildinfo)
object.build(target, buildinfo)
-- load linker instance
- local linker_instance = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
+ local linkinst = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
-- get link flags
- local linkflags = linker_instance:linkflags({target = target})
+ local linkflags = linkinst:linkflags({target = target})
-- load dependent info
- local dependinfo = {}
local dependfile = target:dependfile()
- if not buildinfo.rebuild then
- dependinfo = depend.load(dependfile) or {}
- end
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
-- need build this target?
- local depvalues = {linker_instance:program(), linkflags}
- if not buildinfo.rebuild and not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
+ local depvalues = {linkinst:program(), linkflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
return
end
@@ -83,14 +80,14 @@ function _build_from_objects(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
+ print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
end
-- flush io buffer to update progress info
io.flush()
-- link it
- assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags}))
+ assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
dependinfo.values = depvalues
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 9734363eb..8cbb0aebf 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -103,21 +103,18 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
return _build_from_static(target, sourcefile, objectfile, percent)
end
- -- load dependent info
- local dependinfo = {}
- if not buildinfo.rebuild then
- dependinfo = depend.load(dependfile) or {}
- end
-
- -- load compiler instance
- local compiler_instance = compiler.load(sourcekind, {target = target})
+ -- load compiler
+ local compinst = compiler.load(sourcekind, {target = target})
-- get compile flags
- local compflags = compiler_instance:compflags({target = target, sourcefile = sourcefile})
+ local compflags = compinst:compflags({target = target, sourcefile = sourcefile})
+ -- load dependent info
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+
-- need build this object?
- local depvalues = {compiler_instance:program(), compflags}
- if not buildinfo.rebuild and not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then
+ local depvalues = {compinst:program(), compflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then
return
end
@@ -133,7 +130,7 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
-- trace verbose info
if verbose then
- print(compiler_instance:compcmd(sourcefile, objectfile, {compflags = compflags}))
+ print(compinst:compcmd(sourcefile, objectfile, {compflags = compflags}))
end
-- flush io buffer to update progress info
@@ -141,7 +138,7 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache)
-- complie it
dependinfo.files = {}
- assert(compiler_instance:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags}))
+ assert(compinst:compile(sourcefile, objectfile, {dependinfo = dependinfo, compflags = compflags}))
-- update files and values to the dependent file
dependinfo.values = depvalues
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 043e3dc36..4c3031196 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -36,21 +36,18 @@ function _build_from_objects(target, buildinfo)
object.build(target, buildinfo)
-- load linker instance
- local linker_instance = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
+ local linkinst = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
-- get link flags
- local linkflags = linker_instance:linkflags({target = target})
+ local linkflags = linkinst:linkflags({target = target})
-- load dependent info
- local dependinfo = {}
local dependfile = target:dependfile()
- if not buildinfo.rebuild then
- dependinfo = depend.load(dependfile) or {}
- end
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
-- need build this target?
- local depvalues = {linker_instance:program(), linkflags}
- if not buildinfo.rebuild and not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
+ local depvalues = {linkinst:program(), linkflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
return
end
@@ -96,14 +93,14 @@ function _build_from_objects(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
+ print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
end
-- flush io buffer to update progress info
io.flush()
-- link it
- assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags}))
+ assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
dependinfo.values = depvalues
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 8606606d6..a46e899d6 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -36,21 +36,18 @@ function _build_from_objects(target, buildinfo)
object.build(target, buildinfo)
-- load linker instance
- local linker_instance = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
+ local linkinst = linker.load(target:targetkind(), target:sourcekinds(), {target = target})
-- get link flags
- local linkflags = linker_instance:linkflags({target = target})
+ local linkflags = linkinst:linkflags({target = target})
-- load dependent info
- local dependinfo = {}
local dependfile = target:dependfile()
- if not buildinfo.rebuild then
- dependinfo = depend.load(dependfile) or {}
- end
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
-- need build this target?
- local depvalues = {linker_instance:program(), linkflags}
- if not buildinfo.rebuild and not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
+ local depvalues = {linkinst:program(), linkflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues}) then
return
end
@@ -96,14 +93,14 @@ function _build_from_objects(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker_instance:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
+ print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags}))
end
-- flush io buffer to update progress info
io.flush()
-- link it
- assert(linker_instance:link(objectfiles, targetfile, {linkflags = linkflags}))
+ assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
-- update files and values to the dependent file
dependinfo.values = depvalues
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index bf3578ab2..6add5aa7b 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -50,7 +50,7 @@ function main()
try
{
function ()
- builder.build(targetname, option.get("rebuild"))
+ builder.build(targetname)
end,
catch
@@ -73,7 +73,7 @@ function main()
os.cd(oldir)
-- trace
- if rebuild then
+ if option.get("rebuild") then
cprint("${bright}build ok!${clear}${ok_hand}")
end
end
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index cbb3d1bd8..277601506 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -40,10 +40,17 @@ end
--
function is_changed(dependinfo, opt)
+ -- empty depend info? always be changed
+ local files = dependinfo.files or {}
+ local values = dependinfo.values or {}
+ if #files == 0 and #values == 0 then
+ return true
+ end
+
-- check the dependent files are changed?
local lastmtime = nil
_g.file_results = _g.file_results or {}
- for _, file in ipairs(dependinfo.files) do
+ for _, file in ipairs(files) do
-- optimization: this file has been not checked?
local status = _g.file_results[file]
@@ -70,7 +77,7 @@ function is_changed(dependinfo, opt)
end
-- check the dependent values are changed?
- local depvalues = dependinfo.values or {}
+ local depvalues = values
local optvalues = opt.values or {}
if #depvalues ~= #optvalues then
return true
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index abd4e9667..b8e7ec3c5 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -123,29 +123,52 @@ rule("qt.moc")
import("core.base.option")
import("core.project.config")
import("core.tool.compiler")
+ import("core.project.depend")
-- get c++ source file for moc
local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp")
- -- generate c++ source file for moc
- moc.generate(target, headerfile_moc, sourcefile_moc)
-
-- get object file
local objectfile = target:objectfile(sourcefile_moc)
+ -- load compiler
+ local compinst = compiler.load("cxx", {target = target})
+
+ -- get compile flags
+ local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc})
+
+ -- load dependent info
+ local dependfile = target:dependfile(objectfile)
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+
+ -- need build this object?
+ local depvalues = {compinst:program(), compflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then
+ return
+ end
+
+ -- generate c++ source file for moc
+ moc.generate(target, headerfile_moc, sourcefile_moc)
+
-- trace
if option.get("verbose") then
- print(compiler.compcmd(sourcefile_moc, objectfile, {target = target}))
+ print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags}))
end
-- compile c++ source file for moc
- compiler.compile(sourcefile_moc, objectfile, {target = target})
+ dependinfo.files = {}
+ compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags})
-- add objectfile
table.insert(target:objectfiles(), objectfile)
-- add clean files
target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile})
+
+ -- update files and values to the dependent file
+ dependinfo.values = depvalues
+ table.insert(dependinfo.files, headerfile_moc)
+ depend.save(dependinfo, dependfile)
end)
-- define rule: *.qrc