From 5c68815ee523bb6fff7d285016e57efbc88d483a Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 5 Aug 2026 23:57:23 +0800 Subject: rewrite to install plugin from xmake-repo --- xmake/plugins/plugin/main.lua | 53 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) (limited to 'xmake/plugins/plugin/main.lua') diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua index 5158352c0..fde93547a 100644 --- a/xmake/plugins/plugin/main.lua +++ b/xmake/plugins/plugin/main.lua @@ -24,6 +24,7 @@ import("core.base.global") import("core.package.repository") import("devel.git") import("private.action.require.impl.environment") +import("private.action.require.impl.install_packages") -- validate a plugin directory name function _check_plugin_name(name) @@ -42,36 +43,18 @@ function _repositories() return table.join(repository.repositories({global = false}), repository.repositories({global = true})) end --- find a plugin directory in the given repository directory --- --- plugins in a repository follow the same layout as packages: --- /plugins///xmake.lua -function _find_plugin_in_repo(repodir, name) - local dir = path.join(repodir, "plugins", name:sub(1, 1):lower(), name) - if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) then - return dir - end -end - -- install a plugin from the given repository or the first repository containing it function _install_plugins_from_repo(name, reponame) + + -- check plugin name _check_plugin_name(name) - for _, repo in ipairs(_repositories()) do - if not reponame or repo:name() == reponame then - local srcdir = _find_plugin_in_repo(repo:directory(), name) - if srcdir then - local dstdir = _get_plugindir(name) - assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) - os.vcp(srcdir, dstdir) - cprint("${color.success}install ${bright}%s${clear} from repository ${bright}%s${clear} ok!", name, repo:name()) - return - end - end - end + + -- do install + local installname = name if reponame then - raise("plugin(%s): not found in repository %s!", name, reponame) + installname = reponame .. "@" .. name end - raise("plugin(%s): not found in any repository! try ${bright}xrepo update-repo${clear} first.", name) + os.execv(os.programfile(), {"lua", "private.xrepo", "install", "--plugin", installname}) end -- install a single plugin from a source directory (as the given name, default to the directory name) @@ -137,20 +120,9 @@ end function _install() local names = assert(option.get("plugins"), "please specify the plugins to be installed!") environment.enter() - try - { - function () - for _, name in ipairs(names) do - _install_one(name) - end - end, - catch - { - function (errors) - raise(errors) - end - } - } + for _, name in ipairs(names) do + _install_one(name) + end environment.leave() end @@ -171,7 +143,8 @@ function _plugin_description(dir) if os.isfile(filepath) then local content = io.readfile(filepath) if content then - return content:match("description%s*=%s*\"(.-)\"") + -- parse description from task or package scope + return content:match("description%s*=%s*\"(.-)\"") or content:match("set_description%s*%(\"(.-)\"%)") end end end -- cgit v1.3.1