diff options
| author | ruki <[email protected]> | 2016-07-10 10:18:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-10 10:18:05 +0800 |
| commit | fd39adb3d959e605370098a72ec7e92b462fce62 (patch) | |
| tree | 392b866ab32e33cae167c95daa7bff7cfbb9767c | |
| parent | 4d2231a5136ddf5dca5398feaccc2d82bb56e1e0 (diff) | |
check include dependence
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 22 | ||||
| -rwxr-xr-x | xmake/actions/clean/main.lua | 3 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 28 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 4 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/cl.lua | 2 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua | 26 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 2 |
9 files changed, 81 insertions, 16 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 4750add95..a1adb5d0f 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -63,13 +63,31 @@ function _build(target, g, index) -- the object and source files local objectfiles = target:objectfiles() local sourcefiles = target:sourcefiles() + local incdepfiles = target:incdepfiles() -- get the object and source with the given index local sourcefile = sourcefiles[index] local objectfile = objectfiles[index] + local incdepfile = incdepfiles[index] + + -- get dependent files + local depfiles = {} + if incdepfile and os.isfile(incdepfile) then + depfiles = io.load(incdepfile) + end + table.insert(depfiles, sourcefile) + + -- check the dependent files are modified? + local modified = false + for _, depfile in ipairs(depfiles) do + if os.mtime(depfile) > os.mtime(objectfile) then + modified = true + break + end + end -- we need not rebuild it if the files are not modified - if os.mtime(sourcefile) < os.mtime(objectfile) then + if not modified then return end @@ -102,7 +120,7 @@ function _build(target, g, index) end -- complie it and enable multitasking - compiler.compile(sourcefile, objectfile, target, true) + compiler.compile(sourcefile, objectfile, incdepfile, target, true) end -- build objects for the given target diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 18ddea50d..82bfce253 100755 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -65,6 +65,9 @@ function _on_clean_target(target) -- remove the object files _remove(target:objectfiles()) + -- remove the incdep files + _remove(target:incdepfiles()) + -- remove the header files local _, dstheaders = target:headerfiles() _remove(dstheaders) diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 1d554d887..af727808f 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -94,7 +94,7 @@ function option:_check_include(include, srcpath, objpath) end -- attempt to run this command - local ok, errors = instance:compile(srcpath, objpath, self) + local ok, errors = instance:compile(srcpath, objpath, nil, self) if not ok and option_.get("verbose") then print(errors) end @@ -148,7 +148,7 @@ function option:_check_function(checkcode, srcpath, objpath) srcfile:close() -- execute the compile command - local ok, errors = instance:compile(srcpath, objpath, self) + local ok, errors = instance:compile(srcpath, objpath, nil, self) if not ok and option_.get("verbose") then print(errors) end @@ -202,7 +202,7 @@ function option:_check_typedef(typedef, srcpath, objpath) srcfile:close() -- execute the compile command - local ok, errors = instance:compile(srcpath, objpath, self) + local ok, errors = instance:compile(srcpath, objpath, nil, self) if not ok and option_.get("verbose") then print(errors) end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 5e3669c69..27d4e926b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -358,6 +358,34 @@ function target:headerfiles(outputdir) return srcheaders, dstheaders end +-- get the dependent include files +function target:incdepfiles() + + -- the previous object files + local objectfiles_prev = self._OBJECTFILES + + -- the object files + local objectfiles = self:objectfiles() + + -- cached? return it directly + local modified = objectfiles_prev ~= objectfiles + if self._INCDEPFILES and not modified then + return self._INCDEPFILES + end + + -- make include files + local incdepfiles = {} + for _, objectfile in ipairs(objectfiles) do + table.insert(incdepfiles, path.join(path.directory(objectfile), path.basename(objectfile) .. ".d")) + end + + -- cache it + self._INCDEPFILES = incdepfiles + + -- ok + return incdepfiles +end + -- get the kinds of sourcefiles -- -- .e.g cc cxx mm mxx as ... diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 71059ad16..340b32734 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -42,7 +42,7 @@ function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target) end -- compile source file -function sandbox_core_tool_compiler.compile(sourcefile, objectfile, target, multitasking) +function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target, multitasking) -- get the compiler instance local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) @@ -51,7 +51,7 @@ function sandbox_core_tool_compiler.compile(sourcefile, objectfile, target, mult end -- compile it - local ok, errors = instance:compile(sourcefile, objectfile, target, multitasking) + local ok, errors = instance:compile(sourcefile, objectfile, incdepfile, target, multitasking) if not ok then raise(errors) end diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index bb4aa2455..a523af449 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -399,7 +399,7 @@ function compiler:get(name) end -- compile the source file -function compiler:compile(sourcefile, objectfile, target, multitasking) +function compiler:compile(sourcefile, objectfile, incdepfile, target, multitasking) -- get flags local flags = nil @@ -408,7 +408,7 @@ function compiler:compile(sourcefile, objectfile, target, multitasking) end -- compile it - return sandbox.load(self:_tool().compile, sourcefile, objectfile, flags or "", multitasking) + return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, flags or "", multitasking) end -- get the compile command diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua index c71111300..30d30a6f3 100755 --- a/xmake/tools/cl.lua +++ b/xmake/tools/cl.lua @@ -112,7 +112,7 @@ function compcmd(sourcefile, objectfile, flags) end -- complie the source file -function compile(sourcefile, objectfile, flags, multitasking) +function compile(sourcefile, objectfile, incdepfile, flags, multitasking) -- ensure the object directory os.mkdir(path.directory(objectfile)) diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index 5019aa06f..85bc7a379 100755 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -142,16 +142,32 @@ function link(objectfiles, targetfile, flags) end -- complie the source file -function compile(sourcefile, objectfile, flags, multitasking) +function compile(sourcefile, objectfile, incdepfile, flags, multitasking) -- ensure the object directory os.mkdir(path.directory(objectfile)) + -- run function + local run = ifelse(multitasking, os.corun, os.run) + -- compile it - if multitasking then - os.corun(compcmd(sourcefile, objectfile, flags)) - else - os.run(compcmd(sourcefile, objectfile, flags)) + run(compcmd(sourcefile, objectfile, flags)) + + -- generate includes file + if incdepfile then + + -- generate it + run(compcmd(sourcefile, incdepfile, flags .. " -MM")) + + -- translate it + local results = {} + local incdeps = io.read(incdepfile) + for includefile in string.gmatch(incdeps, "([%w|/|%.|%-|%+|_|%$]-%.[h|hpp])") do + table.insert(results, includefile) + end + + -- update it + io.save(incdepfile, results) end end diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index 9f7842440..49b9476b2 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -94,7 +94,7 @@ function compcmd(sourcefile, objectfile, flags) end -- complie the source file -function compile(sourcefile, objectfile, flags, multitasking) +function compile(sourcefile, objectfile, incdepfile, flags, multitasking) -- ensure the object directory os.mkdir(path.directory(objectfile)) |
