Skip to content

Commit 83f9dec

Browse files
authored
Merge pull request #5481 from xmake-io/toolchain2
Split package installation stages
2 parents 530cf15 + ac586d2 commit 83f9dec

File tree

5 files changed

+53
-84
lines changed

5 files changed

+53
-84
lines changed

xmake/core/package/package.lua

-25
Original file line numberDiff line numberDiff line change
@@ -1218,14 +1218,6 @@ function _instance:has_runtime(...)
12181218
end
12191219
end
12201220

1221-
-- check call limits in on_load
1222-
-- @see https://github.com/xmake-io/xmake/issues/5455
1223-
function _instance:_check_limits_on_load(apiname)
1224-
if not self._LOADED then
1225-
os.raise("we cannot call package:%s() in on_load(), please call it in on_check/on_install/on_test.", apiname)
1226-
end
1227-
end
1228-
12291221
-- get the given toolchain
12301222
function _instance:toolchain(name)
12311223
local toolchains_map = self:_memcache():get("toolchains_map")
@@ -1271,7 +1263,6 @@ end
12711263

12721264
-- get the program and name of the given tool kind
12731265
function _instance:tool(toolkind)
1274-
self:_check_limits_on_load("tool")
12751266
if self:toolchains() then
12761267
local cachekey = "package_" .. tostring(self)
12771268
return toolchain.tool(self:toolchains(), toolkind, {cachekey = cachekey, plat = self:plat(), arch = self:arch()})
@@ -1282,7 +1273,6 @@ end
12821273

12831274
-- get tool configuration from the toolchains
12841275
function _instance:toolconfig(name)
1285-
self:_check_limits_on_load("toolconfig")
12861276
if self:toolchains() then
12871277
local cachekey = "package_" .. tostring(self)
12881278
return toolchain.toolconfig(self:toolchains(), name, {cachekey = cachekey, plat = self:plat(), arch = self:arch()})
@@ -1316,7 +1306,6 @@ end
13161306
-- ...
13171307
-- end
13181308
function _instance:has_tool(toolkind, ...)
1319-
self:_check_limits_on_load("has_tool")
13201309
local _, toolname = self:tool(toolkind)
13211310
if toolname then
13221311
for _, v in ipairs(table.join(...)) do
@@ -2447,7 +2436,6 @@ end
24472436
-- @return true or false, errors
24482437
--
24492438
function _instance:has_cfuncs(funcs, opt)
2450-
self:_check_limits_on_load("has_cfuncs")
24512439
opt = opt or {}
24522440
opt.target = self
24532441
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2462,7 +2450,6 @@ end
24622450
-- @return true or false, errors
24632451
--
24642452
function _instance:has_cxxfuncs(funcs, opt)
2465-
self:_check_limits_on_load("has_cxxfuncs")
24662453
opt = opt or {}
24672454
opt.target = self
24682455
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2477,7 +2464,6 @@ end
24772464
-- @return true or false, errors
24782465
--
24792466
function _instance:has_ctypes(types, opt)
2480-
self:_check_limits_on_load("has_ctypes")
24812467
opt = opt or {}
24822468
opt.target = self
24832469
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2492,7 +2478,6 @@ end
24922478
-- @return true or false, errors
24932479
--
24942480
function _instance:has_cxxtypes(types, opt)
2495-
self:_check_limits_on_load("has_cxxtypes")
24962481
opt = opt or {}
24972482
opt.target = self
24982483
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2507,7 +2492,6 @@ end
25072492
-- @return true or false, errors
25082493
--
25092494
function _instance:has_cincludes(includes, opt)
2510-
self:_check_limits_on_load("has_cincludes")
25112495
opt = opt or {}
25122496
opt.target = self
25132497
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2522,7 +2506,6 @@ end
25222506
-- @return true or false, errors
25232507
--
25242508
function _instance:has_cxxincludes(includes, opt)
2525-
self:_check_limits_on_load("has_cxxincludes")
25262509
opt = opt or {}
25272510
opt.target = self
25282511
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2537,7 +2520,6 @@ end
25372520
-- @return true or false, errors
25382521
--
25392522
function _instance:has_cflags(flags, opt)
2540-
self:_check_limits_on_load("has_cflags")
25412523
local compinst = self:compiler("cc")
25422524
return compinst:has_flags(flags, "cflags", opt)
25432525
end
@@ -2550,7 +2532,6 @@ end
25502532
-- @return true or false, errors
25512533
--
25522534
function _instance:has_cxxflags(flags, opt)
2553-
self:_check_limits_on_load("has_cxxflags")
25542535
local compinst = self:compiler("cxx")
25552536
return compinst:has_flags(flags, "cxxflags", opt)
25562537
end
@@ -2563,7 +2544,6 @@ end
25632544
-- @return true or false, errors
25642545
--
25652546
function _instance:has_features(features, opt)
2566-
self:_check_limits_on_load("has_features")
25672547
opt = opt or {}
25682548
opt.target = self
25692549
return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt)
@@ -2577,7 +2557,6 @@ end
25772557
-- @return the type size
25782558
--
25792559
function _instance:check_sizeof(typename, opt)
2580-
self:_check_limits_on_load("check_sizeof")
25812560
opt = opt or {}
25822561
opt.target = self
25832562
return sandbox_module.import("lib.detect.check_sizeof", {anonymous = true})(typename, opt)
@@ -2591,7 +2570,6 @@ end
25912570
-- @return true or false, errors
25922571
--
25932572
function _instance:check_csnippets(snippets, opt)
2594-
self:_check_limits_on_load("check_csnippets")
25952573
opt = opt or {}
25962574
opt.target = self
25972575
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
@@ -2606,7 +2584,6 @@ end
26062584
-- @return true or false, errors
26072585
--
26082586
function _instance:check_cxxsnippets(snippets, opt)
2609-
self:_check_limits_on_load("check_cxxsnippets")
26102587
opt = opt or {}
26112588
opt.target = self
26122589
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
@@ -2621,7 +2598,6 @@ end
26212598
-- @return true or false, errors
26222599
--
26232600
function _instance:check_msnippets(snippets, opt)
2624-
self:_check_limits_on_load("check_msnippets")
26252601
opt = opt or {}
26262602
opt.target = self
26272603
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "mm"})
@@ -2636,7 +2612,6 @@ end
26362612
-- @return true or false, errors
26372613
--
26382614
function _instance:check_mxxsnippets(snippets, opt)
2639-
self:_check_limits_on_load("check_mxxsnippets")
26402615
opt = opt or {}
26412616
opt.target = self
26422617
opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "mxx"})

xmake/modules/package/manager/system/find_package.lua

-30
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,6 @@ function _get_package_items()
3838
return items
3939
end
4040

41-
-- check package toolchains
42-
function _check_package_toolchains(package)
43-
local has_standalone
44-
if package:toolchains() then
45-
for _, toolchain_inst in ipairs(package:toolchains()) do
46-
if toolchain_inst:check() and toolchain_inst:is_standalone() then
47-
has_standalone = true
48-
end
49-
end
50-
else
51-
-- we need also check platform toolchain, perhaps it has a different platform arch.
52-
-- @see https://github.com/xmake-io/xmake/issues/4043#issuecomment-2102486249
53-
local platform_inst = platform.load(package:plat(), package:arch())
54-
if platform_inst:check() then
55-
has_standalone = true
56-
end
57-
end
58-
return has_standalone
59-
end
60-
6141
-- find package from system and compiler
6242
-- @see https://github.com/xmake-io/xmake/issues/4596
6343
--
@@ -80,16 +60,6 @@ function main(name, opt)
8060
end
8161
snippet_configs.links = snippet_configs.links or name
8262

83-
-- We need to check package toolchain first
84-
-- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801
85-
--
86-
-- But if it depends on some toolchain packages,
87-
-- then they can't be detected early in the fetch and we have to disable system.find_package
88-
local package = opt.package
89-
if package and not _check_package_toolchains(package) then
90-
return
91-
end
92-
9363
local snippet_opt = {
9464
verbose = opt.verbose,
9565
target = opt.package,

xmake/modules/private/action/require/impl/actions/install.lua

-20
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,6 @@ function _fix_paths_for_precompiled_package(package)
223223
end
224224
end
225225

226-
-- check package toolchains
227-
function _check_package_toolchains(package)
228-
if package:toolchains() then
229-
for _, toolchain_inst in pairs(package:toolchains()) do
230-
if not toolchain_inst:check() then
231-
raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
232-
end
233-
end
234-
else
235-
-- maybe this package is host package, it's platform and toolchain has been not checked yet.
236-
local platform_inst = platform.load(package:plat(), package:arch())
237-
if not platform_inst:check() then
238-
raise("no any matched platform for this package(%s)!", package:name())
239-
end
240-
end
241-
end
242-
243226
-- get failed install directory
244227
function _get_installdir_failed(package)
245228
return path.join(package:cachedir(), "installdir.failed")
@@ -404,9 +387,6 @@ function main(package)
404387
-- enter the environments of all package dependencies
405388
_enter_package_installenvs(package)
406389

407-
-- check package toolchains
408-
_check_package_toolchains(package)
409-
410390
-- do install
411391
if script ~= nil then
412392
filter.call(script, package, {oldenvs = oldenvs})

xmake/modules/private/action/require/impl/install_packages.lua

+22-9
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ function _get_confirm_from_3rd(packages)
167167
end
168168

169169
-- get user confirm
170-
function _get_confirm(packages)
170+
function _get_confirm(packages, opt)
171+
opt = opt or {}
171172

172173
-- no confirmed packages?
173174
if #packages == 0 then
@@ -201,7 +202,11 @@ function _get_confirm(packages)
201202
end
202203

203204
-- show tips
204-
cprint("${bright color.warning}note: ${clear}install or modify (m) these packages (pass -y to skip confirm)?")
205+
if opt.toolchain then
206+
cprint("${bright color.warning}note: ${clear}install or modify (m) these ${bright}toolchain${clear} packages first (pass -y to skip confirm)?")
207+
else
208+
cprint("${bright color.warning}note: ${clear}install or modify (m) these packages (pass -y to skip confirm)?")
209+
end
205210
for reponame, packages in pairs(packages_repo) do
206211
if reponame ~= "" then
207212
print("in %s:", reponame)
@@ -379,8 +384,8 @@ function _should_install_package(instance)
379384
return result
380385
end
381386

382-
-- install packages
383-
function _install_packages(packages_install, packages_download, installdeps)
387+
-- do install packages
388+
function _do_install_packages(packages_install, packages_download, installdeps)
384389

385390
-- we need to hide wait characters if is not a tty
386391
local show_wait = io.isatty()
@@ -663,9 +668,7 @@ function _get_package_installdeps(packages)
663668
end
664669

665670
-- install packages
666-
function main(requires, opt)
667-
668-
-- init options
671+
function _install_packages(requires, opt)
669672
opt = opt or {}
670673

671674
-- load packages
@@ -760,7 +763,7 @@ function main(requires, opt)
760763
end
761764

762765
-- get user confirm
763-
local confirm, packages_modified = _get_confirm(packages_install)
766+
local confirm, packages_modified = _get_confirm(packages_install, opt)
764767
if not confirm then
765768
local packages_must = {}
766769
for _, instance in ipairs(packages_install) do
@@ -794,7 +797,7 @@ function main(requires, opt)
794797
_sort_packages_urls(packages_download)
795798

796799
-- install all required packages from repositories
797-
_install_packages(packages_install, packages_download, installdeps)
800+
_do_install_packages(packages_install, packages_download, installdeps)
798801

799802
-- disable other packages in same group
800803
_disable_other_packages_in_group(packages)
@@ -813,3 +816,13 @@ function main(requires, opt)
813816
return packages
814817
end
815818

819+
function main(requires, opt)
820+
-- we need to install toolchain packages first,
821+
-- because we will call compiler-specific api in package.on_load,
822+
-- and we will check package toolchains before calling package.on_load
823+
--
824+
-- @see https://github.com/xmake-io/xmake/pull/5466
825+
_install_packages(requires, table.join(opt or {}, {toolchain = true}))
826+
return _install_packages(requires, opt)
827+
end
828+

xmake/modules/private/action/require/impl/package.lua

+31
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,23 @@ function _check_package_configurations(package)
487487
end
488488
end
489489

490+
-- check package toolchains
491+
function _check_package_toolchains(package)
492+
if package:toolchains() then
493+
for _, toolchain_inst in pairs(package:toolchains()) do
494+
if not toolchain_inst:check() then
495+
raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
496+
end
497+
end
498+
else
499+
-- maybe this package is host package, it's platform and toolchain has been not checked yet.
500+
local platform_inst = platform.load(package:plat(), package:arch())
501+
if not platform_inst:check() then
502+
raise("no any matched platform for this package(%s)!", package:name())
503+
end
504+
end
505+
end
506+
490507
-- match require path
491508
function _match_requirepath(requirepath, requireconf)
492509

@@ -937,6 +954,13 @@ function _load_package(packagename, requireinfo, opt)
937954
-- save require info
938955
package:requireinfo_set(requireinfo)
939956

957+
-- only load toolchain package and its deps
958+
if opt.toolchain then
959+
if package:is_toplevel() and not package:is_toolchain()then
960+
return
961+
end
962+
end
963+
940964
-- init urls source
941965
package:_init_source()
942966

@@ -1004,6 +1028,13 @@ function _load_package(packagename, requireinfo, opt)
10041028
end
10051029
end
10061030

1031+
-- we need to check package toolchains before on_load,
1032+
-- because we will call compiler-specific apis in on_load/on_fetch/find_package ..
1033+
--
1034+
-- @see https://github.com/xmake-io/xmake/pull/5466
1035+
-- https://github.com/xmake-io/xmake/issues/4596#issuecomment-2014528801
1036+
_check_package_toolchains(package)
1037+
10071038
-- do load
10081039
package:_load()
10091040

0 commit comments

Comments
 (0)