diff options
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/doxygen/main.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/format/main.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/macro/main.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/pack/wix/main.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/plugin/main.lua | 315 | ||||
| -rw-r--r-- | xmake/plugins/plugin/xmake.lua | 17 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 11 | ||||
| -rw-r--r-- | xmake/plugins/project/ninja/build_ninja.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/project/utils/target_cmds.lua | 3 |
9 files changed, 240 insertions, 123 deletions
diff --git a/xmake/plugins/doxygen/main.lua b/xmake/plugins/doxygen/main.lua index 80fd77675..b84754cb2 100644 --- a/xmake/plugins/doxygen/main.lua +++ b/xmake/plugins/doxygen/main.lua @@ -71,6 +71,10 @@ end function main() + -- @note we cannot use utils.warning() here, it's queued and only shown at the end + cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake doxygen` plugin is deprecated, " .. + "please use the doxygen-plugin addon: `xmake addon --install doxygen-plugin`") + -- load configuration config.load() diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua index 408de0421..c8f50a15e 100644 --- a/xmake/plugins/format/main.lua +++ b/xmake/plugins/format/main.lua @@ -103,6 +103,10 @@ end -- main function main() + -- @note we cannot use utils.warning() here, it's queued and only shown at the end + cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake format` plugin is deprecated, " .. + "please use the format-plugin addon: `xmake addon --install format-plugin`") + -- load configuration config.load() diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index 86b50e2da..6c2c8c734 100644 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -309,6 +309,10 @@ end -- main function main() + -- @note we cannot use utils.warning() here, it's queued and only shown at the end + cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake macro` plugin is deprecated, " .. + "please use the macro-plugin addon: `xmake addon --install macro-plugin`") + -- list macros if option.get("list") then diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index e12461883..f91c15273 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -326,7 +326,7 @@ function _pack_wix(wix, package) table.join2(argv, {"-ext", "WixToolset.UI.wixext"}) table.join2(argv, {"-o", package:outputfile()}) - if package:arch() == "x64" then + if package:is_arch("x64", "x86_64") then table.join2(argv, {"-arch", "x64"}) elseif package:arch() == "x86" then table.join2(argv, {"-arch", "x86"}) diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua index b362381e4..ce1ac3e4f 100644 --- a/xmake/plugins/plugin/main.lua +++ b/xmake/plugins/plugin/main.lua @@ -21,146 +21,235 @@ -- imports import("core.base.option") import("core.base.global") +import("core.package.repository") import("devel.git") -import("net.fasturl") import("private.action.require.impl.environment") +import("private.action.require.impl.install_packages") --- get plugin urls -function _plugin_urls() - local urls = option.get("plugins") - if urls then - local result = {} - for _, url in ipairs(urls) do - table.insert(result, git.asgiturl(url) or url) - end - urls = result - else - urls = { - "https://github.com/xmake-io/xmake-plugins.git", - "https://gitlab.com/tboox/xmake-plugins.git", - "https://gitee.com/tboox/xmake-plugins.git"} - urls = fasturl.add(urls) - urls = fasturl.sort(urls) +-- validate a plugin directory name +function _check_plugin_name(name) + assert(type(name) == "string" and name ~= "" and name ~= "." and not name:find("..", 1, true) and not name:find("[/\\:]"), "invalid plugin name(%s)!", name) + return name +end + +-- get plugin directory in ~/.xmake/plugins +function _get_plugindir(name) + local plugindir = path.join(global.directory(), "plugins") + return name and path.join(plugindir, _check_plugin_name(name)) or plugindir +end + +-- get local and global repositories, with local taking precedence +function _repositories() + return table.join(repository.repositories({global = false}), repository.repositories({global = true})) +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) + + -- do install + local installname = name + if reponame then + installname = reponame .. "@" .. name + end + local argv = {"lua", "private.xrepo", "install", "--plugin"} + -- we need to pass the common options to the sub-process, e.g. -y, -v, -D + if option.get("yes") then + table.insert(argv, "-y") end - return urls + if option.get("verbose") then + table.insert(argv, "-v") + end + if option.get("diagnosis") then + table.insert(argv, "-D") + end + table.insert(argv, installname) + os.execv(os.programfile(), argv) end --- get manifest path -function _manifest_path() - return path.join(global.directory(), "plugins", "manifest.txt") +-- install a single plugin from a source directory (as the given name, default to the directory name) +function _install_from_local(dir, name) + assert(os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")), "plugin path(%s): ${bright}xmake.lua${clear} not found!", dir) + name = name or path.filename(path.absolute(dir)) + local dstdir = _get_plugindir(name) + assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) + os.vcp(dir, dstdir) + cprint("${color.success}install ${bright}%s${clear} ok!", name) end --- load manifest -function _load_manifest() - local manifest_path = _manifest_path() - if os.isfile(manifest_path) then - return io.load(manifest_path) +-- install a single plugin from a git url or github shortcut, e.g. https://github.com/xmake-io/hello-world +function _install_from_git(url) + local branch + if url:startswith("github:") then + local i = url:find("#", 1, true) + if i then + branch = url:sub(i + 1) + url = url:sub(1, i - 1) + end + url = git.asgiturl(url) end + local name = (path.filename(url):gsub("%.git$", "")) + local tmpdir = os.tmpfile() .. ".dir" + git.clone(url, {verbose = option.get("verbose"), branch = branch, outputdir = tmpdir}) + os.tryrm(path.join(tmpdir, ".git")) + _install_from_local(tmpdir, name) + os.tryrm(tmpdir) end --- save manifest -function _save_manifest(manifest) - io.save(_manifest_path(), manifest) +-- install a single plugin +function _install_one(name) + -- parse repo@plugin format + local i = name:find("@", 1, true) + if i and not name:find("[/\\:]") then + local reponame = name:sub(1, i - 1) + local pluginname = name:sub(i + 1) + _install_plugins_from_repo(pluginname, reponame) + return + end + + -- github shortcut: github:user/repo or github:user/repo#branch + if name:startswith("github:") then + _install_from_git(name) + return + end + + -- git url or local path + if git.asgiturl(name) then + _install_from_git(name) + return + elseif os.isdir(name) then + _install_from_local(name) + return + end + + -- plain name: try to find it in repositories + _install_plugins_from_repo(name) end -- install plugins function _install() - - -- enter environment + local names = assert(option.get("plugins"), "please specify the plugins to be installed!") environment.enter() + for _, name in ipairs(names) do + _install_one(name) + end + environment.leave() +end - try - { - function () +-- remove the given installed plugin +function _remove() + local names = assert(option.get("plugins"), "please specify the plugin name to be removed!") + assert(#names == 1, "please specify only one plugin name to be removed!") + local name = names[1] + local dir = _get_plugindir(name) + assert(os.isdir(dir), "plugin(%s) not found!", name) + os.rmdir(dir) + cprint("${color.success}remove ${bright}%s${clear} ok!", name) +end - -- do install - local urls = _plugin_urls() - local tmpdir = os.tmpfile() .. ".dir" - local plugindir = path.join(global.directory(), "plugins") - local installed_url - for _, url in ipairs(urls) do - cprint("installing plugins from %s ..", url) - git.clone(url, {verbose = option.get("verbose"), outputdir = tmpdir}) - installed_url = url - break - end - for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do - local srcdir = path.directory(filepath) - local name = path.filename(srcdir) - local dstdir = path.join(plugindir, name) - assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) - os.vcp(srcdir, dstdir) - cprint(" ${yellow}->${clear} %s", name) - end - os.tryrm(tmpdir) +-- get the description of a plugin from its xmake.lua menu +function _plugin_description(dir) + local filepath = path.join(dir, "xmake.lua") + if os.isfile(filepath) then + local content = io.readfile(filepath) + if content then + -- parse description from task or package scope + return content:match("description%s*=%s*\"(.-)\"") or content:match("set_description%s*%(\"(.-)\"%)") + end + end +end - -- save manifest - if installed_url then - local manifest = _load_manifest() or {} - manifest.urls = manifest.urls or {} - table.join2(manifest.urls, installed_url) - _save_manifest(manifest) - end - cprint("${bright}all plugins have been installed in %s!", plugindir) - end, - catch - { - function (errors) - raise(errors) +-- collect plugins (each subdirectory containing xmake.lua) under the given root +-- +-- built-in/installed plugins are flat (<root>/<name>), while plugins in a +-- repository follow the packages layout (<root>/<first-letter>/<name>) +function _collect_plugins(root, seen, nested) + local entries = {} + local pattern = nested and path.join(root, "*", "*") or path.join(root, "*") + for _, dir in ipairs(os.dirs(pattern) or {}) do + local name = path.filename(dir) + if os.isfile(path.join(dir, "xmake.lua")) and (not seen or not seen[name]) then + if seen then + seen[name] = true end - } - } + table.insert(entries, {name = name, description = _plugin_description(dir)}) + end + end + return entries +end - -- leave environment - environment.leave() +-- print a plugin entry with its description aligned on the right +function _print_plugin(name, description, width, note) + local suffix = description or "" + if note then + suffix = suffix ~= "" and (suffix .. " " .. note) or note + end + if suffix ~= "" then + local padding = math.max(width - #name, 1) + cprint(" ${color.dump.string}%s${clear}%s%s", name, (" "):rep(padding), suffix) + else + cprint(" ${color.dump.string}%s${clear}", name) + end end --- update plugins -function _update() +-- list all plugins +function _list() + local seen = {} - -- enter environment - environment.enter() + -- collect plugins from every source + local builtin = _collect_plugins(path.join(os.programdir(), "plugins"), seen) + local plugindir = _get_plugindir() + local installed = _collect_plugins(plugindir, seen) + local avail = {} + for _, repo in ipairs(_repositories()) do + table.join2(avail, _collect_plugins(path.join(repo:directory(), "plugins"), seen, true)) + end - try - { - function () + -- compute the alignment width from all plugin names + local width = 0 + for _, entries in ipairs({builtin, installed, avail}) do + for _, entry in ipairs(entries) do + width = math.max(width, #entry.name + 4) + end + end - -- do update - local manifest = _load_manifest() - assert(manifest and manifest.urls, "3rd plugins not found!") - local urls = manifest.urls - local plugindir = path.join(global.directory(), "plugins") - for _, url in ipairs(urls) do - cprint("updating plugins from %s ..", url) - local tmpdir = os.tmpfile() .. ".dir" - git.clone(url, {verbose = option.get("verbose"), outputdir = tmpdir}) - for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do - local srcdir = path.directory(filepath) - local name = path.filename(srcdir) - local dstdir = path.join(plugindir, name) - os.tryrm(dstdir) - os.vcp(srcdir, dstdir) - cprint(" ${yellow}->${clear} %s", name) - end - os.tryrm(tmpdir) - end - cprint("${bright}all plugins have been updated in %s!", plugindir) - end, - catch - { - function (errors) - raise(errors) - end - } - } + -- built-in plugins + cprint("${bright}the built-in plugins:${clear}") + if #builtin > 0 then + for _, entry in ipairs(builtin) do + _print_plugin(entry.name, entry.description, width) + end + else + print(" (none)") + end - -- leave environment - environment.leave() + -- installed plugins + cprint("${bright}the installed plugins:${clear}") + if #installed > 0 then + for _, entry in ipairs(installed) do + _print_plugin(entry.name, entry.description, width) + end + else + print(" (none)") + end + + -- plugins available in repositories (not yet installed) + cprint("${bright}available in configured repositories:${clear}") + if #avail > 0 then + for _, entry in ipairs(avail) do + local note = string.format("(run xmake plugin --install %s to install)", entry.name) + _print_plugin(entry.name, entry.description, width, note) + end + else + print(" (none)") + end end -- clear all installed plugins function _clear() - local plugindir = path.join(global.directory(), "plugins") + local plugindir = _get_plugindir() if os.isdir(plugindir) then os.rmdir(plugindir) end @@ -168,12 +257,14 @@ function _clear() end function main() + cprint("${bright color.warning}${text.warning}: ${color.warning}`xmake plugin` is deprecated, please use `xmake addon` instead!") if option.get("install") then _install() - elseif option.get("update") then - _update() + elseif option.get("remove") then + _remove() + elseif option.get("list") then + _list() elseif option.get("clear") then _clear() end end - diff --git a/xmake/plugins/plugin/xmake.lua b/xmake/plugins/plugin/xmake.lua index 05d9e3631..1136b0044 100644 --- a/xmake/plugins/plugin/xmake.lua +++ b/xmake/plugins/plugin/xmake.lua @@ -23,14 +23,21 @@ task("plugin") on_run("main") set_menu { usage = "xmake plugin [options]", - description = "Manage plugins of xmake.", + description = "Manage plugins of xmake. (deprecated, please use `xmake addon` instead)", options = { {'i', "install", "k", nil, "Install plugins."}, - {'u', "update", "k", nil, "Update plugins."}, + {'r', "remove", "k", nil, "Remove the given installed plugin."}, + {'l', "list", "k", nil, "List all installed plugins."}, {'c', "clear", "k", nil, "Clear all installed plugins."}, - {nil, "plugins", "v", nil, "The plugins path or url.", + {nil, "plugins", "vs", nil, "The plugin paths, urls or names.", "e.g.", - " $ xmake plugin --install https://github.com/xmake-io/xmake-plugins", - " $ xmake plugin --update"} + " $ xmake plugin --install https://github.com/myrepo/hello-world", + " $ xmake plugin --install github:myrepo/hello-world", + " $ xmake plugin --install github:myrepo/hello-world#dev", + " $ xmake plugin --install /tmp/my-plugin", + " $ xmake plugin --install xmake-repo@hello-world", + " $ xmake plugin --install hello-world", + " $ xmake plugin --remove hello-world", + " $ xmake plugin --list"} } } diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 2f25194cc..a8fdb547f 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -69,10 +69,13 @@ end -- specify windows sdk verison function _get_windows_sdk_arguments(target) local args = {} - local msvc = target:toolchain("msvc") - if msvc then - local envs = msvc:runenvs() - if envs then + if target and target:is_plat("windows") then + local toolchain = target:toolchain("msvc") or + target:toolchain("clang-cl") or + target:toolchain("clang") or + target:toolchain("llvm") + local envs = toolchain and toolchain:runenvs() + if envs and envs.INCLUDE then for _, dir in ipairs(path.splitenv(envs.INCLUDE)) do table.insert(args, "-imsvc") table.insert(args, dir) diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index f89915e02..bd9a3d292 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -37,7 +37,8 @@ function _sourcebatch_is_built(sourcebatch) local rulename = sourcebatch.rulename if rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or rulename == "cuda.build" - or rulename == "objc.build" or rulename == "objc++.build" then + or rulename == "objc.build" or rulename == "objc++.build" + or rulename == "win.sdk.resource" then return true end end diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua index 7ea3a13a0..1c5fed7c8 100644 --- a/xmake/plugins/project/utils/target_cmds.lua +++ b/xmake/plugins/project/utils/target_cmds.lua @@ -87,6 +87,9 @@ function get_target_buildcmds(target, opt) cmd.program = os.programfile() cmd.argv = table.join("lua", cmd.script, cmd.argv) cmd.script = nil + elseif cmd.func and kind == "call" then + local name = cmd.opt and cmd.opt.name or "unknown" + wprint("%s: batchcmds:call() is not supported by the project generator and will be ignored!", name) end end return buildcmds:cmds() |
