Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split package installation stages #5481

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -1271,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()})
Expand All @@ -1282,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()})
Expand Down Expand Up @@ -1316,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
Expand Down Expand Up @@ -2447,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"})
Expand All @@ -2462,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"})
Expand All @@ -2477,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"})
Expand All @@ -2492,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"})
Expand All @@ -2507,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"})
Expand All @@ -2522,7 +2506,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"})
Expand All @@ -2537,7 +2520,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
Expand All @@ -2550,7 +2532,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
Expand All @@ -2563,7 +2544,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)
Expand All @@ -2577,7 +2557,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)
Expand All @@ -2591,7 +2570,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"})
Expand All @@ -2606,7 +2584,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"})
Expand All @@ -2621,7 +2598,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"})
Expand All @@ -2636,7 +2612,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"})
Expand Down
30 changes: 0 additions & 30 deletions xmake/modules/package/manager/system/find_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand All @@ -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,
Expand Down
20 changes: 0 additions & 20 deletions xmake/modules/private/action/require/impl/actions/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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})
Expand Down
31 changes: 22 additions & 9 deletions xmake/modules/private/action/require/impl/install_packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

31 changes: 31 additions & 0 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
Loading