diff options
| author | ruki <[email protected]> | 2026-08-11 23:57:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-11 23:57:56 +0800 |
| commit | 911febdde5f22a4e548f7c8e5380c31c51be2af0 (patch) | |
| tree | ecd3213472446231a9081ddf04810cc39eccf2c2 | |
| parent | 7e2b17bd3e82bfedc3aa5a94bcf4cad68eaba581 (diff) | |
improve to register addon
| -rw-r--r-- | xmake/core/project/rule.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/install.lua | 69 |
2 files changed, 55 insertions, 34 deletions
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index f4d2be491..dfc385f35 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -459,6 +459,19 @@ function rule.new(name, info, opt) return instance end +-- report the missing addon of the given rule reference, e.g. add_rules("@addon/esp32/flash") +-- +-- it's either not installed at all, or it's installed but does not provide this rule +-- +function rule._raise_addon_notfound(name) + 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, referenceinfo and referenceinfo.addon or "<addon>") +end + -- get the given global rule -- -- @param name the rule name, the rules of the installed addons need the @@ -467,12 +480,7 @@ end function rule.rule(name) local instance = rule.rules()[name] if instance == nil and name:startswith("@addon/") then - 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, referenceinfo and referenceinfo.addon or "<addon>") + rule._raise_addon_notfound(name) end return instance end diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index c9e09763e..65750c1bc 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -284,6 +284,46 @@ function _merge_staticlibs(package) end end +-- register the installed addon, so that xmake can find its payloads, e.g. plugins +-- +-- @note the addon manifest(addon.lua) is only read when installing it, everything which +-- is needed later is recorded in the addons registry, @see core/package/addon.lua +-- +function _register_addon(package) + + -- get the addon deps from the package recipe + local deps + for _, dep in ipairs(package:plaindeps() or {}) do + if dep:is_addon() then + deps = deps or {} + table.insert(deps, dep:name()) + end + end + + -- the addon describes itself? we prefer its own description + -- + -- @note the deps are duplicated in its manifest, but the recipe is authoritative, + -- xmake needs them before downloading the addon sources, so we only report the + -- mismatch, they must be kept in sync + -- + local description = package:description() + local manifest = package:data("addon.manifest") + if manifest then + description = manifest.description or description + for _, dep in ipairs(manifest.deps) do + if not (deps and table.contains(deps, dep)) then + wprint("addon(%s): dep(%s) is declared in its manifest, but not in the package recipe!", + package:name(), dep) + end + end + end + + addon.register(package:name(), package:version_str() or "latest", + {description = description, deps = deps, + manifest_deps = manifest and manifest.deps or nil, + globalmodules = manifest and #manifest.globalmodules > 0 and manifest.globalmodules or nil}) +end + -- get failed install directory function _get_installdir_failed(package) return path.join(package:cachedir(), "installdir.failed") @@ -503,34 +543,7 @@ function main(package) -- register this addon, so that xmake can find its payloads, e.g. plugins if package:is_addon() then - local deps - for _, dep in ipairs(package:plaindeps() or {}) do - if dep:is_addon() then - deps = deps or {} - table.insert(deps, dep:name()) - end - end - - -- the addon describes itself? we prefer its own description - -- - -- @note the deps are duplicated in its manifest, but the recipe is - -- authoritative, xmake needs them before downloading the addon sources, - -- so we only report the mismatch, they must be kept in sync - local description = package:description() - local manifest = package:data("addon.manifest") - if manifest then - description = manifest.description or description - for _, dep in ipairs(manifest.deps) do - if not (deps and table.contains(deps, dep)) then - wprint("addon(%s): dep(%s) is declared in its manifest, but not in the package recipe!", - package:name(), dep) - end - end - end - addon.register(package:name(), package:version_str() or "latest", - {description = description, deps = deps, - manifest_deps = manifest and manifest.deps or nil, - globalmodules = manifest and #manifest.globalmodules > 0 and manifest.globalmodules or nil}) + _register_addon(package) end installed_now = true end |
