summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-02 23:29:03 +0800
committerruki <[email protected]>2021-10-02 23:29:03 +0800
commite80a41789b0de5f2249c15d57486fd3a4b40ff99 (patch)
treef3a893345c8da889236e68775dc3de92f1a092e9
parentd4789ff5e968294bf2e9831209d0cf61b61c9d43 (diff)
save and restore scope
-rw-r--r--tests/apis/check_xxx/foo.c6
-rw-r--r--tests/apis/check_xxx/main.c2
-rw-r--r--tests/apis/check_xxx/xmake.lua11
-rw-r--r--xmake/core/base/interpreter.lua110
-rw-r--r--xmake/includes/check_cflags.lua4
-rw-r--r--xmake/includes/check_cfuncs.lua4
-rw-r--r--xmake/includes/check_cincludes.lua4
-rw-r--r--xmake/includes/check_csnippets.lua4
-rw-r--r--xmake/includes/check_ctypes.lua4
-rw-r--r--xmake/includes/check_cxxflags.lua4
-rw-r--r--xmake/includes/check_cxxfuncs.lua4
-rw-r--r--xmake/includes/check_cxxincludes.lua4
-rw-r--r--xmake/includes/check_cxxsnippets.lua4
-rw-r--r--xmake/includes/check_cxxtypes.lua4
-rw-r--r--xmake/includes/check_features.lua4
-rw-r--r--xmake/includes/check_links.lua4
-rw-r--r--xmake/includes/check_macros.lua4
-rw-r--r--xmake/includes/check_syslinks.lua4
-rw-r--r--xmake/includes/find_and_add_packages.lua2
-rw-r--r--xmake/languages/c++/load.lua8
20 files changed, 139 insertions, 56 deletions
diff --git a/tests/apis/check_xxx/foo.c b/tests/apis/check_xxx/foo.c
new file mode 100644
index 000000000..c055f5886
--- /dev/null
+++ b/tests/apis/check_xxx/foo.c
@@ -0,0 +1,6 @@
+#include "config.h"
+
+int foo()
+{
+ return 0;
+}
diff --git a/tests/apis/check_xxx/main.c b/tests/apis/check_xxx/main.c
index 5e40e6691..e5a9ccbdf 100644
--- a/tests/apis/check_xxx/main.c
+++ b/tests/apis/check_xxx/main.c
@@ -1,5 +1,3 @@
-#include "config.h"
-
int main(int argc, char** argv)
{
return 0;
diff --git a/tests/apis/check_xxx/xmake.lua b/tests/apis/check_xxx/xmake.lua
index 810a67612..b412571c4 100644
--- a/tests/apis/check_xxx/xmake.lua
+++ b/tests/apis/check_xxx/xmake.lua
@@ -7,9 +7,9 @@ includes("check_features.lua")
includes("check_csnippets.lua")
includes("check_cincludes.lua")
-target("test")
- set_kind("binary")
- add_files("*.c")
+target("foo")
+ set_kind("static")
+ add_files("foo.c")
add_includedirs("$(buildir)")
add_configfiles("config.h.in")
@@ -41,3 +41,8 @@ target("test")
configvar_check_macros("HAS_GCC", "__GNUC__")
configvar_check_macros("NO_GCC", "__GNUC__", {defined = false})
configvar_check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"})
+
+target("test")
+ add_deps("foo")
+ set_kind("binary")
+ add_files("main.c")
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 131a6d1c2..9a0416c52 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -694,6 +694,10 @@ function interpreter.new()
instance:api_register(nil, "add_subdirs", interpreter.api_builtin_includes)
instance:api_register(nil, "add_subfiles", interpreter.api_builtin_includes)
instance:api_register(nil, "set_xmakever", interpreter.api_builtin_set_xmakever)
+ instance:api_register(nil, "save_scope", interpreter.api_builtin_save_scope)
+ instance:api_register(nil, "restore_scope",interpreter.api_builtin_restore_scope)
+ instance:api_register(nil, "get_scopekind",interpreter.api_builtin_get_scopekind)
+ instance:api_register(nil, "get_scopename",interpreter.api_builtin_get_scopename)
-- register the builtin modules
for module_name, module in pairs(interpreter._builtin_modules()) do
@@ -1533,22 +1537,12 @@ end
-- the builtin api: includes()
function interpreter:api_builtin_includes(...)
-
- -- check
assert(self and self._PRIVATE and self._PRIVATE._ROOTDIR and self._PRIVATE._MTIMES)
-
- -- the current file
local curfile = self._PRIVATE._CURFILE
- assert(curfile)
-
- -- the scopes
local scopes = self._PRIVATE._SCOPES
- assert(scopes)
-
- -- get all subpaths
- local subpaths = table.join(...)
-- find all files
+ local subpaths = table.join(...)
local subpaths_matched = {}
for _, subpath in ipairs(subpaths) do
-- find the given files from the project directory
@@ -1646,6 +1640,64 @@ function interpreter:api_builtin_includes(...)
self._PRIVATE._CURFILE = curfile
end
+-- the builtin api: save_scope()
+-- save the current scope
+function interpreter:api_builtin_save_scope()
+ assert(self and self._PRIVATE)
+
+ -- the scopes
+ local scopes = self._PRIVATE._SCOPES
+ assert(scopes)
+
+ -- save the current scope
+ local scope = {}
+ scope._CURRENT = scopes._CURRENT
+ scope._CURRENT_KIND = scopes._CURRENT_KIND
+ self._PRIVATE._SCOPES_SAVED = self._PRIVATE._SCOPES_SAVED or {}
+ table.insert(self._PRIVATE._SCOPES_SAVED, scope)
+end
+
+-- the builtin api: restore_scope()
+-- restore the current scope
+function interpreter:api_builtin_restore_scope()
+ assert(self and self._PRIVATE)
+
+ -- the scopes
+ local scopes = self._PRIVATE._SCOPES
+ assert(scopes)
+
+ -- restore it
+ local scopes_saved = self._PRIVATE._SCOPES_SAVED
+ if scopes_saved and #scopes_saved > 0 then
+ local scope = scopes_saved[#scopes_saved]
+ if scope then
+ scopes._CURRENT = scope._CURRENT
+ scopes._CURRENT_KIND = scope._CURRENT_KIND
+ table.remove(scopes_saved, #scopes_saved)
+ end
+ end
+end
+
+-- the builtin api: get_scopekind()
+function interpreter:api_builtin_get_scopekind()
+ local scopes = self._PRIVATE._SCOPES
+ return scopes._CURRENT_KIND
+end
+
+-- the builtin api: get_scopename()
+function interpreter:api_builtin_get_scopename()
+ local scopes = self._PRIVATE._SCOPES
+ local scope_kind = scopes._CURRENT_KIND
+ if scope_kind and scopes[scope_kind] then
+ local scope_current = scopes._CURRENT
+ for name, scope in pairs(scopes[scope_kind]) do
+ if scope_current == scope then
+ return name
+ end
+ end
+ end
+end
+
-- get api function
function interpreter:api_func(apiname)
@@ -1672,40 +1724,6 @@ function interpreter:api_call(apiname, ...)
return apifunc(...)
end
--- save the current scope
-function interpreter:scope_save()
-
- -- check
- assert(self and self._PRIVATE)
-
- -- the scopes
- local scopes = self._PRIVATE._SCOPES
- assert(scopes)
-
- -- the current scope
- local scope = {}
- scope._CURRENT = scopes._CURRENT
- scope._CURRENT_KIND = scopes._CURRENT_KIND
-
- -- ok?
- return scope
-end
-
--- restore the current scope
-function interpreter:scope_restore(scope)
-
- -- check
- assert(self and self._PRIVATE and scope)
-
- -- the scopes
- local scopes = self._PRIVATE._SCOPES
- assert(scopes)
-
- -- restore it
- scopes._CURRENT = scope._CURRENT
- scopes._CURRENT_KIND = scope._CURRENT_KIND
-end
-
-- get current instance in the interpreter modules
function interpreter.instance(script)
@@ -1753,8 +1771,6 @@ function interpreter.instance(script)
-- next
level = level + 1
end
-
- -- ok?
return instance
end
diff --git a/xmake/includes/check_cflags.lua b/xmake/includes/check_cflags.lua
index 85c9ef3c7..ef3f7866b 100644
--- a/xmake/includes/check_cflags.lua
+++ b/xmake/includes/check_cflags.lua
@@ -28,6 +28,7 @@
function check_cflags(definition, flags, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_defines(definition)
on_check(function (option)
@@ -37,6 +38,7 @@ function check_cflags(definition, flags, opt)
end
end)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -54,6 +56,7 @@ function configvar_check_cflags(definition, flags, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
@@ -65,6 +68,7 @@ function configvar_check_cflags(definition, flags, opt)
end
end)
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cfuncs.lua b/xmake/includes/check_cfuncs.lua
index 42d173a18..1a64cb250 100644
--- a/xmake/includes/check_cfuncs.lua
+++ b/xmake/includes/check_cfuncs.lua
@@ -34,6 +34,7 @@
function check_cfuncs(definition, funcs, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cfuncs(funcs)
add_defines(definition)
@@ -59,6 +60,7 @@ function check_cfuncs(definition, funcs, opt)
set_warnings(opt.warnings)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -75,6 +77,7 @@ function configvar_check_cfuncs(definition, funcs, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cfuncs(funcs)
if opt.default == nil then
@@ -102,6 +105,7 @@ function configvar_check_cfuncs(definition, funcs, opt)
set_warnings(opt.warnings)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cincludes.lua b/xmake/includes/check_cincludes.lua
index f9d69aad5..dc0308a65 100644
--- a/xmake/includes/check_cincludes.lua
+++ b/xmake/includes/check_cincludes.lua
@@ -28,6 +28,7 @@
function check_cincludes(definition, includes, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cincludes(includes)
if opt.includedirs then
@@ -35,6 +36,7 @@ function check_cincludes(definition, includes, opt)
end
add_defines(definition)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -50,6 +52,7 @@ function configvar_check_cincludes(definition, includes, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cincludes(includes)
if opt.includedirs then
@@ -59,6 +62,7 @@ function configvar_check_cincludes(definition, includes, opt)
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_csnippets.lua b/xmake/includes/check_csnippets.lua
index 95aa0b2d5..9d2370ee0 100644
--- a/xmake/includes/check_csnippets.lua
+++ b/xmake/includes/check_csnippets.lua
@@ -29,6 +29,7 @@
function check_csnippets(definition, snippets, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if not opt.output then
@@ -69,6 +70,7 @@ function check_csnippets(definition, snippets, opt)
end)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -86,6 +88,7 @@ function configvar_check_csnippets(definition, snippets, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if opt.default == nil then
@@ -120,6 +123,7 @@ function configvar_check_csnippets(definition, snippets, opt)
end)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_ctypes.lua b/xmake/includes/check_ctypes.lua
index e0c3caa47..b3f59b04e 100644
--- a/xmake/includes/check_ctypes.lua
+++ b/xmake/includes/check_ctypes.lua
@@ -28,6 +28,7 @@
function check_ctypes(definition, types, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_ctypes(types)
add_defines(definition)
@@ -47,6 +48,7 @@ function check_ctypes(definition, types, opt)
add_cincludes(opt.includes)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -63,6 +65,7 @@ function configvar_check_ctypes(definition, types, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_ctypes(types)
if opt.default == nil then
@@ -84,6 +87,7 @@ function configvar_check_ctypes(definition, types, opt)
add_cincludes(opt.includes)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cxxflags.lua b/xmake/includes/check_cxxflags.lua
index 9a0880697..38ea5172e 100644
--- a/xmake/includes/check_cxxflags.lua
+++ b/xmake/includes/check_cxxflags.lua
@@ -28,6 +28,7 @@
function check_cxxflags(definition, flags, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_defines(definition)
on_check(function (option)
@@ -37,6 +38,7 @@ function check_cxxflags(definition, flags, opt)
end
end)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -54,6 +56,7 @@ function configvar_check_cxxflags(definition, flags, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
@@ -65,6 +68,7 @@ function configvar_check_cxxflags(definition, flags, opt)
end
end)
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cxxfuncs.lua b/xmake/includes/check_cxxfuncs.lua
index 3a64075dc..1488f7312 100644
--- a/xmake/includes/check_cxxfuncs.lua
+++ b/xmake/includes/check_cxxfuncs.lua
@@ -34,6 +34,7 @@
function check_cxxfuncs(definition, funcs, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cxxfuncs(funcs)
add_defines(definition)
@@ -59,6 +60,7 @@ function check_cxxfuncs(definition, funcs, opt)
set_warnings(opt.warnings)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -75,6 +77,7 @@ function configvar_check_cxxfuncs(definition, funcs, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cxxfuncs(funcs)
if opt.default == nil then
@@ -102,6 +105,7 @@ function configvar_check_cxxfuncs(definition, funcs, opt)
set_warnings(opt.warnings)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cxxincludes.lua b/xmake/includes/check_cxxincludes.lua
index a779ffd15..45cb2d2c0 100644
--- a/xmake/includes/check_cxxincludes.lua
+++ b/xmake/includes/check_cxxincludes.lua
@@ -28,10 +28,12 @@
function check_cxxincludes(definition, includes, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cxxincludes(includes)
add_defines(definition)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -47,12 +49,14 @@ function configvar_check_cxxincludes(definition, includes, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cxxincludes(includes)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cxxsnippets.lua b/xmake/includes/check_cxxsnippets.lua
index b46c650ff..daa71780c 100644
--- a/xmake/includes/check_cxxsnippets.lua
+++ b/xmake/includes/check_cxxsnippets.lua
@@ -29,6 +29,7 @@
function check_cxxsnippets(definition, snippets, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if not opt.output then
@@ -69,6 +70,7 @@ function check_cxxsnippets(definition, snippets, opt)
end)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -86,6 +88,7 @@ function configvar_check_cxxsnippets(definition, snippets, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output})
if opt.default == nil then
@@ -120,6 +123,7 @@ function configvar_check_cxxsnippets(definition, snippets, opt)
end)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_cxxtypes.lua b/xmake/includes/check_cxxtypes.lua
index e53caae6e..f5b8c677a 100644
--- a/xmake/includes/check_cxxtypes.lua
+++ b/xmake/includes/check_cxxtypes.lua
@@ -28,6 +28,7 @@
function check_cxxtypes(definition, types, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_cxxtypes(types)
add_defines(definition)
@@ -47,6 +48,7 @@ function check_cxxtypes(definition, types, opt)
add_cxxincludes(opt.includes)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -63,6 +65,7 @@ function configvar_check_cxxtypes(definition, types, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_cxxtypes(types)
if opt.default == nil then
@@ -84,6 +87,7 @@ function configvar_check_cxxtypes(definition, types, opt)
add_cxxincludes(opt.includes)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_features.lua b/xmake/includes/check_features.lua
index 7c02be173..3e8fb47be 100644
--- a/xmake/includes/check_features.lua
+++ b/xmake/includes/check_features.lua
@@ -28,6 +28,7 @@
function check_features(definition, features, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_features(features)
add_defines(definition)
@@ -44,6 +45,7 @@ function check_features(definition, features, opt)
add_cxxflags(opt.cxxflags)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -59,6 +61,7 @@ function configvar_check_features(definition, features, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_features(features)
if opt.default == nil then
@@ -77,6 +80,7 @@ function configvar_check_features(definition, features, opt)
add_cxxflags(opt.cxxflags)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_links.lua b/xmake/includes/check_links.lua
index 06b8cb38c..54891361e 100644
--- a/xmake/includes/check_links.lua
+++ b/xmake/includes/check_links.lua
@@ -28,10 +28,12 @@
function check_links(definition, links, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_links(links)
add_defines(definition)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -47,12 +49,14 @@ function configvar_check_links(definition, links, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_links(links)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_macros.lua b/xmake/includes/check_macros.lua
index ec4beddce..0ed879c95 100644
--- a/xmake/includes/check_macros.lua
+++ b/xmake/includes/check_macros.lua
@@ -30,6 +30,7 @@ function check_macros(definition, macros, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local snippets = {}
+ save_scope()
option(optname)
for _, macro in ipairs(macros) do
if macro:find(' ', 1, true) then
@@ -67,6 +68,7 @@ function check_macros(definition, macros, opt)
add_cxxflags(opt.cxxflags)
end
option_end()
+ restore_scope()
add_options(optname)
end
@@ -81,6 +83,7 @@ function configvar_check_macros(definition, macros, opt)
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
local snippets = {}
+ save_scope()
option(optname)
for _, macro in ipairs(macros) do
if macro:find(' ', 1, true) then
@@ -120,6 +123,7 @@ function configvar_check_macros(definition, macros, opt)
add_cxxflags(opt.cxxflags)
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/check_syslinks.lua b/xmake/includes/check_syslinks.lua
index 133e24dcd..8df32a1b8 100644
--- a/xmake/includes/check_syslinks.lua
+++ b/xmake/includes/check_syslinks.lua
@@ -28,10 +28,12 @@
function check_syslinks(definition, links, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
+ save_scope()
option(optname)
add_syslinks(links)
add_defines(definition)
option_end()
+ restore_scope()
add_options(optname)
end
@@ -47,12 +49,14 @@ function configvar_check_syslinks(definition, links, opt)
opt = opt or {}
local optname = "__" .. (opt.name or definition)
local defname, defval = unpack(definition:split('='))
+ save_scope()
option(optname)
add_syslinks(links)
if opt.default == nil then
set_configvar(defname, defval or 1, {quote = opt.quote})
end
option_end()
+ restore_scope()
if opt.default == nil then
add_options(optname)
else
diff --git a/xmake/includes/find_and_add_packages.lua b/xmake/includes/find_and_add_packages.lua
index 21aa2f783..4bcdd76f9 100644
--- a/xmake/includes/find_and_add_packages.lua
+++ b/xmake/includes/find_and_add_packages.lua
@@ -33,11 +33,13 @@
function find_and_add_packages(...)
for _, name in ipairs({...}) do
local optname = "__" .. name
+ save_scope()
option(optname)
before_check(function (option)
option:add(find_packages(name))
end)
option_end()
+ restore_scope()
add_options(optname)
end
end
diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua
index 12fb5283b..16380ab3c 100644
--- a/xmake/languages/c++/load.lua
+++ b/xmake/languages/c++/load.lua
@@ -68,7 +68,7 @@ function _api_add_cfunc(interp, module, alias, links, includes, func)
end
-- save the current scope
- local scope = interp:scope_save()
+ interp:api_builtin_save_scope()
-- check option
interp:api_call("option", name)
@@ -78,7 +78,7 @@ function _api_add_cfunc(interp, module, alias, links, includes, func)
if includes then interp:api_call("add_cincludes", includes) end
-- restore the current scope
- interp:scope_restore(scope)
+ interp:api_builtin_restore_scope()
-- add this option
interp:api_call("add_options", name)
@@ -120,7 +120,7 @@ function _api_add_cxxfunc(interp, module, alias, links, includes, func)
end
-- save the current scope
- local scope = interp:scope_save()
+ interp:api_builtin_save_scope()
-- check option
interp:api_call("option", name)
@@ -130,7 +130,7 @@ function _api_add_cxxfunc(interp, module, alias, links, includes, func)
if includes then interp:api_call("add_cxxincludes", includes) end
-- restore the current scope
- interp:scope_restore(scope)
+ interp:api_builtin_restore_scope()
-- add this option
interp:api_call("add_options", name)