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

Improve to check and load toolchain #5466

Merged
merged 15 commits into from
Aug 23, 2024
9 changes: 3 additions & 6 deletions xmake/actions/clean/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,15 @@ function main()
return remote_build_action()
end

-- load config first
task.run("config", {require = false}, {disable_dump = true})

-- lock the whole project
project.lock()

-- get the target name
local targetname = option.get("target")

-- local config first
config.load()

-- load targets
project.load_targets()

-- enter project directory
local oldir = os.cd(project.directory())

Expand Down
5 changes: 1 addition & 4 deletions xmake/actions/install/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ end
function main()

-- load config first
config.load()

-- load targets
project.load_targets()
task.run("config", {require = false}, {disable_dump = true})

-- check targets first
local targetname
Expand Down
6 changes: 3 additions & 3 deletions xmake/actions/test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ function main()
return remote_build_action()
end

-- lock the whole project
project.lock()

-- load config first
task.run("config", {}, {disable_dump = true})

-- lock the whole project
project.lock()

-- get tests
local tests = get_tests()
local test_patterns = option.get("tests")
Expand Down
6 changes: 3 additions & 3 deletions xmake/actions/uninstall/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import("uninstall")

function main()

-- config it first
local targetname = option.get("target")
task.run("config", {require = "n", verbose = false})
-- load config first
task.run("config", {require = false}, {disable_dump = true})

-- attempt to uninstall directly
local targetname = option.get("target")
try
{
function ()
Expand Down
14 changes: 0 additions & 14 deletions xmake/core/base/option.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ end

-- get the top context
function option._context()

-- the contexts
local contexts = option._CONTEXTS
if contexts then
return contexts[#contexts]
Expand All @@ -74,29 +72,17 @@ end

-- save context
function option.save(taskname)

-- init contexts
option._CONTEXTS = option._CONTEXTS or {}

-- new a context
local context = {options = {}, defaults = {}, taskname = taskname}

-- init defaults
if taskname then
context.defaults = option.defaults(taskname) or context.defaults
end

-- push this new context to the top stack
table.insert(option._CONTEXTS, context)

-- ok
return context
end

-- restore context
function option.restore()

-- pop it
if option._CONTEXTS then
table.remove(option._CONTEXTS)
end
Expand Down
34 changes: 0 additions & 34 deletions xmake/core/base/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,67 +142,35 @@ end

-- print format string with newline
function utils.print(format, ...)

-- check
assert(format)

-- init message
local message = string.tryformat(format, ...)

-- trace
utils._print(message)

-- write to the log file
log:printv(message)
end

-- print format string without newline
function utils.printf(format, ...)

-- check
assert(format)

-- init message
local message = string.tryformat(format, ...)

-- trace
utils._iowrite(message)

-- write to the log file
log:write(message)
end

-- print format string and colors with newline
function utils.cprint(format, ...)

-- check
assert(format)

-- init message
local message = string.tryformat(format, ...)

-- trace
utils._print(colors.translate(message))

-- write to the log file
if log:file() then
log:printv(colors.ignore(message))
end
end

-- print format string and colors without newline
function utils.cprintf(format, ...)

-- check
assert(format)

-- init message
local message = string.tryformat(format, ...)

-- trace
utils._iowrite(colors.translate(message))

-- write to the log file
if log:file() then
log:write(colors.ignore(message))
end
Expand Down Expand Up @@ -237,8 +205,6 @@ end

-- add warning message
function utils.warning(format, ...)

-- check
assert(format)

-- format message
Expand Down
6 changes: 5 additions & 1 deletion xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,14 @@ function _instance:_load()
if on_load then
on_load(self)
end
self._LOADED = true
end
end

-- mark as loaded package
function _instance:_mark_as_loaded()
self._LOADED = true
end

-- get the raw environments
function _instance:_rawenvs()
local envs = self._RAWENVS
Expand Down
7 changes: 0 additions & 7 deletions xmake/core/project/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,6 @@ function project.interpreter()
if type(result) == "function" then
result = result()
end

-- attempt to get it from the platform tools, e.g. cc, cxx, ld ..
-- because these values may not exist in config cache when call `config.get()`, we need check and get it.
--
if not result then
result = platform.tool(variable)
end
end
return result
end)
Expand Down
3 changes: 3 additions & 0 deletions xmake/core/tool/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ function builder:_add_flags_from_argument(flags, target, args)
return values, extras
end,
toolchain = function (name)
if target and target.toolconfig then
return target:toolconfig(name)
end
local plat, arch
if target and target.plat then
plat = target:plat()
Expand Down
20 changes: 16 additions & 4 deletions xmake/core/tool/toolchain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ end

-- get the program and name of the given tool kind
function _instance:tool(toolkind)
if not self:_is_checked() then
os.raise("we cannot get tool(%s) in toolchain(%s) with %s/%s, because it has been not checked yet!", toolkind, self:name(), self:plat(), self:arch())
end
-- ensure to do load for initializing toolset first
-- @note we cannot call self:check() here, because it can only be called on config
self:_load()
Expand Down Expand Up @@ -270,7 +273,8 @@ end
-- do check, we only check it once for all architectures
function _instance:check()
local checkok = true
if not self._CHECKED then
local checked = self:_is_checked()
if not checked then
local on_check = self:_on_check()
if on_check then
local ok, results_or_errors = sandbox.load(on_check, self)
Expand All @@ -280,7 +284,9 @@ function _instance:check()
os.raise(results_or_errors)
end
end
self._CHECKED = true
-- we need to persist this state
self:config_set("__checked", true)
self:configs_save()
end
return checkok
end
Expand Down Expand Up @@ -374,6 +380,11 @@ function _instance:_is_loaded()
return self:info():get("__loaded")
end

-- is checked?
function _instance:_is_checked()
return self:config("__checked") == true or self:_on_check() == nil
end

-- get the tool description from the tool kind
function _instance:_description(toolkind)
local descriptions = self._DESCRIPTIONS
Expand Down Expand Up @@ -708,8 +719,6 @@ function toolchain.load_fromfile(filepath, opt)
local scope_opt = {interpreter = toolchain._interpreter(), deduplicate = true, enable_filter = true}
local info = scopeinfo.new("toolchain", fileinfo.info, scope_opt)
local instance = toolchain.load_withinfo(fileinfo.name, info, opt)
-- we need to skip check
instance._CHECKED = true
return instance
end

Expand Down Expand Up @@ -800,6 +809,9 @@ function toolchain.toolconfig(toolchains, name, opt)
local toolconfig = cache:get2(cachekey, name)
if toolconfig == nil then
for _, toolchain_inst in ipairs(toolchains) do
if not toolchain_inst:_is_checked() then
os.raise("we cannot get toolconfig(%s) in toolchain(%s) with %s/%s, because it has been not checked yet!", name, toolchain_inst:name(), toolchain_inst:plat(), toolchain_inst:arch())
end
local values = toolchain_inst:get(name)
if values then
toolconfig = toolconfig or {}
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
12 changes: 0 additions & 12 deletions xmake/modules/private/action/require/impl/actions/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ function _fix_paths_for_precompiled_package(package)
end
end

-- check package toolchains
function _check_package_toolchains(package)
for _, toolchain_inst in pairs(package:toolchains()) do
if not toolchain_inst:check() then
raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
end
end
end

-- get failed install directory
function _get_installdir_failed(package)
return path.join(package:cachedir(), "installdir.failed")
Expand Down Expand Up @@ -396,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
Loading
Loading