summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-24 07:22:42 +0800
committerGitHub <[email protected]>2024-08-24 07:22:42 +0800
commitc80898e12f88abe7df463bc64e0fb6bf081b8cdf (patch)
tree778fc24c5ff2207419f0f06c60fff46b67739d03
parent3ba77c15ccf34187b6678f277f2dd418433493c8 (diff)
parentd19c47eac0a44b0bfbbf2e4ce7cf98713720a245 (diff)
Merge pull request #5466 from xmake-io/toolchain
Improve to check and load toolchain
-rw-r--r--xmake/actions/clean/main.lua9
-rw-r--r--xmake/actions/install/main.lua5
-rw-r--r--xmake/actions/test/main.lua6
-rw-r--r--xmake/actions/uninstall/main.lua6
-rw-r--r--xmake/core/base/option.lua14
-rw-r--r--xmake/core/base/utils.lua34
-rw-r--r--xmake/core/package/package.lua6
-rw-r--r--xmake/core/project/project.lua7
-rw-r--r--xmake/core/tool/builder.lua3
-rw-r--r--xmake/core/tool/toolchain.lua20
-rw-r--r--xmake/modules/package/manager/system/find_package.lua30
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua12
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua31
-rw-r--r--xmake/modules/private/action/require/impl/package.lua34
-rw-r--r--xmake/modules/utils/ci/packageskey.lua6
-rw-r--r--xmake/plugins/pack/main.lua6
16 files changed, 99 insertions, 130 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/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/core/package/package.lua b/xmake/core/package/package.lua
index 65af6cc6e..c6676327f 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
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)
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()
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index be4e82810..a754d0f18 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -208,6 +208,9 @@ 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) 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
self:_load()
@@ -270,7 +273,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 +284,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 +380,11 @@ function _instance:_is_loaded()
return self:info():get("__loaded")
end
+-- is checked?
+function _instance:_is_checked()
+ return self:config("__checked") == true or self:_on_check() == nil
+end
+
-- get the tool description from the tool kind
function _instance:_description(toolkind)
local descriptions = self._DESCRIPTIONS
@@ -708,8 +719,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 +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
+ if not toolchain_inst:_is_checked() then
+ 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
toolconfig = toolconfig or {}
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 056ebddb9..04ecd0036 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -223,15 +223,6 @@ function _fix_paths_for_precompiled_package(package)
end
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())
- end
- end
-end
-
-- get failed install directory
function _get_installdir_failed(package)
return path.join(package:cachedir(), "installdir.failed")
@@ -396,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..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)
@@ -379,8 +384,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 +668,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
@@ -760,7 +763,7 @@ function main(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
@@ -794,7 +797,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 +816,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 1c7eaf9e5..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()
@@ -1017,6 +1048,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
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
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())