summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/utils/plugins.lua
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-07-10 22:28:38 +0300
committerruki <[email protected]>2026-07-30 10:17:31 +0800
commit4b6a2eb23d0903124871f837798db2dd718e86a1 (patch)
treec0dda814d7b199e1c54db61803c4051f4a834a3b /xmake/modules/private/action/require/impl/utils/plugins.lua
parenta928217681c4c5dc60b80a230182e5254bc30c8d (diff)
feat: add support for plugin packages in xmake
Diffstat (limited to 'xmake/modules/private/action/require/impl/utils/plugins.lua')
-rw-r--r--xmake/modules/private/action/require/impl/utils/plugins.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/xmake/modules/private/action/require/impl/utils/plugins.lua b/xmake/modules/private/action/require/impl/utils/plugins.lua
new file mode 100644
index 000000000..9cd7c5d86
--- /dev/null
+++ b/xmake/modules/private/action/require/impl/utils/plugins.lua
@@ -0,0 +1,51 @@
+--!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 plugins.lua
+--
+
+-- imports
+import("core.base.global")
+
+-- get the plugin directory of the given plugin package in the global plugins directory
+function plugindir(name)
+ return path.join(global.directory(), "plugins", name)
+end
+
+-- register the given plugin package to the global plugins directory,
+-- then we can run it directly. e.g. `xmake plugin-name`
+function register(package)
+ local installdir = package:installdir()
+ assert(os.isfile(path.join(installdir, "xmake.lua")),
+ "plugin(%s): xmake.lua not found in the installed files, it should be installed with `os.cp(\"*\", package:installdir())`!", package:name())
+ local dir = plugindir(package:name())
+ os.tryrm(dir)
+ os.cp(installdir, dir)
+ -- remove the install logs, they do not belong to the plugin,
+ -- but we keep manifest.txt to show the plugin version and description. e.g. `xmake plugin --list`
+ os.tryrm(path.join(dir, "logs"))
+ vprint("register plugin(%s) to %s", package:name(), dir)
+end
+
+-- unregister the given plugin from the global plugins directory
+function unregister(name)
+ local dir = plugindir(name)
+ if os.isdir(dir) then
+ os.tryrm(dir)
+ vprint("unregister plugin(%s) from %s", name, dir)
+ end
+end