From 458ca5e8a1dd6b073e8f5102ae0b105cfd40e0f4 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 22:48:44 +0800 Subject: [PATCH 1/7] show list with json --- xmake/plugins/show/showlist.lua | 16 ++++++++++++++-- xmake/plugins/show/xmake.lua | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index 923228e425b..4e9c29c1efc 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -21,9 +21,9 @@ -- imports import("core.base.option") import("core.base.text") +import("core.base.json") --- show values -function main(values) +function _show_text(values) local tbl = {align = 'l', sep = " "} local row = {} for _, value in ipairs(values) do @@ -38,3 +38,15 @@ function main(values) end print(text.table(tbl)) end + +function _show_json(values) + print(json.encode(json.mark_as_array(values))) +end + +function main(values) + if option.get("json") then + _show_json(values) + else + _show_text(values) + end +end diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua index f652ed6203e..bae15471c56 100644 --- a/xmake/plugins/show/xmake.lua +++ b/xmake/plugins/show/xmake.lua @@ -25,11 +25,12 @@ task("show") usage = "xmake show [options] [arguments]", description = "Show the given project information.", options = { - {'l', "list", "kv", nil, "Show the values list of the given name.", + {'l', "list", "kv", nil, "Show the values list of the given name.", values = function (complete, opt) return import("list").lists() end}, - {'t', "target", "kv", nil, "Show the information of the given target.", + {nil, "json", "k", false, "Show information with json format."}, + {'t', "target", "kv", nil, "Show the information of the given target.", values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end} From 01966666e2c6cd565c227b4274c3ae5a723ba837 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 22:55:06 +0800 Subject: [PATCH 2/7] show apis --- xmake/core/package/package.lua | 6 + .../modules/import/core/package/package.lua | 2 + .../modules/import/core/project/option.lua | 8 +- .../modules/import/core/project/rule.lua | 14 +-- .../modules/import/core/project/target.lua | 14 +-- xmake/plugins/show/lists/apis.lua | 118 ++++++++++++++++++ xmake/plugins/show/lists/rules.lua | 2 +- 7 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 xmake/plugins/show/lists/apis.lua diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index abad53326c5..e673f4345f1 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2905,5 +2905,11 @@ function package.load_from_repository(packagename, packagedir, opt) return instance end +-- new a package instance +function package.new(...) + return _instance.new(...) +end + + -- return module return package diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua index 527ae5b645e..a5aa2e9d5da 100644 --- a/xmake/core/sandbox/modules/import/core/package/package.lua +++ b/xmake/core/sandbox/modules/import/core/package/package.lua @@ -32,6 +32,8 @@ sandbox_core_package_package.installdir = package.installdir sandbox_core_package_package.searchdirs = package.searchdirs sandbox_core_package_package.targetplat = package.targetplat sandbox_core_package_package.targetarch = package.targetarch +sandbox_core_package_package.apis = package.apis +sandbox_core_package_package.new = package.new -- load the package from the project file function sandbox_core_package_package.load_from_project(packagename) diff --git a/xmake/core/sandbox/modules/import/core/project/option.lua b/xmake/core/sandbox/modules/import/core/project/option.lua index e96f79d4caf..fe98ccb932a 100644 --- a/xmake/core/sandbox/modules/import/core/project/option.lua +++ b/xmake/core/sandbox/modules/import/core/project/option.lua @@ -25,10 +25,10 @@ local sandbox_core_project_option = sandbox_core_project_option or {} local option = require("project/option") local raise = require("sandbox/modules/raise") --- get the option interpreter -function sandbox_core_project_option.interpreter() - return option.interpreter() -end +-- inherit some builtin interfaces +sandbox_core_project_option.interpreter = option.interpreter +sandbox_core_project_option.new = option.new +sandbox_core_project_option.apis = option.apis -- return module return sandbox_core_project_option diff --git a/xmake/core/sandbox/modules/import/core/project/rule.lua b/xmake/core/sandbox/modules/import/core/project/rule.lua index 1acca90a1a2..f40a69a01ec 100644 --- a/xmake/core/sandbox/modules/import/core/project/rule.lua +++ b/xmake/core/sandbox/modules/import/core/project/rule.lua @@ -28,15 +28,11 @@ local project = require("project/project") local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") --- get the given global rule -function sandbox_core_project_rule.rule(name) - return rule.rule(name) -end - --- get the all global rules -function sandbox_core_project_rule.rules() - return rule.rules() -end +-- inherit some builtin interfaces +sandbox_core_project_rule.rule = rule.rule +sandbox_core_project_rule.rules = rule.rules +sandbox_core_project_rule.new = rule.new +sandbox_core_project_rule.apis = rule.apis -- return module return sandbox_core_project_rule diff --git a/xmake/core/sandbox/modules/import/core/project/target.lua b/xmake/core/sandbox/modules/import/core/project/target.lua index 07424cad38f..e953c3c0ed6 100644 --- a/xmake/core/sandbox/modules/import/core/project/target.lua +++ b/xmake/core/sandbox/modules/import/core/project/target.lua @@ -25,15 +25,11 @@ local sandbox_core_project_target = sandbox_core_project_target or {} local target = require("project/target") local raise = require("sandbox/modules/raise") --- get the filename from the given name and kind -function sandbox_core_project_target.filename(name, kind, opt) - return target.filename(name, kind, opt) -end - --- get the link name of the target file -function sandbox_core_project_target.linkname(filename, opt) - return target.linkname(filename, opt) -end +-- inherit some builtin interfaces +sandbox_core_project_target.filename = target.filename +sandbox_core_project_target.linkname = target.linkname +sandbox_core_project_target.new = target.new +sandbox_core_project_target.apis = target.apis -- return module return sandbox_core_project_target diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua new file mode 100644 index 00000000000..b5d8c5cfea5 --- /dev/null +++ b/xmake/plugins/show/lists/apis.lua @@ -0,0 +1,118 @@ +--!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, TBOOX Open Source Group. +-- +-- @author ruki +-- @file apis.lua +-- + +-- imports +import("core.project.config") +import("core.project.rule") +import("core.project.target") +import("core.project.option") +import("core.package.package") +import(".showlist") + +-- get target apis +function target_apis() + local result = {} + for _, names in pairs(target.apis()) do + for _, name in ipairs(names) do + table.insert(result, name) + end + end + local instance = target.new() + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, "target:" .. k) + end + end + return result +end + +-- get option apis +function option_apis() + local result = {} + for _, names in pairs(option.apis()) do + for _, name in ipairs(names) do + table.insert(result, name) + end + end + local instance = option.new() + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, "option:" .. k) + end + end + return result +end + +-- get rule apis +function rule_apis() + local result = {} + for _, names in pairs(rule.apis()) do + for _, name in ipairs(names) do + table.insert(result, name) + end + end + local instance = rule.new() + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, "rule:" .. k) + end + end + return result +end + +-- get package apis +function package_apis() + local result = {} + for _, names in pairs(package.apis()) do + for _, name in ipairs(names) do + if type(name) == "table" then + name = name[1] + end + table.insert(result, name) + end + end + local instance = package.new() + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, "package:" .. k) + end + end + return result +end + +-- get all apis +function apis() + local result = {} + table.join2(result, target_apis()) + table.join2(result, option_apis()) + table.join2(result, rule_apis()) + table.join2(result, package_apis()) + return result +end + +-- show all apis +function main() + config.load() + local result = apis() + if result then + table.sort(result) + showlist(result) + end +end diff --git a/xmake/plugins/show/lists/rules.lua b/xmake/plugins/show/lists/rules.lua index b6ab2f91953..77c0ea5c244 100644 --- a/xmake/plugins/show/lists/rules.lua +++ b/xmake/plugins/show/lists/rules.lua @@ -23,7 +23,7 @@ import("core.project.config") import("core.project.rule") import(".showlist") --- show all platforms +-- show all rules function main() config.load() local rules = {} From ee9a482a5579e99f922a6df77f0336ce96e98373 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 23:17:31 +0800 Subject: [PATCH 3/7] get some apis --- .../modules/import/core/tool/toolchain.lua | 3 +++ xmake/plugins/show/lists/apis.lua | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua index 667019b1a3c..46bd9fb1d4b 100644 --- a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua +++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua @@ -27,6 +27,9 @@ local toolchain = require("tool/toolchain") local project = require("project/project") local raise = require("sandbox/modules/raise") +-- inherit some builtin interfaces +sandbox_core_tool_toolchain.apis = toolchain.apis + -- get all toolchains list function sandbox_core_tool_toolchain.list() local names = table.copy(platform.toolchains()) diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index b5d8c5cfea5..57acb344884 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -24,6 +24,7 @@ import("core.project.rule") import("core.project.target") import("core.project.option") import("core.package.package") +import("core.tool.toolchain") import(".showlist") -- get target apis @@ -97,6 +98,23 @@ function package_apis() return result end +-- get toolchain apis +function toolchain_apis() + local result = {} + for _, names in pairs(toolchain.apis()) do + for _, name in ipairs(names) do + table.insert(result, name) + end + end + local instance = toolchain.load("clang") + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, "toolchain:" .. k) + end + end + return result +end + -- get all apis function apis() local result = {} @@ -104,6 +122,7 @@ function apis() table.join2(result, option_apis()) table.join2(result, rule_apis()) table.join2(result, package_apis()) + table.join2(result, toolchain_apis()) return result end From 9f2d6865e1d85fbf5a4cf3f6bae1648be32cd5e3 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 23:20:07 +0800 Subject: [PATCH 4/7] add scope and instance apis --- xmake/plugins/show/lists/apis.lua | 84 ++++++++++++++++++++++++------- xmake/plugins/show/showlist.lua | 11 +++- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index 57acb344884..696b7133ccb 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -27,14 +27,20 @@ import("core.package.package") import("core.tool.toolchain") import(".showlist") --- get target apis -function target_apis() +-- get target scope apis +function target_scope_apis() local result = {} for _, names in pairs(target.apis()) do for _, name in ipairs(names) do table.insert(result, name) end end + return result +end + +-- get target instance apis +function target_instance_apis() + local result = {} local instance = target.new() for k, v in pairs(instance) do if not k:startswith("_") and type(v) == "function" then @@ -44,14 +50,20 @@ function target_apis() return result end --- get option apis -function option_apis() +-- get option scope apis +function option_scope_apis() local result = {} for _, names in pairs(option.apis()) do for _, name in ipairs(names) do table.insert(result, name) end end + return result +end + +-- get option instance apis +function option_instance_apis() + local result = {} local instance = option.new() for k, v in pairs(instance) do if not k:startswith("_") and type(v) == "function" then @@ -61,14 +73,20 @@ function option_apis() return result end --- get rule apis -function rule_apis() +-- get rule scope apis +function rule_scope_apis() local result = {} for _, names in pairs(rule.apis()) do for _, name in ipairs(names) do table.insert(result, name) end end + return result +end + +-- get rule instance apis +function rule_instance_apis() + local result = {} local instance = rule.new() for k, v in pairs(instance) do if not k:startswith("_") and type(v) == "function" then @@ -78,8 +96,9 @@ function rule_apis() return result end --- get package apis -function package_apis() + +-- get package scope apis +function package_scope_apis() local result = {} for _, names in pairs(package.apis()) do for _, name in ipairs(names) do @@ -89,6 +108,12 @@ function package_apis() table.insert(result, name) end end + return result +end + +-- get package instance apis +function package_instance_apis() + local result = {} local instance = package.new() for k, v in pairs(instance) do if not k:startswith("_") and type(v) == "function" then @@ -98,14 +123,20 @@ function package_apis() return result end --- get toolchain apis -function toolchain_apis() +-- get toolchain scope apis +function toolchain_scope_apis() local result = {} for _, names in pairs(toolchain.apis()) do for _, name in ipairs(names) do table.insert(result, name) end end + return result +end + +-- get toolchain instance apis +function toolchain_instance_apis() + local result = {} local instance = toolchain.load("clang") for k, v in pairs(instance) do if not k:startswith("_") and type(v) == "function" then @@ -115,23 +146,40 @@ function toolchain_apis() return result end --- get all apis -function apis() +-- get scope apis +function scope_apis() local result = {} - table.join2(result, target_apis()) - table.join2(result, option_apis()) - table.join2(result, rule_apis()) - table.join2(result, package_apis()) - table.join2(result, toolchain_apis()) + table.join2(result, target_scope_apis()) + table.join2(result, option_scope_apis()) + table.join2(result, rule_scope_apis()) + table.join2(result, package_scope_apis()) + table.join2(result, toolchain_scope_apis()) + table.sort(result) return result end +-- get instance apis +function instance_apis() + local result = {} + table.join2(result, target_instance_apis()) + table.join2(result, option_instance_apis()) + table.join2(result, rule_instance_apis()) + table.join2(result, package_instance_apis()) + table.join2(result, toolchain_instance_apis()) + table.sort(result) + return result +end + +-- get all apis +function apis() + return {scope = scope_apis(), instance = instance_apis()} +end + -- show all apis function main() config.load() local result = apis() if result then - table.sort(result) showlist(result) end end diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index 4e9c29c1efc..a80fd3b0199 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -40,13 +40,20 @@ function _show_text(values) end function _show_json(values) - print(json.encode(json.mark_as_array(values))) + print(json.encode(values)) end function main(values) if option.get("json") then _show_json(values) else - _show_text(values) + if table.is_dictionary(values) then + for k, v in pairs(values) do + cprint("${bright}%s:", k) + _show_text(v) + end + else + _show_text(values) + end end end From d00c884b8d6b71f8f232cbb5cd0e7186ad966df9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 23:21:04 +0800 Subject: [PATCH 5/7] add project apis --- .../modules/import/core/project/project.lua | 1 + xmake/plugins/show/lists/apis.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index b8feddefc24..c197ff77086 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -70,6 +70,7 @@ sandbox_core_project.policy = project.policy sandbox_core_project.tmpdir = project.tmpdir sandbox_core_project.tmpfile = project.tmpfile sandbox_core_project.is_loaded = project.is_loaded +sandbox_core_project.apis = project.apis -- check project options function sandbox_core_project.check_options() diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index 696b7133ccb..cfd243c63a0 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -22,11 +22,26 @@ import("core.project.config") import("core.project.rule") import("core.project.target") +import("core.project.project") import("core.project.option") import("core.package.package") import("core.tool.toolchain") import(".showlist") +-- get project scope apis +function project_scope_apis() + local result = {} + for _, names in pairs(project.apis()) do + for _, name in ipairs(names) do + if type(name) == "table" then + name = name[1] + end + table.insert(result, name) + end + end + return result +end + -- get target scope apis function target_scope_apis() local result = {} @@ -149,6 +164,7 @@ end -- get scope apis function scope_apis() local result = {} + table.join2(result, project_scope_apis()) table.join2(result, target_scope_apis()) table.join2(result, option_scope_apis()) table.join2(result, rule_scope_apis()) From 02af5e5ee379711fed6327ae1d52c9ff792510cc Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 23:28:31 +0800 Subject: [PATCH 6/7] show module apis --- .../modules/import/core/sandbox/sandbox.lua | 9 +-- xmake/core/sandbox/sandbox.lua | 71 ++++++++----------- xmake/plugins/show/lists/apis.lua | 68 +++++++++++++++++- 3 files changed, 102 insertions(+), 46 deletions(-) diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index c189f398e28..688707e4c4e 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -127,16 +127,17 @@ end -- get the filter of the current sandbox for the given script function sandbox_core_sandbox.filter(script) - - -- get the current sandbox instance local instance = sandbox.instance(script) if not instance then raise("cannot get sandbox instance!") end - - -- get it return instance:filter() end +-- get all builtin modules +function sandbox_core_sandbox.builtin_modules() + return sandbox.builtin_modules() +end + -- return module return sandbox_core_sandbox diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 766e6061c3f..1e0817a4eaf 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -90,50 +90,10 @@ end -- register api for builtin function sandbox._api_register_builtin(self, name, func) - - -- check assert(self and self._PUBLIC and func) - - -- register it self._PUBLIC[name] = func end --- get builtin modules -function sandbox._builtin_modules() - local builtin_modules = sandbox._BUILTIN_MODULES - if builtin_modules == nil then - builtin_modules = {} - local builtin_module_files = os.match(path.join(os.programdir(), "core/sandbox/modules/*.lua")) - if builtin_module_files then - for _, builtin_module_file in ipairs(builtin_module_files) do - - -- the module name - local module_name = path.basename(builtin_module_file) - assert(module_name) - - -- load script - local script, errors = loadfile(builtin_module_file) - if script then - - -- load module - local ok, results = utils.trycall(script) - if not ok then - os.raise(results) - end - - -- save module - builtin_modules[module_name] = results - else - -- error - os.raise(errors) - end - end - end - sandbox._BUILTIN_MODULES = builtin_modules - end - return builtin_modules -end - -- new a sandbox instance function sandbox._new() @@ -145,7 +105,7 @@ function sandbox._new() -- register the builtin modules instance:_api_register_builtin("_g", {}) - for module_name, module in pairs(sandbox._builtin_modules()) do + for module_name, module in pairs(sandbox.builtin_modules()) do instance:_api_register_builtin(module_name, module) end @@ -350,5 +310,34 @@ function sandbox.instance(script) return instance end +-- get builtin modules +function sandbox.builtin_modules() + local builtin_modules = sandbox._BUILTIN_MODULES + if builtin_modules == nil then + builtin_modules = {} + local builtin_module_files = os.files(path.join(os.programdir(), "core/sandbox/modules/*.lua")) + if builtin_module_files then + for _, builtin_module_file in ipairs(builtin_module_files) do + local module_name = path.basename(builtin_module_file) + assert(module_name) + + local script, errors = loadfile(builtin_module_file) + if script then + local ok, results = utils.trycall(script) + if not ok then + os.raise(results) + end + builtin_modules[module_name] = results + else + os.raise(errors) + end + end + end + sandbox._BUILTIN_MODULES = builtin_modules + end + return builtin_modules +end + + -- return module return sandbox diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index cfd243c63a0..46f36946452 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -25,9 +25,21 @@ import("core.project.target") import("core.project.project") import("core.project.option") import("core.package.package") +import("core.sandbox.sandbox") import("core.tool.toolchain") import(".showlist") +function _is_callable(func) + if type(func) == "function" then + return true + elseif type(func) == "table" then + local meta = debug.getmetatable(func) + if meta and meta.__call then + return true + end + end +end + -- get project scope apis function project_scope_apis() local result = {} @@ -186,9 +198,63 @@ function instance_apis() return result end +-- get builtin module apis +function builtin_module_apis() + local builtin_modules = table.clone(sandbox.builtin_modules()) + builtin_modules.pairs = nil + builtin_modules.ipairs = nil + local result = {} + for name, value in pairs(builtin_modules) do + if type(value) == "table" then + for k, v in pairs(value) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, name .. "." .. k) + end + end + elseif type(value) == "function" then + table.insert(result, name) + end + end + table.insert(result, "ipairs") + table.insert(result, "pairs") + table.sort(result) + return result +end + +-- get import module apis +function import_module_apis() + local result = {} + local modulefiles = os.files(path.join(os.programdir(), "modules/**.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua")) + if modulefiles then + for _, modulefile in ipairs(modulefiles) do + local modulename = path.relative(modulefile, path.join(os.programdir(), "modules")) + if path.filename(modulename) == "main.lua" then + modulename = path.directory(modulename) + end + modulename = modulename:gsub("/", "."):gsub("%.lua", "") + local instance = import(modulename, {try = true, anonymous = true}) + if _is_callable(instance) then + table.insert(result, modulename) + elseif type(instance) == "table" then + for k, v in pairs(instance) do + print(k) + if not k:startswith("_") and type(v) == "function" then + table.insert(result, modulename .. "." .. k) + end + end + end + end + end + table.sort(result) + return result +end + -- get all apis function apis() - return {scope = scope_apis(), instance = instance_apis()} + return {scope = scope_apis(), + instance = instance_apis(), + builtin_module = builtin_module_apis(), + import_module = import_module_apis()} end -- show all apis From c5b45c157bba1c348d8d95dc103377859a8cdfe9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Apr 2024 23:28:55 +0800 Subject: [PATCH 7/7] export all modules --- xmake/plugins/show/lists/apis.lua | 36 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/xmake/plugins/show/lists/apis.lua b/xmake/plugins/show/lists/apis.lua index 46f36946452..272b614e03a 100644 --- a/xmake/plugins/show/lists/apis.lua +++ b/xmake/plugins/show/lists/apis.lua @@ -26,6 +26,7 @@ import("core.project.project") import("core.project.option") import("core.package.package") import("core.sandbox.sandbox") +import("core.sandbox.module") import("core.tool.toolchain") import(".showlist") @@ -224,22 +225,25 @@ end -- get import module apis function import_module_apis() local result = {} - local modulefiles = os.files(path.join(os.programdir(), "modules/**.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua")) - if modulefiles then - for _, modulefile in ipairs(modulefiles) do - local modulename = path.relative(modulefile, path.join(os.programdir(), "modules")) - if path.filename(modulename) == "main.lua" then - modulename = path.directory(modulename) - end - modulename = modulename:gsub("/", "."):gsub("%.lua", "") - local instance = import(modulename, {try = true, anonymous = true}) - if _is_callable(instance) then - table.insert(result, modulename) - elseif type(instance) == "table" then - for k, v in pairs(instance) do - print(k) - if not k:startswith("_") and type(v) == "function" then - table.insert(result, modulename .. "." .. k) + local moduledirs = module.directories() + for _, moduledir in ipairs(moduledirs) do + moduledir = path.absolute(moduledir) + local modulefiles = os.files(path.join(moduledir, "**.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua")) + if modulefiles then + for _, modulefile in ipairs(modulefiles) do + local modulename = path.relative(modulefile, moduledir) + if path.filename(modulename) == "main.lua" then + modulename = path.directory(modulename) + end + modulename = modulename:gsub("/", "."):gsub("%.lua", "") + local instance = import(modulename, {try = true, anonymous = true}) + if _is_callable(instance) then + table.insert(result, modulename) + elseif type(instance) == "table" then + for k, v in pairs(instance) do + if not k:startswith("_") and type(v) == "function" then + table.insert(result, modulename .. "." .. k) + end end end end