summaryrefslogtreecommitdiff
path: root/xmake/plugins
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-07-26 22:50:42 +0300
committerruki <[email protected]>2026-07-30 10:17:31 +0800
commit21f1b0efbf5441e5ec82a2caa84984a77ad7e7eb (patch)
tree71bc6323bf53b2d92c04eb95e7e257362180c392 /xmake/plugins
parent5f9a9e45ecb47384aa6c80d3543b7c379cb4e5ea (diff)
Added tests for plugins
Diffstat (limited to 'xmake/plugins')
-rw-r--r--xmake/plugins/plugin/main.lua114
-rw-r--r--xmake/plugins/plugin/xmake.lua3
-rw-r--r--xmake/plugins/xfetch/main.lua289
-rw-r--r--xmake/plugins/xfetch/xmake.lua32
4 files changed, 61 insertions, 377 deletions
diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua
index e12a433e2..276508396 100644
--- a/xmake/plugins/plugin/main.lua
+++ b/xmake/plugins/plugin/main.lua
@@ -62,42 +62,19 @@ end
function _save_manifest(manifest)
io.save(_manifest_path(), manifest)
end
-
--- is the plugin package name? e.g. hello-world, myrepo@hello-world
---
--- the plugin url is the git url or local path, e.g.
--- https://github.com/xmake-io/xmake-plugins, [email protected]:xmake-io/xmake-plugins.git, /tmp/xmake-plugins
-function _is_package_name(str)
- return not os.isdir(str) and not str:find("[/\\:]")
+-- install the plugin by name from the repository.
+-- Repository plugins are loaded directly from the checkout;
+-- ensure the repository is up to date with `xrepo update-repo`.
+function _install_name(name)
+ print("plugin %s will be loaded from the repository after xrepo update-repo.", name)
end
-
--- install the plugin package from repositories, e.g. xmake plugin --install hello-world
-function _install_package(name, opt)
- opt = opt or {}
- local argv = {"lua", "private.xrepo", "install", "--kind=plugin"}
- if opt.force then
- table.insert(argv, "--force")
- end
- if option.get("yes") then
- table.insert(argv, "-y")
- end
- if option.get("verbose") then
- table.insert(argv, "-v")
- end
- if option.get("diagnosis") then
- table.insert(argv, "-D")
- end
- table.insert(argv, name)
- os.execv(os.programfile(), argv)
-end
-
-- install plugins
function _install()
- -- install the plugin package from repositories?
+ -- install the plugin by name from the repository?
local name = option.get("plugins")
- if name and _is_package_name(name) then
- return _install_package(name)
+ if name and not os.isdir(name) and not name:find("[/\\:]") then
+ return _install_name(name)
end
-- enter environment
@@ -151,13 +128,6 @@ end
-- update plugins
function _update()
-
- -- update the plugin package from repositories? e.g. xmake plugin --update hello-world
- local name = option.get("plugins")
- if name and _is_package_name(name) then
- return _install_package(name, {force = true})
- end
-
-- enter environment
environment.enter()
@@ -198,11 +168,9 @@ function _update()
environment.leave()
end
--- remove the given installed plugin
+-- remove the given installed plugin (from ~/.xmake/plugins/)
function _remove()
local name = assert(option.get("plugins"), "please specify the plugin name to be removed!")
- -- avoid escaping the plugins directory, e.g. `xmake plugin --remove ../foo`,
- -- and `.` or the empty name will be resolved to the plugins directory itself
assert(name ~= "" and name ~= "." and not name:find("..", 1, true) and not name:find("[/\\:]"), "invalid plugin name(%s)!", name)
local plugindir = path.join(global.directory(), "plugins", name)
assert(os.isdir(plugindir), "plugin(%s) not found!", name)
@@ -210,24 +178,63 @@ function _remove()
cprint("${color.success}remove plugin(%s) ok!", name)
end
--- list all installed plugins
+-- list all installed plugins (manual + repository)
function _list()
+ local seen = {}
+ -- manually installed plugins
local plugindir = path.join(global.directory(), "plugins")
cprint("plugins in ${bright}%s${clear}:", plugindir)
- for _, dir in ipairs(os.dirs(path.join(plugindir, "*"))) do
+ local found = false
+ for _, dir in ipairs(os.dirs(path.join(plugindir, "*")) or {}) do
if os.isfile(path.join(dir, "xmake.lua")) then
- local version, description
- local manifest_file = path.join(dir, "manifest.txt")
- if os.isfile(manifest_file) then
- local manifest = io.load(manifest_file)
- if manifest then
- version = manifest.version
- description = manifest.description
+ local name = path.filename(dir)
+ seen[name] = true
+ found = true
+ cprint(" ${color.dump.string}%s${clear}", name)
+ end
+ end
+ if not found then
+ print(" (none)")
+ end
+
+ -- repository plugins (from scanned repos)
+ local reposdir = path.join(global.directory(), "repositories")
+ for _, dir in ipairs(os.dirs(path.join(reposdir, "*")) or {}) do
+ local rplugindir = path.join(dir, "plugins")
+ if os.isdir(rplugindir) then
+ local reponame = path.filename(dir)
+ cprint("plugins in repository ${bright}%s${clear}:", reponame)
+ local repofound = false
+ for _, subdir in ipairs(os.dirs(path.join(rplugindir, "*")) or {}) do
+ if os.isfile(path.join(subdir, "xmake.lua")) and not seen[path.filename(subdir)] then
+ seen[path.filename(subdir)] = true
+ repofound = true
+ cprint(" ${color.dump.string}%s${clear}", path.filename(subdir))
+ end
+ end
+ if not repofound then
+ print(" (none)")
+ end
+ end
+ end
+
+ -- local checkout plugins
+ local repodir = os.getenv("XMAKE_MAIN_REPO")
+ if repodir and os.isdir(repodir) then
+ local rplugindir = path.join(repodir, "plugins")
+ if os.isdir(rplugindir) then
+ cprint("plugins in ${bright}XMAKE_MAIN_REPO${clear}:")
+ local repofound = false
+ for _, subdir in ipairs(os.dirs(path.join(rplugindir, "*")) or {}) do
+ if os.isfile(path.join(subdir, "xmake.lua")) and not seen[path.filename(subdir)] then
+ seen[path.filename(subdir)] = true
+ repofound = true
+ cprint(" ${color.dump.string}%s${clear}", path.filename(subdir))
end
end
- cprint(" ${color.dump.string}%s${clear}%s: %s", path.filename(dir),
- version and ("-" .. version) or "",
- description or "")
+ if not repofound then
+ print(" (none)")
+ end
end
end
end
@@ -254,4 +261,3 @@ function main()
_clear()
end
end
-
diff --git a/xmake/plugins/plugin/xmake.lua b/xmake/plugins/plugin/xmake.lua
index b61dd05f9..87d85e81d 100644
--- a/xmake/plugins/plugin/xmake.lua
+++ b/xmake/plugins/plugin/xmake.lua
@@ -36,7 +36,6 @@ task("plugin")
" $ xmake plugin --install hello-world",
" $ xmake plugin --remove hello-world",
" $ xmake plugin --list",
- " $ xmake plugin --update",
- " $ xmake plugin --update hello-world"}
+ " $ xmake plugin --update"}
}
}
diff --git a/xmake/plugins/xfetch/main.lua b/xmake/plugins/xfetch/main.lua
deleted file mode 100644
index 357219486..000000000
--- a/xmake/plugins/xfetch/main.lua
+++ /dev/null
@@ -1,289 +0,0 @@
---!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-present, Xmake Open Source Community.
---
--- @author ruki
--- @file main.lua
---
-
--- imports
-import("core.base.option")
-import("core.base.global")
-import("core.package.package", {alias = "core_package"})
-
--- the small ascii logos for the known systems, like fastfetch
-local logos = {
- xmake = {color = "green", lines = {
- [[ _ ]],
- [[__ ___ __ __ __ _| | ______]],
- [[\ \/ / | \/ |/ _ | |/ / __ \]],
- [[ > < | \__/ | /_| | < ___/]],
- [[/_/\_\_|_| |_|\__ \|_|\_\____|]]}},
- linux = {color = "yellow", lines = {
- [[ .--.]],
- [[ |o_o |]],
- [[ |:_/ |]],
- [[ // \ \]],
- [[ (| | )]],
- [[/'\_ _/`\]],
- [[\___)=(___/]]}},
- windows = {color = "blue", lines = {
- [[ ______ ______]],
- [[| | |]],
- [[|______|______|]],
- [[| | |]],
- [[|______|______|]]}},
- macosx = {color = "white", lines = {
- [[ .:']],
- [[ _ :'_]],
- [[ .'`_`-'_``.]],
- [[:________.-']],
- [[:_______:]],
- [[ :_______`-;]],
- [[ `._.-._.']]}},
- bsd = {color = "red", lines = {
- [[/\,-'''''-,/\]],
- [[\_) (_/]],
- [[| |]],
- [[| |]],
- [[ ; ;]],
- [[ '-_____-']]}},
- archlinux = {color = "cyan", lines = {
- [[ /\]],
- [[ / \]],
- [[ /\ \]],
- [[ / \]],
- [[ / ,, \]],
- [[ / | | -\]],
- [[/_-'' ''-_\]]}},
- ubuntu = {color = "red", lines = {
- [[ _]],
- [[ ---(_)]],
- [[ _/ --- \]],
- [[(_) | |]],
- [[ \ --- _/]],
- [[ ---(_)]]}},
- debian = {color = "red", lines = {
- [[ _____]],
- [[ / __ \]],
- [[| / |]],
- [[| \___-]],
- [[-_]],
- [[ --_]]}},
- fedora = {color = "blue", lines = {
- [[ _____]],
- [[ / __)\]],
- [[ | / \ \]],
- [[ ___| |__/ /]],
- [[ / (_ _)_/]],
- [[/ / | |]],
- [[\ \__/ |]],
- [[ \(_____/]]}},
- centos = {color = "yellow", lines = {
- [[ ____^____]],
- [[ |\ | /|]],
- [[ | \ | / |]],
- [[<---- ---->]],
- [[ | / | \ |]],
- [[ |/__|__\|]],
- [[ v]]}},
- linuxmint = {color = "green", lines = {
- [[ ___________]],
- [[|_ \]],
- [[ | | _____ |]],
- [[ | | | | | |]],
- [[ | | | | | |]],
- [[ | \_____/ |]],
- [[ \_________/]]}},
- gentoo = {color = "magenta", lines = {
- [[ _-----_]],
- [[( \]],
- [[\ 0 \]],
- [[ \ )]],
- [[ / _/]],
- [[( _-]],
- [[\____-]]}},
- opensuse = {color = "green", lines = {
- [[ _______]],
- [[__| __ \]],
- [[ / .\ \]],
- [[ \__/ |]],
- [[ _______|]],
- [[ \_______]],
- [[__________/]]}},
- manjaro = {color = "green", lines = {
- [[||||||||| ||||]],
- [[||||||||| ||||]],
- [[|||| ||||]],
- [[|||| |||| ||||]],
- [[|||| |||| ||||]],
- [[|||| |||| ||||]],
- [[|||| |||| ||||]]}},
- nixos = {color = "blue", lines = {
- [[ \\ \\ //]],
- [[ ==\\__\\/ //]],
- [[ // \\//]],
- [[==// //==]],
- [[ //\\___//]],
- [[// /\\ \\==]],
- [[ // \\ \\]]}},
- alpine = {color = "blue", lines = {
- [[ /\ /\]],
- [[ / \ \]],
- [[ / \ \]],
- [[/ \ \]],
- [[ \ \]],
- [[ \]]}}
-}
--- get the logo of the current system
-function _get_logo()
- local name = option.get("logo")
- if not name then
- -- os.host() is always the real host system, e.g. windows, linux, macosx ..
- -- even if we are running in the msys/cygwin subsystem, @see os.subhost()
- name = os.host()
- if name == "linux" then
- name = linuxos.name()
- end
- end
- -- we will show the linux or xmake logo if the logo drawing is not found
- local logo = logos[name]
- if not logo then
- logo = os.host() == "linux" and logos.linux or logos.xmake
- end
- return logo
-end
-
--- get the user and host name
-function _get_title()
- local user = os.getenv("USER") or os.getenv("USERNAME") or "user"
- local host = os.getenv("HOSTNAME") or os.getenv("COMPUTERNAME")
- if not host and is_host("linux", "macosx", "bsd") and os.isfile("/etc/hostname") then
- local content = io.readfile("/etc/hostname")
- if content then
- host = content:trim()
- end
- end
- return user .. "@" .. (host or os.host())
-end
-
--- get the operation system name and version
-function _get_os()
- if is_host("linux") then
- -- the system version may be unavailable on the rolling release distributions
- local version = try { function () return linuxos.version() end }
- return linuxos.name() .. (version and (" " .. tostring(version)) or "") .. " " .. os.arch()
- elseif is_host("macosx") then
- local version = try { function () return macos.version() end }
- return "macOS" .. (version and (" " .. tostring(version)) or "") .. " " .. os.arch()
- elseif is_host("windows") then
- local version = try { function () return winos.version() end }
- return "Windows" .. (version and (" " .. tostring(version)) or "") .. " " .. os.arch()
- end
- return os.host() .. " " .. os.arch()
-end
-
--- get the cpu name
-function _get_cpu()
- local name = os.cpuinfo("model_name") or os.cpuinfo("vendor") or "unknown"
- return string.format("%s (%d)", name, os.cpuinfo("ncpu") or 1)
-end
-
--- format the given size in MB as GiB, we do not use `%.1f` to avoid the locale decimal separator
-function _format_gib(size_mb)
- local gib10 = math.floor(size_mb / 1024 * 10 + 0.5)
- return string.format("%d.%d GiB", math.floor(gib10 / 10), gib10 % 10)
-end
-
--- get the memory usage, the sizes of os.meminfo() are in MB
-function _get_memory()
- local meminfo = os.meminfo()
- if meminfo.totalsize and meminfo.availsize then
- -- `%%%%` will be shown as `%`, because cprint will format this string again
- return string.format("%s / %s (%d%%%%)",
- _format_gib(meminfo.totalsize - meminfo.availsize),
- _format_gib(meminfo.totalsize),
- math.floor(meminfo.usagerate * 100))
- end
-end
-
--- get the count of the installed packages
-function _get_packages()
- local count = #os.dirs(path.join(core_package.installdir(), "*", "*"))
- return string.format("%d (xrepo)", count)
-end
-
--- get the count of the installed plugins
-function _get_plugins()
- return tostring(#os.files(path.join(global.directory(), "plugins", "*", "xmake.lua")))
-end
-
--- get all the information lines
-function _get_infolines(color)
- local title = _get_title()
- local infos = {
- {"OS", _get_os()},
- {"CPU", _get_cpu()},
- {"Memory", _get_memory()},
- {"Shell", os.shell()},
- {"Terminal", os.term()},
- {"xmake", "v" .. xmake.version()},
- {"Packages", _get_packages()},
- {"Plugins", _get_plugins()},
- {"Theme", global.get("theme") or "default"}
- }
- if is_host("linux") then
- local kernelver = try { function () return linuxos.kernelver() end }
- if kernelver then
- table.insert(infos, 2, {"Kernel", tostring(kernelver)})
- end
- end
- local lines = {}
- table.insert(lines, "${bright " .. color .. "}" .. title .. "${clear}")
- table.insert(lines, string.rep("-", #title))
- for _, info in ipairs(infos) do
- if info[2] then
- table.insert(lines, "${bright " .. color .. "}" .. info[1] .. "${clear}: " .. info[2])
- end
- end
- table.insert(lines, "")
- table.insert(lines, "${onblack} ${onred} ${ongreen} ${onyellow} ${onblue} ${onmagenta} ${oncyan} ${onwhite} ${clear}")
- return lines
-end
-
-function main()
- local logo = _get_logo()
- local logolines = logo.lines
- local infolines = _get_infolines(logo.color)
- -- show the logo and information side by side, like fastfetch
- local width = 0
- for _, line in ipairs(logolines) do
- width = math.max(width, #line)
- end
- local startline = 1
- if #infolines > #logolines then
- startline = math.floor((#infolines - #logolines) / 2) + 1
- end
- print("")
- for i = 1, math.max(#logolines, #infolines) do
- local left = logolines[i - startline + 1] or ""
- local right = infolines[i] or ""
- left = left .. string.rep(" ", width - #left)
- -- escape `%`, because cprint will format this string again
- left = left:gsub("%%", "%%%%")
- cprint(" ${bright %s}%s${clear} %s", logo.color, left, right)
- end
- print("")
-end
diff --git a/xmake/plugins/xfetch/xmake.lua b/xmake/plugins/xfetch/xmake.lua
deleted file mode 100644
index a3296d233..000000000
--- a/xmake/plugins/xfetch/xmake.lua
+++ /dev/null
@@ -1,32 +0,0 @@
---!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-present, Xmake Open Source Community.
---
--- @author ruki
--- @file xmake.lua
---
-
-task("xfetch")
- set_category("plugin")
- on_run("main")
- set_menu {
- usage = "xmake xfetch [options]",
- description = "Fetch and show the system and xmake information.",
- options = {
- {'l', "logo", "kv", nil, "Show the given logo.",
- "e.g.",
- " $ xmake xfetch --logo=archlinux"}
- }
- }