summaryrefslogtreecommitdiff
path: root/xmake/core/base/interpreter.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-16 20:56:42 +0800
committerruki <[email protected]>2026-08-16 20:56:42 +0800
commitf53769382d8f65c6a90a838da55287864888cfbb (patch)
tree65dd0feaa6b1a3b141464baba1c36784ac70adc3 /xmake/core/base/interpreter.lua
parent9721317cf822815a48b8b8986212622ea1079788 (diff)
move add_addons to xmake.lua
Diffstat (limited to 'xmake/core/base/interpreter.lua')
-rw-r--r--xmake/core/base/interpreter.lua50
1 files changed, 21 insertions, 29 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 01b689fe6..215ff6673 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -884,34 +884,25 @@ end
--
-- the root api will affect these scopes
--
--- get the root file name of the included directories, e.g. includes("subdir") -> subdir/xmake.lua
-function interpreter:includes_rootfilename()
- return self._PRIVATE._INCLUDES_ROOTFILENAME or "xmake.lua"
-end
-
--- set the root file name of the included directories
+-- do we defer the unresolvable addon references? e.g. includes("@addon/esp32/board")
--
--- e.g. interp:includes_rootfilename_set("xmake-addons.lua") -> includes("subdir") -> subdir/xmake-addons.lua
+-- @note the project file declares the addons which it needs, but we can only know them
+-- after loading it, so the first load must survive the references of the addons which
+-- are not installed yet, @see project._load()
--
-function interpreter:includes_rootfilename_set(filename)
- self._PRIVATE._INCLUDES_ROOTFILENAME = filename
+function interpreter:addons_deferred()
+ return self._PRIVATE._ADDONS_DEFERRED
end
--- can we include the referenced files? e.g. includes("@builtin/check"), includes("@addon/esp32/board")
-function interpreter:includes_references()
- return self._PRIVATE._INCLUDES_REFERENCES ~= false
+-- defer the unresolvable addon references instead of raising errors
+function interpreter:addons_deferred_set(enabled)
+ self._PRIVATE._ADDONS_DEFERRED = enabled
+ self._PRIVATE._ADDONS_MISSING = nil
end
--- enable/disable the referenced files of includes()
---
--- @param enabled enable them or not
--- @param hint the extra hint of the error message
---
--- @note the addons file is loaded before the addons are installed, so it cannot reference them
---
-function interpreter:includes_references_set(enabled, hint)
- self._PRIVATE._INCLUDES_REFERENCES = enabled
- self._PRIVATE._INCLUDES_REFERENCES_HINT = hint
+-- get the addon references which have not been resolved, @see interpreter:addons_deferred_set
+function interpreter:addons_missing()
+ return self._PRIVATE._ADDONS_MISSING
end
function interpreter:rootscope_set(scope_kind)
@@ -1830,6 +1821,13 @@ end
function interpreter:_find_addon_includes(subpath)
local referenceinfo, errors = addon.resolve_reference(subpath, "/", "includes", {scriptdir = self:scriptdir()})
if not referenceinfo then
+ -- this addon is not installed yet? we will install it and load this file again
+ if self:addons_deferred() then
+ local missing = self._PRIVATE._ADDONS_MISSING or {}
+ table.insert(missing, subpath)
+ self._PRIVATE._ADDONS_MISSING = missing
+ return {}
+ end
os.raise(errors)
end
local addon_path = referenceinfo.name
@@ -1856,12 +1854,6 @@ function interpreter:api_builtin_includes(...)
local subpaths_matched = {}
for _, subpath in ipairs(subpaths) do
local found = false
- -- the referenced files are not always available, e.g. the addons file
- if subpath:startswith("@") and not self:includes_references() then
- local hint = self._PRIVATE._INCLUDES_REFERENCES_HINT
- os.raise("includes(%s): the referenced files are not supported in %s!%s",
- subpath, path.filename(curfile), hint and ("\n" .. hint) or "")
- end
-- attempt to find files from programdir/includes/*.lua
-- e.g. includes("@builtin/check")
if subpath:startswith("@builtin/") then
@@ -1884,7 +1876,7 @@ function interpreter:api_builtin_includes(...)
files = os.files(subpath)
else
-- @see https://github.com/xmake-io/xmake/issues/6026
- files = os.files(path.join(subpath, self:includes_rootfilename()))
+ files = os.files(path.join(subpath, "xmake.lua"))
end
if files and #files > 0 then
table.join2(subpaths_matched, files)