From dfe41c4f149feb3fd1d9460313bd5b9dc87e0ec3 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:15:15 +0800 Subject: improve to check toolchain state --- xmake/core/tool/toolchain.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index be4e82810..bfd90e88c 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -208,6 +208,7 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) + assert(self:_is_checked()) -- ensure to do load for initializing toolset first -- @note we cannot call self:check() here, because it can only be called on config self:_load() @@ -270,7 +271,8 @@ end -- do check, we only check it once for all architectures function _instance:check() local checkok = true - if not self._CHECKED then + local checked = self:_is_checked() + if not checked then local on_check = self:_on_check() if on_check then local ok, results_or_errors = sandbox.load(on_check, self) @@ -280,7 +282,9 @@ function _instance:check() os.raise(results_or_errors) end end - self._CHECKED = true + -- we need to persist this state + self:config_set("__checked", true) + self:configs_save() end return checkok end @@ -374,6 +378,11 @@ function _instance:_is_loaded() return self:info():get("__loaded") end +-- is checked? +function _instance:_is_checked() + return self:config("__checked") == true +end + -- get the tool description from the tool kind function _instance:_description(toolkind) local descriptions = self._DESCRIPTIONS @@ -708,8 +717,6 @@ function toolchain.load_fromfile(filepath, opt) local scope_opt = {interpreter = toolchain._interpreter(), deduplicate = true, enable_filter = true} local info = scopeinfo.new("toolchain", fileinfo.info, scope_opt) local instance = toolchain.load_withinfo(fileinfo.name, info, opt) - -- we need to skip check - instance._CHECKED = true return instance end @@ -800,6 +807,7 @@ function toolchain.toolconfig(toolchains, name, opt) local toolconfig = cache:get2(cachekey, name) if toolconfig == nil then for _, toolchain_inst in ipairs(toolchains) do + assert(toolchain_inst:_is_checked()) local values = toolchain_inst:get(name) if values then toolconfig = toolconfig or {} -- cgit v1.3.1 From 39544b566c426551afe6c72e0f4c76cf5814ce67 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:18:39 +0800 Subject: use raise --- xmake/core/tool/toolchain.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index bfd90e88c..f4055beb7 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -208,7 +208,9 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) - assert(self:_is_checked()) + if not self:_is_checked() then + os.raise("toolchain(%s) has been not checked yet!", self:name()) + end -- ensure to do load for initializing toolset first -- @note we cannot call self:check() here, because it can only be called on config self:_load() @@ -807,7 +809,9 @@ function toolchain.toolconfig(toolchains, name, opt) local toolconfig = cache:get2(cachekey, name) if toolconfig == nil then for _, toolchain_inst in ipairs(toolchains) do - assert(toolchain_inst:_is_checked()) + if not toolchain_inst:_is_checked() then + os.raise("toolchain(%s) has been not checked yet!", toolchain_inst:name()) + end local values = toolchain_inst:get(name) if values then toolconfig = toolconfig or {} -- cgit v1.3.1 From bfa9955d94112c4efdded7ef25e5765b0d282d72 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:19:07 +0800 Subject: improve tips --- xmake/core/tool/toolchain.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index f4055beb7..a3887d47e 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -209,7 +209,7 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) if not self:_is_checked() then - os.raise("toolchain(%s) has been not checked yet!", self:name()) + os.raise("we cannot get tool(%s) in toolchain(%s), because it has been not checked yet!", toolkind, self:name()) end -- ensure to do load for initializing toolset first -- @note we cannot call self:check() here, because it can only be called on config @@ -810,7 +810,7 @@ function toolchain.toolconfig(toolchains, name, opt) if toolconfig == nil then for _, toolchain_inst in ipairs(toolchains) do if not toolchain_inst:_is_checked() then - os.raise("toolchain(%s) has been not checked yet!", toolchain_inst:name()) + os.raise("we cannot get toolconfig(%s) in toolchain(%s), because it has been not checked yet!", name, toolchain_inst:name()) end local values = toolchain_inst:get(name) if values then -- cgit v1.3.1 From c04fe1062f5443425629b441a60f7856e1a5cb00 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:21:56 +0800 Subject: ignore missing on_check toolchains --- xmake/core/tool/toolchain.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index a3887d47e..026399312 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -382,7 +382,7 @@ end -- is checked? function _instance:_is_checked() - return self:config("__checked") == true + return self:config("__checked") == true or self:_on_check() == nil end -- get the tool description from the tool kind -- cgit v1.3.1 From 388d116ef1ee6bd62c498389ea1efa618d9a2a84 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:39:57 +0800 Subject: fix toolchain config for check flags --- xmake/core/tool/builder.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 92a17b68b..54652326d 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -309,6 +309,9 @@ function builder:_add_flags_from_argument(flags, target, args) return values, extras end, toolchain = function (name) + if target and target.toolconfig then + return target:toolconfig(name) + end local plat, arch if target and target.plat then plat = target:plat() -- cgit v1.3.1 From a6ba37ede748b1488e3f32eb37436eda76c1f8b5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:40:57 +0800 Subject: improve error tips --- xmake/core/tool/toolchain.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 026399312..a754d0f18 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -209,7 +209,7 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) if not self:_is_checked() then - os.raise("we cannot get tool(%s) in toolchain(%s), because it has been not checked yet!", toolkind, self:name()) + os.raise("we cannot get tool(%s) in toolchain(%s) with %s/%s, because it has been not checked yet!", toolkind, self:name(), self:plat(), self:arch()) end -- ensure to do load for initializing toolset first -- @note we cannot call self:check() here, because it can only be called on config @@ -810,7 +810,7 @@ function toolchain.toolconfig(toolchains, name, opt) if toolconfig == nil then for _, toolchain_inst in ipairs(toolchains) do if not toolchain_inst:_is_checked() then - os.raise("we cannot get toolconfig(%s) in toolchain(%s), because it has been not checked yet!", name, toolchain_inst:name()) + os.raise("we cannot get toolconfig(%s) in toolchain(%s) with %s/%s, because it has been not checked yet!", name, toolchain_inst:name(), toolchain_inst:plat(), toolchain_inst:arch()) end local values = toolchain_inst:get(name) if values then -- cgit v1.3.1 From c4202692a4758c4b225f285544ee0e7145e32c13 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:48:28 +0800 Subject: improve clean --- xmake/actions/clean/main.lua | 9 +++------ xmake/actions/install/main.lua | 5 +---- xmake/actions/test/main.lua | 6 +++--- xmake/actions/uninstall/main.lua | 6 +++--- xmake/plugins/pack/main.lua | 6 +++--- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 413a3121e..0cc887651 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -156,18 +156,15 @@ function main() return remote_build_action() end + -- load config first + task.run("config", {require = false}, {disable_dump = true}) + -- lock the whole project project.lock() -- get the target name local targetname = option.get("target") - -- local config first - config.load() - - -- load targets - project.load_targets() - -- enter project directory local oldir = os.cd(project.directory()) diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua index 24081f874..c20956203 100644 --- a/xmake/actions/install/main.lua +++ b/xmake/actions/install/main.lua @@ -65,10 +65,7 @@ end function main() -- load config first - config.load() - - -- load targets - project.load_targets() + task.run("config", {require = false}, {disable_dump = true}) -- check targets first local targetname diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index 6d202fe09..408fa5d5f 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -443,12 +443,12 @@ function main() return remote_build_action() end - -- lock the whole project - project.lock() - -- load config first task.run("config", {}, {disable_dump = true}) + -- lock the whole project + project.lock() + -- get tests local tests = get_tests() local test_patterns = option.get("tests") diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua index f2ae59eb9..aef0c30f7 100644 --- a/xmake/actions/uninstall/main.lua +++ b/xmake/actions/uninstall/main.lua @@ -28,11 +28,11 @@ import("uninstall") function main() - -- config it first - local targetname = option.get("target") - task.run("config", {require = "n", verbose = false}) + -- load config first + task.run("config", {require = false}, {disable_dump = true}) -- attempt to uninstall directly + local targetname = option.get("target") try { function () diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua index 9ca47074f..b108be790 100644 --- a/xmake/plugins/pack/main.lua +++ b/xmake/plugins/pack/main.lua @@ -112,12 +112,12 @@ function main() return remote_build_action() end - -- lock the whole project - project.lock() - -- load config first task.run("config", {}, {disable_dump = true}) + -- lock the whole project + project.lock() + -- enter project directory local oldir = os.cd(project.directory()) -- cgit v1.3.1 From 5f0fcf15d5679348e2e8fd42ccd2de88e4a939ed Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 14 Aug 2024 23:56:04 +0800 Subject: check platform packages --- xmake/modules/private/action/require/impl/package.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 1c7eaf9e5..510d9a23f 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -852,6 +852,17 @@ 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) @@ -1004,6 +1015,9 @@ 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() -- cgit v1.3.1 From 9b81b86e21ce132cc3a4d03b1868c2a7748c8345 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 16 Aug 2024 00:47:08 +0800 Subject: limit some calls in package on_load --- xmake/core/package/package.lua | 31 +++++++++++++++++++++- .../action/require/impl/actions/install.lua | 14 +++++++--- .../private/action/require/impl/package.lua | 17 +++--------- 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 -- cgit v1.3.1 From 3000c00cfabfed31edd9e9a67d64045f5de7e589 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 18 Aug 2024 22:54:18 +0800 Subject: install toolchain packages first --- .../package/manager/system/find_package.lua | 30 --------------------- .../action/require/impl/actions/install.lua | 20 -------------- .../action/require/impl/install_packages.lua | 20 +++++++++----- .../private/action/require/impl/package.lua | 31 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 56 deletions(-) diff --git a/xmake/modules/package/manager/system/find_package.lua b/xmake/modules/package/manager/system/find_package.lua index 4d939e495..632db0c63 100644 --- a/xmake/modules/package/manager/system/find_package.lua +++ b/xmake/modules/package/manager/system/find_package.lua @@ -38,26 +38,6 @@ function _get_package_items() return items end --- check package toolchains -function _check_package_toolchains(package) - local has_standalone - if package:toolchains() then - for _, toolchain_inst in ipairs(package:toolchains()) do - if toolchain_inst:check() and toolchain_inst:is_standalone() then - has_standalone = true - end - end - else - -- we need also check platform toolchain, perhaps it has a different platform arch. - -- @see https://github.com/xmake-io/xmake/issues/4043#issuecomment-2102486249 - local platform_inst = platform.load(package:plat(), package:arch()) - if platform_inst:check() then - has_standalone = true - end - end - return has_standalone -end - -- find package from system and compiler -- @see https://github.com/xmake-io/xmake/issues/4596 -- @@ -80,16 +60,6 @@ function main(name, opt) end snippet_configs.links = snippet_configs.links or name - -- We need to check package toolchain first - -- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801 - -- - -- But if it depends on some toolchain packages, - -- then they can't be detected early in the fetch and we have to disable system.find_package - local package = opt.package - if package and not _check_package_toolchains(package) then - return - end - local snippet_opt = { verbose = opt.verbose, target = opt.package, diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index e3e81aa22..04ecd0036 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -223,23 +223,6 @@ function _fix_paths_for_precompiled_package(package) end end --- check package toolchains -function _check_package_toolchains(package) - 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 - -- get failed install directory function _get_installdir_failed(package) return path.join(package:cachedir(), "installdir.failed") @@ -404,9 +387,6 @@ function main(package) -- enter the environments of all package dependencies _enter_package_installenvs(package) - -- check package toolchains - _check_package_toolchains(package) - -- do install if script ~= nil then filter.call(script, package, {oldenvs = oldenvs}) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 14dd87e33..8b9a36cf9 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -379,8 +379,8 @@ function _should_install_package(instance) return result end --- install packages -function _install_packages(packages_install, packages_download, installdeps) +-- do install packages +function _do_install_packages(packages_install, packages_download, installdeps) -- we need to hide wait characters if is not a tty local show_wait = io.isatty() @@ -663,9 +663,7 @@ function _get_package_installdeps(packages) end -- install packages -function main(requires, opt) - - -- init options +function _install_packages(requires, opt) opt = opt or {} -- load packages @@ -794,7 +792,7 @@ function main(requires, opt) _sort_packages_urls(packages_download) -- install all required packages from repositories - _install_packages(packages_install, packages_download, installdeps) + _do_install_packages(packages_install, packages_download, installdeps) -- disable other packages in same group _disable_other_packages_in_group(packages) @@ -813,3 +811,13 @@ function main(requires, opt) return packages end +function main(requires, opt) + -- we need to install toolchain packages first, + -- because we will call compiler-specific api in package.on_load, + -- and we will check package toolchains before calling package.on_load + -- + -- @see https://github.com/xmake-io/xmake/pull/5466 + _install_packages(requires, table.join(opt or {}, {toolchain = true})) + return _install_packages(requires, opt) +end + diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 4fe91b636..0eb2b917c 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -487,6 +487,23 @@ function _check_package_configurations(package) end end +-- check package toolchains +function _check_package_toolchains(package) + 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 + -- match require path function _match_requirepath(requirepath, requireconf) @@ -937,6 +954,13 @@ function _load_package(packagename, requireinfo, opt) -- save require info package:requireinfo_set(requireinfo) + -- only load toolchain package and its deps + if opt.toolchain then + if package:is_toplevel() and not package:is_toolchain()then + return + end + end + -- init urls source package:_init_source() @@ -1004,6 +1028,13 @@ function _load_package(packagename, requireinfo, opt) end end + -- we need to check package toolchains before on_load, + -- because we will call compiler-specific apis in on_load/on_fetch/find_package .. + -- + -- @see https://github.com/xmake-io/xmake/pull/5466 + -- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801 + _check_package_toolchains(package) + -- do load package:_load() -- cgit v1.3.1 From 3dbf27490cbfda4a18843ffb85b74eb30ed9839c Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 18 Aug 2024 23:02:26 +0800 Subject: remove on_load limits --- xmake/core/package/package.lua | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 133531b46..d16be3529 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1218,14 +1218,6 @@ 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") @@ -2522,7 +2514,6 @@ 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"}) @@ -2537,7 +2528,6 @@ 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 @@ -2550,7 +2540,6 @@ 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 @@ -2563,7 +2552,6 @@ 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) @@ -2577,7 +2565,6 @@ 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) @@ -2591,7 +2578,6 @@ 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"}) @@ -2606,7 +2592,6 @@ 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"}) @@ -2621,7 +2606,6 @@ 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"}) @@ -2636,7 +2620,6 @@ 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"}) -- cgit v1.3.1 From 73365950172878680ae5cb0235effe94eddf1586 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 18 Aug 2024 23:05:18 +0800 Subject: remove on_load limits --- xmake/core/package/package.lua | 8 -------- 1 file changed, 8 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index d16be3529..c6676327f 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1263,7 +1263,6 @@ 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()}) @@ -1274,7 +1273,6 @@ 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()}) @@ -1308,7 +1306,6 @@ 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 @@ -2439,7 +2436,6 @@ 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"}) @@ -2454,7 +2450,6 @@ 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"}) @@ -2469,7 +2464,6 @@ 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"}) @@ -2484,7 +2478,6 @@ 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"}) @@ -2499,7 +2492,6 @@ 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"}) -- cgit v1.3.1 From 1799d2ce7712d292c006d279e48d2c2f79894049 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 18 Aug 2024 23:41:50 +0800 Subject: improve tips --- .../modules/private/action/require/impl/install_packages.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 8b9a36cf9..38e965ca6 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -167,7 +167,8 @@ function _get_confirm_from_3rd(packages) end -- get user confirm -function _get_confirm(packages) +function _get_confirm(packages, opt) + opt = opt or {} -- no confirmed packages? if #packages == 0 then @@ -201,7 +202,11 @@ function _get_confirm(packages) end -- show tips - cprint("${bright color.warning}note: ${clear}install or modify (m) these packages (pass -y to skip confirm)?") + if opt.toolchain then + cprint("${bright color.warning}note: ${clear}install or modify (m) these ${bright}toolchain${clear} packages first (pass -y to skip confirm)?") + else + cprint("${bright color.warning}note: ${clear}install or modify (m) these packages (pass -y to skip confirm)?") + end for reponame, packages in pairs(packages_repo) do if reponame ~= "" then print("in %s:", reponame) @@ -758,7 +763,7 @@ function _install_packages(requires, opt) end -- get user confirm - local confirm, packages_modified = _get_confirm(packages_install) + local confirm, packages_modified = _get_confirm(packages_install, opt) if not confirm then local packages_must = {} for _, instance in ipairs(packages_install) do -- cgit v1.3.1 From 84f170de57c8c58d37ccdefed7ad99e6c0c3ae48 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Aug 2024 00:31:54 +0800 Subject: remove some old codes --- xmake/core/project/project.lua | 7 ------- 1 file changed, 7 deletions(-) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index af92f8998..5878ffead 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -714,13 +714,6 @@ function project.interpreter() if type(result) == "function" then result = result() end - - -- attempt to get it from the platform tools, e.g. cc, cxx, ld .. - -- because these values may not exist in config cache when call `config.get()`, we need check and get it. - -- - if not result then - result = platform.tool(variable) - end end return result end) -- cgit v1.3.1 From d19c47eac0a44b0bfbbf2e4ce7cf98713720a245 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Aug 2024 00:34:06 +0800 Subject: suppress logs --- xmake/core/base/option.lua | 14 -------------- xmake/core/base/utils.lua | 34 ---------------------------------- xmake/modules/utils/ci/packageskey.lua | 6 ++++++ 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 76dcc633a..8448788c5 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -64,8 +64,6 @@ end -- get the top context function option._context() - - -- the contexts local contexts = option._CONTEXTS if contexts then return contexts[#contexts] @@ -74,29 +72,17 @@ end -- save context function option.save(taskname) - - -- init contexts option._CONTEXTS = option._CONTEXTS or {} - - -- new a context local context = {options = {}, defaults = {}, taskname = taskname} - - -- init defaults if taskname then context.defaults = option.defaults(taskname) or context.defaults end - - -- push this new context to the top stack table.insert(option._CONTEXTS, context) - - -- ok return context end -- restore context function option.restore() - - -- pop it if option._CONTEXTS then table.remove(option._CONTEXTS) end diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index e8b6401f6..5125d224e 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -142,49 +142,25 @@ end -- print format string with newline function utils.print(format, ...) - - -- check assert(format) - - -- init message local message = string.tryformat(format, ...) - - -- trace utils._print(message) - - -- write to the log file log:printv(message) end -- print format string without newline function utils.printf(format, ...) - - -- check assert(format) - - -- init message local message = string.tryformat(format, ...) - - -- trace utils._iowrite(message) - - -- write to the log file log:write(message) end -- print format string and colors with newline function utils.cprint(format, ...) - - -- check assert(format) - - -- init message local message = string.tryformat(format, ...) - - -- trace utils._print(colors.translate(message)) - - -- write to the log file if log:file() then log:printv(colors.ignore(message)) end @@ -192,17 +168,9 @@ end -- print format string and colors without newline function utils.cprintf(format, ...) - - -- check assert(format) - - -- init message local message = string.tryformat(format, ...) - - -- trace utils._iowrite(colors.translate(message)) - - -- write to the log file if log:file() then log:write(colors.ignore(message)) end @@ -237,8 +205,6 @@ end -- add warning message function utils.warning(format, ...) - - -- check assert(format) -- format message diff --git a/xmake/modules/utils/ci/packageskey.lua b/xmake/modules/utils/ci/packageskey.lua index 50e3e2d1b..a293009af 100644 --- a/xmake/modules/utils/ci/packageskey.lua +++ b/xmake/modules/utils/ci/packageskey.lua @@ -40,6 +40,10 @@ import("private.action.require.impl.utils.get_requires") -- function main(requires_raw) + -- suppress all logs + option.save() + option.set("quiet", true, {force = true}) + -- get requires and extra config local requires_extra = nil local requires, requires_extra = get_requires(requires_raw) @@ -54,6 +58,8 @@ function main(requires_raw) end table.sort(keys) keys = table.concat(keys, ",") + + option.restore() print(hash.uuid4(keys):gsub('-', ''):lower()) end -- cgit v1.3.1