diff options
| author | ruki <[email protected]> | 2026-08-15 14:15:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-15 14:15:54 +0800 |
| commit | 7cb3e6f407ea50bdbd2419cbf47454b7ffe9f78d (patch) | |
| tree | 8dd4b6c18f50f14e1e1087217a4d014c3036f138 | |
| parent | 9926b3eb72c04382dd91e92d9c44fb03767e859e (diff) | |
use table.orderpairs
| -rw-r--r-- | xmake/actions/addon/main.lua | 5 | ||||
| -rw-r--r-- | xmake/core/package/addon.lua | 17 |
2 files changed, 7 insertions, 15 deletions
diff --git a/xmake/actions/addon/main.lua b/xmake/actions/addon/main.lua index aa1edd04e..c2ecdb892 100644 --- a/xmake/actions/addon/main.lua +++ b/xmake/actions/addon/main.lua @@ -246,7 +246,7 @@ end -- function _collect_installed_addons() local entries = {} - for name, addoninfo in pairs(addon.addons()) do + for name, addoninfo in table.orderpairs(addon.addons()) do -- an addon can be installed with several versions, we show the active one, -- the projects can lock the other ones, @see core/project/addons.lua local versions = addon.versions(name) @@ -254,7 +254,6 @@ function _collect_installed_addons() versions = #versions > 1 and versions or nil, description = addoninfo.description, payloads = addoninfo.payloads}) end - table.sort(entries, function (a, b) return a.name < b.name end) return entries end @@ -271,7 +270,7 @@ end -- get the addons in the repositories, we reuse the packages search here function _collect_repo_addons(exclude) local entries = {} - for _, results in pairs(search_packages({"*"}, {kind = "addon", description = false})) do + for _, results in table.orderpairs(search_packages({"*"}, {kind = "addon", description = false})) do for _, result in ipairs(results) do if not exclude[result.name] then table.insert(entries, result) diff --git a/xmake/core/package/addon.lua b/xmake/core/package/addon.lua index 4a4c8f50a..8787ab73a 100644 --- a/xmake/core/package/addon.lua +++ b/xmake/core/package/addon.lua @@ -183,7 +183,7 @@ end function addon._parents(name) local dirname = addon.dirname(name) local parents - for otherdirname, entry in pairs(addon._registry()) do + for otherdirname, entry in table.orderpairs(addon._registry()) do if otherdirname ~= dirname then for _, addoninfo in pairs(entry.versions or {}) do if table.contains(addoninfo.deps or {}, dirname) then @@ -194,9 +194,6 @@ function addon._parents(name) end end end - if parents then - table.sort(parents) - end return parents end @@ -487,13 +484,8 @@ end -- get all the installed versions of the given addon, e.g. {"1.0.2", "1.0.3"} function addon.versions(name) - local versions = {} local addoninfo = addon._registry()[addon.dirname(name)] - for version, _ in pairs(addoninfo and addoninfo.versions or {}) do - table.insert(versions, version) - end - table.sort(versions) - return versions + return table.orderkeys(addoninfo and addoninfo.versions or {}) end -- get all installed addons, only the active version of each addon @@ -581,7 +573,9 @@ end -- function addon.payloadinfos(kind) local payloadinfos = {} - for name, addoninfo in pairs(addon.addons()) do + -- @note we need to iterate them in a deterministic order, the load order matters, + -- e.g. the first plugin wins if two addons provide the same task name + for name, addoninfo in table.orderpairs(addon.addons()) do if table.contains(addoninfo.payloads or {}, kind) then table.insert(payloadinfos, { name = name, @@ -589,7 +583,6 @@ function addon.payloadinfos(kind) dir = path.join(addon.installdir(), name, addoninfo.version, kind)}) end end - table.sort(payloadinfos, function (a, b) return a.name < b.name end) return payloadinfos end |
