diff options
| author | ruki <[email protected]> | 2018-05-09 00:39:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-08 21:54:32 +0800 |
| commit | 87a3262733fb60ab6262893d55ca4b5d0e1b516c (patch) | |
| tree | 21d081c4d84d483c58ae9fb870eae36a2decf4f1 | |
| parent | b5333b27b79f7cabbdc8d75356b2de118f9ea744 (diff) | |
improve qt build deps
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 63 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 18 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 55 |
8 files changed, 96 insertions, 56 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index 528fc5502..d9b451cc0 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -70,7 +70,7 @@ function _build_from_objects(target, buildinfo) -- is verbose? local verbose = option.get("verbose") - -- trace percent into + -- trace progress into cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) @@ -109,7 +109,7 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- is verbose? local verbose = option.get("verbose") - -- trace percent into + -- trace progress into cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 8cbb0aebf..24a8a33b6 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -34,16 +34,16 @@ import("core.language.language") import("detect.tools.find_ccache") -- build the object from the *.[o|obj] source file -function _build_from_object(target, sourcefile, objectfile, percent) +function _build_from_object(target, sourcefile, objectfile, progress) -- is verbose? local verbose = option.get("verbose") - -- trace percent info + -- trace progress info if verbose then - cprint("${green}[%02d%%]: ${dim magenta}inserting.$(mode) %s", percent, sourcefile) + cprint("${green}[%02d%%]: ${dim magenta}inserting.$(mode) %s", progress, sourcefile) else - cprint("${green}[%02d%%]: ${magenta}inserting.$(mode) %s", percent, sourcefile) + cprint("${green}[%02d%%]: ${magenta}inserting.$(mode) %s", progress, sourcefile) end -- trace verbose info @@ -59,16 +59,16 @@ function _build_from_object(target, sourcefile, objectfile, percent) end -- build the object from the *.[a|lib] source file -function _build_from_static(target, sourcefile, objectfile, percent) +function _build_from_static(target, sourcefile, objectfile, progress) -- is verbose? local verbose = option.get("verbose") - -- trace percent info + -- trace progress info if verbose then - cprint("${green}[%02d%%]: ${dim magenta}inserting.$(mode) %s", percent, sourcefile) + cprint("${green}[%02d%%]: ${dim magenta}inserting.$(mode) %s", progress, sourcefile) else - cprint("${green}[%02d%%]: ${magenta}inserting.$(mode) %s", percent, sourcefile) + cprint("${green}[%02d%%]: ${magenta}inserting.$(mode) %s", progress, sourcefile) end -- trace verbose info @@ -92,15 +92,15 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache) local dependfile = sourcebatch.dependfiles[index] local sourcekind = sourcebatch.sourcekind - -- calculate percent - local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) + -- calculate progress + local progress = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) -- build the object for the *.o/obj source makefile if sourcekind == "obj" then - return _build_from_object(target, sourcefile, objectfile, percent) + return _build_from_object(target, sourcefile, objectfile, progress) -- build the object for the *.[a|lib] source file elseif sourcekind == "lib" then - return _build_from_static(target, sourcefile, objectfile, percent) + return _build_from_static(target, sourcefile, objectfile, progress) end -- load compiler @@ -121,11 +121,11 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache) -- is verbose? local verbose = option.get("verbose") - -- trace percent info + -- trace progress info if verbose then - cprint("${green}[%02d%%]:${dim} %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) + cprint("${green}[%02d%%]:${dim} %scompiling.$(mode) %s", progress, ifelse(ccache, "ccache ", ""), sourcefile) else - cprint("${green}[%02d%%]:${clear} %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) + cprint("${green}[%02d%%]:${clear} %scompiling.$(mode) %s", progress, ifelse(ccache, "ccache ", ""), sourcefile) end -- trace verbose info @@ -176,17 +176,17 @@ function _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs, local objectfiles = sourcebatch.objectfiles local dependfiles = sourcebatch.dependfiles - -- trace percent info + -- trace progress info for index, sourcefile in ipairs(sourcefiles) do - -- calculate percent - local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) + -- calculate progress + local progress = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) - -- trace percent info + -- trace progress info if verbose then - cprint("${green}[%02d%%]:${clear} ${dim}%scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) + cprint("${green}[%02d%%]:${clear} ${dim}%scompiling.$(mode) %s", progress, ifelse(ccache, "ccache ", ""), sourcefile) else - cprint("${green}[%02d%%]:${clear} %scompiling.$(mode) %s", percent, ifelse(ccache, "ccache ", ""), sourcefile) + cprint("${green}[%02d%%]:${clear} %scompiling.$(mode) %s", progress, ifelse(ccache, "ccache ", ""), sourcefile) end end @@ -240,7 +240,12 @@ function _build_files_with_rule(target, buildinfo, sourcebatch, jobs, suffix) -- on_build_files? local on_build_files = ruleinst:script("build_files" .. (suffix and ("_" .. suffix) or "")) if on_build_files then - on_build_files(target, sourcebatch.sourcefiles) + + -- calculate progress + local progress = (buildinfo.targetindex + _g.sourceindex / _g.sourcecount) * 100 / buildinfo.targetcount + + -- do build files + on_build_files(target, sourcebatch.sourcefiles, {progress = progress}) else -- get the build file script local on_build_file = ruleinst:script("build_file" .. (suffix and ("_" .. suffix) or "")) @@ -253,24 +258,18 @@ function _build_files_with_rule(target, buildinfo, sourcebatch, jobs, suffix) -- force to set the current directory first because the other jobs maybe changed it os.cd(curdir) - -- calculate percent - local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) + -- calculate progress + local progress = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) if suffix then - percent = ((buildinfo.targetindex + (suffix == "before" and _g.sourceindex or _g.sourcecount) / _g.sourcecount) * 100 / buildinfo.targetcount) + progress = ((buildinfo.targetindex + (suffix == "before" and _g.sourceindex or _g.sourcecount) / _g.sourcecount) * 100 / buildinfo.targetcount) end -- the source file local sourcefile = sourcebatch.sourcefiles[index] - -- trace percent info - if option.get("verbose") then - cprint("${green}[%02d%%]:${dim} compiling.%s %s", percent, rulename, sourcefile) - else - cprint("${green}[%02d%%]:${clear} compiling.%s %s", percent, rulename, sourcefile) - end -- do build file - on_build_file(target, sourcefile) + on_build_file(target, sourcefile, {progress = progress}) end, #sourcebatch.sourcefiles, jobs) end diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 4c3031196..9d04589b7 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -83,7 +83,7 @@ function _build_from_objects(target, buildinfo) -- is verbose? local verbose = option.get("verbose") - -- trace percent info + -- trace progress info cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) @@ -122,7 +122,7 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- is verbose? local verbose = option.get("verbose") - -- trace percent into + -- trace progress into cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index a46e899d6..35ee41276 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -83,7 +83,7 @@ function _build_from_objects(target, buildinfo) -- is verbose? local verbose = option.get("verbose") - -- trace percent info + -- trace progress info cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}archiving.$(mode) %s", path.filename(targetfile)) @@ -117,7 +117,7 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- is verbose? local verbose = option.get("verbose") - -- trace percent into + -- trace progress into cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}archiving.$(mode) %s", path.filename(targetfile)) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 449f90eb4..1452413d7 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -842,9 +842,21 @@ function target:dependfile(objectfile) return path.join(self:dependir(), self:name() .. ".d") end - -- get object depend file - local depentfile = path.join(self:dependir(), path.relative(objectfile, self:objectdir())) - return path.join(path.directory(depentfile), path.basename(depentfile) .. ".d") + -- get the relative object directory + local objectdir = path.directory(path.relative(objectfile, self:objectdir())) + if path.is_absolute(objectdir) and os.host() == "windows" then + objectdir = objectdir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\ + end + + -- objectfile: project/build/.objs/xxxx/../../xxx.c will be out of range for objectdir + -- + -- we need replace '..' to '__' in this case + -- + objectdir = objectdir:gsub("%.%.", "__") + + -- make dependent file + -- full file name(not base) to avoid name-clash of object file + return path.join(self:dependir(), objectdir, path.basename(objectfile) .. ".d") end -- get the dependent include files diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index c9286a80b..2cdb3ca72 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -320,7 +320,7 @@ function _include_deps(self, outdata) includefile = path.relative(includefile, project.directory()) -- save it if belong to the project - if not path.is_absolute(includefile) then + if path.absolute(includefile):startswith(os.projectdir()) then -- insert it and filter repeat if not uniques[includefile] then diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index e0fa9a188..879232535 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -351,7 +351,7 @@ function _include_deps(self, sourcefile, flags) for includefile in string.gmatch(deps, "%s+([%w/%.%-%+_%$%.]+)") do -- save it if belong to the project - if not path.is_absolute(includefile) then + if path.absolute(includefile):startswith(os.projectdir()) then table.insert(results, includefile) end end diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index b8e7ec3c5..fbc147203 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -70,10 +70,12 @@ rule("qt.ui") end) -- before build file - before_build_file(function (target, sourcefile_ui) + before_build_file(function (target, sourcefile_ui, opt) -- imports + import("core.base.option") import("core.project.config") + import("core.project.depend") -- get uic local uic = target:data("qt.uic") @@ -81,6 +83,28 @@ rule("qt.ui") -- get c++ header file for ui local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h") local headerfile_dir = path.directory(headerfile_ui) + + -- add includedirs + target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) + + -- add clean files + target:data_add("qt.cleanfiles", headerfile_ui) + + -- need build this object? + local dependfile = target:dependfile(headerfile_ui) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(headerfile_ui)}) then + return + end + + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.ui %s", opt.progress, sourcefile_ui) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.ui %s", opt.progress, sourcefile_ui) + end + + -- ensure ui header file directory if not os.isdir(headerfile_dir) then os.mkdir(headerfile_dir) end @@ -88,11 +112,9 @@ rule("qt.ui") -- compile ui os.vrunv(uic, {sourcefile_ui, "-o", headerfile_ui}) - -- add includedirs - target:add("includedirs", path.absolute(headerfile_dir, os.projectdir())) - - -- add clean files - target:data_add("qt.cleanfiles", headerfile_ui) + -- update files and values to the dependent file + dependinfo.files = {sourcefile_ui} + depend.save(dependinfo, dependfile) end) -- define rule: moc @@ -116,7 +138,7 @@ rule("qt.moc") end) -- on build file - on_build_file(function (target, headerfile_moc) + on_build_file(function (target, headerfile_moc, opt) -- imports import("moc") @@ -137,6 +159,12 @@ rule("qt.moc") -- get compile flags local compflags = compinst:compflags({target = target, sourcefile = sourcefile_moc}) + -- add objectfile + table.insert(target:objectfiles(), objectfile) + + -- add clean files + target:data_add("qt.cleanfiles", {sourcefile_moc, objectfile}) + -- load dependent info local dependfile = target:dependfile(objectfile) local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) @@ -147,6 +175,13 @@ rule("qt.moc") return end + -- trace progress info + if option.get("verbose") then + cprint("${green}[%02d%%]:${dim} compiling.qt.moc %s", opt.progress, headerfile_moc) + else + cprint("${green}[%02d%%]:${clear} compiling.qt.moc %s", opt.progress, headerfile_moc) + end + -- generate c++ source file for moc moc.generate(target, headerfile_moc, sourcefile_moc) @@ -159,12 +194,6 @@ rule("qt.moc") 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) |
