@@ -1026,10 +1026,14 @@ function _instance:_load()
1026
1026
if on_load then
1027
1027
on_load (self )
1028
1028
end
1029
- self ._LOADED = true
1030
1029
end
1031
1030
end
1032
1031
1032
+ -- mark as loaded package
1033
+ function _instance :_mark_as_loaded ()
1034
+ self ._LOADED = true
1035
+ end
1036
+
1033
1037
-- get the raw environments
1034
1038
function _instance :_rawenvs ()
1035
1039
local envs = self ._RAWENVS
@@ -1214,6 +1218,14 @@ function _instance:has_runtime(...)
1214
1218
end
1215
1219
end
1216
1220
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
+
1217
1229
-- get the given toolchain
1218
1230
function _instance :toolchain (name )
1219
1231
local toolchains_map = self :_memcache ():get (" toolchains_map" )
@@ -1259,6 +1271,7 @@ end
1259
1271
1260
1272
-- get the program and name of the given tool kind
1261
1273
function _instance :tool (toolkind )
1274
+ self :_check_limits_on_load (" tool" )
1262
1275
if self :toolchains () then
1263
1276
local cachekey = " package_" .. tostring (self )
1264
1277
return toolchain .tool (self :toolchains (), toolkind , {cachekey = cachekey , plat = self :plat (), arch = self :arch ()})
@@ -1269,6 +1282,7 @@ end
1269
1282
1270
1283
-- get tool configuration from the toolchains
1271
1284
function _instance :toolconfig (name )
1285
+ self :_check_limits_on_load (" toolconfig" )
1272
1286
if self :toolchains () then
1273
1287
local cachekey = " package_" .. tostring (self )
1274
1288
return toolchain .toolconfig (self :toolchains (), name , {cachekey = cachekey , plat = self :plat (), arch = self :arch ()})
@@ -1302,6 +1316,7 @@ end
1302
1316
-- ...
1303
1317
-- end
1304
1318
function _instance :has_tool (toolkind , ...)
1319
+ self :_check_limits_on_load (" has_tool" )
1305
1320
local _ , toolname = self :tool (toolkind )
1306
1321
if toolname then
1307
1322
for _ , v in ipairs (table .join (... )) do
@@ -2432,6 +2447,7 @@ end
2432
2447
-- @return true or false, errors
2433
2448
--
2434
2449
function _instance :has_cfuncs (funcs , opt )
2450
+ self :_check_limits_on_load (" has_cfuncs" )
2435
2451
opt = opt or {}
2436
2452
opt .target = self
2437
2453
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cc" })
@@ -2446,6 +2462,7 @@ end
2446
2462
-- @return true or false, errors
2447
2463
--
2448
2464
function _instance :has_cxxfuncs (funcs , opt )
2465
+ self :_check_limits_on_load (" has_cxxfuncs" )
2449
2466
opt = opt or {}
2450
2467
opt .target = self
2451
2468
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cxx" })
@@ -2460,6 +2477,7 @@ end
2460
2477
-- @return true or false, errors
2461
2478
--
2462
2479
function _instance :has_ctypes (types , opt )
2480
+ self :_check_limits_on_load (" has_ctypes" )
2463
2481
opt = opt or {}
2464
2482
opt .target = self
2465
2483
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cc" })
@@ -2474,6 +2492,7 @@ end
2474
2492
-- @return true or false, errors
2475
2493
--
2476
2494
function _instance :has_cxxtypes (types , opt )
2495
+ self :_check_limits_on_load (" has_cxxtypes" )
2477
2496
opt = opt or {}
2478
2497
opt .target = self
2479
2498
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cxx" })
@@ -2488,6 +2507,7 @@ end
2488
2507
-- @return true or false, errors
2489
2508
--
2490
2509
function _instance :has_cincludes (includes , opt )
2510
+ self :_check_limits_on_load (" has_cincludes" )
2491
2511
opt = opt or {}
2492
2512
opt .target = self
2493
2513
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cc" })
@@ -2502,6 +2522,7 @@ end
2502
2522
-- @return true or false, errors
2503
2523
--
2504
2524
function _instance :has_cxxincludes (includes , opt )
2525
+ self :_check_limits_on_load (" has_cxxincludes" )
2505
2526
opt = opt or {}
2506
2527
opt .target = self
2507
2528
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cxx" })
@@ -2516,6 +2537,7 @@ end
2516
2537
-- @return true or false, errors
2517
2538
--
2518
2539
function _instance :has_cflags (flags , opt )
2540
+ self :_check_limits_on_load (" has_cflags" )
2519
2541
local compinst = self :compiler (" cc" )
2520
2542
return compinst :has_flags (flags , " cflags" , opt )
2521
2543
end
@@ -2528,6 +2550,7 @@ end
2528
2550
-- @return true or false, errors
2529
2551
--
2530
2552
function _instance :has_cxxflags (flags , opt )
2553
+ self :_check_limits_on_load (" has_cxxflags" )
2531
2554
local compinst = self :compiler (" cxx" )
2532
2555
return compinst :has_flags (flags , " cxxflags" , opt )
2533
2556
end
@@ -2540,6 +2563,7 @@ end
2540
2563
-- @return true or false, errors
2541
2564
--
2542
2565
function _instance :has_features (features , opt )
2566
+ self :_check_limits_on_load (" has_features" )
2543
2567
opt = opt or {}
2544
2568
opt .target = self
2545
2569
return sandbox_module .import (" core.tool.compiler" , {anonymous = true }).has_features (features , opt )
@@ -2553,6 +2577,7 @@ end
2553
2577
-- @return the type size
2554
2578
--
2555
2579
function _instance :check_sizeof (typename , opt )
2580
+ self :_check_limits_on_load (" check_sizeof" )
2556
2581
opt = opt or {}
2557
2582
opt .target = self
2558
2583
return sandbox_module .import (" lib.detect.check_sizeof" , {anonymous = true })(typename , opt )
@@ -2566,6 +2591,7 @@ end
2566
2591
-- @return true or false, errors
2567
2592
--
2568
2593
function _instance :check_csnippets (snippets , opt )
2594
+ self :_check_limits_on_load (" check_csnippets" )
2569
2595
opt = opt or {}
2570
2596
opt .target = self
2571
2597
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cc" })
@@ -2580,6 +2606,7 @@ end
2580
2606
-- @return true or false, errors
2581
2607
--
2582
2608
function _instance :check_cxxsnippets (snippets , opt )
2609
+ self :_check_limits_on_load (" check_cxxsnippets" )
2583
2610
opt = opt or {}
2584
2611
opt .target = self
2585
2612
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " cxx" })
@@ -2594,6 +2621,7 @@ end
2594
2621
-- @return true or false, errors
2595
2622
--
2596
2623
function _instance :check_msnippets (snippets , opt )
2624
+ self :_check_limits_on_load (" check_msnippets" )
2597
2625
opt = opt or {}
2598
2626
opt .target = self
2599
2627
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " mm" })
@@ -2608,6 +2636,7 @@ end
2608
2636
-- @return true or false, errors
2609
2637
--
2610
2638
function _instance :check_mxxsnippets (snippets , opt )
2639
+ self :_check_limits_on_load (" check_mxxsnippets" )
2611
2640
opt = opt or {}
2612
2641
opt .target = self
2613
2642
opt .configs = self :_generate_build_configs (opt .configs , {sourcekind = " mxx" })
0 commit comments