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

Show all apis #5005

Merged
merged 7 commits into from
Apr 23, 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
6 changes: 6 additions & 0 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2905,5 +2905,11 @@ function package.load_from_repository(packagename, packagedir, opt)
return instance
end

-- new a package instance
function package.new(...)
return _instance.new(...)
end


-- return module
return package
2 changes: 2 additions & 0 deletions xmake/core/sandbox/modules/import/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ sandbox_core_package_package.installdir = package.installdir
sandbox_core_package_package.searchdirs = package.searchdirs
sandbox_core_package_package.targetplat = package.targetplat
sandbox_core_package_package.targetarch = package.targetarch
sandbox_core_package_package.apis = package.apis
sandbox_core_package_package.new = package.new

-- load the package from the project file
function sandbox_core_package_package.load_from_project(packagename)
Expand Down
8 changes: 4 additions & 4 deletions xmake/core/sandbox/modules/import/core/project/option.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ local sandbox_core_project_option = sandbox_core_project_option or {}
local option = require("project/option")
local raise = require("sandbox/modules/raise")

-- get the option interpreter
function sandbox_core_project_option.interpreter()
return option.interpreter()
end
-- inherit some builtin interfaces
sandbox_core_project_option.interpreter = option.interpreter
sandbox_core_project_option.new = option.new
sandbox_core_project_option.apis = option.apis

-- return module
return sandbox_core_project_option
1 change: 1 addition & 0 deletions xmake/core/sandbox/modules/import/core/project/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ sandbox_core_project.policy = project.policy
sandbox_core_project.tmpdir = project.tmpdir
sandbox_core_project.tmpfile = project.tmpfile
sandbox_core_project.is_loaded = project.is_loaded
sandbox_core_project.apis = project.apis

-- check project options
function sandbox_core_project.check_options()
Expand Down
14 changes: 5 additions & 9 deletions xmake/core/sandbox/modules/import/core/project/rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ local project = require("project/project")
local sandbox = require("sandbox/sandbox")
local raise = require("sandbox/modules/raise")

-- get the given global rule
function sandbox_core_project_rule.rule(name)
return rule.rule(name)
end

-- get the all global rules
function sandbox_core_project_rule.rules()
return rule.rules()
end
-- inherit some builtin interfaces
sandbox_core_project_rule.rule = rule.rule
sandbox_core_project_rule.rules = rule.rules
sandbox_core_project_rule.new = rule.new
sandbox_core_project_rule.apis = rule.apis

-- return module
return sandbox_core_project_rule
14 changes: 5 additions & 9 deletions xmake/core/sandbox/modules/import/core/project/target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ local sandbox_core_project_target = sandbox_core_project_target or {}
local target = require("project/target")
local raise = require("sandbox/modules/raise")

-- get the filename from the given name and kind
function sandbox_core_project_target.filename(name, kind, opt)
return target.filename(name, kind, opt)
end

-- get the link name of the target file
function sandbox_core_project_target.linkname(filename, opt)
return target.linkname(filename, opt)
end
-- inherit some builtin interfaces
sandbox_core_project_target.filename = target.filename
sandbox_core_project_target.linkname = target.linkname
sandbox_core_project_target.new = target.new
sandbox_core_project_target.apis = target.apis

-- return module
return sandbox_core_project_target
9 changes: 5 additions & 4 deletions xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,17 @@ end

-- get the filter of the current sandbox for the given script
function sandbox_core_sandbox.filter(script)

-- get the current sandbox instance
local instance = sandbox.instance(script)
if not instance then
raise("cannot get sandbox instance!")
end

-- get it
return instance:filter()
end

-- get all builtin modules
function sandbox_core_sandbox.builtin_modules()
return sandbox.builtin_modules()
end

-- return module
return sandbox_core_sandbox
3 changes: 3 additions & 0 deletions xmake/core/sandbox/modules/import/core/tool/toolchain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ local toolchain = require("tool/toolchain")
local project = require("project/project")
local raise = require("sandbox/modules/raise")

-- inherit some builtin interfaces
sandbox_core_tool_toolchain.apis = toolchain.apis

-- get all toolchains list
function sandbox_core_tool_toolchain.list()
local names = table.copy(platform.toolchains())
Expand Down
71 changes: 30 additions & 41 deletions xmake/core/sandbox/sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,10 @@ end

-- register api for builtin
function sandbox._api_register_builtin(self, name, func)

-- check
assert(self and self._PUBLIC and func)

-- register it
self._PUBLIC[name] = func
end

-- get builtin modules
function sandbox._builtin_modules()
local builtin_modules = sandbox._BUILTIN_MODULES
if builtin_modules == nil then
builtin_modules = {}
local builtin_module_files = os.match(path.join(os.programdir(), "core/sandbox/modules/*.lua"))
if builtin_module_files then
for _, builtin_module_file in ipairs(builtin_module_files) do

-- the module name
local module_name = path.basename(builtin_module_file)
assert(module_name)

-- load script
local script, errors = loadfile(builtin_module_file)
if script then

-- load module
local ok, results = utils.trycall(script)
if not ok then
os.raise(results)
end

-- save module
builtin_modules[module_name] = results
else
-- error
os.raise(errors)
end
end
end
sandbox._BUILTIN_MODULES = builtin_modules
end
return builtin_modules
end

-- new a sandbox instance
function sandbox._new()

Expand All @@ -145,7 +105,7 @@ function sandbox._new()

-- register the builtin modules
instance:_api_register_builtin("_g", {})
for module_name, module in pairs(sandbox._builtin_modules()) do
for module_name, module in pairs(sandbox.builtin_modules()) do
instance:_api_register_builtin(module_name, module)
end

Expand Down Expand Up @@ -350,5 +310,34 @@ function sandbox.instance(script)
return instance
end

-- get builtin modules
function sandbox.builtin_modules()
local builtin_modules = sandbox._BUILTIN_MODULES
if builtin_modules == nil then
builtin_modules = {}
local builtin_module_files = os.files(path.join(os.programdir(), "core/sandbox/modules/*.lua"))
if builtin_module_files then
for _, builtin_module_file in ipairs(builtin_module_files) do
local module_name = path.basename(builtin_module_file)
assert(module_name)

local script, errors = loadfile(builtin_module_file)
if script then
local ok, results = utils.trycall(script)
if not ok then
os.raise(results)
end
builtin_modules[module_name] = results
else
os.raise(errors)
end
end
end
sandbox._BUILTIN_MODULES = builtin_modules
end
return builtin_modules
end


-- return module
return sandbox
Loading
Loading