diff options
| author | ruki <[email protected]> | 2016-03-25 15:37:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-25 15:37:20 +0800 |
| commit | f5bf28c7da5c0f5987fc06a0c67f8773535aa7ed (patch) | |
| tree | 67491b53da1eff916954a4670944a71191d5efee | |
| parent | df4bd403becbdd74b13cf92bd906d0d1caa9908c (diff) | |
reimpl clean action
| -rwxr-xr-x | xmake/actions/clean/main.lua | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index a46742b05..120c39bab 100755 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -27,6 +27,102 @@ import("core.project.global") import("core.project.project") import("core.platform.platform") +-- remove the given files or directories +function _remove(filedirs) + + -- done + for _, filedir in ipairs(filedirs) do + + -- exists? remove it + if os.exists(filedir) then + + -- remove it + os.rm(filedir) + + -- remove "*.o/obj" files? + elseif filedir:find("%*") then + + -- match all files + for _, file in ipairs(os.match(filedir)) do + + -- remove it + os.rm(file) + + end + end + end +end + +-- clean the given target files +function _clean_target(target) + + -- remove the target file + _remove(target:targetfile()) + + -- remove the object files + _remove(target:objectfiles()) + + -- remove the header files + local _, dstheaders = target:headerfiles() + _remove(dstheaders) + + -- remove all? + if option.get("all") then + + -- remove the config.h file + _remove(target:get("config_h")) + end + +end + +-- clean the given target and all dependent targets +function _clean_target_and_deps(target) + + -- remove the target + _clean_target(target) + + -- exists the dependent targets? + for _, dep in ipairs(target:get("deps")) do + _clean_target_and_deps(project.target(dep)) + end + +end + +-- clean the given target +function _clean(targetname) + + -- the target name + if targetname and targetname ~= "all" then + + -- clean target + _clean_target_and_deps(project.target(targetname)) + + else + + -- clean targets + for _, target in pairs(project.targets()) do + _clean_target(target) + end + end + + -- remove all + if option.get("all") then + + -- remove makefile + _remove("$(buildir)/makefile") + + -- remove the configure directory + _remove(config.directory()) + + -- remove the log file + _remove("$(buildir)/.build.log") + + -- remove build directory if be empty + os.rm("$(buildir)", true) + end + +end + -- main function main() @@ -58,6 +154,9 @@ function main() -- enter project directory os.cd(project.directory()) + -- clean the current target + _clean(targetname) + -- leave project directory os.cd("-") |
