diff options
| author | ruki <[email protected]> | 2026-08-11 23:36:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-11 23:36:21 +0800 |
| commit | 9e6abef8b0a26d7098d79749dd68b5a2590512c4 (patch) | |
| tree | 58d2fdcc1d01e9c7c1c0c47a900ba458d36cac40 | |
| parent | 1cb3fd90ef205361dad1276e58e63d67bda6f283 (diff) | |
revert option.parse
| -rw-r--r-- | xmake/actions/create/template.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 9 | ||||
| -rw-r--r-- | xmake/core/package/addon.lua | 15 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/option.lua | 14 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/addon.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/module.lua | 8 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 6 |
8 files changed, 31 insertions, 38 deletions
diff --git a/xmake/actions/create/template.lua b/xmake/actions/create/template.lua index fa812468c..ac39e2ff8 100644 --- a/xmake/actions/create/template.lua +++ b/xmake/actions/create/template.lua @@ -108,10 +108,10 @@ function templatedir(lang, templateid) -- @note the template ids are not namespaced, we only need it to disambiguate the conflicts -- if templateid:startswith("@addon/") then - local templatesdir, id = addon.resolve_reference(templateid, "/", "templates") - local subdir = _templateid_subdir(id) + local referenceinfo = addon.resolve_reference(templateid, "/", "templates") + local subdir = _templateid_subdir(referenceinfo.name) if subdir then - local dir = path.join(templatesdir, lang, subdir) + local dir = path.join(referenceinfo.dir, lang, subdir) if os.isfile(path.join(dir, "xmake.lua")) then return dir end diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 7a08446d8..d2b0ae889 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1815,16 +1815,17 @@ function interpreter:api_builtin_includes(...) -- attempt to find files from the includes of the addons -- e.g. includes("@addon/esp32/check"), includes("@self/check") if not found and addon.is_reference(subpath, "/") then - local includesdir, addon_path, _, errors = addon.resolve_reference(subpath, "/", "includes", + local referenceinfo, errors = addon.resolve_reference(subpath, "/", "includes", {scriptdir = self:scriptdir()}) - if not includesdir then + if not referenceinfo then os.raise(errors) end local files + local addon_path = referenceinfo.name if addon_path:endswith(".lua") then - files = os.files(path.join(includesdir, addon_path)) + files = os.files(path.join(referenceinfo.dir, addon_path)) else - files = os.files(path.join(includesdir, addon_path, "xmake.lua")) + files = os.files(path.join(referenceinfo.dir, addon_path, "xmake.lua")) end if files and #files > 0 then table.join2(subpaths_matched, files) diff --git a/xmake/core/package/addon.lua b/xmake/core/package/addon.lua index 727da926a..e5b03b959 100644 --- a/xmake/core/package/addon.lua +++ b/xmake/core/package/addon.lua @@ -349,7 +349,8 @@ end -- @param kind the payload kind, e.g. "rules", "modules" -- @param opt the options, e.g. {scriptdir = "..."}, it's used to resolve `@self` -- --- @return the payload directory, the resource name, the addon name and errors +-- @return the reference information and errors, +-- e.g. {dir = "~/.xmake/addons/esp32/v1.0.0/rules", name = "flash", addon = "esp32"} -- function addon.resolve_reference(reference, sep, kind, opt) opt = opt or {} @@ -358,13 +359,13 @@ function addon.resolve_reference(reference, sep, kind, opt) if reference:startswith("@self" .. sep) then local name = reference:sub(#("@self" .. sep) + 1) if name == "" then - return nil, nil, nil, string.format("invalid addon reference(%s)!", reference) + return nil, string.format("invalid addon reference(%s)!", reference) end local addonname, addondir = addon.owner(opt.scriptdir) if not addondir then - return nil, nil, nil, string.format("%s: cannot resolve `@self`, it can only be used inside an addon!", reference) + return nil, string.format("%s: cannot resolve `@self`, it can only be used inside an addon!", reference) end - return path.join(addondir, kind), name, addonname + return {dir = path.join(addondir, kind), name = name, addon = addonname} end -- resolve the `@addon` reference, the addon name is always required @@ -376,13 +377,13 @@ function addon.resolve_reference(reference, sep, kind, opt) local addonname = pos and reference:sub(#prefix + 1, pos - 1) local name = pos and reference:sub(pos + 1) if not addonname or addonname == "" or not name or name == "" then - return nil, nil, nil, string.format("invalid addon reference(%s), it should be `@addon%s<addon>%s<name>`", reference, sep, sep) + return nil, string.format("invalid addon reference(%s), it should be `@addon%s<addon>%s<name>`", reference, sep, sep) end local payloaddir = addon._payloaddir(addonname, kind) if not payloaddir then - return nil, nil, addonname, string.format("%s not found!\nplease install the addon which provides it first: xmake addon --install %s", reference, addonname) + return nil, string.format("%s not found!\nplease install the addon which provides it first: xmake addon --install %s", reference, addonname) end - return payloaddir, name, addonname + return {dir = payloaddir, name = name, addon = addonname} end -- get all installed addons diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index d98696503..f4d2be491 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -467,11 +467,12 @@ end function rule.rule(name) local instance = rule.rules()[name] if instance == nil and name:startswith("@addon/") then - local _, _, addonname, errors = addon.resolve_reference(name, "/", "rules") + local referenceinfo, errors = addon.resolve_reference(name, "/", "rules") if errors then os.raise(errors) end - os.raise("rule(%s) not found!\nplease install the addon which provides it first: xmake addon --install %s", name, addonname or "<addon>") + os.raise("rule(%s) not found!\nplease install the addon which provides it first: xmake addon --install %s", + name, referenceinfo and referenceinfo.addon or "<addon>") end return instance end diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua index e30c8ad9d..983978917 100644 --- a/xmake/core/sandbox/modules/import/core/base/option.lua +++ b/xmake/core/sandbox/modules/import/core/base/option.lua @@ -69,10 +69,6 @@ function sandbox_core_base_option.raw_parse(argv, options, opt) end -- parse arguments with the given options --- --- @note we can also pass the extra options in the last argument, --- e.g. option.parse(argv, options, "the description", {allow_unknown = true}) --- function sandbox_core_base_option.parse(argv, options, ...) assert(argv and options) @@ -81,14 +77,8 @@ function sandbox_core_base_option.parse(argv, options, ...) table.insert(options, 2, {'h', "help", "k", nil, "Print this help message and exit." }) table.insert(options, 3, {}) - -- get the descriptions and the extra options - local descriptions = {...} - local opt - if type(descriptions[#descriptions]) == "table" then - opt = table.join({populate_defaults = true}, table.remove(descriptions)) - end - -- show help + local descriptions = {...} local function show_help() for _, description in ipairs(descriptions) do print(description) @@ -97,7 +87,7 @@ function sandbox_core_base_option.parse(argv, options, ...) end -- parse it - local results, errors = option.parse(argv, options, opt) + local results, errors = option.parse(argv, options) if not results then show_help() raise(errors) diff --git a/xmake/core/sandbox/modules/import/core/package/addon.lua b/xmake/core/sandbox/modules/import/core/package/addon.lua index c1c7f5b1d..b297347c6 100644 --- a/xmake/core/sandbox/modules/import/core/package/addon.lua +++ b/xmake/core/sandbox/modules/import/core/package/addon.lua @@ -59,14 +59,14 @@ end -- @param kind the payload kind, e.g. "rules", "modules" -- @param opt the options, e.g. {scriptdir = "..."} -- --- @return the payload directory, the name, the addon name +-- @return the reference information, e.g. {dir = "...", name = "flash", addon = "esp32"} -- function sandbox_core_package_addon.resolve_reference(reference, sep, kind, opt) - local payloaddir, name, addonname, errors = addon.resolve_reference(reference, sep, kind, opt) + local referenceinfo, errors = addon.resolve_reference(reference, sep, kind, opt) if errors then raise(errors) end - return payloaddir, name, addonname + return referenceinfo end -- register the given installed addon diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index 6daba311e..3fd2d0fe6 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -539,13 +539,13 @@ function core_sandbox_module.import(name, opt) local addon_modulesdir local addon_reference = name if addon.is_reference(name, ".") then - local modulesdir, modulename, addonname, errors = addon.resolve_reference(name, ".", "modules", + local referenceinfo, errors = addon.resolve_reference(name, ".", "modules", {scriptdir = opt.scriptdir or sandbox.instance() and sandbox.instance():rootdir()}) - if not modulesdir then + if not referenceinfo then raise(errors) end - addon_modulesdir = modulesdir - name = modulename + addon_modulesdir = referenceinfo.dir + name = referenceinfo.name end -- get module name diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 9c3080026..76438abfa 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -823,12 +823,12 @@ function toolchain.load(name, opt) local scriptpath = nil if parseinfo.addon_prefix then -- e.g. set_toolchains("@addon/esp32/xtensa"), set_toolchains("@self/xtensa") - local toolchainsdir, toolchainname, _, errors = addon.resolve_reference(parseinfo.addon_prefix .. name, "/", "toolchains", + local referenceinfo, errors = addon.resolve_reference(parseinfo.addon_prefix .. name, "/", "toolchains", {scriptdir = opt.scriptdir}) - if not toolchainsdir then + if not referenceinfo then return nil, errors end - scriptpath = path.join(toolchainsdir, toolchainname, "xmake.lua") + scriptpath = path.join(referenceinfo.dir, referenceinfo.name, "xmake.lua") else for _, dir in ipairs(toolchain.directories()) do scriptpath = path.join(dir, name, "xmake.lua") |
