diff options
| author | ruki <[email protected]> | 2019-01-14 22:50:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-14 11:02:59 +0800 |
| commit | 3bfc245906c14b03291d57d5f9930ba0259ca9eb (patch) | |
| tree | 2503c7ac32ba072bf93c9fa79efdcc56b5a88721 | |
| parent | 5b9c7e6cdc896c0c469f402142aeadc86c4cdf52 (diff) | |
add add_installfiles api to target
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/actions/install/install.lua | 19 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall.lua | 12 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 79 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 4 |
5 files changed, 114 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 61696726f..eb0f7bcf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [#283](https://github.com/tboox/xmake/issues/283): Add `target:installdir()` and `set_installdir()` api for target * [#260](https://github.com/tboox/xmake/issues/260): Add `add_platformdirs` api, we can define custom platforms * [#310](https://github.com/tboox/xmake/issues/310): Add theme feature +* [#318](https://github.com/tboox/xmake/issues/318): Add `add_installfiles` api to target ### Changes @@ -550,6 +551,7 @@ * [#283](https://github.com/tboox/xmake/issues/283): 添加`target:installdir()`和`set_installdir()`接口 * [#260](https://github.com/tboox/xmake/issues/260): 添加`add_platformdirs`接口,用户现在可以自定义扩展编译平台 * [#310](https://github.com/tboox/xmake/issues/310): 新增主题设置支持,用户可随意切换和扩展主题样式 +* [#318](https://github.com/tboox/xmake/issues/318): 添加`add_installfiles`接口到target去自定义安装文件 ### 改进 diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 8181a3c46..4dff2703d 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -27,6 +27,22 @@ import("core.base.task") import("core.project.rule") import("core.project.project") +-- install files +function _install_files(target) + + local srcfiles, dstfiles = target:installfiles() + if srcfiles and dstfiles then + local i = 1 + for _, srcfile in ipairs(srcfiles) do + local dstfile = dstfiles[i] + if dstfile then + os.cp(srcfile, dstfile) + end + i = i + 1 + end + end +end + -- install binary function _install_binary(target) @@ -98,6 +114,9 @@ function _do_install_target(target) if script then script(target) end + + -- install other files + _install_files(target) end -- on install target diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index 37dede700..f6079759b 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -27,6 +27,15 @@ import("core.base.task") import("core.project.rule") import("core.project.project") +-- uninstall files +function _uninstall_files(target) + + local _, dstfiles = target:installfiles() + for _, dstfile in ipairs(dstfiles) do + os.rm(dstfile) + end +end + -- uninstall binary function _uninstall_binary(target) @@ -82,6 +91,9 @@ function _do_uninstall_target(target) if script then script(target) end + + -- uninstall the other files + _uninstall_files(target) end -- on uninstall target diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 3c639861a..54061c497 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -89,6 +89,7 @@ function target.apis() , "target.set_installdir" -- target.add_xxx , "target.add_files" + , "target.add_installfiles" -- target.del_xxx , "target.del_files" } @@ -1074,6 +1075,84 @@ function target:headerfiles(outputdir) return srcheaders, dstheaders end +-- get the install files +function target:installfiles(outputdir) + + -- cached? return it directly + if self._INSTALLFILES and outputdir == nil then + return self._INSTALLFILES[1], self._INSTALLFILES[2] + end + + -- no install files? + local installfiles = self:get("installfiles") + if not installfiles then return end + + -- get the install directory + local installdir = outputdir or self:installdir() + assert(installdir) + + -- get the extra information + local extrainfo = table.wrap(self:get("__extra_installfiles")) + + -- get the source pathes and destinate pathes + local srcfiles = {} + local dstfiles = {} + for _, installfile in ipairs(table.wrap(installfiles)) do + + -- get the root directory + local rootdir, count = installfile:gsub("|.*$", ""):gsub("%(.*%)$", "") + if count == 0 then + rootdir = nil + end + + -- remove '(' and ')' + local srcpathes = installfile:gsub("[%(%)]", "") + if srcpathes then + + -- get the source pathes + srcpathes = os.match(srcpathes) + if srcpathes and #srcpathes > 0 then + + -- add the source install files + table.join2(srcfiles, srcpathes) + + -- get the prefix directory + local prefixdir = (extrainfo[installfile] or {}).prefixdir + + -- add the destinate install files + for _, srcpath in ipairs(srcpathes) do + + -- get the destinate directory + local dstdir = installdir + if prefixdir then + dstdir = path.join(dstdir, prefixdir) + end + + -- the destinate installfile + local dstfile = nil + if rootdir then + dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir) + else + dstfile = path.join(dstdir, path.filename(srcpath)) + end + assert(dstfile) + + -- add it + table.insert(dstfiles, dstfile) + end + end + end + end + + -- cache it + if outputdir == nil then + self._INSTALLFILES = {srcfiles, dstfiles} + end + + -- ok? + return srcfiles, dstfiles +end + -- get depend file from object file function target:dependfile(objectfile) diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 955843c3a..3ed48f59f 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -145,14 +145,14 @@ end -- print the verbose information function sandbox_utils.vprint(format, ...) - if option.get("verbose") then + if option.get("verbose") or option.get("diagnosis") then sandbox_utils.print(format, ...) end end -- print the verbose information without newline function sandbox_utils.vprintf(format, ...) - if option.get("verbose") then + if option.get("verbose") or option.get("diagnosis") then sandbox_utils.printf(format, ...) end end |
