summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-16 00:47:08 +0800
committerruki <[email protected]>2024-08-23 08:14:32 +0800
commit9b81b86e21ce132cc3a4d03b1868c2a7748c8345 (patch)
tree298d168825154a066919ae3f9f55c29c313cc52e
parent5f0fcf15d5679348e2e8fd42ccd2de88e4a939ed (diff)
limit some calls in package on_load
-rw-r--r--xmake/core/package/package.lua31
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua14
-rw-r--r--xmake/modules/private/action/require/impl/package.lua17
3 files changed, 44 insertions, 18 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 65af6cc6e..133531b46 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1026,10 +1026,14 @@ function _instance:_load()
if on_load then
on_load(self)
end
- self._LOADED = true
end
end
+-- mark as loaded package
+function _instance:_mark_as_loaded()
+ self._LOADED = true
+end
+
-- get the raw environments
function _instance:_rawenvs()
local envs = self._RAWENVS
@@ -1214,6 +1218,14 @@ function _instance:has_runtime(...)
end
end
+-- check call limits in on_load
+-- @see https://github.com/xmake-io/xmake/issues/5455
+function _instance:_check_limits_on_load(apiname)
+ if not self._LOADED then
+ os.raise("we cannot call package:%s() in on_load(), please call it in on_check/on_install/on_test.", apiname)
+ end
+end
+
-- get the given toolchain
function _instance:toolchain(name)
local toolchains_map = self:_memcache():get("toolchains_map")
@@ -1259,6 +1271,7 @@ end
-- get the program and name of the given tool kind
function _instance:tool(toolkind)
+ self:_check_limits_on_load("tool")
if self:toolchains() then
local cachekey = "package_" .. tostring(self)
return toolchain.tool(self:toolchains(), toolkind, {cachekey = cachekey, plat = self:plat(), arch = self:arch()})
@@ -1269,6 +1282,7 @@ end
-- get tool configuration from the toolchains
function _instance:toolconfig(name)
+ self:_check_limits_on_load("toolconfig")
if self:toolchains() then
local cachekey = "package_" .. tostring(self)
return toolchain.toolconfig(self:toolchains(), name, {cachekey = cachekey, plat = self:plat(), arch = self:arch()})
@@ -1302,6 +1316,7 @@ end
-- ...
-- end
function _instance:has_tool(toolkind, ...)
+ self:_check_limits_on_load("has_tool")
local _, toolname = self:tool(toolkind)
if toolname then
for _, v in ipairs(table.join(...)) do
@@ -2432,6 +2447,7 @@ end
-- @return true or false, errors
--
function _instance:has_cfuncs(funcs, opt)
+ self:_check_limits_on_load("has_cfuncs")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2446,6 +2462,7 @@ end
-- @return true or false, errors
--
function _instance:has_cxxfuncs(funcs, opt)
+ self:_check_limits_on_load("has_cxxfuncs")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2460,6 +2477,7 @@ end
-- @return true or false, errors
--
function _instance:has_ctypes(types, opt)
+ self:_check_limits_on_load("has_ctypes")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2474,6 +2492,7 @@ end
-- @return true or false, errors
--
function _instance:has_cxxtypes(types, opt)
+ self:_check_limits_on_load("has_cxxtypes")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2488,6 +2507,7 @@ end
-- @return true or false, errors
--
function _instance:has_cincludes(includes, opt)
+ self:_check_limits_on_load("has_cincludes")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2502,6 +2522,7 @@ end
-- @return true or false, errors
--
function _instance:has_cxxincludes(includes, opt)
+ self:_check_limits_on_load("has_cxxincludes")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2516,6 +2537,7 @@ end
-- @return true or false, errors
--
function _instance:has_cflags(flags, opt)
+ self:_check_limits_on_load("has_cflags")
local compinst = self:compiler("cc")
return compinst:has_flags(flags, "cflags", opt)
end
@@ -2528,6 +2550,7 @@ end
-- @return true or false, errors
--
function _instance:has_cxxflags(flags, opt)
+ self:_check_limits_on_load("has_cxxflags")
local compinst = self:compiler("cxx")
return compinst:has_flags(flags, "cxxflags", opt)
end
@@ -2540,6 +2563,7 @@ end
-- @return true or false, errors
--
function _instance:has_features(features, opt)
+ self:_check_limits_on_load("has_features")
opt = opt or {}
opt.target = self
return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt)
@@ -2553,6 +2577,7 @@ end
-- @return the type size
--
function _instance:check_sizeof(typename, opt)
+ self:_check_limits_on_load("check_sizeof")
opt = opt or {}
opt.target = self
return sandbox_module.import("lib.detect.check_sizeof", {anonymous = true})(typename, opt)
@@ -2566,6 +2591,7 @@ end
-- @return true or false, errors
--
function _instance:check_csnippets(snippets, opt)
+ self:_check_limits_on_load("check_csnippets")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2580,6 +2606,7 @@ end
-- @return true or false, errors
--
function _instance:check_cxxsnippets(snippets, opt)
+ self:_check_limits_on_load("check_cxxsnippets")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2594,6 +2621,7 @@ end
-- @return true or false, errors
--
function _instance:check_msnippets(snippets, opt)
+ self:_check_limits_on_load("check_msnippets")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "mm"})
@@ -2608,6 +2636,7 @@ end
-- @return true or false, errors
--
function _instance:check_mxxsnippets(snippets, opt)
+ self:_check_limits_on_load("check_mxxsnippets")
opt = opt or {}
opt.target = self
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "mxx"})
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 056ebddb9..e3e81aa22 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -225,9 +225,17 @@ end
-- check package toolchains
function _check_package_toolchains(package)
- for _, toolchain_inst in pairs(package:toolchains()) do
- if not toolchain_inst:check() then
- raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
+ if package:toolchains() then
+ for _, toolchain_inst in pairs(package:toolchains()) do
+ if not toolchain_inst:check() then
+ raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
+ end
+ end
+ else
+ -- maybe this package is host package, it's platform and toolchain has been not checked yet.
+ local platform_inst = platform.load(package:plat(), package:arch())
+ if not platform_inst:check() then
+ raise("no any matched platform for this package(%s)!", package:name())
end
end
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 510d9a23f..4fe91b636 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -852,17 +852,6 @@ function _select_package_runtimes(package)
end
end
--- check platform toolchains, package maybe use host platform, it's toolchain has been not checked yet.
--- @see https://github.com/xmake-io/xmake/issues/5455
-function _check_package_platform_toolchains(package)
- if not package:toolchains() then
- local platform_inst = platform.load(package:plat(), package:arch())
- if not platform_inst:check() then
- raise("no any matched platform for this package(%s)!", package:name())
- end
- end
-end
-
-- load required packages
function _load_package(packagename, requireinfo, opt)
@@ -1015,9 +1004,6 @@ function _load_package(packagename, requireinfo, opt)
end
end
- -- check package platform toolchains first, package:has_tool will be called in on_load
- _check_package_platform_toolchains(package)
-
-- do load
package:_load()
@@ -1031,6 +1017,9 @@ function _load_package(packagename, requireinfo, opt)
-- save this package package to cache
_memcache():set2("packages", packagekey, package)
+
+ -- load ok
+ package:_mark_as_loaded()
return package
end