summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-28 23:56:36 +0800
committerruki <[email protected]>2022-02-28 23:56:36 +0800
commitf8b0226814f1f942877c34fd9c6e01f588e640cb (patch)
treea6a345e457a66bcd7025b0419b4d6baa229efa29
parent607a17079782c58d28011c535268410e0c6bbc4b (diff)
improve xrepo remove
-rw-r--r--xmake/modules/private/xrepo/action/remove.lua51
1 files changed, 45 insertions, 6 deletions
diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua
index c9fce0831..1f1f24276 100644
--- a/xmake/modules/private/xrepo/action/remove.lua
+++ b/xmake/modules/private/xrepo/action/remove.lua
@@ -41,6 +41,7 @@ function menu_options()
"e.g.",
" - xrepo remove -f \"vs_runtime='MD'\" zlib",
" - xrepo remove -f \"regex=true,thread=true\" boost"},
+ {nil, "toolchain", "kv", nil, "Set the toolchain name." },
{},
{nil, "all", "k", nil, "Remove all packages and ignore extra package configs.",
"If `--all` is enabled, the package name parameter will support lua pattern",
@@ -76,8 +77,32 @@ end
-- remove packages
function _remove_packages(packages)
+ -- is package configuration file? e.g. xrepo install xxx.lua
+ --
+ -- xxx.lua
+ -- add_requires("libpng", {system = false})
+ -- add_requireconfs("libpng.*", {configs = {shared = true}})
+ local packagefile
+ if type(packages) == "string" or #packages == 1 then
+ local filepath = table.unwrap(packages)
+ if type(filepath) == "string" and filepath:endswith(".lua") and os.isfile(filepath) then
+ packagefile = path.absolute(filepath)
+ end
+ end
+
+ -- add includes to rcfiles
+ local rcfiles = {}
+ local includes = option.get("includes")
+ if includes then
+ table.join2(rcfiles, path.splitenv(includes))
+ end
+
-- enter working project directory
- local workdir = path.join(os.tmpdir(), "xrepo", "working")
+ local subdir = "working"
+ if packagefile then
+ subdir = subdir .. "-" .. hash.uuid(packagefile):split('-')[1]
+ end
+ local workdir = path.join(os.tmpdir(), "xrepo", subdir)
if not os.isdir(workdir) then
os.mkdir(workdir)
os.cd(workdir)
@@ -85,6 +110,10 @@ function _remove_packages(packages)
else
os.cd(workdir)
end
+ if packagefile then
+ assert(os.isfile("xmake.lua"), "xmake.lua not found!")
+ io.writefile("xmake.lua", ('includes("%s")\ntarget("test", {kind = "phony"})'):format((packagefile:gsub("\\", "/"))))
+ end
-- do configure first
local config_argv = {"f", "-c"}
@@ -112,7 +141,14 @@ function _remove_packages(packages)
table.insert(config_argv, "-k")
table.insert(config_argv, kind)
end
- os.vrunv("xmake", config_argv)
+ if option.get("toolchain") then
+ table.insert(config_argv, "--toolchain=" .. option.get("toolchain"))
+ end
+ local envs = {}
+ if #rcfiles > 0 then
+ envs.XMAKE_RCFILES = path.joinenv(rcfiles)
+ end
+ os.vrunv("xmake", config_argv, {envs = envs})
-- do remove
local require_argv = {"require", "--uninstall"}
@@ -143,11 +179,14 @@ function _remove_packages(packages)
raise(errors)
end
end
- if extra then
- local extra_str = string.serialize(extra, {indent = false, strip = true})
- table.insert(require_argv, "--extra=" .. extra_str)
+ if not packagefile then
+ -- avoid to override extra configs in add_requires/xmake.lua
+ if extra then
+ local extra_str = string.serialize(extra, {indent = false, strip = true})
+ table.insert(require_argv, "--extra=" .. extra_str)
+ end
+ table.join2(require_argv, packages)
end
- table.join2(require_argv, packages)
os.vexecv("xmake", require_argv)
end