diff options
| author | ruki <[email protected]> | 2015-05-31 12:06:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-31 12:06:30 +0800 |
| commit | a32ad41a1812ad88043c0ecd0a09301267de9871 (patch) | |
| tree | 1419f0cf04b9e3a845a75d938e41cfab63762d2c | |
| parent | 529a623ed4eadb802b5174db0957c595af32d5e5 (diff) | |
impl clean action
| -rw-r--r-- | xmake/scripts/action/_clean.lua | 111 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 1 | ||||
| -rw-r--r-- | xmake/scripts/tool/mkdir.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/tool/rm.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/tool/rmdir.lua | 4 |
5 files changed, 121 insertions, 3 deletions
diff --git a/xmake/scripts/action/_clean.lua b/xmake/scripts/action/_clean.lua new file mode 100644 index 000000000..e67d1ccd3 --- /dev/null +++ b/xmake/scripts/action/_clean.lua @@ -0,0 +1,111 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file _clean.lua +-- + +-- define module: _clean +local _clean = _clean or {} + +-- load modules +local os = require("base/os") +local utils = require("base/utils") +local config = require("base/config") +local project = require("base/project") + +-- remove the given target +function _clean._rm_target(buildir, target) + + -- check + assert(buildir and target) + + -- the file + local file = string.format("%s/%s", buildir, target) + if not os.exists(file) then + return true + end + + -- clean target + local ok, errors = os.rm(file) + if not ok then + -- error + utils.error(errors) + return false + end + + -- ok + return true +end + +-- remove the given target and all dependent targets +function _clean._rm_target_and_deps(buildir, target) + + -- remove the target + if not _clean._rm_target(buildir, target) then + return false + end + + -- the targets + local targets = project.targets() + assert(targets) + + -- exists the dependent targets? + if targets[target] and targets[target].deps then + local deps = utils.wrap(targets[target].deps) + for _, dep in ipairs(deps) do + if not _clean._rm_target_and_deps(buildir, dep) then return false end + end + end +end + +-- done the given config +function _clean.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- the build directory + local buildir = config.get("buildir") + assert(buildir) + + -- the target + local target = options.target + if target and target ~= "all" then + if not _clean._rm_target_and_deps(buildir, target) then return false end + else + -- the targets + local targets = project.targets() + assert(targets) + + -- clean targets + for target, _ in pairs(targets) do + if not _clean._rm_target(buildir, target) then return false end + end + end + + -- trace + print("clean ok!") + + -- ok + return true +end + +-- return module: _clean +return _clean diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 8a14c1d90..160d65bf7 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -209,6 +209,7 @@ function makefile._make_object(file, target, srcfile, objfile) -- make body file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile)) + file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile))) file:write(string.format("\t@%s\n", c:make(srcfile, objfile, ""))) -- make tail diff --git a/xmake/scripts/tool/mkdir.lua b/xmake/scripts/tool/mkdir.lua index b0c41b310..0cd1eeafe 100644 --- a/xmake/scripts/tool/mkdir.lua +++ b/xmake/scripts/tool/mkdir.lua @@ -23,7 +23,9 @@ -- mkdir all for _, dir in ipairs(...) do if not os.exists(dir) then - os.mkdir(dir) + if not os.mkdir(dir) then + return false + end end end diff --git a/xmake/scripts/tool/rm.lua b/xmake/scripts/tool/rm.lua index 370cffd7f..7759be01d 100644 --- a/xmake/scripts/tool/rm.lua +++ b/xmake/scripts/tool/rm.lua @@ -23,7 +23,9 @@ -- rm all for _, file_or_dir in ipairs(...) do if os.exists(file_or_dir) then - os.rm(file_or_dir) + if not os.rm(file_or_dir) then + return false + end end end diff --git a/xmake/scripts/tool/rmdir.lua b/xmake/scripts/tool/rmdir.lua index b9b4944a7..9df57b1c9 100644 --- a/xmake/scripts/tool/rmdir.lua +++ b/xmake/scripts/tool/rmdir.lua @@ -23,7 +23,9 @@ -- rmdir all for _, dir in ipairs(...) do if os.isdir(dir) then - os.rmdir(dir) + if not os.rmdir(dir) then + return false + end end end |
