xmake从v2.0开始,全面支持插件模式,咱们能够很方便的扩展实现本身的插件,而且xmake也提供了一些内建的使用插件git
咱们能够执行下 xmake -h
看下当前支持的插件:github
Plugins: l, lua Run the lua script. m, macro Run the given macro. doxygen Generate the doxygen document. hello Hello xmake! project Create the project file.
接下来咱们介绍下本文的重点,一个简单的hello xmake插件的开发,代码以下:xcode
-- 定义一个名叫hello的插件任务 task("hello") -- 设置类型为插件 set_category("plugin") -- 插件运行的入口 on_run(function () -- 显示hello xmake! print("hello xmake!") end) -- 设置插件的命令行选项,这里没有任何参数选项,仅仅显示插件描述 set_menu({ -- usage usage = "xmake hello [options]" -- description , description = "Hello xmake!" -- options , options = {} })
这个插件的文件结构以下:bash
hello - xmake.lua
如今一个最简单的插件写完了,那怎么让它被xmake检测到呢,有三种方式:ui
add_plugindirs("./hello")
添加当前的工程的插件搜索目录,这样只对当前工程生效接下来,咱们尝试运行下这个插件:lua
xmake hello
显示结果:.net
hello xmake!
固然你能够经过set_menu中添加一些自定义的参数,这个等后续再详细介绍插件
最后咱们还能够在target自定义的脚本中运行这个插件:命令行
target("demo") -- 构建以后运行插件 after_build(function (target) -- 导入task模块 import("core.project.task") -- 运行插件任务 task.run("hello") end)