summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-06-13 00:26:32 +0800
committerruki <[email protected]>2019-06-12 20:39:14 +0800
commit34b1fe79cfa33e2e185a520e05b3d7c8d70dd01c (patch)
treebc4a00d2adce8da3137adaf4b3e54741b86531d0
parentbf7331c60d83218fbf58431a7d757420549b60fa (diff)
improve clean action
-rw-r--r--xmake/actions/clean/main.lua41
-rw-r--r--xmake/modules/private/action/clean/remove_files.lua42
-rw-r--r--xmake/rules/cuda/devlink/xmake.lua12
-rw-r--r--xmake/rules/qt/env/xmake.lua8
-rw-r--r--xmake/rules/qt/moc/xmake.lua4
-rw-r--r--xmake/rules/qt/qrc/xmake.lua3
-rw-r--r--xmake/rules/qt/ui/xmake.lua4
-rw-r--r--xmake/rules/wdk/env/xmake.lua7
-rw-r--r--xmake/rules/wdk/inf/xmake.lua3
-rw-r--r--xmake/rules/wdk/man/xmake.lua3
-rw-r--r--xmake/rules/wdk/mc/xmake.lua1
-rw-r--r--xmake/rules/wdk/mof/xmake.lua4
-rw-r--r--xmake/rules/wdk/package/xmake.lua3
-rw-r--r--xmake/rules/wdk/sign/xmake.lua3
-rw-r--r--xmake/rules/wdk/tracewpp/xmake.lua3
-rw-r--r--xmake/rules/wdk/xmake.lua3
16 files changed, 66 insertions, 78 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 1b89690ea..36235321e 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -26,24 +26,7 @@ import("core.project.config")
import("core.base.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
-
- -- remove it first
- os.tryrm(filedir)
-
- -- remove it if the parent directory is empty
- local parentdir = path.directory(filedir)
- while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do
- os.tryrm(parentdir)
- parentdir = path.directory(parentdir)
- end
- end
-end
+import("private.action.clean.remove_files")
-- do clean target
function _do_clean_target(target)
@@ -54,33 +37,33 @@ function _do_clean_target(target)
end
-- remove the target file
- _remove(target:targetfile())
+ remove_files(target:targetfile())
-- remove the target dependent file if exists
- _remove(target:dependfile())
+ remove_files(target:dependfile())
-- remove the symbol file
- _remove(target:symbolfile())
+ remove_files(target:symbolfile())
-- remove the c/c++ precompiled header file
- _remove(target:pcoutputfile("c"))
- _remove(target:pcoutputfile("cxx"))
+ remove_files(target:pcoutputfile("c"))
+ remove_files(target:pcoutputfile("cxx"))
-- remove the object files
- _remove(target:objectfiles())
+ remove_files(target:objectfiles())
-- remove the depend files
- _remove(target:dependfiles())
+ remove_files(target:dependfiles())
-- TODO remove the header files (deprecated)
local _, dstheaders = target:headers()
- _remove(dstheaders)
+ remove_files(dstheaders)
-- remove all?
if option.get("all") then
- -- remove the config.h file
- _remove(target:configheader())
+ -- TODO remove the config.h file (deprecated)
+ remove_files(target:configheader())
end
end
@@ -206,7 +189,7 @@ function _clean(targetname)
if option.get("all") then
-- remove the configure directory
- _remove(config.directory())
+ remove_files(config.directory())
end
end
diff --git a/xmake/modules/private/action/clean/remove_files.lua b/xmake/modules/private/action/clean/remove_files.lua
new file mode 100644
index 000000000..a40232002
--- /dev/null
+++ b/xmake/modules/private/action/clean/remove_files.lua
@@ -0,0 +1,42 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file remove_files.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- remove the given files or (empty) directories
+function main(filedirs)
+
+ for _, filedir in ipairs(filedirs) do
+
+ -- remove it first
+ os.tryrm(filedir)
+
+ -- remove all?
+ if option.get("all") then
+ -- remove it if the parent directory is empty
+ local parentdir = path.directory(filedir)
+ while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do
+ os.tryrm(parentdir)
+ parentdir = path.directory(parentdir)
+ end
+ end
+ end
+end
diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua
index 9df1a32ee..db3ea59c1 100644
--- a/xmake/rules/cuda/devlink/xmake.lua
+++ b/xmake/rules/cuda/devlink/xmake.lua
@@ -24,12 +24,6 @@ rule("cuda.devlink")
-- add rule: cuda environment
add_deps("cuda.env")
- -- clean files
- after_clean(function (target)
- os.tryrm(target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")))
- os.tryrm(target:dependfile(targetfile))
- end)
-
-- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/
before_link(function (target, opt)
@@ -119,3 +113,9 @@ rule("cuda.devlink")
depend.save(dependinfo, dependfile)
end)
+ -- clean files
+ after_clean(function (target)
+ import("private.action.clean.remove_files")
+ remove_files(target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")))
+ remove_files(target:dependfile(targetfile))
+ end)
diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua
index 590c77b07..ec5fe06f2 100644
--- a/xmake/rules/qt/env/xmake.lua
+++ b/xmake/rules/qt/env/xmake.lua
@@ -39,9 +39,7 @@ rule("qt.env")
-- clean files
after_clean(function (target)
- for _, file in ipairs(target:data("qt.cleanfiles")) do
- os.rm(file)
- end
- target:data_set("qt.cleanfiles", nil)
+ import("core.project.config")
+ import("private.action.clean.remove_files")
+ remove_files(path.join(config.buildir(), ".qt"))
end)
-
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua
index 9542ed7e8..e4bd6b93e 100644
--- a/xmake/rules/qt/moc/xmake.lua
+++ b/xmake/rules/qt/moc/xmake.lua
@@ -64,9 +64,6 @@ rule("qt.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 {})
@@ -102,4 +99,3 @@ rule("qt.moc")
table.insert(dependinfo.files, headerfile_moc)
depend.save(dependinfo, dependfile)
end)
-
diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua
index 6ae48fa41..b296e9154 100644
--- a/xmake/rules/qt/qrc/xmake.lua
+++ b/xmake/rules/qt/qrc/xmake.lua
@@ -67,9 +67,6 @@ rule("qt.qrc")
-- add objectfile
table.insert(target:objectfiles(), objectfile)
- -- add clean files
- target:data_add("qt.cleanfiles", {sourcefile_cpp, objectfile})
-
-- load dependent info
local dependfile = target:dependfile(objectfile)
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua
index a94894681..59a14c5af 100644
--- a/xmake/rules/qt/ui/xmake.lua
+++ b/xmake/rules/qt/ui/xmake.lua
@@ -57,9 +57,6 @@ rule("qt.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 {})
@@ -87,4 +84,3 @@ rule("qt.ui")
dependinfo.files = {sourcefile_ui}
depend.save(dependinfo, dependfile)
end)
-
diff --git a/xmake/rules/wdk/env/xmake.lua b/xmake/rules/wdk/env/xmake.lua
index 2f6c30965..07d9c5f5f 100644
--- a/xmake/rules/wdk/env/xmake.lua
+++ b/xmake/rules/wdk/env/xmake.lua
@@ -83,10 +83,9 @@ rule("wdk.env")
-- clean files
after_clean(function (target)
- for _, file in ipairs(target:data("wdk.cleanfiles")) do
- os.rm(file)
- end
- target:data_set("wdk.cleanfiles", nil)
+ import("core.project.config")
+ import("private.action.clean.remove_files")
+ remove_files(path.join(config.buildir(), ".wdk"))
end)
-- define rule: umdf
diff --git a/xmake/rules/wdk/inf/xmake.lua b/xmake/rules/wdk/inf/xmake.lua
index 3a591cfa3..60e81488d 100644
--- a/xmake/rules/wdk/inf/xmake.lua
+++ b/xmake/rules/wdk/inf/xmake.lua
@@ -58,9 +58,6 @@ rule("wdk.inf")
-- the target file
local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".inf")
- -- add clean files
- target:data_add("wdk.cleanfiles", targetfile)
-
-- save this target file for signing (wdk.sign.*, wdk.package.* rules)
target:data_set("wdk.sign.inf", targetfile)
diff --git a/xmake/rules/wdk/man/xmake.lua b/xmake/rules/wdk/man/xmake.lua
index 93ecdc17e..aa6af830e 100644
--- a/xmake/rules/wdk/man/xmake.lua
+++ b/xmake/rules/wdk/man/xmake.lua
@@ -83,7 +83,6 @@ rule("wdk.man")
if headerfile then
table.insert(args, "-o")
table.insert(args, headerfile)
- target:data_add("wdk.cleanfiles", headerfile)
else
raise("please call `set_values(\"wdk.man.header\", \"header.h\")` to set the provider header file name!")
end
@@ -101,7 +100,6 @@ rule("wdk.man")
if counter_headerfile then
table.insert(args, "-ch")
table.insert(args, counter_headerfile)
- target:data_add("wdk.cleanfiles", counter_headerfile)
end
-- add resource file
@@ -110,7 +108,6 @@ rule("wdk.man")
if resourcefile then
table.insert(args, "-rc")
table.insert(args, resourcefile)
- target:data_add("wdk.cleanfiles", resourcefile)
end
-- need build this object?
diff --git a/xmake/rules/wdk/mc/xmake.lua b/xmake/rules/wdk/mc/xmake.lua
index 87921ea85..c981bda5b 100644
--- a/xmake/rules/wdk/mc/xmake.lua
+++ b/xmake/rules/wdk/mc/xmake.lua
@@ -88,7 +88,6 @@ rule("wdk.mc")
if headerfile then
table.insert(args, "-z")
table.insert(args, path.basename(headerfile))
- target:data_add("wdk.cleanfiles", headerfile)
else
headerfile = path.join(outputdir, path.basename(sourcefile) .. ".h")
end
diff --git a/xmake/rules/wdk/mof/xmake.lua b/xmake/rules/wdk/mof/xmake.lua
index b198c83f4..a1f643a6c 100644
--- a/xmake/rules/wdk/mof/xmake.lua
+++ b/xmake/rules/wdk/mof/xmake.lua
@@ -99,10 +99,6 @@ rule("wdk.mof")
local outputdir_htm = path.join(outputdir, "htm")
local targetfile_vbs = path.join(outputdir, path.basename(sourcefile) .. ".vbs")
- -- add clean files
- target:data_add("wdk.cleanfiles", {headerfile, sourcefile_mof, targetfile_mfl, targetfile_mof})
- target:data_add("wdk.cleanfiles", {targetfile_mfl_mof, targetfile_bmf, outputdir_htm, targetfile_vbs})
-
-- need build this object?
local dependfile = target:dependfile(headerfile)
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
diff --git a/xmake/rules/wdk/package/xmake.lua b/xmake/rules/wdk/package/xmake.lua
index 829022dc3..180268af5 100644
--- a/xmake/rules/wdk/package/xmake.lua
+++ b/xmake/rules/wdk/package/xmake.lua
@@ -46,9 +46,6 @@ rule("wdk.package.cab")
-- the .ddf file
local ddfile = os.tmpfile(target:targetfile()) .. ".ddf"
- -- add clean files
- target:data_add("wdk.cleanfiles", ddfile)
-
-- trace progress info
if option.get("verbose") then
cprint("${dim magenta}packaging %s", packagefile)
diff --git a/xmake/rules/wdk/sign/xmake.lua b/xmake/rules/wdk/sign/xmake.lua
index 4e2d8ab0e..4344ea301 100644
--- a/xmake/rules/wdk/sign/xmake.lua
+++ b/xmake/rules/wdk/sign/xmake.lua
@@ -108,9 +108,6 @@ rule("wdk.sign")
return
end
- -- add clean files
- target:data_add("wdk.cleanfiles", {tempfile, dependfile})
-
-- trace progress info
cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress)
if option.get("verbose") then
diff --git a/xmake/rules/wdk/tracewpp/xmake.lua b/xmake/rules/wdk/tracewpp/xmake.lua
index 086f7ccff..d940337f3 100644
--- a/xmake/rules/wdk/tracewpp/xmake.lua
+++ b/xmake/rules/wdk/tracewpp/xmake.lua
@@ -87,9 +87,6 @@ rule("wdk.tracewpp")
-- add includedirs
target:add("includedirs", outputdir)
- -- add clean files
- target:data_add("wdk.cleanfiles", outputdir)
-
-- need build this object?
local targetfile = path.join(outputdir, path.basename(sourcefile) .. ".tmh")
local dependfile = target:dependfile(targetfile)
diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua
index a27fac115..4eab4a571 100644
--- a/xmake/rules/wdk/xmake.lua
+++ b/xmake/rules/wdk/xmake.lua
@@ -53,9 +53,6 @@ rule("wdk.driver")
-- copy wdf redist dll libraries (WdfCoInstaller01011.dll, ..) to the target directory
os.cp(path.join(wdk.sdkdir, "Redist", "wdf", config.arch(), "*.dll"), target:targetdir())
-
- -- add clean files
- target:data_add("wdk.cleanfiles", os.files(path.join(target:targetdir(), "*.dll")))
end
end)